Makefile revision 1.83
1#	$NetBSD: Makefile,v 1.83 2020/08/08 13:50:23 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"
47COPTS+=		--coverage -O0 -ggdb
48LDADD+=		--coverage
49CLEANFILES+=	${SRCS:.c=.gcda} ${SRCS:.c=.gcno} ${SRCS:=.gcov}
50.endif
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
59USE_META?=	yes
60.if ${USE_META:tl} != "no"
61
62SRCS+=		meta.c
63CPPFLAGS+=	-DUSE_META
64
65USE_FILEMON?=	ktrace
66.  if ${USE_FILEMON:tl} != "no"
67
68.PATH:	${.CURDIR}/filemon
69SRCS+=		filemon_${USE_FILEMON}.c
70CPPFLAGS+=	-DUSE_FILEMON
71CPPFLAGS+=	-DUSE_FILEMON_${USE_FILEMON:tu}
72
73.    if ${USE_FILEMON} == "dev"
74FILEMON_H?=	/usr/include/dev/filemon/filemon.h
75.      if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
76COPTS.filemon_dev.c+= \
77		-DHAVE_FILEMON_H -I${FILEMON_H:H}
78.      endif
79.    endif
80.  endif
81.endif
82
83SUBDIR.roff+=	PSD.doc
84.if make(obj) || make(clean)
85SUBDIR+=	unit-tests
86.endif
87
88${SRCS:M*.c:.c=.o}: ${HDRS}
89
90.include <bsd.prog.mk>
91.include <bsd.subdir.mk>
92
93CPPFLAGS+=	-DMAKE_NATIVE
94COPTS.var.c+=	-Wno-cast-qual
95COPTS.job.c+=	-Wno-format-nonliteral
96COPTS.parse.c+=	-Wno-format-nonliteral
97COPTS.var.c+=	-Wno-format-nonliteral
98
99.if defined(TOOLDIR)
100# This is a native NetBSD build, use libutil rather than the local emalloc etc.
101CPPFLAGS+=	-DUSE_EMALLOC
102LDADD+=		-lutil
103DPADD+=		${LIBUTIL}
104.endif
105
106COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
107COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}
108COPTS.main.c+=	${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
109COPTS.meta.c+=	${GCC_NO_FORMAT_TRUNCATION}
110COPTS.parse.c+=	${GCC_NO_FORMAT_TRUNCATION}
111
112COPTS+=		-Wdeclaration-after-statement
113
114# A simple unit-test driver to help catch regressions
115test: .MAKE
116	cd ${.CURDIR}/unit-tests \
117	&& MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
118.if ${USE_COVERAGE} == yes
119	gcov ${SRCS}
120	sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
121.endif
122
123accept: .MAKE
124	cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
125
126retest:
127	${.MAKE} -C ${.CURDIR}/unit-tests cleandir
128.if ${USE_COVERAGE} == yes
129	rm -f *.gcov *.gcda
130.endif
131	${.MAKE} test
132