Makefile revision 1.84
1#	$NetBSD: Makefile,v 1.84 2020/08/09 05:51:04 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
59# Whether to compile with GCC 9 from pkgsrc, during development.
60USE_GCC9?=	no
61.if ${USE_GCC9} == "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
71USE_META?=	yes
72.if ${USE_META:tl} != "no"
73
74SRCS+=		meta.c
75CPPFLAGS+=	-DUSE_META
76
77USE_FILEMON?=	ktrace
78.  if ${USE_FILEMON:tl} != "no"
79
80.PATH:	${.CURDIR}/filemon
81SRCS+=		filemon_${USE_FILEMON}.c
82CPPFLAGS+=	-DUSE_FILEMON
83CPPFLAGS+=	-DUSE_FILEMON_${USE_FILEMON:tu}
84
85.    if ${USE_FILEMON} == "dev"
86FILEMON_H?=	/usr/include/dev/filemon/filemon.h
87.      if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
88COPTS.filemon_dev.c+= \
89		-DHAVE_FILEMON_H -I${FILEMON_H:H}
90.      endif
91.    endif
92.  endif
93.endif
94
95SUBDIR.roff+=	PSD.doc
96.if make(obj) || make(clean)
97SUBDIR+=	unit-tests
98.endif
99
100${SRCS:M*.c:.c=.o}: ${HDRS}
101
102.include <bsd.prog.mk>
103.include <bsd.subdir.mk>
104
105CPPFLAGS+=	-DMAKE_NATIVE
106COPTS.var.c+=	-Wno-cast-qual
107COPTS.job.c+=	-Wno-format-nonliteral
108COPTS.parse.c+=	-Wno-format-nonliteral
109COPTS.var.c+=	-Wno-format-nonliteral
110
111.if ${USE_GCC9} == "yes"
112CC=		/usr/pkg/gcc9/bin/gcc
113.endif
114
115.if defined(TOOLDIR)
116# This is a native NetBSD build, use libutil rather than the local emalloc etc.
117CPPFLAGS+=	-DUSE_EMALLOC
118LDADD+=		-lutil
119DPADD+=		${LIBUTIL}
120.endif
121
122COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
123COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}
124COPTS.main.c+=	${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
125COPTS.meta.c+=	${GCC_NO_FORMAT_TRUNCATION}
126COPTS.parse.c+=	${GCC_NO_FORMAT_TRUNCATION}
127
128COPTS+=		-Wdeclaration-after-statement
129
130# A simple unit-test driver to help catch regressions
131test: .MAKE
132	cd ${.CURDIR}/unit-tests \
133	&& MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
134.if ${USE_COVERAGE} == yes
135	gcov ${SRCS}
136	sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
137.endif
138
139accept: .MAKE
140	cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
141
142retest:
143	${.MAKE} -C ${.CURDIR}/unit-tests cleandir
144.if ${USE_COVERAGE} == yes
145	rm -f *.gcov *.gcda
146.endif
147	${.MAKE} test
148