Makefile revision 1.106 1 # $NetBSD: Makefile,v 1.106 2020/10/25 13:25:19 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 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 ${SRCS:M*.c:.c=.o}: ${HDRS}
120 CLEANFILES+= *.o
121
122 .include <bsd.prog.mk>
123 .include <bsd.subdir.mk>
124
125 CPPFLAGS+= -DMAKE_NATIVE
126 COPTS.job.c+= -Wno-format-nonliteral
127 COPTS.parse.c+= -Wno-format-nonliteral
128 COPTS.var.c+= -Wno-format-nonliteral
129
130 .if ${USE_GCC10} == "yes"
131 GCC10BASE?= /usr/pkg/gcc10
132 CC= ${GCC10BASE}/bin/gcc
133 GCOV= ${GCC10BASE}/bin/gcov
134 .endif
135
136 .if ${USE_GCC9} == "yes"
137 GCC9BASE?= /usr/pkg/gcc9
138 CC= ${GCC9BASE}/bin/gcc
139 GCOV= ${GCC9BASE}/bin/gcov
140 .endif
141
142 .if ${USE_GCC8} == "yes"
143 GCC8BASE?= /usr/pkg/gcc8
144 CC= ${GCC8BASE}/bin/gcc
145 GCOV= ${GCC8BASE}/bin/gcov
146 .endif
147
148 .if defined(TOOLDIR)
149 # This is a native NetBSD build, use libutil rather than the local emalloc etc.
150 CPPFLAGS+= -DUSE_EMALLOC
151 LDADD+= -lutil
152 DPADD+= ${LIBUTIL}
153 .endif
154
155 COPTS.arch.c+= ${GCC_NO_FORMAT_TRUNCATION}
156 COPTS.dir.c+= ${GCC_NO_FORMAT_TRUNCATION}
157 COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
158 COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
159
160 COPTS+= -Wdeclaration-after-statement
161
162 # For -DCLEANUP and similar feature toggles.
163 CPPFLAGS+= ${USER_CPPFLAGS}
164 # For overriding -std=gnu99 or similar options.
165 CFLAGS+= ${USER_CFLAGS}
166
167 # A simple unit-test driver to help catch regressions
168 TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
169 test: .MAKE
170 cd ${.CURDIR}/unit-tests \
171 && MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET}
172 .if ${USE_COVERAGE} == yes
173 ${GCOV} ${GCOV_OPTS} ${SRCS}
174 sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
175 .endif
176
177 accept sync-mi: .MAKE
178 cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
179
180 retest:
181 ${.MAKE} -C ${.CURDIR}/unit-tests cleandir
182 .if ${USE_COVERAGE} == yes
183 rm -f *.gcov *.gcda
184 .endif
185 ${.MAKE} test
186
187 # Just out of curiosity, during development.
188 .SUFFIXES: .cpre .casm
189 .c.cpre:
190 ${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
191 .c.casm:
192 ${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
193