Makefile revision 1.90
1#	$NetBSD: Makefile,v 1.90 2020/08/19 06:30: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+=  sprite.h
41HDRS+=  strlist.h
42HDRS+=  trace.h
43
44# Whether to generate a coverage report after running the tests.
45USE_COVERAGE?=	no		# works only with gcc; clang9 fails to link
46.if ${USE_COVERAGE} == "yes"
47GCOV?=		gcov
48COPTS+=		--coverage -O0 -ggdb
49LDADD+=		--coverage
50.endif
51CLEANFILES+=	*.gcda *.gcno *.gcov
52
53# Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
54USE_UBSAN?=	no
55.if ${USE_UBSAN} == "yes"
56COPTS+=		-fsanitize=undefined
57LDADD+=		-fsanitize=undefined
58.endif
59
60# Whether to compile with GCC 10 from pkgsrc, during development.
61USE_GCC10?=	no
62.if ${USE_GCC10} == "yes"
63# CC is set further down in this file
64COPTS+=		-Wno-attributes	# for abs and labs
65COPTS.arch.c+=	-Wno-error=format-truncation
66COPTS.dir.c+=	-Wno-error=format-truncation
67COPTS.main.c+=	-Wno-error=format-truncation
68COPTS.meta.c+=	-Wno-error=format-truncation
69COPTS.parse.c+=	-Wno-error=format-truncation
70.endif
71
72# Whether to compile with GCC 9 from pkgsrc, during development.
73USE_GCC9?=	no
74.if ${USE_GCC9} == "yes"
75# CC is set further down in this file
76COPTS+=		-Wno-attributes	# for abs and labs
77COPTS.arch.c+=	-Wno-error=format-truncation
78COPTS.dir.c+=	-Wno-error=format-truncation
79COPTS.main.c+=	-Wno-error=format-truncation
80COPTS.meta.c+=	-Wno-error=format-truncation
81COPTS.parse.c+=	-Wno-error=format-truncation
82.endif
83
84# Whether to compile with GCC 8 from pkgsrc, during development.
85USE_GCC8?=	no
86.if ${USE_GCC8} == "yes"
87# CC is set further down in this file
88COPTS+=		-Wno-attributes	# for abs and labs
89COPTS.arch.c+=	-Wno-error=format-truncation
90COPTS.dir.c+=	-Wno-error=format-truncation
91COPTS.main.c+=	-Wno-error=format-truncation
92COPTS.meta.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}
125
126.include <bsd.prog.mk>
127.include <bsd.subdir.mk>
128
129CPPFLAGS+=	-DMAKE_NATIVE
130COPTS.job.c+=	-Wno-format-nonliteral
131COPTS.parse.c+=	-Wno-format-nonliteral
132COPTS.var.c+=	-Wno-format-nonliteral
133
134.if ${USE_GCC10} == "yes"
135GCC9BASE?=	/usr/pkg/gcc10
136CC=		${GCC10BASE}/bin/gcc
137GCOV=		${GCC10BASE}/bin/gcov
138.endif
139
140.if ${USE_GCC9} == "yes"
141GCC9BASE?=	/usr/pkg/gcc9
142CC=		${GCC9BASE}/bin/gcc
143GCOV=		${GCC9BASE}/bin/gcov
144.endif
145
146.if ${USE_GCC8} == "yes"
147GCC8BASE?=	/usr/pkg/gcc8
148CC=		${GCC8BASE}/bin/gcc
149GCOV=		${GCC8BASE}/bin/gcov
150.endif
151
152.if defined(TOOLDIR)
153# This is a native NetBSD build, use libutil rather than the local emalloc etc.
154CPPFLAGS+=	-DUSE_EMALLOC
155LDADD+=		-lutil
156DPADD+=		${LIBUTIL}
157.endif
158
159COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
160COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}
161COPTS.main.c+=	${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
162COPTS.meta.c+=	${GCC_NO_FORMAT_TRUNCATION}
163COPTS.parse.c+=	${GCC_NO_FORMAT_TRUNCATION}
164
165COPTS+=		-Wdeclaration-after-statement
166
167# A simple unit-test driver to help catch regressions
168test: .MAKE
169	cd ${.CURDIR}/unit-tests \
170	&& MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
171.if ${USE_COVERAGE} == yes
172	${GCOV} ${GCOV_OPTS} ${SRCS}
173	sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
174.endif
175
176accept sync-mi: .MAKE
177	cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
178
179retest:
180	${.MAKE} -C ${.CURDIR}/unit-tests cleandir
181.if ${USE_COVERAGE} == yes
182	rm -f *.gcov *.gcda
183.endif
184	${.MAKE} test
185