Improve detection of GNU make, avoiding "Arg list too long" errors.
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 19 Dec 2014 14:10:09 +0000 (15:10 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 19 Dec 2014 20:00:19 +0000 (21:00 +0100)
Such errors could take place when the main makefile included too many
sub-makefiles, making $(MAKEFILE_LIST) too long and causing the
recipes $(am__is_gnu_make) to exceed the shell's command-line length
limits.  This is not a theoretical issue: it could happen for projects
having lots of C/C++ sources and using automatic dependency tracking,
which created an included .Po sub-makefile for each of such sources.

Fixes http://debbugs.gnu.org/18744

* lib/am/header-vars.am (am__is_gnu_make): Fix the logic to avoid
the use of $(MAKEFILE_LIST).
* NEWS: Update.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
NEWS
lib/am/header-vars.am

diff --git a/NEWS b/NEWS
index 626d295ac6537885856fafd6a8fd88cf89f255c1..bdc9bb9ab99879e082b0099deea7cde7aae5b2de 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -111,6 +111,11 @@ New in 1.14.2:
   - The expansion of AM_INIT_AUTOMAKE ends once again with a trailing
     newline (bug#16841). Regression introduced in Automake 1.14.
 
+  - The code used to detect whether the currently used make is GNU make
+    or not (relying on the private macro 'am__is_gnu_make') no longer
+    risks causing "Arg list too long" for projects using automatic
+    dependency tracking and having a ton of source files (bug#18744).
+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 New in 1.14.1:
index d25efa6122f94be9b17534979fd2dfe20cb51091..9283903a1c780c7e45bf852463262d1e61bbd14c 100644 (file)
@@ -1,5 +1,5 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994-2013 Free Software Foundation, Inc.
+## Copyright (C) 1994-2014 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
@@ -27,9 +27,36 @@ VPATH = @srcdir@
 ## DESTDIR =
 
 ## Shell code that determines whether we are running under GNU make.
-## This is somewhat of an hack, and might be improved, but is good
-## enough for now.
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+##
+## Why the this needs to be so convoluted?
+##
+## (1) We can't unconditionally use make functions or special variables
+##     starting with a dot, as those cause non-GNU implmentations to
+##     crash hard.
+##
+## (2) We can't use $(MAKE_VERSION) here, as it is also defined in some
+##     non-GNU make implementations (e.g., FreeBSD make).  But at least
+##     BSD make does *not* define the $(CURDIR) variable -- it uses
+##     $(.CURDIR) instead.
+##
+## (3) We can't use $(MAKEFILE_LIST) here, as in some situations it
+##     might cause the shell to die with "Arg list too long" (see
+##     automake bug#18744).
+##
+## (4) We can't use $(MAKE_HOST) unconditionally, as it is only
+##     defined in GNU make 4.0 or later.
+##
+am__is_gnu_make = { \
+  if test -z '$(MAKELEVEL)'; then \
+    false; \
+  elif test -n '$(MAKE_HOST)'; then \
+    true; \
+  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+    true; \
+  else \
+    false; \
+  fi; \
+}
 
 ## Shell code that determines whether the current make instance is
 ## running with a given one-letter option (e.g., -k, -n) that takes