
PACKAGE = @PACKAGE@
VERSION = @VERSION@

DISFILES="jpilot.c address_gui.c"

top_srcdir = @top_srcdir@
top_builddir = @top_srcdir@

SUBDIRS = @INTLSUB@ @POSUB@

# Install variables
prefix=@prefix@

datadir = $(prefix)/@DATADIRNAME@
localedir = $(datadir)/locale
gnulocaledir = $(prefix)/share/locale

#Pilot flags (include dir), and Libraries
PILOT_FLAGS=@PILOT_FLAGS@
PILOT_LIBS=@PILOT_LIBS@

#set CC to your compiler
CC = @CC@

DEFS = @DEFS@ 

I18NDEFS = -DLOCALEDIR=\"$(localedir)\" -DGNULOCALEDIR=\"$(gnulocaledir)\"

# CC options
# japanese support
CCDEFINES = $(DEFS) -DBASE_DIR=\"$(prefix)\"
CFLAGS = @cflags@

# CC options
OPTIONS = @ccoptions@ $(CCDEFINES) $(CFLAGS)

# GTK+ flags
GTKFLAGS = @GTK_CFLAGS@
# GTK+ libs
GTKLIBS = @GTK_LIBS@

INTLLIBS = @INTLLIBS@

# Targets
all: po_dir intl_dir jpilot

jpilot: jpilot.o datebook.o address.o todo.o memo.o \
	utils.o sync.o prefs.o log.o plugins.o \
	datebook_gui.o address_gui.o todo_gui.o memo_gui.o \
	prefs_gui.o search_gui.o install_gui.o weekview_gui.o \
	monthview_gui.o print_gui.o print.o \
	japanese.o
	$(CC) $(OPTIONS) $(GTKFLAGS) \
	jpilot.o datebook.o address.o todo.o memo.o \
	utils.o sync.o prefs.o log.o plugins.o \
	datebook_gui.o address_gui.o todo_gui.o memo_gui.o \
	prefs_gui.o search_gui.o install_gui.o weekview_gui.o \
	monthview_gui.o print_gui.o print.o \
	japanese.o \
	$(PILOT_LIBS) $(GTKLIBS) $(INTLLIBS) \
	-o jpilot


jpilot.o: jpilot.c utils.h
	$(CC) $(I18NDEFS) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c jpilot.c

datebook.o: datebook.c datebook.h utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c datebook.c

address.o: address.c address.h utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c address.c

todo.o: todo.c todo.h utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c todo.c

memo.o: memo.c memo.h utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c memo.c

datebook_gui.o: datebook_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c datebook_gui.c

address_gui.o: address_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c address_gui.c

todo_gui.o: todo_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c todo_gui.c

memo_gui.o: memo_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c memo_gui.c

search_gui.o: search_gui.c utils.h address.h datebook.h todo.h memo.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c search_gui.c

prefs_gui.o: prefs_gui.c prefs.h utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c prefs_gui.c

print_gui.o: print_gui.c print.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c print_gui.c

install_gui.o: install_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c install_gui.c

weekview_gui.o: weekview_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c weekview_gui.c

monthview_gui.o: monthview_gui.c utils.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c monthview_gui.c

utils.o: utils.c utils.h sync.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c utils.c

sync.o: sync.c sync.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c sync.c

log.o: log.c log.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c log.c

plugins.o: plugins.c plugins.h config.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c plugins.c

prefs.o: prefs.c utils.h prefs.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c prefs.c

print.o: print.c print.h config.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c print.c

japanese.o: japanese.c japanese.h
	$(CC) $(OPTIONS) -c japanese.c
#
#libplugin is only needed for compiling plugins
#
#libplugin.o: libplugin.c libplugin.h
#	$(CC) $(OPTIONS) $(GTKFLAGS) -c libplugin.c
#
#libplugin: libplugin.o libplugin.h
#	rm -f libplugin.a
#	ar cur libplugin.a libplugin.o
#	ranlib libplugin.a

libplugin.o: libplugin.c libplugin.h
	./libtool --mode=compile \
	$(CC) $(OPTIONS) $(GTKFLAGS) -c libplugin.c

libplugin: libplugin.o  libplugin.h
	./libtool --mode=link \
	$(CC) $(OPTIONS) $(GTKFLAGS) -o libplugin.la libplugin.lo \
	-static \
	-rpath /home/mouse/jpilot;
	./libtool --mode=install ./install-sh \
	libplugin.la $(PWD)
#	./libtool --mode=finish /home/mouse/jpilot/Expense;
	
jpilot-dump: jpilot-dump.o datebook.o log.o utils.o prefs.o todo.o plugins.o
	$(CC) $(OPTIONS) $(GTKFLAGS) \
	jpilot-dump.o datebook.o log.o utils.o prefs.o todo.o plugins.o \
	$(PILOT_LIBS) $(GTKLIBS) \
	-o jpilot-dump

jpilot-dump.o: jpilot-dump.c config.h
	$(CC) $(OPTIONS) $(PILOT_FLAGS) $(GTKFLAGS) -c jpilot-dump.c

POFILES = @POFILES@
GMOFILES = @GMOFILES@

po_dir:
	cd po; make

intl_dir:
	cd intl; make

clean:
	rm -f *.o *~ config.cache 

distclean: clean
	rm -f config.status config.h config.log jpilot Makefile

install:
#	./install-sh -d $(prefix)/bin/
	if test -d "$(prefix)/bin" ; then \
	  ./install-sh -s -c -m 555 jpilot $(prefix)/bin/jpilot ; \
	else \
	  ./install-sh -s -c -m 555 jpilot $(prefix)/jpilot ; \
	fi
	./install-sh -d -m 755 $(prefix)/share/jpilot
	./install-sh -c -m 755 jpilotrc.blue $(prefix)/share/jpilot
	./install-sh -c -m 755 jpilotrc.default $(prefix)/share/jpilot/
	./install-sh -c -m 755 jpilotrc.green $(prefix)/share/jpilot/
	./install-sh -c -m 755 jpilotrc.purple $(prefix)/share/jpilot/
	./install-sh -c -m 755 jpilotrc.steel $(prefix)/share/jpilot/
	./install-sh -c -m 755 empty/DatebookDB.pdb $(prefix)/share/jpilot/
	./install-sh -c -m 755 empty/AddressDB.pdb $(prefix)/share/jpilot/
	./install-sh -c -m 755 empty/ToDoDB.pdb $(prefix)/share/jpilot/
	./install-sh -c -m 755 empty/MemoDB.pdb $(prefix)/share/jpilot/
	cd intl; make install
	cd po; make install

uninstall:
	rm $(prefix)/share/jpilot/*
	rm $(prefix)/bin/jpilot
	rm $(prefix)/jpilot
	cd intl; make uninstall
	cd po; make uninstall

distdir = $(PACKAGE)-$(VERSION)
dist: Makefile
	rm -fr $(distdir)
	mkdir $(distdir)
	chmod 777 $(distdir)
	for file in $(DISTFILES); do \
	  ln $$file $(distdir) 2>/dev/null || cp -p $$file $(distdir); \
	done
	for subdir in $(SUBDIRS); do \
	  mkdir $(distdir)/$$subdir || exit 1; \
	  chmod 777 $(distdir)/$$subdir; \
          (cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	tar chozf $(distdir).tar.gz $(distdir)
	rm -fr $(distdir)
	
