Makefile revision 1.204
11.204Sthorpej#	$NetBSD: Makefile,v 1.204 2003/04/17 00:33:44 thorpej Exp $
21.95Scjs
31.193Slukem#
41.95Scjs# This is the top-level makefile for building NetBSD. For an outline of
51.95Scjs# how to build a snapshot or release, as well as other release engineering
61.95Scjs# information, see http://www.netbsd.org/developers/releng/index.html
71.95Scjs#
81.95Scjs# Not everything you can set or do is documented in this makefile. In
91.95Scjs# particular, you should review the files in /usr/share/mk (especially
101.95Scjs# bsd.README) for general information on building programs and writing
111.95Scjs# Makefiles within this structure, and see the comments in src/etc/Makefile
121.95Scjs# for further information on installation and release set options.
131.95Scjs#
141.95Scjs# Variables listed below can be set on the make command line (highest
151.95Scjs# priority), in /etc/mk.conf (middle priority), or in the environment
161.95Scjs# (lowest priority).
171.95Scjs#
181.95Scjs# Variables:
191.101Ssommerfe#   DESTDIR is the target directory for installation of the compiled
201.101Ssommerfe#	software. It defaults to /. Note that programs are built against
211.101Ssommerfe#	libraries installed in DESTDIR.
221.95Scjs#   MKMAN, if set to `no', will prevent building of manual pages.
231.178Senami#   MKOBJDIRS, if not set to `no', will build object directories at
241.101Ssommerfe#	an appropriate point in a build.
251.95Scjs#   MKSHARE, if set to `no', will prevent building and installing
261.95Scjs#	anything in /usr/share.
271.125Smrg#   UPDATE, if defined, will avoid a `make cleandir' at the start of
281.178Senami#	`make build', as well as having the effects listed in
291.178Senami#	/usr/share/mk/bsd.README.
301.125Smrg#   NOCLEANDIR, if defined, will avoid a `make cleandir' at the start
311.178Senami#	of the `make build'.
321.119Stoddpw#   NOINCLUDES will avoid the `make includes' usually done by `make build'.
331.95Scjs#
341.95Scjs# Targets:
351.137Stv#   build:
361.196Slukem#	Builds a full release of NetBSD in DESTDIR, except for the
371.196Slukem#	/etc configuration files.
381.196Slukem#	If BUILD_DONE is set, this is an empty target.
391.196Slukem#   distribution:
401.196Slukem#	Builds a full release of NetBSD in DESTDIR, including the /etc
411.196Slukem#	configuration files.
421.196Slukem#   buildworld:
431.196Slukem#	As per `make distribution', except that it ensures that DESTDIR
441.196Slukem#	is not the root directory.
451.196Slukem#   installworld:
461.196Slukem#	Install the distribution from DESTDIR to INSTALLWORLDDIR (which
471.196Slukem#	defaults to the root directory).  Ensures that INSTALLWORLDDIR
481.196Slukem#	is the not root directory if cross compiling.
491.137Stv#   release:
501.196Slukem#	Does a `make build', and then tars up the DESTDIR files
511.196Slukem#	into RELEASEDIR/${MACHINE}, in release(7) format.
521.196Slukem#	(See etc/Makefile for more information on this.)
531.137Stv#   regression-tests:
541.137Stv#	Runs the regression tests in "regress" on this host.
551.123Smrg#
561.137Stv# Targets invoked by `make build,' in order:
571.155Stv#   cleandir:        cleans the tree.
581.137Stv#   obj:             creates object directories.
591.152Stv#   do-tools:        builds host toolchain.
601.202Sthorpej#   do-tools-compat: builds the "libnbcompat" library; needed for some
611.202Sthorpej#                    random host tool programs in the source tree.
621.131Stv#   do-distrib-dirs: creates the distribution directories.
631.137Stv#   includes:        installs include files.
641.168Stv#   do-lib-csu:      builds and installs prerequisites from lib/csu.
651.186Sthorpej#   do-lib-libc:     builds and installs prerequisites from lib/libc.
661.143Stv#   do-lib:          builds and installs prerequisites from lib.
671.143Stv#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
681.189Sitohy#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
691.137Stv#   do-build:        builds and installs the entire system.
701.193Slukem#
711.32Scgd
721.146Stv.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
731.146Stv.MAKEFLAGS: -m ${.CURDIR}/share/mk
741.146Stv.endif
751.163Stv
761.193Slukem#
771.163Stv# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
781.163Stv# not be the top level objdir, because "make obj" can happen in the *middle*
791.163Stv# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
801.163Stv# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
811.193Slukem#
821.163Stv_SRC_TOP_OBJ_=
831.148Sjmc
841.146Stv.include <bsd.own.mk>
851.4Scgd
861.193Slukem#
871.137Stv# Sanity check: make sure that "make build" is not invoked simultaneously
881.137Stv# with a standard recursive target.
891.193Slukem#
901.137Stv
911.137Stv.if make(build) || make(release) || make(snapshot)
921.137Stv.for targ in ${TARGETS:Nobj:Ncleandir}
931.137Stv.if make(${targ}) && !target(.BEGIN)
941.137Stv.BEGIN:
951.137Stv	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
961.137Stv	@false
971.137Stv.endif
981.137Stv.endfor
991.137Stv.endif
1001.58Stv
1011.166Ssimonb_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
1021.183Slukem_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
1031.105Sassar
1041.193Slukem#
1051.137Stv# Weed out directories that don't exist.
1061.193Slukem#
1071.36Sexplorer
1081.137Stv.for dir in ${_SUBDIR}
1091.154Stv.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
1101.137StvSUBDIR+=	${dir}
1111.36Sexplorer.endif
1121.137Stv.endfor
1131.21Scgd
1141.13Sbrezak.if exists(regress)
1151.10Scgdregression-tests:
1161.10Scgd	@echo Running regression tests...
1171.152Stv	@(cd ${.CURDIR}/regress && ${MAKE} regress)
1181.13Sbrezak.endif
1191.20Scgd
1201.179Sthorpej.if defined(UNPRIVED)
1211.179SthorpejNOPOSTINSTALL=	# defined
1221.179Sthorpej.endif
1231.179Sthorpej
1241.176Slukemafterinstall:
1251.137Stv.if ${MKMAN} != "no"
1261.152Stv	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
1271.137Stv.endif
1281.159Sperry.if defined(UNPRIVED) && (${MKINFO} != "no")
1291.164Sjmc	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
1301.176Slukem.endif
1311.179Sthorpej.if !defined(NOPOSTINSTALL)
1321.180Sdrochner	(cd ${.CURDIR} && ${MAKE} postinstall-check)
1331.159Sperry.endif
1341.170Slukem
1351.170Slukempostinstall-check:
1361.169Slukem	@echo "   === Post installation checks ==="
1371.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
1381.171Slukem	@echo "   ================================"
1391.171Slukem
1401.171Slukempostinstall-fix: .NOTMAIN
1411.171Slukem	@echo "   === Post installation fixes ==="
1421.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
1431.169Slukem	@echo "   ================================"
1441.169Slukem
1451.108Serh
1461.193Slukem#
1471.137Stv# Targets (in order!) called by "make build".
1481.193Slukem#
1491.123Smrg
1501.156StvBUILDTARGETS+=	check-tools
1511.155Stv.if !defined(UPDATE) && !defined(NOCLEANDIR)
1521.155StvBUILDTARGETS+=	cleandir
1531.155Stv.endif
1541.149Stv.if ${MKOBJDIRS} != "no"
1551.137StvBUILDTARGETS+=	obj
1561.123Smrg.endif
1571.138Stv.if ${USETOOLS} == "yes"
1581.152StvBUILDTARGETS+=	do-tools
1591.131Stv.endif
1601.137Stv.if !defined(NODISTRIBDIRS)
1611.137StvBUILDTARGETS+=	do-distrib-dirs
1621.131Stv.endif
1631.137Stv.if !defined(NOINCLUDES)
1641.137StvBUILDTARGETS+=	includes
1651.131Stv.endif
1661.202SthorpejBUILDTARGETS+=	do-tools-compat
1671.204SthorpejBUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
1681.200SlukemBUILDTARGETS+=	do-obsolete
1691.131Stv
1701.193Slukem#
1711.137Stv# Enforce proper ordering of some rules.
1721.193Slukem#
1731.123Smrg
1741.137Stv.ORDER:		${BUILDTARGETS}
1751.137Stvincludes-lib:	includes-include includes-sys
1761.137Stvincludes-gnu:	includes-lib
1771.123Smrg
1781.193Slukem#
1791.137Stv# Build the system and install into DESTDIR.
1801.193Slukem#
1811.123Smrg
1821.191SlukemSTART_TIME!=	date
1831.191Slukem
1841.137Stvbuild:
1851.137Stv.if defined(BUILD_DONE)
1861.137Stv	@echo "Build already installed into ${DESTDIR}"
1871.137Stv.else
1881.191Slukem	@echo "Build started at: ${START_TIME}"
1891.145Stv.for tgt in ${BUILDTARGETS}
1901.173Ssommerfe	@(cd ${.CURDIR} && ${MAKE} ${tgt})
1911.145Stv.endfor
1921.191Slukem	@echo   "Build started at:  ${START_TIME}"
1931.172Sbjh21	@printf "Build finished at: " && date
1941.71Smycroft.endif
1951.160Sthorpej
1961.193Slukem#
1971.160Sthorpej# Build a full distribution, but not a release (i.e. no sets into
1981.193Slukem# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
1991.193Slukem#
2001.160Sthorpej
2011.193Slukemdistribution buildworld:
2021.194Slukem.if make(buildworld) && \
2031.194Slukem    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2041.193Slukem	@echo "Won't make ${.TARGET} with DESTDIR=/"
2051.193Slukem	@false
2061.193Slukem.endif
2071.182Suwe	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2081.160Sthorpej	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
2091.181Sthorpej.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
2101.181Sthorpej	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
2111.181Sthorpej.endif
2121.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2131.185Slukem	@printf "make ${.TARGET} finished at: " && date
2141.123Smrg
2151.193Slukem#
2161.193Slukem# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
2171.193Slukem# If installing to /, ensures that the host's operating system is NetBSD and
2181.193Slukem# the host's `uname -m` == ${MACHINE}.
2191.193Slukem#
2201.193Slukem
2211.193SlukemHOST_UNAME_S!=	uname -s
2221.193SlukemHOST_UNAME_M!=	uname -m
2231.193Slukem
2241.193Slukeminstallworld:
2251.194Slukem.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2261.193Slukem	@echo "Can't make ${.TARGET} to DESTDIR=/"
2271.193Slukem	@false
2281.193Slukem.endif
2291.193Slukem.if !defined(INSTALLWORLDDIR) || \
2301.193Slukem    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
2311.193Slukem.if (${HOST_UNAME_S} != "NetBSD")
2321.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
2331.193Slukem	@false
2341.193Slukem.endif
2351.193Slukem.if (${HOST_UNAME_M} != ${MACHINE})
2361.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
2371.193Slukem	@false
2381.193Slukem.endif
2391.193Slukem.endif
2401.193Slukem	(cd ${.CURDIR}/distrib/sets && \
2411.193Slukem	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
2421.193Slukem	(cd ${.CURDIR} && \
2431.193Slukem	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
2441.193Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2451.193Slukem	@printf "make ${.TARGET} finished at: " && date
2461.199Slukem
2471.199Slukem#
2481.199Slukem# Create sets from $DESTDIR into $RELEASEDIR
2491.199Slukem#
2501.199Slukem
2511.199Slukemsets:
2521.199Slukem	(cd ${.CURDIR}/distrib/sets && ${MAKE} maketars)
2531.193Slukem
2541.193Slukem#
2551.181Sthorpej# Build a release or snapshot (implies "make build").  Note that
2561.181Sthorpej# in this case, the set lists will be checked before the tar files
2571.181Sthorpej# are made.
2581.193Slukem#
2591.123Smrg
2601.179Sthorpejrelease snapshot:
2611.179Sthorpej	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2621.152Stv	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
2631.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2641.185Slukem	@printf "make ${.TARGET} finished at: " && date
2651.123Smrg
2661.193Slukem#
2671.137Stv# Special components of the "make build" process.
2681.193Slukem#
2691.156Stv
2701.156Stvcheck-tools:
2711.187Sthorpej.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
2721.187Sthorpej	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
2731.187Sthorpej	@echo '*** May result in a failed build or corrupt binaries!'
2741.187Sthorpej.elif defined(EXTERNAL_TOOLCHAIN)
2751.187Sthorpej	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
2761.156Stv.endif
2771.173Ssommerfe.if defined(NBUILDJOBS)
2781.173Ssommerfe	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
2791.173Ssommerfe.endif
2801.123Smrg
2811.137Stvdo-distrib-dirs:
2821.147Sjmc.if !defined(DESTDIR) || ${DESTDIR} == ""
2831.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
2841.147Sjmc.else
2851.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
2861.147Sjmc.endif
2871.190Slukem
2881.190Slukem.for targ in cleandir obj includes
2891.190Slukemdo-${targ}: ${targ}
2901.190Slukem	@true
2911.190Slukem.endfor
2921.123Smrg
2931.204Sthorpej.for dir in tools tools/compat lib/csu lib/libc lib gnu/lib
2941.143Stvdo-${dir:S/\//-/}:
2951.137Stv.for targ in dependall install
2961.173Ssommerfe	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
2971.137Stv.endfor
2981.184Slukem.endfor
2991.184Slukem
3001.189Sitohydo-ld.so:
3011.184Slukem.for targ in dependall install
3021.189Sitohy.if (${OBJECT_FMT} == "a.out")
3031.189Sitohy	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
3041.189Sitohy.endif
3051.189Sitohy.if (${OBJECT_FMT} == "ELF")
3061.184Slukem	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
3071.189Sitohy.endif
3081.137Stv.endfor
3091.143Stv
3101.143Stvdo-build:
3111.154Stv.for targ in dependall install
3121.173Ssommerfe	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
3131.154Stv.endfor
3141.200Slukem
3151.200Slukemdo-obsolete:
3161.200Slukem	(cd ${.CURDIR}/etc && ${MAKE} install-obsolete-lists)
3171.87Scjs
3181.193Slukem#
3191.137Stv# Speedup stubs for some subtrees that don't need to run these rules.
3201.137Stv# (Tells <bsd.subdir.mk> not to recurse for them.)
3211.193Slukem#
3221.129Stv
3231.152Stv.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
3241.152Stvincludes-${dir}:
3251.152Stv	@true
3261.152Stv.endfor
3271.152Stv.for dir in etc distrib regress
3281.152Stvinstall-${dir}:
3291.152Stv	@true
3301.152Stv.endfor
3311.152Stv
3321.193Slukem#
3331.152Stv# XXX this needs to change when distrib Makefiles are recursion compliant
3341.193Slukem# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
3351.193Slukem#
3361.152Stvdependall-distrib depend-distrib all-distrib:
3371.136Snathanw	@true
3381.130Stv
3391.151Stv.include <bsd.obj.mk>
3401.146Stv.include <bsd.subdir.mk>
3411.144Stv
3421.150Stvbuild-docs: ${.CURDIR}/BUILDING
3431.188Slukem${.CURDIR}/BUILDING: doc/BUILDING.mdoc
3441.150Stv	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
345