This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
215 lines (149 loc) · 5.19 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# *************************************************************************************************
# Includes
include Common.mk
# *************************************************************************************************
# Variables
OUTDIR = build
SUBDIRS = config core drivers modules
PYTHON := $(shell which python2 || which python)
BASH := $(shell which bash || which bash)
# *************************************************************************************************
# Utils
COLS =`tput cols`
PAD = $(shell expr $(COLS) - 6)
# Colors
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
NORMAL=`tput sgr0`
# Macro to display compilation error message
CHECK_ERRORS = @if test -e tmp.errors; \
then printf "$(RED)[ERR]$(NORMAL)\n"; \
elif test -s tmp.log; \
then printf "$(YELLOW)[WARN]$(NORMAL)\n"; \
else printf "$(GREEN)[OK]$(NORMAL)\n" ; fi; \
cat tmp.log >> Build.log; \
rm -f tmp.errors; \
rm -f tmp.log;
# *************************************************************************************************
# Targets
.PHONY: all
.PHONY: clear
.PHONY: clean
.PHONY: config
.PHONY: install
.PHONY: run
.PHONY: debug
.PHONY: depend
.PHONY: force
.PHONY: doc
.PHONY: latexdoc
# *************************************************************************************************
# Build list of sources and objects to build
SRCS := $(wildcard *.c)
$(foreach subdir, $(SUBDIRS), \
$(eval SRCS := $(SRCS) $(wildcard $(subdir)/*.c)) \
)
OBJS := $(patsubst %.c, build/%.o, $(SRCS))
# *************************************************************************************************
# Append specific CFLAGS/LDFLAGS
ifneq ($(wildcard config/config.h), )
DEBUG := $(shell grep "^\#define CONFIG_DEBUG" config/config.h)
ifeq ($(DEBUG),)
TARGET := RELEASE
CFLAGS += $(CFLAGS_REL)
LDFLAGS += $(LDFLAGS_REL)
else
TARGET := DEBUG
CFLAGS += $(CFLAGS_DBG)
LDFLAGS += $(LDFLAGS_DBG)
MEMPYFLAGS := -d
endif
endif
# *************************************************************************************************
# Main rule
all: required depend $(OUTDIR)/openchronos.txt
# *************************************************************************************************
# Required files rules
required: config/config.h config/rtca_now.h $(OUTDIR)/config/modinit.o
config/modinit.c:
@echo "Please do a 'make config' first!" && false
config/config.h:
@echo "Please do a 'make config' first!" && false
# *************************************************************************************************
# Dependencies rules
depend: Dependencies.mk
Dependencies.mk: $(SRCS)
@printf "%-${PAD}s" "(GEN) Checking dependencies..."
@touch $@
@makedepend $(INCLUDES) -Y -f $@ -- $(CFLAGS) $^ 2> tmp.log || touch tmp.errors
$(CHECK_ERRORS)
@rm -f [email protected]
ifneq ($(wildcard Dependencies.mk), )
include Dependencies.mk
endif
# *************************************************************************************************
# Rebuild if CFLAGS changed
# (use the .cflags file to store the last CFLAGS)
config/openchronos.cflags: force
@echo "$(CFLAGS)" | cmp -s - $@ || echo "$(CFLAGS)" > $@
$(OBJS): config/openchronos.cflags
# *************************************************************************************************
# Basic rules
$(OUTDIR)/%.o: %.c
@mkdir -p $(dir $@)
@printf "%-${PAD}s" "(CC) $<"
@$(CC) $(CFLAGS) $(SPEC_FLAGS) $(INCLUDES) -c $< -o $@ 2>> tmp.log || touch tmp.errors
$(CHECK_ERRORS)
# *************************************************************************************************
# Rebuild all every time because system time changed
config/rtca_now.h: force
@printf "(GEN) $@\n"
@$(BASH) ./tools/update_rtca_now.sh
$(OBJS): config/rtca_now.h
# *************************************************************************************************
# Specific rules
$(OUTDIR)/openchronos.elf: $(OUTDIR)/core/even_in_range.o $(OBJS)
@printf "\n%-${PAD}s" "Building $@ as target $(TARGET)..."
@$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) -o $@ $+ 2>> tmp.log || touch tmp.errors
$(CHECK_ERRORS)
@rm -f output.map
$(OUTDIR)/openchronos.txt: $(OUTDIR)/openchronos.elf
@$(PYTHON) tools/firmware/memory.py -i $< -o $@ $(MEMPYFLAGS)
$(OUTDIR)/core/even_in_range.o: core/even_in_range.s
@mkdir -p $(dir $@)
@printf "%-${PAD}s" "(CC) $<"
@$(AS) -c $< -o $@ 2>> tmp.log || touch tmp.errors
$(CHECK_ERRORS)
$(OUTDIR)/config/modinit.o: SPEC_FLAGS = -Wno-implicit-function-declaration
# *************************************************************************************************
# Top rules
config:
@mkdir -p config
@$(PYTHON) tools/config/config.py
@$(PYTHON) tools/config/make_modinit.py
install: $(OUTDIR)/openchronos.txt
ifeq ($(method), usb)
@echo "Installing the new firmware via USB..."
mspdebug rf2500 "prog $(OUTDIR)/openchronos.elf"
else
@echo "Installing the new firmware via RF..."
sudo $(PYTHON) contrib/ChronosTool.py rfbsl $<
endif
clear: clean
@rm -Rf ./config/
clean:
@rm -Rf ./$(OUTDIR)/
@rm -f Dependencies.mk Build.log
debug:
@echo "Starting mspdebug..."
mspdebug rf2500 gdb
run:
@echo "Running the firmware using mspdebug..."
mspdebug rf2500 run
doc:
@rm -Rf doc
@mkdir -p doc
doxygen Doxyfile
latexdoc: doc
@make -f .doc/latex/Makefile pdf