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