]> Savannah Git Hosting - gnulib.git/commitdiff
maintainer-makefile: catch uses of $< in non-implicit rules
authorAkim Demaille <akim.demaille@gmail.com>
Sat, 18 May 2019 06:46:00 +0000 (08:46 +0200)
committerAkim Demaille <akim.demaille@gmail.com>
Sun, 19 May 2019 05:41:22 +0000 (07:41 +0200)
* top/maint.mk (sc_prohibit_magic_number_exit): New.

ChangeLog
top/maint.mk

index 3ec5ac58f1b69249b14f211d88d93fb5a6f65d20..0f5500f1a25f9df21df3949d9dbc82a2458eb836 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-18  Akim Demaille  <akim@lrde.epita.fr>
+
+       maintainer-makefile: catch uses of $< in non-implicit rules
+       * top/maint.mk (sc_prohibit_magic_number_exit): New.
+
 2019-05-18  Bruno Haible  <bruno@clisp.org>
 
        threadlib: Provide an easy way to avoid mingw's winpthreads library.
index e9d5ee7d488510dfff21252e2fc002fabb054487..3dbe9c3788c153467510782605a0e660df38b26b 100644 (file)
@@ -408,6 +408,41 @@ sc_prohibit_magic_number_exit:
        halt='use EXIT_* values rather than magic number'               \
          $(_sc_search_regexp)
 
+# Check that we don't use $< in non-implicit Makefile rules.
+#
+# To find the Makefiles, trace AC_CONFIG_FILES.  Using VC_LIST would
+# miss the Makefiles that are not under VC control (e.g., symlinks
+# installed for gettext).  "Parsing" (recursive) uses of SUBDIRS seems
+# too delicate.
+#
+# Use GNU Make's --print-data-base to normalize the rules into some
+# easy to parse format: they are separated by two \n.  Look for the
+# "section" about non-pattern rules (marked with "# Files") inside
+# which there are still the POSIX Make like implicit rules (".c.o").
+sc_prohibit_gnu_make_extensions_awk_ =                                 \
+  BEGIN {                                                              \
+      RS = "\n\n";                                                     \
+      in_rules = 0;                                                    \
+  }                                                                    \
+  /^\# Files/ {                                                                \
+      in_rules = 1;                                                    \
+  }                                                                    \
+  /\$$</ && in_rules && $$0 !~ /^(.*\n)*\.\w+(\.\w+)?:/ {              \
+      print "Error: " file ": $$< in a non implicit rule\n" $$0;       \
+      status = 1;                                                      \
+  }                                                                    \
+  END {                                                                        \
+     exit status;                                                      \
+  }
+sc_prohibit_gnu_make_extensions:
+       (cd $(srcdir) && autoconf --trace AC_CONFIG_FILES:'$$1') |      \
+         tr ' ' '\n' |                                                 \
+         $(SED) -ne '/Makefile/{s/\.in$$//;p;}' |                      \
+         while read m; do                                              \
+           $(MAKE) -qp -f $$m .DUMMY-TARGET 2>/dev/null |              \
+             awk -v file=$$m -e '$($@_awk_)' || exit 1;                \
+         done
+
 # Using EXIT_SUCCESS as the first argument to error is misleading,
 # since when that parameter is 0, error does not exit.  Use '0' instead.
 sc_error_exit_success: