1# $MirOS: src/Makefile,v 1.149 2013/08/05 21:57:16 tg Exp $
2# $OpenBSD: Makefile,v 1.103 2004/05/03 15:18:18 drahn Exp $
3
4.if defined(MAKECONF) && exists(${MAKECONF})
5.  error MAKECONF is set to '${MAKECONF}', you don't want this!
6.endif
7.include <bsd.own.mk>
8.include "Makefile.inc"
9.if exists(gcc/Makefile.lang)
10.  include "gcc/Makefile.lang"
11.else
12NO_ADA?=	Yes
13NO_PASCAL?=	Yes
14.endif
15NOMAN?=		no
16CVSROOT?=	/cvs
17ANONCVSROOT?=	_anoncvs@anoncvs.mirbsd.org:/cvs
18_SAFEPATH=	/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin
19BATCH?=		No
20TSCOMPRESS?=	Yes
21
22  SUBDIR+= lib
23  SUBDIR+= include
24  SUBDIR+= bin
25  SUBDIR+= libexec
26  SUBDIR+= sbin
27  SUBDIR+= usr.bin
28  SUBDIR+= usr.sbin
29  SUBDIR+= share
30  SUBDIR+= gnu
31  SUBDIR+= sys
32.if make(clean) || make(cleandir) || make(obj)
33  SUBDIR+= distrib
34.endif
35
36beforeinstall: distrib-dirs
37	cd ${.CURDIR}/include && exec ${MAKE} includes
38
39afterinstall:
40.if ${NOMAN:L} == "no"
41	cd ${.CURDIR}/share/man && exec ${MAKE} makedb
42.endif
43
44mksystrace: mksystrace-obj mksystrace-dest
45
46mksystrace-obj:
47	cd ${BSDOBJDIR} && env WRITEDIR=${BSDOBJDIR:Q} \
48	    ${SHELL} ${BSDSRCDIR}/scripts/systrace.mk ${MAKE}
49
50mksystrace-dest:
51	d=${DESTDIR:Q}; cd $${d:-/}; [[ -n $$d ]] || d="/:/*"; \
52	    env WRITEDIR="$$d" NOWRITEDIR=${BSDOBJDIR:Q} \
53	    ${SUDO} ${SHELL} ${BSDSRCDIR}/scripts/systrace.mk ${MAKE}
54
55build-pre:
56	-${SUDO} rm -f ${_STFILE_OBJ} ${_STFILE_DEST}
57	cd ${.CURDIR} && exec ${MAKE} mksystrace
58	cd ${.CURDIR}/share/mk \
59	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install
60	cd ${.CURDIR}/include \
61	    && ${_STCMD_OBJ} ${MAKE} prereq \
62	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} includes
63	rm -rf ${BSDOBJDIR}/lib
64	cd ${.CURDIR}/lib && ${MAKE} obj && exec ${_STCMD_OBJ} ${MAKE} depend
65	cd ${.CURDIR}/lib/csu \
66	    && ${_STCMD_OBJ} ${MAKE} \
67	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install NOMAN=yes
68
69build-lib:
70	cd ${.CURDIR}/lib/libc \
71	    && ${_STCMD_OBJ} ${MAKE} \
72	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install NOMAN=yes
73	${SUDO} /sbin/ldconfig -R
74	cd ${.CURDIR}/lib \
75	    && ${_STCMD_OBJ} ${MAKE} \
76	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install NOMAN=yes
77	${SUDO} /sbin/ldconfig -R
78	cd ${.CURDIR} && ${_STCMD_OBJ} ${MAKE} depend
79
80contbuild:
81	cd ${.CURDIR} && exec ${MAKE} mksystrace
82	cd ${.CURDIR} && ${_STCMD_OBJ} ${MAKE} \
83	    && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install
84	@sleep 1
85	${SUDO} rm -f ${_STFILE_OBJ} ${_STFILE_DEST}
86
87distrib-dirs:
88	[[ -d ${DESTDIR}/. ]] || \
89	    ${SUDO} ${INSTALL} -d -o root -g wheel -m 755 ${DESTDIR}
90	${SUDO} mtree -p ${DESTDIR}/ -Uqdef ${.CURDIR}/etc/mtree/4.4BSD.dist
91	grep -v -e '^fd' -e dev/fd ${.CURDIR}/etc/mtree/special | \
92	    ${SUDO} mtree -p ${DESTDIR}/ -Uqde
93	cd ${DESTDIR}/var/anoncvs && \
94	    if [[ ! -h var || $$(readlink var) != . ]]; then \
95		${SUDO} rm -f var; \
96		${SUDO} ln -s . var; \
97	fi
98	for i in ${DESTDIR}/usr/{ports,src}; do \
99		[[ -d $$i ]] || \
100		    ${SUDO} ${INSTALL} -d -o root -g wsrc -m 775 $$i; \
101	done
102	cd ${DESTDIR}/ && ${SUDO} rm -f sys && ${SUDO} ln -s usr/src/sys sys
103
104b-r:
105	# Test if the targets are mounted suitable for root (BTSTF)
106.for _dir in ${BSDOBJDIR} ${BSDRELDIR}
107	mkdir -p ${_dir} || ${SUDO} mkdir -p ${_dir}
108	${SUDO} touch ${_dir}/permissions.test
109	${SUDO} chown root:wheel ${_dir}/permissions.test
110	${SUDO} rm ${_dir}/permissions.test
111.endfor
112	touch ${BSDOBJDIR}/permissions.test && rm ${BSDOBJDIR}/permissions.test
113	cd ${.CURDIR} && exec ${MAKE} obj
114	cd ${.CURDIR} && exec ${MAKE} build-pre DESTDIR=
115	cd ${.CURDIR} && exec ${MAKE} build-lib DESTDIR=
116	cd ${.CURDIR} && exec ${MAKE} contbuild DESTDIR=
117
118release:
119	mkdir -p ${DESTDIR} || ${SUDO} mkdir -p ${DESTDIR}
120	cd ${.CURDIR} && exec ${MAKE} mksystrace-dest
121	cd ${.CURDIR} && exec ${SUDO} ${_STCMD_DEST} ${MAKE} install
122	cd ${.CURDIR}/etc && exec ${SUDO} ${_STCMD_DEST} ${MAKE} etc-files
123	@sleep 1
124	${SUDO} rm -f ${_STFILE_DEST}
125
126do-htman:
127	-${SUDO} rm -rf ${BSDOBJDIR}/htman ${BSDRELDIR}/htman
128	${SUDO} mkdir -p ${BSDOBJDIR}/htman ${BSDRELDIR}/htman
129	${SUDO} chown $$(id -u) ${BSDOBJDIR}/htman ${BSDRELDIR}/htman
130	BSDOBJDIR=${BSDOBJDIR:Q} BSDSRCDIR=${BSDSRCDIR:Q} \
131	    BSDRELDIR=${BSDRELDIR:Q} OSrev=${OSrev:Q} \
132	    ${SHELL} ${.CURDIR}/scripts/genhtman.sh
133	${SUDO} chown -R 0:0 ${BSDRELDIR}/htman/*
134	${SUDO} chmod -R a=rX ${BSDRELDIR}/htman/*
135
136do-htinfopapers:
137	cd ${BSDOBJDIR} && env WRITEDIR=${BSDOBJDIR:Q} \
138	    ${SHELL} ${BSDSRCDIR}/scripts/systrace.mk ${MAKE} ${SHELL}
139.for _doc in papers psd smm usd
140	cd ${BSDOBJDIR}/htman/papers/${_doc} && ${_STCMD_OBJ} ${MAKE}
141.endfor
142	cd ${.CURDIR} && ${_STCMD_OBJ} ${MAKE} _do-htinfo
143	-rm -f ${BSDOBJDIR}/.policy.mk
144
145_do-htinfo:
146	cd ${BSDOBJDIR}/gnu/usr.bin/binutils/bfd/doc && \
147	    rm -f {bfd,bfdint}.html && \
148	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc \
149	    ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc/bfd.texinfo && \
150	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc \
151	    ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc/bfdint.texi && \
152	    cp {bfd,bfdint}.html ${BSDOBJDIR}/htman/texinfo/
153	cd ${BSDOBJDIR}/gnu/usr.bin/binutils/binutils/doc && \
154	    rm -f binutils.html && \
155	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/binutils/doc \
156	    ${BSDSRCDIR}/gnu/usr.bin/binutils/binutils/doc/binutils.texi && \
157	    cp binutils.html ${BSDOBJDIR}/htman/texinfo/
158	cd ${BSDOBJDIR}/gnu/usr.bin/binutils/gas/doc && \
159	    rm -f as.html && \
160	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gas/doc \
161	    ${BSDSRCDIR}/gnu/usr.bin/binutils/gas/doc/as.texinfo && \
162	    cp as.html ${BSDOBJDIR}/htman/texinfo/
163	cd ${BSDOBJDIR}/gnu/usr.bin/binutils/gdb/doc && \
164	    rm -f {gdb,gdbint,stabs,annotate}.html && \
165	    makeinfo --no-split --html \
166	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/mi \
167	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc \
168	    ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc/gdb.texinfo && \
169	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc \
170	    ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc/gdbint.texinfo && \
171	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc \
172	    ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc/stabs.texinfo && \
173	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc \
174	    ${BSDSRCDIR}/gnu/usr.bin/binutils/gdb/doc/annotate.texinfo && \
175	    cp {gdb,gdbint,stabs,annotate}.html ${BSDOBJDIR}/htman/texinfo/
176	cd ${BSDOBJDIR}/gnu/usr.bin/binutils/ld && \
177	    rm -f ld{,int}.html && \
178	    makeinfo --no-split --html \
179	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/ld \
180	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc \
181	    ${BSDSRCDIR}/gnu/usr.bin/binutils/ld/ld.texinfo && \
182	    makeinfo --no-split --html \
183	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/ld \
184	    -I ${BSDSRCDIR}/gnu/usr.bin/binutils/bfd/doc \
185	    ${BSDSRCDIR}/gnu/usr.bin/binutils/ld/ldint.texinfo && \
186	    cp ld{,int}.html ${BSDOBJDIR}/htman/texinfo/
187	cd ${BSDOBJDIR}/gnu/usr.bin/cvs/doc && \
188	    rm -f cvs{,client}.html && \
189	    makeinfo --no-split --html -I ${BSDSRCDIR}/gnu/usr.bin/cvs/doc \
190	    ${BSDSRCDIR}/gnu/usr.bin/cvs/doc/cvs.texinfo && \
191	    makeinfo --no-split --html \
192	    ${BSDSRCDIR}/gnu/usr.bin/cvs/doc/cvsclient.texi && \
193	    cp cvs{,client}.html ${BSDOBJDIR}/htman/texinfo/
194	cd ${BSDOBJDIR}/gcc/gcc && \
195	    rm -f {cpp{,internals},gcc{,int}}.html && \
196	    makeinfo --no-split --html -I ${BSDSRCDIR}/gcc/gcc/doc/include \
197	    ${BSDSRCDIR}/gcc/gcc/doc/cpp.texi && \
198	    makeinfo --no-split --html -I ${BSDSRCDIR}/gcc/gcc/doc/include \
199	    ${BSDSRCDIR}/gcc/gcc/doc/gcc.texi && \
200	    makeinfo --no-split --html -I ${BSDSRCDIR}/gcc/gcc/doc/include \
201	    ${BSDSRCDIR}/gcc/gcc/doc/gccint.texi && \
202	    makeinfo --no-split --html \
203	    ${BSDSRCDIR}/gcc/gcc/doc/cppinternals.texi && \
204	    cp {cpp{,internals},gcc{,int}}.html ${BSDOBJDIR}/htman/texinfo/
205.if ${NO_ADA:L} == "no"
206	cd ${BSDOBJDIR}/gcc/gcc && \
207	    rm -f gnat{_ugn_unw,_rm,-style}.html && \
208	    makeinfo --no-split --html \
209	    -I ${BSDSRCDIR}/gcc/gcc/doc/include -I ${BSDSRCDIR}/gcc/gcc/ada \
210	    doc/gnat_ugn_unw.texi && \
211	    makeinfo --no-split --html \
212	    -I ${BSDSRCDIR}/gcc/gcc/doc/include -I ${BSDSRCDIR}/gcc/gcc/ada \
213	    ${BSDSRCDIR}/gcc/gcc/ada/gnat_rm.texi && \
214	    makeinfo --no-split --html \
215	    -I ${BSDSRCDIR}/gcc/gcc/doc/include -I ${BSDSRCDIR}/gcc/gcc/ada \
216	    ${BSDSRCDIR}/gcc/gcc/ada/gnat-style.texi && \
217	    cp gnat{_ugn_unw,_rm,-style}.html ${BSDOBJDIR}/htman/texinfo/
218.endif
219.if ${NO_PASCAL:L} == "no"
220	cd ${BSDOBJDIR}/gcc/gpcdoc && \
221	    cp gpc{,-hr,s{,-de,-hr}}.html ${BSDOBJDIR}/htman/texinfo/
222.endif
223
224base-distbuild:
225	cd ${.CURDIR} && exec ${MAKE} mksystrace-obj
226	cd ${.CURDIR}/distrib && ${_STCMD_OBJ} ${MAKE} depend && \
227	    exec ${_STCMD_OBJ} ${MAKE}
228	-rm -f ${_STFILE_OBJ}
229
230base-distinstall:
231	cd ${.CURDIR} && exec ${MAKE} mksystrace-dest
232.if (${MACHINE_ARCH} == "i386")
233	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
234	    ${.CURDIR}/distrib/common/ekeyrng ${DESTDIR}/usr/libexec/
235.endif
236	-rm -rf ${_STFILE_OBJ} ${DESTDIR}/snapshot
237	${INSTALL} -d -o root -g wheel -m 755 ${DESTDIR}/snapshot
238	cd ${DESTDIR} && for file in usr/mdec/*{boot,mbr}*; do \
239		[[ -e $$file ]] || continue; \
240		${INSTALL} -c -o root -g wheel -m 444 $$file snapshot/; \
241	done
242	cd ${.CURDIR}/distrib && exec ${_STCMD_DEST} ${MAKE} install
243	cd ${.CURDIR}/share/man && exec ${_STCMD_DEST} ${MAKE} makedb
244	cd ${.CURDIR}/gnu/usr.bin/texinfo && exec ${_STCMD_DEST} \
245	    ${MAKE} -f Makefile.bsd-wrapper mkinfodir
246	-rm -f ${_STFILE_DEST}
247
248dist:
249	cd ${.CURDIR} && exec /usr/bin/env -i MAKEFLAGS=${MFLAGS:M*:Q} \
250	    HOME=$$(/usr/bin/mktemp -d /var/tmp/buildhome.XXXXXXXXXX) \
251	    PATH=${_SAFEPATH} TZ=UTC \
252	    ${MAKE} _do-dist 2>&1 | tee -a ${.CURDIR}/Build.log
253	@date | tee -a ${.CURDIR}/Build.log
254	-[[ -d ${BSDRELDIR}/rel && -s ${.CURDIR}/Build.log ]] && \
255	    ${SUDO} cp ${.CURDIR}/Build.log ${BSDRELDIR}/rel/
256
257dist-q:
258	cd ${.CURDIR} && exec /usr/bin/env -i MAKEFLAGS=${MFLAGS:M*:Q} \
259	    HOME=$$(/usr/bin/mktemp -d /var/tmp/buildhome.XXXXXXXXXX) \
260	    PATH=${_SAFEPATH} TZ=UTC BATCH=Yes \
261	    ${MAKE} _do-dist 2>&1 | tee -a ${.CURDIR}/Build.log
262	@date | tee -a ${.CURDIR}/Build.log
263	-[[ -d ${BSDRELDIR}/rel && -s ${.CURDIR}/Build.log ]] && \
264	    ${SUDO} cp ${.CURDIR}/Build.log ${BSDRELDIR}/rel/
265
266_DISTS=		base
267.ifdef QUICK_DIST2
268QUICK_DIST=	implied
269.else
270_DISTS+=	x11
271.endif
272.ifndef QUICK_DIST
273_DISTS+=	htman
274.endif
275DIST_RESTART?=	0
276
277_do-dist:
278	@h=${HOME:Q}; [[ $$h = $$HOME ]] || exit 1
279	@if [[ $$HOME != /var/tmp/buildhome.* ]]; then \
280		echo Do not call this target directly; \
281		exit 1; \
282	fi
283	@echo Initialising sudo as ${SUDO:Q}
284	${SUDO} true
285	mkdir -p ${HOME}/.etc/systrace
286.ifdef QUICK_DIST2
287.  if ${NO_JAVA:L} == "no"
288	@[[ -e /usr/X11R6/include/X11/X.h && -e /usr/X11R6/lib/libX11.a ]] || \
289	    {	print 'To build gcc/libjava you must have X11 installed!'; \
290		${SUDO} rm -rf ${HOME}; \
291		exit 1; \
292	}
293.  endif
294.endif
295	@if [[ ! -x /usr/mpkg/bin/gmake ]] || \
296	    ! /usr/mpkg/bin/gmake --version >/dev/null; then \
297		print 'To build gcc you must have GNU make installed!'; \
298		${SUDO} rm -rf ${HOME}; \
299		exit 1; \
300	fi
301.ifndef QUICK_DIST
302	@c='${CVSROOT}'; [[ $$c = @(:@(ext|pserver):|*@(@))*@(:/)* || \
303	    -e $$c/CVSROOT/config ]] || { \
304		print 'To build a full release CVSROOT must point to the'; \
305		print 'locally mounted MirOS /cvs or a remote repository'; \
306		${SUDO} rm -rf ${HOME}; \
307		exit 1; \
308	}
309.endif
310	@if ! ${SUDO} mksh -c '[[ -w /var/anoncvs/bin/cvs ]]'; then \
311		print 'Your /var/anoncvs must be mounted read-write'; \
312		${SUDO} rm -rf ${HOME}; \
313		exit 1; \
314	fi
315	@echo ============================================================
316	@if [[ ! -e /var/tmp/.buildnotice ]]; then \
317		${SUDO} install -c -o 0 -g 0 -m 600 /dev/null \
318		    /var/tmp/.buildnotice; \
319	fi
320	${SUDO} ${MKSH} -c 'echo rm -rf ${HOME} >>/var/tmp/.buildnotice'
321	@${SUDO} rm -f ${BSDRELDIR}/rel/Build.log
322	@echo Initiating MirOS Build...
323	@date
324.if ${BATCH:L} == "yes"
325	@echo BATCH mode engaged.
326.else
327	@echo INTERACTIVE mode engaged.
328.endif
329.ifdef QUICK_DIST
330	@echo QUICK dist-build mode active:
331	@echo not building ports, package tools, or HTML manual pages.
332.  ifdef QUICK_DIST2
333	@echo not building XFree86® either.
334.  endif
335.endif
336	@echo ============================================================
337.if ${DIST_RESTART} > 0
338	@print not removing ${BSDOBJDIR:Q} and ${BSDRELDIR:Q}
339.elif defined(NFS_DIST)
340	@for dir in ${BSDOBJDIR} ${BSDRELDIR}; do \
341		if [[ -d $$dir ]]; then \
342			${SUDO} rm -rf $$dir/{*,.*}; \
343		elif [[ -e $$dir ]]; then \
344			print "Warning: '$$dir' not a directory!"; \
345			print "The build might fail due to strange"; \
346			print "mount combinations, symlinks, etc."; \
347			print "and '$$dir' cannot be cleaned either!"; \
348		else \
349			print "Warning: '$$dir' non-existant; if you"; \
350			print "intend an NFS dist you should better"; \
351			print "mount something there before starting!"; \
352		fi; \
353	done
354.else
355	${SUDO} rm -rf ${BSDOBJDIR} ${BSDRELDIR}
356.endif
357	cd ${.CURDIR} && exec ${MAKE} distrib-dirs DESTDIR=
358	${SUDO} install -d -o 0 -g 0 -m ${DIRMODE} ${BSDRELDIR}/{base,rel,x11}
359.if ${DIST_RESTART} == 0
360	cd ${.CURDIR} && exec ${MAKE} b-r
361.elif ${DIST_RESTART} == 1
362	cd ${.CURDIR} && ${MAKE} build-lib && exec ${MAKE} contbuild
363.elif ${DIST_RESTART} == 2
364	cd ${.CURDIR} && exec ${MAKE} contbuild
365.endif
366	${SUDO} /sbin/ldconfig -R
367.ifndef QUICK_DIST2
368	@date
369.  if ${DIST_RESTART} < 4
370	cd ${.CURDIR}/X11 && exec ${MAKE} b-r
371.  endif
372.endif
373	${SUDO} /sbin/ldconfig -R
374	@date
375.if ${DIST_RESTART} < 5
376	cd ${.CURDIR}/gcc && exec ${MAKE} b-r
377.endif
378	${SUDO} /sbin/ldconfig -R
379	@date
380.if ${DIST_RESTART} < 6
381	cd ${.CURDIR} && exec ${MAKE} release DESTDIR=${BSDRELDIR}/base
382	cd ${.CURDIR}/gcc && \
383	    exec ${SUDO} ${MAKE} install DESTDIR=${BSDRELDIR}/base
384.  ifndef QUICK_DIST2
385	cd ${.CURDIR}/X11 && \
386	    exec ${SUDO} ${MAKE} release DESTDIR=${BSDRELDIR}/x11
387.  endif
388.endif
389	@date
390.if ${DIST_RESTART} < 7
391	cd ${.CURDIR} && exec ${MAKE} base-distbuild DESTDIR=${BSDRELDIR}/base
392	cd ${.CURDIR} && exec ${SUDO} ${MAKE} base-distinstall \
393	    DESTDIR=${BSDRELDIR}/base
394.endif
395.ifndef QUICK_DIST
396	@date
397	t=0; cd ${BSDRELDIR}; \
398	if mount 2>&- | fgrep ' on ${BSDRELDIR}/usr ' >&- 2>&-; then \
399		${SUDO} umount ${BSDRELDIR}/usr; \
400	fi; \
401	test ! -e usr || ${SUDO} rm -rf usr; \
402	mkdir usr && \
403	${SUDO} mount_mfs -s 458752 swap ${BSDRELDIR}/usr && \
404	if ! test -e ${BSDRELDIR}/rel/ports${OSrev}.ngz; then \
405		cd usr && \
406		(umask 002; cvs -Rqz3 -d ${CVSROOT} co -PA ports) && \
407		${MKSH} ${.CURDIR}/scripts/mnt-cvsroot ${ANONCVSROOT} . && \
408		mkdir -m 0775 ports/{Distfiles,Packages} && \
409		${SUDO} chown -R root:wsrc ports && \
410		cd .. && \
411		find usr/ports | sort | cpio -oC512 -Hsv4cpio -Mset | \
412		    gzip -n9 | ${SUDO} dd of=rel/ports${OSrev}.ngz && t=1; \
413	else \
414		${SUDO} tar xzphf ${BSDRELDIR}/rel/ports${OSrev}.ngz \
415		    usr/ports/{CVS,M*,S*,essentials/pkgtools,in*} && t=1; \
416	fi; \
417	test -e ${BSDRELDIR}/rel/pkgutl${OSrev}.ngz || if [[ $$t = 1 ]]; then \
418		cd ${BSDRELDIR}/base/dev; ${SUDO} ./MAKEDEV std systrace; \
419		cd ..; ${SUDO} rm -rf usr/{mpkg,ports} .etc var/games; \
420		${SUDO} mkdir .etc; cd ../usr; ${SUDO} pax -rw -pe -l \
421		    ports/{Makefile,Setup.sh,essentials/pkgtools,infra*} \
422		    ${BSDRELDIR}/base/usr && cd ${BSDRELDIR}/base && \
423		${SUDO} chroot . mksh -c 'cd /usr/ports && make \
424		    HOME=/ SUDO= setup' && \
425		find usr/mpkg | sort | ${SUDO} cpio -oC512 -Hsv4cpio -Mset | \
426		    gzip -n9 | ${SUDO} dd of=../rel/pkgutl${OSrev}.ngz && t=; \
427		[[ -z $$t ]] || rm -f ${BSDRELDIR}/rel/pkgutl${OSrev}.ngz; \
428		cd ${BSDRELDIR}; ${SUDO} rm -rf base/dev/!(MAKEDEV) \
429		    base/usr/{mpkg,ports} base/.etc base/var/games; \
430		${SUDO} mkdir -m 0775 ${BSDRELDIR}/base/usr/ports; \
431		${SUDO} chown root:wsrc ${BSDRELDIR}/base/usr/ports; \
432	fi; \
433	cd ${BSDRELDIR}; ${SUDO} umount ${BSDRELDIR}/usr; \
434	test -e ${BSDRELDIR}/rel/pkgutl${OSrev}.ngz
435	@date
436	if [[ ! -e ${BSDRELDIR}/rel/htmi${OSrev}.ngz || \
437	    ! -e ${BSDRELDIR}/rel/htmd${OSrev}.ngz ]]; then \
438		cd ${.CURDIR} && exec ${MAKE} do-htman; \
439	fi
440.endif
441	col -bx <${BSDRELDIR}/base/usr/share/man/cat7/install.${MACHINE}.0 \
442	    >${BSDOBJDIR}/INSTALL
443	@date
444	@echo ============================================================
445	@if [[ -e /var/tmp/.buildnotice ]]; then \
446		${SUDO} cat /var/tmp/.buildnotice; \
447		${SUDO} ${MKSH} /var/tmp/.buildnotice; \
448		${SUDO} rm -f /var/tmp/.buildnotice || true; \
449		echo ============================================================; \
450	fi
451	@echo Checking files:
452	@echo
453.for _set in ${_DISTS}
454	-cd ${BSDSRCDIR}/distrib/lists/${_set} && \
455	    DESTDIR=${BSDRELDIR:Q}/${_set} RELEASEDIR=${BSDRELDIR:Q}/rel \
456	    ${SUDO} ${SHELL} ${BSDSRCDIR}/scripts/tarsets check
457.endfor
458	@echo ============================================================
459.if ${BATCH:L} != "yes"
460	@date
461	@read a?'Press Return to continue...'
462.endif
463	@date
464	${SUDO} ${INSTALL} -c -o root -g wheel -m 444 \
465	    ${BSDOBJDIR}/INSTALL ${BSDRELDIR}/base/snapshot/* ${BSDRELDIR}/rel/
466	${SUDO} ${INSTALL} -c -o root -g wheel -m 444 \
467	    ${BSDSRCDIR}/distrib/empty.ngz ${BSDRELDIR}/rel/fixes${OSrev}.ngz
468	${SUDO} ${INSTALL} -c -o root -g wheel -m 444 \
469	    ${BSDSRCDIR}/distrib/empty.ngz ${BSDRELDIR}/rel/site${OSrev}.ngz
470.for _set in ${_DISTS}
471	-cd ${BSDSRCDIR}/distrib/lists/${_set} && env doz=${TSCOMPRESS:L:Q} \
472	    DESTDIR=${BSDRELDIR:Q}/${_set} RELEASEDIR=${BSDRELDIR:Q}/rel \
473	    ${SUDO} ${SHELL} ${BSDSRCDIR}/scripts/tarsets make ${OSrev}
474.endfor
475	-cd ${BSDRELDIR}/rel; \
476	    ${SUDO} rm -f CKSUM* index.txt; \
477	    ( \
478		/bin/ls -d1 !(@(Build|index.txt)*); \
479		echo CKSUM; \
480		echo CKSUM.gz; \
481		echo index.txt; \
482	    ) | ${SUDO} sort -uo index.txt; \
483	    sort -k3 |& exec 3>&p; exec 4<&p; \
484	    sort |& exec 5>&p; exec 6<&p; \
485	    cksum -a cksum -a rmd160 -a tiger !(@(Build|CKSUM)*) | \
486	    while IFS= read -r line; do \
487		if [[ $$line = *" = "+([0-9a-fA-F]) ]]; then \
488			print -ru5 "$$line"; \
489		else \
490			print -ru3 "$$line"; \
491		fi; \
492	    done; \
493	    exec 3>&-; exec 5>&-; \
494	    (cat <&4; cat <&6) | ${SUDO} dd of=CKSUM 2>/dev/null; \
495	    ${SUDO} chmod 755 $$(find . -type d); \
496	    ${SUDO} chmod 444 $$(find . -type f); \
497	    ${SUDO} chown -R 0:0 .
498	@echo ============================================================
499	@echo Done with MirOS Build.
500.if ${DIST_RESTART} != 0
501	@${SUDO} touch ${BSDRELDIR}/rel/Not_an_official_release!
502.endif
503	@/bin/ls -Fl ${BSDRELDIR}/rel
504	@date
505	@echo ============================================================
506
507cflags:
508	@print -r -- CFLAGS=\'${CFLAGS:N-Werror:Q} ${COPTS:N-Werror:Q}\'
509
510.PHONY:	afterinstall b-r base-distbuild base-distinstall beforeinstall \
511	build-pre cflags cleandir contbuild dist dist-q distrib-dirs \
512	do-htman mksystrace mksystrace-dest mksystrace-obj release _do-dist
513
514.include <bsd.subdir.mk>
515
516cleandir:
517	-rm -rf ${BSDOBJDIR}/htman
518