-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
147 lines (110 loc) · 3.48 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Needed for both dfu-suffix and compilation
USB_VID ?= 0x1608
USB_PID ?= 0x154f
# Bootloader takes up first 2 kB
CODE_OFFSET = 0x800
# Toolchain
AS = sdas8051
AR = sdar8051
LD = sdld
CC = sdcc
CPP = sdcpp
# Toolchain flags
ASFLAGS = -pwg
CFLAGS = -mmcs51 --Werror --fomit-frame-pointer --fverbose-asm --code-loc $(CODE_OFFSET)
# Sources
C_FILES = $(wildcard *.c)
S_FILES = $(wildcard *.S)
# Stuff for bindist
LICENSE = LICENSES/GPL-3.0-or-later.txt
README = README.md
# Generated files
BINDIST = wpan_fw.tar.gz
DEP_FILES = $(C_FILES:.c=.d)
I_FILES = $(C_FILES:.c=.i)
ASM_FILES = $(C_FILES:.c=.asm) $(S_FILES:.S=.asm)
LST_FILES = $(ASM_FILES:.asm=.lst)
REL_FILES = $(ASM_FILES:.asm=.rel)
SYM_FILES = $(ASM_FILES:.asm=.sym)
MAP_FILES = $(ASM_FILES:.asm=.map)
MEM_FILES = $(ASM_FILES:.asm=.mem)
RST_FILES = $(ASM_FILES:.asm=.rst)
LST_FILES = $(ASM_FILES:.asm=.lst)
UPLOADED_BIN = uploaded.bin
FW_BIN = wpan_fw.bin
FW_IHX = $(FW_BIN:.bin=.ihx)
FW_DFU = $(FW_BIN:.bin=.dfu)
FW_MEM = $(FW_BIN:.bin=.mem)
LK_FILES = $(FW_BIN:.bin=.lk)
GENERATED = $(DEP_FILES) $(I_FILES) $(ASM_FILES) $(LST_FILES) $(REL_FILES) \
$(SYM_FILES) $(MAP_FILES) $(MEM_FILES) $(RST_FILES) \
$(LST_FILES) $(FW_IHX) $(FW_BIN) $(FW_DFU) $(FW_MEM) \
$(LK_FILES) $(UPLOADED_BIN) $(BINDIST)
# Version tag
TAG_COMMIT = $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG = $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT = $(shell git rev-parse --short HEAD)
DATE = $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
VERSION = $(TAG:v%=%)
VERSION_PARTS := $(subst ., ,$(VERSION))
VERSION_MAJOR := $(word 1, $(VERSION_PARTS))
VERSION_MINOR := $(word 2, $(VERSION_PARTS))
ifneq ($(COMMIT),$(TAG_COMMIT))
VERSION := $(VERSION)-next-$(COMMIT)-$(DATE)
endif
ifeq ($(VERSION),"")
VERSION := $(COMMIT)-$(DATE)
endif
ifneq ($(shell git status --porcelain -uno),)
VERSION := $(VERSION)-dirty
endif
CPPFLAGS += -DGIT_VERSION_STR="\"$(VERSION)\""
CPPFLAGS += -DGIT_VERSION_MAJOR=$(VERSION_MAJOR)
CPPFLAGS += -DGIT_VERSION_MINOR=$(VERSION_MINOR)
CPPFLAGS += -DUSB_PID=$(USB_PID)
CPPFLAGS += -DUSB_VID=$(USB_VID)
CPPFLAGS += -DCODE_OFFSET=$(CODE_OFFSET)
all: info $(FW_DFU)
bindist: $(BINDIST)
$(BINDIST): $(FW_DFU) $(LICENSE) $(README)
tar -cvz -f $@ $^
clean:
rm -f $(GENERATED)
info: $(FW_MEM)
cat $(FW_MEM)
download_all: $(FW_DFU) info
sh dfu_all.sh dfu-util -D $< -R
download: $(FW_DFU) info
dfu-util -D $< -R
%.dfu: %.bin
cp $< $@.tmp
dfu-suffix -v $(USB_VID) -p $(USB_PID) --add $@.tmp
mv $@.tmp $@
upload:
rm -f $(UPLOADED_BIN)
dfu-util -U $(UPLOADED_BIN) -R
flash: $(FW_BIN)
# My own hacked-together ESP32 based flasher
ccflash write --erase --reset --verify $<
%.bin: %.ihx
objcopy --input-target=ihex --output-target=binary $< $@
$(FW_IHX) $(FW_MEM) $(RST_FILES): $(REL_FILES) $(LST_FILES)
$(CC) -V $(CFLAGS) -o $(FW_IHX) $(REL_FILES)
%.i: %.c
$(CC) -E $(CPPFLAGS) $(CFLAGS) $< > $@
%.asm: %.S
$(CPP) -P $(CPPFLAGS) $< -o $@
%.asm: %.c
$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $@
%.rel: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
%.rel: %.asm %.lst
$(AS) $(ASFLAGS) -o $@ $<
%.lst: %.asm
$(AS) $(ASFLAGS) -l $@ $<
%.sym: %.asm
$(AS) $(ASFLAGS) -s $@ $<
%.d: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -MM $< >$@
.PHONY: all clean info download_all download upload bindist
-include $(DEP_FILES)