4a3721886c96ab8719529632fd3b44d2859d5657
[uccvend-snackrom.git] / ROM2 / Makefile
1 # muchly stolen from m68hc1x's example.tar.gz's Makefile
2
3 OBJS = \
4         motors.o keypad.o display_basic.o coinmech.o chime.o \
5         helpers.o main_basic.o sci.o \
6         vectors.o start.o romsrc.o xmodem.o
7 INCLUDES = vend.h keypad.h chime.h asm.h display_basic.h ports.h types.h
8 # debugging doesn't get compiled into the ROM image
9 CFLAGS = -m68hc11 -mshort -Wall -O1 \
10         -msoft-reg-count=0 -ffixed-z -g -fomit-frame-pointer
11
12 LDFLAGS = -m68hc11 -mshort -Wl,-m,m68hc11elfb \
13           -nostartfiles \
14           -Wl,-defsym,_io_ports=0x1000 \
15           -Wl,-defsym,_switch_input=0x1800 \
16           -Wl,-defsym,_misc_input=0x2000 \
17           -Wl,-defsym,_home_sensors=0x2800 \
18           -Wl,-defsym,_changer_output=0x3000 \
19           -Wl,-defsym,_misc_output=0x3800 \
20           -Wl,-defsym,_uart_regs=0x4000
21
22 OBJCOPY_FLAGS=--only-section=.text \
23               --only-section=.rodata \
24               --only-section=.vectors \
25               --only-section=.data
26
27
28 DEVC_PREFIX = m68hc11-
29 CC = $(DEVC_PREFIX)gcc
30 AS = $(DEVC_PREFIX)as
31 AR = $(DEVC_PREFIX)ar
32 SIZE = $(DEVC_PREFIX)size
33 OBJCOPY = $(DEVC_PREFIX)objcopy
34 OBJDUMP = $(DEVC_PREFIX)objdump
35 LD = $(DEVC_PREFIX)ld
36
37 all: rom2.b rom2.elf rom2.s19
38
39 rom2.elf: $(OBJS) memory.x check-romsrc.pl
40         $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBADD)
41         $(SIZE) $@
42         @perl -w check-romsrc.pl
43
44 clean:
45         rm -f *.o *.elf *.s19 *.b *.a rom.tar.bz2 romsrc.s crctab.h m68hc11-gdb gencrctab
46
47 #
48 # Some useful rules
49 #
50 dump:   rom2.elf
51         $(OBJDUMP) -d $<
52
53 size:   rom2.s19
54         $(SIZE) $<
55
56 rom.tar.bz2:
57         rm -f romsrc.s crctab.h
58         tar cjf rom.tar.bz2 README Makefile gdbsimrc *.pl *.c *.h *.s *.x
59
60 romsrc.s: rom.tar.bz2 src2asm.pl
61         perl -w src2asm.pl < $< > $@
62
63 xmodem.c: crctab.h
64
65 gencrctab: gencrctab.c
66         gcc -o $@ $<
67
68 crctab.h: gencrctab
69         ./gencrctab > $@
70
71 #
72 # Implicit rules
73 #
74 # .elf is for the simulator and gdb
75 # .s19 is for some downloader and the simulator
76 # .b   is a binary dump
77 #
78 .SUFFIXES: .elf .s19 .b
79
80 .elf.s19:
81         $(OBJCOPY) --output-target=srec $(OBJCOPY_FLAGS) $< $*.s19
82
83 .elf.b:
84         $(OBJCOPY) --output-target=binary --gap-fill=255 \
85                    $(OBJCOPY_FLAGS) $< $*.b
86         @perl -e '$$sum = 0;while(read STDIN, $$a, 1){$$sum += ord($$a); $$sum = $$sum&0xffff;} printf "Checksum is \%x\n", $$sum' < $@
87
88 m68hc11-gdb: /usr/bin/m68hc11-gdb
89         sed -e 's|m68hc11eepr/reg 0xb000 512|m68hc11eepr/reg 0x4000 1  |' < $< > $@
90         chmod 755 $@
91         
92 sim: m68hc11-gdb rom2.elf
93         ./m68hc11-gdb -x gdbsimrc rom2.elf

UCC git Repository :: git.ucc.asn.au