summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-05-10 16:33:42 +0200
committerJim Meyering <meyering@redhat.com>2008-05-17 12:53:29 +0200
commit3abe5c7f968cb2905ecf2c0920f283e5c60016d2 (patch)
tree300926725f2b2daf1e29d815a674d314be645b24 /src
parent98819d0bb2527849d28ba786c481ef55e565b427 (diff)
downloadidutils-3abe5c7f968cb2905ecf2c0920f283e5c60016d2.tar.gz
idutils-3abe5c7f968cb2905ecf2c0920f283e5c60016d2.tar.bz2
idutils-3abe5c7f968cb2905ecf2c0920f283e5c60016d2.zip
tests: enable scoping check
* cfg.mk (local-checks-to-skip): Don't skip sc_tight_scope anymore. * src/Makefile.am (sc_tight_scope): New rule. From coreutils.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am27
1 files changed, 27 insertions, 0 deletions
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; } || :