Subject: bug#13760: [PATCH 1/3] header vars: can determine whether we are running under GNU make

From: Stefano Lattarini <[email-masked]>
Date: Tue, 23 Apr 2013 11:12:46 +0200

This is mostly a preparatory patch in view of future changes.

* lib/am/header-vars.am (am__is_gnu_make): New, contains shell code that
determines whether we are running under GNU make.
* t/make-is-gnu.sh: New test.
* t/list-of-tests.mk: Add it.

Signed-off-by: Stefano Lattarini <[email-masked]>
---
 lib/am/header-vars.am |  6 ++++-
 t/list-of-tests.mk    |  3 ++-
 t/make-is-gnu.sh      | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100755 t/make-is-gnu.sh

diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am
index 9fda37c..8295a99 100644
--- a/lib/am/header-vars.am
+++ b/lib/am/header-vars.am
@@ -26,12 +26,16 @@ VPATH = @srcdir@
 ## a vendor make.
 ## 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)'
+
 ## Shell code that determines whether make is running in "dry mode"
 ## ("make -n") or not.  Useful in rules that invoke make recursively,
 ## and are thus executed also with "make -n" -- either because they
 ## are declared as dependencies to '.MAKE' (NetBSD make), or because
 ## their recipes contain the "$(MAKE)" string (GNU and Solaris make).
-
 am__make_dryrun = \
   { \
     am__dry=no; \
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index f1e3dca..c72a636 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -664,8 +664,9 @@ t/makej.sh \
 t/makej2.sh \
 t/maken.sh \
 t/maken3.sh \
-t/make-dryrun.tap \
 t/makevars.sh \
+t/make-dryrun.tap \
+t/make-is-gnu.sh \
 t/man.sh \
 t/man2.sh \
 t/man3.sh \
diff --git a/t/make-is-gnu.sh b/t/make-is-gnu.sh
new file mode 100755
index 0000000..c37cc17
--- /dev/null
+++ b/t/make-is-gnu.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2013 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/>.
+
+# Check that $(am__is_gnu_make) can be used to correctly determine if
+# we are running under GNU make.
+
+. test-init.sh
+
+if using_gmake; then
+ as_expected () { test $1 -eq 0 && test -f ok && test ! -e ko; }
+else
+ as_expected () { test $1 -gt 0 && test -f ko && test ! -e ok; }
+fi
+
+echo AC_OUTPUT >> configure.ac
+
+cat > Makefile.am <<'END'
+all: file
+	$(am__is_gnu_make)
+file:
+	if $(am__is_gnu_make); then : > ok; else : > ko; fi 
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+st=0; $MAKE || st=$?
+if using_gmake; then
+ test $st -eq 0
+ test -f ok
+ test ! -e ko
+else
+ test $st -gt 0
+ test -f ko
+ test ! -e ok
+fi
+
+rm -f ok ko
+
+$MAKE -s file >output 2>&1
+cat output
+if using_gmake; then
+ test -f ok
+ test ! -e ko
+else
+ test -f ko
+ test ! -e ok
+fi
+test ! -s output
+
+:
-- 
1.8.2.1.389.gcaa7d79