From 91fd934273607a4a395917d5230bd8dd5c866d94 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 9 May 2011 19:28:11 +0200 Subject: [PATCH] maint.mk: change semantics/name of tight_scope variables * top/maint.mk (_gl_TS_var_match, _gl_TS_function_match): Rename variables to align with semantics that make them more useful. --- ChangeLog | 4 ++++ top/maint.mk | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22442c5211..be6516f881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2011-05-09 Jim Meyering + maint.mk: change semantics/name of tight_scope variables + * top/maint.mk (_gl_TS_var_match, _gl_TS_function_match): + Rename variables to align with semantics that make them more useful. + maint.mk: tweak new rule's name not to impinge * top/maint.mk (_gl_tight_scope): Rename from sc_tight_scope-0. (sc_tight_scope): Use new rule name rather than $@-0. diff --git a/top/maint.mk b/top/maint.mk index 6e810bae82..346fe0068c 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -1351,13 +1351,22 @@ ifeq (a,b) # and `usage' are exceptions: they're always extern, but # do not need to be marked. _gl_TS_unmarked_extern_functions ?= main usage -_gl_TS_function_regex ?= \ - ^(?:extern|XTERN) +(?:void|(?:struct |const |enum )?\S+) +\**(\S+) +\( +_gl_TS_function_match ?= \ + /^(?:extern|XTERN) +(?:void|(?:struct |const |enum )?\S+) +\**(\S+) +\(/ # The second nm|grep checks for file-scope variables with `extern' scope. # Without gnulib's progname module, you might put program_name here. _gl_TS_unmarked_extern_vars ?= -_gl_TS_var_regex ?= ^(?:extern|XTERN) .*?\**(\w+)(\[.*?\])?; + +# NOTE: the _match variables are perl expressions -- not mere regular +# expressions -- so that you can extend them to match other patterns +# and easily extract matched variable names. +# For example, if your project declares some global variables via +# a macro like this: GLOBAL(type, var_name, initializer), then you +# 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+)(\[.*?\])?;/ .PHONY: _gl_tight_scope _gl_tight_scope: $(bin_PROGRAMS) t=exceptions-$$$$; \ @@ -1372,14 +1381,14 @@ _gl_tight_scope: $(bin_PROGRAMS) ( printf '^%s$$\n' $(_gl_TS_unmarked_extern_functions); \ grep -h -A1 '^extern .*[^;]$$' $$src \ | grep -vE '^(extern |--)' | sed 's/ .*//'; \ - perl -lne '/$(_gl_TS_function_regex)/' \ + 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 \ && { echo the above functions should have static scope >&2; \ exit 1; } || : ; \ ( printf '^%s$$\n' $(_gl_TS_unmarked_extern_vars); \ - perl -lne '/$(_gl_TS_var_regex)/ and print "^$$1\$$"' \ + perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"' \ $$hdr *.h ) | sort -u > $$t; \ nm -e *.$(OBJEXT) | sed -n 's/.* [BCDGRS] //p' \ | sort -u | grep -Ev -f $$t \ -- 2.30.2