1331246Ssjg#	$Id: Makefile,v 1.99 2017/08/13 20:12:53 sjg Exp $
2246149Ssjg
3246149SsjgPROG=	bmake
4246149Ssjg
5246149SsjgSRCS= \
6246149Ssjg	arch.c \
7246149Ssjg	buf.c \
8246149Ssjg	compat.c \
9246149Ssjg	cond.c \
10246149Ssjg	dir.c \
11246149Ssjg	for.c \
12246149Ssjg	hash.c \
13246149Ssjg	job.c \
14246149Ssjg	main.c \
15246149Ssjg	make.c \
16246149Ssjg	make_malloc.c \
17246149Ssjg	meta.c \
18289842Ssjg	metachar.c \
19246149Ssjg	parse.c \
20246149Ssjg	str.c \
21246149Ssjg	strlist.c \
22246149Ssjg	suff.c \
23246149Ssjg	targ.c \
24246149Ssjg	trace.c \
25246149Ssjg	util.c \
26246149Ssjg	var.c
27246149Ssjg
28246149Ssjg# from lst.lib/
29246149SsjgSRCS+= \
30246149Ssjg	lstAppend.c \
31246149Ssjg	lstAtEnd.c \
32246149Ssjg	lstAtFront.c \
33246149Ssjg	lstClose.c \
34246149Ssjg	lstConcat.c \
35246149Ssjg	lstDatum.c \
36246149Ssjg	lstDeQueue.c \
37246149Ssjg	lstDestroy.c \
38246149Ssjg	lstDupl.c \
39246149Ssjg	lstEnQueue.c \
40246149Ssjg	lstFind.c \
41246149Ssjg	lstFindFrom.c \
42246149Ssjg	lstFirst.c \
43246149Ssjg	lstForEach.c \
44246149Ssjg	lstForEachFrom.c \
45246149Ssjg	lstInit.c \
46246149Ssjg	lstInsert.c \
47246149Ssjg	lstIsAtEnd.c \
48246149Ssjg	lstIsEmpty.c \
49246149Ssjg	lstLast.c \
50246149Ssjg	lstMember.c \
51246149Ssjg	lstNext.c \
52246149Ssjg	lstOpen.c \
53246149Ssjg	lstPrev.c \
54246149Ssjg	lstRemove.c \
55246149Ssjg	lstReplace.c \
56246149Ssjg	lstSucc.c
57246149Ssjg
58331246Ssjg.-include "VERSION"
59331246Ssjg
60246149Ssjg# this file gets generated by configure
61246149Ssjg.-include "Makefile.config"
62246149Ssjg
63246149Ssjg.if !empty(LIBOBJS)
64246149SsjgSRCS+= ${LIBOBJS:T:.o=.c}
65246149Ssjg.endif
66246149Ssjg
67246149Ssjg# just in case
68246149Ssjgprefix?= /usr
69246149Ssjgsrcdir?= ${.CURDIR}
70246149Ssjg
71261212SsjgDEFAULT_SYS_PATH?= ${prefix}/share/mk
72246149Ssjg
73246149SsjgCPPFLAGS+= -DUSE_META
74246149SsjgCFLAGS+= ${CPPFLAGS}
75246149SsjgCFLAGS+= -D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\"
76246149SsjgCFLAGS+= -I. -I${srcdir} ${XDEFS} -DMAKE_NATIVE
77246149SsjgCFLAGS+= ${COPTS.${.ALLSRC:M*.c:T:u}}
78297040SsjgCOPTS.main.c+= "-DMAKE_VERSION=\"${_MAKE_VERSION}\""
79246149Ssjg
80246149Ssjg# meta mode can be useful even without filemon 
81246149SsjgFILEMON_H ?= /usr/include/dev/filemon/filemon.h
82246149Ssjg.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
83246149SsjgCOPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H}
84246149Ssjg.endif
85246149Ssjg
86246149Ssjg.PATH:	${srcdir}
87246149Ssjg.PATH:	${srcdir}/lst.lib
88246149Ssjg
89246149Ssjg.if make(obj) || make(clean)
90246149SsjgSUBDIR+= unit-tests
91246149Ssjg.endif
92246149Ssjg
93246149Ssjg# start-delete1 for bsd.after-import.mk
94246149Ssjg# we skip a lot of this when building as part of FreeBSD etc.
95246149Ssjg
96246149Ssjg# list of OS's which are derrived from BSD4.4
97282740SsjgBSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly MirBSD Bitrig
98246149Ssjg# we are...
99246149SsjgOS!= uname -s
100246149Ssjg# are we 4.4BSD ?
101246149SsjgisBSD44:=${BSD44_LIST:M${OS}}
102246149Ssjg
103246149Ssjg.if ${isBSD44} == ""
104246149SsjgMANTARGET= cat
105246149SsjgINSTALL?=${srcdir}/install-sh
106246149Ssjg.if (${MACHINE} == "sun386")
107246149Ssjg# even I don't have one of these anymore :-)
108246149SsjgCFLAGS+= -DPORTAR
109246149Ssjg.elif (${MACHINE} != "sunos")
110246149SsjgSRCS+= sigcompat.c
111246149SsjgCFLAGS+= -DSIGNAL_FLAGS=SA_RESTART
112246149Ssjg.endif
113246149Ssjg.else
114246149SsjgMANTARGET?= man
115246149Ssjg.endif
116246149Ssjg
117246149Ssjg# turn this on by default - ignored if we are root
118246149SsjgWITH_INSTALL_AS_USER=
119246149Ssjg
120268437Ssjg# suppress with -DWITHOUT_*
121246149SsjgOPTIONS_DEFAULT_YES+= \
122246149Ssjg	AUTOCONF_MK \
123246149Ssjg	INSTALL_MK \
124246149Ssjg	PROG_LINK
125246149Ssjg
126246149SsjgOPTIONS_DEFAULT_NO+= \
127246149Ssjg	PROG_VERSION
128246149Ssjg
129246149Ssjg# process options now
130246149Ssjg.include <own.mk>
131246149Ssjg
132246149Ssjg.if ${MK_PROG_VERSION} == "yes"
133300313SsjgPROG_NAME= ${PROG}-${_MAKE_VERSION}
134246149Ssjg.if ${MK_PROG_LINK} == "yes"
135300313SsjgSYMLINKS+= ${PROG_NAME} ${BINDIR}/${PROG}
136246149Ssjg.endif
137246149Ssjg.endif
138246149Ssjg
139246149SsjgEXTRACT_MAN=no
140246149Ssjg# end-delete1
141246149Ssjg
142246149SsjgMAN= ${PROG}.1
143246149SsjgMAN1= ${MAN}
144246149Ssjg
145246149Ssjg.if (${PROG} != "make")
146246149SsjgCLEANFILES+= my.history
147246149Ssjg.if make(${MAN}) || !exists(${srcdir}/${MAN})
148246149Ssjgmy.history: ${MAKEFILE}
149246149Ssjg	@(echo ".Nm"; \
150246149Ssjg	echo "is derived from NetBSD"; \
151246149Ssjg	echo ".Xr make 1 ."; \
152246149Ssjg	echo "It uses autoconf to facilitate portability to other platforms."; \
153246149Ssjg	echo ".Pp") > $@
154246149Ssjg
155246149Ssjg.NOPATH: ${MAN}
156246149Ssjg${MAN}:	make.1 my.history
157246149Ssjg	@echo making $@
158319884Ssjg	@sed \
159319884Ssjg	-e '/^.Dt/s/MAKE/${PROG:tu}/' \
160319884Ssjg	-e 's/^.Nx/NetBSD/' \
161319884Ssjg	-e '/^.Nm/s/make/${PROG}/' \
162246149Ssjg	-e '/^.Sh HISTORY/rmy.history' \
163246149Ssjg	-e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@
164246149Ssjg
165246149Ssjgall beforeinstall: ${MAN}
166246149Ssjg_mfromdir=.
167246149Ssjg.endif
168246149Ssjg.endif
169246149Ssjg
170246149SsjgMANTARGET?= cat
171246149SsjgMANDEST?= ${MANDIR}/${MANTARGET}1
172246149Ssjg
173246149Ssjg.if ${MANTARGET} == "cat"
174246149Ssjg_mfromdir=${srcdir}
175246149Ssjg.endif
176246149Ssjg
177246149Ssjg.include <prog.mk>
178246149Ssjg
179246149SsjgCPPFLAGS+= -DMAKE_NATIVE -DHAVE_CONFIG_H
180246149SsjgCOPTS.var.c += -Wno-cast-qual
181246149SsjgCOPTS.job.c += -Wno-format-nonliteral
182246149SsjgCOPTS.parse.c += -Wno-format-nonliteral
183246149SsjgCOPTS.var.c += -Wno-format-nonliteral
184246149Ssjg
185246149Ssjg# Force these
186281812SsjgSHAREDIR= ${SHAREDIR.bmake:U${prefix}/share}
187281812SsjgBINDIR= ${BINDIR.bmake:U${prefix}/bin}
188281812SsjgMANDIR= ${MANDIR.bmake:U${SHAREDIR}/man}
189246149Ssjg
190246149Ssjg.if !exists(.depend)
191246149Ssjg${OBJS}: config.h
192246149Ssjg.endif
193246149Ssjg
194331246Ssjg# start-delete2 for bsd.after-import.mk
195331246Ssjg
196246149Ssjg# make sure that MAKE_VERSION gets updated.
197331246Ssjgmain.o: ${SRCS} ${.CURDIR}/VERSION
198246149Ssjg
199249033Ssjg.if ${MK_AUTOCONF_MK} == "yes"
200331246SsjgCONFIGURE_DEPS += ${.CURDIR}/VERSION
201249033Ssjg.include <autoconf.mk>
202249033Ssjg.endif
203246149SsjgSHARE_MK?=${SHAREDIR}/mk
204246149SsjgMKSRC=${srcdir}/mk
205246149SsjgINSTALL?=${srcdir}/install-sh
206246149Ssjg
207246149Ssjg.if ${MK_INSTALL_MK} == "yes"
208246149Ssjginstall: install-mk
209246149Ssjg.endif
210246149Ssjg
211246149Ssjgbeforeinstall:
212246149Ssjg	test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m 775 -d ${DESTDIR}${BINDIR}
213246149Ssjg	test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m 775 -d ${DESTDIR}${MANDEST}
214246149Ssjg
215246149Ssjginstall-mk:
216246149Ssjg.if exists(${MKSRC}/install-mk)
217246149Ssjg	test -d ${DESTDIR}${SHARE_MK} || ${INSTALL} -m 775 -d ${DESTDIR}${SHARE_MK}
218246149Ssjg	sh ${MKSRC}/install-mk -v -m 644 ${DESTDIR}${SHARE_MK}
219246149Ssjg.else
220246149Ssjg	@echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false
221246149Ssjg.endif
222246149Ssjg# end-delete2
223246149Ssjg
224246149Ssjg# A simple unit-test driver to help catch regressions
225246149Ssjgaccept test:
226246149Ssjg	cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
227