Makefile revision 1.196
11.196Slukem#	$NetBSD: Makefile,v 1.196 2003/01/03 15:34:30 lukem 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.131Stv#   do-distrib-dirs: creates the distribution directories.
611.137Stv#   includes:        installs include files.
621.168Stv#   do-lib-csu:      builds and installs prerequisites from lib/csu.
631.186Sthorpej#   do-lib-libc:     builds and installs prerequisites from lib/libc.
641.143Stv#   do-lib:          builds and installs prerequisites from lib.
651.143Stv#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
661.189Sitohy#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
671.137Stv#   do-build:        builds and installs the entire system.
681.193Slukem#
691.32Scgd
701.146Stv.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
711.146Stv.MAKEFLAGS: -m ${.CURDIR}/share/mk
721.146Stv.endif
731.163Stv
741.193Slukem#
751.163Stv# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
761.163Stv# not be the top level objdir, because "make obj" can happen in the *middle*
771.163Stv# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
781.163Stv# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
791.193Slukem#
801.163Stv_SRC_TOP_OBJ_=
811.148Sjmc
821.146Stv.include <bsd.own.mk>
831.4Scgd
841.193Slukem#
851.137Stv# Sanity check: make sure that "make build" is not invoked simultaneously
861.137Stv# with a standard recursive target.
871.193Slukem#
881.137Stv
891.137Stv.if make(build) || make(release) || make(snapshot)
901.137Stv.for targ in ${TARGETS:Nobj:Ncleandir}
911.137Stv.if make(${targ}) && !target(.BEGIN)
921.137Stv.BEGIN:
931.137Stv	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
941.137Stv	@false
951.137Stv.endif
961.137Stv.endfor
971.137Stv.endif
981.58Stv
991.166Ssimonb_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
1001.183Slukem_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
1011.105Sassar
1021.193Slukem#
1031.137Stv# Weed out directories that don't exist.
1041.193Slukem#
1051.36Sexplorer
1061.137Stv.for dir in ${_SUBDIR}
1071.154Stv.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
1081.137StvSUBDIR+=	${dir}
1091.36Sexplorer.endif
1101.137Stv.endfor
1111.21Scgd
1121.13Sbrezak.if exists(regress)
1131.10Scgdregression-tests:
1141.10Scgd	@echo Running regression tests...
1151.152Stv	@(cd ${.CURDIR}/regress && ${MAKE} regress)
1161.13Sbrezak.endif
1171.20Scgd
1181.179Sthorpej.if defined(UNPRIVED)
1191.179SthorpejNOPOSTINSTALL=	# defined
1201.179Sthorpej.endif
1211.179Sthorpej
1221.176Slukemafterinstall:
1231.137Stv.if ${MKMAN} != "no"
1241.152Stv	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
1251.137Stv.endif
1261.159Sperry.if defined(UNPRIVED) && (${MKINFO} != "no")
1271.164Sjmc	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
1281.176Slukem.endif
1291.179Sthorpej.if !defined(NOPOSTINSTALL)
1301.180Sdrochner	(cd ${.CURDIR} && ${MAKE} postinstall-check)
1311.159Sperry.endif
1321.170Slukem
1331.170Slukempostinstall-check:
1341.169Slukem	@echo "   === Post installation checks ==="
1351.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
1361.171Slukem	@echo "   ================================"
1371.171Slukem
1381.171Slukempostinstall-fix: .NOTMAIN
1391.171Slukem	@echo "   === Post installation fixes ==="
1401.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
1411.169Slukem	@echo "   ================================"
1421.169Slukem
1431.108Serh
1441.193Slukem#
1451.137Stv# Targets (in order!) called by "make build".
1461.193Slukem#
1471.123Smrg
1481.156StvBUILDTARGETS+=	check-tools
1491.155Stv.if !defined(UPDATE) && !defined(NOCLEANDIR)
1501.155StvBUILDTARGETS+=	cleandir
1511.155Stv.endif
1521.149Stv.if ${MKOBJDIRS} != "no"
1531.137StvBUILDTARGETS+=	obj
1541.123Smrg.endif
1551.138Stv.if ${USETOOLS} == "yes"
1561.152StvBUILDTARGETS+=	do-tools
1571.131Stv.endif
1581.137Stv.if !defined(NODISTRIBDIRS)
1591.137StvBUILDTARGETS+=	do-distrib-dirs
1601.131Stv.endif
1611.137Stv.if !defined(NOINCLUDES)
1621.137StvBUILDTARGETS+=	includes
1631.131Stv.endif
1641.189SitohyBUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
1651.131Stv
1661.193Slukem#
1671.137Stv# Enforce proper ordering of some rules.
1681.193Slukem#
1691.123Smrg
1701.137Stv.ORDER:		${BUILDTARGETS}
1711.137Stvincludes-lib:	includes-include includes-sys
1721.137Stvincludes-gnu:	includes-lib
1731.123Smrg
1741.193Slukem#
1751.137Stv# Build the system and install into DESTDIR.
1761.193Slukem#
1771.123Smrg
1781.191SlukemSTART_TIME!=	date
1791.191Slukem
1801.137Stvbuild:
1811.137Stv.if defined(BUILD_DONE)
1821.137Stv	@echo "Build already installed into ${DESTDIR}"
1831.137Stv.else
1841.191Slukem	@echo "Build started at: ${START_TIME}"
1851.145Stv.for tgt in ${BUILDTARGETS}
1861.173Ssommerfe	@(cd ${.CURDIR} && ${MAKE} ${tgt})
1871.145Stv.endfor
1881.191Slukem	@echo   "Build started at:  ${START_TIME}"
1891.172Sbjh21	@printf "Build finished at: " && date
1901.71Smycroft.endif
1911.160Sthorpej
1921.193Slukem#
1931.160Sthorpej# Build a full distribution, but not a release (i.e. no sets into
1941.193Slukem# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
1951.193Slukem#
1961.160Sthorpej
1971.193Slukemdistribution buildworld:
1981.194Slukem.if make(buildworld) && \
1991.194Slukem    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2001.193Slukem	@echo "Won't make ${.TARGET} with DESTDIR=/"
2011.193Slukem	@false
2021.193Slukem.endif
2031.182Suwe	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2041.160Sthorpej	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
2051.181Sthorpej.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
2061.181Sthorpej	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
2071.181Sthorpej.endif
2081.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2091.185Slukem	@printf "make ${.TARGET} finished at: " && date
2101.123Smrg
2111.193Slukem#
2121.193Slukem# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
2131.193Slukem# If installing to /, ensures that the host's operating system is NetBSD and
2141.193Slukem# the host's `uname -m` == ${MACHINE}.
2151.193Slukem#
2161.193Slukem
2171.193SlukemHOST_UNAME_S!=	uname -s
2181.193SlukemHOST_UNAME_M!=	uname -m
2191.193Slukem
2201.193Slukeminstallworld:
2211.194Slukem.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2221.193Slukem	@echo "Can't make ${.TARGET} to DESTDIR=/"
2231.193Slukem	@false
2241.193Slukem.endif
2251.193Slukem.if !defined(INSTALLWORLDDIR) || \
2261.193Slukem    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
2271.193Slukem.if (${HOST_UNAME_S} != "NetBSD")
2281.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
2291.193Slukem	@false
2301.193Slukem.endif
2311.193Slukem.if (${HOST_UNAME_M} != ${MACHINE})
2321.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
2331.193Slukem	@false
2341.193Slukem.endif
2351.193Slukem.endif
2361.193Slukem	(cd ${.CURDIR}/distrib/sets && \
2371.193Slukem	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
2381.193Slukem	(cd ${.CURDIR} && \
2391.193Slukem	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
2401.193Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2411.193Slukem	@printf "make ${.TARGET} finished at: " && date
2421.193Slukem
2431.193Slukem#
2441.181Sthorpej# Build a release or snapshot (implies "make build").  Note that
2451.181Sthorpej# in this case, the set lists will be checked before the tar files
2461.181Sthorpej# are made.
2471.193Slukem#
2481.123Smrg
2491.179Sthorpejrelease snapshot:
2501.179Sthorpej	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2511.152Stv	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
2521.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2531.185Slukem	@printf "make ${.TARGET} finished at: " && date
2541.123Smrg
2551.193Slukem#
2561.137Stv# Special components of the "make build" process.
2571.193Slukem#
2581.156Stv
2591.156Stvcheck-tools:
2601.187Sthorpej.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
2611.187Sthorpej	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
2621.187Sthorpej	@echo '*** May result in a failed build or corrupt binaries!'
2631.187Sthorpej.elif defined(EXTERNAL_TOOLCHAIN)
2641.187Sthorpej	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
2651.156Stv.endif
2661.173Ssommerfe.if defined(NBUILDJOBS)
2671.173Ssommerfe	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
2681.173Ssommerfe.endif
2691.123Smrg
2701.137Stvdo-distrib-dirs:
2711.147Sjmc.if !defined(DESTDIR) || ${DESTDIR} == ""
2721.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
2731.147Sjmc.else
2741.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
2751.147Sjmc.endif
2761.190Slukem
2771.190Slukem.for targ in cleandir obj includes
2781.190Slukemdo-${targ}: ${targ}
2791.190Slukem	@true
2801.190Slukem.endfor
2811.123Smrg
2821.186Sthorpej.for dir in tools lib/csu lib/libc lib gnu/lib
2831.143Stvdo-${dir:S/\//-/}:
2841.137Stv.for targ in dependall install
2851.173Ssommerfe	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
2861.137Stv.endfor
2871.184Slukem.endfor
2881.184Slukem
2891.189Sitohydo-ld.so:
2901.184Slukem.for targ in dependall install
2911.189Sitohy.if (${OBJECT_FMT} == "a.out")
2921.189Sitohy	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
2931.189Sitohy.endif
2941.189Sitohy.if (${OBJECT_FMT} == "ELF")
2951.184Slukem	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
2961.189Sitohy.endif
2971.137Stv.endfor
2981.143Stv
2991.143Stvdo-build:
3001.154Stv.for targ in dependall install
3011.173Ssommerfe	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
3021.154Stv.endfor
3031.87Scjs
3041.193Slukem#
3051.137Stv# Speedup stubs for some subtrees that don't need to run these rules.
3061.137Stv# (Tells <bsd.subdir.mk> not to recurse for them.)
3071.193Slukem#
3081.129Stv
3091.152Stv.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
3101.152Stvincludes-${dir}:
3111.152Stv	@true
3121.152Stv.endfor
3131.152Stv.for dir in etc distrib regress
3141.152Stvinstall-${dir}:
3151.152Stv	@true
3161.152Stv.endfor
3171.152Stv
3181.193Slukem#
3191.152Stv# XXX this needs to change when distrib Makefiles are recursion compliant
3201.193Slukem# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
3211.193Slukem#
3221.152Stvdependall-distrib depend-distrib all-distrib:
3231.136Snathanw	@true
3241.130Stv
3251.195Satatat#
3261.195Satatat# we don't want the obj target in etc invoked as part of the normal
3271.195Satatat# course of events because that makes it too early.  therefore, define
3281.195Satatat# a neutral version of the target that bsd.subdir.mk would create.
3291.195Satatat#
3301.195Satatatobj-etc:
3311.195Satatat	@true
3321.195Satatat
3331.151Stv.include <bsd.obj.mk>
3341.146Stv.include <bsd.subdir.mk>
3351.195Satatat
3361.195Satatat#
3371.195Satatat# now, make a "real" target that will recurse into etc to enact the
3381.195Satatat# obj target, and .USE it onto the end of the obj handling for the
3391.195Satatat# current directory.  note that this is only done if we already have
3401.195Satatat# commands for the obj target (we won't if we're not making objdirs),
3411.195Satatat# and only if etc is a target subdirectory.
3421.195Satatat#
3431.195Satatat.if commands(obj) && (${SUBDIR:Metc} == "etc")
3441.195Satatatreal-obj-etc: .USE
3451.195Satatat	@(echo "obj ===> etc"; \
3461.195Satatat		cd ${.CURDIR}/etc && ${MAKE} obj)
3471.195Satatatobj: real-obj-etc
3481.195Satatat.endif
3491.144Stv
3501.150Stvbuild-docs: ${.CURDIR}/BUILDING
3511.188Slukem${.CURDIR}/BUILDING: doc/BUILDING.mdoc
3521.150Stv	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
353