rules.mk
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
MCU = msp430g2553
CC = msp430-gcc
OBJCOPY = msp430-objcopy
SIZE = msp430-size
MSPDEBUG = mspdebug
MSP430FLASHER = MSP430Flasher
EMBUILDER = #em-builder
COPTS = -Os -Wall -fno-strict-aliasing -c -g -mmcu=$(MCU)
LDOPTS = -mmcu=$(MCU) -Wl,-Map=main.map
EMSOUT = $(SCHEMA)/out
RMFILES = *.out *.map *.hex *.obj
CFLAGS = -I$(COMMON) -I$(EMSOUT) $(COPTS)
LDFLAGS = $(LDOPTS)
VPATH = $(COMMON)
OUTFILE = main.out
all: $(OUTFILE)
ifeq (,$(findstring Windows,$(OS)))
load: out-check
$(MSPDEBUG) rf2500 "prog $(OUTFILE)" 2>&1
else
load: $(OUTFILE:.out=.hex)
$(MSP430FLASHER) -i USB -m AUTO -e ERASE_MAIN -n $(MCU) -w $< -v -z [VCC] -g
endif
$(OUTFILE): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^
$(SIZE) $@
%.hex: out-check
$(OBJCOPY) -O ihex $(@:.hex=.out) $@
%.obj: %.c $(EMSOUT)/$(EMSNAME).h
$(CC) $(CFLAGS) -o $@ $<
$(EMSNAME).obj: $(EMSOUT)/$(EMSNAME).c $(EMSOUT)/$(EMSNAME).h
$(CC) $(CFLAGS) -o $@ $<
$(EMSOUT)/$(EMSNAME).h: $(SCHEMA)/schema.ems
$(EMBUILDER) -v --root=$(<D) $<
local-clean:
ifeq (,$(findstring Windows,$(OS)))
rm -f $(RMFILES)
else
ifneq (,$(wildcard $(RMFILES)))
cmd /c del /q $(wildcard $(RMFILES))
endif
endif
clean: local-clean
ifeq (,$(findstring Windows,$(OS)))
rm -rf $(EMSOUT)
else
ifneq (,$(wildcard $(EMSOUT)))
cmd /c rmdir /q /s $(subst /,\,$(EMSOUT))
endif
endif
out-check:
ifeq (,$(wildcard $(OUTFILE)))
@echo error: $(OUTFILE): No such file or directory 1>&2
@exit 1
endif
.PHONY: all load clean local-clean out-check