From d4a56dfb3bcd50e9d323dbd65a1510dd5ffd59c4 Mon Sep 17 00:00:00 2001 From: Joey Armstrong Date: Tue, 3 Apr 2012 13:32:46 -0400 Subject: [PATCH] Bug 734121 - helper macros for writing make user functions - r=khuey --- allmakefiles.sh | 3 +- config/makefiles/makeutils.mk | 41 +++++++++++ config/makefiles/test/Makefile.in | 100 +++++++++++++++++++++++++++ js/src/config/makefiles/makeutils.mk | 41 +++++++++++ 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 config/makefiles/makeutils.mk create mode 100644 config/makefiles/test/Makefile.in create mode 100644 js/src/config/makefiles/makeutils.mk diff --git a/allmakefiles.sh b/allmakefiles.sh index b7202fbfcc3..fcd4f430d67 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -35,7 +35,6 @@ config/autoconf.mk config/nspr/Makefile config/doxygen.cfg config/expandlibs_config.py -config/tests/src-simple/Makefile mfbt/Makefile probes/Makefile extensions/Makefile @@ -108,7 +107,9 @@ fi if [ "$ENABLE_TESTS" ]; then add_makefiles " build/autoconf/test/Makefile + config/makefiles/test/Makefile config/tests/makefiles/autodeps/Makefile + config/tests/src-simple/Makefile " if [ ! "$LIBXUL_SDK" ]; then add_makefiles " diff --git a/config/makefiles/makeutils.mk b/config/makefiles/makeutils.mk new file mode 100644 index 00000000000..78a4986e0a3 --- /dev/null +++ b/config/makefiles/makeutils.mk @@ -0,0 +1,41 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# ***** BEGIN LICENSE BLOCK ***** +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Contributor(s): +# Joey Armstrong +# ***** END LICENSE BLOCK ***** + +# Usage: $(call banner,foo bar tans) +banner =\ +$(info )\ +$(info ***************************************************************************)\ +$(info ** BANNER: $(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9))\ +$(info ***************************************************************************)\ + +## Identify function argument types +istype =$(if $(value ${1}),list,scalar) +isval =$(if $(filter-out list,$(call istype,${1})),true) +isvar =$(if $(filter-out scalar,$(call istype,${1})),true) + +# Access up to 9 arguments passed, option needed to emulate $* +# Inline for function expansion, do not use $(call ) +argv =$(strip +argv +=$(if $(1), $(1))$(if $(2), $(2))$(if $(3), $(3))$(if $(4), $(4)) +argv +=$(if $(5), $(5))$(if $(6), $(6))$(if $(7), $(7))$(if $(8), $(8)) +argv +=$(if $(9), $(9)) +argv +=$(if $(10), $(error makeutils.mk::argv can only handle 9 arguments)) +argv +=) + +########################################################################### +## Access function args as a simple list, inline within user functions. +## Usage: $(info ** $(call banner,$(getargv))) +## $(call banner,scalar) +## $(call banner,list0 list1 list2) +## $(call banner,ref) ; ref=foo bar tans +## getarglist() would be a more accurate name but is longer to type +getargv = $(if $(call isvar,$(1)),$($(1)),$(argv)) diff --git a/config/makefiles/test/Makefile.in b/config/makefiles/test/Makefile.in new file mode 100644 index 00000000000..dbf80324a9c --- /dev/null +++ b/config/makefiles/test/Makefile.in @@ -0,0 +1,100 @@ +# -*- makefile -*- +# +# ***** BEGIN LICENSE BLOCK ***** +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Contributor(s): +# Joey Armstrong +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/makefiles/makeutils.mk + +##------------------_## +##---] TARGETS [---## +##------------------_## +all:: + +########################################################################### +## This test target should really depend on a timestamp to only perform +## work when makeutils.mk is modified. That answer would require using a +## 2nd makefile imposing more shell overhead. Separate makefiles would be +## very handy for testing when pwd==$src/ but for now avoid the overhead. +## +## Test logic will be interpreted at compile time, 'fast' and 'required' so +## the test will always be run when testing is enabled. +########################################################################### +check:: + @true + +## Logic processed at compile time so be selective about when to test +ifneq ($(NULL),$(findstring check,$(MAKECMDGOALS))) + +$(info ===========================================================================) +$(info Running test: $(MAKECMDGOALS): pwd=$(CURDIR)) +$(info ===========================================================================) + +## Silent errors are oh so much fun +ifndef istype + $(error makeutils.mk was not included) +endif + +# arg_scalar = [scalar|literal] +arg_list = foo bar +arg_ref = arg_list + +## Identify type of function argument(s) +######################################## +ifneq (scalar,$(call istype,arg_scalar)) + $(error istype(arg_scalar)=scalar, found [$(call istype,arg_scalar)]) +endif +ifneq (list,$(call istype,arg_list)) + $(error istype(arg_list)=list, found [$(call istype,arg_list)]) +endif +ifneq (list,$(call istype,arg_ref)) + $(error istype(arg_ref)=list, found [$(call istype,arg_ref)]) +endif + +## Type == scalar or a list of values +##################################### +ifneq (true,$(call isval,scalar)) + $(error isval(scalar)=true, found [$(call isval,scalar)]) +endif +ifneq ($(NULL),$(call isval,arg_list)) + $(error isval(arg_list)=null, found [$(call isval,arg_list)]) +endif + +## type == reference: macro=>macro => $($(1)) +############################################# +ifneq ($(NULL),$(call isvar,scalar)) + $(error isvar(scalar)=$(NULL), found [$(call isvar,scalar)]) +endif +ifneq (true,$(call isvar,arg_list)) + $(error isvar(arg_list)=true, found [$(call isvar,arg_list)]) +endif +ifneq (true,$(call isvar,arg_ref)) + $(error isvar(arg_ref)=true, found [$(call isvar,arg_ref)]) +endif + +# Verify getargv expansion +########################## +ifneq (scalar,$(call getargv,scalar)) + $(error getargv(scalar)=scalar, found [$(call getargv,scalar)]) +endif +ifneq ($(arg_list),$(call getargv,arg_list)) + $(error getargv(arg_list)=list, found [$(call getargv,arg_list)]) +endif +ifneq (arg_list,$(call getargv,arg_ref)) + $(error getargv(arg_ref)=list, found [$(call getargv,arg_ref)]) +endif + +endif # check in MAKECMDGOALS + + diff --git a/js/src/config/makefiles/makeutils.mk b/js/src/config/makefiles/makeutils.mk new file mode 100644 index 00000000000..78a4986e0a3 --- /dev/null +++ b/js/src/config/makefiles/makeutils.mk @@ -0,0 +1,41 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# ***** BEGIN LICENSE BLOCK ***** +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Contributor(s): +# Joey Armstrong +# ***** END LICENSE BLOCK ***** + +# Usage: $(call banner,foo bar tans) +banner =\ +$(info )\ +$(info ***************************************************************************)\ +$(info ** BANNER: $(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9))\ +$(info ***************************************************************************)\ + +## Identify function argument types +istype =$(if $(value ${1}),list,scalar) +isval =$(if $(filter-out list,$(call istype,${1})),true) +isvar =$(if $(filter-out scalar,$(call istype,${1})),true) + +# Access up to 9 arguments passed, option needed to emulate $* +# Inline for function expansion, do not use $(call ) +argv =$(strip +argv +=$(if $(1), $(1))$(if $(2), $(2))$(if $(3), $(3))$(if $(4), $(4)) +argv +=$(if $(5), $(5))$(if $(6), $(6))$(if $(7), $(7))$(if $(8), $(8)) +argv +=$(if $(9), $(9)) +argv +=$(if $(10), $(error makeutils.mk::argv can only handle 9 arguments)) +argv +=) + +########################################################################### +## Access function args as a simple list, inline within user functions. +## Usage: $(info ** $(call banner,$(getargv))) +## $(call banner,scalar) +## $(call banner,list0 list1 list2) +## $(call banner,ref) ; ref=foo bar tans +## getarglist() would be a more accurate name but is longer to type +getargv = $(if $(call isvar,$(1)),$($(1)),$(argv))