-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathcommon.mak
144 lines (114 loc) · 4.24 KB
/
common.mak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# TOPDIR == root of test directory - either build dir or copied from share/lcov
TOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
# TESTDIR == path to this particular testcase
TESTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
ifeq ($(LCOV_HOME),)
ROOT_DIR = $(realpath $(TOPDIR)/..)
else
ROOT_DIR := $(LCOV_HOME)
endif
BINDIR = $(ROOT_DIR)/bin
ifneq (,$(wildcard $(ROOT_DIR)/scripts))
SCRIPTDIR := $(ROOT_DIR)/scripts
else
SCRIPTDIR := $(ROOT_DIR)/share/lcov/support-scripts
endif
ifeq ($(DEBUG),1)
$(warning TOPDIR = $(TOPDIR))
$(warning TESTDIR = $(TESTDIR))
$(warning BINDIR = $(BINDIR))
$(warning SCRIPTDIR = $(SCRIPTDIR))
endif
TESTBINDIR := $(TOPDIR)bin
IS_GIT := $(shell git -C $(TOPDIR) rev-parse 2>&1 > /dev/null ; if [ 0 -eq $$? ]; then echo 1 ; else echo 0 ; fi)
IS_P4 = $(shell p4 have ... 2>&1 > /dev/null ; if [ 0 -eq $$? ]; then echo 1 ; else echo 0 ; fi)
ifeq (1,$(IS_GIT))
ANNOTATE_SCRIPT=$(SCRIPTDIR)/gitblame.pm
VERSION_SCRIPT=$(SCRIPTDIR)/gitversion.pm
else
ANNOTATE_SCRIPT=$(SCRIPTDIR)/p4annotate.pm
VERSION_SCRIPT=$(SCRIPTDIR)/P4version.pm,--local-edit,$(ROOT_DIR)
endif
ifneq ($(COVER_DB),)
export PERL_COVER_ARGS := -MDevel::Cover=-db,$(COVER_DB),-coverage,statement,branch,condition,subroutine,-silent,1
EXEC_COVER := perl ${PERL_COVER_ARGS}
export COVERAGE_COMMAND = $(shell which coverage 2>&1 > /dev/null ; if [ 0 -eq $$? ] ; then echo coverage ; else echo python3-coverage ; fi )
PYCOVER = COVERAGE_FILE=$(PYCOV_DB) ${COVERAGE_COMMAND} run --branch --append
#$(warning assigned PYCOVER='$(PYCOVER)')
endif
export TOPDIR TESTDIR
export PARENTDIR := $(dir $(patsubst %/,%,$(TOPDIR)))
export RELDIR := $(TESTDIR:$(PARENTDIR)%=%)
# Path to artificial info files
export ZEROINFO := $(TOPDIR)zero.info
export ZEROCOUNTS := $(TOPDIR)zero.counts
export FULLINFO := $(TOPDIR)full.info
export FULLCOUNTS := $(TOPDIR)full.counts
export TARGETINFO := $(TOPDIR)target.info
export TARGETCOUNTS := $(TOPDIR)target.counts
export PART1INFO := $(TOPDIR)part1.info
export PART1COUNTS := $(TOPDIR)part1.counts
export PART2INFO := $(TOPDIR)part2.info
export PART2COUNTS := $(TOPDIR)part2.counts
export INFOFILES := $(ZEROINFO) $(FULLINFO) $(TARGETINFO) $(PART1INFO) \
$(PART2INFO)
export COUNTFILES := $(ZEROCOUNTS) $(FULLCOUNTS) $(TARGETCOUNTS) \
$(PART1COUNTS) $(PART2COUNTS)
# Use pre-defined lcovrc file
LCOVRC := $(TOPDIR)lcovrc
# Specify size for artificial info files (small, medium, large)
SIZE := small
export CC ?= gcc
export CXX ?= g++
export LCOV_TOOL := $(EXEC_COVER) $(BINDIR)/lcov
export GENHTML_TOOL := $(EXEC_COVER) $(BINDIR)/genhtml
export GENINFO_TOOL := $(EXEC_COVER) $(BINDIR)/geninfo
export PERL2LCOV_TOOL := $(EXEC_COVER) $(BINDIR)/perl2lcov
export LLVM2LCOV_TOOL := $(EXEC_COVER) $(BINDIR)/llvm2lcov
export PY2LCOV_TOOL := $(PYCOVER) $(BINDIR)/py2lcov
export XML2LCOV_TOOL := $(PYCOVER) $(BINDIR)/xml2lcov
export SPREADSHEET_TOOL := $(PYCOVER) $(SCRIPTDIR)/spreadsheet.py
# Specify programs under test
export PATH := $(BINDIR):$(TESTBINDIR):$(PATH)
export LCOV := $(LCOV_TOOL) --config-file $(LCOVRC) $(LCOVFLAGS)
export GENHTML := $(GENHTML_TOOL) --config-file $(LCOVRC) $(GENHTMLFLAGS)
# Ensure stable output
export LANG := C
# Suppress output in non-verbose mode
export V
ifeq ("${V}","1")
echocmd=
else
echocmd=echo $1 ;
.SILENT:
endif
ifneq ($(COVER_DB),)
#OPTS += --coverage $(COVER_DB)
endif
ifneq ($(TESTCASE_ARGS),)
OPTS += --script-args "$(TESTCASE_ARGS)"
endif
# Do not pass TESTS= specified on command line to subdirectories to allow
# make TESTS=subdir
MAKEOVERRIDES := $(filter-out TESTS=%,$(MAKEOVERRIDES))
# Default target
check:
#echo "found tests '$(TESTS)'"
runtests "$(MAKE)" $(TESTS) $(OPTS)
ifeq ($(_ONCE),)
# Do these only once during initialization
export _ONCE := 1
check: checkdeps prepare
checkdeps:
checkdeps $(BINDIR)/* $(TESTBINDIR)/*
prepare: $(INFOFILES) $(COUNTFILES)
# Create artificial info files as test data
$(INFOFILES) $(COUNTFILES):
cd $(TOPDIR) && $(TOPDIR)/bin/mkinfo profiles/$(SIZE) -o src/
endif
clean: clean_echo clean_subdirs
clean_echo:
$(call echocmd," CLEAN lcov/$(patsubst %/,%,$(RELDIR))")
clean_subdirs:
cleantests "$(MAKE)" $(TESTS)
.PHONY: check prepare clean clean_common