rules.mk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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 %.hpp $(VPATH_SRC)
  24. vpath %.S $(VPATH_SRC)
  25. VPATH :=
  26. # Output format. (can be srec, ihex, binary)
  27. FORMAT = ihex
  28. # Optimization level, can be [0, 1, 2, 3, s].
  29. # 0 = turn off optimization. s = optimize for size.
  30. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  31. OPT = s
  32. COLOR ?= true
  33. ifeq ($(COLOR),true)
  34. NO_COLOR=\033[0m
  35. OK_COLOR=\033[32;01m
  36. ERROR_COLOR=\033[31;01m
  37. WARN_COLOR=\033[33;01m
  38. BLUE=\033[0;34m
  39. BOLD=\033[1m
  40. endif
  41. AUTOGEN ?= false
  42. ifneq ($(shell awk --version 2>/dev/null),)
  43. AWK=awk
  44. else
  45. AWK=cat && test
  46. endif
  47. OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
  48. ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
  49. WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
  50. ifndef $(SILENT)
  51. SILENT = false
  52. endif
  53. TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
  54. TAB_LOG_PLAIN = printf "$$LOG\n"
  55. AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
  56. AWK_CMD = $(AWK) '{ printf "%-99s", $$0; }'
  57. PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && exit 1
  58. PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
  59. PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && exit 1
  60. PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
  61. PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
  62. BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
  63. # List any extra directories to look for include files here.
  64. # Each directory must be seperated by a space.
  65. # Use forward slashes for directory separators.
  66. # For a directory that has spaces, enclose it in quotes.
  67. EXTRAINCDIRS += $(subst :, ,$(VPATH_SRC))
  68. # Compiler flag to set the C Standard level.
  69. # c89 = "ANSI" C
  70. # gnu89 = c89 plus GCC extensions
  71. # c99 = ISO C99 standard (not yet fully implemented)
  72. # gnu99 = c99 plus GCC extensions
  73. CSTANDARD = -std=gnu99
  74. # Place -D or -U options here for C sources
  75. CDEFS += $(OPT_DEFS)
  76. # Place -D or -U options here for ASM sources
  77. ADEFS += $(OPT_DEFS)
  78. # Place -D or -U options here for C++ sources
  79. #CPPDEFS += -D__STDC_LIMIT_MACROS
  80. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  81. CPPDEFS += $(OPT_DEFS)
  82. #---------------- Compiler Options C ----------------
  83. # -g*: generate debugging information
  84. # -O*: optimization level
  85. # -f...: tuning, see GCC manual and avr-libc documentation
  86. # -Wall...: warning level
  87. # -Wa,...: tell GCC to pass this to the assembler.
  88. # -adhlns...: create assembler listing
  89. CFLAGS += -g$(DEBUG)
  90. CFLAGS += $(CDEFS)
  91. CFLAGS += -O$(OPT)
  92. # add color
  93. ifeq ($(COLOR),true)
  94. ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
  95. CFLAGS+= -fdiagnostics-color
  96. endif
  97. endif
  98. CFLAGS += -Wall
  99. CFLAGS += -Wstrict-prototypes
  100. #CFLAGS += -mshort-calls
  101. #CFLAGS += -fno-unit-at-a-time
  102. #CFLAGS += -Wundef
  103. #CFLAGS += -Wunreachable-code
  104. #CFLAGS += -Wsign-compare
  105. CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  106. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  107. CFLAGS += $(CSTANDARD)
  108. ifdef CONFIG_H
  109. CFLAGS += -include $(CONFIG_H)
  110. endif
  111. #---------------- Compiler Options C++ ----------------
  112. # -g*: generate debugging information
  113. # -O*: optimization level
  114. # -f...: tuning, see GCC manual and avr-libc documentation
  115. # -Wall...: warning level
  116. # -Wa,...: tell GCC to pass this to the assembler.
  117. # -adhlns...: create assembler listing
  118. CPPFLAGS += -g$(DEBUG)
  119. CPPFLAGS += $(CPPDEFS)
  120. CPPFLAGS += -O$(OPT)
  121. # to supress "warning: only initialized variables can be placed into program memory area"
  122. CPPFLAGS += -w
  123. CPPFLAGS += -Wall
  124. CPPFLAGS += -Wundef
  125. #CPPFLAGS += -mshort-calls
  126. #CPPFLAGS += -fno-unit-at-a-time
  127. #CPPFLAGS += -Wstrict-prototypes
  128. #CPPFLAGS += -Wunreachable-code
  129. #CPPFLAGS += -Wsign-compare
  130. CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  131. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  132. #CPPFLAGS += $(CSTANDARD)
  133. ifdef CONFIG_H
  134. CPPFLAGS += -include $(CONFIG_H)
  135. endif
  136. #---------------- Assembler Options ----------------
  137. # -Wa,...: tell GCC to pass this to the assembler.
  138. # -adhlns: create listing
  139. # -gstabs: have the assembler create line number information; note that
  140. # for use in COFF files, additional information about filenames
  141. # and function names needs to be present in the assembler source
  142. # files -- see avr-libc docs [FIXME: not yet described there]
  143. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  144. # dump that will be displayed for a given single line of source input.
  145. ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
  146. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  147. ifdef CONFIG_H
  148. ASFLAGS += -include $(CONFIG_H)
  149. endif
  150. #---------------- Library Options ----------------
  151. # Minimalistic printf version
  152. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  153. # Floating point printf version (requires MATH_LIB = -lm below)
  154. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  155. # If this is left blank, then it will use the Standard printf version.
  156. PRINTF_LIB =
  157. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  158. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  159. # Minimalistic scanf version
  160. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  161. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  162. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  163. # If this is left blank, then it will use the Standard scanf version.
  164. SCANF_LIB =
  165. #SCANF_LIB = $(SCANF_LIB_MIN)
  166. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  167. MATH_LIB = -lm
  168. # List any extra directories to look for libraries here.
  169. # Each directory must be seperated by a space.
  170. # Use forward slashes for directory separators.
  171. # For a directory that has spaces, enclose it in quotes.
  172. EXTRALIBDIRS =
  173. #---------------- External Memory Options ----------------
  174. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  175. # used for variables (.data/.bss) and heap (malloc()).
  176. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  177. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  178. # only used for heap (malloc()).
  179. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  180. EXTMEMOPTS =
  181. #---------------- Linker Options ----------------
  182. # -Wl,...: tell GCC to pass this to linker.
  183. # -Map: create map file
  184. # --cref: add cross reference to map file
  185. #
  186. # Comennt out "--relax" option to avoid a error such:
  187. # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
  188. #
  189. LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
  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. #---------------- Debugging Options ----------------
  198. # For simulavr only - target MCU frequency.
  199. DEBUG_MFREQ = $(F_CPU)
  200. # Set the DEBUG_UI to either gdb or insight.
  201. # DEBUG_UI = gdb
  202. DEBUG_UI = insight
  203. # Set the debugging back-end to either avarice, simulavr.
  204. DEBUG_BACKEND = avarice
  205. #DEBUG_BACKEND = simulavr
  206. # GDB Init Filename.
  207. GDBINIT_FILE = __avr_gdbinit
  208. # When using avarice settings for the JTAG
  209. JTAG_DEV = /dev/com1
  210. # Debugging port used to communicate between GDB / avarice / simulavr.
  211. DEBUG_PORT = 4242
  212. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  213. # just set to localhost unless doing some sort of crazy debugging when
  214. # avarice is running on a different computer.
  215. DEBUG_HOST = localhost
  216. #============================================================================
  217. # Define programs and commands.
  218. SHELL = sh
  219. REMOVE = rm -f
  220. REMOVEDIR = rmdir
  221. COPY = cp
  222. WINSHELL = cmd
  223. SECHO = $(SILENT) || echo
  224. # Define Messages
  225. # English
  226. MSG_ERRORS_NONE = Errors: none
  227. MSG_BEGIN = -------- begin --------
  228. MSG_END = -------- end --------
  229. MSG_SIZE_BEFORE = Size before:
  230. MSG_SIZE_AFTER = Size after:
  231. MSG_COFF = Converting to AVR COFF:
  232. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  233. MSG_FLASH = Creating load file for Flash:
  234. MSG_EEPROM = Creating load file for EEPROM:
  235. MSG_BIN = Creating binary load file for Flash:
  236. MSG_EXTENDED_LISTING = Creating Extended Listing:
  237. MSG_SYMBOL_TABLE = Creating Symbol Table:
  238. MSG_LINKING = Linking:
  239. MSG_COMPILING = Compiling:
  240. MSG_COMPILING_CPP = Compiling:
  241. MSG_ASSEMBLING = Assembling:
  242. MSG_CLEANING = Cleaning project:
  243. MSG_CREATING_LIBRARY = Creating library:
  244. MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
  245. Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\
  246. git submodule sync --recursive\n\
  247. git submodule update --init --recursive$(NO_COLOR)\n\n\
  248. You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
  249. or if you have modified the ChibiOS libraries yourself. \n\n
  250. # Define all object files.
  251. OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
  252. # The files in the lib folder are shared between all keymaps, so generate that folder name by removing
  253. # the keymap from the name
  254. KBOBJDIR=$(subst _$(KEYMAP),,$(OBJDIR))
  255. # And fixup the object files to match
  256. LIBOBJ = $(foreach v,$(OBJ),$(if $(findstring /lib/,$v),$v))
  257. NONLIBOBJ := $(filter-out $(LIBOBJ),$(OBJ))
  258. LIBOBJ := $(subst _$(KEYMAP)/,/,$(LIBOBJ))
  259. OBJ := $(LIBOBJ) $(NONLIBOBJ)
  260. # Define all listing files.
  261. LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
  262. # Compiler flags to generate dependency files.
  263. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  264. GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
  265. # Combine all necessary flags and optional flags.
  266. # Add target processor to flags.
  267. # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
  268. ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(EXTRAFLAGS)
  269. ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(EXTRAFLAGS)
  270. ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
  271. MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@)
  272. # Default target.
  273. all: build sizeafter
  274. # Change the build target to build a HEX file or a library.
  275. build: elf hex
  276. #build: elf hex eep lss sym
  277. #build: lib
  278. elf: $(BUILD_DIR)/$(TARGET).elf
  279. hex: $(BUILD_DIR)/$(TARGET).hex
  280. eep: $(BUILD_DIR)/$(TARGET).eep
  281. lss: $(BUILD_DIR)/$(TARGET).lss
  282. sym: $(BUILD_DIR)/$(TARGET).sym
  283. LIBNAME=lib$(TARGET).a
  284. lib: $(LIBNAME)
  285. check_submodule:
  286. git submodule status --recursive | \
  287. while IFS= read -r x; do \
  288. case "$$x" in \
  289. \ *) ;; \
  290. *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
  291. esac \
  292. done
  293. # Display size of file.
  294. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  295. #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  296. ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
  297. sizebefore:
  298. @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
  299. 2>/dev/null; $(SECHO); fi
  300. sizeafter: $(BUILD_DIR)/$(TARGET).hex
  301. @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
  302. 2>/dev/null; $(SECHO); fi
  303. # test file sizes eventually
  304. # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
  305. # Display compiler version information.
  306. gccversion :
  307. @$(SILENT) || $(CC) --version
  308. # Program the device.
  309. program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  310. $(PROGRAM_CMD)
  311. teensy: $(BUILD_DIR)/$(TARGET).hex
  312. $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
  313. flip: $(BUILD_DIR)/$(TARGET).hex
  314. batchisp -hardware usb -device $(MCU) -operation erase f
  315. batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
  316. batchisp -hardware usb -device $(MCU) -operation start reset 0
  317. dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
  318. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  319. dfu-programmer $(MCU) erase --force
  320. else
  321. dfu-programmer $(MCU) erase
  322. endif
  323. dfu-programmer $(MCU) erase
  324. dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
  325. dfu-programmer $(MCU) reset
  326. dfu-no-build:
  327. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  328. dfu-programmer $(MCU) erase --force
  329. else
  330. dfu-programmer $(MCU) erase
  331. endif
  332. dfu-programmer $(MCU) erase
  333. dfu-programmer $(MCU) flash $(KEYMAP_PATH)/compiled.hex
  334. dfu-programmer $(MCU) reset
  335. dfu-start:
  336. dfu-programmer $(MCU) reset
  337. dfu-programmer $(MCU) start
  338. flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  339. $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
  340. batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
  341. batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
  342. batchisp -hardware usb -device $(MCU) -operation start reset 0
  343. $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
  344. dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
  345. ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
  346. dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
  347. else
  348. dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
  349. endif
  350. dfu-programmer $(MCU) reset
  351. # Generate avr-gdb config/init file which does the following:
  352. # define the reset signal, load the target file, connect to target, and set
  353. # a breakpoint at main().
  354. gdb-config:
  355. @$(REMOVE) $(GDBINIT_FILE)
  356. @echo define reset >> $(GDBINIT_FILE)
  357. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  358. @echo end >> $(GDBINIT_FILE)
  359. @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
  360. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  361. ifeq ($(DEBUG_BACKEND),simulavr)
  362. @echo load >> $(GDBINIT_FILE)
  363. endif
  364. @echo break main >> $(GDBINIT_FILE)
  365. debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
  366. ifeq ($(DEBUG_BACKEND), avarice)
  367. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  368. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  369. $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  370. @$(WINSHELL) /c pause
  371. else
  372. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  373. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  374. endif
  375. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  376. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  377. COFFCONVERT = $(OBJCOPY) --debugging
  378. COFFCONVERT += --change-section-address .data-0x800000
  379. COFFCONVERT += --change-section-address .bss-0x800000
  380. COFFCONVERT += --change-section-address .noinit-0x800000
  381. COFFCONVERT += --change-section-address .eeprom-0x810000
  382. coff: $(BUILD_DIR)/$(TARGET).elf
  383. @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
  384. $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
  385. extcoff: $(BUILD_DIR)/$(TARGET).elf
  386. @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
  387. $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
  388. # Create final output files (.hex, .eep) from ELF output file.
  389. %.hex: %.elf
  390. @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
  391. $(eval CMD=$(HEX) $< $@)
  392. @$(BUILD_CMD)
  393. @if $(AUTOGEN); then \
  394. $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
  395. $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
  396. else \
  397. $(COPY) $@ $(TARGET).hex; \
  398. fi
  399. %.eep: %.elf
  400. @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
  401. $(eval CMD=$(EEP) $< $@ || exit 0)
  402. @$(BUILD_CMD)
  403. # Create extended listing file from ELF output file.
  404. %.lss: %.elf
  405. @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
  406. $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
  407. @$(BUILD_CMD)
  408. # Create a symbol table from ELF output file.
  409. %.sym: %.elf
  410. @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
  411. $(eval CMD=$(NM) -n $< > $@ )
  412. @$(BUILD_CMD)
  413. %.bin: %.elf
  414. @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
  415. $(eval CMD=$(BIN) $< $@ || exit 0)
  416. @$(BUILD_CMD)
  417. # Create library from object files.
  418. .SECONDARY : $(BUILD_DIR)/$(TARGET).a
  419. .PRECIOUS : $(OBJ)
  420. %.a: $(OBJ)
  421. @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
  422. $(eval CMD=$(AR) $@ $(OBJ) )
  423. @$(BUILD_CMD)
  424. BEGIN = gccversion check_submodule sizebefore
  425. # Link: create ELF output file from object files.
  426. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
  427. .PRECIOUS : $(OBJ)
  428. # Note the obj.txt depeendency is there to force linking if a source file is deleted
  429. %.elf: $(OBJ) $(OBJDIR)/cflags.txt $(OBJDIR)/ldflags.txt $(OBJDIR)/obj.txt | $(BEGIN)
  430. @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
  431. $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS))
  432. @$(BUILD_CMD)
  433. define GEN_OBJRULE
  434. # Compile: create object files from C source files.
  435. $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN)
  436. @mkdir -p $$(@D)
  437. @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
  438. $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
  439. @$$(BUILD_CMD)
  440. # Compile: create object files from C++ source files.
  441. $1/%.o : %.cpp $1/%.d $1/cppflags.txt $1/compiler.txt | $(BEGIN)
  442. @mkdir -p $$(@D)
  443. @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
  444. $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP))
  445. @$(BUILD_CMD)
  446. # Assemble: create object files from assembler source files.
  447. $1/%.o : %.S $1/asflags.txt $1/compiler.txt | $(BEGIN)
  448. @mkdir -p $$(@D)
  449. @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
  450. $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
  451. @$$(BUILD_CMD)
  452. $1/force:
  453. $1/cflags.txt: $1/force
  454. echo '$$(ALL_CFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CFLAGS)' > $$@
  455. $1/cppflags.txt: $1/force
  456. echo '$$(ALL_CPPFLAGS)' | cmp -s - $$@ || echo '$$(ALL_CPPFLAGS)' > $$@
  457. $1/asflags.txt: $1/force
  458. echo '$$(ALL_ASFLAGS)' | cmp -s - $$@ || echo '$$(ALL_ASFLAGS)' > $$@
  459. $1/ldflags.txt: $1/force
  460. echo '$$(LDFLAGS)' | cmp -s - $$@ || echo '$$(LDFLAGS)' > $$@
  461. $1/obj.txt: $1/force
  462. echo '$$(OBJ)' | cmp -s - $$@ || echo '$$(OBJ)' > $$@
  463. $1/compiler.txt: $1/force
  464. $$(CC) --version | cmp -s - $$@ || $$(CC) --version > $$@
  465. endef
  466. # We have to use static rules for the .d files for some reason
  467. DEPS = $(patsubst %.o,%.d,$(OBJ))
  468. # Keep the .d files
  469. .PRECIOUS: $(DEPS)
  470. # Empty rule to force recompilation if the .d file is missing
  471. $(DEPS):
  472. # Since the object files could be in two different folders, generate
  473. # separate rules for them, rather than having too generic rules
  474. $(eval $(call GEN_OBJRULE,$(OBJDIR)))
  475. $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
  476. # Compile: create assembler files from C source files.
  477. %.s : %.c | $(BEGIN)
  478. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  479. $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
  480. @$(BUILD_CMD)
  481. # Compile: create assembler files from C++ source files.
  482. %.s : %.cpp | $(BEGIN)
  483. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  484. $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
  485. @$(BUILD_CMD)
  486. # Create preprocessed source for use in sending a bug report.
  487. %.i : %.c | $(BEGIN)
  488. $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
  489. # Target: clean project.
  490. clean:
  491. $(REMOVE) -r $(OBJDIR) 2>/dev/null
  492. $(REMOVE) -r $(KBOBJDIR) 2>/dev/null
  493. $(REMOVE) $(BUILD_DIR)/$(TARGET).*
  494. show_path:
  495. @echo VPATH=$(VPATH)
  496. @echo SRC=$(SRC)
  497. SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
  498. SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
  499. SUBDIRS := $(sort $(SUBDIRS))
  500. # $(error $(SUBDIRS))
  501. all-keyboards-defaults-%:
  502. @for x in $(SUBDIRS) ; do \
  503. printf "Compiling with default: $$x" | $(AWK_CMD); \
  504. LOG=$$($(MAKE) -C $$x $(subst all-keyboards-defaults-,,$@) VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  505. done
  506. all-keyboards-defaults: all-keyboards-defaults-all
  507. KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
  508. all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
  509. all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
  510. all-keyboards: all-keyboards-all
  511. define make_keyboard
  512. $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
  513. $(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
  514. $(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
  515. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
  516. $(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
  517. @for x in $(KEYMAPS) ; do \
  518. printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
  519. LOG=$$($(MAKE) -C $(TOP_DIR)$1 $2 keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  520. done
  521. endef
  522. define make_keyboard_helper
  523. # Just remove the -all and so on from the first argument and pass it forward
  524. $(call make_keyboard,$(subst -$2,,$1),$2)
  525. endef
  526. /keyboards/%-all:
  527. $(call make_keyboard_helper,$@,all)
  528. /keyboards/%-clean:
  529. $(call make_keyboard_helper,$@,clean)
  530. /keyboards/%:
  531. $(call make_keyboard_helper,$@,all)
  532. all-keymaps-%:
  533. $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
  534. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
  535. @for x in $(KEYMAPS) ; do \
  536. printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
  537. LOG=$$($(MAKE) $(subst all-keymaps-,,$@) keyboard=$(KEYBOARD) keymap=$$x VERBOSE=$(VERBOSE) COLOR=$(COLOR) SILENT=true 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR_PLAIN); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING_PLAIN); else $(PRINT_OK); fi; \
  538. done
  539. all-keymaps: all-keymaps-all
  540. # Create build directory
  541. $(shell mkdir $(BUILD_DIR) 2>/dev/null)
  542. # Create object files directory
  543. $(shell mkdir $(OBJDIR) 2>/dev/null)
  544. $(shell mkdir $(KBOBJDIR) 2>/dev/null)
  545. # Include the dependency files.
  546. -include $(patsubst %.o,%.d,$(OBJ))
  547. # Listing of phony targets.
  548. .PHONY : all finish sizebefore sizeafter gccversion \
  549. build elf hex eep lss sym coff extcoff check_submodule \
  550. clean clean_list debug gdb-config show_path \
  551. program teensy dfu flip dfu-ee flip-ee dfu-start \
  552. all-keyboards-defaults all-keyboards all-keymaps \
  553. all-keyboards-defaults-% all-keyboards-% all-keymaps-%