You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

518 lines
19 KiB

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