Makefile revision 1.118 1 # $NetBSD: Makefile,v 1.118 2021/12/12 10:33:03 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+= for.c
11 SRCS+= hash.c
12 SRCS+= job.c
13 SRCS+= lst.c
14 SRCS+= main.c
15 SRCS+= make.c
16 SRCS+= make_malloc.c
17 SRCS+= metachar.c
18 SRCS+= parse.c
19 SRCS+= str.c
20 SRCS+= suff.c
21 SRCS+= targ.c
22 SRCS+= trace.c
23 SRCS+= var.c
24 SRCS+= util.c
25
26 # Whether to generate a coverage report after running the tests.
27 USE_COVERAGE?= no # works only with gcc; clang9 fails to link
28 .if ${USE_COVERAGE} == "yes"
29 GCOV?= gcov
30 COPTS+= --coverage -O0 -ggdb
31 GCOV_PERL= if (/^File '(?:.*\/)?(\S+)'/) {
32 GCOV_PERL+= $$file = $$1; $$func = "";
33 GCOV_PERL+= } elsif (/^Function '(\S+)'/) {
34 GCOV_PERL+= $$func = $$1;
35 GCOV_PERL+= } elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/ && defined($$file)) {
36 GCOV_PERL+= my ($$percent, $$lines) = ($$1, $$2);
37 GCOV_PERL+= my $$uncovered = $$file =~ /\.h$$/
38 GCOV_PERL+= ? '?'
39 GCOV_PERL+= : `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`;
40 GCOV_PERL+= chomp($$uncovered);
41 GCOV_PERL+= printf("%7.2f %4s/%4d %s%s\n",
42 GCOV_PERL+= $$percent, $$uncovered, $$lines, $$file, $$func);
43 GCOV_PERL+= $$file = undef;
44 GCOV_PERL+= }
45 LDADD+= --coverage
46 .endif
47 CLEANFILES+= *.gcda *.gcno *.gcov
48
49 # Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
50 USE_UBSAN?= no
51 .if ${USE_UBSAN} == "yes"
52 COPTS+= -fsanitize=undefined
53 LDADD+= -fsanitize=undefined
54 .endif
55
56 # Whether to compile with GCC 10 from pkgsrc, during development.
57 USE_GCC10?= no
58 .if ${USE_GCC10} == "yes"
59 # CC is set further down in this file
60 COPTS+= -Wno-attributes # for abs and labs
61 COPTS.arch.c+= -Wno-error=format-truncation
62 COPTS.dir.c+= -Wno-error=format-truncation
63 COPTS.main.c+= -Wno-error=format-truncation
64 COPTS.meta.c+= -Wno-error=format-truncation
65 .endif
66
67 # Whether to compile with GCC 9 from pkgsrc, during development.
68 USE_GCC9?= no
69 .if ${USE_GCC9} == "yes"
70 # CC is set further down in this file
71 COPTS+= -Wno-attributes # for abs and labs
72 COPTS.arch.c+= -Wno-error=format-truncation
73 COPTS.dir.c+= -Wno-error=format-truncation
74 COPTS.main.c+= -Wno-error=format-truncation
75 COPTS.meta.c+= -Wno-error=format-truncation
76 .endif
77
78 # Whether to compile with GCC 8 from pkgsrc, during development.
79 USE_GCC8?= no
80 .if ${USE_GCC8} == "yes"
81 # CC is set further down in this file
82 COPTS+= -Wno-attributes # for abs and labs
83 COPTS.arch.c+= -Wno-error=format-truncation
84 COPTS.dir.c+= -Wno-error=format-truncation
85 COPTS.main.c+= -Wno-error=format-truncation
86 COPTS.meta.c+= -Wno-error=format-truncation
87 .endif
88
89 USE_META?= yes
90 .if ${USE_META:tl} != "no"
91
92 SRCS+= meta.c
93 CPPFLAGS+= -DUSE_META
94
95 USE_FILEMON?= ktrace
96 . if ${USE_FILEMON:tl} != "no"
97
98 .PATH: ${.CURDIR}/filemon
99 SRCS+= filemon_${USE_FILEMON}.c
100 CPPFLAGS+= -DUSE_FILEMON
101 CPPFLAGS+= -DUSE_FILEMON_${USE_FILEMON:tu}
102
103 . if ${USE_FILEMON} == "dev"
104 FILEMON_H?= /usr/include/dev/filemon/filemon.h
105 . if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
106 COPTS.filemon_dev.c+= \
107 -DHAVE_FILEMON_H -I${FILEMON_H:H}
108 . endif
109 . endif
110 . endif
111 .endif
112
113 SUBDIR.roff+= PSD.doc
114 .if make(obj) || make(clean)
115 SUBDIR+= unit-tests
116 .endif
117
118 LINTFLAGS+= -T # strict bool mode, available since 2021-01-11
119 LINTFLAGS+= -w # treat warnings as errors
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 .if ${USE_COVERAGE} == "yes"
191 report-coverage: .PHONY
192 @echo 'covered uncovered file'
193 @${GCOV} ${GCOV_OPTS} *.gcda \
194 | perl -ne ${GCOV_PERL:Q} \
195 | sort -nr
196 @sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
197 .endif
198
199 .include <bsd.prog.mk>
200 .include <bsd.subdir.mk>
201
202 # For -DCLEANUP and similar feature toggles.
203 CPPFLAGS+= ${USER_CPPFLAGS}
204 # For overriding -std=gnu99 or similar options.
205 CFLAGS+= ${USER_CFLAGS}
206 .if defined(LATE_CC)
207 CC= ${LATE_CC}
208 .endif
209