1255253Ssjg#	$Id: Makefile,v 1.20 2013/09/04 15:42:03 sjg Exp $
2246149Ssjg
3246149Ssjg# Base version on src date
4255253SsjgMAKE_VERSION= 20130904
5246149Ssjg
6246149SsjgPROG=	bmake
7246149Ssjg
8246149SsjgSRCS= \
9246149Ssjg	arch.c \
10246149Ssjg	buf.c \
11246149Ssjg	compat.c \
12246149Ssjg	cond.c \
13246149Ssjg	dir.c \
14246149Ssjg	for.c \
15246149Ssjg	hash.c \
16246149Ssjg	job.c \
17246149Ssjg	main.c \
18246149Ssjg	make.c \
19246149Ssjg	make_malloc.c \
20246149Ssjg	meta.c \
21246149Ssjg	parse.c \
22246149Ssjg	str.c \
23246149Ssjg	strlist.c \
24246149Ssjg	suff.c \
25246149Ssjg	targ.c \
26246149Ssjg	trace.c \
27246149Ssjg	util.c \
28246149Ssjg	var.c
29246149Ssjg
30246149Ssjg# from lst.lib/
31246149SsjgSRCS+= \
32246149Ssjg	lstAppend.c \
33246149Ssjg	lstAtEnd.c \
34246149Ssjg	lstAtFront.c \
35246149Ssjg	lstClose.c \
36246149Ssjg	lstConcat.c \
37246149Ssjg	lstDatum.c \
38246149Ssjg	lstDeQueue.c \
39246149Ssjg	lstDestroy.c \
40246149Ssjg	lstDupl.c \
41246149Ssjg	lstEnQueue.c \
42246149Ssjg	lstFind.c \
43246149Ssjg	lstFindFrom.c \
44246149Ssjg	lstFirst.c \
45246149Ssjg	lstForEach.c \
46246149Ssjg	lstForEachFrom.c \
47246149Ssjg	lstInit.c \
48246149Ssjg	lstInsert.c \
49246149Ssjg	lstIsAtEnd.c \
50246149Ssjg	lstIsEmpty.c \
51246149Ssjg	lstLast.c \
52246149Ssjg	lstMember.c \
53246149Ssjg	lstNext.c \
54246149Ssjg	lstOpen.c \
55246149Ssjg	lstPrev.c \
56246149Ssjg	lstRemove.c \
57246149Ssjg	lstReplace.c \
58246149Ssjg	lstSucc.c
59246149Ssjg
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
71246149SsjgDEFAULT_SYS_PATH?= .../share/mk:${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}}
78246149SsjgCOPTS.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
97246149SsjgBSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly
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
120246149Ssjg# supress 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"
133246149SsjgPROG_NAME= ${PROG}-${MAKE_VERSION}
134246149Ssjg.if ${MK_PROG_LINK} == "yes"
135246149SsjgSYMLINKS+= ${PROG}-${MAKE_VERSION} ${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 $@
158246149Ssjg	@sed -e 's/^.Nx/NetBSD/' -e '/^.Nm/s/make/${PROG}/' \
159246149Ssjg	-e '/^.Sh HISTORY/rmy.history' \
160246149Ssjg	-e '/^.Sh HISTORY/,$$s,^.Nm,make,' ${srcdir}/make.1 > $@
161246149Ssjg
162246149Ssjgall beforeinstall: ${MAN}
163246149Ssjg_mfromdir=.
164246149Ssjg.endif
165246149Ssjg.endif
166246149Ssjg
167246149SsjgMANTARGET?= cat
168246149SsjgMANDEST?= ${MANDIR}/${MANTARGET}1
169246149Ssjg
170246149Ssjg.if ${MANTARGET} == "cat"
171246149Ssjg_mfromdir=${srcdir}
172246149Ssjg.endif
173246149Ssjg
174246149Ssjg.include <prog.mk>
175246149Ssjg
176246149SsjgCPPFLAGS+= -DMAKE_NATIVE -DHAVE_CONFIG_H
177246149SsjgCOPTS.var.c += -Wno-cast-qual
178246149SsjgCOPTS.job.c += -Wno-format-nonliteral
179246149SsjgCOPTS.parse.c += -Wno-format-nonliteral
180246149SsjgCOPTS.var.c += -Wno-format-nonliteral
181246149Ssjg
182246149Ssjg# Force these
183246149SsjgSHAREDIR= ${prefix}/share
184246149SsjgBINDIR= ${prefix}/bin
185246149SsjgMANDIR= ${SHAREDIR}/man
186246149Ssjg
187246149Ssjg.if !exists(.depend)
188246149Ssjg${OBJS}: config.h
189246149Ssjg.endif
190246149Ssjg
191246149Ssjg# make sure that MAKE_VERSION gets updated.
192246149Ssjgmain.o: ${SRCS} ${MAKEFILE}
193246149Ssjg
194246149Ssjg# start-delete2 for bsd.after-import.mk
195249033Ssjg.if ${MK_AUTOCONF_MK} == "yes"
196249033Ssjg.include <autoconf.mk>
197249033Ssjg.endif
198246149SsjgSHARE_MK?=${SHAREDIR}/mk
199246149SsjgMKSRC=${srcdir}/mk
200246149SsjgINSTALL?=${srcdir}/install-sh
201246149Ssjg
202246149Ssjg.if ${MK_INSTALL_MK} == "yes"
203246149Ssjginstall: install-mk
204246149Ssjg.endif
205246149Ssjg
206246149Ssjgbeforeinstall:
207246149Ssjg	test -d ${DESTDIR}${BINDIR} || ${INSTALL} -m 775 -d ${DESTDIR}${BINDIR}
208246149Ssjg	test -d ${DESTDIR}${MANDEST} || ${INSTALL} -m 775 -d ${DESTDIR}${MANDEST}
209246149Ssjg
210246149Ssjginstall-mk:
211246149Ssjg.if exists(${MKSRC}/install-mk)
212246149Ssjg	test -d ${DESTDIR}${SHARE_MK} || ${INSTALL} -m 775 -d ${DESTDIR}${SHARE_MK}
213246149Ssjg	sh ${MKSRC}/install-mk -v -m 644 ${DESTDIR}${SHARE_MK}
214246149Ssjg.else
215246149Ssjg	@echo need to unpack mk.tar.gz under ${srcdir} or set MKSRC; false
216246149Ssjg.endif
217246149Ssjg# end-delete2
218246149Ssjg
219246149Ssjg# A simple unit-test driver to help catch regressions
220246149Ssjgaccept test:
221246149Ssjg	cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}
222