## Makefile for GarminTalk
#
# $Id: Makefile,v 1.36 2004/11/17 21:39:58 clavelei Exp $

SDK_VERSION = -palmos4


TARGET = GPilotS
RSCFILE = gtalkRsc.h
#APPNAME = "GPilotS"
#APPID = "GPil"
L1 = ENGLISH
L2 = FRENCH
L3 = GERMAN
L4 = SPANISH
l1 = en
l2 = fr
l3 = de
l4 = es
# hacking pour eviter renommage des fichiers :
OLDTARGET = gtalk
DOCDIR = doc
DOXYFILE = dox/Doxyfile
# fichiers en edition ?
LOCKED := $(shell ident *.[ch] Makefile | awk '/Id:/{if ($$8!="$$")locked++}END{print locked}')
# version de snapshot :
SNAP :=  $(shell rlog -h $(OLDTARGET).c | \
           awk '(ok)&&($$2==vers){split($$1,t,":");sub("-", ".", t[1]);print t[1];vers="null"}\
                /head:/{vers=$$2}/symbolic names:/{ok=1}')
SNAP := "$(SNAP)"
VERSION :=  $(shell awk -v locked=$(LOCKED) '($$1=="\"AboutMsg\""){ \
              if(locked) print $$4"rc"strftime("%y%m%d%H%M"); \
              else printf("%s",$(SNAP));exit}' $(OLDTARGET).rcp)


OBJS =  MathLib.o log.o memo.o datum.o dbio.o gpsio.o route.o editwpt.o latlong.o map.o $(OLDTARGET).o track.o $(TARGET)-sections.o gpsutil.o objects.o


LIBS = -lPalmOSGlue -L . -lgpslib #-lgpsutil


# defined defines :
DEFS = 
DEFS +=  -D DEBUG #               to compile debugging messages
#DEFS +=  -D SKIPEDIT #           to skip editwpt
#DEFS +=  -D GRAPHICALROUTEEDIT #  select graphical route edition instead of traditional
# DEFS +=  -D BEAM #              to insert beaming code
# DEFS +=  -D EXPORT #            to insert export code
DEFS +=  -D SELECT #              to insert select mode code
DEFS +=  -D NEWSERIALMGR #      to insert new serial manager support code
#DEFS +=  -D FURUNO #            to insert Furuno code
DEFS +=  -D LOOSE #            to allow relax Garmin protocol checks
#DEFS +=  -D EVENTS # to include async events code

# -O2 semble le + efficace en terme de taille
CFLAGS =  -Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g -O2  -T text_64k $(DEFS)

CC        = m68k-palmos-gcc $(SDK_VERSION)
PILRC     = pilrc -q $(DEFS)
NM        = m68k-palmos-nm
MULTIGEN  = m68k-palmos-multigen
SIZE      = m68k-palmos-size
OBJDUMP   = m68k-palmos-objdump
BUILDPRC  = /usr/bin/build-prc
PILOTXFER = pilot-xfer

all: $(TARGET)-$(l1).prc $(TARGET)-$(l2).prc $(TARGET)-$(l3).prc $(TARGET)-$(l4).prc

.S.o:
	$(CC) $(TARGETFLAGS) -c $<

.c.s:
	$(CC) $(CSFLAGS) $<

$(TARGET)-$(l1).prc: $(TARGET) $(TARGET).def bin-$(l1).stamp tver0001.bin
	$(BUILDPRC) -o $(TARGET)-$(l1).prc $(TARGET).def $(TARGET) *.bin
	/bin/rm bin-$(l1).stamp

$(TARGET)-$(l2).prc: $(TARGET) $(TARGET).def bin-$(l2).stamp tver0001.bin
	$(BUILDPRC) -o $(TARGET)-$(l2).prc $(TARGET).def $(TARGET) *.bin
	/bin/rm bin-$(l2).stamp

$(TARGET)-$(l3).prc: $(TARGET) $(TARGET).def bin-$(l3).stamp tver0001.bin
	$(BUILDPRC) -o $(TARGET)-$(l3).prc $(TARGET).def $(TARGET) *.bin
	/bin/rm bin-$(l3).stamp

$(TARGET)-$(l4).prc: $(TARGET) $(TARGET).def bin-$(l4).stamp tver0001.bin
	$(BUILDPRC) -o $(TARGET)-$(l4).prc $(TARGET).def $(TARGET) *.bin
	/bin/rm bin-$(l4).stamp

$(TARGET)-sections.o: $(TARGET)-sections.s
	$(CC) -c $(TARGET)-sections.s

$(TARGET)-sections.s $(TARGET)-sections.ld: $(TARGET).def
	$(MULTIGEN) $(TARGET).def

bin-$(l1).stamp: $(OLDTARGET).rcp $(RSCFILE) $(TARGET).pbm
	$(PILRC) -L $(L1) $(OLDTARGET).rcp .
	touch bin-$(l1).stamp

bin-$(l2).stamp: $(OLDTARGET).rcp $(RSCFILE) $(TARGET).pbm
	$(PILRC) -L $(L2) $(OLDTARGET).rcp .
	touch bin-$(l2).stamp

bin-$(l3).stamp: $(OLDTARGET).rcp $(RSCFILE) $(TARGET).pbm
	$(PILRC) -L $(L3) $(OLDTARGET).rcp .
	touch bin-$(l3).stamp

bin-$(l4).stamp: $(OLDTARGET).rcp $(RSCFILE) $(TARGET).pbm
	$(PILRC) -L $(L4) $(OLDTARGET).rcp .
	touch bin-$(l4).stamp

$(TARGET): $(OBJS) $(TARGET)-sections.ld
	$(CC) $(CFLAGS) $(OBJS) -o $(TARGET) $(LIBS) $(TARGET)-sections.ld
	! $(NM) -u $(TARGET) | grep .

tver0001.bin: $(OLDTARGET).rcp Makefile
	VERSION=$(VERSION); if [ "$(DEBUG)" == "-DDEBUG" ] ; then VERSION=$(VERSION)"d"; fi;\
	echo -n -e $$VERSION'\000' > tver0001.bin

send-$(l1): $(TARGET)-$(l1).prc
	$(PILOTXFER) -i $(TARGET)-$(l1).prc

send-$(l2): $(TARGET)-$(l2).prc
	$(PILOTXFER) -i $(TARGET)-$(l2).prc

send-$(l3): $(TARGET)-$(l3).prc
	$(PILOTXFER) -i $(TARGET)-$(l3).prc

send-$(l4): $(TARGET)-$(l4).prc
	$(PILOTXFER) -i $(TARGET)-$(l4).prc

dist: $(TARGET)-$(l1).prc $(TARGET)-$(l2).prc $(TARGET)-$(l3).prc $(TARGET)-$(l4).prc
	zip -j -q $(TARGET)$(VERSION)-$(l1).zip $(TARGET)-$(l1).prc Readme ../gpslib/gpslib*.*.prc ../gpsutils/gpsutil*.*.prc ;\
	zip -j -q $(TARGET)$(VERSION)-$(l2).zip $(TARGET)-$(l2).prc Readme Lisezmoi ../gpslib/gpslib*.*.prc ../gpsutils/gpsutil*.*.prc ;\
	zip -j -q $(TARGET)$(VERSION)-$(l3).zip $(TARGET)-$(l3).prc Readme ../gpslib/gpslib*.*.prc ../gpsutils/gpsutil*.*.prc ;\
	zip -j -q $(TARGET)$(VERSION)-$(l4).zip $(TARGET)-$(l4).prc Readme ../gpslib/gpslib*.*.prc ../gpsutils/gpsutil*.*.prc ;\
	echo "made  $(TARGET)$(VERSION)-$(l1).zip, $(TARGET)$(VERSION)-$(l2).zip, $(TARGET)$(VERSION)-$(l3).zip, $(TARGET)$(VERSION)-$(l4).zip "

tags:
	etags *.[ch] ;\
	echo "../utils/TAGS,include" >> TAGS

stats:
	wc *.c *.h

showsizes:
	echo "Sizes of object files sections (dec) :";\
	$(SIZE) -d $(OBJS)

showundef:
	echo "undefined symbols :";\
	$(NM) -u -l $(OBJS)

showreloc:
	echo "Relocation entries :";\
	$(OBJDUMP) -r -l $(OBJS)

cxref: $(OLDTARGET).c
	mkdir -p cxref;cxref *.c -Ocxref -xref-all -index-all -html32-src \
	-CPP "$(CC) -E -C -dD" \
	-I/opt/palmdev/sdk-4/include \
	-I/opt/palmdev/sdk-4/include/Core/UI \
	-I/opt/palmdev/sdk-4/include/Core/System \
	-I/opt/palmdev/sdk-4/include/Core/Hardware;\
	cxref MathLib.c -delete  -Ocxref

depend:
	makedepend -Y -I. *.c

doc: $(DOXYFILE) dox/doc.dox
	doxygen $(DOXYFILE)\
	touch $(DOCDIR)

clean:
	-rm -f *.[os] *.ld $(TARGET) *.bin bin-*.stamp *.grc Makefile.bak *~

veryclean: clean
	-rm -rf $(TARGET)*.prc pilot.ram pilot.scratch TAGS $(TARGET)*.zip cxref $(DOCDIR)

# DO NOT DELETE

datum.o: latlong.h sections.h
dbio.o: gtalkRsc.h gpslib.h Garmin.h gtalk.h types.h sections.h gpsutil.h
dbio.o: log.h dbio.h gpsio.h
editwpt.o: gtalkRsc.h latlong.h sections.h MathLib.h gpslib.h Garmin.h
editwpt.o: gtalk.h types.h gpsutil.h dbio.h
gpsio.o: gtalkRsc.h MathLib.h gpslib.h Garmin.h gtalk.h types.h sections.h
gpsio.o: gpsutil.h dbio.h gpsio.h memo.h log.h
gpsutil.o: MathLib.h Garmin.h types.h log.h sections.h gpsutil.h
gtalk.o: gtalkRsc.h latlong.h sections.h MathLib.h gpslib.h Garmin.h gtalk.h
gtalk.o: types.h route.h gpsutil.h log.h map.h gpsio.h memo.h dbio.h track.h
latlong.o: latlong.h sections.h MathLib.h
log.o: log.h sections.h memo.h
map.o: gtalkRsc.h latlong.h sections.h MathLib.h gpslib.h Garmin.h gtalk.h
map.o: types.h gpsutil.h map.h log.h dbio.h route.h memo.h
MathLib.o: MathLib.h
memo.o: memo.h sections.h
objects.o: Garmin.h types.h log.h sections.h gpsutil.h
route.o: gtalkRsc.h gpslib.h Garmin.h gtalk.h types.h sections.h route.h
route.o: gpsutil.h log.h dbio.h map.h
track.o: gtalkRsc.h gpslib.h Garmin.h gtalk.h types.h sections.h track.h
track.o: gpsutil.h log.h dbio.h map.h
