TOOLCHAIN		?=	~/m68k-none-elf/bin/
CC				=	$(TOOLCHAIN)/m68k-none-elf-gcc
LD				=	$(TOOLCHAIN)/m68k-none-elf-gcc
OBJCOPY			=	$(TOOLCHAIN)/m68k-none-elf-objcopy
COMMON			=	-Wno-multichar -funsafe-math-optimizations -Os -m68000 -mno-align-int -mpcrel -fpie -fshort-enums -mshort -mno-align-int
WARN			=	-Wsign-compare -Wextra -Wall -Werror -Wno-unused-parameter -Wno-old-style-declaration -Wno-unused-function -Wno-unused-variable -Wno-error=cpp -Wno-strict-aliasing
LKR				=	linker.lkr
RES				=	res.rcp
CCFLAGS			=	$(LTO) $(WARN) $(COMMON) -I. -ffunction-sections -fdata-sections
LDFLAGS			=	$(LTO) $(WARN) $(COMMON) -Wl,--gc-sections -Wl,-T $(LKR)
SRCS			=	RepalmInfoPanl.c
OBJS			=	$(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SRCS)))
PRC				=	RepalmInfoPanl.prc

#add PalmOS SDK
INCS			+=	-isystem../../SDK
INCS			+=	-isystem../../SDK/Core
INCS			+=	-isystem../../SDK/Core/Hardware
INCS			+=	-isystem../../SDK/Core/System
INCS			+=	-isystem../../SDK/Core/UI
INCS			+=	-isystem../../SDK/Dynamic
INCS			+=	-isystem../../SDK/Libraries
INCS			+=	-isystem../../SDK/Extensions/ExpansionMgr/


#add our include paths
INCS			+=	-I../dal


all:	$(PRC)

$(PRC):	$(RES) code0001.bin
	pilrc -ro -type panl -creator rpII -name RepalmInfoPanl $< $@

%.bin:	%.elf
	$(OBJCOPY) -O binary $< $@ -j.vec -j.text -j.rodata

code0001.elf: $(OBJS)
	$(LD) -o $@ $(LDFLAGS) $^

%.o : %.c Makefile
	$(CC) $(CCFLAGS)  $(INCS) -c $< -o $@

clean:
	rm -rf $(OBJS) $(TARGET).elf $(TARGET).bin
 
.PHONY: clean
