Debian Codegraph @

Makefile

raw
1 #
2 # Makefile for LCOV
3 #
4 # Make targets:
5 # - install: install LCOV tools and man pages on the system
6 # - uninstall: remove tools and man pages from the system
7 # - dist: create files required for distribution, i.e. the lcov.tar.gz
8 # and the lcov.rpm file. Just make sure to adjust the VERSION
9 # and RELEASE variables below - both version and date strings
10 # will be updated in all necessary files.
11 # - checkstyle: check source files for coding style issues
12 # MODE=(full|diff) [UPDATE=1]
13 # - clean: remove all generated files
14 # - release: finalize release and create git tag for specified VERSION
15 # - test: run regression tests.
16 # additional Make variables:
17 # COVERGAGE=1
18 # - enable perl coverage data collection
19 # TESTCASE_ARGS=string
20 # - pass these arguments to testcase script
21 # Sample args:
22 # --update - overwrite GOLD file with
23 # result
24 # --parallel n - use --parallel flag
25 # --home path - path to lcov script
26 # --llvm - use LLVM rather than gcc
27 # --keep-going - don't stop on error
28 # --verbose - echo commands to test.log
29 # Note that not all tests have been updated to use
30 # all flags
31
32 VERSION := $(shell bin/get_version.sh --version)
33 RELEASE := $(shell bin/get_version.sh --release)
34 FULL := $(shell bin/get_version.sh --full)
35
36 # Set this variable during 'make install' to specify the interpreters used in
37 # installed scripts, or leave empty to keep the current interpreter.
38 export LCOV_PERL_PATH := /usr/bin/perl
39 export LCOV_PYTHON_PATH := /usr/bin/python3
40
41 PREFIX := /usr/local
42
43 FIRST_CHAR = $(shell echo "$(DESTDIR)$(PREFIX)" | cut -c 1)
44 ifneq ("$(FIRST_CHAR)", "/")
45 $(error "DESTDIR + PREFIX expected to be absolute path - found $(FIRST_CHAR)")
46 endif
47
48 CFG_DIR := $(PREFIX)/etc
49 BIN_DIR := $(PREFIX)/bin
50 LIB_DIR := $(PREFIX)/lib/lcov
51 MAN_DIR := $(PREFIX)/share/man
52 SHARE_DIR := $(PREFIX)/share/lcov/
53 SCRIPT_DIR := $(SHARE_DIR)/support-scripts
54
55 CFG_INST_DIR := $(DESTDIR)$(CFG_DIR)
56 BIN_INST_DIR := $(DESTDIR)$(BIN_DIR)
57 LIB_INST_DIR := $(DESTDIR)$(LIB_DIR)
58 MAN_INST_DIR := $(DESTDIR)$(MAN_DIR)
59 SHARE_INST_DIR := $(DESTDIR)$(SHARE_DIR)
60 SCRIPT_INST_DIR := $(SHARE_INST_DIR)/support-scripts
61
62 TMP_DIR := $(shell mktemp -d)
63 FILES := README Makefile lcovrc \
64 $(wildcard bin/*) $(wildcard example/*) $(wildcard lib/*) \
65 $(wildcard man/*) $(wildcard rpm/*) $(wildcard scripts/*)
66 DIST_CONTENT := CONTRIBUTING COPYING README Makefile lcovrc \
67 bin example lib man rpm scripts tests
68
69 EXES = \
70 lcov genhtml geninfo genpng gendesc \
71 perl2lcov py2lcov xml2lcov xml2lcovutil.py \
72 llvm2lcov
73 # there may be both public and non-public user scripts - so lets not show
74 # any of their names
75 SCRIPTS = $(shell ls scripts | grep -v -E '([\#\~]|\.orig|\.bak|\.BAK)' )
76 LIBS = lcovutil.pm
77 MAN_SECTIONS = 1 5
78 # similarly, lets not talk about man pages
79 MANPAGES = $(foreach s, $(MAN_SECTIONS), $(foreach m, $(shell cd man ; ls *.$(s)), man$(s)/$(m)))
80
81 # Program for checking coding style
82 CHECKSTYLE = $(CURDIR)/bin/checkstyle.sh
83
84 INSTALL = install
85 FIX = $(realpath bin/fix.pl)
86 RM = rm -f
87 RMDIR = rmdir
88
89 export V
90 ifeq ("${V}","1")
91 echocmd=
92 else
93 echocmd=echo $1 ;
94 .SILENT:
95 endif
96
97 .PHONY: all info clean install uninstall rpms test
98
99 all: info
100
101 info:
102 @echo "Available make targets:"
103 @echo " install : install binaries and man pages in DESTDIR (default /)"
104 @echo " uninstall : delete binaries and man pages from DESTDIR (default /)"
105 @echo " dist : create packages (RPM, tarball) ready for distribution"
106 @echo " check : perform self-tests"
107 @echo " checkstyle: check source files for coding style issues"
108 @echo " release : finalize release and create git tag for specified VERSION"
109 @echo " test : same as 'make check'"
110
111 clean:
112 $(call echocmd," CLEAN lcov")
113 $(RM) lcov-*.tar.gz lcov-*.rpm
114 $(RM) -r ./bin/__pycache__
115 $(MAKE) -C example -s clean
116 $(MAKE) -C tests -s clean
117 find . -name '*.tdy' -o -name '*.orig' | xargs rm -f
118
119 install:
120 $(INSTALL) -d -m 755 $(BIN_INST_DIR)
121 for b in $(EXES) ; do \
122 $(call echocmd," INSTALL $(BIN_INST_DIR)/$$b") \
123 $(INSTALL) -m 755 bin/$$b $(BIN_INST_DIR)/$$b ; \
124 $(FIX) --version $(VERSION) --release $(RELEASE) \
125 --libdir $(LIB_DIR) --bindir $(BIN_DIR) \
126 --fixver --fixlibdir --fixbindir \
127 --exec $(BIN_INST_DIR)/$$b ; \
128 done
129 $(INSTALL) -d -m 755 $(SCRIPT_INST_DIR)
130 for s in $(SCRIPTS) ; do \
131 $(call echocmd," INSTALL $(SCRIPT_INST_DIR)/$$s") \
132 $(INSTALL) -m 755 scripts/$$s $(SCRIPT_INST_DIR)/$$s ; \
133 $(FIX) --version $(VERSION) --release $(RELEASE) \
134 --libdir $(LIB_DIR) --bindir $(BIN_DIR) \
135 --fixver --fixlibdir \
136 --fixscriptdir --scriptdir $(SCRIPT_DIR) \
137 --exec $(SCRIPT_INST_DIR)/$$s ; \
138 done
139 $(INSTALL) -d -m 755 $(LIB_INST_DIR)
140 for l in $(LIBS) ; do \
141 $(call echocmd," INSTALL $(LIB_INST_DIR)/$$l") \
142 $(INSTALL) -m 644 lib/$$l $(LIB_INST_DIR)/$$l ; \
143 $(FIX) --version $(VERSION) --release $(RELEASE) \
144 --libdir $(LIB_DIR) --bindir $(BIN_DIR) \
145 --fixver --fixlibdir --fixbindir \
146 --exec $(LIB_INST_DIR)/$$l ; \
147 done
148 for section in $(MAN_SECTIONS) ; do \
149 DEST=$(MAN_INST_DIR)/man$$section ; \
150 $(INSTALL) -d -m 755 $$DEST ; \
151 for m in man/*.$$section ; do \
152 F=`basename $$m` ; \
153 $(call echocmd," INSTALL $$DEST/$$F") \
154 $(INSTALL) -m 644 man/$$F $$DEST/$$F ; \
155 $(FIX) --version $(VERSION) --fixver --fixdate \
156 --fixscriptdir --scriptdir $(SCRIPT_DIR) \
157 --manpage $$DEST/$$F ; \
158 done ; \
159 done
160 mkdir -p $(SHARE_INST_DIR)
161 for d in example tests ; do \
162 ( cd $$d ; make clean ) ; \
163 find $$d -type d -exec mkdir -p "$(SHARE_INST_DIR){}" \; ; \
164 find $$d -type f -exec $(INSTALL) -Dm 644 "{}" "$(SHARE_INST_DIR){}" \; ; \
165 done ;
166 @chmod -R ugo+x $(SHARE_INST_DIR)/tests/bin
167 @find $(SHARE_INST_DIR)/tests \( -name '*.sh' -o -name '*.pl' \) -exec chmod ugo+x {} \;
168 $(INSTALL) -d -m 755 $(CFG_INST_DIR)
169 $(call echocmd," INSTALL $(CFG_INST_DIR)/lcovrc")
170 $(INSTALL) -m 644 lcovrc $(CFG_INST_DIR)/lcovrc
171 $(call echocmd," done INSTALL")
172
173
174 uninstall:
175 for b in $(EXES) ; do \
176 $(call echocmd," UNINST $(BIN_INST_DIR)/$$b") \
177 $(RM) $(BIN_INST_DIR)/$$b ; \
178 done
179 $(RMDIR) $(BIN_INST_DIR) || true
180 # .../lib/lcov installed by us - so safe to remove
181 $(call echocmd," UNINST $(LIB_INST_DIR)")
182 $(RM) -r $(LIB_INST_DIR)
183 $(call echocmd," UNINST $(shell dirname $(LIB_INST_DIR)) (if empty)")
184 $(RMDIR) `dirname $(LIB_INST_DIR)` || true
185 # .../share/lcov installed by us - so safe to remove
186 $(call echocmd," UNINST $(SHARE_INST_DIR)")
187 $(RM) -r $(SHARE_INST_DIR)
188 $(call echocmd," UNINST $(MAN_INST_DIR) pages")
189 for section in $(MAN_SECTIONS) ; do \
190 DEST=$(MAN_INST_DIR)/man$$section ; \
191 for m in man/*.$$section ; do \
192 F=`basename $$m` ; \
193 $(RM) $$DEST/$$F ; \
194 done ; \
195 $(RMDIR) $$DEST || true; \
196 done
197 $(call echocmd," UNINST $(MAN_INST_DIR) (if empty)")
198 $(RMDIR) $(MAN_INST_DIR) || true;
199 $(call echocmd," UNINST $(shell dirname $(SHARE_INST_DIR)) (if empty)")
200 $(RMDIR) `dirname $(SHARE_INST_DIR)`
201 $(call echocmd," UNINST $(CFG_INST_DIR)/lcovrc")
202 $(RM) $(CFG_INST_DIR)/lcovrc
203 $(RMDIR) $(CFG_INST_DIR) || true
204 $(call echocmd," UNINST $(DESTDIR)/$(PREFIX)")
205 $(RMDIR) $(DESTDIR)$(PREFIX) || true
206
207 dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \
208 lcov-$(VERSION)-$(RELEASE).src.rpm
209
210 lcov-$(VERSION).tar.gz: $(FILES)
211 $(call echocmd," DIST lcov-$(VERSION).tar.gz")
212 $(RM) -r $(TMP_DIR)/lcov-$(VERSION)
213 mkdir -p $(TMP_DIR)/lcov-$(VERSION)
214 cp -r $(DIST_CONTENT) $(TMP_DIR)/lcov-$(VERSION)
215 ./bin/copy_dates.sh . $(TMP_DIR)/lcov-$(VERSION)
216 $(MAKE) -s -C $(TMP_DIR)/lcov-$(VERSION) clean >/dev/null
217 cd $(TMP_DIR)/lcov-$(VERSION) ; \
218 $(FIX) --version $(VERSION) --release $(RELEASE) \
219 --verfile .version --fixver --fixdate \
220 $(patsubst %,bin/%,$(EXES)) $(patsubst %,scripts/%,$(SCRIPTS)) \
221 $(patsubst %,lib/%,$(LIBS)) \
222 $(patsubst %,man/%,$(notdir $(MANPAGES))) README rpm/lcov.spec
223 ./bin/get_changes.sh > $(TMP_DIR)/lcov-$(VERSION)/CHANGES || true
224 cd $(TMP_DIR) ; \
225 tar cfz $(TMP_DIR)/lcov-$(VERSION).tar.gz lcov-$(VERSION) \
226 --owner root --group root
227 mv $(TMP_DIR)/lcov-$(VERSION).tar.gz .
228 $(RM) -r $(TMP_DIR)
229
230 lcov-$(VERSION)-$(RELEASE).noarch.rpm: rpms
231 lcov-$(VERSION)-$(RELEASE).src.rpm: rpms
232
233 rpms: lcov-$(VERSION).tar.gz
234 $(call echocmd," DIST lcov-$(VERSION)-$(RELEASE).noarch.rpm")
235 mkdir -p $(TMP_DIR)
236 mkdir $(TMP_DIR)/BUILD
237 mkdir $(TMP_DIR)/RPMS
238 mkdir $(TMP_DIR)/SOURCES
239 mkdir $(TMP_DIR)/SRPMS
240 cp lcov-$(VERSION).tar.gz $(TMP_DIR)/SOURCES
241 ( \
242 cd $(TMP_DIR)/BUILD ; \
243 tar xfz ../SOURCES/lcov-$(VERSION).tar.gz \
244 lcov-$(VERSION)/rpm/lcov.spec \
245 )
246 rpmbuild --define '_topdir $(TMP_DIR)' --define '_buildhost localhost' \
247 --define "_target_os linux" \
248 --undefine vendor --undefine packager \
249 -ba $(TMP_DIR)/BUILD/lcov-$(VERSION)/rpm/lcov.spec --quiet
250 mv $(TMP_DIR)/RPMS/noarch/lcov-$(VERSION)-$(RELEASE).noarch.rpm .
251 $(call echocmd," DIST lcov-$(VERSION)-$(RELEASE).src.rpm")
252 mv $(TMP_DIR)/SRPMS/lcov-$(VERSION)-$(RELEASE).src.rpm .
253 $(RM) -r $(TMP_DIR)
254
255 ifeq ($(COVERAGE), 1)
256 # write to .../tests/cover_db
257 export COVER_DB := $(shell echo `pwd`/tests/cover_db)
258 export PYCOV_DB := $(shell echo `pwd`/tests/pycov.dat)
259 export HTML_RPT := $(shell echo `pwd`/lcov_coverage)
260 #export LCOV_FORCE_PARALLEL = 1
261 endif
262 export TESTCASE_ARGS
263
264 test: check
265
266 # for COVERAGE mode check: run once with LCOV_FORCE_PARALLEL=1 and
267 # once without - so we can merge the result
268 check:
269 if [ "x$(COVERAGE)" != 'x' ] ; then \
270 if [ ! -d $(COVER_DB) ]; then \
271 mkdir $(COVER_DB) ; \
272 fi ; \
273 echo "*** Run once, force parallel ***" ; \
274 LCOV_FORCE_PARALLEL=1 $(MAKE) -s -C tests check LCOV_HOME=`pwd` ; \
275 echo "*** Run again, no force ***" ; \
276 fi
277 @$(MAKE) -s -C tests check LCOV_HOME=`pwd`
278 @if [ "x$(COVERAGE)" != 'x' ] ; then \
279 $(MAKE) -s -C example LCOV_HOME=`pwd`; \
280 $(MAKE) -s -C tests report ; \
281 fi
282
283 # Files to be checked for coding style issue issues -
284 # - anything containing "#!/usr/bin/env perl" or the like
285 # - anything named *.pm - expected to be perl module
286 # ... as long as the name doesn't end in .tdy or .orig
287 checkstyle:
288 ifeq ($(MODE),full)
289 @echo "Checking source files for coding style issues (MODE=full):"
290 else
291 @echo "Checking changes in source files for coding style issues (MODE=diff):"
292 endif
293 @RC=0 ; \
294 CHECKFILES=`find . -path ./.git -prune -o \( \( -type f -exec grep -q '^#!.*perl' {} \; \) -o -name '*.pm' \) -not \( -name '*.tdy' -o -name '*.orig' -o -name '*~' \) -print `; \
295 for FILE in $$CHECKFILES ; do \
296 $(CHECKSTYLE) "$$FILE"; \
297 if [ 0 != $$? ] ; then \
298 RC=1; \
299 echo "saw mismatch for $$FILE"; \
300 if [ -f $$FILE.tdy -a "$(UPDATE)x" != 'x' ]; then \
301 echo "updating $$FILE"; \
302 mv $$FILE $$FILE.orig; \
303 mv $$FILE.tdy $$FILE ; \
304 fi \
305 fi \
306 done ; \
307 exit $$RC
308
309 release:
310 @if [ "$(origin VERSION)" != "command line" ] ; then echo "Please specify new version number, e.g. VERSION=1.16" >&2 ; exit 1 ; fi
311 @if [ -n "$$(git status --porcelain 2>&1)" ] ; then echo "The repository contains uncommitted changes" >&2 ; exit 1 ; fi
312 @if [ -n "$$(git tag -l v$(VERSION))" ] ; then echo "A tag for the specified version already exists (v$(VERSION))" >&2 ; exit 1 ; fi
313 @echo "Preparing release tag for version $(VERSION)"
314 git checkout master
315 bin/copy_dates.sh . .
316 $(FIX) --version $(VERSION) --release $(RELEASE) \
317 --fixver --fixdate $(patsubst %,man/%,$(notdir $(MANPAGES))) \
318 README rpm/lcov.spec
319 git commit -a -s -m "lcov: Finalize release $(VERSION)"
320 git tag v$(VERSION) -m "LCOV version $(VERSION)"
321 @echo "**********************************************"
322 @echo "Release tag v$(VERSION) successfully created"
323 @echo "Next steps:"
324 @echo " - Review resulting commit and tag"
325 @echo " - Publish with: git push origin master v$(VERSION)"
326 @echo "**********************************************"
327