3177d577a59f50fcd0895fc0918cbc9506e09b6f
[gnulib.git] / top / maint.mk
1 # -*-Makefile-*-
2 # This Makefile fragment is intended to be useful by any GNU-like project.
3 # This file originate from coreutils, CPPI, Bison, and Autoconf.
4
5 # Copyright (C) 2001-2009 Free Software Foundation, Inc.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License,
10 # or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 ME := maint.mk
21 MYSELF := $(srcdir)/$(ME)
22
23 # List of all C-like source code files that will be tested for
24 # stylistic "errors".  You may want to define this to something
25 # more complex in cfg.mk.
26 C_SOURCES ?= $(shell find . -name '*.[chly]')
27
28 # Add some more files to check, typically set in cfg.mk.
29 C_SOURCES += $(C_SOURCES_ADD)
30
31 # Do not save the original name or timestamp in the .tar.gz file.
32 # Use --rsyncable if available.
33 gzip_rsyncable := \
34   $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
35 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
36
37 # Prevent programs like 'sort' from considering distinct strings to be equal.
38 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
39 export LC_ALL = C
40
41 # Casting arguments to free is never necessary.
42 sc_cast_of_argument_to_free:
43         @grep -nE '\<free *\( *\(' $(C_SOURCES) &&                      \
44           { echo '$(ME): don'\''t cast free argument' 1>&2;             \
45             exit 1; } || :
46
47 sc_cast_of_x_alloc_return_value:
48         @grep -nE '\*\) *x(m|c|re)alloc\>' $(C_SOURCES) &&              \
49           { echo '$(ME): don'\''t cast x*alloc return value' 1>&2;      \
50             exit 1; } || :
51
52 sc_cast_of_alloca_return_value:
53         @grep -nE '\*\) *alloca\>' $(C_SOURCES) &&                      \
54           { echo '$(ME): don'\''t cast alloca return value' 1>&2;       \
55             exit 1; } || :
56
57 sc_space_tab:
58         @grep -n '[ ]   ' $(C_SOURCES) &&                               \
59           { echo '$(ME): found SPACE-TAB sequence; remove the SPACE'    \
60                 1>&2; exit 1; } || :
61
62 # Don't use the old ato* functions in `real' code.
63 # They provide no error checking mechanism.
64 # Instead, use strto* functions.
65 sc_prohibit_atoi_atof:
66         @grep -nE '\<ato([filq]|ll)\>' $(C_SOURCES) &&                  \
67           { echo '$(ME): do not use ato''f, ato''i, ato''l, ato''ll, or ato''q' \
68                 1>&2; exit 1; } || :
69
70 # Using EXIT_SUCCESS as the first argument to error is misleading,
71 # since when that parameter is 0, error does not exit.  Use `0' instead.
72 sc_error_exit_success:
73         @grep -nF 'error (EXIT_SUCCESS,' $(C_SOURCES) &&                \
74           { echo '$(ME): found error (EXIT_SUCCESS' 1>&2;               \
75             exit 1; } || :
76
77 # Stylistic, use #ifdef instead of #if
78 sc_no_if_have_config_h:
79         @grep -n '^# *if HAVE_CONFIG_H' $(C_SOURCES) &&                 \
80           { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef'    \
81                 1>&2; exit 1; } || :
82
83 # Prohibit the inclusion of assert.h without an actual use of assert.
84 sc_prohibit_assert_without_use:
85         @files=$$(grep -l '# *include [<"]assert\.h[>"]' $(C_SOURCES)   \
86                         | grep '\.[cy]$$') &&                           \
87         grep -L '\<assert (' $$files                                    \
88             | grep . &&                                                 \
89           { echo "$(ME): the above files include <assert.h> but don't use it" \
90                 1>&2; exit 1; } || :
91
92 sc_obsolete_symbols:
93         @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' $(C_SOURCES) &&     \
94           { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY'       \
95                 1>&2; exit 1; } || :
96
97 # Each nonempty line must start with a year number, or a TAB.
98 sc_changelog:
99         @grep -n '^[^12 ]' $$(find . -name ChangeLog) &&        \
100           { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2;  \
101             exit 1; } || :
102
103 # Collect the names of rules starting with `sc_'.
104 syntax-check-rules := \
105   $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(MYSELF))
106 .PHONY: $(syntax-check-rules)
107
108 syntax-check: $(syntax-check-rules)
109
110 # Code Coverage
111
112 init-coverage:
113         $(MAKE) $(AM_MAKEFLAGS) clean
114         lcov --directory . --zerocounters
115
116 COVERAGE_CCOPTS ?= "-g --coverage"
117 COVERAGE_OUT ?= doc/coverage
118
119 build-coverage:
120         $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
121         $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
122         mkdir -p $(COVERAGE_OUT)
123         lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
124                 --capture
125
126 gen-coverage:
127         genhtml --output-directory $(COVERAGE_OUT) \
128                 $(COVERAGE_OUT)/$(PACKAGE).info \
129                 --highlight --frames --legend \
130                 --title "$(PACKAGE_NAME)"
131
132 coverage: init-coverage build-coverage gen-coverage
133
134 # Update gettext files.
135 PACKAGE ?= $(shell basename $(PWD))
136 POURL = http://translationproject.org/latest/$(PACKAGE)/
137 PODIR ?= po
138 refresh-po:
139         rm -f $(PODIR)/*.po && \
140         echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
141         wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
142         echo 'en@boldquot' > $(PODIR)/LINGUAS && \
143         echo 'en@quot' >> $(PODIR)/LINGUAS && \
144         ls $(PODIR)/*.po | sed 's/\.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS
145
146 INDENT_SOURCES ?= $(C_SOURCES)
147 .PHONY: indent
148 indent:
149         indent $(INDENT_SOURCES)