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