rules.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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. ifdef quick
  42. QUICK = $(quick)
  43. endif
  44. QUICK ?= false
  45. AUTOGEN ?= false
  46. ifneq ($(shell awk --version 2>/dev/null),)
  47. AWK=awk
  48. else
  49. AWK=cat && test
  50. endif
  51. OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\n
  52. ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\n
  53. WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\n
  54. ifndef $(SILENT)
  55. SILENT = false
  56. endif
  57. TAB_LOG = printf "\n$$LOG\n\n" | $(AWK) '{ sub(/^/," | "); print }'
  58. TAB_LOG_PLAIN = printf "$$LOG\n"
  59. AWK_STATUS = $(AWK) '{ printf " %-10s\n", $$1; }'
  60. AWK_CMD = $(AWK) '{ printf "%-99s", $$0; }'
  61. PRINT_ERROR = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG) && exit 1
  62. PRINT_WARNING = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG)
  63. PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) && exit 1
  64. PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
  65. PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
  66. BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
  67. # List any extra directories to look for include files here.
  68. # Each directory must be seperated by a space.
  69. # Use forward slashes for directory separators.
  70. # For a directory that has spaces, enclose it in quotes.
  71. EXTRAINCDIRS += $(subst :, ,$(VPATH_SRC))
  72. # Compiler flag to set the C Standard level.
  73. # c89 = "ANSI" C
  74. # gnu89 = c89 plus GCC extensions
  75. # c99 = ISO C99 standard (not yet fully implemented)
  76. # gnu99 = c99 plus GCC extensions
  77. CSTANDARD = -std=gnu99
  78. # Place -D or -U options here for C sources
  79. CDEFS += $(OPT_DEFS)
  80. # Place -D or -U options here for ASM sources
  81. ADEFS += $(OPT_DEFS)
  82. # Place -D or -U options here for C++ sources
  83. #CPPDEFS += -D__STDC_LIMIT_MACROS
  84. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  85. CPPDEFS += $(OPT_DEFS)
  86. #---------------- Compiler Options C ----------------
  87. # -g*: generate debugging information
  88. # -O*: optimization level
  89. # -f...: tuning, see GCC manual and avr-libc documentation
  90. # -Wall...: warning level
  91. # -Wa,...: tell GCC to pass this to the assembler.
  92. # -adhlns...: create assembler listing
  93. CFLAGS += -g$(DEBUG)
  94. CFLAGS += $(CDEFS)
  95. CFLAGS += -O$(OPT)
  96. # add color
  97. ifeq ($(COLOR),true)
  98. ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
  99. CFLAGS+= -fdiagnostics-color
  100. endif
  101. endif
  102. CFLAGS += -Wall
  103. CFLAGS += -Wstrict-prototypes
  104. #CFLAGS += -mshort-calls
  105. #CFLAGS += -fno-unit-at-a-time
  106. #CFLAGS += -Wundef
  107. #CFLAGS += -Wunreachable-code
  108. #CFLAGS += -Wsign-compare
  109. CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  110. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  111. CFLAGS += $(CSTANDARD)
  112. ifdef CONFIG_H
  113. CFLAGS += -include $(CONFIG_H)
  114. endif
  115. #---------------- Compiler Options C++ ----------------
  116. # -g*: generate debugging information
  117. # -O*: optimization level
  118. # -f...: tuning, see GCC manual and avr-libc documentation
  119. # -Wall...: warning level
  120. # -Wa,...: tell GCC to pass this to the assembler.
  121. # -adhlns...: create assembler listing
  122. CPPFLAGS += -g$(DEBUG)
  123. CPPFLAGS += $(CPPDEFS)
  124. CPPFLAGS += -O$(OPT)
  125. # to supress "warning: only initialized variables can be placed into program memory area"
  126. CPPFLAGS += -w
  127. CPPFLAGS += -Wall
  128. CPPFLAGS += -Wundef
  129. #CPPFLAGS += -mshort-calls
  130. #CPPFLAGS += -fno-unit-at-a-time
  131. #CPPFLAGS += -Wstrict-prototypes
  132. #CPPFLAGS += -Wunreachable-code
  133. #CPPFLAGS += -Wsign-compare
  134. CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
  135. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  136. #CPPFLAGS += $(CSTANDARD)
  137. ifdef CONFIG_H
  138. CPPFLAGS += -include $(CONFIG_H)
  139. endif
  140. #---------------- Assembler Options ----------------
  141. # -Wa,...: tell GCC to pass this to the assembler.
  142. # -adhlns: create listing
  143. # -gstabs: have the assembler create line number information; note that
  144. # for use in COFF files, additional information about filenames
  145. # and function names needs to be present in the assembler source
  146. # files -- see avr-libc docs [FIXME: not yet described there]
  147. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  148. # dump that will be displayed for a given single line of source input.
  149. ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
  150. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  151. ifdef CONFIG_H
  152. ASFLAGS += -include $(CONFIG_H)
  153. endif
  154. #---------------- Library Options ----------------
  155. # Minimalistic printf version
  156. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  157. # Floating point printf version (requires MATH_LIB = -lm below)
  158. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  159. # If this is left blank, then it will use the Standard printf version.
  160. PRINTF_LIB =
  161. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  162. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  163. # Minimalistic scanf version
  164. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  165. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  166. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  167. # If this is left blank, then it will use the Standard scanf version.
  168. SCANF_LIB =
  169. #SCANF_LIB = $(SCANF_LIB_MIN)
  170. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  171. MATH_LIB = -lm
  172. #---------------- Linker Options ----------------
  173. # -Wl,...: tell GCC to pass this to linker.
  174. # -Map: create map file
  175. # --cref: add cross reference to map file
  176. #
  177. # Comennt out "--relax" option to avoid a error such:
  178. # (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
  179. #
  180. LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
  181. #LDFLAGS += -Wl,--relax
  182. LDFLAGS += $(EXTMEMOPTS)
  183. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  184. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  185. #LDFLAGS += -T linker_script.x
  186. # You can give EXTRALDFLAGS at 'make' command line.
  187. LDFLAGS += $(EXTRALDFLAGS)
  188. # Define programs and commands.
  189. SHELL = sh
  190. REMOVE = rm -f
  191. REMOVEDIR = rmdir
  192. COPY = cp
  193. WINSHELL = cmd
  194. SECHO = $(SILENT) || echo
  195. # Define Messages
  196. # English
  197. MSG_ERRORS_NONE = Errors: none
  198. MSG_BEGIN = -------- begin --------
  199. MSG_END = -------- end --------
  200. MSG_SIZE_BEFORE = Size before:
  201. MSG_SIZE_AFTER = Size after:
  202. MSG_COFF = Converting to AVR COFF:
  203. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  204. MSG_FLASH = Creating load file for Flash:
  205. MSG_EEPROM = Creating load file for EEPROM:
  206. MSG_BIN = Creating binary load file for Flash:
  207. MSG_EXTENDED_LISTING = Creating Extended Listing:
  208. MSG_SYMBOL_TABLE = Creating Symbol Table:
  209. MSG_LINKING = Linking:
  210. MSG_COMPILING = Compiling:
  211. MSG_COMPILING_CPP = Compiling:
  212. MSG_ASSEMBLING = Assembling:
  213. MSG_CLEANING = Cleaning project:
  214. MSG_CREATING_LIBRARY = Creating library:
  215. MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
  216. Some git sub-modules are out of date or modified, please consider runnning:$(BOLD)\n\
  217. git submodule sync --recursive\n\
  218. git submodule update --init --recursive$(NO_COLOR)\n\n\
  219. You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
  220. or if you have modified the ChibiOS libraries yourself. \n\n
  221. # Define all object files.
  222. OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
  223. # The files in the lib folder are shared between all keymaps, so generate that folder name by removing
  224. # the keymap from the name
  225. KBOBJDIR=$(subst _$(KEYMAP),,$(OBJDIR))
  226. # And fixup the object files to match
  227. LIBOBJ = $(foreach v,$(OBJ),$(if $(findstring /lib/,$v),$v))
  228. NONLIBOBJ := $(filter-out $(LIBOBJ),$(OBJ))
  229. LIBOBJ := $(subst _$(KEYMAP)/,/,$(LIBOBJ))
  230. OBJ := $(LIBOBJ) $(NONLIBOBJ)
  231. # Define all listing files.
  232. LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst %.S,$(OBJDIR)/%.lst,$(SRC))))
  233. # Compiler flags to generate dependency files.
  234. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  235. GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d
  236. # Combine all necessary flags and optional flags.
  237. # Add target processor to flags.
  238. # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
  239. ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  240. ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
  241. ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
  242. # Default target.
  243. all: build sizeafter
  244. # Quick make that doesn't clean
  245. quick: build sizeafter
  246. # Change the build target to build a HEX file or a library.
  247. build: elf hex
  248. #build: elf hex eep lss sym
  249. #build: lib
  250. elf: $(BUILD_DIR)/$(TARGET).elf
  251. hex: $(BUILD_DIR)/$(TARGET).hex
  252. eep: $(BUILD_DIR)/$(TARGET).eep
  253. lss: $(BUILD_DIR)/$(TARGET).lss
  254. sym: $(BUILD_DIR)/$(TARGET).sym
  255. LIBNAME=lib$(TARGET).a
  256. lib: $(LIBNAME)
  257. check_submodule:
  258. git submodule status --recursive | \
  259. while IFS= read -r x; do \
  260. case "$$x" in \
  261. \ *) ;; \
  262. *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
  263. esac \
  264. done
  265. # Display size of file.
  266. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  267. #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  268. ELFSIZE = $(SIZE) $(BUILD_DIR)/$(TARGET).elf
  269. sizebefore:
  270. @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \
  271. 2>/dev/null; $(SECHO); fi
  272. sizeafter: $(BUILD_DIR)/$(TARGET).hex
  273. @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \
  274. 2>/dev/null; $(SECHO); fi
  275. # test file sizes eventually
  276. # @if [[ $($(SIZE) --target=$(FORMAT) $(TARGET).hex | $(AWK) 'NR==2 {print "0x"$5}') -gt 0x200 ]]; then $(SECHO) "File is too big!"; fi
  277. # Display compiler version information.
  278. gccversion :
  279. @$(SILENT) || $(CC) --version
  280. # Create final output files (.hex, .eep) from ELF output file.
  281. %.hex: %.elf
  282. @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
  283. $(eval CMD=$(HEX) $< $@)
  284. @$(BUILD_CMD)
  285. @if $(AUTOGEN); then \
  286. $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
  287. $(COPY) $@ $(KEYMAP_PATH)/$(KEYBOARD)_$(KEYMAP).hex; \
  288. else \
  289. $(COPY) $@ $(TARGET).hex; \
  290. fi
  291. %.eep: %.elf
  292. @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
  293. $(eval CMD=$(EEP) $< $@ || exit 0)
  294. @$(BUILD_CMD)
  295. # Create extended listing file from ELF output file.
  296. %.lss: %.elf
  297. @$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
  298. $(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
  299. @$(BUILD_CMD)
  300. # Create a symbol table from ELF output file.
  301. %.sym: %.elf
  302. @$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
  303. $(eval CMD=$(NM) -n $< > $@ )
  304. @$(BUILD_CMD)
  305. %.bin: %.elf
  306. @$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
  307. $(eval CMD=$(BIN) $< $@ || exit 0)
  308. @$(BUILD_CMD)
  309. # Create library from object files.
  310. .SECONDARY : $(BUILD_DIR)/$(TARGET).a
  311. .PRECIOUS : $(OBJ)
  312. %.a: $(OBJ)
  313. @$(SILENT) || printf "$(MSG_CREATING_LIBRARY) $@" | $(AWK_CMD)
  314. $(eval CMD=$(AR) $@ $(OBJ) )
  315. @$(BUILD_CMD)
  316. BEGIN = gccversion check_submodule sizebefore
  317. # Link: create ELF output file from object files.
  318. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf
  319. .PRECIOUS : $(OBJ)
  320. %.elf: $(OBJ) | $(BEGIN)
  321. @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD)
  322. $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS))
  323. @$(BUILD_CMD)
  324. define GEN_OBJRULE
  325. # Compile: create object files from C source files.
  326. $1/%.o : %.c | $(BEGIN)
  327. @mkdir -p $$(@D)
  328. @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD)
  329. $$(eval CMD=$$(CC) -c $$(ALL_CFLAGS) $$< -o $$@)
  330. @$$(BUILD_CMD)
  331. # Compile: create object files from C++ source files.
  332. $1/%.o : %.cpp | $(BEGIN)
  333. @mkdir -p $$(@D)
  334. @$$(SILENT) || printf "$$(MSG_COMPILING_CPP) $$<" | $$(AWK_CMD)
  335. $$(eval CMD=$$(CC) -c $$(ALL_CPPFLAGS) $$< -o $$@)
  336. @$(BUILD_CMD)
  337. # Assemble: create object files from assembler source files.
  338. $1/%.o : %.S | $(BEGIN)
  339. @mkdir -p $$(@D)
  340. @$(SILENT) || printf "$$(MSG_ASSEMBLING) $$<" | $$(AWK_CMD)
  341. $$(eval CMD=$$(CC) -c $$(ALL_ASFLAGS) $$< -o $$@)
  342. @$$(BUILD_CMD)
  343. endef
  344. # Since the object files could be in two different folders, generate
  345. # separate rules for them, rather than having too generic rules
  346. $(eval $(call GEN_OBJRULE,$(OBJDIR)))
  347. $(eval $(call GEN_OBJRULE,$(KBOBJDIR)))
  348. # Compile: create assembler files from C source files.
  349. %.s : %.c | $(BEGIN)
  350. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  351. $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@)
  352. @$(BUILD_CMD)
  353. # Compile: create assembler files from C++ source files.
  354. %.s : %.cpp | $(BEGIN)
  355. @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD)
  356. $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@)
  357. @$(BUILD_CMD)
  358. # Create preprocessed source for use in sending a bug report.
  359. %.i : %.c | $(BEGIN)
  360. $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@
  361. # Target: clean project.
  362. clean:
  363. show_path:
  364. @echo VPATH=$(VPATH)
  365. @echo SRC=$(SRC)
  366. SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
  367. SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
  368. SUBDIRS := $(sort $(SUBDIRS))
  369. # $(error $(SUBDIRS))
  370. all-keyboards-defaults-%:
  371. @for x in $(SUBDIRS) ; do \
  372. printf "Compiling with default: $$x" | $(AWK_CMD); \
  373. 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; \
  374. done
  375. all-keyboards-defaults: all-keyboards-defaults-all
  376. KEYBOARDS := $(SUBDIRS:$(TOP_DIR)/keyboards/%/=/keyboards/%)
  377. all-keyboards-all: $(addsuffix -all,$(KEYBOARDS))
  378. all-keyboards-quick: $(addsuffix -quick,$(KEYBOARDS))
  379. all-keyboards-clean: $(addsuffix -clean,$(KEYBOARDS))
  380. all-keyboards: all-keyboards-all
  381. define make_keyboard
  382. $(eval KEYBOARD=$(patsubst /keyboards/%,%,$1))
  383. $(eval SUBPROJECT=$(lastword $(subst /, ,$(KEYBOARD))))
  384. $(eval KEYBOARD=$(firstword $(subst /, ,$(KEYBOARD))))
  385. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
  386. $(eval KEYMAPS+=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/*/.))))
  387. @for x in $(KEYMAPS) ; do \
  388. printf "Compiling $(BOLD)$(KEYBOARD)/$(SUBPROJECT)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
  389. 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; \
  390. done
  391. endef
  392. define make_keyboard_helper
  393. # Just remove the -quick, -all and so on from the first argument and pass it forward
  394. $(call make_keyboard,$(subst -$2,,$1),$2)
  395. endef
  396. /keyboards/%-quick:
  397. $(call make_keyboard_helper,$@,quick)
  398. /keyboards/%-all:
  399. $(call make_keyboard_helper,$@,all)
  400. /keyboards/%-clean:
  401. $(call make_keyboard_helper,$@,clean)
  402. /keyboards/%:
  403. $(call make_keyboard_helper,$@,all)
  404. all-keymaps-%:
  405. $(eval MAKECONFIG=$(call get_target,all-keymaps,$@))
  406. $(eval KEYMAPS=$(notdir $(patsubst %/.,%,$(wildcard $(TOP_DIR)/keyboards/$(KEYBOARD)/keymaps/*/.))))
  407. @for x in $(KEYMAPS) ; do \
  408. printf "Compiling $(BOLD)$(KEYBOARD)$(NO_COLOR) with $(BOLD)$$x$(NO_COLOR)" | $(AWK) '{ printf "%-118s", $$0; }'; \
  409. 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; \
  410. done
  411. all-keymaps: all-keymaps-all
  412. GOAL=$(MAKECMDGOALS)
  413. ifeq ($(MAKECMDGOALS),)
  414. GOAL = all
  415. endif
  416. CLEANING_GOALS=clean clean_list all
  417. ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),)
  418. $(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null)
  419. $(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR))
  420. $(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR))
  421. $(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi)
  422. $(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR))
  423. endif
  424. # Create build directory
  425. $(shell mkdir $(BUILD_DIR) 2>/dev/null)
  426. # Create object files directory
  427. $(shell mkdir $(OBJDIR) 2>/dev/null)
  428. $(shell mkdir $(KBOBJDIR) 2>/dev/null)
  429. # Include the dependency files.
  430. -include $(shell mkdir $(BUILD_DIR)/.dep 2>/dev/null) $(wildcard $(BUILD_DIR)/.dep/*)
  431. # Listing of phony targets.
  432. .PHONY : all quick finish sizebefore sizeafter gccversion \
  433. build elf hex eep lss sym coff extcoff check_submodule \
  434. clean clean_list debug gdb-config show_path \
  435. program teensy dfu flip dfu-ee flip-ee dfu-start \
  436. all-keyboards-defaults all-keyboards all-keymaps \
  437. all-keyboards-defaults-% all-keyboards-% all-keymaps-%