maint.mk: enforce the "include <config.h> first" rule
authorJim Meyering <meyering@redhat.com>
Sun, 21 Dec 2008 16:37:22 +0000 (17:37 +0100)
committerJim Meyering <meyering@redhat.com>
Sun, 21 Dec 2008 16:49:58 +0000 (17:49 +0100)
* maint.mk (sc_require_config_h_first): New rule.
* .x-sc_require_config_h_first: New file.

.x-sc_require_config_h_first [new file with mode: 0644]
maint.mk

diff --git a/.x-sc_require_config_h_first b/.x-sc_require_config_h_first
new file mode 100644 (file)
index 0000000..727bb8e
--- /dev/null
@@ -0,0 +1,9 @@
+^lib/buffer-lcm\.c$
+^src/false\.c$
+^src/lbracket\.c$
+^src/ls-dir\.c$
+^src/ls-ls\.c$
+^src/ls-vdir\.c$
+^src/tac-pipe\.c$
+^src/uname-arch\.c$
+^src/uname-uname\.c$
index cb3c6a56d6842c44c7c8c918e9ec8ffecd0d8166..7a9649e10214c7368ba27f95d6a049189d35dcf7 100644 (file)
--- a/maint.mk
+++ b/maint.mk
@@ -191,6 +191,21 @@ sc_require_config_h:
        else :;                                                         \
        fi
 
+# You must include <config.h> before including any other header file.
+sc_require_config_h_first:
+       @if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then          \
+         fail=0;                                                       \
+         for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do             \
+           grep '^# *include\>' $$i | sed 1q                           \
+               | grep '^# *include <config\.h>' > /dev/null            \
+             || { echo $$i; fail=1; };                                 \
+         done;                                                         \
+         test $$fail = 1 &&                                            \
+           { echo '$(ME): the above files include some other header'   \
+               'before <config.h>' 1>&2; exit 1; } || :;               \
+       else :;                                                         \
+       fi
+
 # To use this "command" macro, you must first define two shell variables:
 # h: the header, enclosed in <> or ""
 # re: a regular expression that matches IFF something provided by $h is used.