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