#
# This file is part of APT.
#
# APT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# APT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with APT.  If not, see <http://www.gnu.org/licenses/>.
#
#

#
# Makefile
# Copyright 2009 Jerome Ibanes
#

RCPFILE = apt.rcp
PRCFILE = Apt.prc
ASSISTPRCFILE=AptAssist.prc
APT_CREATOR=AptA

GLUELIB=/opt/palmdev/sdk-5r3/lib/m68k-palmos-coff/libPalmOSGlue.a
OBJS=resident.o ui.o ui2.o  share.o apt-sections.o
CC = m68k-palmos-gcc -Os
HOME=/opt/palmdev/sdk-5r3/include

CFLAGS=-palmos5r3  -Wall -I$(HOME) -I$(HOME)/Core/Hardware  -I$(HOME)/Core/System -I$(HOME)/Core -I$(HOME)/Dynamic -I$(HOME)/Core/UI -I$(HOME)/Libraries -I$(HOME)/68K/Libraries/Network -I$(HOME)/Extensions/ExpansionMgr -I$(HOME)/Common/Libraries/CodecPluginMgr -I$(HOME)/68K/Libraries/CodecPluginMgr -I$(HOME)/Common/System  -I$(HOME)/68K/System -I$(HOME)/Common/Libraries/hssoundlib -I${HOME}/Common/Libraries/PmKeyLib

AS = m68k-palmos-gcc
ASFLAGS = -c

all: full
	cp -f Apt.prc apt2/apt2.prc
	rm -f apt2.zip
	zip -r apt2.zip apt2

pub:
	-cd publish && rm -f *.prc
	make full
	cp ${PRCFILE} publish
	cp ${ASSISTPRCFILE} publish
	cp aptassist.c publish/aptassist/

aptassist: aptassist.o share.o 
	$(CC) -nostartfiles -e DAMain -o aptassist aptassist.o share.o ${GLUELIB}

${ASSISTPRCFILE}: aptassist
	build-prc --no-check-resources -o ${ASSISTPRCFILE} -n "AptAssist" -c ${APT_CREATOR} -t DAcc aptassist

full: clean ${PRCFILE} ${ASSISTPRCFILE}

aptassist.o: aptassist.c
	$(CC) $(CFLAGS) -c aptassist.c -o aptassist.o

${PRCFILE}: apt apt.def tfrm03e8.bin
	build-prc -o ${PRCFILE} -n "Apt" -c ${APT_CREATOR}  apt.def apt *.bin

tfrm03e8.bin: ${RCPFILE} ui.h ui2.h res.h resident.h
	pilrc ${RCPFILE}

apt: $(OBJS) apt-sections.ld
	$(CC)  -o apt $(OBJS)  apt-sections.ld

share.o:
	$(CC) $(CFLAGS) -c share.c -o share.o

resident.o: resident.c resident.h residentshared.h
	$(CC) $(CFLAGS) -c resident.c -o resident.o

ui.o: ui.c ui.h uishared.h residentshared.h
	$(CC) $(CFLAGS) -c ui.c -o ui.o

ui2.o: ui2.c ui2.h ui.h uishared.h residentshared.h
	$(CC) $(CFLAGS) -c ui2.c  -o ui2.o

apt.sections.o: apt-sections.s
	$(CC) $(CFLAGS) -c apt-sections.s

apt-sections.s apt-sections.ld: apt.def
	m68k-palmos-multigen apt.def
	cp pilot.ld apt-sections.ld

clean:
	-rm -f *.bin *.o *-sections.* apt *.prc *~  mv \#* code aptassist *.zip
