syntax-check: keep one maint.mk rule in sync with its header
[gnulib.git] / Makefile
1 # GNU Makefile for gnulib central.
2 # Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
3 #
4 # Copying and distribution of this file, with or without modification,
5 # in any medium, are permitted without royalty provided the copyright
6 # notice and this notice are preserved.
7
8 # This Makefile requires the use of GNU make.  Some targets require
9 # that you have tools like git, makeinfo and cppi installed.
10
11 # Required for the use of <(...) below.
12 SHELL=/bin/bash
13
14 # Produce some files that are not stored in the repository.
15 all:
16
17 # Produce the documentation in readable form.
18 info html dvi pdf:
19         cd doc && $(MAKE) $@ && $(MAKE) mostlyclean
20
21 # Collect the names of rules starting with `sc_'.
22 syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p'\
23                         Makefile))
24
25 # Perform some platform independent checks on the gnulib code.
26 check: $(syntax-check-rules)
27
28 sc_prefer_ac_check_funcs_once:
29         if test -d .git; then                                           \
30           git grep -w -l AC_CHECK_FUNCS modules                         \
31             && { echo use AC_CHECK_FUNCS_ONCE, not AC_CHECK_FUNCS       \
32                    in modules/ 1>&2; exit 1; } || :                     \
33         else :; fi
34
35 sc_prohibit_augmenting_PATH_via_TESTS_ENVIRONMENT:
36         if test -d .git; then                                           \
37           url=http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/22874; \
38           git grep '^[   ]*TESTS_ENVIRONMENT += PATH=' modules          \
39             && { printf '%s\n' 'Do not augment PATH via TESTS_ENVIRONMENT;' \
40                  "  see <$$url>" 1>&2; exit 1; } || :                   \
41         else :; fi
42
43 # Files in m4/ that (exceptionally) may use AC_LIBOBJ.
44 # Do not include their ".m4" suffix.
45 allow_AC_LIBOBJ =       \
46   close                 \
47   dprintf               \
48   dup2                  \
49   faccessat             \
50   fchdir                \
51   fclose                \
52   fcntl                 \
53   fprintf-posix         \
54   open                  \
55   printf-posix-rpl      \
56   snprintf              \
57   sprintf-posix         \
58   stdio_h               \
59   vasnprintf            \
60   vasprintf             \
61   vdprintf              \
62   vfprintf-posix        \
63   vprintf-posix         \
64   vsnprintf             \
65   vsprintf-posix
66
67 allow_AC_LIBOBJ_or := $(shell echo $(allow_AC_LIBOBJ) | tr -s ' ' '|')
68
69 sc_prohibit_AC_LIBOBJ_in_m4:
70         url=http://article.gmane.org/gmane.comp.lib.gnulib.bugs/26995;  \
71         if test -d .git; then                                           \
72           git ls-files m4                                               \
73              | grep -Ev '^m4/($(allow_AC_LIBOBJ_or))\.m4$$'             \
74              | xargs grep '^ *AC_LIBOBJ('                               \
75             && { printf '%s\n' 'Do not use AC_LIBOBJ in m4/*.m4;'       \
76                  "see <$$url>"; exit 1; } || :;                         \
77         else :; fi
78
79 sc_pragma_columns:
80         if test -d .git; then                                           \
81           git ls-files|grep '\.in\.h$$'                                 \
82               | xargs grep -l '^@PRAGMA_SYSTEM_HEADER@'                 \
83               | xargs grep -L '^@PRAGMA_COLUMNS@'                       \
84               | grep .                                                  \
85             && { printf '%s\n'                                          \
86                    'the files listed above use @PRAGMA_SYSTEM_HEADER@'  \
87                    'without also using @PRAGMA_COLUMNS@' 1>&2;          \
88                  exit 1; } || :;                                        \
89         else :; fi
90
91 # Verify that certain (for now, only Jim Meyering and Eric Blake's)
92 # *.c files are consistently cpp indented.
93 sc_cpp_indent_check:
94         ./gnulib-tool --extract-filelist \
95             $$(cd ./modules; grep -ilrE '(meyering|blake)' .) \
96           | sort -u \
97           | grep '\.c$$' \
98           | grep -v '/getloadavg\.c$$' \
99           | xargs cppi -c
100
101 # Ensure that the list of symbols checked for by the
102 # sc_prohibit_intprops_without_use rule match those in the actual file.
103 # Extract the symbols from the .h file and compare with the list of
104 # symbols extracted from the rule in maint.mk.
105 sc_check_sym_list:
106         i=lib/intprops.h; \
107         diff -u <(perl -lne '/^# *define ([A-Z]\w+)\(/ and print $$1' $$i|fmt) \
108           <(sed -n /^_intprops_name/,/^_intprops_syms_re/p top/maint.mk \
109             |sed '/^_/d;s/^  //;s/      *\\$$//')
110
111 # Regenerate some files that are stored in the repository.
112 regen: MODULES.html
113
114 # MODULES.html is periodically being generated and copied to the web pages at
115 # :ext:USER@cvs.savannah.gnu.org:/web/gnulib/gnulib/
116 # where it then appears at <http://www.gnu.org/software/gnulib/MODULES.html>.
117 MODULES.html: MODULES.html.sh
118         ./MODULES.html.sh > MODULES.html
119
120 # Run this rule once per year (usually early in January)
121 # to update all FSF copyright year lists here.
122 # We exclude the files listed in srclist.txt (maintained elsewhere)
123 # as well as those in tests/unictype (generated).
124 # Also exclude any file that includes the "GENERATED AUTOMATICALLY" comment,
125 # being careful not to exclude code that merely generates the comment.
126 # Also exclude doc/INSTALL*, since they too are generated.
127 update-copyright:
128         exempt=$$(mktemp);                                              \
129         grep -v '^#' config/srclist.txt|grep -v '^$$'                   \
130           | while read src dst; do                                      \
131               test -f "$$dst" && { echo "$$dst"; continue; };           \
132               test -d "$$dst" || continue;                              \
133               echo "$$dst"/$$(basename "$$src");                        \
134             done > $$exempt;                                            \
135         git ls-files tests/unictype >> $$exempt;                        \
136         git ls-files doc/INSTALL* >> $$exempt;                          \
137         git ls-files | grep -vFf $$exempt                               \
138           | xargs grep -L '^/\*.*GENERATED AUTOMATICALLY'               \
139           | UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79                         \
140             UPDATE_COPYRIGHT_USE_INTERVALS=1                            \
141               xargs build-aux/update-copyright