diff options
author | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
commit | dc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch) | |
tree | 4ccb8fa5886b66fa9d480edef74236c27f035e16 /tmk_core/rules.mk |
Diffstat (limited to 'tmk_core/rules.mk')
-rw-r--r-- | tmk_core/rules.mk | 524 |
1 files changed, 524 insertions, 0 deletions
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk new file mode 100644 index 000000000..6767a8e4a --- /dev/null +++ b/tmk_core/rules.mk | |||
@@ -0,0 +1,524 @@ | |||
1 | # Hey Emacs, this is a -*- makefile -*- | ||
2 | #---------------------------------------------------------------------------- | ||
3 | # WinAVR Makefile Template written by Eric B. Weddington, Jg Wunsch, et al. | ||
4 | # | ||
5 | # Released to the Public Domain | ||
6 | # | ||
7 | # Additional material for this makefile was written by: | ||
8 | # Peter Fleury | ||
9 | # Tim Henigan | ||
10 | # Colin O'Flynn | ||
11 | # Reiner Patommel | ||
12 | # Markus Pfaff | ||
13 | # Sander Pool | ||
14 | # Frederik Rouleau | ||
15 | # Carlos Lamas | ||
16 | # | ||
17 | |||
18 | # Enable vpath seraching for source files only | ||
19 | # Without this, output files, could be read from the wrong .build directories | ||
20 | VPATH_SRC := $(VPATH) | ||
21 | vpath %.c $(VPATH_SRC) | ||
22 | vpath %.h $(VPATH_SRC) | ||
23 | vpath %.cpp $(VPATH_SRC) | ||
24 | vpath %.cc $(VPATH_SRC) | ||
25 | vpath %.hpp $(VPATH_SRC) | ||
26 | vpath %.S $(VPATH_SRC) | ||
27 | VPATH := | ||
28 | |||
29 | # Convert all SRC to OBJ | ||
30 | define OBJ_FROM_SRC | ||
31 | $(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$(patsubst %.clib,$1/%.a,$($1_SRC)))))) | ||
32 | endef | ||
33 | $(foreach OUTPUT,$(OUTPUTS),$(eval $(OUTPUT)_OBJ +=$(call OBJ_FROM_SRC,$(OUTPUT)))) | ||
34 | |||
35 | # Define a list of all objects | ||
36 | OBJ := $(foreach OUTPUT,$(OUTPUTS),$($(OUTPUT)_OBJ)) | ||
37 | NO_LTO_OBJ := $(filter %.a,$(OBJ)) | ||
38 | |||
39 | MASTER_OUTPUT := $(firstword $(OUTPUTS)) | ||
40 | |||
41 | |||
42 | |||
43 | # Output format. (can be srec, ihex, binary) | ||
44 | FORMAT = ihex | ||
45 | |||
46 | # Optimization level, can be [0, 1, 2, 3, s]. | ||
47 | # 0 = turn off optimization. s = optimize for size. | ||
48 | # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) | ||
49 | OPT ?= s | ||
50 | |||
51 | # Compiler flag to set the C Standard level. | ||
52 | # c89 = "ANSI" C | ||
53 | # gnu89 = c89 plus GCC extensions | ||
54 | # c99 = ISO C99 standard (not yet fully implemented) | ||
55 | # gnu99 = c99 plus GCC extensions | ||
56 | CSTANDARD = -std=gnu99 | ||
57 | |||
58 | |||
59 | # Place -D or -U options here for C sources | ||
60 | #CDEFS += | ||
61 | |||
62 | |||
63 | # Place -D or -U options here for ASM sources | ||
64 | #ADEFS += | ||
65 | |||
66 | |||
67 | # Place -D or -U options here for C++ sources | ||
68 | #CXXDEFS += -D__STDC_LIMIT_MACROS | ||
69 | #CXXDEFS += -D__STDC_CONSTANT_MACROS | ||
70 | #CXXDEFS += | ||
71 | |||
72 | # Speed up recompilations by opt-in usage of ccache | ||
73 | USE_CCACHE ?= no | ||
74 | ifneq ($(USE_CCACHE),no) | ||
75 | CC_PREFIX ?= ccache | ||
76 | endif | ||
77 | |||
78 | #---------------- Compiler Options C ---------------- | ||
79 | # -g*: generate debugging information | ||
80 | # -O*: optimization level | ||
81 | # -f...: tuning, see GCC manual and avr-libc documentation | ||
82 | # -Wall...: warning level | ||
83 | # -Wa,...: tell GCC to pass this to the assembler. | ||
84 | ifeq ($(strip $(LTO_ENABLE)), yes) | ||
85 | ifeq ($(PLATFORM),CHIBIOS) | ||
86 | $(info Enabling LTO on ChibiOS-targeting boards is known to have a high likelihood of failure.) | ||
87 | $(info If unsure, set LTO_ENABLE = no.) | ||
88 | endif | ||
89 | CDEFS += -flto | ||
90 | CDEFS += -DLTO_ENABLE | ||
91 | endif | ||
92 | |||
93 | DEBUG_ENABLE ?= yes | ||
94 | ifeq ($(strip $(SKIP_DEBUG_INFO)),yes) | ||
95 | DEBUG_ENABLE=no | ||
96 | endif | ||
97 | |||
98 | ifeq ($(strip $(DEBUG_ENABLE)),yes) | ||
99 | CFLAGS += -g$(DEBUG) | ||
100 | endif | ||
101 | CFLAGS += $(CDEFS) | ||
102 | CFLAGS += -O$(OPT) | ||
103 | # add color | ||
104 | ifeq ($(COLOR),true) | ||
105 | ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "") | ||
106 | CFLAGS+= -fdiagnostics-color | ||
107 | endif | ||
108 | endif | ||
109 | CFLAGS += -Wall | ||
110 | CFLAGS += -Wstrict-prototypes | ||
111 | ifneq ($(strip $(ALLOW_WARNINGS)), yes) | ||
112 | CFLAGS += -Werror | ||
113 | endif | ||
114 | #CFLAGS += -mshort-calls | ||
115 | #CFLAGS += -fno-unit-at-a-time | ||
116 | #CFLAGS += -Wundef | ||
117 | #CFLAGS += -Wunreachable-code | ||
118 | #CFLAGS += -Wsign-compare | ||
119 | CFLAGS += $(CSTANDARD) | ||
120 | |||
121 | # This fixes lots of keyboards linking errors but SHOULDN'T BE A FINAL SOLUTION | ||
122 | # Fixing of multiple variable definitions must be made. | ||
123 | CFLAGS += -fcommon | ||
124 | |||
125 | #---------------- Compiler Options C++ ---------------- | ||
126 | # -g*: generate debugging information | ||
127 | # -O*: optimization level | ||
128 | # -f...: tuning, see GCC manual and avr-libc documentation | ||
129 | # -Wall...: warning level | ||
130 | # -Wa,...: tell GCC to pass this to the assembler. | ||
131 | ifeq ($(strip $(DEBUG_ENABLE)),yes) | ||
132 | CXXFLAGS += -g$(DEBUG) | ||
133 | endif | ||
134 | CXXFLAGS += $(CXXDEFS) | ||
135 | CXXFLAGS += -O$(OPT) | ||
136 | # to supress "warning: only initialized variables can be placed into program memory area" | ||
137 | CXXFLAGS += -w | ||
138 | CXXFLAGS += -Wall | ||
139 | CXXFLAGS += -Wundef | ||
140 | |||
141 | ifneq ($(strip $(ALLOW_WARNINGS)), yes) | ||
142 | CXXFLAGS += -Werror | ||
143 | endif | ||
144 | #CXXFLAGS += -mshort-calls | ||
145 | #CXXFLAGS += -fno-unit-at-a-time | ||
146 | #CXXFLAGS += -Wstrict-prototypes | ||
147 | #CXXFLAGS += -Wunreachable-code | ||
148 | #CXXFLAGS += -Wsign-compare | ||
149 | #CXXFLAGS += $(CSTANDARD) | ||
150 | |||
151 | #---------------- Assembler Options ---------------- | ||
152 | ASFLAGS += $(ADEFS) | ||
153 | ifeq ($(VERBOSE_AS_CMD),yes) | ||
154 | ASFLAGS += -v | ||
155 | endif | ||
156 | |||
157 | #---------------- Library Options ---------------- | ||
158 | # Minimalistic printf version | ||
159 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min | ||
160 | |||
161 | # Floating point printf version (requires MATH_LIB = -lm below) | ||
162 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt | ||
163 | |||
164 | # If this is left blank, then it will use the Standard printf version. | ||
165 | PRINTF_LIB = | ||
166 | #PRINTF_LIB = $(PRINTF_LIB_MIN) | ||
167 | #PRINTF_LIB = $(PRINTF_LIB_FLOAT) | ||
168 | |||
169 | |||
170 | # Minimalistic scanf version | ||
171 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min | ||
172 | |||
173 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) | ||
174 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt | ||
175 | |||
176 | # If this is left blank, then it will use the Standard scanf version. | ||
177 | SCANF_LIB = | ||
178 | #SCANF_LIB = $(SCANF_LIB_MIN) | ||
179 | #SCANF_LIB = $(SCANF_LIB_FLOAT) | ||
180 | |||
181 | |||
182 | MATH_LIB = -lm | ||
183 | CREATE_MAP ?= yes | ||
184 | |||
185 | |||
186 | #---------------- Linker Options ---------------- | ||
187 | # -Wl,...: tell GCC to pass this to linker. | ||
188 | # -Map: create map file | ||
189 | # --cref: add cross reference to map file | ||
190 | # | ||
191 | # Comennt out "--relax" option to avoid a error such: | ||
192 | # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' | ||
193 | # | ||
194 | |||
195 | ifeq ($(CREATE_MAP),yes) | ||
196 | LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref | ||
197 | endif | ||
198 | ifeq ($(VERBOSE_LD_CMD),yes) | ||
199 | LDFLAGS += -v | ||
200 | endif | ||
201 | #LDFLAGS += -Wl,--relax | ||
202 | LDFLAGS += $(EXTMEMOPTS) | ||
203 | LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) | ||
204 | LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) | ||
205 | #LDFLAGS += -T linker_script.x | ||
206 | # You can give EXTRALDFLAGS at 'make' command line. | ||
207 | LDFLAGS += $(EXTRALDFLAGS) | ||
208 | |||
209 | #---------------- Assembler Listings ---------------- | ||
210 | # -Wa,...: tell GCC to pass this to the assembler. | ||
211 | # -adhlns: create listing | ||
212 | # -gstabs: have the assembler create line number information; note that | ||
213 | # for use in COFF files, additional information about filenames | ||
214 | # and function names needs to be present in the assembler source | ||
215 | # files -- see avr-libc docs [FIXME: not yet described there] | ||
216 | # -listing-cont-lines: Sets the maximum number of continuation lines of hex | ||
217 | # dump that will be displayed for a given single line of source input. | ||
218 | |||
219 | ADHLNS_ENABLE ?= no | ||
220 | ifeq ($(ADHLNS_ENABLE),yes) | ||
221 | # Avoid "Options to '-Xassembler' do not match" - only specify assembler options at LTO link time | ||
222 | ifeq ($(strip $(LTO_ENABLE)), yes) | ||
223 | LDFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(TARGET).lst | ||
224 | else | ||
225 | CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | ||
226 | CXXFLAGS += -Wa,-adhlns=$(@:%.o=%.lst) | ||
227 | ifeq ($(strip $(DEBUG_ENABLE)),yes) | ||
228 | ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 | ||
229 | else | ||
230 | ASFLAGS = -Wa,-adhlns=$(@:%.o=%.lst),--listing-cont-lines=100 | ||
231 | endif | ||
232 | endif | ||
233 | endif | ||
234 | |||
235 | # Define programs and commands. | ||
236 | SHELL = sh | ||
237 | REMOVE = rm -f | ||
238 | REMOVEDIR = rmdir | ||
239 | COPY = cp | ||
240 | WINSHELL = cmd | ||
241 | SECHO = $(SILENT) || echo | ||
242 | MD5SUM ?= md5sum | ||
243 | ifneq ($(filter Darwin FreeBSD,$(shell uname -s)),) | ||
244 | MD5SUM = md5 | ||
245 | endif | ||
246 | |||
247 | # UF2 format settings | ||
248 | # To produce a UF2 file in your build, add to your keyboard's rules.mk: | ||
249 | # FIRMWARE_FORMAT = uf2 | ||
250 | UF2CONV = $(TOP_DIR)/util/uf2conv.py | ||
251 | UF2_FAMILY ?= 0x0 | ||
252 | |||
253 | # Compiler flags to generate dependency files. | ||
254 | #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d | ||
255 | GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@) | ||
256 | |||
257 | |||
258 | # Combine all necessary flags and optional flags. | ||
259 | # Add target processor to flags. | ||
260 | # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar | ||
261 | ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS) | ||
262 | ALL_CXXFLAGS = $(MCUFLAGS) -x c++ $(CXXFLAGS) $(EXTRAFLAGS) | ||
263 | ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) | ||
264 | |||
265 | define NO_LTO | ||
266 | $(patsubst %.a,%.o,$1): NOLTO_CFLAGS += -fno-lto | ||
267 | endef | ||
268 | $(foreach LOBJ, $(NO_LTO_OBJ), $(eval $(call NO_LTO,$(LOBJ)))) | ||
269 | |||
270 | MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) | ||
271 | |||
272 | # For a ChibiOS build, ensure that the board files have the hook overrides injected | ||
273 | define BOARDSRC_INJECT_HOOKS | ||
274 | $(KEYBOARD_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): INIT_HOOK_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h | ||
275 | endef | ||
276 | $(foreach LOBJ, $(BOARDSRC), $(eval $(call BOARDSRC_INJECT_HOOKS,$(LOBJ)))) | ||
277 | |||
278 | # Add QMK specific flags | ||
279 | DFU_SUFFIX ?= dfu-suffix | ||
280 | DFU_SUFFIX_ARGS ?= | ||
281 | |||
282 | |||
283 | elf: $(BUILD_DIR)/$(TARGET).elf | ||
284 | hex: $(BUILD_DIR)/$(TARGET).hex | ||
285 | uf2: $(BUILD_DIR)/$(TARGET).uf2 | ||
286 | cpfirmware: $(FIRMWARE_FORMAT) | ||
287 | $(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to qmk_firmware folder" | $(AWK_CMD) | ||
288 | $(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK) | ||
289 | eep: $(BUILD_DIR)/$(TARGET).eep | ||
290 | lss: $(BUILD_DIR)/$(TARGET).lss | ||
291 | sym: $(BUILD_DIR)/$(TARGET).sym | ||
292 | LIBNAME=lib$(TARGET).a | ||
293 | lib: $(LIBNAME) | ||
294 | |||
295 | # Display size of file. | ||
296 | HEXSIZE = $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | ||
297 | #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf | ||
298 | ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf | ||
299 | |||
300 | sizebefore: | ||
301 | @if test -f $(BUILD_DIR)/$(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \ | ||
302 | 2>/dev/null; $(SECHO); fi | ||
303 | |||
304 | sizeafter: $(BUILD_DIR)/$(TARGET).hex | ||
305 | @if test -f $(BUILD_DIR)/$(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \ | ||
306 | 2>/dev/null; $(SECHO); fi | ||
307 | |||
308 | # Display compiler version information. | ||
309 | gccversion : | ||
310 | @$(SILENT) || $(CC) --version | ||
311 | |||
312 | # Create final output files (.hex, .eep) from ELF output file. | ||
313 | %.hex: %.elf | ||
314 | $(eval CMD=$(HEX) $< $@) | ||
315 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
316 | @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD) | ||
317 | @$(BUILD_CMD) | ||
318 | |||
319 | %.uf2: %.hex | ||
320 | $(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex -o $(BUILD_DIR)/$(TARGET).uf2 -c -f $(UF2_FAMILY) >/dev/null 2>&1) | ||
321 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
322 | @$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD) | ||
323 | @$(BUILD_CMD) | ||
324 | |||
325 | %.eep: %.elf | ||
326 | $(eval CMD=$(EEP) $< $@ || exit 0) | ||
327 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
328 | @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD) | ||
329 | @$(BUILD_CMD) | ||
330 | |||
331 | # Create extended listing file from ELF output file. | ||
332 | %.lss: %.elf | ||
333 | $(eval CMD=$(OBJDUMP) -h -S -z $< > $@) | ||
334 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
335 | @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD) | ||
336 | @$(BUILD_CMD) | ||
337 | |||
338 | # Create a symbol table from ELF output file. | ||
339 | %.sym: %.elf | ||
340 | $(eval CMD=$(NM) -n $< > $@ ) | ||
341 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
342 | @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD) | ||
343 | @$(BUILD_CMD) | ||
344 | |||
345 | %.bin: %.elf | ||
346 | $(eval CMD=$(BIN) $< $@ || exit 0) | ||
347 | #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" | ||
348 | @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD) | ||
349 | @$(BUILD_CMD) | ||
350 | if [ ! -z "$(DFU_SUFFIX_ARGS)" ]; then \ | ||
351 | $(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null ;\ | ||
352 | fi | ||
353 | #$(SILENT) || printf "$(MSG_EXECUTING) '$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null':\n" ;\ | ||
354 | $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin; | ||
355 | |||
356 | BEGIN = gccversion sizebefore | ||
357 | |||
358 | # Link: create ELF output file from object files. | ||
359 | .SECONDARY : $(BUILD_DIR)/$(TARGET).elf | ||
360 | .PRECIOUS : $(OBJ) | ||
361 | # Note the obj.txt depeendency is there to force linking if a source file is deleted | ||
362 | %.elf: $(OBJ) $(MASTER_OUTPUT)/cflags.txt $(MASTER_OUTPUT)/ldflags.txt $(MASTER_OUTPUT)/obj.txt | $(BEGIN) | ||
363 | @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) | ||
364 | $(eval CMD=MAKE=$(MAKE) $(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) | ||
365 | @$(BUILD_CMD) | ||
366 | |||
367 | |||
368 | define GEN_OBJRULE | ||
369 | $1_INCFLAGS := $$(patsubst %,-I%,$$($1_INC)) | ||
370 | ifdef $1_CONFIG | ||
371 | $1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) | ||
372 | endif | ||
373 | $1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) | ||
374 | $1_CXXFLAGS = $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) | ||
375 | $1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) | ||
376 | |||
377 | # Compile: create object files from C source files. | ||
378 | $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) | ||
379 | @mkdir -p $$(@D) | ||
380 | @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) | ||
381 | $$(eval CC_EXEC := $$(CC)) | ||
382 | ifneq ($$(VERBOSE_C_CMD),) | ||
383 | $$(if $$(filter $$(notdir $$(VERBOSE_C_CMD)),$$(notdir $$<)),$$(eval CC_EXEC += -v)) | ||
384 | endif | ||
385 | ifneq ($$(VERBOSE_C_INCLUDE),) | ||
386 | $$(if $$(filter $$(notdir $$(VERBOSE_C_INCLUDE)),$$(notdir $$<)),$$(eval CC_EXEC += -H)) | ||
387 | endif | ||
388 | $$(eval CMD := $$(CC_EXEC) -c $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | ||
389 | @$$(BUILD_CMD) | ||
390 | ifneq ($$(DUMP_C_MACROS),) | ||
391 | $$(eval CMD := $$(CC) -E -dM $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$<) | ||
392 | @$$(if $$(filter $$(notdir $$(DUMP_C_MACROS)),$$(notdir $$<)),$$(BUILD_CMD)) | ||
393 | endif | ||
394 | |||
395 | # Compile: create object files from C++ source files. | ||
396 | $1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) | ||
397 | @mkdir -p $$(@D) | ||
398 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) | ||
399 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | ||
400 | @$$(BUILD_CMD) | ||
401 | |||
402 | $1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) | ||
403 | @mkdir -p $$(@D) | ||
404 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) | ||
405 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | ||
406 | @$$(BUILD_CMD) | ||
407 | |||
408 | # Assemble: create object files from assembler source files. | ||
409 | $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN) | ||
410 | @mkdir -p $$(@D) | ||
411 | @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD) | ||
412 | $$(eval CMD=$$(CC) -c $$($1_ASFLAGS) $$< -o $$@) | ||
413 | @$$(BUILD_CMD) | ||
414 | |||
415 | $1/%.a : $1/%.o | ||
416 | @mkdir -p $$(@D) | ||
417 | @$(SILENT) || printf "Archiving: $$<" | $$(AWK_CMD) | ||
418 | $$(eval CMD=$$(AR) rcs $$@ $$<) | ||
419 | @$$(BUILD_CMD) | ||
420 | |||
421 | $1/force: | ||
422 | |||
423 | $1/cflags.txt: $1/force | ||
424 | echo '$$($1_CFLAGS)' | cmp -s - $$@ || echo '$$($1_CFLAGS)' > $$@ | ||
425 | |||
426 | $1/cxxflags.txt: $1/force | ||
427 | echo '$$($1_CXXFLAGS)' | cmp -s - $$@ || echo '$$($1_CXXFLAGS)' > $$@ | ||
428 | |||
429 | $1/asflags.txt: $1/force | ||
430 | echo '$$($1_ASFLAGS)' | cmp -s - $$@ || echo '$$($1_ASFLAGS)' > $$@ | ||
431 | |||
432 | $1/compiler.txt: $1/force | ||
433 | $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@ | ||
434 | endef | ||
435 | |||
436 | .PRECIOUS: $(MASTER_OUTPUT)/obj.txt | ||
437 | $(MASTER_OUTPUT)/obj.txt: $(MASTER_OUTPUT)/force | ||
438 | echo '$(OBJ)' | cmp -s - $@ || echo '$(OBJ)' > $@ | ||
439 | |||
440 | .PRECIOUS: $(MASTER_OUTPUT)/ldflags.txt | ||
441 | $(MASTER_OUTPUT)/ldflags.txt: $(MASTER_OUTPUT)/force | ||
442 | echo '$(LDFLAGS)' | cmp -s - $@ || echo '$(LDFLAGS)' > $@ | ||
443 | |||
444 | |||
445 | # We have to use static rules for the .d files for some reason | ||
446 | DEPS = $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ))) | ||
447 | # Keep the .d files | ||
448 | .PRECIOUS: $(DEPS) | ||
449 | # Empty rule to force recompilation if the .d file is missing | ||
450 | $(DEPS): | ||
451 | |||
452 | |||
453 | $(foreach OUTPUT,$(OUTPUTS),$(eval $(call GEN_OBJRULE,$(OUTPUT)))) | ||
454 | |||
455 | # Create preprocessed source for use in sending a bug report. | ||
456 | %.i : %.c | $(BEGIN) | ||
457 | $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ | ||
458 | |||
459 | # Target: clean project. | ||
460 | clean: | ||
461 | $(foreach OUTPUT,$(OUTPUTS), $(REMOVE) -r $(OUTPUT) 2>/dev/null) | ||
462 | $(REMOVE) $(BUILD_DIR)/$(TARGET).* | ||
463 | |||
464 | show_path: | ||
465 | @echo VPATH=$(VPATH) | ||
466 | @echo SRC=$(SRC) | ||
467 | @echo OBJ=$(OBJ) | ||
468 | |||
469 | dump_vars: ERROR_IF_EMPTY="" | ||
470 | dump_vars: ERROR_IF_NONBOOL="" | ||
471 | dump_vars: ERROR_IF_UNSET="" | ||
472 | dump_vars: | ||
473 | @$(foreach V,$(sort $(.VARIABLES)),$(if $(filter-out environment% default automatic,$(origin $V)),$(info $V=$($V)))) | ||
474 | |||
475 | objs-size: | ||
476 | for i in $(OBJ); do echo $$i; done | sort | xargs $(SIZE) | ||
477 | |||
478 | ifeq ($(findstring avr-gcc,$(CC)),avr-gcc) | ||
479 | SIZE_MARGIN = 1024 | ||
480 | |||
481 | check-size: | ||
482 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) | ||
483 | $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi)) | ||
484 | $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE))) | ||
485 | $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE))) | ||
486 | $(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE))) | ||
487 | if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \ | ||
488 | $(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \ | ||
489 | if [ $(CURRENT_SIZE) -gt $(MAX_SIZE) ]; then \ | ||
490 | printf "\n * $(MSG_FILE_TOO_BIG)"; $(PRINT_ERROR_PLAIN); \ | ||
491 | else \ | ||
492 | if [ $(FREE_SIZE) -lt $(SIZE_MARGIN) ]; then \ | ||
493 | $(PRINT_WARNING_PLAIN); printf " * $(MSG_FILE_NEAR_LIMIT)"; \ | ||
494 | else \ | ||
495 | $(PRINT_OK); $(SILENT) || printf " * $(MSG_FILE_JUST_RIGHT)"; \ | ||
496 | fi ; \ | ||
497 | fi ; \ | ||
498 | fi | ||
499 | else | ||
500 | check-size: | ||
501 | $(SILENT) || echo "$(MSG_CHECK_FILESIZE_SKIPPED)" | ||
502 | endif | ||
503 | |||
504 | check-md5: | ||
505 | $(MD5SUM) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) | ||
506 | |||
507 | # Create build directory | ||
508 | $(shell mkdir -p $(BUILD_DIR) 2>/dev/null) | ||
509 | |||
510 | # Create object files directory | ||
511 | $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null))) | ||
512 | |||
513 | # Include the dependency files. | ||
514 | -include $(patsubst %.o,%.d,$(patsubst %.a,%.o,$(OBJ))) | ||
515 | |||
516 | |||
517 | # Listing of phony targets. | ||
518 | .PHONY : all dump_vars finish sizebefore sizeafter qmkversion \ | ||
519 | gccversion build elf hex uf2 eep lss sym coff extcoff \ | ||
520 | clean clean_list debug gdb-config show_path \ | ||
521 | program teensy dfu dfu-ee dfu-start \ | ||
522 | flash dfu-split-left dfu-split-right \ | ||
523 | avrdude-split-left avrdude-split-right \ | ||
524 | avrdude-loop usbasp | ||