xref: /freebsd/contrib/bmake/Makefile (revision 2008043f386721d58158e37e0d7e50df8095942d)
1#	$Id: Makefile,v 1.125 2023/05/17 00:15:46 sjg Exp $
2
3PROG=	bmake
4
5SRCS= \
6	arch.c \
7	buf.c \
8	compat.c \
9	cond.c \
10	dir.c \
11	for.c \
12	hash.c \
13	job.c \
14	lst.c \
15	main.c \
16	make.c \
17	make_malloc.c \
18	meta.c \
19	metachar.c \
20	parse.c \
21	str.c \
22	suff.c \
23	targ.c \
24	trace.c \
25	util.c \
26	var.c
27
28.-include "VERSION"
29.-include "Makefile.inc"
30
31# this file gets generated by configure
32.-include "Makefile.config"
33
34.if !empty(LIBOBJS)
35SRCS+= ${LIBOBJS:T:.o=.c}
36.endif
37
38# just in case
39prefix?= /usr
40srcdir?= ${.CURDIR}
41
42DEFAULT_SYS_PATH?= ${prefix}/share/mk
43
44CPPFLAGS+= -DUSE_META
45CFLAGS+= ${CPPFLAGS}
46CFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
47CFLAGS+= -I. -I${srcdir} ${XDEFS} -DMAKE_NATIVE
48CFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}}
49COPTS.main.c+= "-DMAKE_VERSION=\"${_MAKE_VERSION}\""
50
51.for x in FORCE_MACHINE FORCE_MACHINE_ARCH
52.ifdef $x
53COPTS.main.c+= "-D$x=\"${$x}\""
54.endif
55.endfor
56
57# meta mode can be useful even without filemon
58# should be set by now
59USE_FILEMON ?= no
60.if ${USE_FILEMON:tl} != "no"
61.PATH:	${srcdir}/filemon
62SRCS+=	filemon_${USE_FILEMON}.c
63COPTS.meta.c+= -DUSE_FILEMON -DUSE_FILEMON_${USE_FILEMON:tu}
64COPTS.job.c+= ${COPTS.meta.c}
65
66.if ${USE_FILEMON} == "dev"
67FILEMON_H ?= /usr/include/dev/filemon/filemon.h
68.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
69COPTS.filemon_dev.c += -DHAVE_FILEMON_H -I${FILEMON_H:H}
70.endif
71.elif ${USE_FILEMON} == "ktrace"
72COPTS.filemon_ktrace.c += -Wno-error=unused-parameter
73.endif
74
75.endif				# USE_FILEMON
76
77.PATH:	${srcdir}
78
79.if make(obj) || make(clean)
80SUBDIR+= unit-tests
81.endif
82
83# start-delete1 for bsd.after-import.mk
84# we skip a lot of this when building as part of FreeBSD etc.
85
86# list of OS's which are derrived from BSD4.4
87BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly MirBSD Bitrig
88# we are...
89OS := ${.MAKE.OS:U${uname -s:L:sh}}
90# are we 4.4BSD ?
91isBSD44:=${BSD44_LIST:M${OS}}
92
93.if ${isBSD44} == "" && ${OS:NDarwin:NLinux} != ""
94MANTARGET= cat
95INSTALL?=${srcdir}/install-sh
96.if ${MACHINE} == "sun386"
97# even I don't have one of these anymore :-)
98CFLAGS+= -DPORTAR
99.elif ${OS} != "SunOS"
100# assume the worst
101SRCS+= sigcompat.c
102CFLAGS+= -DSIGNAL_FLAGS=SA_RESTART
103.endif
104.else
105MANTARGET?= man
106.endif
107
108# turn this on by default - ignored if we are root
109WITH_INSTALL_AS_USER=
110
111# suppress with -DWITHOUT_*
112OPTIONS_DEFAULT_YES+= \
113	AUTOCONF_MK \
114	INSTALL_MK \
115	PROG_LINK
116
117OPTIONS_DEFAULT_NO+= \
118	PROG_VERSION
119
120# process options now
121.include <own.mk>
122
123.if ${MK_PROG_VERSION} == "yes"
124PROG_NAME= ${PROG}-${_MAKE_VERSION}
125.if ${MK_PROG_LINK} == "yes"
126SYMLINKS+= ${PROG_NAME} ${BINDIR}/${PROG}
127.endif
128.endif
129
130EXTRACT_MAN=no
131# end-delete1
132
133MAN= ${PROG}.1
134MAN1= ${MAN}
135
136.if ${PROG} != "make"
137CLEANFILES+= my.history
138.if make(${MAN}) || !exists(${srcdir}/${MAN})
139my.history:
140	@(echo ".Nm"; \
141	echo "is derived from NetBSD"; \
142	echo ".Xr make 1 ."; \
143	echo "It uses autoconf to facilitate portability to other platforms."; \
144	echo ".Pp") > $@
145
146.NOPATH: ${MAN}
147${MAN}:	make.1 my.history
148	@echo making $@
149	@sed \
150	-e '/^.Dt/s/MAKE/${PROG:tu}/' \
151	-e 's/^.Nx/NetBSD/' \
152	-e '/^.Nm/s/make/${PROG}/' \
153	-e '/^.Sh HISTORY/rmy.history' \
154	-e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@
155
156all beforeinstall: ${MAN}
157_mfromdir=.
158.endif
159.endif
160
161MANTARGET?= cat
162MANDEST?= ${MANDIR}/${MANTARGET}1
163
164.if ${MANTARGET} == "cat"
165_mfromdir=${srcdir}
166.endif
167
168.include <prog.mk>
169
170CPPFLAGS+= -DMAKE_NATIVE -DHAVE_CONFIG_H
171COPTS.var.c += -Wno-cast-qual
172COPTS.job.c += -Wno-format-nonliteral
173COPTS.parse.c += -Wno-format-nonliteral
174COPTS.var.c += -Wno-format-nonliteral
175
176# Force these
177SHAREDIR= ${SHAREDIR.bmake:U${prefix}/share}
178BINDIR= ${BINDIR.bmake:U${prefix}/bin}
179MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
180
181${OBJS}: config.h
182
183# start-delete2 for bsd.after-import.mk
184
185# make sure that MAKE_VERSION gets updated.
186main.o: ${srcdir}/VERSION
187
188.if ${MK_AUTOCONF_MK} == "yes"
189CONFIGURE_DEPS += ${.CURDIR}/VERSION
190# we do not need or want the generated makefile
191CONFIGURE_ARGS += --without-makefile
192AUTOCONF_GENERATED_MAKEFILE = Makefile.config
193.include <autoconf.mk>
194.endif
195SHARE_MK ?= ${SHAREDIR}/mk
196MKSRC = ${srcdir}/mk
197INSTALL ?= ${srcdir}/install-sh
198
199.if ${MK_INSTALL_MK} == "yes"
200install: install-mk
201.endif
202
203beforeinstall:
204	test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${BINDIR}
205	test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${MANDEST}
206
207install-mk:
208.if exists(${MKSRC}/install-mk)
209	test -d ${DESTDIR}${SHARE_MK} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${SHARE_MK}
210	sh ${MKSRC}/install-mk -v -m ${NONBINMODE} ${DESTDIR}${SHARE_MK}
211.else
212	@echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false
213.endif
214# end-delete2
215
216# A simple unit-test driver to help catch regressions
217TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
218accept test: .NOMETA
219	cd ${.CURDIR}/unit-tests && \
220	MAKEFLAGS= ${TEST_MAKE} -r -m / ${.TARGET} ${TESTS:DTESTS=${TESTS:Q}}
221
222
223.if make(test) && ${MK_AUTO_OBJ} == "yes"
224# The test target above visits unit-tests with -r -m /
225# which prevents MK_AUTO_OBJ doing its job
226# so do it here
227.if defined(MAKEOBJDIRPREFIX) || ${MAKEOBJDIR:U:M*/*} != ""
228_utobj = ${.OBJDIR}/unit-tests
229.else
230_utobj = ${.CURDIR}/unit-tests/${MAKEOBJDIR:Uobj}
231.endif
232utobj: .NOMETA
233	@test -d ${_utobj} && exit 0; \
234	echo "[Creating ${_utobj}...]"; \
235	umask ${OBJDIR_UMASK:U002}; \
236	mkdir -p ${_utobj}
237test: utobj
238.endif
239