xref: /dragonfly/Makefile.inc1 (revision 7d3e9a5b)
1#
2# $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
3#
4# This file defines the user-driven targets.
5#
6# Standard targets are documented in the makefiles in /usr/share/mk and include:
7#	obj depend all install clean cleandepend cleanobj
8#
9# Build-time options are documented in make.conf(5).
10#
11
12DFLYVERSION!=   awk '/^\#define[[:blank:]]__DragonFly_version/ {print $$3}' \
13		< ${.CURDIR}/sys/sys/param.h
14
15OSREL!=		echo ${DFLYVERSION} | \
16		awk '{a=int($$1/100000); b=int(($$1-(a*100000))/100); \
17		print a "." b}'
18
19# Put initial settings here.
20SUBDIR=
21
22# /libexec/ld-elf.so.2 needs to be installed first
23# Otherwise, install(1) beeing a dynamically linked binary will fail
24# during the first upgrade from a static to a dynamic world
25SUBDIR+= libexec
26
27# We need to do include and lib early.
28#
29SUBDIR+= include
30SUBDIR+= lib
31
32SUBDIR+= bin
33.if !defined(NO_GAMES)
34SUBDIR+= games
35.endif
36SUBDIR+= gnu
37SUBDIR+= sbin
38.if !defined(NO_SHARE)
39SUBDIR+= share
40.endif
41SUBDIR+= stand
42SUBDIR+= sys
43SUBDIR+= usr.bin
44SUBDIR+= usr.sbin
45
46SUBDIR+= etc
47
48# These are last, since it is nice to at least get the base system
49# rebuilt before you do them.
50.if defined(LOCAL_DIRS)
51.for _DIR in ${LOCAL_DIRS}
52.if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
53SUBDIR+= ${_DIR}
54.endif
55.endfor
56.endif
57
58.if defined(SUBDIR_OVERRIDE)
59SUBDIR=		${SUBDIR_OVERRIDE}
60.endif
61
62.if defined(NOCLEANDIR)
63CLEANDIR=	clean cleandepend
64.else
65CLEANDIR=	cleandir
66.endif
67
68.if defined(NO_CLEAN)
69NOCLEAN=	# defined
70.endif
71
72# Object directory base in primary make.  Note that when we rerun make
73# from inside this file we change MAKEOBJDIRPREFIX to the appropriate
74# subdirectory because the rest of the build system needs it that way.
75# The original object directory base is saved in OBJTREE.
76#
77MAKEOBJDIRPREFIX?=	/usr/obj
78OBJTREE?=		${MAKEOBJDIRPREFIX}
79
80# Used for stage installs and pathing
81#
82DESTDIRBASE:=		${OBJTREE}${.CURDIR}
83
84# Remove DESTDIR from MAKEFLAGS.  It is present in the environment
85# anyhow, and we need to be able to override it for stage installs
86.MAKEFLAGS:=	${.MAKEFLAGS:NDESTDIR=*}
87
88# This section sets the tools used to build the world/kernel
89WORLD_CCVER?=		gcc80
90WORLD_LDVER?=		ld.bfd
91WORLD_BINUTILSVER?=	binutils234
92
93.if !defined(NO_BACKUP)
94# Set the backup parameters if they are not already defined
95#
96WORLD_BACKUP?=		/var/backups/world_backup
97AUTO_BACKUP?=		${OBJTREE}/world_backup/${DESTDIR}
98.endif
99
100TARGET_ARCH?=	${MACHINE_ARCH}
101.if ${TARGET_ARCH} == ${MACHINE_ARCH}
102TARGET?=	${MACHINE}
103.else
104TARGET?=	${TARGET_ARCH}
105.endif
106.if make(buildworld)
107BUILD_ARCH!=	sysctl -n hw.machine_arch
108
109# temporary until everybody has converted to x86_64
110.if ${BUILD_ARCH} == "amd64"
111BUILD_ARCH=	x86_64
112.endif
113
114.if ${MACHINE_ARCH} != ${BUILD_ARCH}
115.error To cross-build, set TARGET_ARCH.
116.endif
117.endif
118
119# XXX this is ugly and we need to come up with a nicer solution
120.if !defined(TARGET_PLATFORM)
121.if ${TARGET_ARCH} == "x86_64"
122TARGET_PLATFORM= pc64
123.else
124.error Unknown target architecture.
125.endif
126.endif
127
128THREAD_LIB?=	thread_xu
129
130# BTOOLS	(Natively built) All non-cross-development tools that the
131#		main build needs.  This includes things like 'mkdir' and 'rm'.
132#		We will not use the native system's exec path once we start
133#		on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
134#
135# CTOOLS	(Natively built) Cross development tools which are specific
136#		to the target architecture.
137#
138# WORLD		(Cross built) Our ultimate buildworld, using only BTOOLS and
139#		CTOOLS.
140#
141# MACHINE_PLATFORM	Platform Architecture we are building on
142# MACHINE		Machine Architecture (usually the same as MACHINE_ARCH)
143# MACHINE_ARCH		CPU Architecture we are building on
144#
145# TARGET_PLATFORM 	Platform Architecture we are building for
146# TARGET		Machine Architecture we are building for
147# TARGET_ARCH		CPU Architecture we are building for
148#
149BTOOLSDEST=	${DESTDIRBASE}/btools_${MACHINE_ARCH}
150CTOOLSDEST=	${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
151WORLDDEST=	${DESTDIRBASE}/world_${TARGET_ARCH}
152
153# The bootstrap-tools path is used by the bootstrap-tools, build-tools, and
154# cross-tools stages to augment the existing command path to access newer
155# versions of certain utilities that the cross-tools stage might expect.
156#
157BTOOLSPATH= ${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/sbin:${BTOOLSDEST}/bin
158
159# The cross-tools path containing the cross-tools to cross build the
160# ultimate world.
161#
162CTOOLSPATH= ${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/sbin:${CTOOLSDEST}/bin
163
164# The strict temporary command path contains all binaries required
165# by the buildworld system after the cross-tools stage.
166#
167# NOTE: Append '/usr/local/bin:/usr/pkg/bin' to support external compilers.
168#       See compilers.conf(5) man page for more info.
169#
170STRICTTMPPATH= ${CTOOLSPATH}:${BTOOLSPATH}:/usr/local/bin:/usr/pkg/bin
171
172TMPDIR?=	/tmp
173TMPPID!=	echo $$$$
174
175#
176# Building a world goes through the following stages
177#
178# 1. bootstrap-tool stage [BMAKE]
179#	This stage is responsible for creating programs that
180#	are needed for backward compatibility reasons. They
181#	are not built as cross-tools.
182# 2. build-tool stage [TMAKE]
183#	This stage is responsible for creating the object
184#	tree and building any tools that are needed during
185#	the build process.
186# 3. cross-tool stage [XMAKE]
187#	This stage is responsible for creating any tools that
188#	are needed for cross-builds. A cross-compiler is one
189#	of them.
190# 4. world stage [WMAKE]
191#	This stage actually builds the world.
192# 5. install stage (optional) [IMAKE]
193#	This stage installs a previously built world.
194#
195# In all cases we must carefully adjust the environment so the proper
196# tools and header files are used.
197#
198# NOTE: The M4 environment variable is used by the [f]lex binary to
199#	override the location of the 'm4' binary.  The override is
200#	needed for certain buildworld version transitions, specifically
201#	past a certain point in 3.3 because the older /usr/bin/m4 will
202#	generate output that will blow up the newer [f]lex/yacc/bison
203#	utilities.
204#
205
206# bootstrap-tool stage
207#
208BMAKEENV=	MAKEOBJDIRPREFIX=${BTOOLSDEST} \
209		OBJTREE=${OBJTREE} \
210		DESTDIR=${BTOOLSDEST} \
211		LC_ALL=C \
212		_SHLIBDIRPREFIX=${BTOOLSDEST} \
213		PATH=${BTOOLSPATH}:${PATH} \
214		M4=${BTOOLSDEST}/usr/bin/m4 \
215		INSTALL="sh ${.CURDIR}/tools/install.sh"
216
217BMAKE=		${BMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
218		-DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
219		-DNO_WERROR -DNO_NLS -DSYSBUILD
220
221# build-tool stage
222#
223TMAKEENV=	MAKEOBJDIRPREFIX=${BTOOLSDEST} \
224		OBJTREE=${OBJTREE} \
225		DESTDIR= \
226		LC_ALL=C \
227		PATH=${BTOOLSPATH}:${PATH} \
228		M4=${BTOOLSDEST}/usr/bin/m4 \
229		INSTALL="sh ${.CURDIR}/tools/install.sh"
230
231TMAKE=		${TMAKEENV} make -f Makefile.inc1 -DBOOTSTRAPPING \
232		-DNOSHARED -DSYSBUILD
233
234# cross-tool stage
235#
236# note: TOOLS_PREFIX points to the obj root holding the cross
237#	compiler binaries, while USRDATA_PREFIX points to the obj root
238#	holding the target environment (and also determines where cross-built
239#	libraries, crt*.o, and include files are installed).
240#
241XMAKEENV=	MAKEOBJDIRPREFIX=${CTOOLSDEST} \
242		OBJTREE=${OBJTREE} \
243		DESTDIR=${CTOOLSDEST} \
244		LC_ALL=C \
245		_SHLIBDIRPREFIX=${CTOOLSDEST} \
246		INSTALL="sh ${.CURDIR}/tools/install.sh" \
247		TOOLS_PREFIX=${CTOOLSDEST} \
248		USRDATA_PREFIX=${WORLDDEST} \
249		SELECT_LINKER=${WORLD_LDVER} \
250		M4=${BTOOLSDEST}/usr/bin/m4 \
251		PATH=${BTOOLSPATH}:${PATH}
252
253XMAKE=		${XMAKEENV} make -f Makefile.inc1 -DNO_GDB \
254		-DBOOTSTRAPPING -DNOMAN -DNOSHARED -DSYSBUILD
255
256# world stage, note the strict path and note that TOOLS_PREFIX is left
257# unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
258# which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
259# for both binary and library paths, even though it is being compiled to
260# WORLDDEST.  None of the programs in the world stage are ever actually
261# executed during the buildworld/installworld.
262#
263CROSSENV=	MAKEOBJDIRPREFIX=${WORLDDEST} \
264		OBJTREE=${OBJTREE} \
265		MACHINE_ARCH=${TARGET_ARCH} \
266		MACHINE=${TARGET} \
267		MACHINE_PLATFORM=${TARGET_PLATFORM} \
268		LC_ALL=C \
269		OBJFORMAT_PATH=${CTOOLSDEST} \
270		HOST_CCVER=${HOST_CCVER} \
271		CCVER=${WORLD_CCVER} \
272		LDVER=${WORLD_LDVER} \
273		BINUTILSVER=${WORLD_BINUTILSVER}
274
275WMAKEENV=	${CROSSENV} \
276		WORLDBUILD=1 \
277		DESTDIR=${WORLDDEST} \
278		_SHLIBDIRPREFIX=${WORLDDEST} \
279		INSTALL="sh ${.CURDIR}/tools/install.sh" \
280		M4=${BTOOLSDEST}/usr/bin/m4 \
281		PATH=${STRICTTMPPATH}
282
283WMAKE=		${WMAKEENV} make -f Makefile.inc1 -DSYSBUILD
284
285# install stage
286#
287IMAKEENV=	${CROSSENV} \
288		PATH=${STRICTTMPPATH}
289IMAKE=		${IMAKEENV} make -f Makefile.inc1 -DSYSBUILD
290
291# kernel stage
292#
293KMAKEENV=	${WMAKEENV}
294
295# buildworld
296#
297# Attempt to rebuild the entire system, with reasonable chance of
298# success, regardless of how old your existing system is.
299#
300_worldtmp: _cleantmp _mtreetmp
301.ORDER: _cleantmp _mtreetmp
302
303_cleantmp:
304.if !defined(NOCLEAN)
305	rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
306.else
307	# XXX - These two can depend on any header file.
308	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
309	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
310.endif
311
312_mtreetmp:
313	@echo
314	@echo "--------------------------------------------------------------"
315	@echo ">>> Rebuilding the temporary build tree"
316	@echo "--------------------------------------------------------------"
317	mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
318.for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
319	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist	\
320		-p ${_dir}/  > /dev/null
321	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist		\
322		-p ${_dir}/usr > /dev/null
323.endfor
324	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist	\
325		-p ${WORLDDEST}/usr/include > /dev/null
326	${LN} -sf ${.CURDIR}/sys ${WORLDDEST}
327
328_bwinit:
329	@echo "--------------------------------------------------------------"
330	@echo ">>> starting buildworld target"
331	@echo "--------------------------------------------------------------"
332_bootstrap-tools:
333	@echo
334	@echo "--------------------------------------------------------------"
335	@echo ">>> stage 1: bootstrap tools"
336	@echo "--------------------------------------------------------------"
337	cd ${.CURDIR}; ${BMAKE} bootstrap-tools
338_cleanobj:
339	@echo
340	@echo "--------------------------------------------------------------"
341	@echo ">>> stage 2a: cleaning up the object tree"
342	@echo "--------------------------------------------------------------"
343	cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
344_obj:
345	@echo
346	@echo "--------------------------------------------------------------"
347	@echo ">>> stage 2b: rebuilding the object tree"
348	@echo "--------------------------------------------------------------"
349	cd ${.CURDIR}; ${WMAKE} par-obj
350_build-tools:
351	@echo
352	@echo "--------------------------------------------------------------"
353	@echo ">>> stage 2c: build tools"
354	@echo "--------------------------------------------------------------"
355	cd ${.CURDIR}; ${TMAKE} build-tools
356_cross-tools:
357	@echo
358	@echo "--------------------------------------------------------------"
359	@echo ">>> stage 3: cross tools"
360	@echo "--------------------------------------------------------------"
361	cd ${.CURDIR}; ${XMAKE} cross-tools
362_includes:
363	@echo
364	@echo "--------------------------------------------------------------"
365	@echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
366	@echo "--------------------------------------------------------------"
367	cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
368_libraries:
369	@echo
370	@echo "--------------------------------------------------------------"
371	@echo ">>> stage 4b: building libraries"
372	@echo "--------------------------------------------------------------"
373	cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOMAN -DNOFSCHG libraries
374_depend:
375	@echo
376	@echo "--------------------------------------------------------------"
377	@echo ">>> stage 4c: make dependencies"
378	@echo "--------------------------------------------------------------"
379	cd ${.CURDIR}; ${WMAKE} par-depend
380everything:
381	@echo
382	@echo "--------------------------------------------------------------"
383	@echo ">>> stage 4d: building everything"
384	@echo "--------------------------------------------------------------"
385	cd ${.CURDIR}; ${WMAKE} all
386_initrd:
387	@echo
388	@echo "--------------------------------------------------------------"
389	@echo ">>> stage 5: building rescue and initrd"
390	@echo "--------------------------------------------------------------"
391.if !defined(NO_INITRD)
392	cd ${.CURDIR}/initrd; ${WMAKEENV} make all
393.endif
394_bwdone:
395	@echo "--------------------------------------------------------------"
396	@echo ">>> buildworld target complete"
397	@echo "--------------------------------------------------------------"
398_qwinit:
399	@echo "--------------------------------------------------------------"
400	@echo ">>> starting quickworld target"
401	@echo "--------------------------------------------------------------"
402_qwdone:
403	@echo "--------------------------------------------------------------"
404	@echo ">>> quickworld target complete"
405	@echo "--------------------------------------------------------------"
406_iwinit:
407	@echo "--------------------------------------------------------------"
408	@echo ">>> starting installworld target"
409	@echo "--------------------------------------------------------------"
410
411# note: buildworld no longer depends on _cleanobj because we rm -rf the
412# entire object tree and built the bootstrap tools in a different location.
413#
414# buildworld	- build everything from scratch
415# quickworld	- skip the bootstrap, build, and cross-build steps
416# realquickworld - skip the bootstrap, build, crossbuild, and depend step.
417#
418# note: we include _obj in realquickworld to prevent accidental creation
419# of files in /usr/src.
420
421WMAKE_TGTS=
422.if !defined(SUBDIR_OVERRIDE)
423WMAKE_TGTS+=	_worldtmp _bootstrap-tools
424.endif
425WMAKE_TGTS+=	_obj _build-tools
426.if !defined(SUBDIR_OVERRIDE)
427WMAKE_TGTS+=	_cross-tools
428.endif
429WMAKE_TGTS+=	_includes _libraries _depend everything _initrd
430
431.if defined(WMAKE_TGTS_OVERRIDE)
432SUBDIR=
433WMAKE_TGTS=	${WMAKE_TGTS_OVERRIDE}
434.endif
435
436QMAKE_TGTS=	_mtreetmp _obj _includes _libraries _depend everything _initrd
437
438buildworld: _bwinit ${WMAKE_TGTS} _bwdone
439
440quickworld: _qwinit ${QMAKE_TGTS} _qwdone
441
442realquickworld: _qwinit _mtreetmp _obj _includes _libraries everything _qwdone
443
444crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools
445
446GENLOGDIR=	/usr/obj${.CURDIR}
447.ORDER: build-all install-all
448
449# build-all
450#
451# build
452build-all:
453	@echo "Building world, log file in ${GENLOGDIR}/bw.out"
454	@mkdir -p ${GENLOGDIR}
455	@(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildworld > ${GENLOGDIR}/bw.out 2>&1)
456	@sync
457	@echo "Building kernel, log file in ${GENLOGDIR}/bk.out"
458	@(cd ${.CURDIR}; ${MAKE} -j `sysctl -n hw.ncpu` buildkernel > ${GENLOGDIR}/bk.out 2>&1)
459	@echo "build-all completed ok"
460	@sync
461
462install-all:
463	@echo "Installing kernel, log file in ${GENLOGDIR}/bk.out"
464	@mkdir -p ${GENLOGDIR}
465	@(cd ${.CURDIR}; ${MAKE} -j 1 installkernel >> ${GENLOGDIR}/bk.out 2>&1)
466	@sync
467	@echo "Installing world, log file in ${GENLOGDIR}/bw.out"
468	@(cd ${.CURDIR}; ${MAKE} -j 1 installworld >> ${GENLOGDIR}/bw.out 2>&1)
469	@sync
470	@echo "Upgrading world"
471	@(cd ${.CURDIR}; ${MAKE} -j 1 upgrade >> ${GENLOGDIR}/bw.out 2>&1)
472	@sync
473	@echo "install-all completed ok.  reboot recommended and after that, "
474	@echo "when doing a major upgrade, 'pkg upgrade -f' after rebooting"
475
476.ORDER: _bwinit ${WMAKE_TGTS} _bwdone
477.ORDER: _obj _includes
478.ORDER: _qwinit _mtreetmp _obj
479.ORDER: installcheck backupworld-auto
480.ORDER: everything _qwdone
481
482
483# installcheck
484#
485# Checks to be sure system is ready for installworld
486#
487installcheck: _iwinit
488.if !defined(OVERRIDE_CHECKS)
489.if !defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/"
490	@case `uname -r` in \
491	    1.2*|1.3-*|1.3.*|1.4.*|1.5.0-*|1.5.1-*|1.5.2-*|1.5.3-*) \
492		echo "You must upgrade your kernel to at least 1.5.4" \
493		     "and reboot before you can safely installworld," \
494		     "due to libc/system call ABI changes."; \
495		/usr/bin/false; \
496	esac
497	@case `uname -r` in \
498	    1.*|2.*|3.0*|3.1*|3.2*|3.3*|3.4*|3.5*|3.6*) \
499		echo "The system is too old for a normal installworld," \
500		     "you need to use 'installworld-force'."; \
501		/usr/bin/false; \
502	esac
503.endif
504.endif
505
506# installworld
507#
508# Backs up the current world if ${AUTO_BACKUP} is writable.
509# Installs everything compiled by a 'buildworld'.
510#
511installworld: installcheck
512.if !defined(NO_BACKUP)
513	-@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1
514	@cd ${.CURDIR}; \
515	    (touch ${AUTO_BACKUP}/.updating > /dev/null 2>&1 && \
516	     ${IMAKE} backupworld-auto) || \
517	    echo "Cannot write to ${AUTO_BACKUP} - world not backed up"
518.endif
519	cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}
520	${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc \
521	    ${DESTDIR}/etc/upgrade/
522	cd ${.CURDIR}; ${IMAKE} -DWORLDINSTALL os-release
523.if !defined(NO_INITRD)
524	cd ${.CURDIR}; ${IMAKE} -DWORLDINSTALL initrd
525.endif
526	sync
527	@echo "--------------------------------------------------------------"
528	@echo ">>> installworld target complete"
529	@echo "--------------------------------------------------------------"
530
531os-release:
532	@echo "NAME=DragonFly" > ${DESTDIR}/etc/os-release
533	@echo "VERSION=${OSREL}-SYNTH" >> ${DESTDIR}/etc/os-release
534	@echo "VERSION_ID=${OSREL}" >> ${DESTDIR}/etc/os-release
535	@echo "ID=dragonfly" >> ${DESTDIR}/etc/os-release
536	@echo "ANSI_COLOR=\"0;32\"" >> ${DESTDIR}/etc/os-release
537	@echo "PRETTY_NAME=\"DragonFlyBSD ${OSREL}-SYNTH\"" >> ${DESTDIR}/etc/os-release
538	@echo "CPE_NAME=\"cpe:/o:dragonflybsd:dragonfly:${OSREL}\"" >> ${DESTDIR}/etc/os-release
539	@echo "SUPPORT_URL=\"http://chat.efnet.org:9090/?nick=dflynick&channels=%23dragonflybsd&Login=Login\"" >> ${DESTDIR}/etc/os-release
540	@echo "HOME_URL=\"https://www.dragonflybsd.org/\"" >> ${DESTDIR}/etc/os-release
541	@echo "BUG_REPORT_URL=\"https://bugs.dragonflybsd.org/\"" >> ${DESTDIR}/etc/os-release
542	@echo "MACHINE_ARCH=${MACHINE_ARCH}" >> ${DESTDIR}/etc/os-release
543	@echo "MACHINE=${MACHINE}" >> ${DESTDIR}/etc/os-release
544	@echo "DFLYVERSION=${DFLYVERSION}" >> ${DESTDIR}/etc/os-release
545
546installworld-force:
547	@echo "Doing a forced installworld.  This will install to a temporary directory,"
548	@echo "then copy the main binaries and libraries with a static cpdup to ${DESTDIR}/"
549	@echo "and finally will issue a normal installworld."
550	@echo
551	@echo "Starting in 5 seconds.  ^C to abort."
552	@echo
553	sleep 1
554	rm -rf /usr/obj/temp > /dev/null 2>&1 || chflags -R noschg /usr/obj/temp
555	rm -rf /usr/obj/temp
556	mkdir -p /usr/obj/temp/cpdup/bin
557	(cd ${.CURDIR}/bin/cpdup; \
558		make clean && \
559		make obj && \
560		make clean && \
561		make CFLAGS=-static all install DESTDIR=/usr/obj/temp/cpdup NOMAN=TRUE)
562	@echo "XXXXXXXXX Installing to temporary XXXXXXXXX"
563	@sleep 1
564	(cd ${.CURDIR}; ${MAKE} installworld DESTDIR=/usr/obj/temp > /dev/null 2>&1)
565	@echo "XXXXXXXXX Blasting binaries and libraries XXXXXXXXX"
566	@sleep 1
567	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/bin /bin
568	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/sbin /sbin
569	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/lib /lib
570	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/bin /usr/bin
571	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/sbin /usr/sbin
572	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/lib /usr/lib
573	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/libexec /libexec
574	/usr/obj/temp/cpdup/bin/cpdup -i0 /usr/obj/temp/usr/libexec /usr/libexec
575	@echo "XXXXXXXXX Doing final installworld XXXXXXXX"
576	sleep 5
577	(cd ${.CURDIR}; ${MAKE} installworld OVERRIDE_CHECKS=TRUE)
578	(cd ${.CURDIR}; ${MAKE} upgrade OVERRIDE_CHECKS=TRUE)
579.if !defined(NO_INITRD)
580	(cd ${.CURDIR}; ${MAKE} initrd)
581.endif
582
583# reinstall
584#
585# If you have a build server, you can NFS mount the source and obj directories
586# and do a 'make reinstall' on the *client* to install new binaries from the
587# most recent server build.
588#
589reinstall:
590	@echo "--------------------------------------------------------------"
591	@echo ">>> Making hierarchy"
592	@echo "--------------------------------------------------------------"
593	cd ${.CURDIR}; make -f Makefile.inc1 hierarchy
594	@echo
595	@echo "--------------------------------------------------------------"
596	@echo ">>> Installing everything"
597	@echo "--------------------------------------------------------------"
598	cd ${.CURDIR}; make -f Makefile.inc1 install
599
600# initrd
601#
602# Install the rescue tools and the initrd image built by 'buildworld'.
603#
604initrd: .PHONY
605	(cd ${.CURDIR}/initrd; ${IMAKEENV} make install)
606
607
608# buildkernel, nativekernel, quickkernel, realquickkernel, and installkernel
609#
610# Which kernels to build and/or install is specified by setting
611# KERNCONF. If not defined an X86_64_GENERIC kernel is built/installed.
612# Only the existing (depending TARGET) config files are used
613# for building kernels and only the first of these is designated
614# as the one being installed.
615#
616# You can specify INSTALLSTRIPPED=1 if you wish the installed
617# kernel and modules to be stripped of its debug info (required
618# symbols are left intact).  You can specify INSTALLSTRIPPEDMODULES
619# if you only want to strip the modules of their debug info.  These
620# only apply if you have DEBUG=-g in your kernel config or make line.
621#
622# Note that we have to use TARGET instead of TARGET_ARCH when
623# we're in kernel-land. Since only TARGET_ARCH is (expected) to
624# be set to cross-build, we have to make sure TARGET is set
625# properly.
626
627.if !defined(KERNCONF) && defined(KERNEL)
628KERNCONF=	${KERNEL}
629KERNWARN=	yes
630.else
631# XXX makeshift fix to build the right kernel for the (target) architecture
632# We should configure this in the platform files somehow
633.if ${TARGET_ARCH} == "x86_64"
634KERNCONF?=	X86_64_GENERIC
635.endif
636.endif
637INSTKERNNAME?=	kernel
638
639KRNLSRCDIR=	${.CURDIR}/sys
640KRNLCONFDIR=	${KRNLSRCDIR}/config
641KRNLOBJDIR=	${OBJTREE}${KRNLSRCDIR}
642KERNCONFDIR?=	${KRNLCONFDIR}
643
644BUILDKERNELS=
645INSTALLKERNEL=
646.for _kernel in ${KERNCONF}
647.if exists(${KERNCONFDIR}/${_kernel})
648BUILDKERNELS+=	${_kernel}
649.if empty(INSTALLKERNEL)
650INSTALLKERNEL= ${_kernel}
651.endif
652.endif
653.endfor
654
655# kernel version numbers survive rm -rf
656#
657.for _kernel in ${BUILDKERNELS}
658.if exists(${KRNLOBJDIR}/${_kernel}/version)
659KERNEL_VERSION_${_kernel} != cat ${KRNLOBJDIR}/${_kernel}/version
660.endif
661.endfor
662
663# buildkernel
664#
665# Builds all kernels defined by BUILDKERNELS.
666#
667bk_tools:
668	@if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
669	    echo "You must buildworld before buildkernel.  If you wish"; \
670	    echo "to build a kernel using native tools, config it manually"; \
671	    echo "or use the nativekernel target if you are in a rush"; \
672	    /usr/bin/false; \
673	fi
674
675maybe_bk_tools:
676.for _kernel in ${BUILDKERNELS}
677	@if [ ! -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
678	    if [ ! -f ${WORLDDEST}/.libraries_done ]; then \
679		echo "The kernel was build using buildworld tools which no" ; \
680		echo "longer appear to exist, (real)quickkernel failed!" ; \
681		/usr/bin/false; \
682	    fi; \
683	fi
684.endfor
685
686bk_build_list:
687.if empty(BUILDKERNELS)
688	@echo ">>> ERROR: Missing kernel configuration file(s)."
689	@echo ">>> ${KERNCONF} not found in ${KERNCONFDIR}."
690	@false
691.endif
692
693bk_kernwarn:
694.if defined(KERNWARN)
695	@echo "--------------------------------------------------------------"
696	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
697	@echo "--------------------------------------------------------------"
698	@sleep 3
699.endif
700	@echo
701
702# The buildkernel target rebuilds the specified kernels from scratch
703# using the crossbuild tools generated by the last buildworld.  It is
704# the safest (but also the most time consuming) way to build a new kernel.
705#
706buildkernel:	bk_tools bk_build_list bk_kernwarn
707.for _kernel in ${BUILDKERNELS}
708	@echo "--------------------------------------------------------------"
709	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
710	@echo "--------------------------------------------------------------"
711	@echo "===> ${_kernel}"
712.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
713	rm -rf ${KRNLOBJDIR}/${_kernel}
714.else
715	@if [ -f ${KRNLOBJDIR}/${_kernel}/.nativekernel_run ]; then \
716		echo "YOU ARE REBUILDING WITH BUILDKERNEL, REMOVING OLD NATIVEKERNEL BUILD"; \
717		rm -rf ${KRNLOBJDIR}/${_kernel}; fi
718.endif
719	mkdir -p ${KRNLOBJDIR}
720.if !defined(NO_KERNELCONFIG)
721	cd ${KRNLCONFDIR}; \
722		PATH=${STRICTTMPPATH} \
723		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
724			${KERNCONFDIR}/${_kernel}
725.endif
726.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
727	echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
728.endif
729	touch ${KRNLOBJDIR}/${_kernel}/.buildkernel_run
730.if !defined(NO_KERNELDEPEND)
731	cd ${KRNLOBJDIR}/${_kernel}; \
732	    ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
733.endif
734	cd ${KRNLOBJDIR}/${_kernel}; \
735	    ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
736	@echo "--------------------------------------------------------------"
737	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
738	@echo "--------------------------------------------------------------"
739.endfor
740
741# The nativekernel target rebuilds the specified kernels from scratch
742# using the system's standard compiler rather than using the crossbuild
743# tools generated by the last buildworld.  This is fairly safe if your
744# system is reasonable up-to-date.
745#
746nativekernel:	bk_build_list bk_kernwarn
747.for _kernel in ${BUILDKERNELS}
748	@echo "--------------------------------------------------------------"
749	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
750	@echo "--------------------------------------------------------------"
751	@echo "===> ${_kernel}"
752.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
753	rm -rf ${KRNLOBJDIR}/${_kernel}
754.else
755	@if [ -f ${KRNLOBJDIR}/${_kernel}/.buildkernel_run ]; then \
756		echo "YOU ARE REBUILDING WITH NATIVEKERNEL, REMOVING OLD BUILDKERNEL BUILD"; \
757		rm -rf ${KRNLOBJDIR}/${_kernel}; fi
758.endif
759	mkdir -p ${KRNLOBJDIR}
760.if !defined(NO_KERNELCONFIG)
761	cd ${KRNLCONFDIR}; \
762		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
763			${KERNCONFDIR}/${_kernel}
764.endif
765.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN) && defined(KERNEL_VERSION_${_kernel})
766	echo ${KERNEL_VERSION_${_kernel}} > ${KRNLOBJDIR}/${_kernel}/version
767.endif
768	touch ${KRNLOBJDIR}/${_kernel}/.nativekernel_run
769.if !defined(NO_KERNELDEPEND)
770	cd ${KRNLOBJDIR}/${_kernel}; \
771	    make KERNEL=${INSTKERNNAME} depend
772.endif
773	cd ${KRNLOBJDIR}/${_kernel}; \
774	    make KERNEL=${INSTKERNNAME} all
775	@echo "--------------------------------------------------------------"
776	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
777	@echo "--------------------------------------------------------------"
778.endfor
779
780# The (real)quickkernel target rebuilds the specified kernels as quickly
781# as possible.  It will use the native tools or the buildworld cross tools
782# based on whether the kernel was originally generated via buildkernel or
783# nativekernel.  Config is rerun but the object hierarchy is not rebuilt.
784# realquickkernel skips the depend step (analogous to realquickworld).
785#
786quickkernel realquickkernel:	maybe_bk_tools bk_build_list bk_kernwarn
787.for _kernel in ${BUILDKERNELS}
788	@echo "--------------------------------------------------------------"
789	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
790	@echo "--------------------------------------------------------------"
791	@echo "===> ${_kernel}"
792.if exists(${KRNLOBJDIR}/${_kernel}/.buildkernel_run)
793.if !defined(NO_KERNELCONFIG)
794	cd ${KRNLCONFDIR}; \
795		PATH=${STRICTTMPPATH} \
796		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
797			${KERNCONFDIR}/${_kernel}
798.endif
799.if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
800	cd ${KRNLOBJDIR}/${_kernel}; \
801	    ${KMAKEENV} make KERNEL=${INSTKERNNAME} depend
802.endif
803	cd ${KRNLOBJDIR}/${_kernel}; \
804	    ${KMAKEENV} make KERNEL=${INSTKERNNAME} all
805.else
806.if !defined(NO_KERNELCONFIG)
807	cd ${KRNLCONFDIR}; \
808	    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
809		${KERNCONFDIR}/${_kernel}
810.endif
811.if !defined(NO_KERNELDEPEND) && !make(realquickkernel)
812	cd ${KRNLOBJDIR}/${_kernel}; \
813	    make KERNEL=${INSTKERNNAME} depend
814.endif
815	cd ${KRNLOBJDIR}/${_kernel}; \
816	    make KERNEL=${INSTKERNNAME} all
817.endif
818	@echo "--------------------------------------------------------------"
819	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
820	@echo "--------------------------------------------------------------"
821.endfor
822
823
824# installkernel
825#
826# Install the kernel defined by INSTALLKERNEL
827#
828installkernel reinstallkernel:
829	@echo "--------------------------------------------------------------"
830	@echo ">>> Kernel install for ${INSTALLKERNEL} started on `LC_ALL=C date`"
831	@echo "--------------------------------------------------------------"
832.if exists(${KRNLOBJDIR}/${INSTALLKERNEL}/.buildkernel_run)
833	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
834	    ${IMAKEENV} make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
835.else
836	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
837	    make KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}
838.endif
839	@echo "--------------------------------------------------------------"
840	@echo ">>> Kernel install for ${INSTALLKERNEL} completed on `LC_ALL=C date`"
841	@echo "--------------------------------------------------------------"
842
843
844# ------------------------------------------------------------------------
845#
846# From here onwards are utility targets used by the 'make world' and
847# related targets.  If your 'world' breaks, you may like to try to fix
848# the problem and manually run the following targets to attempt to
849# complete the build.  Beware, this is *not* guaranteed to work, you
850# need to have a pretty good grip on the current state of the system
851# to attempt to manually finish it.  If in doubt, 'make world' again.
852#
853
854# bootstrap-tools: Build all tools required to build all tools.  Note that
855# order is important in a number of cases and also note that the bootstrap
856# and build tools stages have access to earlier binaries they themselves
857# had generated.
858#
859# [x]install:	dependencies on various new install features
860# rpcgen:	old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
861#		envs are not compatible with older objformat binaries.
862#
863
864# BSTRAPDIRS1 - must be built in strict order, no parallelism
865#
866# order is very important. yacc before m4 before flex.  flex exec's m4,
867# m4's parser file needs the latest byacc (insanity!).
868#
869BSTRAPDIRS1= \
870	bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo \
871	bin/test bin/cat bin/ln bin/mv bin/expr bin/sh \
872	bin/hostname bin/kill \
873	usr.bin/yacc usr.bin/m4 usr.bin/localedef \
874	usr.bin/uudecode usr.bin/xinstall \
875	usr.bin/rpcgen usr.bin/bmake usr.bin/awk usr.bin/stat \
876	usr.bin/find usr.bin/flex
877
878# BSTRAPDIRS2 - may built in parallel
879#
880BSTRAPDIRS2= \
881	usr.bin/sed usr.bin/uname usr.bin/touch \
882	usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
883	usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
884	usr.bin/gencat usr.bin/chflags \
885	usr.bin/uuencode usr.bin/cap_mkdb usr.bin/true usr.bin/false \
886	usr.bin/cmp usr.bin/xargs usr.bin/env usr.bin/dirname \
887	usr.bin/tail usr.bin/unifdef \
888	usr.sbin/chown usr.sbin/mtree usr.sbin/config \
889	usr.sbin/tzsetup usr.sbin/zic usr.sbin/pwd_mkdb \
890	gnu/usr.bin/grep usr.bin/sort usr.bin/gzip \
891	usr.bin/mkcsmapper usr.bin/mkesdb usr.bin/crunch
892
893bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
894	touch ${BTOOLSDEST}/.bootstrap_done
895
896bootstrap-tools-before:
897	${LN} -fs /bin/date ${BTOOLSDEST}/bin/date
898
899bootstrap-tools-targets1: ${BSTRAPDIRS1:S/^/bstrap-/}
900
901bootstrap-tools-targets2: ${BSTRAPDIRS2:S/^/bstrap-/}
902
903.ORDER: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2
904
905.ORDER: ${BSTRAPDIRS1:S/^/bstrap-/}
906
907.for _tool in ${BSTRAPDIRS1} ${BSTRAPDIRS2}
908bstrap-${_tool}!
909	${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
910		cd ${.CURDIR}/${_tool}; \
911		make DIRPRFX=${_tool}/ obj && \
912		make DIRPRFX=${_tool}/ depend && \
913		make DIRPRFX=${_tool}/ all && \
914		make DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
915.endfor
916
917# build-tools: Build special purpose build tools.
918#
919# XXX we may be able to remove or consolidate this into bootstrap-tools
920# now that we have the native helper (.nx/.no) infrastructure.
921#
922# XXX we should separate this into new Makefile.inc2.
923# Just to prepare for reduction of ORDER: that slows down parallel crossworld.
924
925# Make sure Makefile.inc1 logic is intact.
926.if !defined(WORLD_ALTCOMPILER)
927.warning undefined WORLD_ALTCOMPILER
928.endif
929
930# gcc80 is now the default compiler.  See sys.mk for WORLD_ALTCOMPILER default
931# and this file for WORLD_CCVER.
932#
933_gcc47_cross= gnu/usr.bin/cc47
934_gcc80_cross= gnu/usr.bin/cc80
935_gcc_common_cross= lib/libz gnu/usr.bin/gmp gnu/usr.bin/mpfr gnu/usr.bin/mpc
936
937.if !defined(NO_ALTCOMPILER)
938. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
939_altcompiler_cross+= ${_gcc47_cross}
940. endif
941.endif
942
943_basecompiler_cross= ${_gcc80_cross}
944
945_custom_cross= libexec/customcc
946_binutils= gnu/usr.bin/${WORLD_BINUTILSVER}
947
948build-tools: build-tools-targets
949	touch ${BTOOLSDEST}/.build_done
950
951build-tools-targets: ${BTOOLSDIRS:S/^/btools-/}
952
953#
954# cross-tools: Build cross-building tools
955#
956
957CTOOLSDIRS= usr.bin/objformat
958
959CTOOLSDIRS+=	${_binutils} \
960		${_gcc_common_cross} \
961		${_altcompiler_cross} \
962		${_basecompiler_cross} ${_custom_cross}
963
964cross-tools: cross-tools-targets
965	touch ${CTOOLSDEST}/.cross_done
966
967cross-tools-targets: ${CTOOLSDIRS:S/^/ctools-/}
968
969.for _tool in ${CTOOLSDIRS}
970ctools-${_tool}!
971	${ECHODIR} "===> ${_tool} (cross-tools)"; \
972		cd ${.CURDIR}/${_tool}; \
973		make DIRPRFX=${_tool}/ obj && \
974		make DIRPRFX=${_tool}/ depend && \
975		make DIRPRFX=${_tool}/ all && \
976		make DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
977.endfor
978
979#
980# hierarchy - ensure that all the needed directories are present
981#
982hierarchy:
983	cd ${.CURDIR}/etc;		make distrib-dirs
984
985#
986# libraries - build all libraries, and install them under ${DESTDIR}.
987#
988# The list of libraries with dependents (${_prebuild_libs}) and their
989# interdependencies (__L) are built automatically by the
990# ${.CURDIR}/tools/make_libdeps.sh script.
991#
992# .makeenv does not work when bootstrapping from 4.x, so we must be sure
993# to specify the correct CCVER or 'cc' will not exec the correct compiler.
994#
995libraries:
996	cd ${.CURDIR}; \
997	    HOST_CCVER=${HOST_CCVER} CCVER=gcc80 \
998		make -f Makefile.inc1 _startup_libs80 -DSYSBUILD -DLIBGCC_ONLY;
999.if !defined(NO_ALTCOMPILER)
1000. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1001	cd ${.CURDIR}; \
1002	    HOST_CCVER=${HOST_CCVER} CCVER=gcc47 \
1003		make -f Makefile.inc1 _startup_libs47 -DSYSBUILD -DLIBGCC_ONLY;
1004. endif
1005.endif
1006	cd ${.CURDIR}; \
1007	    make -f Makefile.inc1 _startup_libs -DSYSBUILD && \
1008	    make -f Makefile.inc1 _prebuild_libs -DSYSBUILD && \
1009	    make -f Makefile.inc1 _generic_libs -DSYSBUILD && \
1010	    touch ${WORLDDEST}/.libraries_done
1011
1012# These dependencies are not automatically generated:
1013#
1014# gnu/lib/${CCVER}/libgcc and gnu/lib/${CCVER}/csu must be built before all
1015# shared libraries for ELF.  The target for _startup_libsXX is
1016# specifically built using gccXX.
1017#
1018_startup_libs47=	gnu/usr.bin/cc47/cc_prep \
1019			gnu/usr.bin/cc47/cc_tools \
1020			gnu/lib/gcc47/csu \
1021			gnu/lib/gcc47/libgcc \
1022			gnu/lib/gcc47/libgcc_eh \
1023			gnu/lib/gcc47/libgcc_pic
1024
1025_startup_libs80=	gnu/usr.bin/cc80/cc_prep \
1026			gnu/usr.bin/cc80/cc_tools \
1027			gnu/lib/gcc80/csu \
1028			gnu/lib/gcc80/libgcc \
1029			gnu/lib/gcc80/libgcc_eh \
1030			gnu/lib/gcc80/libgcc_pic
1031
1032.if !defined(NO_ALTCOMPILER)
1033. if defined(WORLD_ALTCOMPILER) && (${WORLD_ALTCOMPILER} == "all" || ${WORLD_ALTCOMPILER:Mgcc47})
1034_startup_libs_alt+=	_startup_libs47
1035. endif
1036.endif
1037
1038_startup_libs_base=	_startup_libs80
1039
1040_startup_libs=		lib/csu lib/libc lib/libc_rtld
1041lib/libc__L: lib/csu__L
1042
1043_prebuild_libs=		lib/libbz2 lib/liblzma lib/libz lib/libzstd
1044_prebuild_libs+=	lib/libutil
1045
1046_prebuild_libs+=	lib/libpcap
1047
1048_generic_libs=	gnu/lib
1049
1050_prebuild_libs+= lib/libcrypt lib/libncurses/libncurses
1051
1052_generic_libs+=	lib
1053
1054_prebuild_libs+=	lib/librecrypto lib/libressl
1055lib/libressl__L: lib/librecrypto__L
1056
1057_prebuild_libs+=       lib/libldns
1058lib/libldns__L: lib/librecrypto__L
1059
1060_prebuild_libs+= lib/libsbuf lib/libm \
1061		lib/libpam/libpam lib/libypclnt lib/lib${THREAD_LIB} \
1062		lib/libpthread lib/libprop
1063
1064_generic_libs+=	usr.bin/flex/lib
1065
1066.for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1067__startup_alibs+= ${${_alib}}
1068.endfor
1069
1070.for _lib in ${__startup_alibs} \
1071		${_startup_libs} ${_prebuild_libs} ${_generic_libs}
1072${_lib}__L: .PHONY
1073.if exists(${.CURDIR}/${_lib})
1074	@${ECHODIR} "===> ${_lib}"; \
1075		cd ${.CURDIR}/${_lib}; \
1076		echo "STEP DEP ${_lib}" && \
1077		make DIRPRFX=${_lib}/ depend && \
1078		echo "STEP ALL ${_lib}" && \
1079		make DIRPRFX=${_lib}/ all && \
1080		echo "STEP INSTALL ${_lib}" && \
1081		make DIRPRFX=${_lib}/ install && \
1082		echo "STEP DONE ${_lib}";
1083.else
1084.warning missing ${.CURDIR}/${_lib} directory.
1085.endif
1086.endfor
1087
1088_startup_libs: ${_startup_libs:S/$/__L/}
1089.for _alib in ${_startup_libs_alt} ${_startup_libs_base}
1090${_alib}: ${${_alib}:C/$/__L/}
1091.endfor
1092_prebuild_libs: ${_prebuild_libs:S/$/__L/}
1093_generic_libs: ${_generic_libs:S/$/__L/}
1094
1095# library targets must be ordered because there are inter-library
1096# races (e.g. generation of tconfig.h)
1097#
1098.for _alib in ${_startup_libs_base} ${_startup_libs_alt}
1099.ORDER: ${${_alib}:C/$/__L/}
1100.endfor
1101
1102# uncomment if there are missing dependencies
1103.if 0
1104.ORDER: ${_prebuild_libs:S/$/__L/}
1105# we can disable this one, no lib/* depend on libstdc++
1106.ORDER: ${_generic_libs:S/$/__L/}
1107.endif
1108
1109.for __target in clean cleandepend cleandir obj depend includes
1110.for entry in ${SUBDIR}
1111${entry}.${__target}__D: .PHONY
1112	@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
1113		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
1114		edir=${entry}.${MACHINE_ARCH}; \
1115		cd ${.CURDIR}/$${edir}; \
1116	else \
1117		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
1118		edir=${entry}; \
1119		cd ${.CURDIR}/$${edir}; \
1120	fi; \
1121	make ${__target} DIRPRFX=${DIRPRFX}$${edir}/
1122.endfor
1123par-${__target}: ${SUBDIR:C/$/.${__target}__D/}
1124.ORDER: ${SUBDIR:C/$/.${__target}__D/}
1125.endfor
1126.ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes
1127
1128# The wmake target is used by /usr/bin/wmake to run make in a
1129# world build environment.
1130#
1131wmake:
1132	@echo '${WMAKEENV} make ${WMAKE_ARGS} -DSYSBUILD'
1133
1134wmakeenv:
1135	@echo '${WMAKEENV} /bin/sh'
1136
1137bmake:
1138	@echo '${BMAKEENV} make ${BMAKE_ARGS} -DSYSBUILD'
1139
1140bmakeenv:
1141	@echo '${BMAKEENV} /bin/sh'
1142
1143tmake:
1144	@echo '${TMAKEENV} make ${TMAKE_ARGS} -DSYSBUILD'
1145
1146tmakeenv:
1147	@echo '${TMAKEENV} /bin/sh'
1148
1149xmake:
1150	@echo '${XMAKEENV} make ${XMAKE_ARGS} -DSYSBUILD'
1151
1152xmakeenv:
1153	@echo '${XMAKEENV} /bin/sh'
1154
1155.if !defined(NO_BACKUP)
1156backupworld: backup-clean
1157	@mkdir -p ${WORLD_BACKUP}
1158.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1159     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1160     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1161	tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1162		--options gzip:compression-level=1 \
1163		sbin bin usr/sbin usr/bin usr/lib usr/libexec
1164.endif
1165
1166backupworld-auto:
1167	rm -f ${AUTO_BACKUP}/binaries.tar.gz
1168	@mkdir -p ${AUTO_BACKUP}
1169.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \
1170     exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \
1171     exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec))
1172	/usr/bin/tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \
1173		--options gzip:compression-level=1 \
1174		sbin bin usr/sbin usr/bin usr/lib usr/libexec
1175.endif
1176
1177backup-auto-clean:
1178	rm -f ${AUTO_BACKUP}/binaries.tar.gz
1179
1180backup-clean:
1181	rm -f ${WORLD_BACKUP}/binaries.tar.gz
1182
1183restoreworld:
1184.if !exists(${WORLD_BACKUP}/binaries.tar.gz)
1185	@echo "There does not seem to be a valid archive present."
1186.else
1187	@echo "Restoring system binaries from manual backup archive..."
1188	@chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1189		${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1190		${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1191	tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1192.endif
1193
1194restoreworld-auto:
1195.if !exists(${AUTO_BACKUP}/binaries.tar.gz)
1196	@echo "There does not seem to be a valid archive present."
1197.else
1198	@echo "Restoring system binaries from auto-backup archive..."
1199	@chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \
1200		${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \
1201		${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec
1202	tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/
1203.endif
1204.endif
1205
1206# Take advantage of bmake error response
1207#
1208MAKE_PRINT_VAR_ON_ERROR= \
1209	.CURDIR \
1210	.OBJDIR \
1211	.TARGETS \
1212	.ERROR_TARGET \
1213	.MAKE.LEVEL \
1214	.MAKE.MODE \
1215	PATH \
1216	LD_LIBRARY_PATH \
1217	MACHINE_ARCH \
1218	MACHINE \
1219	MAKEFILE \
1220	MAKESYSPATH \
1221	MAKEOBJDIRPREFIX \
1222	WORLD_ALTCOMPILER \
1223	DESTDIR \
1224	SHELL .SHELL
1225.if ${.MAKE.LEVEL} > 0
1226MAKE_PRINT_VAR_ON_ERROR+= .MAKE.MAKEFILES .PATH
1227.endif
1228
1229.include <bsd.subdir.mk>
1230