rules.mk 17 KB

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