build: Move misc helpers to make/utility.mk.
This commit is contained in:
parent
f0d1278458
commit
3d2a7a09af
2 changed files with 30 additions and 7 deletions
|
@ -32,6 +32,8 @@ ifeq ($(SRCDIR),)
|
||||||
foo := $(error SRCDIR not set, do not include makefile_base directly, run ./configure.sh to generate Makefile)
|
foo := $(error SRCDIR not set, do not include makefile_base directly, run ./configure.sh to generate Makefile)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
include $(SRC)/make/utility.mk
|
||||||
|
|
||||||
# If CC is coming from make's defaults or nowhere, use our own default. Otherwise respect environment.
|
# If CC is coming from make's defaults or nowhere, use our own default. Otherwise respect environment.
|
||||||
ifeq ($(ENABLE_CCACHE),1)
|
ifeq ($(ENABLE_CCACHE),1)
|
||||||
CCACHE_BIN := ccache
|
CCACHE_BIN := ccache
|
||||||
|
@ -137,13 +139,6 @@ SANITY_FLAGS := -fwrapv -fno-strict-aliasing
|
||||||
COMMON_FLAGS := $(OPTIMIZE_FLAGS) $(SANITY_FLAGS)
|
COMMON_FLAGS := $(OPTIMIZE_FLAGS) $(SANITY_FLAGS)
|
||||||
CARGO_BUILD_ARG := --release
|
CARGO_BUILD_ARG := --release
|
||||||
|
|
||||||
# Use $(call QUOTE,$(VAR)) to flatten a list to a single element (for feeding to a shell)
|
|
||||||
|
|
||||||
# v-- This flattens a list when called. Don't look directly into it.
|
|
||||||
QUOTE = $(subst $(eval) ,\ ,$(1))
|
|
||||||
QUOTE_VARIABLE = $(eval $(1) := $$(call QUOTE,$$($(1))))
|
|
||||||
QUOTE_VARIABLE_LIST = $(foreach a,$(1),$(call QUOTE_VARIABLE,$(a)))
|
|
||||||
|
|
||||||
# These variables might need to be quoted, but might not
|
# These variables might need to be quoted, but might not
|
||||||
#
|
#
|
||||||
# That is, $(STRIP) is how you invoke strip, STRIP=$(STRIP_QUOTED) is how you pass it to a shell script properly
|
# That is, $(STRIP) is how you invoke strip, STRIP=$(STRIP_QUOTED) is how you pass it to a shell script properly
|
||||||
|
|
28
make/utility.mk
Normal file
28
make/utility.mk
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
empty =
|
||||||
|
space = $(empty) $(empty)
|
||||||
|
comma = ,
|
||||||
|
quote = '
|
||||||
|
double-quote = "
|
||||||
|
|
||||||
|
define newline
|
||||||
|
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
||||||
|
escape = $(subst $(space),\$(space),$(subst $(double-quote),\$(double-quote),$(1)))
|
||||||
|
|
||||||
|
list-join = $(if $(2),$(3)$(subst $(space),$(1),$(strip $(2)))$(4))
|
||||||
|
list-quote = $(call list-join,$(quote)$(comma)$(quote),$(1),$(2)$(quote),$(quote)$(3))
|
||||||
|
list-double-quote = $(call list-join,$(double-quote)$(space)$(double-quote),$(1),$(2)$(double-quote),$(double-quote)$(3))
|
||||||
|
|
||||||
|
head = $(word 1,$(1))
|
||||||
|
tail = $(wordlist 2,$(words $(1)),$(1))
|
||||||
|
|
||||||
|
translate = $(if $(1),$(call translate,$(call tail,$(1)),$(call tail,$(2)),$$(subst $(call head,$(1)),$(call head,$(2)),$(3))),$(3))
|
||||||
|
reverse = $(if $(1),$(call reverse,$(call tail,$(1)) $(call head,$(1))))
|
||||||
|
|
||||||
|
[lower] := a b c d e f g h i j k l m n o p q r s t u v w x y z - .
|
||||||
|
[upper] := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ _
|
||||||
|
|
||||||
|
$(eval toupper = $(call translate,$([lower]),$([upper]),$$(1)))
|
||||||
|
$(eval tolower = $(call translate,$([upper]),$([lower]),$$(1)))
|
Loading…
Reference in a new issue