2 # vim:set ts=8 sw=8 sts=8 noet:
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 # You can obtain one at http://mozilla.org/MPL/2.0/.
8 ## Identify function argument types
9 istype
=$(if
$(value
${1}),list
,scalar
)
10 isval
=$(if
$(filter-out list
,$(call istype
,${1})),true
)
11 isvar
=$(if
$(filter-out scalar
,$(call istype
,${1})),true
)
13 # Access up to 9 arguments passed, option needed to emulate $*
14 # Inline for function expansion, do not use $(call )
16 argv
+=$(if
$(1), $(1))$(if
$(2), $(2))$(if
$(3), $(3))$(if
$(4), $(4))
17 argv
+=$(if
$(5), $(5))$(if
$(6), $(6))$(if
$(7), $(7))$(if
$(8), $(8))
18 argv
+=$(if
$(9), $(9))
19 argv
+=$(if
$(10), $(error makeutils.mk
::argv can only handle
9 arguments
))
22 ###########################################################################
23 ## Access function args as a simple list, inline within user functions.
24 ## Usage: $(info ** $(call banner,$(getargv)))
25 ## $(call banner,scalar)
26 ## $(call banner,list0 list1 list2)
27 ## $(call banner,ref) ; ref=foo bar tans
28 ## getarglist() would be a more accurate name but is longer to type
29 getargv
= $(if
$(call isvar
,$(1)),$($(1)),$(argv
))
31 ###########################################################################
32 # Strip [n] leading options from an argument list. This will allow passing
33 # extra args to user functions that will not propogate to sub-$(call )'s
34 # Usage: $(call subargv,2)
35 subargv
=$(wordlist
$(1),$(words $(getargv
)),$(getargv
))
37 ###########################################################################
38 # Intent: Display a distinct banner heading in the output stream
39 # Usage: $(call banner,BUILDING: foo bar tans)
42 # $(call banner,target-preqs-BEGIN) \
44 # $(call banner,target-preqs-END) \
46 # target: $(target-preqs)
50 $(info ***************************************************************************) \
51 $(info ** $(getargv
)) \
52 $(info ***************************************************************************) \
55 #####################################################################
56 # Intent: Determine if a string or pattern is contained in a list
57 # Usage: strcmp - $(call if_XinY,clean,$(MAKECMDGOALS))
58 # : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS))
59 is_XinY
=$(filter $(1),$(call subargv
,3,$(getargv
)))
61 #####################################################################
62 # Provide an alternate var to support testing
63 ifdef MAKEUTILS_UNIT_TEST
64 mcg_goals
=TEST_MAKECMDGOALS
66 mcg_goals
=MAKECMDGOALS
69 # Intent: Conditionals for detecting common/tier target use
70 isTargetStem
= $(sort \
71 $(foreach var
,$(getargv
),\
72 $(foreach pat
,$(var
)% %$(var
),\
73 $(call is_XinY
,$(pat
),${$(mcg_goals
)})\
75 isTargetStemClean
= $(call isTargetStem
,clean)
76 isTargetStemExport
= $(call isTargetStem
,export)
77 isTargetStemLibs
= $(call isTargetStem
,libs
)
78 isTargetStemTools
= $(call isTargetStem
,tools
)
80 ##################################################
81 # Intent: Validation functions / unit test helpers
83 errorifneq
=$(if
$(subst $(strip $(1)),$(NULL
),$(strip $(2))),$(error expected
[$(1)] but found
[$(2)]))
85 # Intent: verify function declaration exists
86 requiredfunction
=$(foreach func
,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if
$(value
$(func
)),$(NULL
),$(error required function
[$(func
)] is unavailable
)))
90 ## http://www.gnu.org/software/make/manual/make.html#Call-Function
91 ## Usage: o = $(call map,origin,o map $(MAKE))
92 map
= $(foreach val
,$(2),$(call
$(1),$(val
)))
95 ## Disable checking for clean targets
96 ifeq (,$(filter %clean clean%,$(MAKECMDGOALS
))) #{
98 # Usage: $(call checkIfEmpty,[error|warning] foo NULL bar)
99 checkIfEmpty
=$(foreach var
,$(wordlist
2,100,$(argv
)),$(if
$(strip $($(var
))),$(NOP
),$(call
$(1),Variable
$(var
) does not contain a value
)))
101 # Usage: $(call errorIfEmpty,foo NULL bar)
102 errorIfEmpty
=$(call checkIfEmpty
,error
$(argv
))
103 warnIfEmpty
=$(call checkIfEmpty
,warning
$(argv
))
107 ###########################################################################
108 ## Common makefile library loader
109 ###########################################################################
111 topORerr
= $(MOZILLA_DIR
)
113 topORerr
= $(if
$(topsrcdir
),$(topsrcdir
),$(error topsrcdir is not defined
))
116 ifdef USE_AUTOTARGETS_MK
# mkdir_deps
117 include $(topORerr
)/config
/makefiles
/autotargets.mk
120 ## copy(src, dst): recursive copy
121 copy_dir
= (cd
$(1)/.
&& $(TAR
) $(TAR_CREATE_FLAGS
) - .
) |
(cd
$(2)/.
&& tar -xf
-)