# $Id: Makefile,v 1.10 2000/09/07 07:10:06 keithp Exp $
# 
# Copyright  2000 Keith Packard
# 
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of Keith Packard not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission.  Keith Packard makes no
# representations about the suitability of this software for any purpose.  It
# is provided "as is" without express or implied warranty.
# 
# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#

PROG = formula
TARGET = $(PROG).prc
MATHLIB=MathLib.prc
ZIP = $(PROG).zip
OBJS = gram.o lex.o node.o execute.o builtin.o formula.o compile.o prim.o load.o mlib.o
HDRS = formula.h
RES = formula.rcp
ICON = formula.pbitm
RLOC= rloc0000.$(PROG).grc
GRCS = code0000.$(PROG).grc code0001.$(PROG).grc data0000.$(PROG).grc $(RLOC)
PREF= pref0000.$(PROG).grc


PREFIX = /local/PalmOS
TOOLS= $(PREFIX)/bin
CC = $(TOOLS)/m68k-palmos-coff-gcc

#uncomment this if you want to build a gdb debuggable version
#DEFINES = -DDEBUG
INCLUDES=-I../mathlib/src

CSFLAGS = -O2 -S $(DEFINES) $(INCLUDES)
CFLAGS = -O2 $(DEFINES) $(INCLUDES) -Wall -Wstrict-prototypes -fno-builtin

LIBS = $(LDIR) -lgdb -lc -lgcc

PILRC = $(TOOLS)/pilrc
TXT2BITM = $(TOOLS)/txt2bitm
OBJRES = $(TOOLS)/obj-res -reloc
#OBJRES = $(TOOLS)/obj-res
BUILDPRC = $(TOOLS)/build-prc

ICONTEXT = "Formula"
APPID = frml

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

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

all: $(TARGET)

$(TARGET): $(GRCS) bin.res
	$(BUILDPRC) $(TARGET) $(ICONTEXT) $(APPID) $(GRCS) \
		*.bin $(PREF)
$(ZIP): $(TARGET) $(MATHLIB) readme.txt
	zip $@ $(TARGET) $(MATHLIB) readme.txt

$(GRCS): $(PROG)
	$(OBJRES) $(PROG)

$(MATHLIB): ../mathlib/MathLib.prc
	ln -s ../mathlib/MathLib.prc $@

bin.res: $(RES) $(ICON) formulares.h
	rm -f *.bin
	$(PILRC) $(RES) .
	$(TXT2BITM) $(ICON)
	touch $@

$(PROG): $(OBJS)
	$(CC) -Wl,-M -Wl,-r -Wl,-dc $(CFLAGS) $(OBJS) -o $(PROG) $(LIBS)

$(OBJS): $(HDRS)
gram.o lex.o: gram.h
formula.o: formulares.h

gram.c gram.h: gram.y
	bison -d -o gram.c gram.y
	
clean:
	rm -rf gram.c gram.h $(OBJS) $(TARGET) $(PROG) *.bin bin.res $(GRCS)\
	$(PREF) $(MATHLIB)
