Makefile revision 1.115 1 # $NetBSD: Makefile,v 1.115 2021/05/30 21:03:08 rillig Exp $
2 # @(#)Makefile 5.2 (Berkeley) 12/28/90
3
4 PROG= make
5 SRCS= arch.c
6 SRCS+= buf.c
7 SRCS+= compat.c
8 SRCS+= cond.c
9 SRCS+= dir.c
10 SRCS+= enum.c
11 SRCS+= for.c
12 SRCS+= hash.c
13 SRCS+= job.c
14 SRCS+= lst.c
15 SRCS+= main.c
16 SRCS+= make.c
17 SRCS+= make_malloc.c
18 SRCS+= metachar.c
19 SRCS+= parse.c
20 SRCS+= str.c
21 SRCS+= suff.c
22 SRCS+= targ.c
23 SRCS+= trace.c
24 SRCS+= var.c
25 SRCS+= util.c
26
27 # Whether to generate a coverage report after running the tests.
28 USE_COVERAGE?= no # works only with gcc; clang9 fails to link
29 .if ${USE_COVERAGE} == "yes"
30 GCOV?= gcov
31 COPTS+= --coverage -O0 -ggdb
32 GCOV_PERL= if (/^File '(?:.*\/)?(\S+)'/) {
33 GCOV_PERL+= $$file = $$1; $$func = "";
34 GCOV_PERL+= } elsif (/^Function '(\S+)'/) {
35 GCOV_PERL+= $$func = $$1;
36 GCOV_PERL+= } elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/ && defined($$file)) {
37 GCOV_PERL+= my ($$percent, $$lines) = ($$1, $$2);
38 GCOV_PERL+= my $$uncovered = $$file =~ /\.h$$/
39 GCOV_PERL+= ? '?'
40 GCOV_PERL+= : `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`;
41 GCOV_PERL+= chomp($$uncovered);
42 GCOV_PERL+= printf("%7.2f %4s/%4d %s%s\n",
43 GCOV_PERL+= $$percent, $$uncovered, $$lines, $$file, $$func);
44 GCOV_PERL+= $$file = undef;
45 GCOV_PERL+= }
46 LDADD+= --coverage
47 .endif
48 CLEANFILES+= *.gcda *.gcno *.gcov
49
50 # Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
51 USE_UBSAN?= no
52 .if ${USE_UBSAN} == "yes"
53 COPTS+= -fsanitize=undefined
54 LDADD+= -fsanitize=undefined
55 .endif
56
57 # Whether to compile with GCC 10 from pkgsrc, during development.
58 USE_GCC10?= no
59 .if ${USE_GCC10} == "yes"
60 # CC is set further down in this file
61 COPTS+= -Wno-attributes # for abs and labs
62 COPTS.arch.c+= -Wno-error=format-truncation
63 COPTS.dir.c+= -Wno-error=format-truncation
64 COPTS.main.c+= -Wno-error=format-truncation
65 COPTS.meta.c+= -Wno-error=format-truncation
66 .endif
67
68 # Whether to compile with GCC 9 from pkgsrc, during development.
69 USE_GCC9?= no
70 .if ${USE_GCC9} == "yes"
71 # CC is set further down in this file
72 COPTS+= -Wno-attributes # for abs and labs
73 COPTS.arch.c+= -Wno-error=format-truncation
74 COPTS.dir.c+= -Wno-error=format-truncation
75 COPTS.main.c+= -Wno-error=format-truncation
76 COPTS.meta.c+= -Wno-error=format-truncation
77 .endif
78
79 # Whether to compile with GCC 8 from pkgsrc, during development.
80 USE_GCC8?= no
81 .if ${USE_GCC8} == "yes"
82 # CC is set further down in this file
83 COPTS+= -Wno-attributes # for abs and labs
84 COPTS.arch.c+= -Wno-error=format-truncation
85 COPTS.dir.c+= -Wno-error=format-truncation
86 COPTS.main.c+= -Wno-error=format-truncation
87 COPTS.meta.c+= -Wno-error=format-truncation
88 .endif
89
90 USE_META?= yes
91 .if ${USE_META:tl} != "no"
92
93 SRCS+= meta.c
94 CPPFLAGS+= -DUSE_META
95
96 USE_FILEMON?= ktrace
97 . if ${USE_FILEMON:tl} != "no"
98
99 .PATH: ${.CURDIR}/filemon
100 SRCS+= filemon_${USE_FILEMON}.c
101 CPPFLAGS+= -DUSE_FILEMON
102 CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu}
103
104 . if ${USE_FILEMON} == "dev"
105 FILEMON_H?= /usr/include/dev/filemon/filemon.h
106 . if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
107 COPTS.filemon_dev.c+= \
108 -DHAVE_FILEMON_H -I${FILEMON_H:H}
109 . endif
110 . endif
111 . endif
112 .endif
113
114 SUBDIR.roff+= PSD.doc
115 .if make(obj) || make(clean)
116 SUBDIR+= unit-tests
117 .endif
118
119 LINTFLAGS+= -T # strict bool mode, available since 2021-01-11
120 CLEANFILES+= *.o # for filemon objects
121
122 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION}
123 COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION}
124 COPTS.job.c+= -Wno-format-nonliteral
125 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
126 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
127 COPTS.parse.c+= -Wno-format-nonliteral
128 COPTS.var.c+= -Wno-format-nonliteral
129
130 CPPFLAGS+= -DMAKE_NATIVE
131
132 .if ${USE_GCC10} == "yes"
133 GCC10BASE?= /usr/pkg/gcc10
134 LATE_CC= ${GCC10BASE}/bin/gcc
135 GCOV= ${GCC10BASE}/bin/gcov
136 .endif
137
138 .if ${USE_GCC9} == "yes"
139 GCC9BASE?= /usr/pkg/gcc9
140 LATE_CC= ${GCC9BASE}/bin/gcc
141 GCOV= ${GCC9BASE}/bin/gcov
142 .endif
143
144 .if ${USE_GCC8} == "yes"
145 GCC8BASE?= /usr/pkg/gcc8
146 LATE_CC= ${GCC8BASE}/bin/gcc
147 GCOV= ${GCC8BASE}/bin/gcov
148 .endif
149
150 .if defined(TOOLDIR)
151 # This is a native NetBSD build, use libutil rather than the local emalloc etc.
152 CPPFLAGS+= -DUSE_EMALLOC
153 LDADD+= -lutil
154 DPADD+= ${LIBUTIL}
155 .endif
156
157 COPTS+= -Wdeclaration-after-statement
158
159 # A simple unit-test driver to help catch regressions
160 TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
161 test: .MAKE
162 cd ${.CURDIR}/unit-tests \
163 && MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET}
164 .if ${USE_COVERAGE} == yes
165 ${MAKE} report-coverage
166 .endif
167
168 accept sync-mi: .MAKE
169 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
170
171 retest:
172 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir
173 .if ${USE_COVERAGE} == yes
174 rm -f *.gcov *.gcda
175 .endif
176 ${.MAKE} test
177
178 # Just out of curiosity, during development.
179 .SUFFIXES: .cpre .casm
180 .c.cpre:
181 ${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
182 .c.casm:
183 ${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
184
185 test-coverage: .PHONY
186 @make -s clean cleandir
187 @env USE_COVERAGE=yes COPTS="-O0 -ggdb" USER_CPPFLAGS="-DCLEANUP" \
188 sh -c 'make -s all -j8 && make -s test'
189
190 report-coverage: .PHONY
191 @echo 'covered uncovered file'
192 @${GCOV} ${GCOV_OPTS} *.gcda 2>&1 \
193 | perl -ne ${GCOV_PERL:Q} \
194 | sort -nr
195 @sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
196
197 .include <bsd.prog.mk>
198 .include <bsd.subdir.mk>
199
200 # For -DCLEANUP and similar feature toggles.
201 CPPFLAGS+= ${USER_CPPFLAGS}
202 # For overriding -std=gnu99 or similar options.
203 CFLAGS+= ${USER_CFLAGS}
204 .if defined(LATE_CC)
205 CC= ${LATE_CC}
206 .endif
207