aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-08-20 14:53:29 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-08-20 14:53:29 +0300
commitb26ded3ab1c09e2a127feb5f4e22e97242ce77d7 (patch)
treef57e0a347d1ecd73dd2df1e5a1c419df404f650a
parent48f8ab1ae2612960cbd82c1f9967fd118aae4c67 (diff)
downloadqmk_firmware-b26ded3ab1c09e2a127feb5f4e22e97242ce77d7.tar.gz
qmk_firmware-b26ded3ab1c09e2a127feb5f4e22e97242ce77d7.zip
Comment the Makefile
Also move some messages to message.mk
-rw-r--r--Makefile129
-rw-r--r--message.mk13
2 files changed, 124 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 9ca73b4ad..d70ac9a3b 100644
--- a/Makefile
+++ b/Makefile
@@ -2,15 +2,18 @@ ifndef VERBOSE
2.SILENT: 2.SILENT:
3endif 3endif
4 4
5# Allow the silent with lower caps to work the same way as upper caps
5ifdef silent 6ifdef silent
6 SILENT = $(silent) 7 SILENT = $(silent)
7endif 8endif
8 9
9ifdef SILENT 10ifdef SILENT
10 SUB_IS_SILENT := $(silent) 11 SUB_IS_SILENT := $(SILENT)
11endif 12endif
12 13
13override SILENT = false 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
16override SILENT := false
14 17
15ON_ERROR := error_occured=1 18ON_ERROR := error_occured=1
16 19
@@ -26,27 +29,44 @@ ABS_STARTING_DIR := $(dir $(ABS_STARTING_MAKEFILE))
26ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE)) 29ABS_ROOT_DIR := $(dir $(ABS_ROOT_MAKEFILE))
27STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR)) 30STARTING_DIR := $(subst $(ABS_ROOT_DIR),,$(ABS_STARTING_DIR))
28 31
29PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR))
30
31MAKEFILE_INCLUDED=yes 32MAKEFILE_INCLUDED=yes
32 33
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
33define NEXT_PATH_ELEMENT 38define NEXT_PATH_ELEMENT
34 $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS))) 39 $$(eval CURRENT_PATH_ELEMENT := $$(firstword $$(PATH_ELEMENTS)))
35 $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS))) 40 $$(eval PATH_ELEMENTS := $$(wordlist 2,9999,$$(PATH_ELEMENTS)))
36endef 41endef
37 42
43# We change the / to spaces so that we more easily can work with the elements
44# separately
45PATH_ELEMENTS := $(subst /, ,$(STARTING_DIR))
46# Initialize the path elements list for further processing
38$(eval $(call NEXT_PATH_ELEMENT)) 47$(eval $(call NEXT_PATH_ELEMENT))
39 48
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
40ifeq ($(CURRENT_PATH_ELEMENT),keyboards) 54ifeq ($(CURRENT_PATH_ELEMENT),keyboards)
41 $(eval $(call NEXT_PATH_ELEMENT)) 55 $(eval $(call NEXT_PATH_ELEMENT))
42 KEYBOARD := $(CURRENT_PATH_ELEMENT) 56 KEYBOARD := $(CURRENT_PATH_ELEMENT)
43 $(eval $(call NEXT_PATH_ELEMENT)) 57 $(eval $(call NEXT_PATH_ELEMENT))
58 # If we are in a subfolder of keymaps, or in other words in a keymap
59 # folder
44 ifeq ($(CURRENT_PATH_ELEMENT),keymaps) 60 ifeq ($(CURRENT_PATH_ELEMENT),keymaps)
45 $(eval $(call NEXT_PATH_ELEMENT)) 61 $(eval $(call NEXT_PATH_ELEMENT))
46 KEYMAP := $(CURRENT_PATH_ELEMENT) 62 KEYMAP := $(CURRENT_PATH_ELEMENT)
63 # else if we are not in the keyboard folder itself
47 else ifneq ($(CURRENT_PATH_ELEMENT),) 64 else ifneq ($(CURRENT_PATH_ELEMENT),)
65 # the we can assume it's a subproject, as no other folders
66 # should have make files in them
48 SUBPROJECT := $(CURRENT_PATH_ELEMENT) 67 SUBPROJECT := $(CURRENT_PATH_ELEMENT)
49 $(eval $(call NEXT_PATH_ELEMENT)) 68 $(eval $(call NEXT_PATH_ELEMENT))
69 # if we are inside a keymap folder of a subproject
50 ifeq ($(CURRENT_PATH_ELEMENT),keymaps) 70 ifeq ($(CURRENT_PATH_ELEMENT),keymaps)
51 $(eval $(call NEXT_PATH_ELEMENT)) 71 $(eval $(call NEXT_PATH_ELEMENT))
52 KEYMAP := $(CURRENT_PATH_ELEMENT) 72 KEYMAP := $(CURRENT_PATH_ELEMENT)
@@ -57,7 +77,8 @@ endif
57# Only consider folders with makefiles, to prevent errors in case there are extra folders 77# Only consider folders with makefiles, to prevent errors in case there are extra folders
58KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile))) 78KEYBOARDS := $(notdir $(patsubst %/Makefile,%,$(wildcard $(ROOT_DIR)/keyboards/*/Makefile)))
59 79
60#Compability with the old make variables 80#Compability with the old make variables, anything you specify directly on the command line
81# always overrides the detected folders
61ifdef keyboard 82ifdef keyboard
62 KEYBOARD := $(keyboard) 83 KEYBOARD := $(keyboard)
63endif 84endif
@@ -71,29 +92,41 @@ ifdef keymap
71 KEYMAP := $(keymap) 92 KEYMAP := $(keymap)
72endif 93endif
73 94
95# Uncomment these for debugging
74#$(info Keyboard: $(KEYBOARD)) 96#$(info Keyboard: $(KEYBOARD))
75#$(info Keymap: $(KEYMAP)) 97#$(info Keymap: $(KEYMAP))
76#$(info Subproject: $(SUBPROJECT)) 98#$(info Subproject: $(SUBPROJECT))
77#$(info Keyboards: $(KEYBOARDS)) 99#$(info Keyboards: $(KEYBOARDS))
78 100
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
79.DEFAULT_GOAL := all 104.DEFAULT_GOAL := all
80ifneq ($(KEYMAP),) 105ifneq ($(KEYMAP),)
81 ifeq ($(SUBPROJECT),) 106 ifeq ($(SUBPROJECT),)
107 # Inside a keymap folder, just build the keymap, with the
108 # default subproject
82 .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP) 109 .DEFAULT_GOAL := $(KEYBOARD)-$(KEYMAP)
83 else 110 else
111 # Inside a subproject keyamp folder, build the keymap
112 # for that subproject
84 .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-$(KEYMAP) 113 .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-$(KEYMAP)
85 endif 114 endif
86else ifneq ($(SUBPROJECT),) 115else ifneq ($(SUBPROJECT),)
116 # Inside a subproject folder, build all keymaps for that subproject
87 .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-allkm 117 .DEFAULT_GOAL := $(KEYBOARD)-$(SUBPROJECT)-allkm
88else ifneq ($(KEYBOARD),) 118else ifneq ($(KEYBOARD),)
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
89 .DEFAULT_GOAL := $(KEYBOARD)-allsp-allkm 122 .DEFAULT_GOAL := $(KEYBOARD)-allsp-allkm
90endif 123endif
91 124
92 125
93# Compare the start of the RULE_VARIABLE with the first argument($1) 126# Compare the start of the RULE variable with the first argument($1)
94# If the rules equals $1 or starts with $1-, RULE_FOUND is set to true 127# If the rules equals $1 or starts with $1-, RULE_FOUND is set to true
95# and $1 is removed from the RULE variable 128# and $1 is removed from the RULE variable
96# Otherwise the RULE_FOUND variable is set to false 129# Otherwise the RULE_FOUND variable is set to false, and RULE left as it was
97# The function is a bit tricky, since there's no built in $(startswith) function 130# The function is a bit tricky, since there's no built in $(startswith) function
98define COMPARE_AND_REMOVE_FROM_RULE_HELPER 131define COMPARE_AND_REMOVE_FROM_RULE_HELPER
99 ifeq ($1,$$(RULE)) 132 ifeq ($1,$$(RULE))
@@ -110,10 +143,12 @@ define COMPARE_AND_REMOVE_FROM_RULE_HELPER
110 endif 143 endif
111endef 144endef
112 145
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
113COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND) 148COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND)
114 149
115 150
116# Recursively try to find a match 151# Recursively try to find a match for the start of the rule to be checked
117# $1 The list to be checked 152# $1 The list to be checked
118# If a match is found, then RULE_FOUND is set to true 153# If a match is found, then RULE_FOUND is set to true
119# and MATCHED_ITEM to the item that was matched 154# and MATCHED_ITEM to the item that was matched
@@ -127,6 +162,7 @@ define TRY_TO_MATCH_RULE_FROM_LIST_HELPER
127 endif 162 endif
128endef 163endef
129 164
165# Make it easier to call TRY_TO_MATCH_RULE_FROM_LIST
130TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND) 166TRY_TO_MATCH_RULE_FROM_LIST = $(eval $(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER,$1))$(RULE_FOUND)
131 167
132define ALL_IN_LIST_LOOP 168define ALL_IN_LIST_LOOP
@@ -139,47 +175,70 @@ define PARSE_ALL_IN_LIST
139 $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1))) 175 $$(foreach ITEM$1,$2,$$(eval $$(call ALL_IN_LIST_LOOP,$1)))
140endef 176endef
141 177
178# The entry point for rule parsing
179# parses a rule in the format <keyboard>-<subproject>-<keymap>-<target>
180# but this particular function only deals with the first <keyboard> part
142define PARSE_RULE 181define PARSE_RULE
143 RULE := $1 182 RULE := $1
144 COMMANDS := 183 COMMANDS :=
184 # If the rule starts with allkb, then continue the parsing from
185 # PARSE_ALL_KEYBOARDS
145 ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true) 186 ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkb),true)
146 $$(eval $$(call PARSE_ALL_KEYBOARDS)) 187 $$(eval $$(call PARSE_ALL_KEYBOARDS))
188 # If the rule starts with the name of a known keyboard, then continue
189 # the parsing from PARSE_KEYBOARD
147 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true) 190 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYBOARDS)),true)
148 $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM))) 191 $$(eval $$(call PARSE_KEYBOARD,$$(MATCHED_ITEM)))
192 # Otherwise use the KEYBOARD variable, which is determined either by
193 # the current directory you run make from, or passed in as an argument
149 else ifneq ($$(KEYBOARD),) 194 else ifneq ($$(KEYBOARD),)
150 $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD))) 195 $$(eval $$(call PARSE_KEYBOARD,$$(KEYBOARD)))
151 else 196 else
152 $$(info make: *** No rule to make target '$1'. Stop.) 197 $$(info make: *** No rule to make target '$1'. Stop.)
198 # Notice the tab instead of spaces below!
153 exit 1 199 exit 1
154 endif 200 endif
155endef 201endef
156 202
157# $1 = Keyboard 203# $1 = Keyboard
204# Parses a rule in the format <subproject>-<keymap>-<target>
205# the keyboard is already known when entering this function
158define PARSE_KEYBOARD 206define PARSE_KEYBOARD
159 CURRENT_KB := $1 207 CURRENT_KB := $1
160 # A subproject is any keyboard subfolder with a makefile 208 # A subproject is any keyboard subfolder with a makefile
161 SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile))) 209 SUBPROJECTS := $$(notdir $$(patsubst %/Makefile,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/*/Makefile)))
210 # if the rule starts with allsp, then continue with looping over all subprojects
162 ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true) 211 ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allsp),true)
163 $$(eval $$(call PARSE_ALL_SUBPROJECTS)) 212 $$(eval $$(call PARSE_ALL_SUBPROJECTS))
213 # A special case for matching the defaultsp (default subproject)
164 else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,defaultsp),true) 214 else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,defaultsp),true)
165 $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) 215 $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
216 # If the rule starts with the name of a known subproject
166 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true) 217 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(SUBPROJECTS)),true)
167 $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM))) 218 $$(eval $$(call PARSE_SUBPROJECT,$$(MATCHED_ITEM)))
219 # Try to use the SUBPROJECT variable, which is either determined by the
220 # directory which invoked make, or passed as an argument to make
168 else ifneq ($$(SUBPROJECT),) 221 else ifneq ($$(SUBPROJECT),)
169 $$(eval $$(call PARSE_SUBPROJECT,$$(SUBPROJECT))) 222 $$(eval $$(call PARSE_SUBPROJECT,$$(SUBPROJECT)))
223 # If there's no matching subproject, we assume it's the default
224 # This will allow you to leave the subproject part of the target out
170 else 225 else
171 # If there's no matching subproject, we assume it's the default
172 # This will allow you to leave the subproject part of the target out
173 $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) 226 $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
174 endif 227 endif
175endef 228endef
176 229
230# if we are going to compile all keyboards, match the rest of the rule
231# for each of them
177define PARSE_ALL_KEYBOARDS 232define PARSE_ALL_KEYBOARDS
178 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS))) 233 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYBOARD,$(KEYBOARDS)))
179endef 234endef
180 235
181# $1 Subproject 236# $1 Subproject
237# When entering this, the keyboard and subproject are known, so now we need
238# to determine which keymaps are going to get compiled
182define PARSE_SUBPROJECT 239define PARSE_SUBPROJECT
240 # If we want to compile the default subproject, then we need to
241 # include the correct makefile to determine the actual name of it
183 ifeq ($1,defaultsp) 242 ifeq ($1,defaultsp)
184 SUBPROJECT_DEFAULT= 243 SUBPROJECT_DEFAULT=
185 $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile) 244 $$(eval include $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/Makefile)
@@ -188,39 +247,54 @@ define PARSE_SUBPROJECT
188 CURRENT_SP := $1 247 CURRENT_SP := $1
189 endif 248 endif
190 # If current subproject is empty (the default was not defined), and we have a list of subproject 249 # If current subproject is empty (the default was not defined), and we have a list of subproject
191 # then make all 250 # then make all of them
192 ifeq ($$(CURRENT_SP),) 251 ifeq ($$(CURRENT_SP),)
193 ifneq ($$(SUBPROJECTS),) 252 ifneq ($$(SUBPROJECTS),)
194 CURRENT_SP := allsp 253 CURRENT_SP := allsp
195 endif 254 endif
196 endif 255 endif
256 # The special allsp is handled later
197 ifneq ($$(CURRENT_SP),allsp) 257 ifneq ($$(CURRENT_SP),allsp)
258 # get a list of all keymaps
198 KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.))) 259 KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/keymaps/*/.)))
199 ifneq ($$(CURRENT_SP),) 260 ifneq ($$(CURRENT_SP),)
261 # if the subproject is defined, then also look for keymaps inside the subproject folder
200 SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.))) 262 SP_KEYMAPS := $$(notdir $$(patsubst %/.,%,$$(wildcard $(ROOT_DIR)/keyboards/$$(CURRENT_KB)/$$(CURRENT_SP)/keymaps/*/.)))
201 KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS)) 263 KEYMAPS := $$(sort $$(KEYMAPS) $$(SP_KEYMAPS))
202 endif 264 endif
265 # if the rule after removing the start of it is empty (we haven't specified a kemap or target)
266 # compile all the keymaps
203 ifeq ($$(RULE),) 267 ifeq ($$(RULE),)
204 $$(eval $$(call PARSE_ALL_KEYMAPS)) 268 $$(eval $$(call PARSE_ALL_KEYMAPS))
269 # The same if allkm was specified
205 else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true) 270 else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,allkm),true)
206 $$(eval $$(call PARSE_ALL_KEYMAPS)) 271 $$(eval $$(call PARSE_ALL_KEYMAPS))
272 # Try to match the specified keyamp with the list of known keymaps
207 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true) 273 else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true)
208 $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM))) 274 $$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
275 # Otherwise try to match the keymap from the current folder, or arguments to the make command
209 else ifneq ($$(KEYMAP),) 276 else ifneq ($$(KEYMAP),)
210 $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP))) 277 $$(eval $$(call PARSE_KEYMAP,$$(KEYMAP)))
211 else 278 else
279 # Otherwise something is wrong with the target
280 # Try to give as much information as possible of what it it was trying to do
212 ifeq ($$(CURRENT_SP),) 281 ifeq ($$(CURRENT_SP),)
213 $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.) 282 $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(RULE)'. Stop.)
214 else 283 else
215 $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(CURRENT_SP)-$$(RULE)'. Stop.) 284 $$(info make: *** No rule to make target '$$(CURRENT_KB)-$$(CURRENT_SP)-$$(RULE)'. Stop.)
216 endif 285 endif
286 # Notice the tab instead of spaces below!
217 exit 1 287 exit 1
218 endif 288 endif
219 else 289 else
290 # As earlier mentione,d when allsb is specified, we call our self recursively
291 # for all of the subprojects
220 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS))) 292 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_SUBPROJECT,$(SUBPROJECTS)))
221 endif 293 endif
222endef 294endef
223 295
296# If we want to parse all subprojects, but the keyboard doesn't have any,
297# then use defaultsp instead
224define PARSE_ALL_SUBPROJECTS 298define PARSE_ALL_SUBPROJECTS
225 ifeq ($$(SUBPROJECTS),) 299 ifeq ($$(SUBPROJECTS),)
226 $$(eval $$(call PARSE_SUBPROJECT,defaultsp)) 300 $$(eval $$(call PARSE_SUBPROJECT,defaultsp))
@@ -230,27 +304,36 @@ define PARSE_ALL_SUBPROJECTS
230endef 304endef
231 305
232# $1 Keymap 306# $1 Keymap
307# This is the meat of compiling a keyboard, when entering this, everything is known
308# keyboard, subproject, and keymap
309# Note that we are not directly calling the command here, but instead building a list,
310# which will later be processed
233define PARSE_KEYMAP 311define PARSE_KEYMAP
234 CURRENT_KM = $1 312 CURRENT_KM = $1
235 # The rest of the rule is the target 313 # The rest of the rule is the target
236 # Remove the leading "-" from the target, as it acts as a separator 314 # Remove the leading "-" from the target, as it acts as a separator
237 MAKE_TARGET := $$(patsubst -%,%,$$(RULE)) 315 MAKE_TARGET := $$(patsubst -%,%,$$(RULE))
316 # We need to generate an unique indentifer to append to the COMMANDS list
238 COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM) 317 COMMAND := COMMAND_KEYBOARD_$$(CURRENT_KB)_SUBPROJECT_$(CURRENT_SP)_KEYMAP_$$(CURRENT_KM)
239 COMMANDS += $$(COMMAND) 318 COMMANDS += $$(COMMAND)
319 # If we are compiling a keyboard without a subproject, we want to display just the name
320 # of the keyboard, otherwise keyboard/subproject
240 ifeq ($$(CURRENT_SP),) 321 ifeq ($$(CURRENT_SP),)
241 KB_SP := $(CURRENT_KB) 322 KB_SP := $(CURRENT_KB)
242 else 323 else
243 KB_SP := $(CURRENT_KB)/$$(CURRENT_SP) 324 KB_SP := $(CURRENT_KB)/$$(CURRENT_SP)
244 endif 325 endif
326 # Format it in bold
245 KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR) 327 KB_SP := $(BOLD)$$(KB_SP)$(NO_COLOR)
328 # Specify the variables that we are passing forward to submake
246 MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM) 329 MAKE_VARS := KEYBOARD=$$(CURRENT_KB) SUBPROJECT=$$(CURRENT_SP) KEYMAP=$$(CURRENT_KM)
247 MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR) 330 MAKE_VARS += VERBOSE=$(VERBOSE) COLOR=$(COLOR)
331 # And the first part of the make command
248 MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET) 332 MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_keyboard.mk $$(MAKE_TARGET)
249 MAKE_MSG := Making $$(KB_SP) with keymap $(BOLD)$$(CURRENT_KM)$(NO_COLOR) 333 # The message to display
250 ifneq ($$(MAKE_TARGET),) 334 MAKE_MSG := $$(MSG_MAKE_KB)
251 MAKE_MSG += and target $(BOLD)$$(MAKE_TARGET)$(NO_COLOR) 335 # We run the command differently, depending on if we want more output or not
252 endif 336 # The true version for silent output and the false version otherwise
253 MAKE_MSG_FORMAT := $(AWK) '{ printf "%-118s", $$$$0;}'
254 COMMAND_true_$$(COMMAND) := \ 337 COMMAND_true_$$(COMMAND) := \
255 printf "$$(MAKE_MSG)" | \ 338 printf "$$(MAKE_MSG)" | \
256 $$(MAKE_MSG_FORMAT); \ 339 $$(MAKE_MSG_FORMAT); \
@@ -267,10 +350,14 @@ define PARSE_KEYMAP
267 $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false; 350 $$(MAKE_CMD) $$(MAKE_VARS) SILENT=false;
268endef 351endef
269 352
353# Just parse all the keymaps for a specifc keyboard
270define PARSE_ALL_KEYMAPS 354define PARSE_ALL_KEYMAPS
271 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS))) 355 $$(eval $$(call PARSE_ALL_IN_LIST,PARSE_KEYMAP,$$(KEYMAPS)))
272endef 356endef
273 357
358# Set the silent mode depending on if we are trying to compile multiple keyboards or not
359# By default it's on in that case, but it can be overriden by specifying silent=false
360# from the command line
274define SET_SILENT_MODE 361define SET_SILENT_MODE
275 ifdef SUB_IS_SILENT 362 ifdef SUB_IS_SILENT
276 SILENT_MODE := $(SUB_IS_SILENT) 363 SILENT_MODE := $(SUB_IS_SILENT)
@@ -291,9 +378,12 @@ SUBPROJECTS := $(notdir $(patsubst %/Makefile,%,$(wildcard ./*/Makefile)))
291.PHONY: $(SUBPROJECTS) 378.PHONY: $(SUBPROJECTS)
292$(SUBPROJECTS): %: %-allkm 379$(SUBPROJECTS): %: %-allkm
293 380
381# Let's match everything, we handle all the rule parsing ourselves
294.PHONY: % 382.PHONY: %
295%: 383%:
384 # Check if we have the CMP tool installed
296 cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; 385 cmp --version >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi;
386 # Check if the submodules are dirty, and display a warning if they are
297 git submodule status --recursive 2>/dev/null | \ 387 git submodule status --recursive 2>/dev/null | \
298 while IFS= read -r x; do \ 388 while IFS= read -r x; do \
299 case "$$x" in \ 389 case "$$x" in \
@@ -303,14 +393,20 @@ $(SUBPROJECTS): %: %-allkm
303 done 393 done
304 $(eval $(call PARSE_RULE,$@)) 394 $(eval $(call PARSE_RULE,$@))
305 $(eval $(call SET_SILENT_MODE)) 395 $(eval $(call SET_SILENT_MODE))
396 # Run all the commands in the same shell, notice the + at the first line
397 # it has to be there to allow parallel execution of the submake
398 # This always tries to compile everything, even if error occurs in the middle
399 # But we return the error code at the end, to trigger travis failures
306 +error_occured=0; \ 400 +error_occured=0; \
307 $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \ 401 $(foreach COMMAND,$(COMMANDS),$(RUN_COMMAND)) \
308 if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi 402 if [ $$error_occured -gt 0 ]; then printf "$(MSG_ERRORS)" & exit $$error_occured; fi
309 403
310 404
405# All should compile everything
311.PHONY: all 406.PHONY: all
312all: all-keyboards 407all: all-keyboards
313 408
409# Define some shortcuts, mostly for compability with the old syntax
314.PHONY: all-keyboards 410.PHONY: all-keyboards
315all-keyboards: allkb-allsp-allkm 411all-keyboards: allkb-allsp-allkm
316 412
@@ -318,6 +414,7 @@ all-keyboards: allkb-allsp-allkm
318all-keyboards-defaults: allkb-allsp-default 414all-keyboards-defaults: allkb-allsp-default
319 415
320 416
417# Generate the version.h file
321GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") 418GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S")
322BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") 419BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S")
323$(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h) 420$(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(ROOT_DIR)/quantum/version.h)
diff --git a/message.mk b/message.mk
index f8fd38712..fb1a7a1f9 100644
--- a/message.mk
+++ b/message.mk
@@ -31,7 +31,7 @@ PRINT_ERROR_PLAIN = ($(SILENT) ||printf " $(ERROR_STRING)" | $(AWK_STATUS)) && $
31PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN) 31PRINT_WARNING_PLAIN = ($(SILENT) || printf " $(WARN_STRING)" | $(AWK_STATUS)) && $(TAB_LOG_PLAIN)
32PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS) 32PRINT_OK = $(SILENT) || printf " $(OK_STRING)" | $(AWK_STATUS)
33BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi; 33BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [ "$$LOG" != "" ] ; then $(PRINT_WARNING); else $(PRINT_OK); fi;
34MSG_NO_CMP = $(ERROR_COLOR)Error:$(NO_COLOR)$(BOLD) cmp command not found, please install diffutils\n$(NO_COLOR) 34MAKE_MSG_FORMAT = $(AWK) '{ printf "%-118s", $$0;}'
35 35
36# Define Messages 36# Define Messages
37# English 37# English
@@ -59,4 +59,13 @@ MSG_SUBMODULE_DIRTY = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
59 git submodule sync --recursive\n\ 59 git submodule sync --recursive\n\
60 git submodule update --init --recursive$(NO_COLOR)\n\n\ 60 git submodule update --init --recursive$(NO_COLOR)\n\n\
61 You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\ 61 You can ignore this warning if you are not compiling any ChibiOS keyboards,\n\
62 or if you have modified the ChibiOS libraries yourself. \n\n \ No newline at end of file 62 or if you have modified the ChibiOS libraries yourself. \n\n
63MSG_NO_CMP = $(ERROR_COLOR)Error:$(NO_COLOR)$(BOLD) cmp command not found, please install diffutils\n$(NO_COLOR)
64
65define GENERATE_MSG_MAKE_KB
66 MSG_MAKE_KB_ACTUAL := Making $$(KB_SP) with keymap $(BOLD)$$(CURRENT_KM)$(NO_COLOR)
67 ifneq ($$(MAKE_TARGET),)
68 MSG_MAKE_KB_ACTUAL += and target $(BOLD)$$(MAKE_TARGET)$(NO_COLOR)
69 endif
70endef
71MSG_MAKE_KB = $(eval $(call GENERATE_MSG_MAKE_KB))$(MSG_MAKE_KB_ACTUAL)