I've been finding too many in-project definitions of symbols that are now guaranteed to be defined by gnulib. This macro automates the detection of such undesirable duplication.
It is unlike most other sc_ rules in that it creates a temporary file, .re-defmac. However, it does take care to remove it upon receipt of a catchable signal. So far, coreutils and diffutils have been adjusted to pass this new test. The new rule did not expose anything to complain about in grep. This rule has evolved since the last one I posted here. For details, see the recent commits to coreutils' cfg.mk. As always, suggestions for improvements are most welcome. >From 880f2b69df57af506439d6aaf1fe185a6f960e43 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Sun, 9 May 2010 18:50:40 +0200 Subject: [PATCH] maint.mk: prohibit definition of symbols defined by gnulib * top/maint.mk (sc_prohibit_always-defined_macros): Reject the definition of symbols defined by gnulib. --- ChangeLog | 6 ++++++ top/maint.mk | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c1f4e2..4de7bb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-05-09 Jim Meyering <[email protected]> + + maint.mk: prohibit definition of symbols defined by gnulib + * top/maint.mk (sc_prohibit_always-defined_macros): Reject the + definition of symbols defined by gnulib. + 2010-05-09 Bruno Haible <[email protected]> acl: Avoid test failure on Cygwin-hosted mingw. diff --git a/top/maint.mk b/top/maint.mk index 335d078..8d3d137 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -665,6 +665,50 @@ sc_prohibit_always_true_header_tests: ' with the corresponding gnulib module, they are always true' \ $(_sc_search_regexp) +# ================================================================== +gl_other_headers_ ?= \ + intprops.h \ + openat.h \ + stat-macros.h + +# Perl -lne code to extract "significant" cpp-defined symbols from a +# gnulib header file, eliminating a few common false-positives. +gl_extract_significant_defines_ = \ + /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/ && $$2 !~ /(?:rpl_|_used_without_)/\ + and print $$1 + +# Create a list of regular expressions matching the names +# of macros that are guaranteed to be defined by parts of gnulib. +.re-defmac: + @gen_h=$(gl_generated_headers_); \ + (cd $(gnulib_dir)/lib; \ + for f in *.in.h $(gl_other_headers_); do \ + perl -lne '$(gl_extract_significant_defines_)' $$f; \ + done; \ + ) | sort -u \ + | grep -Ev '^ATTRIBUTE_NORETURN' \ + | sed 's/^/^ *# *define /;s/$$/\\>/' \ + > $...@-t + @mv $...@-t $@ + +define gl_trap_ + Exit () { set +e; (exit $$1); exit $$1; }; \ + for sig in 1 2 3 13 15; do \ + eval "trap 'Exit $$(expr $$sig + 128)' $$sig"; \ + done +endef + +# Don't define macros that we already get from gnulib header files. +sc_prohibit_always-defined_macros: .re-defmac + @if test -d $(gnulib_dir); then \ + trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0; \ + $(gl_trap_); \ + grep -f .re-defmac $$($(VC_LIST_EXCEPT)) \ + && { echo '$(ME): define the above via some gnulib .h file' \ + 1>&2; exit 1; } || :; \ + fi +# ================================================================== + # Prohibit checked in backup files. sc_prohibit_backup_files: @$(VC_LIST) | grep '~$$' && \ -- 1.7.1.189.g07419
