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