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.

562 lines
20 KiB

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