Makefile revision 1.212
11.212Slukem#	$NetBSD: Makefile,v 1.212 2003/07/17 07:46:11 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.206Slukem#   sets:
561.206Slukem#	Populate ${RELEASEDIR}/${MACHINE}/binary/sets from ${DESTDIR}
571.206Slukem#   sourcesets:
581.206Slukem#	Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
591.123Smrg#
601.137Stv# Targets invoked by `make build,' in order:
611.155Stv#   cleandir:        cleans the tree.
621.137Stv#   obj:             creates object directories.
631.152Stv#   do-tools:        builds host toolchain.
641.208Slukem#   do-distrib-dirs: creates the distribution directories.
651.208Slukem#   includes:        installs include files.
661.202Sthorpej#   do-tools-compat: builds the "libnbcompat" library; needed for some
671.202Sthorpej#                    random host tool programs in the source tree.
681.208Slukem#   do-gnu-lib-libgcc: builds and installs prerequisites from gnu/lib/libgcc
691.168Stv#   do-lib-csu:      builds and installs prerequisites from lib/csu.
701.186Sthorpej#   do-lib-libc:     builds and installs prerequisites from lib/libc.
711.143Stv#   do-lib:          builds and installs prerequisites from lib.
721.143Stv#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
731.189Sitohy#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
741.137Stv#   do-build:        builds and installs the entire system.
751.208Slukem#   do-obsolete:     builds and installs the entire system.
761.193Slukem#
771.32Scgd
781.146Stv.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
791.146Stv.MAKEFLAGS: -m ${.CURDIR}/share/mk
801.146Stv.endif
811.163Stv
821.193Slukem#
831.163Stv# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
841.163Stv# not be the top level objdir, because "make obj" can happen in the *middle*
851.163Stv# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
861.163Stv# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
871.193Slukem#
881.163Stv_SRC_TOP_OBJ_=
891.148Sjmc
901.146Stv.include <bsd.own.mk>
911.4Scgd
921.193Slukem#
931.137Stv# Sanity check: make sure that "make build" is not invoked simultaneously
941.137Stv# with a standard recursive target.
951.193Slukem#
961.137Stv
971.137Stv.if make(build) || make(release) || make(snapshot)
981.137Stv.for targ in ${TARGETS:Nobj:Ncleandir}
991.137Stv.if make(${targ}) && !target(.BEGIN)
1001.137Stv.BEGIN:
1011.137Stv	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
1021.137Stv	@false
1031.137Stv.endif
1041.137Stv.endfor
1051.137Stv.endif
1061.58Stv
1071.166Ssimonb_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
1081.205Sthorpej_SUBDIR+=	usr.sbin share rescue sys etc .WAIT distrib regress
1091.105Sassar
1101.193Slukem#
1111.137Stv# Weed out directories that don't exist.
1121.193Slukem#
1131.36Sexplorer
1141.137Stv.for dir in ${_SUBDIR}
1151.154Stv.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
1161.137StvSUBDIR+=	${dir}
1171.36Sexplorer.endif
1181.137Stv.endfor
1191.21Scgd
1201.13Sbrezak.if exists(regress)
1211.10Scgdregression-tests:
1221.10Scgd	@echo Running regression tests...
1231.152Stv	@(cd ${.CURDIR}/regress && ${MAKE} regress)
1241.13Sbrezak.endif
1251.20Scgd
1261.179Sthorpej.if defined(UNPRIVED)
1271.179SthorpejNOPOSTINSTALL=	# defined
1281.179Sthorpej.endif
1291.179Sthorpej
1301.176Slukemafterinstall:
1311.137Stv.if ${MKMAN} != "no"
1321.152Stv	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
1331.137Stv.endif
1341.159Sperry.if defined(UNPRIVED) && (${MKINFO} != "no")
1351.164Sjmc	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
1361.176Slukem.endif
1371.179Sthorpej.if !defined(NOPOSTINSTALL)
1381.180Sdrochner	(cd ${.CURDIR} && ${MAKE} postinstall-check)
1391.159Sperry.endif
1401.170Slukem
1411.170Slukempostinstall-check:
1421.169Slukem	@echo "   === Post installation checks ==="
1431.212Slukem	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
1441.171Slukem	@echo "   ================================"
1451.171Slukem
1461.171Slukempostinstall-fix: .NOTMAIN
1471.171Slukem	@echo "   === Post installation fixes ==="
1481.212Slukem	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
1491.212Slukem	@echo "   ==============================="
1501.212Slukem
1511.212Slukempostinstall-fix-obsolete: .NOTMAIN
1521.212Slukem	@echo "   === Removing obsolete files ==="
1531.212Slukem	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix obsolete
1541.212Slukem	@echo "   ==============================="
1551.169Slukem
1561.108Serh
1571.193Slukem#
1581.137Stv# Targets (in order!) called by "make build".
1591.193Slukem#
1601.123Smrg
1611.156StvBUILDTARGETS+=	check-tools
1621.155Stv.if !defined(UPDATE) && !defined(NOCLEANDIR)
1631.155StvBUILDTARGETS+=	cleandir
1641.155Stv.endif
1651.149Stv.if ${MKOBJDIRS} != "no"
1661.137StvBUILDTARGETS+=	obj
1671.123Smrg.endif
1681.138Stv.if ${USETOOLS} == "yes"
1691.152StvBUILDTARGETS+=	do-tools
1701.131Stv.endif
1711.137Stv.if !defined(NODISTRIBDIRS)
1721.137StvBUILDTARGETS+=	do-distrib-dirs
1731.131Stv.endif
1741.137Stv.if !defined(NOINCLUDES)
1751.137StvBUILDTARGETS+=	includes
1761.131Stv.endif
1771.202SthorpejBUILDTARGETS+=	do-tools-compat
1781.207Sdrochner.if ${MKGCC} != "no"
1791.207SdrochnerBUILDTARGETS+=	do-gnu-lib-libgcc
1801.207Sdrochner.endif
1811.204SthorpejBUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
1821.200SlukemBUILDTARGETS+=	do-obsolete
1831.131Stv
1841.193Slukem#
1851.137Stv# Enforce proper ordering of some rules.
1861.193Slukem#
1871.123Smrg
1881.137Stv.ORDER:		${BUILDTARGETS}
1891.137Stvincludes-lib:	includes-include includes-sys
1901.137Stvincludes-gnu:	includes-lib
1911.123Smrg
1921.193Slukem#
1931.137Stv# Build the system and install into DESTDIR.
1941.193Slukem#
1951.123Smrg
1961.191SlukemSTART_TIME!=	date
1971.191Slukem
1981.137Stvbuild:
1991.137Stv.if defined(BUILD_DONE)
2001.137Stv	@echo "Build already installed into ${DESTDIR}"
2011.137Stv.else
2021.191Slukem	@echo "Build started at: ${START_TIME}"
2031.145Stv.for tgt in ${BUILDTARGETS}
2041.173Ssommerfe	@(cd ${.CURDIR} && ${MAKE} ${tgt})
2051.145Stv.endfor
2061.191Slukem	@echo   "Build started at:  ${START_TIME}"
2071.172Sbjh21	@printf "Build finished at: " && date
2081.71Smycroft.endif
2091.160Sthorpej
2101.193Slukem#
2111.160Sthorpej# Build a full distribution, but not a release (i.e. no sets into
2121.193Slukem# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
2131.193Slukem#
2141.160Sthorpej
2151.193Slukemdistribution buildworld:
2161.194Slukem.if make(buildworld) && \
2171.194Slukem    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2181.193Slukem	@echo "Won't make ${.TARGET} with DESTDIR=/"
2191.193Slukem	@false
2201.193Slukem.endif
2211.182Suwe	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2221.160Sthorpej	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
2231.181Sthorpej.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
2241.212Slukem	${MAKE} postinstall-fix-obsolete
2251.181Sthorpej	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
2261.181Sthorpej.endif
2271.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2281.185Slukem	@printf "make ${.TARGET} finished at: " && date
2291.123Smrg
2301.193Slukem#
2311.193Slukem# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
2321.193Slukem# If installing to /, ensures that the host's operating system is NetBSD and
2331.193Slukem# the host's `uname -m` == ${MACHINE}.
2341.193Slukem#
2351.193Slukem
2361.193SlukemHOST_UNAME_S!=	uname -s
2371.193SlukemHOST_UNAME_M!=	uname -m
2381.193Slukem
2391.193Slukeminstallworld:
2401.194Slukem.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2411.193Slukem	@echo "Can't make ${.TARGET} to DESTDIR=/"
2421.193Slukem	@false
2431.193Slukem.endif
2441.193Slukem.if !defined(INSTALLWORLDDIR) || \
2451.193Slukem    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
2461.193Slukem.if (${HOST_UNAME_S} != "NetBSD")
2471.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
2481.193Slukem	@false
2491.193Slukem.endif
2501.193Slukem.if (${HOST_UNAME_M} != ${MACHINE})
2511.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
2521.193Slukem	@false
2531.193Slukem.endif
2541.193Slukem.endif
2551.193Slukem	(cd ${.CURDIR}/distrib/sets && \
2561.193Slukem	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
2571.193Slukem	(cd ${.CURDIR} && \
2581.193Slukem	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
2591.193Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2601.193Slukem	@printf "make ${.TARGET} finished at: " && date
2611.199Slukem
2621.199Slukem#
2631.206Slukem# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
2641.199Slukem#
2651.199Slukem
2661.206Slukem.for tgt in sets sourcesets
2671.206Slukem${tgt}:
2681.206Slukem	(cd ${.CURDIR}/distrib/sets && ${MAKE} $@)
2691.206Slukem.endfor
2701.193Slukem
2711.193Slukem#
2721.181Sthorpej# Build a release or snapshot (implies "make build").  Note that
2731.181Sthorpej# in this case, the set lists will be checked before the tar files
2741.181Sthorpej# are made.
2751.193Slukem#
2761.123Smrg
2771.179Sthorpejrelease snapshot:
2781.179Sthorpej	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2791.152Stv	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
2801.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2811.185Slukem	@printf "make ${.TARGET} finished at: " && date
2821.123Smrg
2831.193Slukem#
2841.137Stv# Special components of the "make build" process.
2851.193Slukem#
2861.156Stv
2871.156Stvcheck-tools:
2881.187Sthorpej.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
2891.187Sthorpej	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
2901.187Sthorpej	@echo '*** May result in a failed build or corrupt binaries!'
2911.187Sthorpej.elif defined(EXTERNAL_TOOLCHAIN)
2921.187Sthorpej	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
2931.156Stv.endif
2941.173Ssommerfe.if defined(NBUILDJOBS)
2951.173Ssommerfe	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
2961.173Ssommerfe.endif
2971.123Smrg
2981.137Stvdo-distrib-dirs:
2991.147Sjmc.if !defined(DESTDIR) || ${DESTDIR} == ""
3001.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
3011.147Sjmc.else
3021.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
3031.147Sjmc.endif
3041.190Slukem
3051.190Slukem.for targ in cleandir obj includes
3061.190Slukemdo-${targ}: ${targ}
3071.190Slukem	@true
3081.190Slukem.endfor
3091.123Smrg
3101.207Sdrochner.for dir in tools tools/compat lib/csu gnu/lib/libgcc lib/libc lib gnu/lib
3111.207Sdrochnerdo-${dir:S/\//-/g}:
3121.137Stv.for targ in dependall install
3131.173Ssommerfe	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
3141.137Stv.endfor
3151.184Slukem.endfor
3161.184Slukem
3171.189Sitohydo-ld.so:
3181.184Slukem.for targ in dependall install
3191.189Sitohy.if (${OBJECT_FMT} == "a.out")
3201.189Sitohy	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
3211.189Sitohy.endif
3221.189Sitohy.if (${OBJECT_FMT} == "ELF")
3231.184Slukem	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
3241.189Sitohy.endif
3251.137Stv.endfor
3261.143Stv
3271.143Stvdo-build:
3281.154Stv.for targ in dependall install
3291.173Ssommerfe	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
3301.154Stv.endfor
3311.200Slukem
3321.200Slukemdo-obsolete:
3331.200Slukem	(cd ${.CURDIR}/etc && ${MAKE} install-obsolete-lists)
3341.87Scjs
3351.193Slukem#
3361.137Stv# Speedup stubs for some subtrees that don't need to run these rules.
3371.137Stv# (Tells <bsd.subdir.mk> not to recurse for them.)
3381.193Slukem#
3391.129Stv
3401.152Stv.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
3411.152Stvincludes-${dir}:
3421.152Stv	@true
3431.152Stv.endfor
3441.152Stv.for dir in etc distrib regress
3451.152Stvinstall-${dir}:
3461.152Stv	@true
3471.152Stv.endfor
3481.152Stv
3491.193Slukem#
3501.152Stv# XXX this needs to change when distrib Makefiles are recursion compliant
3511.193Slukem# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
3521.193Slukem#
3531.152Stvdependall-distrib depend-distrib all-distrib:
3541.136Snathanw	@true
3551.130Stv
3561.211Slukem.include <bsd.sys.mk>
3571.151Stv.include <bsd.obj.mk>
3581.209Slukem.include <bsd.kernobj.mk>
3591.146Stv.include <bsd.subdir.mk>
3601.144Stv
3611.150Stvbuild-docs: ${.CURDIR}/BUILDING
3621.188Slukem${.CURDIR}/BUILDING: doc/BUILDING.mdoc
3631.211Slukem	${TOOL_GROFF} -mdoc -Tascii -P-b -P-u -P-o $> >$@
3641.209Slukem
3651.209Slukem
3661.209Slukem#
3671.209Slukem# Display current make(1) parameters
3681.209Slukem#
3691.209Slukemparams:
3701.209Slukem.for var in	BSDSRCDIR BSDOBJDIR BUILDID DESTDIR EXTERNAL_TOOLCHAIN \
3711.209Slukem		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
3721.210Slukem		MACHINE MACHINE_ARCH MAKECONF MAKEFLAGS \
3731.210Slukem		MAKEOBJDIR MAKEOBJDIRPREFIX MKOBJDIRS \
3741.210Slukem		RELEASEDIR TOOLCHAIN_MISSING TOOLDIR \
3751.209Slukem		UNPRIVED UPDATE USETOOLS
3761.209Slukem.if defined(${var})
3771.209Slukem	@printf "%20s = '%-s'\n" ${var} ${${var}:Q}
3781.209Slukem.else
3791.209Slukem	@printf "%20s = (undefined)\n" ${var}
3801.209Slukem.endif
3811.209Slukem.endfor
382