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.

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