-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
87 lines (66 loc) · 2.53 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
ifeq ($(OS),Windows_NT) # Windows tools
PATH:=C:/tools/msys64/mingw32/bin:${PATH}
RMDIR = -cmd /C rd /S /Q # Ignore "cannot find the file" error
EXEC = .exe
else # POSIX tools
RMDIR = rm -rf
EXEC =
endif
# Add all subdirectories 1 level deep into make search path
VPATH = $(wildcard ./*/)
# Compile all .c files in directories
SRCFILES := $(wildcard ./*/*.c)
# File that has the main() function
MAINFILE := core/main.c
#
PROGRAMMER := python3 ../RTDMultiProg/rtdmultiprog.py -i i2cdev -d 2 -w
# Native compiler
ifeq ($(OS),Windows_NT) # Windows tools
NATIVE_PKGCFG =
NATIVE_CC = gcc
NATIVE_CFLAGS = -I. -MMD -ggdb3
NATIVE_LDFLAGS = -Lcore -lch341
NATIVE_OUTPUTDIR = output_native
else
NATIVE_PKGCFG = pkg-config
NATIVE_CC = gcc
NATIVE_CFLAGS = -I. -MMD -ggdb3 $(shell $(NATIVE_PKGCFG) --cflags python3-embed)
NATIVE_LDFLAGS = $(shell $(NATIVE_PKGCFG) --libs python3-embed)
NATIVE_OUTPUTDIR = output_native
endif
NATIVE_OBJFILES := $(addprefix $(NATIVE_OUTPUTDIR)/, $(notdir $(SRCFILES:.c=.o)))
NATIVE_DFILES := $(addprefix $(NATIVE_OUTPUTDIR)/, $(notdir $(SRCFILES:.c=.d)))
native: $(NATIVE_OUTPUTDIR) $(NATIVE_OUTPUTDIR)/native$(EXEC)
$(NATIVE_OUTPUTDIR):
mkdir $(NATIVE_OUTPUTDIR)
$(NATIVE_OUTPUTDIR)/native$(EXEC): $(NATIVE_OBJFILES)
$(NATIVE_CC) $^ $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) -o $@
$(NATIVE_OUTPUTDIR)/%.o: %.c
$(NATIVE_CC) $< $(NATIVE_CFLAGS) -o $@ -c
# Firmware compiler
SDCC_CC = sdcc
SDCC_CFLAGS = -I. -MMD --model-large --stack-auto
SDCC_LDFLAGS = --xram-loc 0xFB00 --xram-size 640
SDCC_OUTPUTDIR = output
# Remove _.c files
SDCC_SRCFILES := $(filter-out %_.c, $(SRCFILES))
SDCC_RELFILES := $(addprefix $(SDCC_OUTPUTDIR)/, $(notdir $(SDCC_SRCFILES:.c=.rel)))
SDCC_DFILES := $(addprefix $(SDCC_OUTPUTDIR)/, $(notdir $(SDCC_SRCFILES:.c=.d)))
firmware: $(SDCC_OUTPUTDIR) $(SDCC_OUTPUTDIR)/firmware.bin
$(SDCC_OUTPUTDIR):
mkdir $(SDCC_OUTPUTDIR)
$(SDCC_OUTPUTDIR)/firmware.hex: $(SDCC_RELFILES)
$(SDCC_CC) $^ $(SDCC_CFLAGS) $(SDCC_LDFLAGS) -o $@
$(SDCC_OUTPUTDIR)/firmware.bin: $(SDCC_OUTPUTDIR)/firmware.hex
makebin $(SDCC_OUTPUTDIR)/firmware.hex $(SDCC_OUTPUTDIR)/firmware.bin
$(SDCC_OUTPUTDIR)/%.rel: %.c
$(SDCC_CC) -o $@ -c $(SDCC_CFLAGS) $<
all: native firmware
program: $(SDCC_OUTPUTDIR)/firmware.bin
$(PROGRAMMER) "$(CURDIR)/$(SDCC_OUTPUTDIR)/firmware.bin"
clean:
$(RMDIR) $(NATIVE_OUTPUTDIR)
$(RMDIR) $(SDCC_OUTPUTDIR)
# Include dependency target files
-include $(NATIVE_DFILES)
-include $(SDCC_DFILES)