Makefile revision 1.107
1#	$NetBSD: Makefile,v 1.107 2020/12/03 18:43:02 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+=  suff.c
22SRCS+=  targ.c
23SRCS+=  trace.c
24SRCS+=  var.c
25SRCS+=  util.c
26HDRS=   buf.h
27HDRS+=  config.h
28HDRS+=  dir.h
29HDRS+=  enum.h
30HDRS+=  hash.h
31HDRS+=  job.h
32HDRS+=  lst.h
33HDRS+=  make.h
34HDRS+=  make_malloc.h
35HDRS+=  meta.h
36HDRS+=  metachar.h
37HDRS+=  nonints.h
38HDRS+=  pathnames.h
39HDRS+=  trace.h
40
41# Whether to generate a coverage report after running the tests.
42USE_COVERAGE?=	no		# works only with gcc; clang9 fails to link
43.if ${USE_COVERAGE} == "yes"
44GCOV?=		gcov
45COPTS+=		--coverage -O0 -ggdb
46GCOV_PERL=	if (/^File '(\S+)'/) {
47GCOV_PERL+=		$$file = $$1; $$func = "";
48GCOV_PERL+=	} elsif (/^Function '(\S+)'/) {
49GCOV_PERL+=		$$func = $$1;
50GCOV_PERL+=	} elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/) {
51GCOV_PERL+=		printf("%6.2f  %5d   %s%s\n", $$1, $$2, $$file, $$func);
52GCOV_PERL+=	}
53LDADD+=		--coverage
54.endif
55CLEANFILES+=	*.gcda *.gcno *.gcov
56
57# Whether to compile using the Undefined Behavior Sanitizer (GCC, Clang).
58USE_UBSAN?=	no
59.if ${USE_UBSAN} == "yes"
60COPTS+=		-fsanitize=undefined
61LDADD+=		-fsanitize=undefined
62.endif
63
64# Whether to compile with GCC 10 from pkgsrc, during development.
65USE_GCC10?=	no
66.if ${USE_GCC10} == "yes"
67# CC is set further down in this file
68COPTS+=		-Wno-attributes	# for abs and labs
69COPTS.arch.c+=	-Wno-error=format-truncation
70COPTS.dir.c+=	-Wno-error=format-truncation
71COPTS.main.c+=	-Wno-error=format-truncation
72COPTS.meta.c+=	-Wno-error=format-truncation
73.endif
74
75# Whether to compile with GCC 9 from pkgsrc, during development.
76USE_GCC9?=	no
77.if ${USE_GCC9} == "yes"
78# CC is set further down in this file
79COPTS+=		-Wno-attributes	# for abs and labs
80COPTS.arch.c+=	-Wno-error=format-truncation
81COPTS.dir.c+=	-Wno-error=format-truncation
82COPTS.main.c+=	-Wno-error=format-truncation
83COPTS.meta.c+=	-Wno-error=format-truncation
84.endif
85
86# Whether to compile with GCC 8 from pkgsrc, during development.
87USE_GCC8?=	no
88.if ${USE_GCC8} == "yes"
89# CC is set further down in this file
90COPTS+=		-Wno-attributes	# for abs and labs
91COPTS.arch.c+=	-Wno-error=format-truncation
92COPTS.dir.c+=	-Wno-error=format-truncation
93COPTS.main.c+=	-Wno-error=format-truncation
94COPTS.meta.c+=	-Wno-error=format-truncation
95.endif
96
97USE_META?=	yes
98.if ${USE_META:tl} != "no"
99
100SRCS+=		meta.c
101CPPFLAGS+=	-DUSE_META
102
103USE_FILEMON?=	ktrace
104.  if ${USE_FILEMON:tl} != "no"
105
106.PATH:	${.CURDIR}/filemon
107SRCS+=		filemon_${USE_FILEMON}.c
108CPPFLAGS+=	-DUSE_FILEMON
109CPPFLAGS+=	-DUSE_FILEMON_${USE_FILEMON:tu}
110
111.    if ${USE_FILEMON} == "dev"
112FILEMON_H?=	/usr/include/dev/filemon/filemon.h
113.      if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
114COPTS.filemon_dev.c+= \
115		-DHAVE_FILEMON_H -I${FILEMON_H:H}
116.      endif
117.    endif
118.  endif
119.endif
120
121SUBDIR.roff+=	PSD.doc
122.if make(obj) || make(clean)
123SUBDIR+=	unit-tests
124.endif
125
126${SRCS:M*.c:.c=.o}: ${HDRS}
127CLEANFILES+=	*.o
128
129.include <bsd.prog.mk>
130.include <bsd.subdir.mk>
131
132CPPFLAGS+=	-DMAKE_NATIVE
133COPTS.job.c+=	-Wno-format-nonliteral
134COPTS.parse.c+=	-Wno-format-nonliteral
135COPTS.var.c+=	-Wno-format-nonliteral
136
137.if ${USE_GCC10} == "yes"
138GCC10BASE?=	/usr/pkg/gcc10
139CC=		${GCC10BASE}/bin/gcc
140GCOV=		${GCC10BASE}/bin/gcov
141.endif
142
143.if ${USE_GCC9} == "yes"
144GCC9BASE?=	/usr/pkg/gcc9
145CC=		${GCC9BASE}/bin/gcc
146GCOV=		${GCC9BASE}/bin/gcov
147.endif
148
149.if ${USE_GCC8} == "yes"
150GCC8BASE?=	/usr/pkg/gcc8
151CC=		${GCC8BASE}/bin/gcc
152GCOV=		${GCC8BASE}/bin/gcov
153.endif
154
155.if defined(TOOLDIR)
156# This is a native NetBSD build, use libutil rather than the local emalloc etc.
157CPPFLAGS+=	-DUSE_EMALLOC
158LDADD+=		-lutil
159DPADD+=		${LIBUTIL}
160.endif
161
162COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
163COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}
164COPTS.main.c+=	${GCC_NO_FORMAT_TRUNCATION} ${GCC_NO_STRINGOP_TRUNCATION}
165COPTS.meta.c+=	${GCC_NO_FORMAT_TRUNCATION}
166
167COPTS+=		-Wdeclaration-after-statement
168
169# For -DCLEANUP and similar feature toggles.
170CPPFLAGS+=	${USER_CPPFLAGS}
171# For overriding -std=gnu99 or similar options.
172CFLAGS+=	${USER_CFLAGS}
173
174# A simple unit-test driver to help catch regressions
175TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
176test: .MAKE
177	cd ${.CURDIR}/unit-tests \
178	&& MAKEFLAGS= ${TEST_MAKE} -r -m / TEST_MAKE=${TEST_MAKE} ${TESTS:DTESTS=${TESTS:Q}} ${.TARGET}
179.if ${USE_COVERAGE} == yes
180	@${GCOV} ${GCOV_OPTS} ${SRCS} | perl -ne ${GCOV_PERL:Q} | sort -nr
181	@sed -i 's,^\([^:]*\): *[0-9]*:,\1: ,' *.gcov
182.endif
183
184accept sync-mi: .MAKE
185	cd ${.CURDIR}/unit-tests && ${.MAKE} ${.TARGET}
186
187retest:
188	${.MAKE} -C ${.CURDIR}/unit-tests cleandir
189.if ${USE_COVERAGE} == yes
190	rm -f *.gcov *.gcda
191.endif
192	${.MAKE} test
193
194# Just out of curiosity, during development.
195.SUFFIXES: .cpre .casm
196.c.cpre:
197	${COMPILE.c:S,^-c$,-E,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
198.c.casm:
199	${COMPILE.c:S,^-c$,-S,} ${COPTS.${.IMPSRC}} ${.IMPSRC} -o ${.TARGET}
200