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