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