Makefile revision 36682
12061Sjkh#
236682Sbde#	$Id: Makefile,v 1.196 1998/06/05 16:50:45 jkh Exp $
32061Sjkh#
433611Sjb# While porting to the another architecture include the bootstrap instead
532427Sjb# of the normal build.
632427Sjb#
736111Sjb.if exists(${.CURDIR}/Makefile.${MACHINE}) && defined(BOOTSTRAP_WORLD)
833611Sjb.include "${.CURDIR}/Makefile.${MACHINE}"
932427Sjb.else
1032427Sjb#
112061Sjkh# Make command line options:
1215603Smarkm#	-DCLOBBER will remove /usr/include
1330169Sjkh#	-DMAKE_KERBEROS4 to build KerberosIV
1420710Sasami#	-DALLLANG to build documentation for all languages
1520710Sasami#	  (where available -- see share/doc/Makefile)
163197Scsgr#
172061Sjkh#	-DNOCLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
1812483Speter#	-DNOCLEAN do not clean at all
1934509Sbde#	-DNOTOOLS do not rebuild any tools first
202160Scsgr#	-DNOCRYPT will prevent building of crypt versions
212834Swollman#	-DNOLKM do not build loadable kernel modules
222061Sjkh#	-DNOOBJDIR do not run ``${MAKE} obj''
232061Sjkh#	-DNOPROFILE do not build profiled libraries
242160Scsgr#	-DNOSECURE do not go into secure subdir
2517308Speter#	-DNOGAMES do not go into games subdir
2619320Sadam#	-DNOSHARE do not go into share subdir
2727788Sasami#	-DNOINFO do not make or install info files
2830169Sjkh#	-DNOLIBC_R do not build libc_r.
2925980Sasami#	LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
301594Srgrimes
3117308Speter#
3217308Speter# The intended user-driven targets are:
3327910Sasami# buildworld  - rebuild *everything*, including glue to help do upgrades
3427910Sasami# installworld- install everything built by "buildworld"
3527910Sasami# world       - buildworld + installworld
3617308Speter# update      - convenient way to update your source tree (eg: sup/cvs)
3717308Speter# most        - build user commands, no libraries or include files
3817308Speter# installmost - install user commands, no libraries or include files
3919175Sbde#
4019175Sbde# Standard targets (not defined here) are documented in the makefiles in
4119175Sbde# /usr/share/mk.  These include:
4219175Sbde#		obj depend all install clean cleandepend cleanobj
4317308Speter
4427910Sasami.if (!make(world)) && (!make(buildworld)) && (!make(installworld))
4534509Sbde.MAKEFLAGS:=	-m ${.CURDIR}/share/mk ${.MAKEFLAGS}
4627910Sasami.endif
4717308Speter
482061Sjkh# Put initial settings here.
492061SjkhSUBDIR=
501594Srgrimes
5130169Sjkh# We must do share/info early so that installation of info `dir'
5230169Sjkh# entries works correctly.  Do it first since it is less likely to
5330169Sjkh# grow dependencies on include and lib than vice versa.
5430169Sjkh.if exists(share/info)
5530169SjkhSUBDIR+= share/info
5630169Sjkh.endif
5730169Sjkh
5830169Sjkh# We must do include and lib early so that the perl *.ph generation
597407Srgrimes# works correctly as it uses the header files installed by this.
607108Sphk.if exists(include)
617108SphkSUBDIR+= include
627108Sphk.endif
637407Srgrimes.if exists(lib)
647407SrgrimesSUBDIR+= lib
657407Srgrimes.endif
667108Sphk
672061Sjkh.if exists(bin)
682061SjkhSUBDIR+= bin
692061Sjkh.endif
7017308Speter.if exists(games) && !defined(NOGAMES)
712061SjkhSUBDIR+= games
722061Sjkh.endif
732061Sjkh.if exists(gnu)
742061SjkhSUBDIR+= gnu
752061Sjkh.endif
7635427Sbde.if exists(kerberosIV) && exists(crypto) && !defined(NOCRYPT) && \
7735427Sbde    defined(MAKE_KERBEROS4)
7830169SjkhSUBDIR+= kerberosIV
792626Scsgr.endif
802061Sjkh.if exists(libexec)
812061SjkhSUBDIR+= libexec
822061Sjkh.endif
832061Sjkh.if exists(sbin)
842061SjkhSUBDIR+= sbin
852061Sjkh.endif
8619320Sadam.if exists(share) && !defined(NOSHARE)
872061SjkhSUBDIR+= share
882061Sjkh.endif
892061Sjkh.if exists(sys)
902061SjkhSUBDIR+= sys
912061Sjkh.endif
922061Sjkh.if exists(usr.bin)
932061SjkhSUBDIR+= usr.bin
942061Sjkh.endif
952061Sjkh.if exists(usr.sbin)
962061SjkhSUBDIR+= usr.sbin
972061Sjkh.endif
982834Swollman.if exists(secure) && !defined(NOCRYPT) && !defined(NOSECURE)
992834SwollmanSUBDIR+= secure
1002834Swollman.endif
1012834Swollman.if exists(lkm) && !defined(NOLKM)
1022834SwollmanSUBDIR+= lkm
1032834Swollman.endif
1041594Srgrimes
1054486Sphk# etc must be last for "distribute" to work
1064486Sphk.if exists(etc) && make(distribute)
1074486SphkSUBDIR+= etc
1084486Sphk.endif
1094486Sphk
1102061Sjkh# These are last, since it is nice to at least get the base system
1112061Sjkh# rebuilt before you do them.
11225979Sjkh.if defined(LOCAL_DIRS)
11325979Sjkh.for _DIR in ${LOCAL_DIRS}
11425979Sjkh.if exists(${_DIR}) & exists(${_DIR}/Makefile)
11525979SjkhSUBDIR+= ${_DIR}
1162061Sjkh.endif
11725979Sjkh.endfor
1182061Sjkh.endif
1192061Sjkh
12017308Speter# Handle -DNOOBJDIR, -DNOCLEAN and -DNOCLEANDIR
1212061Sjkh.if defined(NOOBJDIR)
1222061SjkhOBJDIR=
1232061Sjkh.else
1242061SjkhOBJDIR=		obj
1252061Sjkh.endif
12612483Speter
12712483Speter.if defined(NOCLEAN)
12812483SpeterCLEANDIR=
12912483Speter.else
1302061Sjkh.if defined(NOCLEANDIR)
13135479SbdeCLEANDIR=	clean cleandepend
1328854Srgrimes.else
1332061SjkhCLEANDIR=	cleandir
1342061Sjkh.endif
13512483Speter.endif
1362061Sjkh
13735479Sbde.if !defined(NOCLEAN) && ${.MAKEFLAGS:M-j} == ""
13835479Sbde_NODEPEND=	true
13935479Sbde.endif
14035479Sbde.if defined(_NODEPEND)
14135479Sbde_DEPEND=	cleandepend
14235479Sbde.else
14335479Sbde_DEPEND=	depend
14435479Sbde.endif
14535479Sbde
14635462SjkhSUP?=		cvsup
14735462SjkhSUPFLAGS?=	-g -L 2 -P -
14818714Sache
14917308Speter#
15034541Sbde# While building tools for bootstrapping, we don't need to waste time on
15134575Sbde# shared or profiled libraries, shared linkage, or documentation, except
15234575Sbde# when the tools won't get cleaned we must use the defaults for shared
15334575Sbde# libraries and shared linkage (and this doesn't waste time).
15434592Sbde# XXX actually, we do need to waste time building shared libraries.
15517308Speter#
15634575Sbde.if defined(NOCLEAN)
15735427SbdeMK_FLAGS=	-DNOINFO -DNOMAN         -DNOPROFILE
15834575Sbde.else
15935427SbdeMK_FLAGS=	-DNOINFO -DNOMAN -DNOPIC -DNOPROFILE -DNOSHARED
16034575Sbde.endif
16115603Smarkm
16217308Speter#
16317308Speter# world
16417308Speter#
16517308Speter# Attempt to rebuild and reinstall *everything*, with reasonable chance of
16617308Speter# success, regardless of how old your existing system is.
16717308Speter#
16817308Speter# >> Beware, it overwrites the local build environment! <<
16917308Speter#
17017308Speterworld:
17118362Sjkh	@echo "--------------------------------------------------------------"
17219966Sache	@echo "make world started on `LC_TIME=C date`"
17318362Sjkh	@echo "--------------------------------------------------------------"
17417308Speter.if target(pre-world)
17527910Sasami	@echo
17617308Speter	@echo "--------------------------------------------------------------"
17717308Speter	@echo " Making 'pre-world' target"
17817308Speter	@echo "--------------------------------------------------------------"
17936074Sbde	cd ${.CURDIR}; ${MAKE} pre-world
18027910Sasami.endif
18136074Sbde	cd ${.CURDIR}; ${MAKE} buildworld
18236074Sbde	cd ${.CURDIR}; ${MAKE} -B installworld
18327910Sasami.if target(post-world)
18417308Speter	@echo
1852061Sjkh	@echo "--------------------------------------------------------------"
18627910Sasami	@echo " Making 'post-world' target"
1872061Sjkh	@echo "--------------------------------------------------------------"
18836074Sbde	cd ${.CURDIR}; ${MAKE} post-world
18927910Sasami.endif
1902061Sjkh	@echo
19117308Speter	@echo "--------------------------------------------------------------"
19227910Sasami	@echo "make world completed on `LC_TIME=C date`"
19317308Speter	@echo "--------------------------------------------------------------"
19427910Sasami
19527910Sasami.if defined(MAKEOBJDIRPREFIX)
19627910SasamiWORLDTMP=	${MAKEOBJDIRPREFIX}${.CURDIR}/tmp
19717308Speter.else
19827910SasamiWORLDTMP=	/usr/obj${.CURDIR}/tmp
19917308Speter.endif
20027910SasamiSTRICTTMPPATH=	${WORLDTMP}/sbin:${WORLDTMP}/usr/sbin:${WORLDTMP}/bin:${WORLDTMP}/usr/bin
20127910SasamiTMPPATH=	${STRICTTMPPATH}:${PATH}
20227910Sasami
20327910Sasami# XXX COMPILER_PATH is needed for finding cc1, ld and as
20436622Scharnier# XXX GCC_EXEC_PREFIX is for *crt.o.  It is probably unnecessary now
20536622Scharnier#	that LIBRARY_PATH is set.  We still can't use -nostdlib, since gcc
20627910Sasami#	wouldn't link *crt.o or libgcc if it were used.
20727910Sasami# XXX LD_LIBRARY_PATH is for ld.so.  It is also used by ld, although we don't
20827910Sasami#	want that - all compile-time library paths should be resolved by gcc.
20927910Sasami#	It fails for set[ug]id executables (are any used?).
21027910SasamiCOMPILER_ENV=	BISON_SIMPLE=${WORLDTMP}/usr/share/misc/bison.simple \
21127910Sasami		COMPILER_PATH=${WORLDTMP}/usr/libexec:${WORLDTMP}/usr/bin \
21234509Sbde		GCC_EXEC_PREFIX=${WORLDTMP}${SHLIBDIR}:${WORLDTMP}/usr/lib/ \
21327910Sasami		LD_LIBRARY_PATH=${WORLDTMP}${SHLIBDIR} \
21427910Sasami		LIBRARY_PATH=${WORLDTMP}${SHLIBDIR}:${WORLDTMP}/usr/lib
21527910Sasami
21636423SpeterBMAKEENV=	PATH=${TMPPATH} ${COMPILER_ENV} NOEXTRADEPEND=t \
21736423Speter		OBJFORMAT_PATH=${WORLDTMP}/usr/libexec:/usr/libexec
21827910SasamiXMAKEENV=	PATH=${STRICTTMPPATH} ${COMPILER_ENV} \
21936423Speter		OBJFORMAT_PATH=${WORLDTMP}/usr/libexec \
22035479Sbde		CFLAGS="-nostdinc ${CFLAGS}"	# XXX -nostdlib
22127910Sasami
22227910Sasami# used to compile and install 'make' in temporary build tree
22334688SbdeMAKETMP=	${WORLDTMP}/make
22434688SbdeIBMAKE=	${BMAKEENV} MAKEOBJDIR=${MAKETMP} ${MAKE} DESTDIR=${WORLDTMP}
22527910Sasami# bootstrap make
22635427SbdeBMAKE=	${BMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
22727910Sasami# cross make used for compilation
22835427SbdeXMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
22927910Sasami# cross make used for final installation
23035427SbdeIXMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make
23127910Sasami
23227910Sasami#
23327910Sasami# buildworld
23427910Sasami#
23527910Sasami# Attempt to rebuild the entire system, with reasonable chance of
23627910Sasami# success, regardless of how old your existing system is.
23727910Sasami#
23827910Sasamibuildworld:
23927910Sasami.if !defined(NOCLEAN)
24017308Speter	@echo
24117308Speter	@echo "--------------------------------------------------------------"
24227910Sasami	@echo " Cleaning up the temporary build tree"
24317308Speter	@echo "--------------------------------------------------------------"
24427910Sasami	mkdir -p ${WORLDTMP}
24527910Sasami	chflags -R noschg ${WORLDTMP}/
24627910Sasami	rm -rf ${WORLDTMP}
24727910Sasami.endif
24833133Sadam.if !defined(NOTOOLS)
24917466Speter	@echo
25017308Speter	@echo "--------------------------------------------------------------"
25127910Sasami	@echo " Making make"
25217308Speter	@echo "--------------------------------------------------------------"
25334688Sbde	mkdir -p ${WORLDTMP}/usr/bin ${MAKETMP}
25434688Sbde	( \
25536074Sbde	cd ${.CURDIR}/usr.bin/make; \
25636074Sbde		MAKEOBJDIRPREFIX=""; unset MAKEOBJDIRPREFIX; \
25736074Sbde		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} all; \
25836074Sbde		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} install; \
25934688Sbde		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} clean \
26034688Sbde	)
26133133Sadam.endif
26217308Speter	@echo
26317308Speter	@echo "--------------------------------------------------------------"
26427910Sasami	@echo " Making hierarchy"
26517308Speter	@echo "--------------------------------------------------------------"
26636074Sbde	cd ${.CURDIR}; ${BMAKE} hierarchy
26727910Sasami.if !defined(NOCLEAN)
26817308Speter	@echo
26917308Speter	@echo "--------------------------------------------------------------"
27027910Sasami	@echo " Cleaning up the obj tree"
27117308Speter	@echo "--------------------------------------------------------------"
27236074Sbde	cd ${.CURDIR}; ${BMAKE} ${CLEANDIR:S/^/par-/}
27327910Sasami.endif
27427910Sasami.if !defined(NOOBJDIR)
27517308Speter	@echo
27617308Speter	@echo "--------------------------------------------------------------"
27727910Sasami	@echo " Rebuilding the obj tree"
27817308Speter	@echo "--------------------------------------------------------------"
27936074Sbde	cd ${.CURDIR}; ${BMAKE} par-${OBJDIR}
28027910Sasami.endif
28133133Sadam.if !defined(NOTOOLS)
28217308Speter	@echo
28317308Speter	@echo "--------------------------------------------------------------"
28427910Sasami	@echo " Rebuilding bootstrap tools"
28517308Speter	@echo "--------------------------------------------------------------"
28636074Sbde	cd ${.CURDIR}; ${BMAKE} bootstrap
28717308Speter	@echo
28817308Speter	@echo "--------------------------------------------------------------"
28927910Sasami	@echo " Rebuilding tools necessary to build the include files"
29017308Speter	@echo "--------------------------------------------------------------"
29136074Sbde	cd ${.CURDIR}; ${BMAKE} include-tools
29233133Sadam.endif
29317308Speter	@echo
29417308Speter	@echo "--------------------------------------------------------------"
29534509Sbde	@echo " Rebuilding ${DESTDIR}/usr/include"
29617308Speter	@echo "--------------------------------------------------------------"
29736429Speter	cd ${.CURDIR}; SHARED=copies ${BMAKE} includes
29835851Sjb	@echo
29935851Sjb	@echo "--------------------------------------------------------------"
30035851Sjb	@echo " Rebuilding bootstrap libraries"
30135851Sjb	@echo "--------------------------------------------------------------"
30236074Sbde	cd ${.CURDIR}; ${BMAKE} bootstrap-libraries
30333133Sadam.if !defined(NOTOOLS)
30417962Speter	@echo
30517962Speter	@echo "--------------------------------------------------------------"
30635851Sjb	@echo " Rebuilding tools needed to build libraries"
30717962Speter	@echo "--------------------------------------------------------------"
30836074Sbde	cd ${.CURDIR}; ${BMAKE} lib-tools
30933133Sadam.endif
31033133Sadam.if !defined(NOTOOLS)
31117962Speter	@echo
31217962Speter	@echo "--------------------------------------------------------------"
31327910Sasami	@echo " Rebuilding all other tools needed to build the world"
31417962Speter	@echo "--------------------------------------------------------------"
31536074Sbde	cd ${.CURDIR}; ${BMAKE} build-tools
31633133Sadam.endif
31735479Sbde.if !defined(_NODEPEND)
31817308Speter	@echo
31917308Speter	@echo "--------------------------------------------------------------"
32027910Sasami	@echo " Rebuilding dependencies"
32117308Speter	@echo "--------------------------------------------------------------"
32236074Sbde	cd ${.CURDIR}; ${XMAKE} par-depend
32335479Sbde.endif
32417308Speter	@echo
32517308Speter	@echo "--------------------------------------------------------------"
32635427Sbde	@echo " Building libraries"
32735427Sbde	@echo "--------------------------------------------------------------"
32836074Sbde	cd ${.CURDIR}; ${XMAKE} -DNOINFO -DNOMAN libraries
32935427Sbde	@echo
33035427Sbde	@echo "--------------------------------------------------------------"
33127910Sasami	@echo " Building everything.."
33217962Speter	@echo "--------------------------------------------------------------"
33336074Sbde	cd ${.CURDIR}; ${XMAKE} all
3342061Sjkh
33517308Speter#
33627910Sasami# installworld
33727910Sasami#
33827910Sasami# Installs everything compiled by a 'buildworld'.
33927910Sasami#
34027910Sasamiinstallworld:
34136074Sbde	cd ${.CURDIR}; ${IXMAKE} reinstall
34227910Sasami
34327910Sasami#
34417308Speter# reinstall
34517308Speter#
34617308Speter# If you have a build server, you can NFS mount the source and obj directories
34717308Speter# and do a 'make reinstall' on the *client* to install new binaries from the
34817308Speter# most recent server build.
34917308Speter#
35017308Speterreinstall:
35112483Speter	@echo "--------------------------------------------------------------"
35217308Speter	@echo " Making hierarchy"
35312483Speter	@echo "--------------------------------------------------------------"
35436074Sbde	cd ${.CURDIR}; ${MAKE} hierarchy
35512483Speter	@echo
3562061Sjkh	@echo "--------------------------------------------------------------"
35717962Speter	@echo " Installing everything.."
35817962Speter	@echo "--------------------------------------------------------------"
35936074Sbde	cd ${.CURDIR}; ${MAKE} install
36036638Sjb.if ${MACHINE_ARCH} == "i386"
36117962Speter	@echo
36217962Speter	@echo "--------------------------------------------------------------"
36333595Snate	@echo " Re-scanning the shared libraries.."
36433595Snate	@echo "--------------------------------------------------------------"
36536074Sbde	cd ${.CURDIR}; ldconfig -R
36636638Sjb.endif
36733595Snate	@echo
36833595Snate	@echo "--------------------------------------------------------------"
36917962Speter	@echo " Rebuilding man page indexes"
37017962Speter	@echo "--------------------------------------------------------------"
37136074Sbde	cd ${.CURDIR}/share/man; ${MAKE} makedb
3722061Sjkh
37317308Speter#
37417308Speter# update
37517308Speter#
37617308Speter# Update the source tree, by running sup and/or running cvs to update to the
37717308Speter# latest copy.
37817308Speter#
3792302Spaulupdate:
3802302Spaul.if defined(SUP_UPDATE)
3812302Spaul	@echo "--------------------------------------------------------------"
38235462Sjkh	@echo "Running ${SUP}"
3832302Spaul	@echo "--------------------------------------------------------------"
38418714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE}
38510760Sache.if defined(SUPFILE1)
38618714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE1}
3872302Spaul.endif
38810760Sache.if defined(SUPFILE2)
38918714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE2}
39010760Sache.endif
39110760Sache.endif
3922302Spaul.if defined(CVS_UPDATE)
3932302Spaul	@echo "--------------------------------------------------------------"
3942302Spaul	@echo "Updating /usr/src from cvs repository" ${CVSROOT}
3952302Spaul	@echo "--------------------------------------------------------------"
39636074Sbde	cd ${.CURDIR}; cvs -q update -P -d
3972302Spaul.endif
3982302Spaul
39917308Speter#
40017308Speter# most
40117308Speter#
40217308Speter# Build most of the user binaries on the existing system libs and includes.
40317308Speter#
40417308Spetermost:
4052061Sjkh	@echo "--------------------------------------------------------------"
40617308Speter	@echo " Building programs only"
4072061Sjkh	@echo "--------------------------------------------------------------"
40836074Sbde	cd ${.CURDIR}/bin;		${MAKE} all
40936074Sbde	cd ${.CURDIR}/sbin;		${MAKE} all
41036074Sbde	cd ${.CURDIR}/libexec;		${MAKE} all
41136074Sbde	cd ${.CURDIR}/usr.bin;		${MAKE} all
41236074Sbde	cd ${.CURDIR}/usr.sbin;		${MAKE} all
41336074Sbde	cd ${.CURDIR}/gnu/libexec;	${MAKE} all
41436074Sbde	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} all
41536074Sbde	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} all
41630169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
41736074Sbde#	cd ${.CURDIR}/kerberosIV;	${MAKE} most
41817308Speter#.endif
41917308Speter#.if !defined(NOSECURE) && !defined(NOCRYPT)
42036074Sbde#	cd ${.CURDIR}/secure;		${MAKE} most
42117308Speter#.endif
4222061Sjkh
42317308Speter#
42417308Speter# installmost
42517308Speter#
42617308Speter# Install the binaries built by the 'most' target.  This does not include
42717308Speter# libraries or include files.
42817308Speter#
4293626Swollmaninstallmost:
4303626Swollman	@echo "--------------------------------------------------------------"
4313626Swollman	@echo " Installing programs only"
4323626Swollman	@echo "--------------------------------------------------------------"
43336074Sbde	cd ${.CURDIR}/bin;		${MAKE} install
43436074Sbde	cd ${.CURDIR}/sbin;		${MAKE} install
43536074Sbde	cd ${.CURDIR}/libexec;		${MAKE} install
43636074Sbde	cd ${.CURDIR}/usr.bin;		${MAKE} install
43736074Sbde	cd ${.CURDIR}/usr.sbin;		${MAKE} install
43836074Sbde	cd ${.CURDIR}/gnu/libexec;	${MAKE} install
43936074Sbde	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} install
44036074Sbde	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} install
44130169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
44236074Sbde#	cd ${.CURDIR}/kerberosIV;	${MAKE} installmost
4433626Swollman#.endif
4443626Swollman#.if !defined(NOSECURE) && !defined(NOCRYPT)
44536074Sbde#	cd ${.CURDIR}/secure;		${MAKE} installmost
4463626Swollman#.endif
4473626Swollman
44817308Speter#
44917308Speter# ------------------------------------------------------------------------
45017308Speter#
45117308Speter# From here onwards are utility targets used by the 'make world' and
45217308Speter# related targets.  If your 'world' breaks, you may like to try to fix
45317308Speter# the problem and manually run the following targets to attempt to
45417308Speter# complete the build.  Beware, this is *not* guaranteed to work, you
45517308Speter# need to have a pretty good grip on the current state of the system
45617308Speter# to attempt to manually finish it.  If in doubt, 'make world' again.
45717308Speter#
4583626Swollman
45917308Speter#
46017308Speter# heirarchy - ensure that all the needed directories are present
46117308Speter#
46217308Speterhierarchy:
46336074Sbde	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
46417308Speter
46517308Speter#
46617308Speter# bootstrap - [re]build tools needed to run the actual build, this includes
46717308Speter# tools needed by 'make depend', as some tools are needed to generate source
46817308Speter# for the dependency information to be gathered from.
46917308Speter#
47017308Speterbootstrap:
47127910Sasami.if defined(DESTDIR)
47227910Sasami	rm -f ${DESTDIR}/usr/src/sys
47327910Sasami	ln -s ${.CURDIR}/sys ${DESTDIR}/usr/src
47436074Sbde	cd ${.CURDIR}/include; find -dx . | cpio -dump ${DESTDIR}/usr/include
47536442Speter.for d in net netinet posix4 sys vm machine
47636442Speter	if [ -h ${DESTDIR}/usr/include/$d ]; then \
47736442Speter		rm -f ${DESTDIR}/usr/include/$d ; \
47836442Speter	fi
47936442Speter.endfor
48036429Speter	cd ${.CURDIR}/sys; \
48136429Speter		find -dx net netinet posix4 sys vm -name '*.h' -o -type d | \
48236429Speter		cpio -dump ${DESTDIR}/usr/include
48336429Speter	mkdir -p ${DESTDIR}/usr/include/machine
48436638Sjb	cd ${.CURDIR}/sys/${MACHINE_ARCH}/include; find -dx . -name '*.h' -o -type d | \
48536429Speter		cpio -dump ${DESTDIR}/usr/include/machine
48627910Sasami.endif
48736074Sbde	cd ${.CURDIR}/usr.bin/make; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
48836074Sbde		${MAKE} ${MK_FLAGS} all; \
48930113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
49036074Sbde	cd ${.CURDIR}/usr.bin/xinstall; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
49136074Sbde		${MAKE} ${MK_FLAGS} all; \
49230113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
49336074Sbde	cd ${.CURDIR}/usr.bin/lex; ${MAKE} bootstrap; \
49436074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
49536074Sbde		${MAKE} ${MK_FLAGS} -DNOLIB all; \
49636682Sbde		${MAKE} ${MK_FLAGS} -DNOLIB -B install ${CLEANDIR}
49736682Sbde.if !defined(NOOBJDIR)
49836682Sbde	cd ${.CURDIR}/usr.bin/lex; ${MAKE} ${OBJDIR}
49936682Sbde.endif
50036672Sjkh	cd ${.CURDIR}/usr.sbin/mtree; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
50136672Sjkh		${MAKE} ${MK_FLAGS} all; \
50236672Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
50336429Speter.if defined(DESTDIR)
50436429Speter	cd ${.CURDIR}/include && ${MAKE} copies
50536429Speter.endif
50617308Speter
50717308Speter#
50817308Speter# include-tools - generally the same as 'bootstrap', except that it's for
50917308Speter# things that are specifically needed to generate include files.
51017308Speter#
51127910Sasami# XXX should be merged with bootstrap, it's not worth keeeping them separate.
51227910Sasami# Well, maybe it is now.  We force 'cleandepend' here to avoid dependencies
51327910Sasami# on cleaned away headers in ${WORLDTMP}.
51417308Speter#
51517308Speterinclude-tools:
51634520Sbde.for d in usr.bin/compile_et usr.bin/rpcgen
51736074Sbde	cd ${.CURDIR}/$d; ${MAKE} cleandepend; \
51836074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
51936074Sbde		${MAKE} ${MK_FLAGS} all; \
52030113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
52134520Sbde.endfor
52217308Speter
52317308Speter#
52417308Speter# includes - possibly generate and install the include files.
52517308Speter#
52614119Speterincludes:
5272061Sjkh.if defined(CLOBBER)
5287130Srgrimes	rm -rf ${DESTDIR}/usr/include/*
5297130Srgrimes	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
5307130Srgrimes		-p ${DESTDIR}/usr/include
5312061Sjkh.endif
53236074Sbde	cd ${.CURDIR}/include;			${MAKE} -B all install
53336074Sbde	cd ${.CURDIR}/gnu/include;		${MAKE} install
53436074Sbde	cd ${.CURDIR}/gnu/lib/libmp;		${MAKE} beforeinstall
53536074Sbde	cd ${.CURDIR}/gnu/lib/libobjc;		${MAKE} beforeinstall
53636074Sbde	cd ${.CURDIR}/gnu/lib/libreadline;	${MAKE} beforeinstall
53736074Sbde	cd ${.CURDIR}/gnu/lib/libregex;		${MAKE} beforeinstall
53836074Sbde	cd ${.CURDIR}/gnu/lib/libstdc++;	${MAKE} beforeinstall
53936074Sbde	cd ${.CURDIR}/gnu/lib/libg++;		${MAKE} beforeinstall
54036074Sbde	cd ${.CURDIR}/gnu/lib/libdialog;	${MAKE} beforeinstall
54136074Sbde	cd ${.CURDIR}/gnu/lib/libgmp;		${MAKE} beforeinstall
54230169Sjkh.if exists(secure) && !defined(NOCRYPT)
54336074Sbde	cd ${.CURDIR}/secure/lib/libdes;	${MAKE} beforeinstall
5443197Scsgr.endif
54530169Sjkh.if exists(kerberosIV) && !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
54636074Sbde	cd ${.CURDIR}/kerberosIV/lib/libacl;	${MAKE} beforeinstall
54736074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkadm;	${MAKE} beforeinstall
54836074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkafs;	${MAKE} beforeinstall
54936074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkdb;	${MAKE} beforeinstall
55036074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkrb;	${MAKE} beforeinstall
55136074Sbde	cd ${.CURDIR}/kerberosIV/lib/libtelnet; ${MAKE} beforeinstall
55230169Sjkh.else
55336074Sbde	cd ${.CURDIR}/lib/libtelnet;		${MAKE} beforeinstall
55430169Sjkh.endif
55532427Sjb.if exists(${.CURDIR}/lib/csu/${MACHINE})
55636074Sbde	cd ${.CURDIR}/lib/csu/${MACHINE};	${MAKE} beforeinstall
55732427Sjb.endif
55836074Sbde	cd ${.CURDIR}/lib/libalias;		${MAKE} beforeinstall
55936074Sbde	cd ${.CURDIR}/lib/libc;			${MAKE} beforeinstall
56036074Sbde	cd ${.CURDIR}/lib/libcalendar;		${MAKE} beforeinstall
56136074Sbde	cd ${.CURDIR}/lib/libcurses;		${MAKE} beforeinstall
56236074Sbde	cd ${.CURDIR}/lib/libdisk;		${MAKE} beforeinstall
56336074Sbde	cd ${.CURDIR}/lib/libedit;		${MAKE} beforeinstall
56436074Sbde	cd ${.CURDIR}/lib/libftpio;		${MAKE} beforeinstall
56536074Sbde	cd ${.CURDIR}/lib/libmd;		${MAKE} beforeinstall
56636074Sbde	cd ${.CURDIR}/lib/libmytinfo;		${MAKE} beforeinstall
56736074Sbde	cd ${.CURDIR}/lib/libncurses;		${MAKE} beforeinstall
5687281Srgrimes.if !defined(WANT_CSRG_LIBM)
56936074Sbde	cd ${.CURDIR}/lib/msun;			${MAKE} beforeinstall
5703242Spaul.endif
57136074Sbde	cd ${.CURDIR}/lib/libopie;		${MAKE} beforeinstall
57236074Sbde	cd ${.CURDIR}/lib/libpcap;		${MAKE} beforeinstall
57336074Sbde	cd ${.CURDIR}/lib/librpcsvc;		${MAKE} beforeinstall
57436074Sbde	cd ${.CURDIR}/lib/libskey;		${MAKE} beforeinstall
57530169Sjkh.if !defined(NOTCL) && exists (${.CURDIR}/contrib/tcl) && \
57630169Sjkh	exists(${.CURDIR}/usr.bin/tclsh) && exists (${.CURDIR}/lib/libtcl)
57736074Sbde	cd ${.CURDIR}/lib/libtcl;		${MAKE} installhdrs
57830169Sjkh.endif
57936074Sbde	cd ${.CURDIR}/lib/libtermcap;		${MAKE} beforeinstall
58036074Sbde	cd ${.CURDIR}/lib/libcom_err;		${MAKE} beforeinstall
58136074Sbde	cd ${.CURDIR}/lib/libss;		${MAKE} -B hdrs beforeinstall
58236074Sbde	cd ${.CURDIR}/lib/libscsi;		${MAKE} beforeinstall
58336074Sbde	cd ${.CURDIR}/lib/libutil;		${MAKE} beforeinstall
58436074Sbde	cd ${.CURDIR}/lib/libvgl;		${MAKE} beforeinstall
58536074Sbde	cd ${.CURDIR}/lib/libz;			${MAKE} beforeinstall
58636074Sbde	cd ${.CURDIR}/usr.bin/f2c;		${MAKE} beforeinstall
58736074Sbde	cd ${.CURDIR}/usr.bin/lex;		${MAKE} beforeinstall
5882061Sjkh
58917308Speter#
59036638Sjb# Declare tools if they are not required on all architectures.
59136638Sjb#
59236638Sjb.if ${MACHINE_ARCH} == "i386"
59336638Sjb# aout tools:
59436638Sjb_aout_ar	= usr.bin/ar
59536638Sjb_aout_as	= gnu/usr.bin/as
59636638Sjb_aout_ld	= gnu/usr.bin/ld
59736638Sjb_aout_nm	= usr.bin/nm
59836638Sjb_aout_ranlib	= usr.bin/ranlib
59936638Sjb_aout_size	= usr.bin/size
60036638Sjb_aout_strip	= usr.bin/strip
60136638Sjb_aout_ldconfig	= sbin/ldconfig
60236638Sjb_objformat	= usr.bin/objformat
60336638Sjb.endif
60436638Sjb
60536638Sjb#
60617308Speter# lib-tools - build tools to compile and install the libraries.
60717308Speter#
60827910Sasami# XXX gperf is required for cc
60927910Sasami# XXX a new ld and tsort is required for cc
61036573Speter# XXX ldconfig is required at the end of reinstall/installworld.
6115366Snatelib-tools:
61227910Sasami.for d in				\
61327910Sasami		gnu/usr.bin/gperf	\
61436638Sjb		${_aout_ld}		\
61527910Sasami		usr.bin/tsort		\
61636638Sjb		${_aout_as}		\
61727910Sasami		gnu/usr.bin/bison	\
61827910Sasami		gnu/usr.bin/cc		\
61936638Sjb		${_aout_ar}		\
62027910Sasami		usr.bin/lex/lib		\
62127910Sasami		usr.bin/mk_cmds		\
62236638Sjb		${_aout_nm}		\
62336638Sjb		${_aout_ranlib}		\
62436638Sjb		${_aout_strip}		\
62536374Ssos		usr.bin/env		\
62636374Ssos		gnu/usr.bin/binutils	\
62736419Speter		usr.bin/uudecode	\
62836638Sjb		${_aout_ldconfig}	\
62936638Sjb		${_objformat}
63036074Sbde	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
63136074Sbde		${MAKE} ${MK_FLAGS} all; \
63236074Sbde		${MAKE} ${MK_FLAGS} -B install; \
63334575Sbde		${MAKE} ${MK_FLAGS:S/-DNOPIC//} -B ${CLEANDIR} ${OBJDIR}
63427910Sasami.endfor
6355366Snate
63617308Speter#
63735427Sbde# We have to know too much about ordering and subdirs in the lib trees:
63817308Speter#
63935427Sbde# To satisfy shared library linkage when only the libraries being built
64035427Sbde# are visible:
64135427Sbde#
64235427Sbde# libcom_err must be built before libss.
64335427Sbde# libcrypt and libmd must be built before libskey.
64435427Sbde# libm must be built before libtcl.
64535427Sbde# libmytinfo must be built before libdialog and libncurses.
64635427Sbde# libncurses must be built before libdialog.
64735427Sbde# libtermcap must be built before libcurses, libedit and libreadline.
64835427Sbde#
64935427Sbde# Some libraries are built conditionally and/or are in inconsistently
65035427Sbde# named directories:
65135427Sbde#
65235427Sbde.if exists(lib/csu/${MACHINE}.pcc)
65335427Sbde_csu=lib/csu/${MACHINE}.pcc
65434541Sbde.else
65535427Sbde_csu=lib/csu/${MACHINE}
65624754Sjdp.endif
65734541Sbde
65836444Speter# Build the "default" libcrypt first since it sets symlinks for static
65936444Speter# binaries such as /sbin/init.  lib/Makefile builds the other if needed.
66036470Sjhay.if exists(secure) && !defined(NOSECURE) && !defined(NOCRYPT)
66136444Speter_libcrypt=	secure/lib/libcrypt
66236444Speter.else
66335427Sbde_libcrypt=	lib/libcrypt
66435427Sbde.endif
66535427Sbde
66634541Sbde.if defined(WANT_CSRG_LIBM)
66735427Sbde_libm=	lib/libm
66834541Sbde.else
66935427Sbde_libm=	lib/msun
6708295Srgrimes.endif
67134541Sbde
67234541Sbde#
67335427Sbde# bootstrap-libraries - build just enough libraries for the bootstrap
67435427Sbde# tools, and install them under ${WORLDTMP}.
67534541Sbde#
67635427Sbde# Build csu and libgcc early so that some tools get linked to the new
67735427Sbde# versions (too late for the main tools, however).  Then build the
67835427Sbde# necessary prerequisite libraries (libtermcap just needs to be before
67935427Sbde# libcurses, and this only matters for the NOCLEAN case when NOPIC is
68035427Sbde# not set).
68134541Sbde#
68235427Sbde# This is mostly wrong.  The build tools must run on the host system,
68335427Sbde# so they should use host libraries.  We depend on the target being
68435427Sbde# similar enough to the host for new target libraries to work on the
68535427Sbde# host.
68634541Sbde#
68735427Sbdebootstrap-libraries:
68835427Sbde.for _lib in ${_csu} gnu/usr.bin/cc/libgcc lib/libtermcap \
68936397Ssos    gnu/lib/libregex gnu/lib/libreadline lib/libc \
69036444Speter    ${_libcrypt} lib/libcurses lib/libedit ${_libm} \
69135427Sbde    lib/libmd lib/libutil lib/libz usr.bin/lex/lib
69234541Sbde.if exists(${.CURDIR}/${_lib})
69336074Sbde	cd ${.CURDIR}/${_lib}; \
69436074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
69536074Sbde		${MAKE} ${MK_FLAGS} all; \
69630113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
6978489Srgrimes.endif
69834541Sbde.endfor
69935427Sbde
70035427Sbde#
70135427Sbde# libraries - build all libraries, and install them under ${DESTDIR}.
70235427Sbde#
70335427Sbde# The ordering is not as special as for bootstrap-libraries.  Build
70435427Sbde# the prerequisites first, then build almost everything else in
70535427Sbde# alphabetical order.
70635427Sbde#
70735427Sbdelibraries:
70835427Sbde.for _lib in lib/libcom_err ${_libcrypt} ${_libm} lib/libmytinfo \
70935427Sbde    lib/libncurses lib/libtermcap \
71035427Sbde    gnu/lib gnu/usr.bin/cc/libgcc lib usr.bin/lex/lib usr.sbin/pcvt/keycap
71135427Sbde.if exists(${.CURDIR}/${_lib})
71236074Sbde	cd ${.CURDIR}/${_lib}; ${MAKE} all; ${MAKE} -B install
71335427Sbde.endif
71435427Sbde.endfor
71534541Sbde.if exists(${.CURDIR}/secure/lib) && !defined(NOCRYPT) && !defined(NOSECURE)
71636074Sbde	cd ${.CURDIR}/secure/lib; ${MAKE} all; ${MAKE} -B install
7172160Scsgr.endif
71834541Sbde.if exists(${.CURDIR}/kerberosIV/lib) && !defined(NOCRYPT) && \
71934541Sbde    defined(MAKE_KERBEROS4)
72036074Sbde	cd ${.CURDIR}/kerberosIV/lib; ${MAKE} all; ${MAKE} -B install
7212626Scsgr.endif
7222061Sjkh
72336589Sjhay# Exclude perl from the build-tools if NOPERL is defined.
72436589Sjhay.if defined(NOPERL)
72536589Sjhay_perl=
72636589Sjhay.else
72736589Sjhay_perl=	gnu/usr.bin/perl/perl
72836589Sjhay.endif
72936589Sjhay
73017308Speter#
73117308Speter# build-tools - build and install any other tools needed to complete the
73217308Speter# compile and install.
73327910Sasami# ifdef stale
73427910Sasami# bc and cpp are required to build groff.  Otherwise, the order here is
73527910Sasami# mostly historical, i.e., bogus.
73627910Sasami# chmod is used to build gcc's tmpmultilib[2] at obscure times.
73727910Sasami# endif stale
73827910Sasami# XXX uname is a bug - the target should not depend on the host.
73917308Speter#
74011806Sphkbuild-tools:
74119175Sbde.for d in				\
74227910Sasami		bin/cat 		\
74327910Sasami		bin/chmod		\
74427910Sasami		bin/cp 			\
74527910Sasami		bin/date		\
74627910Sasami		bin/dd			\
74727910Sasami		bin/echo		\
74827910Sasami		bin/expr		\
74927910Sasami		bin/hostname		\
75027910Sasami		bin/ln			\
75127910Sasami		bin/ls			\
75227910Sasami		bin/mkdir		\
75327910Sasami		bin/mv			\
75427910Sasami		bin/rm			\
75527910Sasami		bin/test		\
75627910Sasami		gnu/usr.bin/awk		\
75727910Sasami		gnu/usr.bin/bc		\
75827910Sasami		gnu/usr.bin/grep	\
75927910Sasami		gnu/usr.bin/groff	\
76027910Sasami		gnu/usr.bin/gzip	\
76127910Sasami		gnu/usr.bin/man/makewhatis	\
76235621Sbde		gnu/usr.bin/patch	\
76336589Sjhay		${_perl}		\
76427910Sasami		gnu/usr.bin/sort	\
76534509Sbde		gnu/usr.bin/texinfo	\
76627910Sasami		usr.bin/basename	\
76727910Sasami		usr.bin/cap_mkdb	\
76827910Sasami		usr.bin/chflags		\
76927910Sasami		usr.bin/cmp		\
77027910Sasami		usr.bin/col		\
77127910Sasami		usr.bin/cpp		\
77227910Sasami		usr.bin/expand		\
77327910Sasami		usr.bin/file2c		\
77427910Sasami		usr.bin/find		\
77527910Sasami		usr.bin/gencat		\
77636454Sjkh		usr.bin/id		\
77727910Sasami		usr.bin/lorder		\
77827910Sasami		usr.bin/m4		\
77927910Sasami		usr.bin/mkdep		\
78027910Sasami		usr.bin/paste		\
78127910Sasami		usr.bin/sed		\
78236638Sjb		${_aout_size}		\
78327910Sasami		usr.bin/soelim		\
78436638Sjb		${_aout_strip}		\
78519175Sbde		usr.bin/symorder	\
78627910Sasami		usr.bin/touch		\
78727910Sasami		usr.bin/tr		\
78827910Sasami		usr.bin/true		\
78927910Sasami		usr.bin/uname		\
79027910Sasami		usr.bin/uuencode	\
79127910Sasami		usr.bin/vgrind		\
79227910Sasami		usr.bin/vi		\
79327910Sasami		usr.bin/wc		\
79434688Sbde		usr.bin/xargs		\
79527910Sasami		usr.bin/yacc		\
79627910Sasami		usr.sbin/chown		\
79727910Sasami		usr.sbin/mtree		\
79836455Sjkh		usr.sbin/zic		\
79936455Sjkh		bin/sh
80036074Sbde	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
80136074Sbde		${MAKE} ${MK_FLAGS} all; \
80230113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
80319175Sbde.endfor
8042061Sjkh
80535479Sbde.for __target in clean cleandepend cleandir depend obj
80630113Sjkh.for entry in ${SUBDIR}
80730113Sjkh${entry}.${__target}__D: .PHONY
80835294Sdt	@if test -d ${.CURDIR}/${entry}.${MACHINE}; then \
80930113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE}"; \
81030113Sjkh		edir=${entry}.${MACHINE}; \
81130113Sjkh		cd ${.CURDIR}/$${edir}; \
81230113Sjkh	else \
81330113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
81430113Sjkh		edir=${entry}; \
81530113Sjkh		cd ${.CURDIR}/$${edir}; \
81630113Sjkh	fi; \
81730113Sjkh	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
81830113Sjkh.endfor
81930113Sjkhpar-${__target}: ${SUBDIR:S/$/.${__target}__D/}
82030113Sjkh.endfor
82130113Sjkh
82232427Sjb.endif
82332427Sjb
8241594Srgrimes.include <bsd.subdir.mk>
825