Makefile 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. ifndef VERBOSE
  2. .SILENT:
  3. endif
  4. # Allow the silent with lower caps to work the same way as upper caps
  5. ifdef silent
  6. SILENT = $(silent)
  7. endif
  8. ifdef SILENT
  9. SUB_IS_SILENT := $(SILENT)
  10. endif
  11. # We need to make sure that silent is always turned off at the top level
  12. # Otherwise the [OK], [ERROR] and [WARN] messags won't be displayed correctly
  13. override SILENT := false
  14. ON_ERROR := error_occured=1
  15. STARTING_MAKEFILE := $(firstword $(MAKEFILE_LIST))
  16. ROOT_MAKEFILE := $(lastword $(MAKEFILE_LIST))
  17. ROOT_DIR := $(dir $(ROOT_MAKEFILE))
  18. ifeq ($(ROOT_DIR),)
  19. ROOT_DIR := .
  20. endif
  21. ABS_STARTING_MAKEFILE := $(abspath $(STARTING_MAKEFILE))
  22. ABS_ROOT_MAKEFILE := $(abspath $(ROOT_MAKEFILE))
  23. ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE))
  24. ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE))
  25. STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR))
  26. TEST_DIR := $(ROOT_DIR)/.build/test
  27. MAKEFILE_INCLUDED=yes
  28. # Helper function to process the newt element of a space separated path
  29. # It works a bit like the traditional functional head tail
  30. # so the CURRENT_PATH_ELEMENT will beome the new head
  31. # and the PATH_ELEMENTS are the rest that are still unprocessed
  32. define NEXT_PATH_ELEMENT
  33. $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS)))
  34. $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS)))
  35. endef
  36. # We change the / to spaces so that we more easily can work with the elements
  37. # separately
  38. PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR))
  39. # Initialize the path elements list for further processing
  40. $(eval $(call NEXT_PATH_ELEMENT))
  41. # This function sets the KEYBOARD; KEYMAP and SUBPROJECT to the correct
  42. # variables depending on which directory you stand in.
  43. # It's really a very simple if else chain, if you squint enough,
  44. # but the makefile syntax makes it very verbose.
  45. # If we are in a subfolder of keyboards
  46. ifeq ($(CURRENT_PATH_ELEMENT),keyboards)
  47. $(eval $(call NEXT_PATH_ELEMENT))
  48. KEYBOARD := $(CURRENT_PATH_ELEMENT)
  49. $(eval $(call NEXT_PATH_ELEMENT))
  50. # If we are in a subfolder of keymaps, or in other words in a keymap
  51. # folder
  52. ifeq ($(CURRENT_PATH_ELEMENT),keymaps)
  53. $(eval $(call NEXT_PATH_ELEMENT))
  54. KEYMAP := $(CURRENT_PATH_ELEMENT)
  55. # else if we are not in the keyboard folder itself
  56. else ifneq ($(CURRENT_PATH_ELEMENT),)
  57. # the we can assume it's a subproject, as no other folders
  58. # should have make files in them
  59. SUBPROJECT := $(CURRENT_PATH_ELEMENT)
  60. $(eval $(call NEXT_PATH_ELEMENT))
  61. # if we are inside a keymap folder of a subproject
  62. ifeq ($(CURRENT_PATH_ELEMENT),keymaps)
  63. $(eval $(call NEXT_PATH_ELEMENT))
  64. KEYMAP := $(CURRENT_PATH_ELEMENT)
  65. endif
  66. endif
  67. endif
  68. # Only consider folders with makefiles, to prevent errors in case there are extra folders
  69. KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile)))
  70. #Compability with the old make variables, anything you specify directly on the command line
  71. # always overrides the detected folders
  72. ifdef keyboard
  73. KEYBOARD := $(keyboard)
  74. endif
  75. ifdef sub
  76. SUBPROJECT := $(sub)
  77. endif
  78. ifdef subproject
  79. SUBPROJECT := $(subproject)
  80. endif
  81. ifdef keymap
  82. KEYMAP := $(keymap)
  83. endif
  84. # Uncomment these for debugging
  85. #$(info Keyboard: $(KEYBOARD))
  86. #$(info Keymap: $(KEYMAP))
  87. #$(info Subproject: $(SUBPROJECT))
  88. #$(info Keyboards: $(KEYBOARDS))
  89. # Set the default goal depening on where we are running make from
  90. # this handles the case where you run make without any arguments
  91. .DEFAULT_GOAL := all
  92. ifneq ($(KEYMAP),)
  93. ifeq ($(SUBPROJECT),)
  94. # Inside a keymap folder, just build the keymap, with the
  95. # default subproject
  96. .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP)
  97. else
  98. # Inside a subproject keyamp folder, build the keymap
  99. # for that subproject
  100. .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-$(KEYMAP)
  101. endif
  102. else ifneq ($(SUBPROJECT),)
  103. # Inside a subproject folder, build all keymaps for that subproject
  104. .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-allkm
  105. else ifneq ($(KEYBOARD),)
  106. # Inside a keyboard folder, build all keymaps for all subprojects
  107. # Note that this is different from the old behaviour, which would
  108. # build only the default keymap of the default keyboard
  109. .DEFAULT_GOAL := $(KEYBOARD)-allsp-allkm
  110. endif
  111. # Compare the start of the RULE variable with the first argument($1)
  112. # If the rules equals $1 or starts with $1-, RULE_FOUND is set to true
  113. # and $1 is removed from the RULE variable
  114. # Otherwise the RULE_FOUND variable is set to false, and RULE left as it was
  115. # The function is a bit tricky, since there's no built in $(startswith) function
  116. define COMPARE_AND_REMOVE_FROM_RULE_HELPER
  117. ifeq ($1,$$(RULE))
  118. RULE:=
  119. RULE_FOUND := true
  120. else
  121. STARTDASH_REMOVED=$$(subst START$1-,,START$$(RULE))
  122. ifneq ($$(STARTDASH_REMOVED),START$$(RULE))
  123. RULE_FOUND := true
  124. RULE := $$(STARTDASH_REMOVED)
  125. else
  126. RULE_FOUND := false
  127. endif
  128. endif
  129. endef
  130. # This makes it easier to call COMPARE_AND_REMOVE_FROM_RULE, since it makes it behave like
  131. # a function that returns the value
  132. COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND)
  133. # Recursively try to find a match for the start of the rule to be checked
  134. # $1 The list to be checked
  135. # If a match is found, then RULE_FOUND is set to true
  136. # and MATCHED_ITEM to the item that was matched
  137. define TRY_TO_MATCH_RULE_FROM_LIST_HELPER3
  138. ifneq ($1,)
  139. ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true)
  140. MATCHED_ITEM := $$(firstword $1)
  141. else
  142. $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$$(wordlist 2,9999,$1)))
  143. endif
  144. endif
  145. endef
  146. # A recursive helper function for finding the longest match
  147. # $1 The list to be checed
  148. # It works by always removing the currently matched item from the list
  149. # and call itself recursively, until a match is found
  150. define TRY_TO_MATCH_RULE_FROM_LIST_HELPER2
  151. # Stop the recursion when the list is empty
  152. ifneq ($1,)
  153. RULE_BEFORE := $$(RULE)
  154. $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$1))
  155. # If a match is found in the current list, otherwise just return what we had before
  156. ifeq ($$(RULE_FOUND),true)
  157. # Save the best match so far and call itself recursivel
  158. BEST_MATCH := $$(MATCHED_ITEM)
  159. BEST_MATCH_RULE := $$(RULE)
  160. RULE_FOUND := false
  161. RULE := $$(RULE_BEFORE)
  162. $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$$(filter-out $$(MATCHED_ITEM),$1)))
  163. endif
  164. endif
  165. endef
  166. # Recursively try to find the longest match for the start of the rule to be checked
  167. # $1 The list to be checked
  168. # If a match is found, then RULE_FOUND is set to true
  169. # and MATCHED_ITEM to the item that was matched
  170. define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
  171. BEST_MATCH :=
  172. $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$1))
  173. ifneq ($$(BEST_MATCH),)
  174. RULE_FOUND := true
  175. RULE := $$(BEST_MATCH_RULE)
  176. MATCHED_ITEM := $$(BEST_MATCH)
  177. else
  178. RULE_FOUND := false
  179. MATCHED_ITEM :=
  180. endif
  181. endef
  182. # Make it easier to call TRY_TO_MATCH_RULE_FROM_LIST
  183. TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
  184. define ALL_IN_LIST_LOOP
  185. OLD_RULE$1 := $$(RULE)
  186. $$(eval $$(call $1,$$(ITEM$1)))
  187. RULE := $$(OLD_RULE$1)
  188. endef
  189. define PARSE_ALL_IN_LIST
  190. $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1)))
  191. endef
  192. # The entry point for rule parsing
  193. # parses a rule in the format <keyboard>-<subproject>-<keymap>-<target>
  194. # but this particular function only deals with the first <keyboard> part
  195. define PARSE_RULE
  196. RULE := $1
  197. COMMANDS :=
  198. # If the rule starts with allkb, then continue the parsing from
  199. # PARSE_ALL_KEYBOARDS
  200. ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true)
  201. $$(eval $$(call PARSE_ALL_KEYBOARDS))
  202. else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,test),true)
  203. $$(eval $$(call PARSE_TEST))
  204. # If the rule starts with the name of a known keyboard, then continue
  205. # the parsing from PARSE_KEYBOARD
  206. else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true)
  207. $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
  208. # Otherwise use the KEYBOARD variable, which is determined either by
  209. # the current directory you run make from, or passed in as an argument
  210. else ifneq ($$(KEYBOARD),)
  211. $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD)))
  212. else
  213. $$(info make: *** No rule to make target '$1'. Stop.)
  214. # Notice the tab instead of spaces below!
  215. exit 1
  216. endif
  217. endef
  218. # $1 = Keyboard
  219. # Parses a rule in the format <subproject>-<keymap>-<target>
  220. # the keyboard is already known when entering this function
  221. define PARSE_KEYBOARD
  222. CURRENT_KB := $1
  223. # A subproject is any keyboard subfolder with a makefile
  224. SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
  225. # if the rule starts with allsp, then continue with looping over all subprojects
  226. ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true)
  227. $$(eval $$(call PARSE_ALL_SUBPROJECTS))
  228. # A special case for matching the defaultsp (default subproject)
  229. else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,defaultsp),true)
  230. $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
  231. # If the rule starts with the name of a known subproject
  232. else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true)
  233. $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
  234. # Try to use the SUBPROJECT variable, which is either determined by the
  235. # directory which invoked make, or passed as an argument to make
  236. else ifneq ($$(SUBPROJECT),)
  237. $$(eval $$(call PARSE_SUBPROJECT,$$(SUBPROJECT)))
  238. # If there's no matching subproject, we assume it's the default
  239. # This will allow you to leave the subproject part of the target out
  240. else
  241. $$(eval $$(call PARSE_SUBPROJECT,))
  242. endif
  243. endef
  244. # if we are going to compile all keyboards, match the rest of the rule
  245. # for each of them
  246. define PARSE_ALL_KEYBOARDS
  247. $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS)))
  248. endef
  249. # $1 Subproject
  250. # When entering this, the keyboard and subproject are known, so now we need
  251. # to determine which keymaps are going to get compiled
  252. define PARSE_SUBPROJECT
  253. # If we want to compile the default subproject, then we need to
  254. # include the correct makefile to determine the actual name of it
  255. CURRENT_SP := $1
  256. ifeq ($$(CURRENT_SP),)
  257. CURRENT_SP := defaultsp
  258. endif
  259. ifeq ($$(CURRENT_SP),defaultsp)
  260. SUBPROJECT_DEFAULT=
  261. $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile)
  262. CURRENT_SP := $$(SUBPROJECT_DEFAULT)
  263. endif
  264. # If current subproject is empty (the default was not defined), and we have a list of subproject
  265. # then make all of them
  266. ifeq ($$(CURRENT_SP),)
  267. ifneq ($$(SUBPROJECTS),)
  268. CURRENT_SP := allsp
  269. endif
  270. endif
  271. # The special allsp is handled later
  272. ifneq ($$(CURRENT_SP),allsp)
  273. # get a list of all keymaps
  274. KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.)))
  275. ifneq ($$(CURRENT_SP),)
  276. # if the subproject is defined, then also look for keymaps inside the subproject folder
  277. SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.)))
  278. KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS))
  279. endif
  280. # if the rule after removing the start of it is empty (we haven't specified a kemap or target)
  281. # compile all the keymaps
  282. ifeq ($$(RULE),)
  283. $$(eval $$(call PARSE_ALL_KEYMAPS))
  284. # The same if allkm was specified
  285. else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true)
  286. $$(eval $$(call PARSE_ALL_KEYMAPS))
  287. # Try to match the specified keyamp with the list of known keymaps
  288. else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true)
  289. $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
  290. # Otherwise try to match the keymap from the current folder, or arguments to the make command
  291. else ifneq ($$(KEYMAP),)
  292. $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP)))
  293. # No matching keymap found, so we assume that the rest of the rule is the target
  294. # If we haven't been able to parse out a subproject, then make all of them
  295. # This is consistent with running make without any arguments from the keyboard
  296. # folder
  297. else ifeq ($1,)
  298. $$(eval $$(call PARSE_ALL_SUBPROJECTS))
  299. # Otherwise, make all keymaps, again this is consistent with how it works without
  300. # any arguments
  301. else
  302. $$(eval $$(call PARSE_ALL_KEYMAPS))
  303. endif
  304. else
  305. # As earlier mentione,d when allsb is specified, we call our self recursively
  306. # for all of the subprojects
  307. $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS)))
  308. endif
  309. endef
  310. # If we want to parse all subprojects, but the keyboard doesn't have any,
  311. # then use defaultsp instead
  312. define PARSE_ALL_SUBPROJECTS
  313. ifeq ($$(SUBPROJECTS),)
  314. $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
  315. else
  316. $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$$(SUBPROJECTS)))
  317. endif
  318. endef
  319. # $1 Keymap
  320. # This is the meat of compiling a keyboard, when entering this, everything is known
  321. # keyboard, subproject, and keymap
  322. # Note that we are not directly calling the command here, but instead building a list,
  323. # which will later be processed
  324. define PARSE_KEYMAP
  325. CURRENT_KM = $1
  326. # The rest of the rule is the target
  327. # Remove the leading "-" from the target, as it acts as a separator
  328. MAKE_TARGET := $$(patsubst -%,%,$$(RULE))
  329. # We need to generate an unique indentifer to append to the COMMANDS list
  330. COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM)
  331. # If we are compiling a keyboard without a subproject, we want to display just the name
  332. # of the keyboard, otherwise keyboard/subproject
  333. ifeq ($$(CURRENT_SP),)
  334. KB_SP := $(CURRENT_KB)
  335. else
  336. KB_SP := $(CURRENT_KB)/$$(CURRENT_SP)
  337. endif
  338. # Format it in bold
  339. KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR)
  340. # Specify the variables that we are passing forward to submake
  341. MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM)
  342. # And the first part of the make command
  343. MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET)
  344. # The message to display
  345. MAKE_MSG := $$(MSG_MAKE_KB)
  346. # We run the command differently, depending on if we want more output or not
  347. # The true version for silent output and the false version otherwise
  348. $$(eval $$(call BUILD))
  349. endef
  350. define BUILD
  351. MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR)
  352. COMMANDS += $$(COMMAND)
  353. COMMAND_true_$$(COMMAND) := \
  354. printf "$$(MAKE_MSG)" | \
  355. $$(MAKE_MSG_FORMAT); \
  356. LOG=$$$$($$(MAKE_CMD) $$(MAKE_VARS) SILENT=true 2>&1) ; \
  357. if [ $$$$? -gt 0 ]; \
  358. then $$(PRINT_ERROR_PLAIN); \
  359. elif [ "$$$$LOG" != "" ] ; \
  360. then $$(PRINT_WARNING_PLAIN); \
  361. else \
  362. $$(PRINT_OK); \
  363. fi;
  364. COMMAND_false_$$(COMMAND) := \
  365. printf "$$(MAKE_MSG)\n\n"; \
  366. $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; \
  367. if [ $$$$? -gt 0 ]; \
  368. then error_occured=1; \
  369. fi;
  370. endef
  371. # Just parse all the keymaps for a specifc keyboard
  372. define PARSE_ALL_KEYMAPS
  373. $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS)))
  374. endef
  375. define BUILD_TEST
  376. TEST_NAME := $1
  377. MAKE_TARGET := $2
  378. COMMAND := $1
  379. MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET)
  380. MAKE_VARS := TEST=$$(TEST_NAME)
  381. MAKE_MSG := $$(MSG_MAKE_TEST)
  382. $$(eval $$(call BUILD))
  383. ifneq ($$(MAKE_TARGET),clean)
  384. TEST_EXECUTABLE := $$(TEST_DIR)/$$(TEST_NAME).elf
  385. TESTS += $$(TEST_NAME)
  386. TEST_MSG := $$(MSG_TEST)
  387. $$(TEST_NAME)_COMMAND := \
  388. printf "$$(TEST_MSG)\n"; \
  389. $$(TEST_EXECUTABLE); \
  390. if [ $$$$? -gt 0 ]; \
  391. then error_occured=1; \
  392. fi; \
  393. printf "\n";
  394. endif
  395. endef
  396. define PARSE_TEST
  397. TESTS :=
  398. TEST_NAME := $$(firstword $$(subst -, ,$$(RULE)))
  399. TEST_TARGET := $$(subst $$(TEST_NAME),,$$(subst $$(TEST_NAME)-,,$$(RULE)))
  400. ifeq ($$(TEST_NAME),all)
  401. MATCHED_TESTS := $$(TEST_LIST)
  402. else
  403. MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),))
  404. endif
  405. $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET))))
  406. endef
  407. # Set the silent mode depending on if we are trying to compile multiple keyboards or not
  408. # By default it's on in that case, but it can be overriden by specifying silent=false
  409. # from the command line
  410. define SET_SILENT_MODE
  411. ifdef SUB_IS_SILENT
  412. SILENT_MODE := $(SUB_IS_SILENT)
  413. else ifeq ($$(words $$(COMMANDS)),1)
  414. SILENT_MODE := false
  415. else
  416. SILENT_MODE := true
  417. endif
  418. endef
  419. include $(ROOT_DIR)/message.mk
  420. RUN_COMMAND = \
  421. $(COMMAND_$(SILENT_MODE)_$(COMMAND))
  422. # Allow specifying just the subproject, in the keyboard directory, which will compile all keymaps
  423. SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile)))
  424. .PHONY: $(SUBPROJECTS)
  425. $(SUBPROJECTS): %: %-allkm
  426. # Let's match everything, we handle all the rule parsing ourselves
  427. .PHONY: %
  428. %:
  429. # Check if we have the CMP tool installed
  430. cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi;
  431. # Check if the submodules are dirty, and display a warning if they are
  432. git submodule status --recursive 2>/dev/null | \
  433. while IFS= read -r x; do \
  434. case "$$x" in \
  435. \ *) ;; \
  436. *) printf "$(MSG_SUBMODULE_DIRTY)";break;; \
  437. esac \
  438. done
  439. $(eval $(call PARSE_RULE,$@))
  440. $(eval $(call SET_SILENT_MODE))
  441. # Run all the commands in the same shell, notice the + at the first line
  442. # it has to be there to allow parallel execution of the submake
  443. # This always tries to compile everything, even if error occurs in the middle
  444. # But we return the error code at the end, to trigger travis failures
  445. +error_occured=0; \
  446. $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \
  447. if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\
  448. $(foreach TEST,$(TESTS),$($(TEST)_COMMAND)) \
  449. if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi;\
  450. # All should compile everything
  451. .PHONY: all
  452. all: all-keyboards
  453. # Define some shortcuts, mostly for compability with the old syntax
  454. .PHONY: all-keyboards
  455. all-keyboards: allkb-allsp-allkm
  456. .PHONY: all-keyboards-defaults
  457. all-keyboards-defaults: allkb-allsp-default
  458. .PHONY: test
  459. test: test-all
  460. .PHONY: test-clean
  461. test-clean: test-all-clean
  462. # Generate the version.h file
  463. GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S")
  464. BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S")
  465. $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h)
  466. $(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(ROOT_DIR)/quantum/version.h)
  467. include $(ROOT_DIR)/testlist.mk