Makefile revision 35851
12061Sjkh#
235851Sjb#	$Id: Makefile,v 1.174 1998/05/02 12:29:48 bde Exp $
32061Sjkh#
433611Sjb# While porting to the another architecture include the bootstrap instead
532427Sjb# of the normal build.
632427Sjb#
733611Sjb.if exists(${.CURDIR}/Makefile.${MACHINE})
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 "--------------------------------------------------------------"
17928803Speter	cd ${.CURDIR} && ${MAKE} pre-world
18027910Sasami.endif
18128803Speter	cd ${.CURDIR} && ${MAKE} buildworld
18230113Sjkh	cd ${.CURDIR} && ${MAKE} -B installworld
18327910Sasami.if target(post-world)
18417308Speter	@echo
1852061Sjkh	@echo "--------------------------------------------------------------"
18627910Sasami	@echo " Making 'post-world' target"
1872061Sjkh	@echo "--------------------------------------------------------------"
18828803Speter	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
21627910SasamiBMAKEENV=	PATH=${TMPPATH} ${COMPILER_ENV} NOEXTRADEPEND=t
21727910SasamiXMAKEENV=	PATH=${STRICTTMPPATH} ${COMPILER_ENV} \
21835479Sbde		CFLAGS="-nostdinc ${CFLAGS}"	# XXX -nostdlib
21927910Sasami
22027910Sasami# used to compile and install 'make' in temporary build tree
22134688SbdeMAKETMP=	${WORLDTMP}/make
22234688SbdeIBMAKE=	${BMAKEENV} MAKEOBJDIR=${MAKETMP} ${MAKE} DESTDIR=${WORLDTMP}
22327910Sasami# bootstrap make
22435427SbdeBMAKE=	${BMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
22527910Sasami# cross make used for compilation
22635427SbdeXMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make DESTDIR=${WORLDTMP}
22727910Sasami# cross make used for final installation
22835427SbdeIXMAKE=	${XMAKEENV} ${WORLDTMP}/usr/bin/make
22927910Sasami
23027910Sasami#
23127910Sasami# buildworld
23227910Sasami#
23327910Sasami# Attempt to rebuild the entire system, with reasonable chance of
23427910Sasami# success, regardless of how old your existing system is.
23527910Sasami#
23627910Sasamibuildworld:
23727910Sasami.if !defined(NOCLEAN)
23817308Speter	@echo
23917308Speter	@echo "--------------------------------------------------------------"
24027910Sasami	@echo " Cleaning up the temporary build tree"
24117308Speter	@echo "--------------------------------------------------------------"
24227910Sasami	mkdir -p ${WORLDTMP}
24327910Sasami	chflags -R noschg ${WORLDTMP}/
24427910Sasami	rm -rf ${WORLDTMP}
24527910Sasami.endif
24633133Sadam.if !defined(NOTOOLS)
24717466Speter	@echo
24817308Speter	@echo "--------------------------------------------------------------"
24927910Sasami	@echo " Making make"
25017308Speter	@echo "--------------------------------------------------------------"
25134688Sbde	mkdir -p ${WORLDTMP}/usr/bin ${MAKETMP}
25234688Sbde	( \
25327910Sasami	cd ${.CURDIR}/usr.bin/make && \
25434688Sbde		MAKEOBJDIRPREFIX= && unset MAKEOBJDIRPREFIX && \
25530113Sjkh		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} all && \
25630277Sasami		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} install && \
25734688Sbde		${IBMAKE} -I${.CURDIR}/share/mk ${MK_FLAGS} clean \
25834688Sbde	)
25933133Sadam.endif
26017308Speter	@echo
26117308Speter	@echo "--------------------------------------------------------------"
26227910Sasami	@echo " Making hierarchy"
26317308Speter	@echo "--------------------------------------------------------------"
26427910Sasami	cd ${.CURDIR} && ${BMAKE} hierarchy
26527910Sasami.if !defined(NOCLEAN)
26617308Speter	@echo
26717308Speter	@echo "--------------------------------------------------------------"
26827910Sasami	@echo " Cleaning up the obj tree"
26917308Speter	@echo "--------------------------------------------------------------"
27035479Sbde	cd ${.CURDIR} && ${BMAKE} ${CLEANDIR:S/^/par-/}
27127910Sasami.endif
27227910Sasami.if !defined(NOOBJDIR)
27317308Speter	@echo
27417308Speter	@echo "--------------------------------------------------------------"
27527910Sasami	@echo " Rebuilding the obj tree"
27617308Speter	@echo "--------------------------------------------------------------"
27734509Sbde	cd ${.CURDIR} && ${BMAKE} par-${OBJDIR}
27827910Sasami.endif
27933133Sadam.if !defined(NOTOOLS)
28017308Speter	@echo
28117308Speter	@echo "--------------------------------------------------------------"
28227910Sasami	@echo " Rebuilding bootstrap tools"
28317308Speter	@echo "--------------------------------------------------------------"
28427910Sasami	cd ${.CURDIR} && ${BMAKE} bootstrap
28517308Speter	@echo
28617308Speter	@echo "--------------------------------------------------------------"
28727910Sasami	@echo " Rebuilding tools necessary to build the include files"
28817308Speter	@echo "--------------------------------------------------------------"
28927910Sasami	cd ${.CURDIR} && ${BMAKE} include-tools
29033133Sadam.endif
29117308Speter	@echo
29217308Speter	@echo "--------------------------------------------------------------"
29334509Sbde	@echo " Rebuilding ${DESTDIR}/usr/include"
29417308Speter	@echo "--------------------------------------------------------------"
29529503Sbde	cd ${.CURDIR} && SHARED=symlinks ${BMAKE} includes
29635851Sjb	@echo
29735851Sjb	@echo "--------------------------------------------------------------"
29835851Sjb	@echo " Rebuilding bootstrap libraries"
29935851Sjb	@echo "--------------------------------------------------------------"
30035851Sjb	cd ${.CURDIR} && ${BMAKE} bootstrap-libraries
30133133Sadam.if !defined(NOTOOLS)
30217962Speter	@echo
30317962Speter	@echo "--------------------------------------------------------------"
30435851Sjb	@echo " Rebuilding tools needed to build libraries"
30517962Speter	@echo "--------------------------------------------------------------"
30627910Sasami	cd ${.CURDIR} && ${BMAKE} lib-tools
30733133Sadam.endif
30833133Sadam.if !defined(NOTOOLS)
30917962Speter	@echo
31017962Speter	@echo "--------------------------------------------------------------"
31127910Sasami	@echo " Rebuilding all other tools needed to build the world"
31217962Speter	@echo "--------------------------------------------------------------"
31327910Sasami	cd ${.CURDIR} && ${BMAKE} build-tools
31433133Sadam.endif
31535479Sbde.if !defined(_NODEPEND)
31617308Speter	@echo
31717308Speter	@echo "--------------------------------------------------------------"
31827910Sasami	@echo " Rebuilding dependencies"
31917308Speter	@echo "--------------------------------------------------------------"
32030205Sbde	cd ${.CURDIR} && ${XMAKE} par-depend
32135479Sbde.endif
32217308Speter	@echo
32317308Speter	@echo "--------------------------------------------------------------"
32435427Sbde	@echo " Building libraries"
32535427Sbde	@echo "--------------------------------------------------------------"
32635479Sbde	cd ${.CURDIR} && ${XMAKE} -DNOINFO -DNOMAN libraries
32735427Sbde	@echo
32835427Sbde	@echo "--------------------------------------------------------------"
32927910Sasami	@echo " Building everything.."
33017962Speter	@echo "--------------------------------------------------------------"
33127910Sasami	cd ${.CURDIR} && ${XMAKE} all
3322061Sjkh
33317308Speter#
33427910Sasami# installworld
33527910Sasami#
33627910Sasami# Installs everything compiled by a 'buildworld'.
33727910Sasami#
33827910Sasamiinstallworld:
33927910Sasami	cd ${.CURDIR} && ${IXMAKE} reinstall
34027910Sasami
34127910Sasami#
34217308Speter# reinstall
34317308Speter#
34417308Speter# If you have a build server, you can NFS mount the source and obj directories
34517308Speter# and do a 'make reinstall' on the *client* to install new binaries from the
34617308Speter# most recent server build.
34717308Speter#
34817308Speterreinstall:
34912483Speter	@echo "--------------------------------------------------------------"
35017308Speter	@echo " Making hierarchy"
35112483Speter	@echo "--------------------------------------------------------------"
35217308Speter	cd ${.CURDIR} && ${MAKE} hierarchy
35312483Speter	@echo
3542061Sjkh	@echo "--------------------------------------------------------------"
35517962Speter	@echo " Installing everything.."
35617962Speter	@echo "--------------------------------------------------------------"
35717308Speter	cd ${.CURDIR} && ${MAKE} install
35817962Speter	@echo
35917962Speter	@echo "--------------------------------------------------------------"
36033595Snate	@echo " Re-scanning the shared libraries.."
36133595Snate	@echo "--------------------------------------------------------------"
36233595Snate	cd ${.CURDIR} && ldconfig -R
36333595Snate	@echo
36433595Snate	@echo "--------------------------------------------------------------"
36517962Speter	@echo " Rebuilding man page indexes"
36617962Speter	@echo "--------------------------------------------------------------"
36717308Speter	cd ${.CURDIR}/share/man && ${MAKE} makedb
3682061Sjkh
36917308Speter#
37017308Speter# update
37117308Speter#
37217308Speter# Update the source tree, by running sup and/or running cvs to update to the
37317308Speter# latest copy.
37417308Speter#
3752302Spaulupdate:
3762302Spaul.if defined(SUP_UPDATE)
3772302Spaul	@echo "--------------------------------------------------------------"
37835462Sjkh	@echo "Running ${SUP}"
3792302Spaul	@echo "--------------------------------------------------------------"
38018714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE}
38110760Sache.if defined(SUPFILE1)
38218714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE1}
3832302Spaul.endif
38410760Sache.if defined(SUPFILE2)
38518714Sache	@${SUP} ${SUPFLAGS} ${SUPFILE2}
38610760Sache.endif
38710760Sache.endif
3882302Spaul.if defined(CVS_UPDATE)
3892302Spaul	@echo "--------------------------------------------------------------"
3902302Spaul	@echo "Updating /usr/src from cvs repository" ${CVSROOT}
3912302Spaul	@echo "--------------------------------------------------------------"
39230132Sfsmp	cd ${.CURDIR} && cvs -q update -P -d
3932302Spaul.endif
3942302Spaul
39517308Speter#
39617308Speter# most
39717308Speter#
39817308Speter# Build most of the user binaries on the existing system libs and includes.
39917308Speter#
40017308Spetermost:
4012061Sjkh	@echo "--------------------------------------------------------------"
40217308Speter	@echo " Building programs only"
4032061Sjkh	@echo "--------------------------------------------------------------"
40430205Sbde	cd ${.CURDIR}/bin	&&	${MAKE} all
40530205Sbde	cd ${.CURDIR}/sbin	&&	${MAKE} all
40630205Sbde	cd ${.CURDIR}/libexec	&&	${MAKE} all
40730205Sbde	cd ${.CURDIR}/usr.bin	&&	${MAKE} all
40830205Sbde	cd ${.CURDIR}/usr.sbin	&&	${MAKE} all
40930205Sbde	cd ${.CURDIR}/gnu/libexec &&	${MAKE} all
41030205Sbde	cd ${.CURDIR}/gnu/usr.bin &&	${MAKE} all
41130205Sbde	cd ${.CURDIR}/gnu/usr.sbin &&	${MAKE} all
41230169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
41330205Sbde#	cd ${.CURDIR}/kerberosIV	&&	${MAKE} most
41417308Speter#.endif
41517308Speter#.if !defined(NOSECURE) && !defined(NOCRYPT)
41630205Sbde#	cd ${.CURDIR}/secure	&&	${MAKE} most
41717308Speter#.endif
4182061Sjkh
41917308Speter#
42017308Speter# installmost
42117308Speter#
42217308Speter# Install the binaries built by the 'most' target.  This does not include
42317308Speter# libraries or include files.
42417308Speter#
4253626Swollmaninstallmost:
4263626Swollman	@echo "--------------------------------------------------------------"
4273626Swollman	@echo " Installing programs only"
4283626Swollman	@echo "--------------------------------------------------------------"
42930205Sbde	cd ${.CURDIR}/bin	&&	${MAKE} install
43030205Sbde	cd ${.CURDIR}/sbin	&&	${MAKE} install
43130205Sbde	cd ${.CURDIR}/libexec	&&	${MAKE} install
43230205Sbde	cd ${.CURDIR}/usr.bin	&&	${MAKE} install
43330205Sbde	cd ${.CURDIR}/usr.sbin	&&	${MAKE} install
43430205Sbde	cd ${.CURDIR}/gnu/libexec &&	${MAKE} install
43530205Sbde	cd ${.CURDIR}/gnu/usr.bin &&	${MAKE} install
43630205Sbde	cd ${.CURDIR}/gnu/usr.sbin &&	${MAKE} install
43730169Sjkh#.if defined(MAKE_KERBEROS4) && !defined(NOCRYPT)
43830205Sbde#	cd ${.CURDIR}/kerberosIV &&	${MAKE} installmost
4393626Swollman#.endif
4403626Swollman#.if !defined(NOSECURE) && !defined(NOCRYPT)
44130205Sbde#	cd ${.CURDIR}/secure	&&	${MAKE} installmost
4423626Swollman#.endif
4433626Swollman
44417308Speter#
44517308Speter# ------------------------------------------------------------------------
44617308Speter#
44717308Speter# From here onwards are utility targets used by the 'make world' and
44817308Speter# related targets.  If your 'world' breaks, you may like to try to fix
44917308Speter# the problem and manually run the following targets to attempt to
45017308Speter# complete the build.  Beware, this is *not* guaranteed to work, you
45117308Speter# need to have a pretty good grip on the current state of the system
45217308Speter# to attempt to manually finish it.  If in doubt, 'make world' again.
45317308Speter#
4543626Swollman
45517308Speter#
45617308Speter# heirarchy - ensure that all the needed directories are present
45717308Speter#
45817308Speterhierarchy:
45917308Speter	cd ${.CURDIR}/etc &&		${MAKE} distrib-dirs
46017308Speter
46117308Speter#
46217308Speter# bootstrap - [re]build tools needed to run the actual build, this includes
46317308Speter# tools needed by 'make depend', as some tools are needed to generate source
46417308Speter# for the dependency information to be gathered from.
46517308Speter#
46617308Speterbootstrap:
46727910Sasami.if defined(DESTDIR)
46827910Sasami	rm -f ${DESTDIR}/usr/src/sys
46927910Sasami	ln -s ${.CURDIR}/sys ${DESTDIR}/usr/src
47027910Sasami	cd ${.CURDIR}/include && find -dx . | cpio -dump ${DESTDIR}/usr/include
47134575Sbde	cd ${.CURDIR}/include && ${MAKE} symlinks
47227910Sasami.endif
47335479Sbde	cd ${.CURDIR}/usr.bin/make && ${MAKE} ${MK_FLAGS} ${_DEPEND} && \
47430113Sjkh		${MAKE} ${MK_FLAGS} all && \
47530113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
47635479Sbde	cd ${.CURDIR}/usr.bin/xinstall && ${MAKE} ${MK_FLAGS} ${_DEPEND} && \
47730113Sjkh		${MAKE} ${MK_FLAGS} all && \
47830113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
47934509Sbde	cd ${.CURDIR}/usr.bin/lex && ${MAKE} bootstrap && \
48035479Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND} && \
48130170Sjkh		${MAKE} ${MK_FLAGS} -DNOLIB all && \
48230113Sjkh		${MAKE} ${MK_FLAGS} -DNOLIB -B install ${CLEANDIR}
48329938Smckay.if !defined(NOOBJDIR)
48434509Sbde	cd ${.CURDIR}/usr.bin/lex && ${MAKE} ${OBJDIR}
48529938Smckay.endif
48617308Speter
48717308Speter#
48817308Speter# include-tools - generally the same as 'bootstrap', except that it's for
48917308Speter# things that are specifically needed to generate include files.
49017308Speter#
49127910Sasami# XXX should be merged with bootstrap, it's not worth keeeping them separate.
49227910Sasami# Well, maybe it is now.  We force 'cleandepend' here to avoid dependencies
49327910Sasami# on cleaned away headers in ${WORLDTMP}.
49417308Speter#
49517308Speterinclude-tools:
49634520Sbde.for d in usr.bin/compile_et usr.bin/rpcgen
49734520Sbde	cd ${.CURDIR}/$d && ${MAKE} cleandepend && \
49835479Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND} && \
49930113Sjkh		${MAKE} ${MK_FLAGS} all && \
50030113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
50134520Sbde.endfor
50217308Speter
50317308Speter#
50417308Speter# includes - possibly generate and install the include files.
50517308Speter#
50614119Speterincludes:
5072061Sjkh.if defined(CLOBBER)
5087130Srgrimes	rm -rf ${DESTDIR}/usr/include/*
5097130Srgrimes	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
5107130Srgrimes		-p ${DESTDIR}/usr/include
5112061Sjkh.endif
51230113Sjkh	cd ${.CURDIR}/include &&		${MAKE} -B all install
51317308Speter	cd ${.CURDIR}/gnu/include &&		${MAKE} install
51430169Sjkh	cd ${.CURDIR}/gnu/lib/libmp &&		${MAKE} beforeinstall
51530169Sjkh	cd ${.CURDIR}/gnu/lib/libobjc &&	${MAKE} beforeinstall
5162685Srgrimes	cd ${.CURDIR}/gnu/lib/libreadline &&	${MAKE} beforeinstall
5176927Snate	cd ${.CURDIR}/gnu/lib/libregex &&	${MAKE} beforeinstall
51827790Sasami	cd ${.CURDIR}/gnu/lib/libstdc++ &&	${MAKE} beforeinstall
51927790Sasami	cd ${.CURDIR}/gnu/lib/libg++ &&		${MAKE} beforeinstall
52027790Sasami	cd ${.CURDIR}/gnu/lib/libdialog &&	${MAKE} beforeinstall
52130169Sjkh	cd ${.CURDIR}/gnu/lib/libgmp &&		${MAKE} beforeinstall
52230169Sjkh.if exists(secure) && !defined(NOCRYPT)
52330169Sjkh	cd ${.CURDIR}/secure/lib/libdes &&	${MAKE} beforeinstall
5243197Scsgr.endif
52530169Sjkh.if exists(kerberosIV) && !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
52630169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libacl &&	${MAKE} beforeinstall
52730169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libkadm &&	${MAKE} beforeinstall
52830169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libkafs &&	${MAKE} beforeinstall
52930169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libkdb &&	${MAKE} beforeinstall
53030169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libkrb &&	${MAKE} beforeinstall
53130169Sjkh	cd ${.CURDIR}/kerberosIV/lib/libtelnet && ${MAKE} beforeinstall
53230169Sjkh.else
53330169Sjkh	cd ${.CURDIR}/lib/libtelnet &&		${MAKE} beforeinstall
53430169Sjkh.endif
53532427Sjb.if exists(${.CURDIR}/lib/csu/${MACHINE})
53632427Sjb	cd ${.CURDIR}/lib/csu/${MACHINE} &&	${MAKE} beforeinstall
53732427Sjb.endif
53826152Speter	cd ${.CURDIR}/lib/libalias &&		${MAKE} beforeinstall
5392061Sjkh	cd ${.CURDIR}/lib/libc &&		${MAKE} beforeinstall
54035452Sandreas	cd ${.CURDIR}/lib/libcalendar &&	${MAKE} beforeinstall
5412061Sjkh	cd ${.CURDIR}/lib/libcurses &&		${MAKE} beforeinstall
54230169Sjkh	cd ${.CURDIR}/lib/libdisk &&		${MAKE} beforeinstall
5432061Sjkh	cd ${.CURDIR}/lib/libedit &&		${MAKE} beforeinstall
54416786Snate	cd ${.CURDIR}/lib/libftpio &&		${MAKE} beforeinstall
5452883Sphk	cd ${.CURDIR}/lib/libmd &&		${MAKE} beforeinstall
54627790Sasami	cd ${.CURDIR}/lib/libmytinfo &&		${MAKE} beforeinstall
54717308Speter	cd ${.CURDIR}/lib/libncurses &&		${MAKE} beforeinstall
5487281Srgrimes.if !defined(WANT_CSRG_LIBM)
5493242Spaul	cd ${.CURDIR}/lib/msun &&		${MAKE} beforeinstall
5503242Spaul.endif
55130169Sjkh	cd ${.CURDIR}/lib/libopie &&		${MAKE} beforeinstall
5527171Sats	cd ${.CURDIR}/lib/libpcap &&		${MAKE} beforeinstall
5532061Sjkh	cd ${.CURDIR}/lib/librpcsvc &&		${MAKE} beforeinstall
5543213Spst	cd ${.CURDIR}/lib/libskey &&		${MAKE} beforeinstall
55530169Sjkh.if !defined(NOTCL) && exists (${.CURDIR}/contrib/tcl) && \
55630169Sjkh	exists(${.CURDIR}/usr.bin/tclsh) && exists (${.CURDIR}/lib/libtcl)
55730169Sjkh	cd ${.CURDIR}/lib/libtcl &&		${MAKE} installhdrs
55830169Sjkh.endif
55917308Speter	cd ${.CURDIR}/lib/libtermcap &&		${MAKE} beforeinstall
5605749Swollman	cd ${.CURDIR}/lib/libcom_err &&		${MAKE} beforeinstall
56134520Sbde	cd ${.CURDIR}/lib/libss &&		${MAKE} -B hdrs beforeinstall
56217308Speter	cd ${.CURDIR}/lib/libscsi &&		${MAKE} beforeinstall
56317308Speter	cd ${.CURDIR}/lib/libutil &&		${MAKE} beforeinstall
56430169Sjkh	cd ${.CURDIR}/lib/libvgl &&		${MAKE} beforeinstall
56526504Sjhay	cd ${.CURDIR}/lib/libz &&		${MAKE} beforeinstall
56630169Sjkh	cd ${.CURDIR}/usr.bin/f2c &&		${MAKE} beforeinstall
56730169Sjkh	cd ${.CURDIR}/usr.bin/lex &&		${MAKE} beforeinstall
5682061Sjkh
56917308Speter#
57017308Speter# lib-tools - build tools to compile and install the libraries.
57117308Speter#
57227910Sasami# XXX gperf is required for cc
57327910Sasami# XXX a new ld and tsort is required for cc
5745366Snatelib-tools:
57527910Sasami.for d in				\
57627910Sasami		gnu/usr.bin/gperf	\
57727910Sasami		gnu/usr.bin/ld		\
57827910Sasami		usr.bin/tsort		\
57927910Sasami		gnu/usr.bin/as		\
58027910Sasami		gnu/usr.bin/bison	\
58127910Sasami		gnu/usr.bin/cc		\
58227910Sasami		usr.bin/ar		\
58327910Sasami		usr.bin/lex/lib		\
58427910Sasami		usr.bin/mk_cmds		\
58527910Sasami		usr.bin/nm		\
58627910Sasami		usr.bin/ranlib		\
58727910Sasami		usr.bin/uudecode
58835479Sbde	cd ${.CURDIR}/$d && ${MAKE} ${MK_FLAGS} ${_DEPEND} && \
58930113Sjkh		${MAKE} ${MK_FLAGS} all && \
59034623Sbde		${MAKE} ${MK_FLAGS} -B install && \
59134575Sbde		${MAKE} ${MK_FLAGS:S/-DNOPIC//} -B ${CLEANDIR} ${OBJDIR}
59227910Sasami.endfor
5935366Snate
59417308Speter#
59535427Sbde# We have to know too much about ordering and subdirs in the lib trees:
59617308Speter#
59735427Sbde# To satisfy shared library linkage when only the libraries being built
59835427Sbde# are visible:
59935427Sbde#
60035427Sbde# libcom_err must be built before libss.
60135427Sbde# libcrypt and libmd must be built before libskey.
60235427Sbde# libm must be built before libtcl.
60335427Sbde# libmytinfo must be built before libdialog and libncurses.
60435427Sbde# libncurses must be built before libdialog.
60535427Sbde# libtermcap must be built before libcurses, libedit and libreadline.
60635427Sbde#
60735427Sbde# Some libraries are built conditionally and/or are in inconsistently
60835427Sbde# named directories:
60935427Sbde#
61035427Sbde.if exists(lib/csu/${MACHINE}.pcc)
61135427Sbde_csu=lib/csu/${MACHINE}.pcc
61234541Sbde.else
61335427Sbde_csu=lib/csu/${MACHINE}
61424754Sjdp.endif
61534541Sbde
61635427Sbde_libcrypt=	lib/libcrypt
61735427Sbde.if !defined(NOSECURE) && !defined(NOCRYPT)
61835427Sbde_libcrypt+=	secure/lib/libcrypt
61935427Sbde.endif
62035427Sbde
62134541Sbde.if defined(WANT_CSRG_LIBM)
62235427Sbde_libm=	lib/libm
62334541Sbde.else
62435427Sbde_libm=	lib/msun
6258295Srgrimes.endif
62634541Sbde
62734541Sbde#
62835427Sbde# bootstrap-libraries - build just enough libraries for the bootstrap
62935427Sbde# tools, and install them under ${WORLDTMP}.
63034541Sbde#
63135427Sbde# Build csu and libgcc early so that some tools get linked to the new
63235427Sbde# versions (too late for the main tools, however).  Then build the
63335427Sbde# necessary prerequisite libraries (libtermcap just needs to be before
63435427Sbde# libcurses, and this only matters for the NOCLEAN case when NOPIC is
63535427Sbde# not set).
63634541Sbde#
63735427Sbde# This is mostly wrong.  The build tools must run on the host system,
63835427Sbde# so they should use host libraries.  We depend on the target being
63935427Sbde# similar enough to the host for new target libraries to work on the
64035427Sbde# host.
64134541Sbde#
64235427Sbdebootstrap-libraries:
64335427Sbde.for _lib in ${_csu} gnu/usr.bin/cc/libgcc lib/libtermcap \
64435427Sbde    gnu/lib/libregex lib/libc lib/libcurses lib/libedit ${_libm} \
64535427Sbde    lib/libmd lib/libutil lib/libz usr.bin/lex/lib
64634541Sbde.if exists(${.CURDIR}/${_lib})
64734541Sbde	cd ${.CURDIR}/${_lib} && \
64835479Sbde		${MAKE} ${MK_FLAGS} ${_DEPEND} && \
64930113Sjkh		${MAKE} ${MK_FLAGS} all && \
65030113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
6518489Srgrimes.endif
65234541Sbde.endfor
65335427Sbde
65435427Sbde#
65535427Sbde# libraries - build all libraries, and install them under ${DESTDIR}.
65635427Sbde#
65735427Sbde# The ordering is not as special as for bootstrap-libraries.  Build
65835427Sbde# the prerequisites first, then build almost everything else in
65935427Sbde# alphabetical order.
66035427Sbde#
66135427Sbdelibraries:
66235427Sbde.for _lib in lib/libcom_err ${_libcrypt} ${_libm} lib/libmytinfo \
66335427Sbde    lib/libncurses lib/libtermcap \
66435427Sbde    gnu/lib gnu/usr.bin/cc/libgcc lib usr.bin/lex/lib usr.sbin/pcvt/keycap
66535427Sbde.if exists(${.CURDIR}/${_lib})
66635427Sbde	cd ${.CURDIR}/${_lib} && ${MAKE} all && ${MAKE} -B install
66735427Sbde.endif
66835427Sbde.endfor
66934541Sbde.if exists(${.CURDIR}/secure/lib) && !defined(NOCRYPT) && !defined(NOSECURE)
67035427Sbde	cd ${.CURDIR}/secure/lib && ${MAKE} all && ${MAKE} -B install
6712160Scsgr.endif
67234541Sbde.if exists(${.CURDIR}/kerberosIV/lib) && !defined(NOCRYPT) && \
67334541Sbde    defined(MAKE_KERBEROS4)
67435427Sbde	cd ${.CURDIR}/kerberosIV/lib && ${MAKE} all && ${MAKE} -B install
6752626Scsgr.endif
6762061Sjkh
67717308Speter#
67817308Speter# build-tools - build and install any other tools needed to complete the
67917308Speter# compile and install.
68027910Sasami# ifdef stale
68127910Sasami# bc and cpp are required to build groff.  Otherwise, the order here is
68227910Sasami# mostly historical, i.e., bogus.
68327910Sasami# chmod is used to build gcc's tmpmultilib[2] at obscure times.
68427910Sasami# endif stale
68527910Sasami# XXX uname is a bug - the target should not depend on the host.
68617308Speter#
68711806Sphkbuild-tools:
68819175Sbde.for d in				\
68927910Sasami		bin/cat 		\
69027910Sasami		bin/chmod		\
69127910Sasami		bin/cp 			\
69227910Sasami		bin/date		\
69327910Sasami		bin/dd			\
69427910Sasami		bin/echo		\
69527910Sasami		bin/expr		\
69627910Sasami		bin/hostname		\
69727910Sasami		bin/ln			\
69827910Sasami		bin/ls			\
69927910Sasami		bin/mkdir		\
70027910Sasami		bin/mv			\
70127910Sasami		bin/rm			\
70227910Sasami		bin/sh			\
70327910Sasami		bin/test		\
70427910Sasami		gnu/usr.bin/awk		\
70527910Sasami		gnu/usr.bin/bc		\
70627910Sasami		gnu/usr.bin/grep	\
70727910Sasami		gnu/usr.bin/groff	\
70827910Sasami		gnu/usr.bin/gzip	\
70927910Sasami		gnu/usr.bin/man/makewhatis	\
71035621Sbde		gnu/usr.bin/patch	\
71127910Sasami		gnu/usr.bin/sort	\
71234509Sbde		gnu/usr.bin/texinfo	\
71321673Sjkh		share/info		\
71427910Sasami		usr.bin/basename	\
71527910Sasami		usr.bin/cap_mkdb	\
71627910Sasami		usr.bin/chflags		\
71727910Sasami		usr.bin/cmp		\
71827910Sasami		usr.bin/col		\
71927910Sasami		usr.bin/cpp		\
72027910Sasami		usr.bin/expand		\
72127910Sasami		usr.bin/file2c		\
72227910Sasami		usr.bin/find		\
72327910Sasami		usr.bin/gencat		\
72427910Sasami		usr.bin/lorder		\
72527910Sasami		usr.bin/m4		\
72627910Sasami		usr.bin/mkdep		\
72727910Sasami		usr.bin/paste		\
72827910Sasami		usr.bin/sed		\
72927910Sasami		usr.bin/size		\
73027910Sasami		usr.bin/soelim		\
73127910Sasami		usr.bin/strip		\
73219175Sbde		usr.bin/symorder	\
73327910Sasami		usr.bin/touch		\
73427910Sasami		usr.bin/tr		\
73527910Sasami		usr.bin/true		\
73627910Sasami		usr.bin/uname		\
73727910Sasami		usr.bin/uuencode	\
73827910Sasami		usr.bin/vgrind		\
73927910Sasami		usr.bin/vi		\
74027910Sasami		usr.bin/wc		\
74134688Sbde		usr.bin/xargs		\
74227910Sasami		usr.bin/yacc		\
74327910Sasami		usr.sbin/chown		\
74427910Sasami		usr.sbin/mtree		\
74527910Sasami		usr.sbin/zic
74635479Sbde	cd ${.CURDIR}/$d && ${MAKE} ${MK_FLAGS} ${_DEPEND} && \
74730113Sjkh		${MAKE} ${MK_FLAGS} all && \
74830113Sjkh		${MAKE} ${MK_FLAGS} -B install ${CLEANDIR} ${OBJDIR}
74919175Sbde.endfor
7502061Sjkh
75135479Sbde.for __target in clean cleandepend cleandir depend obj
75230113Sjkh.for entry in ${SUBDIR}
75330113Sjkh${entry}.${__target}__D: .PHONY
75435294Sdt	@if test -d ${.CURDIR}/${entry}.${MACHINE}; then \
75530113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE}"; \
75630113Sjkh		edir=${entry}.${MACHINE}; \
75730113Sjkh		cd ${.CURDIR}/$${edir}; \
75830113Sjkh	else \
75930113Sjkh		${ECHODIR} "===> ${DIRPRFX}${entry}"; \
76030113Sjkh		edir=${entry}; \
76130113Sjkh		cd ${.CURDIR}/$${edir}; \
76230113Sjkh	fi; \
76330113Sjkh	${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/
76430113Sjkh.endfor
76530113Sjkhpar-${__target}: ${SUBDIR:S/$/.${__target}__D/}
76630113Sjkh.endfor
76730113Sjkh
76832427Sjb.endif
76932427Sjb
7701594Srgrimes.include <bsd.subdir.mk>
771