michael@0: # -*- makefile -*- michael@0: # vim:set ts=8 sw=8 sts=8 noet: michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ## Identify function argument types michael@0: istype =$(if $(value ${1}),list,scalar) michael@0: isval =$(if $(filter-out list,$(call istype,${1})),true) michael@0: isvar =$(if $(filter-out scalar,$(call istype,${1})),true) michael@0: michael@0: # Access up to 9 arguments passed, option needed to emulate $* michael@0: # Inline for function expansion, do not use $(call ) michael@0: argv =$(strip michael@0: argv +=$(if $(1), $(1))$(if $(2), $(2))$(if $(3), $(3))$(if $(4), $(4)) michael@0: argv +=$(if $(5), $(5))$(if $(6), $(6))$(if $(7), $(7))$(if $(8), $(8)) michael@0: argv +=$(if $(9), $(9)) michael@0: argv +=$(if $(10), $(error makeutils.mk::argv can only handle 9 arguments)) michael@0: argv +=) michael@0: michael@0: ########################################################################### michael@0: ## Access function args as a simple list, inline within user functions. michael@0: ## Usage: $(info ** $(call banner,$(getargv))) michael@0: ## $(call banner,scalar) michael@0: ## $(call banner,list0 list1 list2) michael@0: ## $(call banner,ref) ; ref=foo bar tans michael@0: ## getarglist() would be a more accurate name but is longer to type michael@0: getargv = $(if $(call isvar,$(1)),$($(1)),$(argv)) michael@0: michael@0: ########################################################################### michael@0: # Strip [n] leading options from an argument list. This will allow passing michael@0: # extra args to user functions that will not propogate to sub-$(call )'s michael@0: # Usage: $(call subargv,2) michael@0: subargv =$(wordlist $(1),$(words $(getargv)),$(getargv)) michael@0: michael@0: ########################################################################### michael@0: # Intent: Display a distinct banner heading in the output stream michael@0: # Usage: $(call banner,BUILDING: foo bar tans) michael@0: # Debug: michael@0: # target-preqs = \ michael@0: # $(call banner,target-preqs-BEGIN) \ michael@0: # foo bar tans \ michael@0: # $(call banner,target-preqs-END) \ michael@0: # $(NULL) michael@0: # target: $(target-preqs) michael@0: michael@0: banner = \ michael@0: $(info ) \ michael@0: $(info ***************************************************************************) \ michael@0: $(info ** $(getargv)) \ michael@0: $(info ***************************************************************************) \ michael@0: $(NULL) michael@0: michael@0: ##################################################################### michael@0: # Intent: Determine if a string or pattern is contained in a list michael@0: # Usage: strcmp - $(call if_XinY,clean,$(MAKECMDGOALS)) michael@0: # : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS)) michael@0: is_XinY =$(filter $(1),$(call subargv,3,$(getargv))) michael@0: michael@0: ##################################################################### michael@0: # Provide an alternate var to support testing michael@0: ifdef MAKEUTILS_UNIT_TEST michael@0: mcg_goals=TEST_MAKECMDGOALS michael@0: else michael@0: mcg_goals=MAKECMDGOALS michael@0: endif michael@0: michael@0: # Intent: Conditionals for detecting common/tier target use michael@0: isTargetStem = $(sort \ michael@0: $(foreach var,$(getargv),\ michael@0: $(foreach pat,$(var)% %$(var),\ michael@0: $(call is_XinY,$(pat),${$(mcg_goals)})\ michael@0: ))) michael@0: isTargetStemClean = $(call isTargetStem,clean) michael@0: isTargetStemExport = $(call isTargetStem,export) michael@0: isTargetStemLibs = $(call isTargetStem,libs) michael@0: isTargetStemTools = $(call isTargetStem,tools) michael@0: michael@0: ################################################## michael@0: # Intent: Validation functions / unit test helpers michael@0: michael@0: errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)])) michael@0: michael@0: # Intent: verify function declaration exists michael@0: requiredfunction =$(foreach func,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if $(value $(func)),$(NULL),$(error required function [$(func)] is unavailable))) michael@0: michael@0: michael@0: michael@0: ## http://www.gnu.org/software/make/manual/make.html#Call-Function michael@0: ## Usage: o = $(call map,origin,o map $(MAKE)) michael@0: map = $(foreach val,$(2),$(call $(1),$(val))) michael@0: michael@0: michael@0: ## Disable checking for clean targets michael@0: ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{ michael@0: michael@0: # Usage: $(call checkIfEmpty,[error|warning] foo NULL bar) michael@0: checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(NOP),$(call $(1),Variable $(var) does not contain a value))) michael@0: michael@0: # Usage: $(call errorIfEmpty,foo NULL bar) michael@0: errorIfEmpty =$(call checkIfEmpty,error $(argv)) michael@0: warnIfEmpty =$(call checkIfEmpty,warning $(argv)) michael@0: michael@0: endif #} michael@0: michael@0: ########################################################################### michael@0: ## Common makefile library loader michael@0: ########################################################################### michael@0: topORerr =$(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined)) michael@0: michael@0: ifdef USE_AUTOTARGETS_MK # mkdir_deps michael@0: include $(topORerr)/config/makefiles/autotargets.mk michael@0: endif michael@0: michael@0: ifdef USE_RCS_MK michael@0: include $(topORerr)/config/makefiles/rcs.mk michael@0: endif michael@0: michael@0: ## copy(src, dst): recursive copy michael@0: copy_dir = (cd $(1)/. && $(TAR) $(TAR_CREATE_FLAGS) - .) | (cd $(2)/. && tar -xf -)