summaryrefslogtreecommitdiff
path: root/top
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-05-23 09:12:06 +0200
committerJim Meyering <meyering@redhat.com>2011-05-23 09:12:06 +0200
commit9df761edc6b29dbe2b7009b15dfe26a296d50a92 (patch)
tree681f9e4a28c5f02ce9449bb95150b3656272ca99 /top
parent99b313868bb6a7441f762d78252ce418f5ca7fdb (diff)
downloadgnulib-9df761edc6b29dbe2b7009b15dfe26a296d50a92.tar.gz
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.
Diffstat (limited to 'top')
-rw-r--r--top/maint.mk58
1 files changed, 39 insertions, 19 deletions
diff --git a/top/maint.mk b/top/maint.mk
index c838516e54..58e8004fba 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; } || :