Bug 734121 - helper macros for writing make user functions - r=khuey
authorJoey Armstrong <jarmstrong@mozilla.com>
Tue, 03 Apr 2012 13:32:46 -0400
changeset 90974 6236ee493160f1448424886d1697eb3827cd2986
parent 90973 dd43f89c753e15a3c21b1005a0b0bf14955172fe
child 90975 329bd787a846961753ac8c42dcef57f8f2f6aea7
push id22404
push usercoop@mozilla.com
push dateWed, 04 Apr 2012 18:06:17 +0000
treeherdermozilla-central@c598b7b202e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs734121
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 734121 - helper macros for writing make user functions - r=khuey
allmakefiles.sh
config/makefiles/makeutils.mk
config/makefiles/test/Makefile.in
js/src/config/makefiles/makeutils.mk
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -30,17 +30,16 @@ build/Makefile
 build/pgo/Makefile
 build/pgo/blueprint/Makefile
 build/pgo/js-input/Makefile
 config/Makefile
 config/autoconf.mk
 config/nspr/Makefile
 config/doxygen.cfg
 config/expandlibs_config.py
-config/tests/src-simple/Makefile
 mfbt/Makefile
 probes/Makefile
 extensions/Makefile
 "
 
 if [ ! "$LIBXUL_SDK" ]; then
   if [ "$STLPORT_SOURCES" ]; then
     add_makefiles "
@@ -103,17 +102,19 @@ if [ "$ENABLE_MARIONETTE" ]; then
     testing/marionette/components/Makefile
     testing/marionette/tests/Makefile
   "
 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 "
       mozglue/tests/Makefile
     "
   fi
   if [ "$_MSC_VER" -a "$OS_TEST" != "x86_64" ]; then
     add_makefiles "
new file mode 100644
--- /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 <joey@mozilla.com>
+# ***** 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))
new file mode 100644
--- /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 <joey@mozilla.com>
+# ***** 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
+
+
new file mode 100644
--- /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 <joey@mozilla.com>
+# ***** 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))