maintainer-makefile: (PO_DOMAIN): New variable, allows overriding of gettext domain.
[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 # There are many rules below that prohibit constructs in this package.
42 # If the offending construct can be matched with a grep-E-style regexp,
43 # use this macro.  The shell variables "re" and "msg" must be defined.
44 define _prohibit_regexp
45   dummy=; : so we do not need a semicolon before each use;              \
46   test "x$$re" != x || { echo '$(ME): re not defined' 1>&2; exit 1; };  \
47   test "x$$msg" != x || { echo '$(ME): msg not defined' 1>&2; exit 1; };\
48   grep $(_ignore_case) -nE "$$re" $(C_SOURCES) &&                       \
49     { echo '$(ME): '"$$msg" 1>&2; exit 1; } || :
50 endef
51
52 # Casting arguments to free is never necessary.
53 sc_cast_of_argument_to_free:
54         @re='\<free *\( *\(' msg='don'\''t cast free argument'          \
55           $(_prohibit_regexp)
56
57 sc_cast_of_x_alloc_return_value:
58         @re='\*\) *x(m|c|re)alloc\>'                                    \
59         msg='don'\''t cast x*alloc return value'                        \
60           $(_prohibit_regexp)
61
62 sc_cast_of_alloca_return_value:
63         @re='\*\) *alloca\>' msg='don'\''t cast alloca return value'    \
64           $(_prohibit_regexp)
65
66 sc_space_tab:
67         @re='[ ]        ' msg='found SPACE-TAB sequence; remove the SPACE' \
68           $(_prohibit_regexp)
69
70 # Don't use *scanf or the old ato* functions in `real' code.
71 # They provide no error checking mechanism.
72 # Instead, use strto* functions.
73 sc_prohibit_atoi_atof:
74         @re='\<([fs]?scanf|ato([filq]|ll)) *\('                         \
75         msg='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \
76           $(_prohibit_regexp)
77
78 # Using EXIT_SUCCESS as the first argument to error is misleading,
79 # since when that parameter is 0, error does not exit.  Use `0' instead.
80 sc_error_exit_success:
81         @grep -nF 'error (EXIT_SUCCESS,' $(C_SOURCES) &&                \
82           { echo '$(ME): found error (EXIT_SUCCESS' 1>&2;               \
83             exit 1; } || :
84
85 # Stylistic, use #ifdef instead of #if
86 sc_no_if_have_config_h:
87         @grep -n '^# *if HAVE_CONFIG_H' $(C_SOURCES) &&                 \
88           { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef'    \
89                 1>&2; exit 1; } || :
90
91 # To use this "command" macro, you must first define two shell variables:
92 # h: the header, enclosed in <> or ""
93 # re: a regular expression that matches IFF something provided by $h is used.
94 define _header_without_use
95   h_esc=`echo "$$h"|sed 's/\./\\./g'`;                                  \
96   if $(C_SOURCES) | grep -l '\.c$$' > /dev/null; then                   \
97     files=$$(grep -l '^# *include '"$$h_esc"                            \
98              $$($(C_SOURCES) | grep '\.c$$')) &&                        \
99     grep -LE "$$re" $$files | grep . &&                                 \
100       { echo "$(ME): the above files include $$h but don't use it"      \
101         1>&2; exit 1; } || :;                                           \
102   else :;                                                               \
103   fi
104 endef
105
106 # Prohibit the inclusion of assert.h without an actual use of assert.
107 sc_prohibit_assert_without_use:
108         @h='<assert.h>' re='\<assert *\(' $(_header_without_use)
109
110 sc_obsolete_symbols:
111         @re='\<(HAVE''_FCNTL_H|O''_NDELAY)\>'                           \
112         msg='do not use HAVE''_FCNTL_H or O'_NDELAY                     \
113           $(_prohibit_regexp)
114
115 # Each nonempty ChangeLog line must start with a year number, or a TAB.
116 sc_changelog:
117         @grep -n '^[^12 ]' $$(find . -name ChangeLog) &&        \
118           { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2;  \
119             exit 1; } || :
120
121 # Collect the names of rules starting with `sc_'.
122 syntax-check-rules := \
123   $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(MYSELF))
124 .PHONY: $(syntax-check-rules)
125
126 syntax-check: $(syntax-check-rules)
127
128 # Code Coverage
129
130 init-coverage:
131         $(MAKE) $(AM_MAKEFLAGS) clean
132         lcov --directory . --zerocounters
133
134 COVERAGE_CCOPTS ?= "-g --coverage"
135 COVERAGE_OUT ?= doc/coverage
136
137 build-coverage:
138         $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
139         $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
140         mkdir -p $(COVERAGE_OUT)
141         lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
142                 --capture
143
144 gen-coverage:
145         genhtml --output-directory $(COVERAGE_OUT) \
146                 $(COVERAGE_OUT)/$(PACKAGE).info \
147                 --highlight --frames --legend \
148                 --title "$(PACKAGE_NAME)"
149
150 coverage: init-coverage build-coverage gen-coverage
151
152 # Update gettext files.
153 PACKAGE ?= $(shell basename $(PWD))
154 PO_DOMAIN ?= $(PACKAGE)
155 POURL = http://translationproject.org/latest/$(PO_DOMAIN)/
156 PODIR ?= po
157 refresh-po:
158         rm -f $(PODIR)/*.po && \
159         echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
160         wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
161         echo 'en@boldquot' > $(PODIR)/LINGUAS && \
162         echo 'en@quot' >> $(PODIR)/LINGUAS && \
163         ls $(PODIR)/*.po | sed 's/\.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS
164
165 INDENT_SOURCES ?= $(C_SOURCES)
166 .PHONY: indent
167 indent:
168         indent $(INDENT_SOURCES)