1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/makefiles/makeutils.mk Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +# -*- makefile -*- 1.5 +# vim:set ts=8 sw=8 sts=8 noet: 1.6 +# 1.7 +# This Source Code Form is subject to the terms of the Mozilla Public 1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.9 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + 1.11 +## Identify function argument types 1.12 +istype =$(if $(value ${1}),list,scalar) 1.13 +isval =$(if $(filter-out list,$(call istype,${1})),true) 1.14 +isvar =$(if $(filter-out scalar,$(call istype,${1})),true) 1.15 + 1.16 +# Access up to 9 arguments passed, option needed to emulate $* 1.17 +# Inline for function expansion, do not use $(call ) 1.18 +argv =$(strip 1.19 +argv +=$(if $(1), $(1))$(if $(2), $(2))$(if $(3), $(3))$(if $(4), $(4)) 1.20 +argv +=$(if $(5), $(5))$(if $(6), $(6))$(if $(7), $(7))$(if $(8), $(8)) 1.21 +argv +=$(if $(9), $(9)) 1.22 +argv +=$(if $(10), $(error makeutils.mk::argv can only handle 9 arguments)) 1.23 +argv +=) 1.24 + 1.25 +########################################################################### 1.26 +## Access function args as a simple list, inline within user functions. 1.27 +## Usage: $(info ** $(call banner,$(getargv))) 1.28 +## $(call banner,scalar) 1.29 +## $(call banner,list0 list1 list2) 1.30 +## $(call banner,ref) ; ref=foo bar tans 1.31 +## getarglist() would be a more accurate name but is longer to type 1.32 +getargv = $(if $(call isvar,$(1)),$($(1)),$(argv)) 1.33 + 1.34 +########################################################################### 1.35 +# Strip [n] leading options from an argument list. This will allow passing 1.36 +# extra args to user functions that will not propogate to sub-$(call )'s 1.37 +# Usage: $(call subargv,2) 1.38 +subargv =$(wordlist $(1),$(words $(getargv)),$(getargv)) 1.39 + 1.40 +########################################################################### 1.41 +# Intent: Display a distinct banner heading in the output stream 1.42 +# Usage: $(call banner,BUILDING: foo bar tans) 1.43 +# Debug: 1.44 +# target-preqs = \ 1.45 +# $(call banner,target-preqs-BEGIN) \ 1.46 +# foo bar tans \ 1.47 +# $(call banner,target-preqs-END) \ 1.48 +# $(NULL) 1.49 +# target: $(target-preqs) 1.50 + 1.51 +banner = \ 1.52 +$(info ) \ 1.53 +$(info ***************************************************************************) \ 1.54 +$(info ** $(getargv)) \ 1.55 +$(info ***************************************************************************) \ 1.56 +$(NULL) 1.57 + 1.58 +##################################################################### 1.59 +# Intent: Determine if a string or pattern is contained in a list 1.60 +# Usage: strcmp - $(call if_XinY,clean,$(MAKECMDGOALS)) 1.61 +# : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS)) 1.62 +is_XinY =$(filter $(1),$(call subargv,3,$(getargv))) 1.63 + 1.64 +##################################################################### 1.65 +# Provide an alternate var to support testing 1.66 +ifdef MAKEUTILS_UNIT_TEST 1.67 + mcg_goals=TEST_MAKECMDGOALS 1.68 +else 1.69 + mcg_goals=MAKECMDGOALS 1.70 +endif 1.71 + 1.72 +# Intent: Conditionals for detecting common/tier target use 1.73 +isTargetStem = $(sort \ 1.74 + $(foreach var,$(getargv),\ 1.75 + $(foreach pat,$(var)% %$(var),\ 1.76 + $(call is_XinY,$(pat),${$(mcg_goals)})\ 1.77 + ))) 1.78 +isTargetStemClean = $(call isTargetStem,clean) 1.79 +isTargetStemExport = $(call isTargetStem,export) 1.80 +isTargetStemLibs = $(call isTargetStem,libs) 1.81 +isTargetStemTools = $(call isTargetStem,tools) 1.82 + 1.83 +################################################## 1.84 +# Intent: Validation functions / unit test helpers 1.85 + 1.86 +errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)])) 1.87 + 1.88 +# Intent: verify function declaration exists 1.89 +requiredfunction =$(foreach func,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if $(value $(func)),$(NULL),$(error required function [$(func)] is unavailable))) 1.90 + 1.91 + 1.92 + 1.93 +## http://www.gnu.org/software/make/manual/make.html#Call-Function 1.94 +## Usage: o = $(call map,origin,o map $(MAKE)) 1.95 +map = $(foreach val,$(2),$(call $(1),$(val))) 1.96 + 1.97 + 1.98 +## Disable checking for clean targets 1.99 +ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{ 1.100 + 1.101 +# Usage: $(call checkIfEmpty,[error|warning] foo NULL bar) 1.102 +checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(NOP),$(call $(1),Variable $(var) does not contain a value))) 1.103 + 1.104 +# Usage: $(call errorIfEmpty,foo NULL bar) 1.105 +errorIfEmpty =$(call checkIfEmpty,error $(argv)) 1.106 +warnIfEmpty =$(call checkIfEmpty,warning $(argv)) 1.107 + 1.108 +endif #} 1.109 + 1.110 +########################################################################### 1.111 +## Common makefile library loader 1.112 +########################################################################### 1.113 +topORerr =$(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined)) 1.114 + 1.115 +ifdef USE_AUTOTARGETS_MK # mkdir_deps 1.116 + include $(topORerr)/config/makefiles/autotargets.mk 1.117 +endif 1.118 + 1.119 +ifdef USE_RCS_MK 1.120 + include $(topORerr)/config/makefiles/rcs.mk 1.121 +endif 1.122 + 1.123 +## copy(src, dst): recursive copy 1.124 +copy_dir = (cd $(1)/. && $(TAR) $(TAR_CREATE_FLAGS) - .) | (cd $(2)/. && tar -xf -)