remove a bash-ism from a Makefile
[fx2lib.git] / lib / fx2.mk
blob501040faaa82583ad8d23e8207d976c3856e6a2e
1 # common make targets for compiling fx2 firmware
3 # In your Makefile, define:
4 # SOURCES: list of c files to compile
5 # A51_SOURCES: list of any a51 files.
6 # DEPS: list of any depedancies (like auto-generated header files) that need
7 # generated prior to compiling. You must provide the target definition
8 # for any DEPS you define.
9 # BASENAME: name of your firmware file, i.e., myfirmware, but not myfirmware.c
11 # Leave these alone or redefine as necessary to customize firmware.
12 # (Redefine after including this makefile)
13 # VID vendor id
14 # PID product id
15 # LIBS optional additional libraries to link with the firmware.
16 # SDCC build/link options
17 # CODE_SIZE: Default --code-size 0x3c00
18 # XRAM_SIZE: Default --xram-size 0x0200
19 # XRAM_LOC: Default --xram-loc 0x3c00
20 # BUILDDIR: build directory (default build)
21 # These two can be changed to be blank if no device descriptor is being used.
22 # DSCR_AREA: Default -Wl"-b DSCR_AREA=0x3e00"
23 # INT2JT: Default -Wl"-b INT2JT=0x3f00"
25 # Provided targets:
27 # default target: creates $(BASENAME).ihx
28 # bix: creates $(BASENAME).bix
29 # iic: creates $(BASENAME).iic
30 # load: uses fx2load to load firmware.bix onto the development board
31 # (You can customize VID/PID if you need to load the firmware onto a device that has different vendor and product id
32 # The default is 0x04b4, 0x8613
33 # clean: delete all the temp files.
38 AS8051?=sdas8051
40 VID?=0x04b4
41 PID?=0x8613
43 INCLUDES?=""
44 DSCR_AREA?=-Wl"-b DSCR_AREA=0x3e00"
45 INT2JT?=-Wl"-b INT2JT=0x3f00"
46 CC=sdcc
47 # these are pretty good settings for most firmwares.
48 # Have to be careful with memory locations for
49 # firmwares that require more xram etc.
50 CODE_SIZE?=--code-size 0x3c00
51 XRAM_SIZE?=--xram-size 0x0200
52 XRAM_LOC?=--xram-loc 0x3c00
53 BUILDDIR?=build
55 FX2LIBDIR?=$(dir $(lastword $(MAKEFILE_LIST)))../
57 RELS=$(addprefix $(BUILDDIR)/, $(addsuffix .rel, $(notdir $(basename $(SOURCES) $(A51_SOURCES)))))
59 LINKFLAGS=$(CODE_SIZE) \
60 $(XRAM_SIZE) \
61 $(XRAM_LOC) \
62 $(DSCR_AREA) \
63 $(INT2JT)
66 .PHONY: all ihx iic bix load clean clean-all
68 all: ihx
69 ihx: $(BUILDDIR)/$(BASENAME).ihx
70 bix: $(BUILDDIR)/$(BASENAME).bix
71 iic: $(BUILDDIR)/$(BASENAME).iic
73 $(FX2LIBDIR)/lib/fx2.lib: $(FX2LIBDIR)/lib/*.c $(FX2LIBDIR)/lib/*.a51
74 $(MAKE) -C $(FX2LIBDIR)/lib
76 $(BUILDDIR):
77 mkdir -p $(BUILDDIR)
79 $(BUILDDIR)/$(BASENAME).ihx: $(BUILDDIR) $(RELS) $(FX2LIBDIR)/lib/fx2.lib $(DEPS)
80 $(CC) -mmcs51 $(SDCCFLAGS) -o $@ $(RELS) fx2.lib $(LINKFLAGS) -L $(FX2LIBDIR)/lib $(LIBS)
82 %.rel: ../%.c
83 $(CC) -mmcs51 $(SDCCFLAGS) -c -o $@ -I $(FX2LIBDIR)/include -I $(INCLUDES) $<
85 %.rel: ../%.a51
86 $(AS8051) -logs $@ $<
89 $(BUILDDIR)/$(BASENAME).bix: $(BUILDDIR)/$(BASENAME).ihx
90 objcopy -I ihex -O binary $< $@
91 $(BUILDDIR)/$(BASENAME).iic: $(BUILDDIR)/$(BASENAME).ihx
92 $(FX2LIBDIR)/utils/ihx2iic.py -v $(VID) -p $(PID) $< $@
94 load: $(BUILDDIR)/$(BASENAME).bix
95 fx2load -v $(VID) -p $(PID) $(BUILDDIR)/$(BASENAME).bix
97 clean:
98 rm -f $(foreach ext, a51 asm ihx lnk lk lst map mem rel rst rest sym adb cdb bix, $(BUILDDIR)/*.${ext})
100 clean-all: clean
101 $(MAKE) -C $(FX2LIBDIR)/lib clean