diff options
-rw-r--r-- | cfg.mk | 3 | ||||
-rw-r--r-- | src/Makefile.am | 27 |
2 files changed, 28 insertions, 2 deletions
@@ -32,8 +32,7 @@ gpg_key_ID = B9AB9A16 # files -- otherwise, you'd need to have the upcoming version number # at the top of the file for each `make distcheck' run. local-checks-to-skip = changelog-check strftime-check patch-check \ - sc_prohibit_atoi_atof sc_changelog sc_tight_scope \ - check-AUTHORS + sc_prohibit_atoi_atof sc_changelog check-AUTHORS # The local directory containing the checked-out copy of gnulib used in # this release. Used solely to get a date for the "announcement" target. diff --git a/src/Makefile.am b/src/Makefile.am index 953c73a..f3958d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,3 +10,30 @@ AM_CPPFLAGS = -I$(top_builddir)/intl \ -DLANGUAGE_MAP_FILE=\"$(datadir)/id-lang.map\" LDADD = ../libidu/libidu.a ../lib/libgnu.a $(LIBINTL) ../lib/libgnu.a + +# Most functions in src/*.c should have static scope. +# Any that don't must be marked with `extern', but `main' +# and `usage' are exceptions. They're always extern, but +# don't need to be marked. +# +# The second nm|grep checks for file-scope variables with `extern' scope. +.PHONY: sc_tight_scope +sc_tight_scope: $(all_programs) + @t=exceptions-$$$$; \ + trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15; \ + ( printf '^main$$\n^usage$$\n'; \ + grep -h -A1 '^extern .*[^;]$$' $(SOURCES) \ + | grep -vE '^(extern |--)' |sed 's/^/^/;s/ .*/$$/' ) > $$t; \ + nm -e *.$(OBJEXT) \ + | sed -n 's/.* T //p' \ + | grep -Ev -f $$t && \ + { echo 'the above functions should have static scope' 1>&2; \ + exit 1; } || : ; \ + ( printf '^program_name$$\n'; \ + sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p' \ + $(noinst_HEADERS) ) > $$t; \ + nm -e *.$(OBJEXT) \ + | sed -n 's/.* [BD] //p' \ + | grep -Ev -f $$t && \ + { echo 'the above variables should have static scope' 1>&2; \ + exit 1; } || : |