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/>.
22 # List of all C-like source code files that will be tested for
23 # stylistic "errors". You may want to define this to something
24 # more complex in cfg.mk.
25 C_SOURCES ?= $(shell find . -name '*.[chly]')
27 # Add some more files to check, typically set in cfg.mk.
28 C_SOURCES += $(C_SOURCES_ADD)
30 # Do not save the original name or timestamp in the .tar.gz file.
31 # Use --rsyncable if available.
33 $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
34 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
36 # Prevent programs like 'sort' from considering distinct strings to be equal.
37 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
40 # Casting arguments to free is never necessary.
41 sc_cast_of_argument_to_free:
42 @grep -nE '\<free *\( *\(' $(C_SOURCES) && \
43 { echo '$(ME): don'\''t cast free argument' 1>&2; \
46 sc_cast_of_x_alloc_return_value:
47 @grep -nE '\*\) *x(m|c|re)alloc\>' $(C_SOURCES) && \
48 { echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
51 sc_cast_of_alloca_return_value:
52 @grep -nE '\*\) *alloca\>' $(C_SOURCES) && \
53 { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
57 @grep -n '[ ] ' $(C_SOURCES) && \
58 { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
61 # Don't use the old ato* functions in `real' code.
62 # They provide no error checking mechanism.
63 # Instead, use strto* functions.
64 sc_prohibit_atoi_atof:
65 @grep -nE '\<ato([filq]|ll)\>' $(C_SOURCES) && \
66 { echo '$(ME): do not use ato''f, ato''i, ato''l, ato''ll, or ato''q' \
69 # Using EXIT_SUCCESS as the first argument to error is misleading,
70 # since when that parameter is 0, error does not exit. Use `0' instead.
71 sc_error_exit_success:
72 @grep -nF 'error (EXIT_SUCCESS,' $(C_SOURCES) && \
73 { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; \
76 # Stylistic, use #ifdef instead of #if
77 sc_no_if_have_config_h:
78 @grep -n '^# *if HAVE_CONFIG_H' $(C_SOURCES) && \
79 { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef' \
82 # Prohibit the inclusion of assert.h without an actual use of assert.
83 sc_prohibit_assert_without_use:
84 @files=$$(grep -l '# *include [<"]assert\.h[>"]' $(C_SOURCES) \
85 | grep '\.[cy]$$') && \
86 grep -L '\<assert (' $$files \
88 { echo "$(ME): the above files include <assert.h> but don't use it" \
92 @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' $(C_SOURCES) && \
93 { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
96 # Each nonempty line must start with a year number, or a TAB.
98 @grep -n '^[^12 ]' $$(find . -name ChangeLog) && \
99 { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
102 # Collect the names of rules starting with `sc_'.
103 syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(ME))
104 .PHONY: $(syntax-check-rules)
106 syntax-check: $(syntax-check-rules)
112 lcov --directory . --zerocounters
114 COVERAGE_CCOPTS ?= "-g -fprofile-arcs -ftest-coverage"
115 COVERAGE_OUT ?= doc/coverage
118 make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
119 make CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
120 mkdir -p $(COVERAGE_OUT)
121 lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
125 genhtml --output-directory $(COVERAGE_OUT) \
126 $(COVERAGE_OUT)/$(PACKAGE).info \
127 --highlight --frames --legend \
128 --title "$(PACKAGE_NAME)"
130 coverage: init-coverage build-coverage gen-coverage
132 # Update gettext files.
133 PACKAGE ?= $(shell basename $(PWD))
134 POURL = http://translationproject.org/latest/$(PACKAGE)/
137 rm -f $(PODIR)/*.po && \
138 echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
139 wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
140 echo 'en@boldquot' > $(PODIR)/LINGUAS && \
141 echo 'en@quot' >> $(PODIR)/LINGUAS && \
142 ls $(PODIR)/*.po | sed 's/.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS
144 INDENT_SOURCES ?= $(C_SOURCES)
147 indent $(INDENT_SOURCES)