SHELL = bash

#Compiler to use
CC = m68k-palmos-gcc

#Use this to check the size of the Palm executable.
SIZE = m68k-palmos-size

#Application info
APPID = MWH2
TARGET = Astro
DOCS = ../docs/Astro.pdb ../docs/Location.pdb ../docs/license.pdb
OSLEVEL = -palmos3.5

#OPTIONS = -O2 -DAPPID="'$(APPID)'" -DERROR_CHECK_LEVEL=ERROR_CHECK_PARTIAL
OPTIONS = -g -O -DAPPID="'$(APPID)'" -DERROR_CHECK_LEVEL=ERROR_CHECK_FULL -DMOONRISE_CHECK

INCLUDES =

CFLAGS = -Wall -Werror $(OPTIONS) $(OSLEVEL)

PILRC = pilrc
OBJRES = m68k-palmos-obj-res
BUILDPRC = build-prc
PINSTALLER = pilot-xfer /dev/pilot -i
MAKEDOC = makedoc
ZIP = zip

PRC = ../bin/$(TARGET).prc
OBJS = $(TARGET).o MathLib.o AstroLib.o AstroCat.o PalmUtil.o \
       $(TARGET)-sections.o \
       ../lib/libnfm.a

all: $(PRC) $(DOCS) catalogs

$(PRC): $(TARGET)
	if [ ! -d ../bin ] ; then  mkdir ../bin ; fi
	$(BUILDPRC) -o $(PRC) $(TARGET).def $(TARGET) *.bin

resource.h: $(TARGET).rcp ../lib/bar.bmp ../lib/icon.bmp ../lib/icong.bmp ../lib/iconc.bmp
	echo >$@
	$(PILRC) -h $@ $(TARGET).rcp

$(TARGET): $(OBJS) Makefile
	$(CC) $(CFLAGS) $(OBJS) \
	$(TARGET)-sections.ld \
	-o $@
	$(SIZE) $@

clean:
	rm -rf *.[oa] $(TARGET) *.bin resource.h *.ld *~
	cd ../docs; rm -rf *~

scrub:  clean
	rm -rf $(PRC) $(DOCS) 

install: all
	$(PINSTALLER) ../bin/Astro.prc ../lib/MathLib.prc Astro.pdb ../docs/*.pdb

palmUtil.o: PalmUtil.h PalmUtil.c

AstroLib.o: constants.h MathLib.h AstroLib.h

Astro.o:    resource.h MathLib.h constants.h AstroLib.h Astro.h \
            PalmUtil.h AstroCat.h

AstroCat.o: resource.h AstroLib.h Astro.h PalmUtil.h AstroCat.h

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

../docs/license.pdb:      ../docs/license.txt
	-$(MAKEDOC) ../docs/license.txt ../docs/license.pdb "Astro Info License"

../docs/Astro.pdb:      ../docs/Astro.txt
	-$(MAKEDOC) ../docs/Astro.txt ../docs/Astro.pdb "Astro Info Readme"

../docs/Location.pdb:   ../docs/Location.txt
	-$(MAKEDOC) ../docs/Location.txt ../docs/Location.pdb "Lat/Long/TZ List"

catalogs:
	cd ../java; make

zip:            all
	rm -f ../astro.zip
	cd ..; $(ZIP) -j astro.zip bin/Astro.prc docs/*.pdb docs/*.txt lib/MathLib.prc

sourcezip:      scrub
	rm -f ../astros.zip
	cd ..; $(ZIP) -r astros.zip * -x *.zip 
