Makefile revision 36444
12061Sjkh#
236444Speter#	$Id: Makefile,v 1.186 1998/05/28 12:31:42 peter 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
20427910Sasami# XXX GCC_EXEC_PREFIX is for *crt.o.  It is probably unnecssary now
20527910Sasami#	tbat 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
36017962Speter	@echo
36117962Speter	@echo "--------------------------------------------------------------"
36233595Snate	@echo " Re-scanning the shared libraries.."
36333595Snate	@echo "--------------------------------------------------------------"
36436074Sbde	cd ${.CURDIR}; ldconfig -R
36533595Snate	@echo
36633595Snate	@echo "--------------------------------------------------------------"
36717962Speter	@echo " Rebuilding man page indexes"
36817962Speter	@echo "--------------------------------------------------------------"
36936074Sbde	cd ${.CURDIR}/share/man; ${MAKE} makedb
3702061Sjkh
37117308Speter#
37217308Speter# update
37317308Speter#
37417308Speter# Update the source tree, by running sup and/or running cvs to update to the
37517308Speter# latest copy.
37617308Speter#
3772302Spaulupdate:
3782302Spaul.if defined(SUP_UPDATE)
3792302Spaul	@echo "--------------------------------------------------------------"
38035462Sjkh	@echo "Running ${SUP}"
3812302Spaul	@echo "--------------------------------------------------------------"
38218714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE}
38310760Sache.if defined(SUPFILE1)
38418714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE1}
3852302Spaul.endif
38610760Sache.if defined(SUPFILE2)
38718714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE2}
38810760Sache.endif
38910760Sache.endif
3902302Spaul.if defined(CVS_UPDATE)
3912302Spaul	@echo "--------------------------------------------------------------"
3922302Spaul	@echo "Updating /usr/src from cvs repository" ${CVSROOT}
3932302Spaul	@echo "--------------------------------------------------------------"
39436074Sbde	cd ${.CURDIR}; cvs -q update -P -d
3952302Spaul.endif
3962302Spaul
39717308Speter#
39817308Speter# most
39917308Speter#
40017308Speter# Build most of the user binaries on the existing system libs and includes.
40117308Speter#
40217308Spetermost:
4032061Sjkh	@echo "--------------------------------------------------------------"
40417308Speter	@echo " Building programs only"
4052061Sjkh	@echo "--------------------------------------------------------------"
40636074Sbde	cd ${.CURDIR}/bin;		${MAKE} all
40736074Sbde	cd ${.CURDIR}/sbin;		${MAKE} all
40836074Sbde	cd ${.CURDIR}/libexec;		${MAKE} all
40936074Sbde	cd ${.CURDIR}/usr.bin;		${MAKE} all
41036074Sbde	cd ${.CURDIR}/usr.sbin;		${MAKE} all
41136074Sbde	cd ${.CURDIR}/gnu/libexec;	${MAKE} all
41236074Sbde	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} all
41336074Sbde	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} all
41430169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
41536074Sbde#	cd ${.CURDIR}/kerberosIV;	${MAKE} most
41617308Speter#.endif
41717308Speter#.if !defined(NOSECURE) && !defined(NOCRYPT)
41836074Sbde#	cd ${.CURDIR}/secure;		${MAKE} most
41917308Speter#.endif
4202061Sjkh
42117308Speter#
42217308Speter# installmost
42317308Speter#
42417308Speter# Install the binaries built by the 'most' target.  This does not include
42517308Speter# libraries or include files.
42617308Speter#
4273626Swollmaninstallmost:
4283626Swollman	@echo "--------------------------------------------------------------"
4293626Swollman	@echo " Installing programs only"
4303626Swollman	@echo "--------------------------------------------------------------"
43136074Sbde	cd ${.CURDIR}/bin;		${MAKE} install
43236074Sbde	cd ${.CURDIR}/sbin;		${MAKE} install
43336074Sbde	cd ${.CURDIR}/libexec;		${MAKE} install
43436074Sbde	cd ${.CURDIR}/usr.bin;		${MAKE} install
43536074Sbde	cd ${.CURDIR}/usr.sbin;		${MAKE} install
43636074Sbde	cd ${.CURDIR}/gnu/libexec;	${MAKE} install
43736074Sbde	cd ${.CURDIR}/gnu/usr.bin;	${MAKE} install
43836074Sbde	cd ${.CURDIR}/gnu/usr.sbin;	${MAKE} install
43930169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
44036074Sbde#	cd ${.CURDIR}/kerberosIV;	${MAKE} installmost
4413626Swollman#.endif
4423626Swollman#.if !defined(NOSECURE) && !defined(NOCRYPT)
44336074Sbde#	cd ${.CURDIR}/secure;		${MAKE} installmost
4443626Swollman#.endif
4453626Swollman
44617308Speter#
44717308Speter# ------------------------------------------------------------------------
44817308Speter#
44917308Speter# From here onwards are utility targets used by the 'make world' and
45017308Speter# related targets.  If your 'world' breaks, you may like to try to fix
45117308Speter# the problem and manually run the following targets to attempt to
45217308Speter# complete the build.  Beware, this is *not* guaranteed to work, you
45317308Speter# need to have a pretty good grip on the current state of the system
45417308Speter# to attempt to manually finish it.  If in doubt, 'make world' again.
45517308Speter#
4563626Swollman
45717308Speter#
45817308Speter# heirarchy - ensure that all the needed directories are present
45917308Speter#
46017308Speterhierarchy:
46136074Sbde	cd ${.CURDIR}/etc;		${MAKE} distrib-dirs
46217308Speter
46317308Speter#
46417308Speter# bootstrap - [re]build tools needed to run the actual build, this includes
46517308Speter# tools needed by 'make depend', as some tools are needed to generate source
46617308Speter# for the dependency information to be gathered from.
46717308Speter#
46817308Speterbootstrap:
46927910Sasami.if defined(DESTDIR)
47027910Sasami	rm -f ${DESTDIR}/usr/src/sys
47127910Sasami	ln -s ${.CURDIR}/sys ${DESTDIR}/usr/src
47236074Sbde	cd ${.CURDIR}/include; find -dx . | cpio -dump ${DESTDIR}/usr/include
47336442Speter.for d in net netinet posix4 sys vm machine
47436442Speter	if [ -h ${DESTDIR}/usr/include/$d ]; then \
47536442Speter		rm -f ${DESTDIR}/usr/include/$d ; \
47636442Speter	fi
47736442Speter.endfor
47836429Speter	cd ${.CURDIR}/sys; \
47936429Speter		find -dx net netinet posix4 sys vm -name '*.h' -o -type d | \
48036429Speter		cpio -dump ${DESTDIR}/usr/include
48136429Speter	mkdir -p ${DESTDIR}/usr/include/machine
48236429Speter	cd ${.CURDIR}/sys/i386/include; find -dx . -name '*.h' -o -type d | \
48336429Speter		cpio -dump ${DESTDIR}/usr/include/machine
48427910Sasami.endif
48536074Sbde	cd ${.CURDIR}/usr.bin/make; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
48636074Sbde		${MAKE} ${MK_FLAGS} all; \
48730113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
48836074Sbde	cd ${.CURDIR}/usr.bin/xinstall; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
48936074Sbde		${MAKE} ${MK_FLAGS} all; \
49030113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
49136074Sbde	cd ${.CURDIR}/usr.bin/lex; ${MAKE} bootstrap; \
49236074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
49336074Sbde		${MAKE} ${MK_FLAGS} -DNOLIB all; \
49430113Sjkh		${MAKE} ${MK_FLAGS} -DNOLIB -B install ${CLEANDIR}
49536429Speter.if defined(DESTDIR)
49636429Speter	cd ${.CURDIR}/include && ${MAKE} copies
49736429Speter.endif
49829938Smckay.if !defined(NOOBJDIR)
49936074Sbde	cd ${.CURDIR}/usr.bin/lex; ${MAKE} ${OBJDIR}
50029938Smckay.endif
50117308Speter
50217308Speter#
50317308Speter# include-tools - generally the same as 'bootstrap', except that it's for
50417308Speter# things that are specifically needed to generate include files.
50517308Speter#
50627910Sasami# XXX should be merged with bootstrap, it's not worth keeeping them separate.
50727910Sasami# Well, maybe it is now.  We force 'cleandepend' here to avoid dependencies
50827910Sasami# on cleaned away headers in ${WORLDTMP}.
50917308Speter#
51017308Speterinclude-tools:
51134520Sbde.for d in usr.bin/compile_et usr.bin/rpcgen
51236074Sbde	cd ${.CURDIR}/$d; ${MAKE} cleandepend; \
51336074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
51436074Sbde		${MAKE} ${MK_FLAGS} all; \
51530113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
51634520Sbde.endfor
51717308Speter
51817308Speter#
51917308Speter# includes - possibly generate and install the include files.
52017308Speter#
52114119Speterincludes:
5222061Sjkh.if defined(CLOBBER)
5237130Srgrimes	rm -rf ${DESTDIR}/usr/include/*
5247130Srgrimes	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
5257130Srgrimes		-p ${DESTDIR}/usr/include
5262061Sjkh.endif
52736074Sbde	cd ${.CURDIR}/include;			${MAKE} -B all install
52836074Sbde	cd ${.CURDIR}/gnu/include;		${MAKE} install
52936074Sbde	cd ${.CURDIR}/gnu/lib/libmp;		${MAKE} beforeinstall
53036074Sbde	cd ${.CURDIR}/gnu/lib/libobjc;		${MAKE} beforeinstall
53136074Sbde	cd ${.CURDIR}/gnu/lib/libreadline;	${MAKE} beforeinstall
53236074Sbde	cd ${.CURDIR}/gnu/lib/libregex;		${MAKE} beforeinstall
53336074Sbde	cd ${.CURDIR}/gnu/lib/libstdc++;	${MAKE} beforeinstall
53436074Sbde	cd ${.CURDIR}/gnu/lib/libg++;		${MAKE} beforeinstall
53536074Sbde	cd ${.CURDIR}/gnu/lib/libdialog;	${MAKE} beforeinstall
53636074Sbde	cd ${.CURDIR}/gnu/lib/libgmp;		${MAKE} beforeinstall
53730169Sjkh.if exists(secure) && !defined(NOCRYPT)
53836074Sbde	cd ${.CURDIR}/secure/lib/libdes;	${MAKE} beforeinstall
5393197Scsgr.endif
54030169Sjkh.if exists(kerberosIV) && !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
54136074Sbde	cd ${.CURDIR}/kerberosIV/lib/libacl;	${MAKE} beforeinstall
54236074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkadm;	${MAKE} beforeinstall
54336074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkafs;	${MAKE} beforeinstall
54436074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkdb;	${MAKE} beforeinstall
54536074Sbde	cd ${.CURDIR}/kerberosIV/lib/libkrb;	${MAKE} beforeinstall
54636074Sbde	cd ${.CURDIR}/kerberosIV/lib/libtelnet; ${MAKE} beforeinstall
54730169Sjkh.else
54836074Sbde	cd ${.CURDIR}/lib/libtelnet;		${MAKE} beforeinstall
54930169Sjkh.endif
55032427Sjb.if exists(${.CURDIR}/lib/csu/${MACHINE})
55136074Sbde	cd ${.CURDIR}/lib/csu/${MACHINE};	${MAKE} beforeinstall
55232427Sjb.endif
55336074Sbde	cd ${.CURDIR}/lib/libalias;		${MAKE} beforeinstall
55436074Sbde	cd ${.CURDIR}/lib/libc;			${MAKE} beforeinstall
55536074Sbde	cd ${.CURDIR}/lib/libcalendar;		${MAKE} beforeinstall
55636074Sbde	cd ${.CURDIR}/lib/libcurses;		${MAKE} beforeinstall
55736074Sbde	cd ${.CURDIR}/lib/libdisk;		${MAKE} beforeinstall
55836074Sbde	cd ${.CURDIR}/lib/libedit;		${MAKE} beforeinstall
55936074Sbde	cd ${.CURDIR}/lib/libftpio;		${MAKE} beforeinstall
56036074Sbde	cd ${.CURDIR}/lib/libmd;		${MAKE} beforeinstall
56136074Sbde	cd ${.CURDIR}/lib/libmytinfo;		${MAKE} beforeinstall
56236074Sbde	cd ${.CURDIR}/lib/libncurses;		${MAKE} beforeinstall
5637281Srgrimes.if !defined(WANT_CSRG_LIBM)
56436074Sbde	cd ${.CURDIR}/lib/msun;			${MAKE} beforeinstall
5653242Spaul.endif
56636074Sbde	cd ${.CURDIR}/lib/libopie;		${MAKE} beforeinstall
56736074Sbde	cd ${.CURDIR}/lib/libpcap;		${MAKE} beforeinstall
56836074Sbde	cd ${.CURDIR}/lib/librpcsvc;		${MAKE} beforeinstall
56936074Sbde	cd ${.CURDIR}/lib/libskey;		${MAKE} beforeinstall
57030169Sjkh.if !defined(NOTCL) && exists (${.CURDIR}/contrib/tcl) && \
57130169Sjkh	exists(${.CURDIR}/usr.bin/tclsh) && exists (${.CURDIR}/lib/libtcl)
57236074Sbde	cd ${.CURDIR}/lib/libtcl;		${MAKE} installhdrs
57330169Sjkh.endif
57436074Sbde	cd ${.CURDIR}/lib/libtermcap;		${MAKE} beforeinstall
57536074Sbde	cd ${.CURDIR}/lib/libcom_err;		${MAKE} beforeinstall
57636074Sbde	cd ${.CURDIR}/lib/libss;		${MAKE} -B hdrs beforeinstall
57736074Sbde	cd ${.CURDIR}/lib/libscsi;		${MAKE} beforeinstall
57836074Sbde	cd ${.CURDIR}/lib/libutil;		${MAKE} beforeinstall
57936074Sbde	cd ${.CURDIR}/lib/libvgl;		${MAKE} beforeinstall
58036074Sbde	cd ${.CURDIR}/lib/libz;			${MAKE} beforeinstall
58136074Sbde	cd ${.CURDIR}/usr.bin/f2c;		${MAKE} beforeinstall
58236074Sbde	cd ${.CURDIR}/usr.bin/lex;		${MAKE} beforeinstall
5832061Sjkh
58417308Speter#
58517308Speter# lib-tools - build tools to compile and install the libraries.
58617308Speter#
58727910Sasami# XXX gperf is required for cc
58827910Sasami# XXX a new ld and tsort is required for cc
5895366Snatelib-tools:
59027910Sasami.for d in				\
59127910Sasami		gnu/usr.bin/gperf	\
59227910Sasami		gnu/usr.bin/ld		\
59327910Sasami		usr.bin/tsort		\
59427910Sasami		gnu/usr.bin/as		\
59527910Sasami		gnu/usr.bin/bison	\
59627910Sasami		gnu/usr.bin/cc		\
59727910Sasami		usr.bin/ar		\
59827910Sasami		usr.bin/lex/lib		\
59927910Sasami		usr.bin/mk_cmds		\
60027910Sasami		usr.bin/nm		\
60127910Sasami		usr.bin/ranlib		\
60236374Ssos		usr.bin/strip		\
60336374Ssos		usr.bin/env		\
60436374Ssos		gnu/usr.bin/binutils	\
60536419Speter		usr.bin/uudecode	\
60636419Speter		usr.bin/objformat
60736074Sbde	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
60836074Sbde		${MAKE} ${MK_FLAGS} all; \
60936074Sbde		${MAKE} ${MK_FLAGS} -B install; \
61034575Sbde		${MAKE} ${MK_FLAGS:S/-DNOPIC//} -B ${CLEANDIR} ${OBJDIR}
61127910Sasami.endfor
6125366Snate
61317308Speter#
61435427Sbde# We have to know too much about ordering and subdirs in the lib trees:
61517308Speter#
61635427Sbde# To satisfy shared library linkage when only the libraries being built
61735427Sbde# are visible:
61835427Sbde#
61935427Sbde# libcom_err must be built before libss.
62035427Sbde# libcrypt and libmd must be built before libskey.
62135427Sbde# libm must be built before libtcl.
62235427Sbde# libmytinfo must be built before libdialog and libncurses.
62335427Sbde# libncurses must be built before libdialog.
62435427Sbde# libtermcap must be built before libcurses, libedit and libreadline.
62535427Sbde#
62635427Sbde# Some libraries are built conditionally and/or are in inconsistently
62735427Sbde# named directories:
62835427Sbde#
62935427Sbde.if exists(lib/csu/${MACHINE}.pcc)
63035427Sbde_csu=lib/csu/${MACHINE}.pcc
63134541Sbde.else
63235427Sbde_csu=lib/csu/${MACHINE}
63324754Sjdp.endif
63434541Sbde
63536444Speter# Build the "default" libcrypt first since it sets symlinks for static
63636444Speter# binaries such as /sbin/init.  lib/Makefile builds the other if needed.
63736444Speter.if !defined(NOSECURE) && !defined(NOCRYPT)
63836444Speter_libcrypt=	secure/lib/libcrypt
63936444Speter.else
64035427Sbde_libcrypt=	lib/libcrypt
64135427Sbde.endif
64235427Sbde
64334541Sbde.if defined(WANT_CSRG_LIBM)
64435427Sbde_libm=	lib/libm
64534541Sbde.else
64635427Sbde_libm=	lib/msun
6478295Srgrimes.endif
64834541Sbde
64934541Sbde#
65035427Sbde# bootstrap-libraries - build just enough libraries for the bootstrap
65135427Sbde# tools, and install them under ${WORLDTMP}.
65234541Sbde#
65335427Sbde# Build csu and libgcc early so that some tools get linked to the new
65435427Sbde# versions (too late for the main tools, however).  Then build the
65535427Sbde# necessary prerequisite libraries (libtermcap just needs to be before
65635427Sbde# libcurses, and this only matters for the NOCLEAN case when NOPIC is
65735427Sbde# not set).
65834541Sbde#
65935427Sbde# This is mostly wrong.  The build tools must run on the host system,
66035427Sbde# so they should use host libraries.  We depend on the target being
66135427Sbde# similar enough to the host for new target libraries to work on the
66235427Sbde# host.
66334541Sbde#
66435427Sbdebootstrap-libraries:
66535427Sbde.for _lib in ${_csu} gnu/usr.bin/cc/libgcc lib/libtermcap \
66636397Ssos    gnu/lib/libregex gnu/lib/libreadline lib/libc \
66736444Speter    ${_libcrypt} lib/libcurses lib/libedit ${_libm} \
66835427Sbde    lib/libmd lib/libutil lib/libz usr.bin/lex/lib
66934541Sbde.if exists(${.CURDIR}/${_lib})
67036074Sbde	cd ${.CURDIR}/${_lib}; \
67136074Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND}; \
67236074Sbde		${MAKE} ${MK_FLAGS} all; \
67330113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
6748489Srgrimes.endif
67534541Sbde.endfor
67635427Sbde
67735427Sbde#
67835427Sbde# libraries - build all libraries, and install them under ${DESTDIR}.
67935427Sbde#
68035427Sbde# The ordering is not as special as for bootstrap-libraries.  Build
68135427Sbde# the prerequisites first, then build almost everything else in
68235427Sbde# alphabetical order.
68335427Sbde#
68435427Sbdelibraries:
68535427Sbde.for _lib in lib/libcom_err ${_libcrypt} ${_libm} lib/libmytinfo \
68635427Sbde    lib/libncurses lib/libtermcap \
68735427Sbde    gnu/lib gnu/usr.bin/cc/libgcc lib usr.bin/lex/lib usr.sbin/pcvt/keycap
68835427Sbde.if exists(${.CURDIR}/${_lib})
68936074Sbde	cd ${.CURDIR}/${_lib}; ${MAKE} all; ${MAKE} -B install
69035427Sbde.endif
69135427Sbde.endfor
69234541Sbde.if exists(${.CURDIR}/secure/lib) && !defined(NOCRYPT) && !defined(NOSECURE)
69336074Sbde	cd ${.CURDIR}/secure/lib; ${MAKE} all; ${MAKE} -B install
6942160Scsgr.endif
69534541Sbde.if exists(${.CURDIR}/kerberosIV/lib) && !defined(NOCRYPT) && \
69634541Sbde    defined(MAKE_KERBEROS4)
69736074Sbde	cd ${.CURDIR}/kerberosIV/lib; ${MAKE} all; ${MAKE} -B install
6982626Scsgr.endif
6992061Sjkh
70017308Speter#
70117308Speter# build-tools - build and install any other tools needed to complete the
70217308Speter# compile and install.
70327910Sasami# ifdef stale
70427910Sasami# bc and cpp are required to build groff.  Otherwise, the order here is
70527910Sasami# mostly historical, i.e., bogus.
70627910Sasami# chmod is used to build gcc's tmpmultilib[2] at obscure times.
70727910Sasami# endif stale
70827910Sasami# XXX uname is a bug - the target should not depend on the host.
70917308Speter#
71011806Sphkbuild-tools:
71119175Sbde.for d in				\
71227910Sasami		bin/cat 		\
71327910Sasami		bin/chmod		\
71427910Sasami		bin/cp 			\
71527910Sasami		bin/date		\
71627910Sasami		bin/dd			\
71727910Sasami		bin/echo		\
71827910Sasami		bin/expr		\
71927910Sasami		bin/hostname		\
72027910Sasami		bin/ln			\
72127910Sasami		bin/ls			\
72227910Sasami		bin/mkdir		\
72327910Sasami		bin/mv			\
72427910Sasami		bin/rm			\
72527910Sasami		bin/sh			\
72627910Sasami		bin/test		\
72727910Sasami		gnu/usr.bin/awk		\
72827910Sasami		gnu/usr.bin/bc		\
72927910Sasami		gnu/usr.bin/grep	\
73027910Sasami		gnu/usr.bin/groff	\
73127910Sasami		gnu/usr.bin/gzip	\
73227910Sasami		gnu/usr.bin/man/makewhatis	\
73335621Sbde		gnu/usr.bin/patch	\
73436142Sjb		gnu/usr.bin/perl/perl	\
73527910Sasami		gnu/usr.bin/sort	\
73634509Sbde		gnu/usr.bin/texinfo	\
73727910Sasami		usr.bin/basename	\
73827910Sasami		usr.bin/cap_mkdb	\
73927910Sasami		usr.bin/chflags		\
74027910Sasami		usr.bin/cmp		\
74127910Sasami		usr.bin/col		\
74227910Sasami		usr.bin/cpp		\
74327910Sasami		usr.bin/expand		\
74427910Sasami		usr.bin/file2c		\
74527910Sasami		usr.bin/find		\
74627910Sasami		usr.bin/gencat		\
74727910Sasami		usr.bin/lorder		\
74827910Sasami		usr.bin/m4		\
74927910Sasami		usr.bin/mkdep		\
75027910Sasami		usr.bin/paste		\
75127910Sasami		usr.bin/sed		\
75227910Sasami		usr.bin/size		\
75327910Sasami		usr.bin/soelim		\
75427910Sasami		usr.bin/strip		\
75519175Sbde		usr.bin/symorder	\
75627910Sasami		usr.bin/touch		\
75727910Sasami		usr.bin/tr		\
75827910Sasami		usr.bin/true		\
75927910Sasami		usr.bin/uname		\
76027910Sasami		usr.bin/uuencode	\
76127910Sasami		usr.bin/vgrind		\
76227910Sasami		usr.bin/vi		\
76327910Sasami		usr.bin/wc		\
76434688Sbde		usr.bin/xargs		\
76527910Sasami		usr.bin/yacc		\
76627910Sasami		usr.sbin/chown		\
76727910Sasami		usr.sbin/mtree		\
76827910Sasami		usr.sbin/zic
76936074Sbde	cd ${.CURDIR}/$d; ${MAKE} ${MK_FLAGS} ${_DEPEND}; \
77036074Sbde		${MAKE} ${MK_FLAGS} all; \
77130113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
77219175Sbde.endfor
7732061Sjkh
77435479Sbde.for __target in clean cleandepend cleandir depend obj
77530113Sjkh.for entry in ${SUBDIR}
77630113Sjkh${entry}.${__target}__D: .PHONY
77735294Sdt	@if test -d ${.CURDIR}/${entry}.${MACHINE}; then \
77830113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE}"; \
77930113Sjkh		edir=${entry}.${MACHINE}; \
78030113Sjkh		cd ${.CURDIR}/$${edir}; \
78130113Sjkh	else \
78230113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
78330113Sjkh		edir=${entry}; \
78430113Sjkh		cd ${.CURDIR}/$${edir}; \
78530113Sjkh	fi; \
78630113Sjkh	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
78730113Sjkh.endfor
78830113Sjkhpar-${__target}: ${SUBDIR:S/$/.${__target}__D/}
78930113Sjkh.endfor
79030113Sjkh
79132427Sjb.endif
79232427Sjb
7931594Srgrimes.include <bsd.subdir.mk>
794