xref: /freebsd/contrib/bmake/Makefile (revision 548bfc56eb0b2cefa0fb8dc2478240bfef610309)
1#	$Id: Makefile,v 1.127 2024/03/19 16:03:23 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_MAKE_OS 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:NCygwin:NDarwin:NLinux} != ""
94MANTARGET?= cat
95.if ${MACHINE} == "sun386"
96# even I don't have one of these anymore :-)
97CFLAGS+= -DPORTAR
98.elif ${OS} != "SunOS"
99# assume the worst
100SRCS+= sigcompat.c
101CFLAGS+= -DSIGNAL_FLAGS=SA_RESTART
102.endif
103.else
104MANTARGET?= man
105.endif
106
107# turn this on by default - ignored if we are root
108WITH_INSTALL_AS_USER=
109
110# suppress with -DWITHOUT_*
111OPTIONS_DEFAULT_YES+= \
112	AUTOCONF_MK \
113	INSTALL_MK \
114	PROG_LINK
115
116OPTIONS_DEFAULT_NO+= \
117	PROG_VERSION
118
119# process options now
120.include <own.mk>
121
122.if ${MK_PROG_VERSION} == "yes"
123PROG_NAME= ${PROG}-${_MAKE_VERSION}
124.if ${MK_PROG_LINK} == "yes"
125SYMLINKS+= ${PROG_NAME} ${BINDIR}/${PROG}
126.endif
127.endif
128
129EXTRACT_MAN=no
130# end-delete1
131
132MAN= ${PROG}.1
133MAN1= ${MAN}
134
135.if ${PROG} != "make"
136CLEANFILES+= my.history
137.if make(${MAN}) || !exists(${srcdir}/${MAN})
138my.history:
139	@(echo ".Nm"; \
140	echo "is derived from NetBSD"; \
141	echo ".Xr make 1 ."; \
142	echo "It uses autoconf to facilitate portability to other platforms."; \
143	echo ".Pp") > $@
144
145.NOPATH: ${MAN}
146${MAN}:	make.1 my.history
147	@echo making $@
148	@sed \
149	-e '/^.Dt/s/MAKE/${PROG:tu}/' \
150	-e 's/^.Nx/NetBSD/' \
151	-e '/^.Nm/s/make/${PROG}/' \
152	-e '/^.Sh HISTORY/rmy.history' \
153	-e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@
154
155all beforeinstall: ${MAN}
156_mfromdir=.
157.endif
158.endif
159
160MANTARGET?= cat
161MANDEST?= ${MANDIR}/${MANTARGET}1
162
163.if ${MANTARGET} == "cat"
164_mfromdir=${srcdir}
165.endif
166
167.include <prog.mk>
168
169CPPFLAGS+= -DMAKE_NATIVE -DHAVE_CONFIG_H
170COPTS.var.c += -Wno-cast-qual
171COPTS.job.c += -Wno-format-nonliteral
172COPTS.parse.c += -Wno-format-nonliteral
173COPTS.var.c += -Wno-format-nonliteral
174
175# Force these
176SHAREDIR= ${SHAREDIR.bmake:U${prefix}/share}
177BINDIR= ${BINDIR.bmake:U${prefix}/bin}
178MANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
179
180${OBJS}: config.h
181
182# start-delete2 for bsd.after-import.mk
183
184# make sure that MAKE_VERSION gets updated.
185main.o: ${srcdir}/VERSION
186
187.if ${MK_AUTOCONF_MK} == "yes"
188CONFIGURE_DEPS += ${.CURDIR}/VERSION
189# we do not need or want the generated makefile
190CONFIGURE_ARGS += --without-makefile
191AUTOCONF_GENERATED_MAKEFILE = Makefile.config
192.include <autoconf.mk>
193.endif
194SHARE_MK ?= ${SHAREDIR}/mk
195MKSRC = ${srcdir}/mk
196INSTALL ?= ${srcdir}/install-sh
197
198.if ${MK_INSTALL_MK} == "yes"
199install: install-mk
200.endif
201
202beforeinstall:
203	test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${BINDIR}
204	test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${MANDEST}
205
206install-mk:
207.if exists(${MKSRC}/install-mk)
208	test -d ${DESTDIR}${SHARE_MK} || ${INSTALL} -m ${DIRMODE} -d ${DESTDIR}${SHARE_MK}
209	sh ${MKSRC}/install-mk -v -m ${NONBINMODE} ${DESTDIR}${SHARE_MK}
210.else
211	@echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false
212.endif
213# end-delete2
214
215# A simple unit-test driver to help catch regressions
216TEST_MAKE ?= ${.OBJDIR}/${PROG:T}
217accept test: .NOMETA
218	cd ${.CURDIR}/unit-tests && \
219	MAKEFLAGS= ${TEST_MAKE} -r -m / ${.TARGET} ${TESTS:DTESTS=${TESTS:Q}}
220
221
222.if make(test) && ${MK_AUTO_OBJ} == "yes"
223# The test target above visits unit-tests with -r -m /
224# which prevents MK_AUTO_OBJ doing its job
225# so do it here
226.if defined(MAKEOBJDIRPREFIX) || ${MAKEOBJDIR:U:M*/*} != ""
227_utobj = ${.OBJDIR}/unit-tests
228.else
229_utobj = ${.CURDIR}/unit-tests/${MAKEOBJDIR:Uobj}
230.endif
231utobj: .NOMETA
232	@test -d ${_utobj} && exit 0; \
233	echo "[Creating ${_utobj}...]"; \
234	umask ${OBJDIR_UMASK:U002}; \
235	mkdir -p ${_utobj}
236test: utobj
237.endif
238