Makefile revision 1.195
11.195Satatat#	$NetBSD: Makefile,v 1.195 2003/01/02 23:15:27 atatat 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.137Stv#	Builds a full release of NetBSD in DESTDIR.  If BUILD_DONE is
371.110Sjlam#	set, this is an empty target.
381.137Stv#   release:
391.137Stv#	Does a `make build,' and then tars up the DESTDIR files
401.95Scjs#	into RELEASEDIR, in release(7) format. (See etc/Makefile for
411.95Scjs#	more information on this.)
421.137Stv#   regression-tests:
431.137Stv#	Runs the regression tests in "regress" on this host.
441.123Smrg#
451.137Stv# Targets invoked by `make build,' in order:
461.155Stv#   cleandir:        cleans the tree.
471.137Stv#   obj:             creates object directories.
481.152Stv#   do-tools:        builds host toolchain.
491.131Stv#   do-distrib-dirs: creates the distribution directories.
501.137Stv#   includes:        installs include files.
511.168Stv#   do-lib-csu:      builds and installs prerequisites from lib/csu.
521.186Sthorpej#   do-lib-libc:     builds and installs prerequisites from lib/libc.
531.143Stv#   do-lib:          builds and installs prerequisites from lib.
541.143Stv#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
551.189Sitohy#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
561.137Stv#   do-build:        builds and installs the entire system.
571.193Slukem#
581.32Scgd
591.146Stv.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
601.146Stv.MAKEFLAGS: -m ${.CURDIR}/share/mk
611.146Stv.endif
621.163Stv
631.193Slukem#
641.163Stv# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
651.163Stv# not be the top level objdir, because "make obj" can happen in the *middle*
661.163Stv# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
671.163Stv# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
681.193Slukem#
691.163Stv_SRC_TOP_OBJ_=
701.148Sjmc
711.146Stv.include <bsd.own.mk>
721.4Scgd
731.193Slukem#
741.137Stv# Sanity check: make sure that "make build" is not invoked simultaneously
751.137Stv# with a standard recursive target.
761.193Slukem#
771.137Stv
781.137Stv.if make(build) || make(release) || make(snapshot)
791.137Stv.for targ in ${TARGETS:Nobj:Ncleandir}
801.137Stv.if make(${targ}) && !target(.BEGIN)
811.137Stv.BEGIN:
821.137Stv	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
831.137Stv	@false
841.137Stv.endif
851.137Stv.endfor
861.137Stv.endif
871.58Stv
881.166Ssimonb_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
891.183Slukem_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
901.105Sassar
911.193Slukem#
921.137Stv# Weed out directories that don't exist.
931.193Slukem#
941.36Sexplorer
951.137Stv.for dir in ${_SUBDIR}
961.154Stv.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
971.137StvSUBDIR+=	${dir}
981.36Sexplorer.endif
991.137Stv.endfor
1001.21Scgd
1011.13Sbrezak.if exists(regress)
1021.10Scgdregression-tests:
1031.10Scgd	@echo Running regression tests...
1041.152Stv	@(cd ${.CURDIR}/regress && ${MAKE} regress)
1051.13Sbrezak.endif
1061.20Scgd
1071.179Sthorpej.if defined(UNPRIVED)
1081.179SthorpejNOPOSTINSTALL=	# defined
1091.179Sthorpej.endif
1101.179Sthorpej
1111.176Slukemafterinstall:
1121.137Stv.if ${MKMAN} != "no"
1131.152Stv	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
1141.137Stv.endif
1151.159Sperry.if defined(UNPRIVED) && (${MKINFO} != "no")
1161.164Sjmc	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
1171.176Slukem.endif
1181.179Sthorpej.if !defined(NOPOSTINSTALL)
1191.180Sdrochner	(cd ${.CURDIR} && ${MAKE} postinstall-check)
1201.159Sperry.endif
1211.170Slukem
1221.170Slukempostinstall-check:
1231.169Slukem	@echo "   === Post installation checks ==="
1241.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
1251.171Slukem	@echo "   ================================"
1261.171Slukem
1271.171Slukempostinstall-fix: .NOTMAIN
1281.171Slukem	@echo "   === Post installation fixes ==="
1291.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
1301.169Slukem	@echo "   ================================"
1311.169Slukem
1321.108Serh
1331.193Slukem#
1341.137Stv# Targets (in order!) called by "make build".
1351.193Slukem#
1361.123Smrg
1371.156StvBUILDTARGETS+=	check-tools
1381.155Stv.if !defined(UPDATE) && !defined(NOCLEANDIR)
1391.155StvBUILDTARGETS+=	cleandir
1401.155Stv.endif
1411.149Stv.if ${MKOBJDIRS} != "no"
1421.137StvBUILDTARGETS+=	obj
1431.123Smrg.endif
1441.138Stv.if ${USETOOLS} == "yes"
1451.152StvBUILDTARGETS+=	do-tools
1461.131Stv.endif
1471.137Stv.if !defined(NODISTRIBDIRS)
1481.137StvBUILDTARGETS+=	do-distrib-dirs
1491.131Stv.endif
1501.137Stv.if !defined(NOINCLUDES)
1511.137StvBUILDTARGETS+=	includes
1521.131Stv.endif
1531.189SitohyBUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
1541.131Stv
1551.193Slukem#
1561.137Stv# Enforce proper ordering of some rules.
1571.193Slukem#
1581.123Smrg
1591.137Stv.ORDER:		${BUILDTARGETS}
1601.137Stvincludes-lib:	includes-include includes-sys
1611.137Stvincludes-gnu:	includes-lib
1621.123Smrg
1631.193Slukem#
1641.137Stv# Build the system and install into DESTDIR.
1651.193Slukem#
1661.123Smrg
1671.191SlukemSTART_TIME!=	date
1681.191Slukem
1691.137Stvbuild:
1701.137Stv.if defined(BUILD_DONE)
1711.137Stv	@echo "Build already installed into ${DESTDIR}"
1721.137Stv.else
1731.191Slukem	@echo "Build started at: ${START_TIME}"
1741.145Stv.for tgt in ${BUILDTARGETS}
1751.173Ssommerfe	@(cd ${.CURDIR} && ${MAKE} ${tgt})
1761.145Stv.endfor
1771.191Slukem	@echo   "Build started at:  ${START_TIME}"
1781.172Sbjh21	@printf "Build finished at: " && date
1791.71Smycroft.endif
1801.160Sthorpej
1811.193Slukem#
1821.160Sthorpej# Build a full distribution, but not a release (i.e. no sets into
1831.193Slukem# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
1841.193Slukem#
1851.160Sthorpej
1861.193Slukemdistribution buildworld:
1871.194Slukem.if make(buildworld) && \
1881.194Slukem    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
1891.193Slukem	@echo "Won't make ${.TARGET} with DESTDIR=/"
1901.193Slukem	@false
1911.193Slukem.endif
1921.182Suwe	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
1931.160Sthorpej	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
1941.181Sthorpej.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
1951.181Sthorpej	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
1961.181Sthorpej.endif
1971.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
1981.185Slukem	@printf "make ${.TARGET} finished at: " && date
1991.123Smrg
2001.193Slukem#
2011.193Slukem# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
2021.193Slukem# If installing to /, ensures that the host's operating system is NetBSD and
2031.193Slukem# the host's `uname -m` == ${MACHINE}.
2041.193Slukem#
2051.193Slukem
2061.193SlukemHOST_UNAME_S!=	uname -s
2071.193SlukemHOST_UNAME_M!=	uname -m
2081.193Slukem
2091.193Slukeminstallworld:
2101.194Slukem.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2111.193Slukem	@echo "Can't make ${.TARGET} to DESTDIR=/"
2121.193Slukem	@false
2131.193Slukem.endif
2141.193Slukem.if !defined(INSTALLWORLDDIR) || \
2151.193Slukem    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
2161.193Slukem.if (${HOST_UNAME_S} != "NetBSD")
2171.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
2181.193Slukem	@false
2191.193Slukem.endif
2201.193Slukem.if (${HOST_UNAME_M} != ${MACHINE})
2211.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
2221.193Slukem	@false
2231.193Slukem.endif
2241.193Slukem.endif
2251.193Slukem	(cd ${.CURDIR}/distrib/sets && \
2261.193Slukem	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
2271.193Slukem	(cd ${.CURDIR} && \
2281.193Slukem	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
2291.193Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2301.193Slukem	@printf "make ${.TARGET} finished at: " && date
2311.193Slukem
2321.193Slukem#
2331.181Sthorpej# Build a release or snapshot (implies "make build").  Note that
2341.181Sthorpej# in this case, the set lists will be checked before the tar files
2351.181Sthorpej# are made.
2361.193Slukem#
2371.123Smrg
2381.179Sthorpejrelease snapshot:
2391.179Sthorpej	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2401.152Stv	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
2411.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2421.185Slukem	@printf "make ${.TARGET} finished at: " && date
2431.123Smrg
2441.193Slukem#
2451.137Stv# Special components of the "make build" process.
2461.193Slukem#
2471.156Stv
2481.156Stvcheck-tools:
2491.187Sthorpej.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
2501.187Sthorpej	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
2511.187Sthorpej	@echo '*** May result in a failed build or corrupt binaries!'
2521.187Sthorpej.elif defined(EXTERNAL_TOOLCHAIN)
2531.187Sthorpej	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
2541.156Stv.endif
2551.173Ssommerfe.if defined(NBUILDJOBS)
2561.173Ssommerfe	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
2571.173Ssommerfe.endif
2581.123Smrg
2591.137Stvdo-distrib-dirs:
2601.147Sjmc.if !defined(DESTDIR) || ${DESTDIR} == ""
2611.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
2621.147Sjmc.else
2631.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
2641.147Sjmc.endif
2651.190Slukem
2661.190Slukem.for targ in cleandir obj includes
2671.190Slukemdo-${targ}: ${targ}
2681.190Slukem	@true
2691.190Slukem.endfor
2701.123Smrg
2711.186Sthorpej.for dir in tools lib/csu lib/libc lib gnu/lib
2721.143Stvdo-${dir:S/\//-/}:
2731.137Stv.for targ in dependall install
2741.173Ssommerfe	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
2751.137Stv.endfor
2761.184Slukem.endfor
2771.184Slukem
2781.189Sitohydo-ld.so:
2791.184Slukem.for targ in dependall install
2801.189Sitohy.if (${OBJECT_FMT} == "a.out")
2811.189Sitohy	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
2821.189Sitohy.endif
2831.189Sitohy.if (${OBJECT_FMT} == "ELF")
2841.184Slukem	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
2851.189Sitohy.endif
2861.137Stv.endfor
2871.143Stv
2881.143Stvdo-build:
2891.154Stv.for targ in dependall install
2901.173Ssommerfe	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
2911.154Stv.endfor
2921.87Scjs
2931.193Slukem#
2941.137Stv# Speedup stubs for some subtrees that don't need to run these rules.
2951.137Stv# (Tells <bsd.subdir.mk> not to recurse for them.)
2961.193Slukem#
2971.129Stv
2981.152Stv.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
2991.152Stvincludes-${dir}:
3001.152Stv	@true
3011.152Stv.endfor
3021.152Stv.for dir in etc distrib regress
3031.152Stvinstall-${dir}:
3041.152Stv	@true
3051.152Stv.endfor
3061.152Stv
3071.193Slukem#
3081.152Stv# XXX this needs to change when distrib Makefiles are recursion compliant
3091.193Slukem# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
3101.193Slukem#
3111.152Stvdependall-distrib depend-distrib all-distrib:
3121.136Snathanw	@true
3131.130Stv
3141.195Satatat#
3151.195Satatat# we don't want the obj target in etc invoked as part of the normal
3161.195Satatat# course of events because that makes it too early.  therefore, define
3171.195Satatat# a neutral version of the target that bsd.subdir.mk would create.
3181.195Satatat#
3191.195Satatatobj-etc:
3201.195Satatat	@true
3211.195Satatat
3221.151Stv.include <bsd.obj.mk>
3231.146Stv.include <bsd.subdir.mk>
3241.195Satatat
3251.195Satatat#
3261.195Satatat# now, make a "real" target that will recurse into etc to enact the
3271.195Satatat# obj target, and .USE it onto the end of the obj handling for the
3281.195Satatat# current directory.  note that this is only done if we already have
3291.195Satatat# commands for the obj target (we won't if we're not making objdirs),
3301.195Satatat# and only if etc is a target subdirectory.
3311.195Satatat#
3321.195Satatat.if commands(obj) && (${SUBDIR:Metc} == "etc")
3331.195Satatatreal-obj-etc: .USE
3341.195Satatat	@(echo "obj ===> etc"; \
3351.195Satatat		cd ${.CURDIR}/etc && ${MAKE} obj)
3361.195Satatatobj: real-obj-etc
3371.195Satatat.endif
3381.144Stv
3391.150Stvbuild-docs: ${.CURDIR}/BUILDING
3401.188Slukem${.CURDIR}/BUILDING: doc/BUILDING.mdoc
3411.150Stv	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
342