## Makefile for Disassembler
# (C) 1998 University of Troms, Norway
# by Per Harald Myrvang <perm@stud.cs.uit.no>

TARGET = disasm
APPNAME = "Disassembler"
APPID = "DiAs"

#OBJS = $(TARGET).o convert.o pilot-trap.o sprintf.o
OBJS = $(TARGET).o convert.o pilot-trap.o
LIBS = -lc

CC = m68k-palmos-coff-gcc

CFLAGS = -Wall -O2 -DVERBOSE -g
#CFLAGS = -Wall -g -O2 

PERL = perl
PILRC = pilrc
OBJRES = m68k-palmos-coff-obj-res
BUILDPRC = build-prc
PILOTXFER = pilot-xfer
SYSTRAP_H = /usr/local/pilot/m68k-palmos-coff/include/PalmOS/System/SysTraps.h
M68328HWR_H = /usr/local/pilot/m68k-palmos-coff/include/PalmOS/Hardware/M68328Hwr.h

all: $(TARGET).prc

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

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

$(TARGET).prc: code0000.$(TARGET).grc code0001.$(TARGET).grc data0000.$(TARGET).grc pref0000.$(TARGET).grc rloc0000.$(TARGET).grc bin.res
	$(BUILDPRC) $(TARGET).prc $(APPNAME) $(APPID) code0001.$(TARGET).grc code0000.$(TARGET).grc data0000.$(TARGET).grc *.bin pref0000.$(TARGET).grc rloc0000.$(TARGET).grc

code0000.$(TARGET).grc: $(TARGET)
	$(OBJRES) $(TARGET)

code0001.$(TARGET).grc: code0000.$(TARGET).grc

data0000.$(TARGET).grc: code0000.$(TARGET).grc

pref0000.$(TARGET).grc: code0000.$(TARGET).grc

rloc0000.$(TARGET).grc: code0000.$(TARGET).grc

m68328Hwr_massaged.data:
	$(PERL) -e '\
    print "sysCtrl\0mskRev\0csAGrpBase\0csBGrpBase\0csCGrpBase\0";\
    print "sDGrpBase\0csAGrpMsk\0csBGrpMsk\0csCGrpMsk\0csDGrpMsk\0";\
    print "csASel0\0csASel1\0csASel2\0csASel3\0csBSel0\0csBSel1\0";\
    print "csBSel2\0csBSel3\0csCSel0\0csCSel1\0csCSel2\0csCSel3\0";\
    print "csDSel0\0csDSel1\0csDSel2\0csDSel3\0pllCtrl\0pllFreqSel\0";\
    print "pwrCtrl\0intVec\0iCtrl\0iMask\0iWakeupEn\0iStat\0iPending\0pADir\0";\
    print "pAData\0pASel\0pBDir\0pBData\0pBSel\0pCDir\0pCData\0pCSel\0";\
    print "pDDir\0pDData\0pDPullupEn\0pDPolarity\0pDIntReqEn\0pDIntEdge\0";\
    print "pEDir\0pEData\0pEPullupEn\0pESel\0pFDir\0pFData\0pFPullupEn\0";\
    print "pFSel\0pGDir\0pGData\0pGPullupEn\0pGSel\0pJDir\0pJData\0pJSel\0";\
    print "pKDir\0pKData\0pKPullupEn\0pKSel\0pMDir\0pMData\0pMPullupEn\0";\
    print "pMSel\0pwmCtrl\0pwmPer\0pwmWdt\0pwmCnt\0tmr1Ctrl\0tmr1Prescal\0";\
    print "tmr1Cmp\0tmr1Cap\0tmr1Cnt\0tmr1Stat\0tmr2Ctrl\0tmr2Prescal\0";\
    print "tmr2Cmp\0tmr2Cap\0tmr2Cnt\0tmr2Stat\0wdCtrl\0wdRef\0wdCnt\0";\
    print "spiSlave\0spiMstrData\0spiMstrCtrl\0uCtrl\0uBaud\0uRx\0uTx\0";\
    print "uMisc\0lcdStartAddr\0lcdPgWdt\0lcdScrWdt\0lcdScrHgt\0lcdCurXPos\0";\
    print "lcdCurYPos\0lcdCurWH\0lcdBlinkCtrl\0lcdPanelCtrl\0lcdPolarity\0";\
    print "lcdACDRate\0lcdPixelClock\0lcdClockCtrl\0lcdLastBufAddr\0";\
    print "lcdOctTermCnt\0lcdPanOffset\0lcdFrmRate\0lcdGrayPal\0rtcHMS\0";\
    print "rtcAlarm\0rtcCtrl\0rtcIntStat\0rtcIntEnable\0stopWatch\0";\
    ' > m68328Hwr_massaged.data
	echo -ne "\0\0" >> m68328Hwr_massaged.data


systraps_massaged.data:
	$(PERL) -ne 'if (m/sysTrap(\S+)\s*,.*$$/) { print "$$1\0"; }' \
	    < $(SYSTRAP_H) > systraps_massaged.data
	echo -ne "\0\0" >> systraps_massaged.data
	
bin.res: $(TARGET).rcp $(TARGET).pbm systraps_massaged.data m68328Hwr_massaged.data
	cp systraps_massaged.data tSTR4000.bin
	cp m68328Hwr_massaged.data tSTR4001.bin
	$(PILRC) $(TARGET).rcp .
	touch bin.res

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) -o $(TARGET) $(LIBS)

send: $(TARGET).prc
	$(PILOTXFER) -i $(TARGET).prc

debug:
	m68k-palmos-coff-gdb $(TARGET)

depend:
	makedepend -Y -I. *.c

clean:
	-rm -f *.[oa] $(TARGET) *.bin bin.res *.grc Makefile.bak

veryclean: clean
	-rm -f $(TARGET).prc pilot.ram pilot.scratch

