rules.mk 16 KB

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