Imported Upstream version 3.5.1
[platform/upstream/ccache.git] / dev.mk.in
1 # GNU make syntax reigns in this file.
2
3 all_cflags += -Werror @more_warnings@
4 all_cppflags += -MD -MP -MF .deps/$(subst .._,,$(subst /,_,$<)).d
5
6 A2X = a2x
7 ASCIIDOC = asciidoc
8 CPPCHECK = cppcheck
9 CPPCHECK_SUPPRESSIONS = misc/cppcheck-suppressions.txt
10 SHELLCHECK = shellcheck
11 SHELLCHECK_EXCLUDES = misc/shellcheck-excludes.txt
12 SCAN_BUILD = scan-build
13 DOCKER = docker
14 GPERF = gperf
15 TEST = test
16
17 version := \
18     $(shell (git --git-dir=$(srcdir)/.git describe --dirty || git --git-dir=$(srcdir)/.git describe || echo vunknown) \
19             2>/dev/null | sed -e 's/v//' -e 's/-/+/' -e 's/-/_/g')
20
21 dist_dir = ccache-$(version)
22 dist_archives = \
23     ccache-$(version).tar.bz2 \
24     ccache-$(version).tar.gz
25 ifneq ($(shell uname), Darwin)
26     dist_archives += ccache-$(version).tar.xz
27 endif
28
29 generated_docs = \
30     LICENSE.html \
31     doc/AUTHORS.html \
32     doc/MANUAL.html \
33     doc/NEWS.html \
34     doc/ccache.1
35 built_dist_files = $(generated_sources) $(generated_docs)
36
37 headers = \
38     src/ccache.h \
39     src/compopt.h \
40     src/conf.h \
41     src/confitems.h \
42     src/counters.h \
43     src/envtoconfitems.h \
44     src/getopt_long.h \
45     src/hash.h \
46     src/hashtable.h \
47     src/hashtable_itr.h \
48     src/hashtable_private.h \
49     src/hashutil.h \
50     src/language.h \
51     src/macroskip.h \
52     src/manifest.h \
53     src/mdfour.h \
54     src/murmurhashneutral2.h \
55     src/system.h \
56     src/unify.h \
57     unittest/framework.h \
58     unittest/util.h
59 generated_headers = \
60     unittest/suites.h
61
62 files_to_clean += *.tar.bz2 *.tar.gz *.tar.xz *.xml .deps/* perfdir.*
63 files_to_distclean += $(built_dist_files) src/version.c unittest/suites.h
64 files_to_distclean += .deps dev.mk
65
66 source_dist_files = \
67     $(non_3pp_sources) \
68     $(3pp_sources) \
69     $(headers) \
70     $(test_sources) \
71     CONTRIBUTING.md \
72     GPL-3.0.txt \
73     LICENSE.adoc \
74     Makefile.in \
75     README.md \
76     autogen.sh \
77     config.guess \
78     config.h.in \
79     config.sub \
80     configure \
81     configure.ac \
82     dev.mk.in \
83     doc/AUTHORS.adoc \
84     doc/MANUAL.adoc \
85     doc/NEWS.adoc \
86     install-sh \
87     m4 \
88     src/confitems.gperf \
89     src/confitems_lookup.c \
90     src/envtoconfitems.gperf \
91     src/envtoconfitems_lookup.c \
92     src/getopt_long.c \
93     src/main.c \
94     src/zlib/*.c \
95     src/zlib/*.h \
96     test/run \
97     test/suites/*
98
99 dist_files = \
100     $(addprefix $(srcdir)/, $(source_dist_files)) \
101     $(built_dist_files)
102
103 uncrustify_exclude_files = \
104     src/getopt_long.c \
105     src/hashtable.c \
106     src/hashtable_itr.c \
107     src/snprintf.c
108
109 ifneq ($(shell sed 's/.*"\(.*\)".*/\1/' src/version.c 2>/dev/null),$(version))
110   $(shell echo 'extern const char CCACHE_VERSION[]; const char CCACHE_VERSION[] = "$(version)";' >src/version.c)
111 endif
112 src/version.o: src/version.c
113
114 %_lookup.c: %.gperf
115         $(if $(quiet),@echo "  GPERF    $@")
116         $(Q)$(GPERF) $< >$@
117         $(Q)echo "size_t $$(echo '$(notdir $*)_count(void)') { return $$(sed -nr 's/.*TOTAL_KEYWORDS = (.+),.*/\1/p' $@); }" >>$@
118
119 .PHONY: dist
120 dist: $(dist_archives)
121
122 $(dist_archives): $(dist_files)
123         tmpdir=$$(mktemp -d /tmp/tmp-ccache-dist.XXXXXX) && \
124         dir=$$tmpdir/$(dist_dir) && \
125         mkdir $$dir && \
126         (cd $(srcdir) && \
127          rsync -r --relative $(source_dist_files) $$dir) && \
128         cp $(srcdir)/doc/INSTALL-from-release-archive.md $$dir/INSTALL.md && \
129         (cd $(builddir) && \
130          rsync -r --relative $(built_dist_files) $$dir) && \
131         echo "Remove this file to enable developer mode." >$$dir/dev_mode_disabled && \
132         (cd $$tmpdir && \
133          tarcompression= && \
134          case $@ in \
135              *.bz2) tarcompression=-j ;; \
136              *.gz) tarcompression=-z ;; \
137              *.xz) tarcompression=-J ;; \
138          esac && \
139          tar -c $$tarcompression -f $(CURDIR)/$@ $(dist_dir)) && \
140         rm -rf $$tmpdir
141
142 # $(1): extra configure options
143 define do_distcheck
144         tmpdir=$$(mktemp -d /tmp/tmp-ccache-distcheck.XXXXXX) && \
145         (cd $$tmpdir && \
146          tar xf $(CURDIR)/$< && \
147          mkdir -p $(dist_dir)/build && \
148          chmod -R a-w $(dist_dir) && \
149          chmod u+w $(dist_dir)/build && \
150          cd $(dist_dir)/build && \
151          ../configure --enable-more-warnings --prefix=$$tmpdir/root $(1) && \
152          $(MAKE) install CFLAGS=-Werror V=1 && \
153          $(MAKE) installcheck) && \
154         chmod -R u+w $$tmpdir/$(dist_dir) && \
155         rm -rf $$tmpdir
156 endef
157
158 .PHONY: distcheck
159 distcheck: $(firstword $(dist_archives))
160         $(call do_distcheck, --without-bundled-zlib)
161         $(call do_distcheck, --with-bundled-zlib)
162         $(call do_distcheck, CC=clang)
163
164 .PHONY: docs
165 docs: $(generated_docs)
166
167 %.html: %.adoc
168         @mkdir -p $(@D)
169         $(if $(quiet),@echo "  ASCIIDOC $@")
170         $(Q)$(ASCIIDOC) -o $@ -a revnumber=$(version) -a toc -b xhtml11 $<
171
172 %.xml: %.adoc
173         @mkdir -p $(@D)
174 # Make literals stand out as bold in the man page:
175         $(if $(quiet),@echo "  ASCIIDOC $@")
176         $(Q)$(ASCIIDOC) -a revnumber=$(version) -d manpage -b docbook -o - $< | \
177           perl -pe 's!<literal>(.*?)</literal>!<emphasis role="strong">\1</emphasis>!g' >$@
178
179 doc/ccache.1: doc/MANUAL.xml
180         $(if $(quiet),@echo "  A2X      $@")
181         $(Q)$(A2X) --doctype manpage --format manpage $<
182
183 .PHONY: update-authors
184 update-authors:
185         git log --pretty=format:"* %aN <%aE>" \
186           | sort -u \
187           | perl -00 -p -i -e 's/^\*.*/<STDIN> . "\n"/es' doc/AUTHORS.adoc
188
189 .PHONY: check-syntax
190 check-syntax:
191         $(CC) $(all_cppflags) -I. $(all_cflags) -S -o /dev/null $(CHK_SOURCES)
192
193 .PHONY: cppcheck
194 cppcheck:
195         $(CPPCHECK) --suppressions-list=$(CPPCHECK_SUPPRESSIONS) \
196           --inline-suppr -q --enable=all --force -I . \
197           --template='cppcheck: warning: {id}:{file}:{line}: {message}' \
198           $(non_3pp_sources) src/main.c $(test_sources)
199
200 .PHONY: shellcheck
201 shellcheck: test/suites/*.bash
202         $(SHELLCHECK) --shell=bash --exclude=$(shell sed -e 's/:.*//' <$(SHELLCHECK_EXCLUDES) | grep -v '#' | tr '\n' ',' | sed -e 's/,$$//') $^
203
204 .PHONY: uncrustify
205 uncrustify:
206         uncrustify -c misc/uncrustify.cfg --no-backup --replace $(filter-out $(uncrustify_exclude_files), $(base_sources)) $(test_sources)
207
208 .PHONY: analyze
209 analyze:
210         $(SCAN_BUILD) --use-cc=$(CC) $(srcdir)/configure
211         $(SCAN_BUILD) --use-cc=$(CC) --status-bugs $(MAKE) -B
212
213 .PHONY: docker
214 docker: misc/Dockerfile
215         $(DOCKER) build -f $< $(srcdir)
216
217 .PHONY: travis
218 travis: .travis/Dockerfile
219         $(DOCKER) inspect travis-build >/dev/null || $(DOCKER) build -t travis-build .travis
220         $(DOCKER) run --rm --volume $(PWD):/src --tmpfs /dst:rw,exec --env ASAN_OPTIONS='$(ASAN_OPTIONS)' travis-build \
221         sh -c "cd /src && ./autogen.sh && cd /dst && CC=$(CC) CFLAGS='$(CFLAGS)' /src/configure $(HOST) && make && make $(TEST)"
222
223 -include .deps/*.d