| 1 |
# -*- makefile -*- |
| 2 |
# vim:set ts=8 sw=8 sts=8 noet: |
| 3 |
# |
| 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/. |
| 7 |
|
| 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) |
| 12 |
|
| 13 |
# Access up to 9 arguments passed, option needed to emulate $* |
| 14 |
# Inline for function expansion, do not use $(call ) |
| 15 |
argv =$(strip |
| 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)) |
| 20 |
argv +=) |
| 21 |
|
| 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)) |
| 30 |
|
| 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)) |
| 36 |
|
| 37 |
########################################################################### |
| 38 |
# Intent: Display a distinct banner heading in the output stream |
| 39 |
# Usage: $(call banner,BUILDING: foo bar tans) |
| 40 |
# Debug: |
| 41 |
# target-preqs = \ |
| 42 |
# $(call banner,target-preqs-BEGIN) \ |
| 43 |
# foo bar tans \ |
| 44 |
# $(call banner,target-preqs-END) \ |
| 45 |
# $(NULL) |
| 46 |
# target: $(target-preqs) |
| 47 |
|
| 48 |
banner = \ |
| 49 |
$(info ) \ |
| 50 |
$(info ***************************************************************************) \ |
| 51 |
$(info ** $(getargv)) \ |
| 52 |
$(info ***************************************************************************) \ |
| 53 |
$(NULL) |
| 54 |
|
| 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))) |
| 60 |
|
| 61 |
##################################################################### |
| 62 |
# Provide an alternate var to support testing |
| 63 |
ifdef MAKEUTILS_UNIT_TEST |
| 64 |
mcg_goals=TEST_MAKECMDGOALS |
| 65 |
else |
| 66 |
mcg_goals=MAKECMDGOALS |
| 67 |
endif |
| 68 |
|
| 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)})\ |
| 74 |
))) |
| 75 |
isTargetStemClean = $(call isTargetStem,clean) |
| 76 |
isTargetStemExport = $(call isTargetStem,export) |
| 77 |
isTargetStemLibs = $(call isTargetStem,libs) |
| 78 |
isTargetStemTools = $(call isTargetStem,tools) |
| 79 |
|
| 80 |
################################################## |
| 81 |
# Intent: Validation functions / unit test helpers |
| 82 |
|
| 83 |
errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)])) |
| 84 |
|
| 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))) |
| 87 |
|
| 88 |
|
| 89 |
|
| 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))) |
| 93 |
|
| 94 |
|
| 95 |
## Disable checking for clean targets |
| 96 |
ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{ |
| 97 |
|
| 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))) |
| 100 |
|
| 101 |
# Usage: $(call errorIfEmpty,foo NULL bar) |
| 102 |
errorIfEmpty =$(call checkIfEmpty,error $(argv)) |
| 103 |
warnIfEmpty =$(call checkIfEmpty,warning $(argv)) |
| 104 |
|
| 105 |
endif #} |
| 106 |
|
| 107 |
########################################################################### |
| 108 |
## Common makefile library loader |
| 109 |
########################################################################### |
| 110 |
ifdef MOZILLA_DIR |
| 111 |
topORerr = $(MOZILLA_DIR) |
| 112 |
else |
| 113 |
topORerr = $(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined)) |
| 114 |
endif |
| 115 |
|
| 116 |
ifdef USE_AUTOTARGETS_MK # mkdir_deps |
| 117 |
include $(topORerr)/config/makefiles/autotargets.mk |
| 118 |
endif |