# Mobilelink (MAL client) makefile

.SUFFIXES: .prc .ppm .bmp .Tbmp

MAL_COMMON_DIR        = ../../../../common
MAL_COMMON_CLIENT_DIR = ../../../common
MAL_LIBMAL_DIR = ../../lib/src
SYSTEM_DIR = ../../system
INCLUDES = \
	-I$(MAL_COMMON_CLIENT_DIR) \
	-I$(MAL_COMMON_DIR)        \
	-I$(MAL_LIBMAL_DIR)        \
	-I$(SYSTEM_DIR)            \
	-I.

COPT_FLAGS = -O2 -g0
CC = m68k-palmos-coff-gcc
CFLAGS = -Wall $(COPT_FLAGS) $(INCLUDES)
LD = m68k-palmos-coff-gcc
LDFLAGS = $(COPT_FLAGS)

PILRC = pilrc -q
OBJRES = m68k-palmos-coff-obj-res
BUILDPRC = build-prc

APPID =   MBla
PRCNAME = MobileLink
APPTEXT = MobileLink

CFILES =                \
	mobilelink.c    \
	malclient.c     \
	password.c      \
	palmmal.c	\
	progresspanel.c \
	debug.c		\
#

LIBS = -L$(SYSTEM_DIR) -lthunk

# Resources
RCPFILE = $(PRCNAME).rcp
APPICONS = icon_s.Tbm icon_l.Tbm

OFILES = $(CFILES:.c=.o)

# shared make vars ############################################################

default: $(PRCNAME).prc

_resources: $(RCPFILE) $(APPICONS)
	awk '\
	/FIELD ID .* NONEDITABLE/ { print $$0; next } \
	/FIELD ID .* UNDERLINED/  { print $$0; next } \
	/FIELD ID /               { print $$0 "UNDERLINED"; next } \
	/BITMAP ID 100[01]/       { next } \
	                          { print $$0 }' $(RCPFILE) > $(RCPFILE).tmp
	$(PILRC) $(RCPFILE).tmp >/dev/null
	rm -f $(RCPFILE).tmp
	cp -f icon_l.Tbm tAIB03e8.bin
	cp -f icon_s.Tbm tAIB03e9.bin
	touch _resources

$(PRCNAME).prc: $(PRCNAME) _resources
	$(OBJRES) $*
	rm -f $*
	$(BUILDPRC) -f 'resource|backup' $(PRCNAME).prc $(APPTEXT) $(APPID) \
	*.grc *.bin || (rm -f $*.prc; false)

$(PRCNAME): $(OFILES)
	$(LD) $(LDFLAGS) -o $(PRCNAME) $(OFILES) $(LIBS)

$(PRCNAME).rcp: mobilelink.rsrc
	@echo "$(PRCNAME).rcp needs to be updated, see READMEGCC" ; false

release: $(PRCNAME).prc
	mkdir -p ../Release
	cp -f $(PRCNAME).prc ../Release

clean:
	rm -f $(OFILES) *.bin *.prc *.grc *~ _resources $(PRCNAME)

