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