Makefile revision 179309
112099Sjoerg#
291592Smarkm# $FreeBSD: head/Makefile 179309 2008-05-25 22:13:17Z jb $
312099Sjoerg#
412099Sjoerg# The user-driven targets are:
591592Smarkm#
612099Sjoerg# universe            - *Really* build *everything* (buildworld and
712099Sjoerg#                       all kernels on all architectures).
812099Sjoerg# buildworld          - Rebuild *everything*, including glue to help do
912099Sjoerg#                       upgrades.
1012099Sjoerg# installworld        - Install everything built by "buildworld".
1112099Sjoerg# world               - buildworld + installworld, no kernel.
1212099Sjoerg# buildkernel         - Rebuild the kernel and the kernel-modules.
1312099Sjoerg# installkernel       - Install the kernel and the kernel-modules.
1412099Sjoerg# installkernel.debug
1512099Sjoerg# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1612099Sjoerg# reinstallkernel.debug
1712099Sjoerg# kernel              - buildkernel + installkernel.
1812099Sjoerg# doxygen             - Build API documentation of the kernel, needs doxygen.
1912099Sjoerg# update              - Convenient way to update your source tree (cvs).
2012099Sjoerg# check-old           - List obsolete directories/files/libraries.
2112099Sjoerg# check-old-dirs      - List obsolete directories.
2212099Sjoerg# check-old-files     - List obsolete files.
2312099Sjoerg# check-old-libs      - List obsolete libraries.
2412099Sjoerg# delete-old          - Delete obsolete directories/files/libraries.
2512099Sjoerg# delete-old-dirs     - Delete obsolete directories.
2612099Sjoerg# delete-old-files    - Delete obsolete files.
2712099Sjoerg# delete-old-libs     - Delete obsolete libraries.
2812099Sjoerg#
2912099Sjoerg# This makefile is simple by design. The FreeBSD make automatically reads
3012099Sjoerg# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3112099Sjoerg# command line. By keeping this makefile simple, it doesn't matter too
3212099Sjoerg# much how different the installed mk files are from those in the source
3312099Sjoerg# tree. This makefile executes a child make process, forcing it to use
3412099Sjoerg# the mk files from the source tree which are supposed to DTRT.
3512099Sjoerg#
3691592Smarkm# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3791592Smarkm#
3891592Smarkm# If you want to build your system from source be sure that /usr/obj has
3912099Sjoerg# at least 800MB of diskspace available.
4091592Smarkm#
4112099Sjoerg# For individuals wanting to build from the sources currently on their
4212099Sjoerg# system, the simple instructions are:
4391592Smarkm#
4412099Sjoerg# 1.  `cd /usr/src'  (or to the directory containing your source tree).
4512099Sjoerg# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
4612099Sjoerg# 3.  `make world'
4712099Sjoerg#
4812099Sjoerg# For individuals wanting to upgrade their sources (even if only a
4912099Sjoerg# delta of a few days):
5012099Sjoerg#
5112099Sjoerg#  1.  `cd /usr/src'       (or to the directory containing your source tree).
5212099Sjoerg#  2.  `make buildworld'
5312099Sjoerg#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
5412099Sjoerg#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
5512099Sjoerg#       [steps 3. & 4. can be combined by using the "kernel" target]
5612099Sjoerg#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
5712099Sjoerg#  6.  `mergemaster -p'
5812099Sjoerg#  7.  `make installworld'
5912099Sjoerg#  8.  `make delete-old'
6012099Sjoerg#  9.  `mergemaster'                         (you may wish to use -U or -ai).
6112099Sjoerg# 10.  `reboot'
6291592Smarkm# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6391592Smarkm#
6491592Smarkm# See src/UPDATING `COMMON ITEMS' for more complete information.
6591592Smarkm#
6691592Smarkm# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
6712099Sjoerg# cross build world for other machine types using the buildworld target,
6891592Smarkm# and once the world is built you can cross build a kernel using the
6991592Smarkm# buildkernel target.
7091592Smarkm#
7191592Smarkm# Define the user-driven targets. These are listed here in alphabetical
7291592Smarkm# order, but that's not important.
7391592Smarkm#
7491592Smarkm# Targets that begin with underscore are internal targets intended for
7591592Smarkm# developer convenience only.  They are intentionally not documented and
7691592Smarkm# completely subject to change without notice.
7791592Smarkm#
7891592Smarkm# For more information, see the build(7) manual page.
7991592Smarkm#
8091592SmarkmTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
8191592Smarkm	check-old check-old-dirs check-old-files check-old-libs \
8291592Smarkm	checkdpadd clean cleandepend cleandir \
8391592Smarkm	delete-old delete-old-dirs delete-old-files delete-old-libs \
8491592Smarkm	depend distribute distributeworld distrib-dirs distribution doxygen \
8591592Smarkm	everything hierarchy install installcheck installkernel \
8691592Smarkm	installkernel.debug reinstallkernel reinstallkernel.debug \
8791592Smarkm	installworld kernel-toolchain libraries lint maninstall \
8891592Smarkm	obj objlink regress rerelease showconfig tags toolchain update \
8991592Smarkm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
9091592Smarkm	_build-tools _cross-tools _includes _libraries _depend \
9191592Smarkm	build32 distribute32 install32
9291592SmarkmTGTS+=	${SUBDIR_TARGETS}
9391592Smarkm
9491592SmarkmBITGTS=	files includes
9591592SmarkmBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
9691592SmarkmTGTS+=	${BITGTS}
9791592Smarkm
9891592Smarkm.ORDER: buildworld installworld
9991592Smarkm.ORDER: buildworld distributeworld
10091592Smarkm.ORDER: buildworld buildkernel
10191592Smarkm.ORDER: buildkernel installkernel
10291592Smarkm.ORDER: buildkernel installkernel.debug
10391592Smarkm.ORDER: buildkernel reinstallkernel
10491592Smarkm.ORDER: buildkernel reinstallkernel.debug
10591592Smarkm
10691592SmarkmPATH=	/sbin:/bin:/usr/sbin:/usr/bin
10791592SmarkmMAKEOBJDIRPREFIX?=	/usr/obj
10812099Sjoerg_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
10912099Sjoerg    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
11012099Sjoerg    -f /dev/null -V MAKEOBJDIRPREFIX dummy
11112099Sjoerg.if !empty(_MAKEOBJDIRPREFIX)
11212099Sjoerg.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
11312099Sjoerg	(in make.conf(5)) or command-line variable.
11412099Sjoerg.endif
11512099SjoergMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
11612099SjoergBINMAKE= \
11712099Sjoerg	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
11812099Sjoerg	-m ${.CURDIR}/share/mk
11912099Sjoerg_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12012099Sjoerg
12112099Sjoerg#
12212099Sjoerg# Make sure we have an up-to-date make(1). Only world and buildworld
12312099Sjoerg# should do this as those are the initial targets used for upgrades.
12412099Sjoerg# The user can define ALWAYS_CHECK_MAKE to have this check performed
12512099Sjoerg# for all targets.
12612099Sjoerg#
12712099Sjoerg.if defined(ALWAYS_CHECK_MAKE)
12812099Sjoerg${TGTS}: upgrade_checks
12912099Sjoerg.else
13012099Sjoergbuildworld: upgrade_checks
13112099Sjoerg.endif
13212099Sjoerg
13312099Sjoerg#
13412099Sjoerg# This 'cleanworld' target is not included in TGTS, because it is not a
13512099Sjoerg# recursive target.  All of the work for it is done right here.   It is
13612099Sjoerg# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
13712099Sjoerg# created by bsd.obj.mk, except that we don't want to .include that file
13812099Sjoerg# in this makefile.  
13912099Sjoerg#
14012099Sjoerg# In the following, the first 'rm' in a series will usually remove all
14112099Sjoerg# files and directories.  If it does not, then there are probably some
14212099Sjoerg# files with chflags set, so this unsets them and tries the 'rm' a
14312099Sjoerg# second time.  There are situations where this target will be cleaning
14412099Sjoerg# some directories via more than one method, but that duplication is
14512099Sjoerg# needed to correctly handle all the possible situations.
14612099Sjoerg#
14712099SjoergBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
14812099Sjoergcleanworld:
14912099Sjoerg.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
15012099Sjoerg.if exists(${BW_CANONICALOBJDIR}/)
15112099Sjoerg	-rm -rf ${BW_CANONICALOBJDIR}/*
15212099Sjoerg	-chflags -R 0 ${BW_CANONICALOBJDIR}
15312099Sjoerg	rm -rf ${BW_CANONICALOBJDIR}/*
15412099Sjoerg.endif
15512099Sjoerg	#   To be safe in this case, fall back to a 'make cleandir'
15612099Sjoerg	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
15712099Sjoerg.else
15812099Sjoerg	-rm -rf ${.OBJDIR}/*
15912099Sjoerg	-chflags -R 0 ${.OBJDIR}
16012099Sjoerg	rm -rf ${.OBJDIR}/*
16112099Sjoerg.endif
16212099Sjoerg
16312099Sjoerg#
16412099Sjoerg# Handle the user-driven targets, using the source relative mk files.
16512099Sjoerg#
16612099Sjoerg
16712099Sjoerg${TGTS}:
16812099Sjoerg	${_+_}@cd ${.CURDIR}; \
16912099Sjoerg		${_MAKE} ${.TARGET}
17012099Sjoerg
17112099Sjoerg# Set a reasonable default
17212099Sjoerg.MAIN:	all
17312099Sjoerg
17412099SjoergSTARTTIME!= LC_ALL=C date
17512099SjoergCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
17612099Sjoerg.if !empty(CHECK_TIME)
17712099Sjoerg.error check your date/time: ${STARTTIME}
17891592Smarkm.endif
17912099Sjoerg
18012099Sjoerg.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18112099Sjoerg#
18212099Sjoerg# world
18312099Sjoerg#
18412099Sjoerg# Attempt to rebuild and reinstall everything. This target is not to be
18512099Sjoerg# used for upgrading an existing FreeBSD system, because the kernel is
18612099Sjoerg# not included. One can argue that this target doesn't build everything
18712099Sjoerg# then.
18812099Sjoerg#
18912099Sjoergworld: upgrade_checks
19012099Sjoerg	@echo "--------------------------------------------------------------"
19112099Sjoerg	@echo ">>> make world started on ${STARTTIME}"
19212099Sjoerg	@echo "--------------------------------------------------------------"
19312099Sjoerg.if target(pre-world)
19412099Sjoerg	@echo
19512099Sjoerg	@echo "--------------------------------------------------------------"
19612099Sjoerg	@echo ">>> Making 'pre-world' target"
19712099Sjoerg	@echo "--------------------------------------------------------------"
19812099Sjoerg	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
19912099Sjoerg.endif
20012099Sjoerg	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
20112099Sjoerg	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20212099Sjoerg.if target(post-world)
20312099Sjoerg	@echo
20412099Sjoerg	@echo "--------------------------------------------------------------"
20512099Sjoerg	@echo ">>> Making 'post-world' target"
20612099Sjoerg	@echo "--------------------------------------------------------------"
20712099Sjoerg	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
20812099Sjoerg.endif
20912099Sjoerg	@echo
21012099Sjoerg	@echo "--------------------------------------------------------------"
21112099Sjoerg	@echo ">>> make world completed on `LC_ALL=C date`"
21212099Sjoerg	@echo "                   (started ${STARTTIME})"
21312099Sjoerg	@echo "--------------------------------------------------------------"
21412099Sjoerg.else
21512099Sjoergworld:
21612099Sjoerg	@echo "WARNING: make world will overwrite your existing FreeBSD"
21712099Sjoerg	@echo "installation without also building and installing a new"
21812099Sjoerg	@echo "kernel.  This can be dangerous.  Please read the handbook,"
21912099Sjoerg	@echo "'Rebuilding world', for how to upgrade your system."
22012099Sjoerg	@echo "Define DESTDIR to where you want to install FreeBSD,"
22112099Sjoerg	@echo "including /, to override this warning and proceed as usual."
22212099Sjoerg	@echo ""
22312099Sjoerg	@echo "Bailing out now..."
22412099Sjoerg	@false
22512099Sjoerg.endif
22612099Sjoerg
22712099Sjoerg#
22812099Sjoerg# kernel
22912099Sjoerg#
23012099Sjoerg# Short hand for `make buildkernel installkernel'
23112099Sjoerg#
23212099Sjoergkernel: buildkernel installkernel
23312099Sjoerg
23412099Sjoerg#
23512099Sjoerg# Perform a few tests to determine if the installed tools are adequate
23612099Sjoerg# for building the world.
23712099Sjoerg#
23812099Sjoergupgrade_checks:
23912099Sjoerg	@if ! (cd ${.CURDIR}/tools/build/make_check && \
24012099Sjoerg	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
24112099Sjoerg	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
24212099Sjoerg	then \
24312099Sjoerg	    (cd ${.CURDIR} && ${MAKE} make); \
24412099Sjoerg	fi
24512099Sjoerg
24612099Sjoerg#
24712099Sjoerg# Upgrade make(1) to the current version using the installed
24812099Sjoerg# headers, libraries and tools.  Also, allow the location of
24912099Sjoerg# the system bsdmake-like utility to be overridden.
25012099Sjoerg#
25112099SjoergMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
25212099Sjoerg		DESTDIR= \
25312099Sjoerg		INSTALL="sh ${.CURDIR}/tools/install.sh"
25412099SjoergMMAKE=		${MMAKEENV} ${MAKE} \
25591592Smarkm		-D_UPGRADING \
25612099Sjoerg		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
25712099Sjoerg		-DNO_CPU_CFLAGS -DNO_WERROR
25812099Sjoerg
25912099Sjoergmake: .PHONY
26012099Sjoerg	@echo
26112099Sjoerg	@echo "--------------------------------------------------------------"
26212099Sjoerg	@echo ">>> Building an up-to-date make(1)"
26312099Sjoerg	@echo "--------------------------------------------------------------"
26412099Sjoerg	${_+_}@cd ${.CURDIR}/usr.bin/make; \
26512099Sjoerg		${MMAKE} obj && \
26612099Sjoerg		${MMAKE} depend && \
26712099Sjoerg		${MMAKE} all && \
26812099Sjoerg		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
26912099Sjoerg
27012099Sjoerg#
27112099Sjoerg# universe
27212099Sjoerg#
27312099Sjoerg# Attempt to rebuild *everything* for all supported architectures,
27412099Sjoerg# with a reasonable chance of success, regardless of how old your
27512099Sjoerg# existing system is.
27612099Sjoerg#
27712099Sjoerg.if make(universe)
27812099SjoergTARGETS?=amd64 arm i386 ia64 pc98 powerpc sparc64 sun4v
27991592Smarkm
28091592Smarkmuniverse: universe_prologue
28112099Sjoerguniverse_prologue:
28291592Smarkm	@echo "--------------------------------------------------------------"
28312099Sjoerg	@echo ">>> make universe started on ${STARTTIME}"
28412099Sjoerg	@echo "--------------------------------------------------------------"
28512099Sjoerg.for target in ${TARGETS}
28691592SmarkmKERNCONFS!=	cd ${.CURDIR}/sys/${target}/conf && \
28712099Sjoerg		find [A-Z]*[A-Z] -type f -maxdepth 0 \
28812099Sjoerg		! -name DEFAULTS ! -name LINT
28912099SjoergKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
29012099Sjoerguniverse: universe_${target}
29112099Sjoerg.ORDER: universe_prologue universe_${target} universe_epilogue
29212099Sjoerguniverse_${target}:
29312099Sjoerg.if !defined(MAKE_JUST_KERNELS)
29412099Sjoerg	@echo ">> ${target} started on `LC_ALL=C date`"
29512099Sjoerg	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
29612099Sjoerg	    TARGET=${target} \
29712099Sjoerg	    __MAKE_CONF=/dev/null \
29812099Sjoerg	    > _.${target}.buildworld 2>&1
29912099Sjoerg	@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
30012099Sjoerg.endif
30112099Sjoerg.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
30212099Sjoerg	-cd ${.CURDIR}/sys/${target}/conf && ${MAKE} LINT \
30312099Sjoerg	    > ${.CURDIR}/_.${target}.makeLINT 2>&1
30412099Sjoerg.endif
30512099Sjoerg.for kernel in ${KERNCONFS}
30612099Sjoerg	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
30712099Sjoerg	    TARGET=${target} \
30812099Sjoerg	    KERNCONF=${kernel} \
30912099Sjoerg	    __MAKE_CONF=/dev/null \
31012099Sjoerg	    > _.${target}.${kernel} 2>&1
31112099Sjoerg.endfor
31212099Sjoerg	@echo ">> ${target} completed on `LC_ALL=C date`"
31312099Sjoerg.endfor
31412099Sjoerguniverse: universe_epilogue
31512099Sjoerguniverse_epilogue:
31612099Sjoerg	@echo "--------------------------------------------------------------"
31712099Sjoerg	@echo ">>> make universe completed on `LC_ALL=C date`"
31812099Sjoerg	@echo "                      (started ${STARTTIME})"
31912099Sjoerg	@echo "--------------------------------------------------------------"
32012099Sjoerg.endif
32112099Sjoerg