diff top/maint.mk @ 14800:a5a7a62228b6

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.
author Jim Meyering <meyering@redhat.com>
date Mon, 23 May 2011 09:12:06 +0200
parents b44f65e44220
children 60872968acd0
line wrap: on
line diff
--- a/top/maint.mk	Sun May 22 18:36:04 2011 -0700
+++ b/top/maint.mk	Mon May 23 09:12:06 2011 +0200
@@ -1353,17 +1353,28 @@
 	  $$(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 @@
 
 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 @@
 # 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 @@
 	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; } || :