bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint.mk: generalize/improve the tight-scope rule


From: Jim Meyering
Subject: [PATCH] maint.mk: generalize/improve the tight-scope rule
Date: Mon, 23 May 2011 09:18:35 +0200

FYI,
Changes, in case anyone else is using this:
  - XTERN is no longer supported, by default.
    See the comments for how to customize it if you rely on this.
  - you now get a diagnostic when the tight-scope syntax-check test is skipped

>From 9df761edc6b29dbe2b7009b15dfe26a296d50a92 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 23 May 2011 09:12:06 +0200
Subject: [PATCH] maint.mk: generalize/improve the tight-scope rule

* top/maint.mk: Emit a warning when the test is skipped.
(_gl_TS_dir): Add $(srcdir)/ prefix.
(_gl_TS_function_match): Simplify, rather than trying
to enumerate common types.  Otherwise, it would fail to match an
"extern unsigned char const *" declaration in idutils.
(_gl_TS_extern): Do not endorse use of "XTERN", but do provide
a way to support use of that type of macro.
(_gl_TS_var_match): Simplify regexp.
(_gl_TS_obj_files): New configurable variable.
(_gl_TS_headers): Likewise.
---
 ChangeLog    |   14 ++++++++++++++
 top/maint.mk |   58 +++++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9509b2c..f206cd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-05-23  Jim Meyering  <address@hidden>
+
+       maint.mk: generalize/improve the tight-scope rule
+       * top/maint.mk: Emit a warning when the test is skipped.
+       (_gl_TS_dir): Add $(srcdir)/ prefix.
+       (_gl_TS_function_match): Simplify, rather than trying
+       to enumerate common types.  Otherwise, it would fail to match an
+       "extern unsigned char const *" declaration in idutils.
+       (_gl_TS_extern): Do not endorse use of "XTERN", but do provide
+       a way to support use of that type of macro.
+       (_gl_TS_var_match): Simplify regexp.
+       (_gl_TS_obj_files): New configurable variable.
+       (_gl_TS_headers): Likewise.
+
 2011-05-22  Paul Eggert  <address@hidden>

        verify: fix bug when gnulib <assert.h> is also included
diff --git a/top/maint.mk b/top/maint.mk
index c838516..58e8004 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1353,17 +1353,28 @@ update-copyright:
          $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
          | $(update-copyright-env) xargs $(build_aux)/$@

-# NOTE: This test is silently skipped if $(_gl_TS_dir)/Makefile.am
-# does not mention noinst_HEADERS.
-# NOTE: to override these _gl_TS_* default values, you must
+# NOTE: This test is skipped with a warning if $(_gl_TS_headers) still
+# has its default value and $(_gl_TS_dir)/Makefile.am does not mention
+# noinst_HEADERS.
+
+# NOTE: to override any _gl_TS_* default value, you must
 # define the variable(s) using "export" in cfg.mk.
-_gl_TS_dir ?= src
+_gl_TS_dir ?= $(srcdir)/src
+
+# The file(s) to search for extern declarations.
+_gl_TS_headers ?= $(noinst_HEADERS)
+
 ALL_RECURSIVE_TARGETS += sc_tight_scope
 sc_tight_scope: tight-scope.mk
-       @grep noinst_HEADERS $(_gl_TS_dir)/Makefile.am > /dev/null 2>&1 \
-         && $(MAKE) -s -C $(_gl_TS_dir) -f Makefile                    \
-             -f '$(abs_srcdir)/tight-scope.mk' _gl_tight_scope         \
-         || :
+       @if test 'x$(_gl_TS_headers)' = 'x$(noinst_HEADERS)'            \
+         && ! grep -w noinst_HEADERS $(_gl_TS_dir)/Makefile.am         \
+               > /dev/null 2>&1; then                                  \
+           echo '$(ME): skipping $@';                                  \
+       else                                                            \
+           $(MAKE) -s -C $(_gl_TS_dir) -f $(abs_builddir)/$<           \
+               -f Makefile _gl_tight_scope                             \
+             || fail=1;                                                \
+       fi
        @rm -f $<

 tight-scope.mk: $(ME)
@@ -1373,14 +1384,19 @@ tight-scope.mk: $(ME)

 ifeq (a,b)
 # TS-start
+
 # Most functions should have static scope.
 # Any that don't must be marked with `extern', but `main'
 # and `usage' are exceptions: they're always extern, but
 # do not need to be marked.  Symbols matching `__.*' are
 # reserved by the compiler, so are automatically excluded below.
 _gl_TS_unmarked_extern_functions ?= main usage
-_gl_TS_function_match ?= \
-  /^(?:extern|XTERN) +(?:void|(?:struct |const |enum )?\S+) +\**(\S+) +\(/
+_gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\S+) +\(/
+
+# If your project uses a macro like "XTERN", then put
+# the following in cfg.mk to override this default:
+# export _gl_TS_extern = extern|XTERN
+_gl_TS_extern ?= extern

 # The second nm|grep checks for file-scope variables with `extern' scope.
 # Without gnulib's progname module, you might put program_name here.
@@ -1396,7 +1412,11 @@ _gl_TS_unmarked_extern_vars ?=
 # can override this definition to automatically extract those names:
 # export _gl_TS_var_match = \
 #   /^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
-_gl_TS_var_match ?= /^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?;/
+_gl_TS_var_match ?= /^(?:extern|XTERN) .*?(\w+)(\[.*?\])?;/
+
+# The names of object files in (or relative to) $(_gl_TS_dir).
+_gl_TS_obj_files ?= *.$(OBJEXT)
+
 .PHONY: _gl_tight_scope
 _gl_tight_scope: $(bin_PROGRAMS)
        t=exceptions-$$$$;                                              \
@@ -1406,21 +1426,21 @@ _gl_tight_scope: $(bin_PROGRAMS)
        done;                                                           \
        src=`for f in $(SOURCES); do                                    \
               test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
-       hdr=`for f in $(noinst_HEADERS); do                             \
+       hdr=`for f in $(_gl_TS_headers); do                             \
               test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
        ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_functions);  \
          grep -h -A1 '^extern .*[^;]$$' $$src                          \
            | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
-         perl -lne '$(_gl_TS_function_match)'                          \
-                 -e 'and print $$1' $$hdr;                             \
-       ) | sort -u | sed 's/^/^/;s/$$/$$/' > $$t;                      \
-       nm -e *.$(OBJEXT) | sed -n 's/.* T //p' | grep -Ev -f $$t       \
+         perl -lne                                                     \
+            '$(_gl_TS_function_match) and print "^$$1\$$"' $$hdr;      \
+       ) | sort -u > $$t;                                              \
+       nm -e $(_gl_TS_obj_files) | sed -n 's/.* T //p'|grep -Ev -f $$t \
          && { echo the above functions should have static scope >&2;   \
               exit 1; } || : ;                                         \
        ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_vars);       \
-         perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"'           \
-           $$hdr *.h ) | sort -u > $$t;                                \
-       nm -e *.$(OBJEXT) | sed -n 's/.* [BCDGRS] //p'                  \
+         perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"' $$hdr *.h \
+       ) | sort -u > $$t;                                              \
+       nm -e $(_gl_TS_obj_files) | sed -n 's/.* [BCDGRS] //p'          \
             | sort -u | grep -Ev -f $$t                                        
\
          && { echo the above variables should have static scope >&2;   \
               exit 1; } || :
--
1.7.5.2.1.g56b30



reply via email to

[Prev in Thread] Current Thread [Next in Thread]