-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
83 lines (63 loc) · 1.99 KB
/
Makefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
PROJECT = nrf24le1-bme280
TARGET = _target_sdcc_nrf24le1_32
MEMORYMODEL = --model-large
HEX2BIN = ../hex2bin/hex2bin
SDCC = sdcc
BUILD := build
OBJDIR := $(BUILD)/obj
DEPDIR := $(BUILD)/dep
SOURCES := $(wildcard *.c)
SRCFILES := $(subst main.c,,$(SOURCES))
DEPFILES := $(subst .c,.d,$(addprefix $(DEPDIR)/,$(SRCFILES)))
DEPFILES += $(DEPDIR)/main.d
OBJFILES := $(SRCFILES:.c=.rel)
OBJFILES := $(addprefix $(OBJDIR)/,$(OBJFILES))
LDSDCC = -L/usr/local/share/sdcc/lib/large -lmcs51 -llibsdcc
LDNRF = -Lsdk/$(TARGET)/lib -lnrf24le1
LIBNRF = sdk/$(TARGET)/lib/nrf24le1.lib
CCFLAGS=--model-large --std-c99 --opt-code-size -Isdk/include -Isdk/$(TARGET)/include/
LDFLAGS=--code-loc 0x0000 --code-size 0x4000 --xram-loc 0x0000 --xram-size 0x400 $(LDSDCC) $(LDNRF)
PROJECTBIN = $(BUILD)/$(PROJECT).bin
CRC8CALC = tools/crc8calc
all: $(LIBNRF) $(PROJECTBIN)
-include $(DEPFILES)
$(OBJDIR)/%.rel : %.c $(DEPFILES)
@echo
@echo "Building object file '$@'"
[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR) > /dev/null
$(SDCC) -c $(CCFLAGS) $< -o $(OBJDIR)/
@echo "Finished building object file '$@'"
$(BUILD)/$(PROJECT).ihx : $(OBJFILES)
@echo
@echo "Building hex file '$@'"
$(SDCC) $(CCFLAGS) $(OBJFILES) main.c -o $@ $(LDFLAGS)
@echo "Finished building hex file '$@'"
$(BUILD)/%.bin: $(BUILD)/%.ihx
@echo
@echo "Building binary file '$@'"
$(HEX2BIN) -p 00 $@ $^
@echo "Finished building binary file '$@'"
# copy to home
cp -vf $(PROJECTBIN) ~/
$(LIBNRF):
make -C sdk all
$(DEPDIR)/%.d: %.c %.h
@echo
@echo "Building dependency file '$@'"
[ -d $(DEPDIR) ] || mkdir -p $(DEPDIR) > /dev/null
$(SDCC) -MM $(CCFLAGS) $< >> [email protected]
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < [email protected] > $@
rm -f [email protected]
@echo "Finished building dependency file '$@'"
tools: tools/crc8calc
tools/crc8calc : tools/crc8calc.c
@echo
@echo "Building '$@'"
gcc $< -o $@
@echo "Finished building '$@'"
clean:
rm -rf $(BUILD)/* && rmdir $(BUILD)
cleanall:
rm -rf $(BUILD)/* && rmdir $(BUILD)
make -C sdk clean
.PHONY: all clean cleanall tools