config/makefiles/makeutils.mk

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial