File:  [DragonFly] / src / Makefile.inc1
Revision 1.24: download - view: text, annotated - select for diffs
Mon Mar 22 23:49:05 2004 UTC (10 years, 4 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
buildworld subsystem update addendum.  Hopefully fix buildkernel,
and fix the GROFF/TROFF environment paths (should solve an infinite loop
occuring in troff when building from FreeBSD-4.x).

#
# $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $
# $DragonFly: src/Makefile.inc1,v 1.24 2004/03/22 23:49:05 dillon Exp $
#
# Make command line options:
#	-DMAKE_KERBEROS5 to build Kerberos5
#	-DNOCLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
#	-DNOCLEAN do not clean at all
#	-DNOCRYPT will prevent building of crypt versions
#	-DNOMAN do not build the manual pages
#	-DNOPROFILE do not build profiled libraries
#	-DNOGAMES do not go into games subdir
#	-DNOSHARE do not go into share subdir
#	-DNOINFO do not make or install info files
#	-DNOLIBC_R do not build libc_r.
#	-DNO_FORTRAN do not build g77 and related libraries.
#	-DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
#	-DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel
#	-DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
#	-DNO_PORTSUPDATE do not update ports in ${MAKE} update
#	-DNO_DOCUPDATE do not update doc in ${MAKE} update
#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
#	TARGET_ARCH="arch" to crossbuild world to a different arch
#
# The intended user-driven targets are:
#
# buildworld  - rebuild *everything*, including glue to help do upgrades
# quickworld  - skip the glue and do a depend+build on the meat
# realquickworld - skip the glue and depend stages and just build the meat
# crossworld  - only build the glue (particularly the cross-build environment)
# installworld- install everything built by "buildworld"
# update      - convenient way to update your source tree (eg: sup/cvs)
# most        - build user commands, no libraries or include files
# installmost - install user commands, no libraries or include files
#
# Standard targets (not defined here) are documented in the makefiles in
# /usr/share/mk.  These include:
#		obj depend all install clean cleandepend cleanobj

# Put initial settings here.
SUBDIR=

# We must do share/info early so that installation of info `dir'
# entries works correctly.  Do it first since it is less likely to
# grow dependencies on include and lib than vice versa.
.if exists(${.CURDIR}/share/info)
SUBDIR+= share/info
.endif

# We must do include and lib early so that the perl *.ph generation
# works correctly as it uses the header files installed by this.
.if exists(${.CURDIR}/include)
SUBDIR+= include
.endif
.if exists(${.CURDIR}/lib)
SUBDIR+= lib
.endif
# This exists simply to ensure that the obj dir hierarchy is
# intact for nrelease, allowing the nrelease Makefile's to 
# reference ${.OBJDIR}.
#
.if exists(${.CURDIR}/nrelease)
SUBDIR+= nrelease
.endif

.if exists(${.CURDIR}/bin)
SUBDIR+= bin
.endif
.if exists(${.CURDIR}/games) && !defined(NOGAMES)
SUBDIR+= games
.endif
.if exists(${.CURDIR}/gnu)
SUBDIR+= gnu
.endif
.if exists(${.CURDIR}/kerberos5) && exists(${.CURDIR}/crypto) && \
    !defined(NOCRYPT) && !defined(NO_OPENSSL) && defined(MAKE_KERBEROS5)
SUBDIR+= kerberos5
.endif
.if exists(${.CURDIR}/libexec)
SUBDIR+= libexec
.endif
.if exists(${.CURDIR}/sbin)
SUBDIR+= sbin
.endif
.if exists(${.CURDIR}/secure) && !defined(NOCRYPT)
SUBDIR+= secure
.endif
.if exists(${.CURDIR}/share) && !defined(NOSHARE)
SUBDIR+= share
.endif
.if exists(${.CURDIR}/sys)
SUBDIR+= sys
.endif
.if exists(${.CURDIR}/usr.bin)
SUBDIR+= usr.bin
.endif
.if exists(${.CURDIR}/usr.sbin)
SUBDIR+= usr.sbin
.endif

# etc must be last for "distribute" to work
.if exists(${.CURDIR}/etc)
SUBDIR+= etc
.endif

# These are last, since it is nice to at least get the base system
# rebuilt before you do them.
.if defined(LOCAL_DIRS)
.for _DIR in ${LOCAL_DIRS}
.if exists(${.CURDIR}/${_DIR}) & exists(${.CURDIR}/${_DIR}/Makefile)
SUBDIR+= ${_DIR}
.endif
.endfor
.endif

.if defined(SUBDIR_OVERRIDE)
SUBDIR=		${SUBDIR_OVERRIDE}
.endif

.if defined(NOCLEANDIR)
CLEANDIR=	clean cleandepend
.else
CLEANDIR=	cleandir
.endif

SUP?=		/usr/local/bin/cvsup
SUPFLAGS?=	-g -L 2 -P -
.if defined(SUPHOST)
SUPFLAGS+=	-h ${SUPHOST}
.endif

# Object directory base in primary make.  Note that when we rerun make
# from inside this file we change MAKEOBJDIRPREFIX to the appropriate
# subdirectory because the rest of the build system needs it that way.
# The original object directory base is saved in OBJTREE.
#
MAKEOBJDIRPREFIX?=	/usr/obj
OBJTREE?=		${MAKEOBJDIRPREFIX}

# Used for stage installs and pathing
#
DESTDIRBASE?=		${OBJTREE}${.CURDIR}

TARGET_ARCH?=	${MACHINE_ARCH}
.if ${TARGET_ARCH} == ${MACHINE_ARCH}
TARGET?=	${MACHINE}
.else
TARGET?=	${TARGET_ARCH}
.endif
.if make(buildworld)
BUILD_ARCH!=	sysctl -n hw.machine_arch
.if ${MACHINE_ARCH} != ${BUILD_ARCH}
.error To cross-build, set TARGET_ARCH.
.endif
.endif

# BTOOLS	(Natively built) All non-cross-development tools that the
#		main build needs.  This includes things like 'mkdir' and 'rm'.
#		We will not use the native system's exec path once we start
#		on WORLD.  (bootstrap-tools and build-tools or BTOOLS)
#
# CTOOLS	(Natively built) Cross development tools which are specific
#		to the target architecture.
#
# WORLD		(Cross built) Our ultimate buildworld, using only BTOOLS and
#		CTOOLS.
#
# MACHINE_ARCH	Architecture we are building on
# TARGET_ARCH	Architecture we are building for
#
BTOOLSDEST=	${DESTDIRBASE}/btools_${MACHINE_ARCH}
CTOOLSDEST=	${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH}
WORLDDEST=	${DESTDIRBASE}/world_${TARGET_ARCH}

# The strict temporary command path contains all binaries required
# by the buildworld system after the cross-tools stage.
#
STRICTTMPPATH=	${CTOOLSDEST}/usr/sbin:${CTOOLSDEST}/usr/bin:${CTOOLSDEST}/bin:${CTOOLSDEST}/usr/games:${BTOOLSDEST}/usr/sbin:${BTOOLSDEST}/usr/bin:${BTOOLSDEST}/bin:${BTOOLSDEST}/usr/games

TMPDIR?=	/tmp
TMPPID!=	echo $$$$

#
# Building a world goes through the following stages
#
# 1. bootstrap-tool stage [BMAKE]
#	This stage is responsible for creating programs that
#	are needed for backward compatibility reasons. They
#	are not built as cross-tools.
# 2. build-tool stage [TMAKE]
#	This stage is responsible for creating the object
#	tree and building any tools that are needed during
#	the build process.
# 3. cross-tool stage [XMAKE]
#	This stage is responsible for creating any tools that
#	are needed for cross-builds. A cross-compiler is one
#	of them.
# 4. world stage [WMAKE]
#	This stage actually builds the world.
# 5. install stage (optional) [IMAKE]
#	This stage installs a previously built world.
#

# bootstrap-tool stage
#
BMAKEENV=	MAKEOBJDIRPREFIX=${BTOOLSDEST} \
		OBJTREE=${OBJTREE} \
		DESTDIR= \
		INSTALL="sh ${.CURDIR}/tools/install.sh"

BMAKE=		${BMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
		-DNOHTML -DNOINFO -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED \
		-DNO_WERROR

# build-tool stage
#
TMAKEENV=	MAKEOBJDIRPREFIX=${BTOOLSDEST} \
		OBJTREE=${OBJTREE} \
		DESTDIR= \
		INSTALL="sh ${.CURDIR}/tools/install.sh"

TMAKE=		${TMAKEENV} ${MAKE} -f Makefile.inc1 -DBOOTSTRAPPING \
		-DNO_FORTRAN

# cross-tool stage
#
# note: TOOLS_PREFIX points to the obj root holding the cross
#	compiler binaries, while INCS_PREFIX points to the obj root holding
#	the target environment (and also determines where cross-built
#	libraries and crt*.o are installed).
#
XMAKEENV=	MAKEOBJDIRPREFIX=${CTOOLSDEST} \
		OBJTREE=${OBJTREE} \
		DESTDIR=${CTOOLSDEST} \
		INSTALL="sh ${.CURDIR}/tools/install.sh" \
		TOOLS_PREFIX=${CTOOLSDEST} \
		USRDATA_PREFIX=${WORLDDEST}

XMAKE=		${XMAKEENV} ${MAKE} -f Makefile.inc1 -DNO_FORTRAN -DNO_GDB

# world stage, note the strict path and note that TOOLS_PREFIX is left
# unset and USRDATA_PREFIX (which defaults to TOOLS_PREFIX) is set to empty,
# which is primarily for the compiler so it targets / (e.g. /usr/<blah>)
# for both binary and library paths, even though it is being compiled to
# WORLDDEST.  None of the programs in the world stage are ever actually
# executed during the buildworld/installworld.
#
CROSSENV=	MAKEOBJDIRPREFIX=${WORLDDEST} \
		OBJTREE=${OBJTREE} \
		MACHINE_ARCH=${TARGET_ARCH} \
		MACHINE=${TARGET} \
		OBJFORMAT_PATH=${CTOOLSDEST} \
		PERL5LIB=${WORLDDEST}/usr/libdata/perl/5.00503 \
		GROFF_BIN_PATH=${BTOOLSDEST}/usr/bin \
		GROFF_FONT_PATH=${BTOOLSDEST}/usr/share/groff_font \
		GROFF_TMAC_PATH=${BTOOLSDEST}/usr/share/tmac

WMAKEENV=	${CROSSENV} \
		DESTDIR=${WORLDDEST} \
		INSTALL="sh ${.CURDIR}/tools/install.sh" \
		PATH=${STRICTTMPPATH}

WMAKE=		${WMAKEENV} ${MAKE} -f Makefile.inc1

# install stage
IMAKEENV=	${CROSSENV} \
		PATH=${STRICTTMPPATH}
IMAKE=		${IMAKEENV} ${MAKE} -f Makefile.inc1

# kernel stage
KMAKEENV=	${WMAKEENV} \
		OBJFORMAT_PATH=${WORLDDEST}:${OBJFORMAT_PATH}

# buildworld
#
# Attempt to rebuild the entire system, with reasonable chance of
# success, regardless of how old your existing system is.
#
_worldtmp:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> Rebuilding the temporary build tree"
	@echo "--------------------------------------------------------------"
.if !defined(NOCLEAN)
	rm -rf ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
.else
	# XXX - These two can depend on any header file.
	rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c
	rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
.endif
	mkdir -p ${DESTDIRBASE} ${BTOOLSDEST} ${CTOOLSDEST} ${WORLDDEST}
.for _dir in ${WORLDDEST} ${BTOOLSDEST} ${CTOOLSDEST}
	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist	\
		-p ${_dir}/  > /dev/null
	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist		\
		-p ${_dir}/usr > /dev/null
.endfor
	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist	\
		-p ${WORLDDEST}/usr/include > /dev/null
	ln -sf ${.CURDIR}/sys ${WORLDDEST}

_bootstrap-tools:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 1: bootstrap tools"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${BMAKE} bootstrap-tools
_cleanobj:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 2a: cleaning up the object tree"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/}
_obj:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 2b: rebuilding the object tree"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} par-obj
_build-tools:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 2c: build tools"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${TMAKE} build-tools
_cross-tools:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 3: cross tools"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${XMAKE} cross-tools
_includes:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 4a: populating ${WORLDDEST}/usr/include"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes
_libraries:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 4b: building libraries"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} -DNOHTML -DNOINFO -DNOMAN -DNOFSCHG libraries
_depend:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 4c: make dependencies"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} par-depend
everything:
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> stage 4d: building everything.."
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${WMAKE} all

# note: buildworld no longer depends on _cleanobj because we rm -rf the
# entire object tree and built the bootstrap tools in a different location.
#
# buildworld	- build everything from scratch
# quickworld	- skip the bootstrap, build, and cross-build steps
# realquickworld - skip the bootstrap, build, crossbuild, and depend step.
#
# note: we include _obj in realquickworld to prevent accidental creation
# of files in /usr/src.

WMAKE_TGTS=
.if !defined(SUBDIR_OVERRIDE)
WMAKE_TGTS+=	_worldtmp _bootstrap-tools
.endif
WMAKE_TGTS+=	_obj _build-tools
.if !defined(SUBDIR_OVERRIDE)
WMAKE_TGTS+=	_cross-tools
.endif
WMAKE_TGTS+=	_includes _libraries _depend everything

buildworld: ${WMAKE_TGTS}

quickworld: _obj _includes _libraries _depend everything

realquickworld: _obj _includes _libraries everything

crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools

.ORDER: ${WMAKE_TGTS}

#
# installcheck
#
# Checks to be sure system is ready for installworld
#
installcheck:
.if !defined(NO_SENDMAIL)
	@if ! `id -u smmsp > /dev/null`; then \
		echo "ERROR: Required smmsp user is missing, see /usr/src/UPDATING."; \
		false; \
	fi
	@if ! `id -g smmsp > /dev/null`; then \
		echo "ERROR: Required smmsp group is missing, see /usr/src/UPDATING."; \
		false; \
	fi
.endif

#
# distributeworld
#
# Distributes everything compiled by a `buildworld'.
#
# installworld
#
# Installs everything compiled by a 'buildworld'.
#
distributeworld installworld: installcheck
	cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}

#
# reinstall
#
# If you have a build server, you can NFS mount the source and obj directories
# and do a 'make reinstall' on the *client* to install new binaries from the
# most recent server build.
#
reinstall:
	@echo "--------------------------------------------------------------"
	@echo ">>> Making hierarchy"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> Installing everything.."
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
.if !defined(NOMAN) && !defined(NO_MAKEDB_RUN)
	@echo
	@echo "--------------------------------------------------------------"
	@echo ">>> Rebuilding man page indices"
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}/share/man; ${MAKE} makedb
.endif

redistribute:
	@echo "--------------------------------------------------------------"
	@echo ">>> Distributing everything.."
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute

#
# buildkernel and installkernel
#
# Which kernels to build and/or install is specified by setting
# KERNCONF. If not defined a GENERIC kernel is built/installed.
# Only the existing (depending TARGET) config files are used
# for building kernels and only the first of these is designated
# as the one being installed.
#
# Note that we have to use TARGET instead of TARGET_ARCH when
# we're in kernel-land. Since only TARGET_ARCH is (expected) to
# be set to cross-build, we have to make sure TARGET is set
# properly.

.if !defined(KERNCONF) && defined(KERNEL)
KERNCONF=	${KERNEL}
KERNWARN=	yes
.else
KERNCONF?=	GENERIC
.endif
INSTKERNNAME?=	kernel

KRNLSRCDIR=	${.CURDIR}/sys
KRNLCONFDIR=	${KRNLSRCDIR}/${TARGET}/conf
KRNLOBJDIR=	${OBJTREE}${KRNLSRCDIR}
KERNCONFDIR?=	${KRNLCONFDIR}

BUILDKERNELS=
INSTALLKERNEL=
.for _kernel in ${KERNCONF}
.if exists(${KERNCONFDIR}/${_kernel})
BUILDKERNELS+=	${_kernel}
.if empty(INSTALLKERNEL)
INSTALLKERNEL= ${_kernel}
.endif
.endif
.endfor

#
# buildkernel
#
# Builds all kernels defined by BUILDKERNELS.
#
buildkernel:
.if empty(BUILDKERNELS)
	@echo ">>> ERROR: Missing kernel configuration file(s) (${KERNCONF})."
	@false
.endif
.if defined(KERNWARN)
	@echo "--------------------------------------------------------------"
	@echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF="
	@echo "--------------------------------------------------------------"
	@sleep 3
.endif
	@echo
.for _kernel in ${BUILDKERNELS}
	@echo "--------------------------------------------------------------"
	@echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`"
	@echo "--------------------------------------------------------------"
	@echo "===> ${_kernel}"
	mkdir -p ${KRNLOBJDIR}
.if !defined(NO_KERNELCONFIG)
	cd ${KRNLCONFDIR}; \
		PATH=${STRICTTMPPATH} \
		    config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \
			${KERNCONFDIR}/${_kernel}
.endif
.if !defined(NOCLEAN) && !defined(NO_KERNELCLEAN)
	cd ${KRNLOBJDIR}/${_kernel}; \
	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} -DNO_MODULES clean
.if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KRNLSRCDIR}/modules)
	cd ${KRNLOBJDIR}/${_kernel}; \
	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} cleandir
.endif
.endif
	cd ${KRNLOBJDIR}/${_kernel}; \
	    MAKESRCPATH=${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm \
	    ${MAKE} -DBOOTSTRAPPING -f ${KRNLSRCDIR}/dev/disk/aic7xxx/aicasm/Makefile
.if !defined(NO_KERNELDEPEND)
	cd ${KRNLOBJDIR}/${_kernel}; \
	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} depend
.endif
	cd ${KRNLOBJDIR}/${_kernel}; \
	    ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all
	@echo "--------------------------------------------------------------"
	@echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`"
	@echo "--------------------------------------------------------------"
.endfor

#
# installkernel
#
# Install the kernel defined by INSTALLKERNEL
#
installkernel reinstallkernel:
	cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
	    ${CROSSENV} ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel$//}

#
# update
#
# Update the source tree, by running sup and/or running cvs to update to the
# latest copy.
#
update:
.if defined(SUP_UPDATE)
	@echo "--------------------------------------------------------------"
	@echo ">>> Running ${SUP}"
	@echo "--------------------------------------------------------------"
.if defined(SUPFILE)
	@${SUP} ${SUPFLAGS} ${SUPFILE}
.endif
.if defined(SUPFILE1)
	@${SUP} ${SUPFLAGS} ${SUPFILE1}
.endif
.if defined(SUPFILE2)
	@${SUP} ${SUPFLAGS} ${SUPFILE2}
.endif
.if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE)
	@${SUP} ${SUPFLAGS} ${PORTSSUPFILE}
.endif
.if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE)
	@${SUP} ${SUPFLAGS} ${DOCSUPFILE}
.endif
.endif
.if defined(CVS_UPDATE)
	@echo "--------------------------------------------------------------"
	@echo ">>> Updating ${.CURDIR} from cvs repository" ${CVSROOT}
	@echo "--------------------------------------------------------------"
	cd ${.CURDIR}; cvs -q update -rRELENG_4 -P -d
.endif

#
# most
#
# Build most of the user binaries on the existing system libs and includes.
#
most:
	@echo "--------------------------------------------------------------"
	@echo ">>> Building programs only"
	@echo "--------------------------------------------------------------"
.for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
	cd ${.CURDIR}/${_dir};		${MAKE} DIRPRFX=${_dir}/ all
.endfor

#
# installmost
#
# Install the binaries built by the 'most' target.  This does not include
# libraries or include files.
#
installmost:
	@echo "--------------------------------------------------------------"
	@echo ">>> Installing programs only"
	@echo "--------------------------------------------------------------"
.for _dir in bin sbin libexec usr.bin usr.sbin gnu/libexec gnu/usr.bin gnu/usr.sbin
	cd ${.CURDIR}/${_dir};		${MAKE} DIRPRFX=${_dir}/ install
.endfor

#
# ------------------------------------------------------------------------
#
# From here onwards are utility targets used by the 'make world' and
# related targets.  If your 'world' breaks, you may like to try to fix
# the problem and manually run the following targets to attempt to
# complete the build.  Beware, this is *not* guaranteed to work, you
# need to have a pretty good grip on the current state of the system
# to attempt to manually finish it.  If in doubt, 'make world' again.
#

# bootstrap-tools: Build all tools required to build all tools.
#
# [x]install:	dependancies on various new install features
# rpcgen:	old rpcgen used a hardwired cpp path, newer OBJFORMAT_PATH
#		envs are not compatible with older objformat binaries.
#
.if exists(${.CURDIR}/games) && !defined(NOGAMES)
_strfile=	games/fortune/strfile
.endif

bootstrap-tools:
.for _tool in ${_strfile} \
    bin/chmod bin/cp bin/dd bin/mkdir bin/rm bin/echo bin/test \
    bin/cat bin/date bin/ln bin/mv bin/csh bin/expr bin/sh bin/ls \
    bin/hostname \
    sbin/sysctl \
    usr.bin/yacc usr.bin/colldef usr.bin/uudecode usr.bin/xinstall \
    usr.bin/m4 usr.bin/rpcgen usr.bin/make gnu/usr.bin/awk usr.bin/file \
    usr.bin/find usr.bin/lex usr.bin/sed usr.bin/uname usr.bin/touch \
    usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \
    usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \
    usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \
    usr.bin/mklocale usr.bin/uuencode usr.bin/compile_et \
    usr.bin/vi usr.bin/cap_mkdb usr.bin/vgrind usr.bin/true usr.bin/false \
    usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \
    usr.sbin/chown usr.sbin/mtree usr.sbin/config \
    usr.sbin/btxld usr.sbin/pwd_mkdb usr.sbin/zic \
    gnu/usr.bin/gperf gnu/usr.bin/groff gnu/usr.bin/texinfo \
    gnu/usr.bin/grep gnu/usr.bin/sort gnu/usr.bin/patch \
    gnu/usr.bin/gzip gnu/usr.bin/perl gnu/usr.bin/man/makewhatis
	${ECHODIR} "===> ${_tool} (bootstrap-tools)"; \
		cd ${.CURDIR}/${_tool}; \
		${MAKE} DIRPRFX=${_tool}/ obj; \
		${MAKE} DIRPRFX=${_tool}/ depend; \
		${MAKE} DIRPRFX=${_tool}/ all; \
		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
.endfor

# build-tools: Build special purpose build tools.  gcc2 related tools are
# only built under the i386 architecture.  Other architectures are
# gcc3-only.
#
# XXX we may be able to remove or consolidate this into bootstrap-tools
# now that we have the native helper (.nx/.no) infrastructure.
#
.if exists(${.CURDIR}/games) && !defined(NOGAMES)
_games=	games/adventure games/hack games/phantasia
.endif

.if exists(${.CURDIR}/share) && !defined(NOSHARE)
_share=	share/syscons/scrnmaps
.endif

_gcc3_cross= gnu/usr.bin/cc3
_gcc3_tools= gnu/usr.bin/cc3/cc_tools
.if ${MACHINE_ARCH} == "i386" && ${TARGET_ARCH} == "i386"
_gcc2_cross= gnu/usr.bin/cc
_gcc2_tools= gnu/usr.bin/cc/cc_tools
_binutils= gnu/usr.bin/binutils gnu/usr.bin/binutils214
.else
_binutils= gnu/usr.bin/binutils214
.endif

.if !defined(NO_FORTRAN)
.if ${TARGET_ARCH} == "i386"
_fortran= gnu/usr.bin/cc/f771
.else
_fortran= gnu/usr.bin/cc3/f771
.endif
.endif

.if !defined(NOPERL)
_perl=	gnu/usr.bin/perl/miniperl
.endif

.if exists(${.CURDIR}/kerberos5) && exists(${.CURDIR}/crypto) && \
    !defined(NOCRYPT) && defined(MAKE_KERBEROS5)
_libkrb5= kerberos5/lib/libroken kerberos5/lib/libvers \
    kerberos5/lib/libasn1 kerberos5/lib/libhdb kerberos5/lib/libsl
.endif

.if defined(RELEASEDIR)
_sysinstall= release/sysinstall
.endif

build-tools:
.for _tool in ${_gcc2_tools} ${_gcc3_tools} \
	      ${_fortran} ${_perl} ${_libroken4} ${_libkrb5} \
	      ${_share} ${_sysinstall}
	${ECHODIR} "===> ${_tool} (build-tools)"; \
		cd ${.CURDIR}/${_tool}; \
		${MAKE} DIRPRFX=${_tool}/ obj; \
		${MAKE} DIRPRFX=${_tool}/ depend; \
		${MAKE} DIRPRFX=${_tool}/ all; \
		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${BTOOLSDEST} install
.endfor

#
# cross-tools: Build cross-building tools
#
.if ${TARGET_ARCH} == "alpha" && ${MACHINE_ARCH} != "alpha"
_elf2exe=	usr.sbin/elf2exe
.endif

.if ${TARGET_ARCH} == "i386" && ${MACHINE_ARCH} != "i386"
_btxld=	usr.sbin/btxld
.endif

cross-tools:
.for _tool in ${_btxld} ${_elf2exe} ${_binutils} \
	      usr.bin/objformat usr.sbin/crunch/crunchide \
	      ${_gcc2_cross} ${_gcc3_cross}
	${ECHODIR} "===> ${_tool} (cross-tools)"; \
		cd ${.CURDIR}/${_tool}; \
		${MAKE} DIRPRFX=${_tool}/ obj; \
		${MAKE} DIRPRFX=${_tool}/ depend; \
		${MAKE} DIRPRFX=${_tool}/ all; \
		${MAKE} DIRPRFX=${_tool}/ DESTDIR=${CTOOLSDEST} install
.endfor

#
# hierarchy - ensure that all the needed directories are present
#
hierarchy:
	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs

#
# libraries - build all libraries, and install them under ${DESTDIR}.
#
# The list of libraries with dependents (${_prebuild_libs}) and their
# interdependencies (__L) are built automatically by the
# ${.CURDIR}/tools/make_libdeps.sh script.
#
# .makeenv does not work when bootstrapping from 4.x, so we must be sure
# to specify the correct CCVER or 'cc' will not exec the correct compiler.
#
libraries:
	cd ${.CURDIR}; \
	    CCVER=gcc2 ${MAKE} -f Makefile.inc1 _startup_libs2; \
	    CCVER=gcc3 ${MAKE} -f Makefile.inc1 _startup_libs3; \
	    ${MAKE} -f Makefile.inc1 _startup_libs; \
	    ${MAKE} -f Makefile.inc1 _prebuild_libs; \
	    ${MAKE} -f Makefile.inc1 _generic_libs;

# These dependencies are not automatically generated:
#
# gnu/lib/csu, gnu/lib/libgcc and lib/csu must be built before all
# shared libraries for ELF.  The targets for _startup_libs{2,3} are
# specifically built using gcc{2,3}.
#
_startup_libs2=	gnu/lib/gcc2/csu gnu/lib/gcc2/libgcc
_startup_libs3=	gnu/lib/gcc3/csu gnu/lib/gcc3/libgcc
.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf)
_startup_libs=	lib/csu/${MACHINE_ARCH}-elf
.else
_startup_libs=	lib/csu/${MACHINE_ARCH}
.endif
_startup_libs+=	lib/libc

_prebuild_libs=

_generic_libs=	gnu/lib

.if !defined(NOPERL)
_generic_libs+=	gnu/usr.bin/perl/libperl
.endif

.if !defined(NOCRYPT) && defined(MAKE_KERBEROS5)
_prebuild_libs+=	kerberos5/lib/libasn1
_prebuild_libs+=	kerberos5/lib/libgssapi
_prebuild_libs+=	kerberos5/lib/libkrb5
_prebuild_libs+=	kerberos5/lib/libroken
_generic_libs+=	kerberos5/lib
.endif

_prebuild_libs+= lib/libcom_err lib/libcrypt lib/libmd \
		lib/libncurses lib/libopie lib/libradius lib/libskey \
		lib/libtacplus lib/libutil \
		lib/libz lib/msun

lib/libopie__L lib/libradius__L lib/libtacplus__L: lib/libmd__L
lib/libskey__L: lib/libcrypt__L lib/libmd__L

_generic_libs+=	lib

.if !defined(NOCRYPT)
.if !defined(NO_OPENSSL)
_prebuild_libs+=	secure/lib/libcrypto secure/lib/libssl
.if !defined(NO_OPENSSH)
_prebuild_libs+=	secure/lib/libssh
secure/lib/libssh__L: secure/lib/libcrypto__L lib/libz__L
.endif
.endif
_generic_libs+=	secure/lib
.endif

_generic_libs+=	usr.bin/lex/lib

.if ${MACHINE_ARCH} == "i386"
_generic_libs+=	usr.sbin/pcvt/keycap
.endif

.for _lib in ${_startup_libs2} ${_startup_libs3} ${_startup_libs} \
		${_prebuild_libs} ${_generic_libs}
${_lib}__L: .PHONY
.if exists(${.CURDIR}/${_lib})
	${ECHODIR} "===> ${_lib}"; \
		cd ${.CURDIR}/${_lib}; \
		${MAKE} DIRPRFX=${_lib}/ depend; \
		${MAKE} DIRPRFX=${_lib}/ all; \
		${MAKE} DIRPRFX=${_lib}/ install
.endif
.endfor

# only mess with gcc2 for i386 architectures.
#
_startup_libs: ${_startup_libs:S/$/__L/}
.if ${TARGET_ARCH} == "i386"
_startup_libs2: ${_startup_libs2:S/$/__L/}
.else
_startup_libs2:
.endif
_startup_libs3: ${_startup_libs3:S/$/__L/}
_prebuild_libs: ${_prebuild_libs:S/$/__L/}
_generic_libs: ${_generic_libs:S/$/__L/}

# library targets must be ordered because there are inter-library
# races (e.g. generation of tconfig.h)
#
.ORDER: ${_startup_libs2:S/$/__L/}
.ORDER: ${_startup_libs3:S/$/__L/}
.ORDER: ${_startup_libs:S/$/__L/}
.ORDER: ${_prebuild_libs:S/$/__L/}
.ORDER: ${_generic_libs:S/$/__L/}

.for __target in clean cleandepend cleandir obj depend includes
.for entry in ${SUBDIR}
${entry}.${__target}__D: .PHONY
	@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \
		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH}"; \
		edir=${entry}.${MACHINE_ARCH}; \
		cd ${.CURDIR}/$${edir}; \
	else \
		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
		edir=${entry}; \
		cd ${.CURDIR}/$${edir}; \
	fi; \
	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
.endfor
par-${__target}: ${SUBDIR:S/$/.${__target}__D/}
.ORDER: ${SUBDIR:S/$/.${__target}__D/}
.endfor
.ORDER: par-clean par-cleandepend par-cleandir par-obj par-depend par-includes

# The wmake target is used by /usr/bin/wmake to run make in a
# world build environment.
#
wmake:
	@echo '${WMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${WMAKE_ARGS}'

wmakeenv:
	@echo '${WMAKEENV} /bin/sh'

bmake:
	@echo '${BMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${BMAKE_ARGS}'

bmakeenv:
	@echo '${BMAKEENV} /bin/sh'

tmake:
	@echo '${TMAKEENV} ${MAKE} -m ${.CURDIR}/share/mk ${TMAKE_ARGS}'

tmakeenv:
	@echo '${TMAKEENV} /bin/sh'

.include <bsd.subdir.mk>