+#
+# The following variables are functions invoked with "call", and thus
+# behave similarly to externally compiled commands
+#
+
+# $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
+# $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
+# $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
+_function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
+
+# $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
+# $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
+# $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
+_function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
+ $(if $(filter DEFAULT,$(1)), \
+ $(DEFAULT_KERNEL_CONFIG), \
+ $(1) \
+ ), \
+ $(if $(filter DEFAULT,$(2)), \
+ $(DEFAULT_ARCH_CONFIG), \
+ $(2) \
+ ), \
+ $(if $(filter DEFAULT,$(3)), \
+ $(if $(filter DEFAULT,$(2)), \
+ $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
+ $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
+ ), \
+ $(3) \
+ ) \
+ )
+
+# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
+# 3 elements at a time
+function_create_build_configs = $(sort \
+ $(strip \
+ $(call _function_create_build_configs_do_expand, \
+ $(word 1,$(1)), \
+ $(word 2,$(1)), \
+ $(word 3,$(1)), \
+ ) \
+ $(if $(word 4,$(1)), \
+ $(call function_create_build_configs, \
+ $(wordlist 4,$(words $(1)),$(1)) \
+ ), \
+ \
+ ) \
+ ) \
+ )
+
+# $(1) is a fully-expanded kernel config
+# $(2) is a fully-expanded arch config
+# $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
+function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
+
+# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
+function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
+ $(word 1,$(subst ^, ,$(1))), \
+ $(word 2,$(subst ^, ,$(1))), \
+ $(word 3,$(subst ^, ,$(1))) \
+ )
+
+# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
+function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
+function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
+function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
+
+# $(1) is an input word
+# $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
+# $(3) is a fallback if no substitutions were made
+function_substitute_word_with_replacement = $(strip $(if $(2), \
+ $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
+ $(word 2,$(subst :, ,$(word 1,$(2)))), \
+ $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
+ $(3) \
+ ) \
+ )
+
+# You can't assign a variable to an empty space without these
+# shenanigans
+empty :=
+space := $(empty) $(empty)
+
+# Arithmetic
+# $(1) is the number to increment
+NUM16 = x x x x x x x x x x x x x x x x
+increment = $(words x $(wordlist 1,$(1),$(NUM16)))
+