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