Makefile revision 1.202
11.202Sthorpej#	$NetBSD: Makefile,v 1.202 2003/04/04 01:06:00 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.201Smycroft#   do-lib-libcrypt: builds and installs prerequisites from lib/libcrypt.
671.143Stv#   do-lib:          builds and installs prerequisites from lib.
681.143Stv#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
691.189Sitohy#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
701.137Stv#   do-build:        builds and installs the entire system.
711.193Slukem#
721.32Scgd
731.146Stv.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
741.146Stv.MAKEFLAGS: -m ${.CURDIR}/share/mk
751.146Stv.endif
761.163Stv
771.193Slukem#
781.163Stv# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
791.163Stv# not be the top level objdir, because "make obj" can happen in the *middle*
801.163Stv# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
811.163Stv# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
821.193Slukem#
831.163Stv_SRC_TOP_OBJ_=
841.148Sjmc
851.146Stv.include <bsd.own.mk>
861.4Scgd
871.193Slukem#
881.137Stv# Sanity check: make sure that "make build" is not invoked simultaneously
891.137Stv# with a standard recursive target.
901.193Slukem#
911.137Stv
921.137Stv.if make(build) || make(release) || make(snapshot)
931.137Stv.for targ in ${TARGETS:Nobj:Ncleandir}
941.137Stv.if make(${targ}) && !target(.BEGIN)
951.137Stv.BEGIN:
961.137Stv	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
971.137Stv	@false
981.137Stv.endif
991.137Stv.endfor
1001.137Stv.endif
1011.58Stv
1021.166Ssimonb_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
1031.183Slukem_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
1041.105Sassar
1051.193Slukem#
1061.137Stv# Weed out directories that don't exist.
1071.193Slukem#
1081.36Sexplorer
1091.137Stv.for dir in ${_SUBDIR}
1101.154Stv.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
1111.137StvSUBDIR+=	${dir}
1121.36Sexplorer.endif
1131.137Stv.endfor
1141.21Scgd
1151.13Sbrezak.if exists(regress)
1161.10Scgdregression-tests:
1171.10Scgd	@echo Running regression tests...
1181.152Stv	@(cd ${.CURDIR}/regress && ${MAKE} regress)
1191.13Sbrezak.endif
1201.20Scgd
1211.179Sthorpej.if defined(UNPRIVED)
1221.179SthorpejNOPOSTINSTALL=	# defined
1231.179Sthorpej.endif
1241.179Sthorpej
1251.176Slukemafterinstall:
1261.137Stv.if ${MKMAN} != "no"
1271.152Stv	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
1281.137Stv.endif
1291.159Sperry.if defined(UNPRIVED) && (${MKINFO} != "no")
1301.164Sjmc	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
1311.176Slukem.endif
1321.179Sthorpej.if !defined(NOPOSTINSTALL)
1331.180Sdrochner	(cd ${.CURDIR} && ${MAKE} postinstall-check)
1341.159Sperry.endif
1351.170Slukem
1361.170Slukempostinstall-check:
1371.169Slukem	@echo "   === Post installation checks ==="
1381.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
1391.171Slukem	@echo "   ================================"
1401.171Slukem
1411.171Slukempostinstall-fix: .NOTMAIN
1421.171Slukem	@echo "   === Post installation fixes ==="
1431.175Slukem	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
1441.169Slukem	@echo "   ================================"
1451.169Slukem
1461.108Serh
1471.193Slukem#
1481.137Stv# Targets (in order!) called by "make build".
1491.193Slukem#
1501.123Smrg
1511.156StvBUILDTARGETS+=	check-tools
1521.155Stv.if !defined(UPDATE) && !defined(NOCLEANDIR)
1531.155StvBUILDTARGETS+=	cleandir
1541.155Stv.endif
1551.149Stv.if ${MKOBJDIRS} != "no"
1561.137StvBUILDTARGETS+=	obj
1571.123Smrg.endif
1581.138Stv.if ${USETOOLS} == "yes"
1591.152StvBUILDTARGETS+=	do-tools
1601.131Stv.endif
1611.137Stv.if !defined(NODISTRIBDIRS)
1621.137StvBUILDTARGETS+=	do-distrib-dirs
1631.131Stv.endif
1641.137Stv.if !defined(NOINCLUDES)
1651.137StvBUILDTARGETS+=	includes
1661.131Stv.endif
1671.202SthorpejBUILDTARGETS+=	do-tools-compat
1681.201SmycroftBUILDTARGETS+=	do-lib-csu do-lib-libc do-lib-libcrypt do-lib do-gnu-lib do-ld.so do-build
1691.200SlukemBUILDTARGETS+=	do-obsolete
1701.131Stv
1711.193Slukem#
1721.137Stv# Enforce proper ordering of some rules.
1731.193Slukem#
1741.123Smrg
1751.137Stv.ORDER:		${BUILDTARGETS}
1761.137Stvincludes-lib:	includes-include includes-sys
1771.137Stvincludes-gnu:	includes-lib
1781.123Smrg
1791.193Slukem#
1801.137Stv# Build the system and install into DESTDIR.
1811.193Slukem#
1821.123Smrg
1831.191SlukemSTART_TIME!=	date
1841.191Slukem
1851.137Stvbuild:
1861.137Stv.if defined(BUILD_DONE)
1871.137Stv	@echo "Build already installed into ${DESTDIR}"
1881.137Stv.else
1891.191Slukem	@echo "Build started at: ${START_TIME}"
1901.145Stv.for tgt in ${BUILDTARGETS}
1911.173Ssommerfe	@(cd ${.CURDIR} && ${MAKE} ${tgt})
1921.145Stv.endfor
1931.191Slukem	@echo   "Build started at:  ${START_TIME}"
1941.172Sbjh21	@printf "Build finished at: " && date
1951.71Smycroft.endif
1961.160Sthorpej
1971.193Slukem#
1981.160Sthorpej# Build a full distribution, but not a release (i.e. no sets into
1991.193Slukem# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
2001.193Slukem#
2011.160Sthorpej
2021.193Slukemdistribution buildworld:
2031.194Slukem.if make(buildworld) && \
2041.194Slukem    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2051.193Slukem	@echo "Won't make ${.TARGET} with DESTDIR=/"
2061.193Slukem	@false
2071.193Slukem.endif
2081.182Suwe	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2091.160Sthorpej	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
2101.181Sthorpej.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
2111.181Sthorpej	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
2121.181Sthorpej.endif
2131.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2141.185Slukem	@printf "make ${.TARGET} finished at: " && date
2151.123Smrg
2161.193Slukem#
2171.193Slukem# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
2181.193Slukem# If installing to /, ensures that the host's operating system is NetBSD and
2191.193Slukem# the host's `uname -m` == ${MACHINE}.
2201.193Slukem#
2211.193Slukem
2221.193SlukemHOST_UNAME_S!=	uname -s
2231.193SlukemHOST_UNAME_M!=	uname -m
2241.193Slukem
2251.193Slukeminstallworld:
2261.194Slukem.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
2271.193Slukem	@echo "Can't make ${.TARGET} to DESTDIR=/"
2281.193Slukem	@false
2291.193Slukem.endif
2301.193Slukem.if !defined(INSTALLWORLDDIR) || \
2311.193Slukem    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
2321.193Slukem.if (${HOST_UNAME_S} != "NetBSD")
2331.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
2341.193Slukem	@false
2351.193Slukem.endif
2361.193Slukem.if (${HOST_UNAME_M} != ${MACHINE})
2371.193Slukem	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
2381.193Slukem	@false
2391.193Slukem.endif
2401.193Slukem.endif
2411.193Slukem	(cd ${.CURDIR}/distrib/sets && \
2421.193Slukem	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
2431.193Slukem	(cd ${.CURDIR} && \
2441.193Slukem	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
2451.193Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2461.193Slukem	@printf "make ${.TARGET} finished at: " && date
2471.199Slukem
2481.199Slukem#
2491.199Slukem# Create sets from $DESTDIR into $RELEASEDIR
2501.199Slukem#
2511.199Slukem
2521.199Slukemsets:
2531.199Slukem	(cd ${.CURDIR}/distrib/sets && ${MAKE} maketars)
2541.193Slukem
2551.193Slukem#
2561.181Sthorpej# Build a release or snapshot (implies "make build").  Note that
2571.181Sthorpej# in this case, the set lists will be checked before the tar files
2581.181Sthorpej# are made.
2591.193Slukem#
2601.123Smrg
2611.179Sthorpejrelease snapshot:
2621.179Sthorpej	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
2631.152Stv	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
2641.192Slukem	@echo   "make ${.TARGET} started at:  ${START_TIME}"
2651.185Slukem	@printf "make ${.TARGET} finished at: " && date
2661.123Smrg
2671.193Slukem#
2681.137Stv# Special components of the "make build" process.
2691.193Slukem#
2701.156Stv
2711.156Stvcheck-tools:
2721.187Sthorpej.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
2731.187Sthorpej	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
2741.187Sthorpej	@echo '*** May result in a failed build or corrupt binaries!'
2751.187Sthorpej.elif defined(EXTERNAL_TOOLCHAIN)
2761.187Sthorpej	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
2771.156Stv.endif
2781.173Ssommerfe.if defined(NBUILDJOBS)
2791.173Ssommerfe	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
2801.173Ssommerfe.endif
2811.123Smrg
2821.137Stvdo-distrib-dirs:
2831.147Sjmc.if !defined(DESTDIR) || ${DESTDIR} == ""
2841.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
2851.147Sjmc.else
2861.152Stv	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
2871.147Sjmc.endif
2881.190Slukem
2891.190Slukem.for targ in cleandir obj includes
2901.190Slukemdo-${targ}: ${targ}
2911.190Slukem	@true
2921.190Slukem.endfor
2931.123Smrg
2941.202Sthorpej<<<<<<< Makefile
2951.202Sthorpej.for dir in tools tools/compat lib/csu lib/libc lib gnu/lib
2961.202Sthorpej=======
2971.201Smycroft.for dir in tools lib/csu lib/libc lib/libcrypt lib gnu/lib
2981.202Sthorpej>>>>>>> 1.201
2991.143Stvdo-${dir:S/\//-/}:
3001.137Stv.for targ in dependall install
3011.173Ssommerfe	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
3021.137Stv.endfor
3031.184Slukem.endfor
3041.184Slukem
3051.189Sitohydo-ld.so:
3061.184Slukem.for targ in dependall install
3071.189Sitohy.if (${OBJECT_FMT} == "a.out")
3081.189Sitohy	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
3091.189Sitohy.endif
3101.189Sitohy.if (${OBJECT_FMT} == "ELF")
3111.184Slukem	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
3121.189Sitohy.endif
3131.137Stv.endfor
3141.143Stv
3151.143Stvdo-build:
3161.154Stv.for targ in dependall install
3171.173Ssommerfe	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
3181.154Stv.endfor
3191.200Slukem
3201.200Slukemdo-obsolete:
3211.200Slukem	(cd ${.CURDIR}/etc && ${MAKE} install-obsolete-lists)
3221.87Scjs
3231.193Slukem#
3241.137Stv# Speedup stubs for some subtrees that don't need to run these rules.
3251.137Stv# (Tells <bsd.subdir.mk> not to recurse for them.)
3261.193Slukem#
3271.129Stv
3281.152Stv.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
3291.152Stvincludes-${dir}:
3301.152Stv	@true
3311.152Stv.endfor
3321.152Stv.for dir in etc distrib regress
3331.152Stvinstall-${dir}:
3341.152Stv	@true
3351.152Stv.endfor
3361.152Stv
3371.193Slukem#
3381.152Stv# XXX this needs to change when distrib Makefiles are recursion compliant
3391.193Slukem# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
3401.193Slukem#
3411.152Stvdependall-distrib depend-distrib all-distrib:
3421.136Snathanw	@true
3431.130Stv
3441.151Stv.include <bsd.obj.mk>
3451.146Stv.include <bsd.subdir.mk>
3461.144Stv
3471.150Stvbuild-docs: ${.CURDIR}/BUILDING
3481.188Slukem${.CURDIR}/BUILDING: doc/BUILDING.mdoc
3491.150Stv	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
350