2 # This Makefile fragment is intended to be useful by any GNU-like project.
3 # This file originate from coreutils, CPPI, Bison, and Autoconf.
5 # Copyright (C) 2001-2008 Free Software Foundation, Inc.
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.
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.
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/>.
21 MYSELF := $(srcdir)/$(ME)
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]')
28 # Add some more files to check, typically set in cfg.mk.
29 C_SOURCES += $(C_SOURCES_ADD)
31 # Do not save the original name or timestamp in the .tar.gz file.
32 # Use --rsyncable if available.
34 $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
35 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
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.
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; \
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; \
52 sc_cast_of_alloca_return_value:
53 @grep -nE '\*\) *alloca\>' $(C_SOURCES) && \
54 { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
58 @grep -n '[ ] ' $(C_SOURCES) && \
59 { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
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' \
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; \
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' \
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 \
89 { echo "$(ME): the above files include <assert.h> but don't use it" \
93 @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' $(C_SOURCES) && \
94 { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
97 # Each nonempty line must start with a year number, or a TAB.
99 @grep -n '^[^12 ]' $$(find . -name ChangeLog) && \
100 { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
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)
108 syntax-check: $(syntax-check-rules)
114 lcov --directory . --zerocounters
116 COVERAGE_CCOPTS ?= "-g --coverage"
117 COVERAGE_OUT ?= doc/coverage
120 make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
121 make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
122 mkdir -p $(COVERAGE_OUT)
123 lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
127 genhtml --output-directory $(COVERAGE_OUT) \
128 $(COVERAGE_OUT)/$(PACKAGE).info \
129 --highlight --frames --legend \
130 --title "$(PACKAGE_NAME)"
132 coverage: init-coverage build-coverage gen-coverage
134 # Update gettext files.
135 PACKAGE ?= $(shell basename $(PWD))
136 POURL = http://translationproject.org/latest/$(PACKAGE)/
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
146 INDENT_SOURCES ?= $(C_SOURCES)
149 indent $(INDENT_SOURCES)