Makefile revision 1.80
1#	$NetBSD: Makefile,v 1.80 2020/08/06 05:27:31 rillig Exp $
2#	@(#)Makefile	5.2 (Berkeley) 12/28/90
3
4PROG=	make
5SRCS=	arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c lst.c main.c
6SRCS+=	make.c make_malloc.c metachar.c parse.c
7SRCS+=	str.c strlist.c suff.c targ.c trace.c var.c util.c
8
9# Whether to generate a coverage report after running the tests.
10USE_COVERAGE?=	no		# works only with gcc; clang9 fails to link
11.if ${USE_COVERAGE} == "yes"
12COPTS+=		--coverage -O0 -ggdb
13LDADD+=		--coverage
14CLEANFILES+=	${SRCS:.c=.gcda} ${SRCS:.c=.gcno} ${SRCS:=.gcov}
15.endif
16
17# Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
18USE_UBSAN?=	no
19.if ${USE_UBSAN} == "yes"
20COPTS+=		-fsanitize=undefined
21LDADD+=		-fsanitize=undefined
22.endif
23
24USE_META?=	yes
25.if ${USE_META:tl} != "no"
26
27SRCS+=		meta.c
28CPPFLAGS+=	-DUSE_META
29
30USE_FILEMON?=	ktrace
31.  if ${USE_FILEMON:tl} != "no"
32
33.PATH:	${.CURDIR}/filemon
34SRCS+=		filemon_${USE_FILEMON}.c
35CPPFLAGS+=	-DUSE_FILEMON
36CPPFLAGS+=	-DUSE_FILEMON_${USE_FILEMON:tu}
37
38.    if ${USE_FILEMON} == "dev"
39FILEMON_H?=	/usr/include/dev/filemon/filemon.h
40.      if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
41COPTS.filemon_dev.c+= \
42		-DHAVE_FILEMON_H -I${FILEMON_H:H}
43.      endif
44.    endif
45.  endif
46.endif
47
48SUBDIR.roff+=	PSD.doc
49.if make(obj) || make(clean)
50SUBDIR+=	unit-tests
51.endif
52
53${SRCS:M*.c:.c=.o}: buf.h config.h dir.h hash.h job.h lst.h make.h make_malloc.h
54${SRCS:M*.c:.c=.o}: meta.h metachar.h nonints.h pathnames.h sprite.h strlist.h trace.h
55
56TARGETS+=	retest
57
58.include <bsd.prog.mk>
59.include <bsd.subdir.mk>
60
61CPPFLAGS+=	-DMAKE_NATIVE
62COPTS.var.c+=	-Wno-cast-qual
63COPTS.job.c+=	-Wno-format-nonliteral
64COPTS.parse.c+=	-Wno-format-nonliteral
65COPTS.var.c+=	-Wno-format-nonliteral
66
67.if defined(TOOLDIR)
68# This is a native NetBSD build, use libutil rather than the local emalloc etc.
69CPPFLAGS+=	-DUSE_EMALLOC
70LDADD+=		-lutil
71DPADD+=		${LIBUTIL}
72.endif
73
74COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
75COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}
76COPTS.main.c+=	${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
77COPTS.meta.c+=	${GCC_NO_FORMAT_TRUNCATION}
78COPTS.parse.c+=	${GCC_NO_FORMAT_TRUNCATION}
79
80COPTS+=		-Wdeclaration-after-statement
81
82# A simple unit-test driver to help catch regressions
83test: .MAKE
84	cd ${.CURDIR}/unit-tests \
85	&& MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
86.if ${USE_COVERAGE} == yes
87	gcov ${SRCS}
88	sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
89.endif
90
91accept: .MAKE
92	cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
93
94retest:
95	${.MAKE} -C ${.CURDIR}/unit-tests cleandir
96.if ${USE_COVERAGE} == yes
97	rm -f *.gcov *.gcda
98.endif
99	${.MAKE} test
100