Makefile revision 1.119 1 # $NetBSD: Makefile,v 1.119 2021/12/12 10:53:37 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 =
38 GCOV_PERL+= $$percent eq '100.00' ? '0'
39 GCOV_PERL+= : $$file =~ /\.h$$/ ? '?'
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 LINTFLAGS+= -w # treat warnings as errors
121 CLEANFILES+= *.o # for filemon objects
122
123 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION}
124 COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION}
125 COPTS.job.c+= -Wno-format-nonliteral
126 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
127 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
128 COPTS.parse.c+= -Wno-format-nonliteral
129 COPTS.var.c+= -Wno-format-nonliteral
130
131 CPPFLAGS+= -DMAKE_NATIVE
132
133 .if ${USE_GCC10} == "yes"
134 GCC10BASE?= /usr/pkg/gcc10
135 LATE_CC= ${GCC10BASE}/bin/gcc
136 GCOV= ${GCC10BASE}/bin/gcov
137 .endif
138
139 .if ${USE_GCC9} == "yes"
140 GCC9BASE?= /usr/pkg/gcc9
141 LATE_CC= ${GCC9BASE}/bin/gcc
142 GCOV= ${GCC9BASE}/bin/gcov
143 .endif
144
145 .if ${USE_GCC8} == "yes"
146 GCC8BASE?= /usr/pkg/gcc8
147 LATE_CC= ${GCC8BASE}/bin/gcc
148 GCOV= ${GCC8BASE}/bin/gcov
149 .endif
150
151 .if defined(TOOLDIR)
152 # This is a native NetBSD build, use libutil rather than the local emalloc etc.
153 CPPFLAGS+= -DUSE_EMALLOC
154 LDADD+= -lutil
155 DPADD+= ${LIBUTIL}
156 .endif
157
158 COPTS+= -Wdeclaration-after-statement
159
160 # A simple unit-test driver to help catch regressions
161 TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
162 test: .MAKE
163 cd ${.CURDIR}/unit-tests \
164 && MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET}
165 .if ${USE_COVERAGE} == yes
166 ${MAKE} report-coverage
167 .endif
168
169 accept sync-mi: .MAKE
170 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
171
172 retest:
173 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir
174 .if ${USE_COVERAGE} == yes
175 rm -f *.gcov *.gcda
176 .endif
177 ${.MAKE} test
178
179 # Just out of curiosity, during development.
180 .SUFFIXES: .cpre .casm
181 .c.cpre:
182 ${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
183 .c.casm:
184 ${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
185
186 test-coverage: .PHONY
187 @make -s clean cleandir
188 @env USE_COVERAGE=yes COPTS="-O0 -ggdb" USER_CPPFLAGS="-DCLEANUP" \
189 sh -c 'make -s all -j8 && make -s test'
190
191 .if ${USE_COVERAGE} == "yes"
192 report-coverage: .PHONY
193 @echo 'covered uncovered file'
194 @${GCOV} ${GCOV_OPTS} *.gcda \
195 | perl -ne ${GCOV_PERL:Q} \
196 | sort -nr
197 @sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
198 .endif
199
200 .include <bsd.prog.mk>
201 .include <bsd.subdir.mk>
202
203 # For -DCLEANUP and similar feature toggles.
204 CPPFLAGS+= ${USER_CPPFLAGS}
205 # For overriding -std=gnu99 or similar options.
206 CFLAGS+= ${USER_CFLAGS}
207 .if defined(LATE_CC)
208 CC= ${LATE_CC}
209 .endif
210