automake-ng
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Automake-NG] [PATCH 2/6] [ng] am.xargs-map: new internal make function


From: Stefano Lattarini
Subject: [Automake-NG] [PATCH 2/6] [ng] am.xargs-map: new internal make function
Date: Sat, 7 Jul 2012 22:40:43 +0200

It will be useful in future changes, to help us to fend of errors
about "exceeded command line length" in our recipes.

* lib/am/header-vars.am (am.xargs-map): New internal function.
(am.max-cmdline-args, am.max-cmdline-args+1): New internal
auxiliary make variables.
* t/am-xargs-map.sh: New test.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 lib/am/header-vars.am |   21 ++++++++
 t/am-xargs-map.sh     |  139 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 160 insertions(+)
 create mode 100755 t/am-xargs-map.sh

diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am
index d2486b6..812f2f6 100644
--- a/lib/am/header-vars.am
+++ b/lib/am/header-vars.am
@@ -256,6 +256,27 @@ am__strip_suffixes = $(strip \
           $(patsubst %$(firstword $1),%$(am__private_suffix),$2))), \
     $2))
 
+# Helper variables and function to help in recipes that could exceed
+# the command line length limit.
+
+## FIXME: this is basically arbitrary.  In the long term, defining this
+## FIXME: after a configure-time test on the command-line length limits,
+## FIXME: or at least on a system-by-system basis, might be better.
+am.max-cmdline-args := 40
+am.max-cmdline-args+1 := 41
+
+# $(call am.xargs-map,FUNCTION,LIST)
+# ----------------------------------
+# Map the function $1 on the arguments $2, ensuring that each
+# call of $1 has at most 40 arguments.
+# The extra $(strip) calls are only to allow clearer formatting.
+define am.xargs-map
+$(if $2,$(strip \
+  )$(call $1,$(wordlist 1,$(am.max-cmdline-args),$2))$(strip \
+  )$(call $0,$1,$(wordlist $(am.max-cmdline-args+1),$(words $2),$2)))
+endef
+
+
 ## Some derived variables that have been found to be useful.
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
diff --git a/t/am-xargs-map.sh b/t/am-xargs-map.sh
new file mode 100755
index 0000000..4da959f
--- /dev/null
+++ b/t/am-xargs-map.sh
@@ -0,0 +1,139 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test Automake internal function 'am.xargs-map', in several usage
+# scenarios.
+
+am_create_testdir=empty
+. ./defs || exit 1
+
+cp "$am_amdir"/header-vars.am . \
+  || fatal_ "fetching makefile fragment headers-vars.am"
+
+# Filter out Automake comments and things that would need configure
+# substitutions.
+LC_ALL=C $EGREP -v '(^##|address@hidden@)' header-vars.am > defn.mk
+rm -f header-vars.am
+
+sed 's/^[0-9][0-9]*:://' > Makefile << 'END'
+01::include ./defn.mk
+02::
+03::args1  := 0 1 2 3 4 5 6 7 8 9
+04::args2  := $(args1) $(args1)
+05::args4  := $(args2) $(args2)
+06::args8  := $(args4) $(args4)
+07::args16 := $(args8) $(args8)
+08::
+09::WARN := no
+10::ifeq ($(WARN),yes)
+11::  $(call am.xargs-map,warning,$(args16))
+12::  $(call am.xargs-map,warning,$(args16) 0 1 2 3)
+13::  $(call am.xargs-map,warning,x y z)
+14::endif
+
+args32 := $(args16) $(args16)
+args64 := $(args32) $(args32)
+
+bar = test '$1' = '$(args4)'$(am__newline)
+test-xargs-map:
+       $(call am.xargs-map,bar,$(args16))
+
+args = $(error 'args' should be overridden from the command line)
+foo = @echo $1$(am__newline)
+echo-xargs-map:
+       $(call am.xargs-map,foo,$(args))
+END
+
+args1="0 1 2 3 4 5 6 7 8 9"
+args2="$args1 $args1"
+args4="$args2 $args2"
+
+$MAKE .am/nil WARN=yes 2>stderr || { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep '^Makefile:' stderr # For debugging
+test $(grep -c "^Makefile:11: $args4$" stderr) -eq 4
+test $(grep -c "^Makefile:12: $args4$" stderr) -eq 4
+test $(grep -c "^Makefile:12: 0 1 2 3$" stderr) -eq 1
+test $(grep -c "^Makefile:13: x y z$" stderr) -eq 1
+test $(grep -c "^Makefile:" stderr) -eq 10
+
+$MAKE 'test-xargs-map'
+
+check_echo ()
+{
+  cat > exp
+  $MAKE --no-print-directory "echo-xargs-map" args="$1" >got \
+    || { cat got >&2; exit 1; }
+  cat exp && cat got && diff exp got || exit 1
+}
+
+echo "$args1" | check_echo '$(args1)'
+echo "$args2" | check_echo '$(args2)'
+echo "$args4" | check_echo '$(args4)'
+
+check_echo '$(args8)'<<END
+$args4
+$args4
+END
+
+check_echo "$args4 $args4" <<END
+$args4
+$args4
+END
+
+check_echo "$args4 $args4 x" <<END
+$args4
+$args4
+x
+END
+
+check_echo "$args4 01 02 03 04 05 06 07" <<END
+$args4
+01 02 03 04 05 06 07
+END
+
+check_echo '$(args32) 11 12 13 67' <<END
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+11 12 13 67
+END
+
+check_echo '$(args64)' <<END
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+$args4
+END
+
+:
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]