Makefile revision 209128
136865Sdfr#
236865Sdfr# $FreeBSD: head/Makefile 209128 2010-06-13 13:02:43Z raj $
336865Sdfr#
436865Sdfr# The user-driven targets are:
536865Sdfr#
636865Sdfr# universe            - *Really* build *everything* (buildworld and
736865Sdfr#                       all kernels on all architectures).
836865Sdfr# buildworld          - Rebuild *everything*, including glue to help do
936865Sdfr#                       upgrades.
1036865Sdfr# installworld        - Install everything built by "buildworld".
1136865Sdfr# world               - buildworld + installworld, no kernel.
1236865Sdfr# buildkernel         - Rebuild the kernel and the kernel-modules.
1336865Sdfr# installkernel       - Install the kernel and the kernel-modules.
1436865Sdfr# installkernel.debug
1536865Sdfr# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1636865Sdfr# reinstallkernel.debug
1736865Sdfr# kernel              - buildkernel + installkernel.
1836865Sdfr# kernel-toolchain    - Builds the subset of world necessary to build a kernel
1936865Sdfr# doxygen             - Build API documentation of the kernel, needs doxygen.
2036865Sdfr# update              - Convenient way to update your source tree (cvs).
2136865Sdfr# check-old           - List obsolete directories/files/libraries.
2236865Sdfr# check-old-dirs      - List obsolete directories.
2336865Sdfr# check-old-files     - List obsolete files.
2436865Sdfr# check-old-libs      - List obsolete libraries.
2536865Sdfr# delete-old          - Delete obsolete directories/files/libraries.
2636865Sdfr# delete-old-dirs     - Delete obsolete directories.
2736865Sdfr# delete-old-files    - Delete obsolete files.
2836865Sdfr# delete-old-libs     - Delete obsolete libraries.
2936865Sdfr#
3036865Sdfr# This makefile is simple by design. The FreeBSD make automatically reads
3136865Sdfr# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3236865Sdfr# command line. By keeping this makefile simple, it doesn't matter too
3336865Sdfr# much how different the installed mk files are from those in the source
3436865Sdfr# tree. This makefile executes a child make process, forcing it to use
3536865Sdfr# the mk files from the source tree which are supposed to DTRT.
3636865Sdfr#
3736865Sdfr# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3836865Sdfr#
3936865Sdfr# If you want to build your system from source be sure that /usr/obj has
4036865Sdfr# at least 800MB of diskspace available.
4150477Speter#
4236865Sdfr# For individuals wanting to build from the sources currently on their
43139825Simp# system, the simple instructions are:
4436865Sdfr#
4536865Sdfr# 1.  `cd /usr/src'  (or to the directory containing your source tree).
4636865Sdfr# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
4736865Sdfr# 3.  `make world'
48126474Sgrehan#
4936865Sdfr# For individuals wanting to upgrade their sources (even if only a
5036865Sdfr# delta of a few days):
5136865Sdfr#
5236865Sdfr#  1.  `cd /usr/src'       (or to the directory containing your source tree).
5336865Sdfr#  2.  `make buildworld'
54126474Sgrehan#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
55126474Sgrehan#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
56126474Sgrehan#       [steps 3. & 4. can be combined by using the "kernel" target]
5736865Sdfr#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
58126474Sgrehan#  6.  `mergemaster -p'
5936865Sdfr#  7.  `make installworld'
6036865Sdfr#  8.  `make delete-old'
6136865Sdfr#  9.  `mergemaster'                         (you may wish to use -U or -ai).
6236865Sdfr# 10.  `reboot'
6336865Sdfr# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6436865Sdfr#
6536865Sdfr# See src/UPDATING `COMMON ITEMS' for more complete information.
6636865Sdfr#
6736865Sdfr# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
6836865Sdfr# cross build world for other machine types using the buildworld target,
6936865Sdfr# and once the world is built you can cross build a kernel using the
7036865Sdfr# buildkernel target.
7136865Sdfr#
7236865Sdfr# Define the user-driven targets. These are listed here in alphabetical
7336865Sdfr# order, but that's not important.
7460041Sphk#
7536865Sdfr# Targets that begin with underscore are internal targets intended for
7685201Smp# developer convenience only.  They are intentionally not documented and
7785201Smp# completely subject to change without notice.
7867365Sjhb#
7936865Sdfr# For more information, see the build(7) manual page.
8036865Sdfr#
8136865SdfrTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
82119563Salc	check-old check-old-dirs check-old-files check-old-libs \
83122780Salc	checkdpadd clean cleandepend cleandir \
8436865Sdfr	delete-old delete-old-dirs delete-old-files delete-old-libs \
8554207Speter	depend distribute distributeworld distrib-dirs distribution doxygen \
8636865Sdfr	everything hierarchy install installcheck installkernel \
8736865Sdfr	installkernel.debug reinstallkernel reinstallkernel.debug \
8836865Sdfr	installworld kernel-toolchain libraries lint maninstall \
8941499Sdfr	obj objlink regress rerelease showconfig tags toolchain update \
9097397Sbenno	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
9136865Sdfr	_build-tools _cross-tools _includes _libraries _depend \
92138129Sdas	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
9336865Sdfr
9478342SbennoTGTS+=	${SUBDIR_TARGETS}
9578342Sbenno
9636865SdfrBITGTS=	files includes
9736865SdfrBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
9836865SdfrTGTS+=	${BITGTS}
9936865Sdfr
10036865Sdfr.ORDER: buildworld installworld
10136865Sdfr.ORDER: buildworld distributeworld
10236865Sdfr.ORDER: buildworld buildkernel
10336865Sdfr.ORDER: buildkernel installkernel
10436865Sdfr.ORDER: buildkernel installkernel.debug
10536865Sdfr.ORDER: buildkernel reinstallkernel
10636865Sdfr.ORDER: buildkernel reinstallkernel.debug
10736865Sdfr
10836865SdfrPATH=	/sbin:/bin:/usr/sbin:/usr/bin
10990361SjulianMAKEOBJDIRPREFIX?=	/usr/obj
11036865Sdfr_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
11184977Sbenno    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
11284977Sbenno    -f /dev/null -V MAKEOBJDIRPREFIX dummy
11384977Sbenno.if !empty(_MAKEOBJDIRPREFIX)
11490643Sbenno.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
11584977Sbenno	(in make.conf(5)) or command-line variable.
11691467Sbenno.endif
11790643SbennoMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
11884977SbennoBINMAKE= \
11984977Sbenno	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
12084977Sbenno	-m ${.CURDIR}/share/mk
12184977Sbenno_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12284977Sbenno
12384977Sbenno#
12484977Sbenno# Make sure we have an up-to-date make(1). Only world and buildworld
125127582Speter# should do this as those are the initial targets used for upgrades.
126127582Speter# The user can define ALWAYS_CHECK_MAKE to have this check performed
12790643Sbenno# for all targets.
12884977Sbenno#
12990643Sbenno.if defined(ALWAYS_CHECK_MAKE)
13090643Sbenno${TGTS}: upgrade_checks
13184977Sbenno.else
13284977Sbennobuildworld: upgrade_checks
13390643Sbenno.endif
13484977Sbenno
13584977Sbenno#
13684977Sbenno# This 'cleanworld' target is not included in TGTS, because it is not a
13790643Sbenno# recursive target.  All of the work for it is done right here.   It is
13890643Sbenno# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
13984977Sbenno# created by bsd.obj.mk, except that we don't want to .include that file
14097397Sbenno# in this makefile.  
14197397Sbenno#
14297397Sbenno# In the following, the first 'rm' in a series will usually remove all
14397397Sbenno# files and directories.  If it does not, then there are probably some
14490643Sbenno# files with chflags set, so this unsets them and tries the 'rm' a
14590643Sbenno# second time.  There are situations where this target will be cleaning
14690643Sbenno# some directories via more than one method, but that duplication is
14790643Sbenno# needed to correctly handle all the possible situations.
148132520Sgrehan#
14991467SbennoBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
15091467Sbennocleanworld:
15191467Sbenno.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
15284977Sbenno.if exists(${BW_CANONICALOBJDIR}/)
15391467Sbenno	-rm -rf ${BW_CANONICALOBJDIR}/*
15491467Sbenno	-chflags -R 0 ${BW_CANONICALOBJDIR}
155105611Sgrehan	rm -rf ${BW_CANONICALOBJDIR}/*
15684977Sbenno.endif
15790643Sbenno	#   To be safe in this case, fall back to a 'make cleandir'
15890643Sbenno	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
15990643Sbenno.else
16036865Sdfr	-rm -rf ${.OBJDIR}/*
16136865Sdfr	-chflags -R 0 ${.OBJDIR}
16236865Sdfr	rm -rf ${.OBJDIR}/*
16336865Sdfr.endif
16436865Sdfr
16536865Sdfr#
16636865Sdfr# Handle the user-driven targets, using the source relative mk files.
16736865Sdfr#
16836865Sdfr
16983682Smp${TGTS}:
17083682Smp	${_+_}@cd ${.CURDIR}; \
17192842Salfred		${_MAKE} ${.TARGET}
17248391Speter
17336865Sdfr# Set a reasonable default
17484977Sbenno.MAIN:	all
17584977Sbenno
17684977SbennoSTARTTIME!= LC_ALL=C date
17784977SbennoCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
17884977Sbenno.if !empty(CHECK_TIME)
17991467Sbenno.error check your date/time: ${STARTTIME}
18084977Sbenno.endif
18191467Sbenno
18291467Sbenno.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18336865Sdfr#
18436865Sdfr# world
18536865Sdfr#
18636865Sdfr# Attempt to rebuild and reinstall everything. This target is not to be
18736865Sdfr# used for upgrading an existing FreeBSD system, because the kernel is
18836865Sdfr# not included. One can argue that this target doesn't build everything
18936865Sdfr# then.
19036865Sdfr#
19136865Sdfrworld: upgrade_checks
19236865Sdfr	@echo "--------------------------------------------------------------"
19383682Smp	@echo ">>> make world started on ${STARTTIME}"
19483682Smp	@echo "--------------------------------------------------------------"
19536865Sdfr.if target(pre-world)
19636865Sdfr	@echo
19736865Sdfr	@echo "--------------------------------------------------------------"
19883276Speter	@echo ">>> Making 'pre-world' target"
19983276Speter	@echo "--------------------------------------------------------------"
200118893Sgrehan	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20183276Speter.endif
20283276Speter	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
203118893Sgrehan	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20483276Speter.if target(post-world)
20536865Sdfr	@echo
20636865Sdfr	@echo "--------------------------------------------------------------"
20736865Sdfr	@echo ">>> Making 'post-world' target"
20865557Sjasone	@echo "--------------------------------------------------------------"
20936865Sdfr	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21036865Sdfr.endif
21136865Sdfr	@echo
21236865Sdfr	@echo "--------------------------------------------------------------"
21378342Sbenno	@echo ">>> make world completed on `LC_ALL=C date`"
21436865Sdfr	@echo "                   (started ${STARTTIME})"
21536865Sdfr	@echo "--------------------------------------------------------------"
21636865Sdfr.else
217128395Salcworld:
218128395Salc	@echo "WARNING: make world will overwrite your existing FreeBSD"
219128395Salc	@echo "installation without also building and installing a new"
220119563Salc	@echo "kernel.  This can be dangerous.  Please read the handbook,"
221119563Salc	@echo "'Rebuilding world', for how to upgrade your system."
222127788Salc	@echo "Define DESTDIR to where you want to install FreeBSD,"
223119563Salc	@echo "including /, to override this warning and proceed as usual."
224119563Salc	@echo ""
225128395Salc	@echo "Bailing out now..."
226119563Salc	@false
227119563Salc.endif
228119563Salc
229128395Salc#
230128395Salc# kernel
231119563Salc#
232119563Salc# Short hand for `make buildkernel installkernel'
233127086Salc#
234119563Salckernel: buildkernel installkernel
235119563Salc
236119563Salc#
237119563Salc# Perform a few tests to determine if the installed tools are adequate
23836865Sdfr# for building the world.
239126474Sgrehan#
240126474Sgrehanupgrade_checks:
241126474Sgrehan	@if ! (cd ${.CURDIR}/tools/build/make_check && \
242126474Sgrehan	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
24378342Sbenno	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
24436865Sdfr	then \
24536865Sdfr	    (cd ${.CURDIR} && ${MAKE} make); \
24678342Sbenno	fi
24736865Sdfr
24836865Sdfr#
24936865Sdfr# Upgrade make(1) to the current version using the installed
25036865Sdfr# headers, libraries and tools.  Also, allow the location of
25136865Sdfr# the system bsdmake-like utility to be overridden.
25236865Sdfr#
25336865SdfrMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
25436865Sdfr		DESTDIR= \
25536865Sdfr		INSTALL="sh ${.CURDIR}/tools/install.sh"
25636865SdfrMMAKE=		${MMAKEENV} ${MAKE} \
25736865Sdfr		-D_UPGRADING \
25836865Sdfr		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
25936865Sdfr		-DNO_CPU_CFLAGS -DNO_WERROR
26036865Sdfr
26136865Sdfrmake: .PHONY
26236865Sdfr	@echo
26336865Sdfr	@echo "--------------------------------------------------------------"
26436865Sdfr	@echo ">>> Building an up-to-date make(1)"
26536865Sdfr	@echo "--------------------------------------------------------------"
26636865Sdfr	${_+_}@cd ${.CURDIR}/usr.bin/make; \
26736865Sdfr		${MMAKE} obj && \
26899659Sbenno		${MMAKE} depend && \
26999659Sbenno		${MMAKE} all && \
27099659Sbenno		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27199659Sbenno
27299659Sbennotinderbox:
273126474Sgrehan	cd ${.CURDIR} && \
27499659Sbenno		DOING_TINDERBOX=YES ${MAKE} ${JFLAG} universe
27599659Sbenno
27699659Sbenno#
27799659Sbenno# universe
278126474Sgrehan#
279107180Smux# Attempt to rebuild *everything* for all supported architectures,
280107180Smux# with a reasonable chance of success, regardless of how old your
281107180Smux# existing system is.
282107180Smux#
28399659Sbenno.if make(universe) || make(universe_kernels) || make(tinderbox)
28499659SbennoTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
285126474Sgrehan
286126474Sgrehan.if defined(DOING_TINDERBOX)
287127618SbennoFAILFILE=tinderbox.failed
288126474SgrehanMAKEFAIL=tee -a ${FAILFILE}
289126474Sgrehan.else
290126474SgrehanMAKEFAIL=cat
291119004Smarcel.endif
29299659Sbenno
293119004Smarceluniverse: universe_prologue
294119004Smarceluniverse_prologue:
295119004Smarcel	@echo "--------------------------------------------------------------"
29699659Sbenno	@echo ">>> make universe started on ${STARTTIME}"
29799659Sbenno	@echo "--------------------------------------------------------------"
29899659Sbenno.if defined(DOING_TINDERBOX)
299119004Smarcel	rm -f ${FAILFILE}
300119004Smarcel.endif
301119004Smarcel.for target in ${TARGETS}
302119004Smarceluniverse: universe_${target}
303119004Smarcel.ORDER: universe_prologue universe_${target} universe_epilogue
304115858Smarceluniverse_${target}:
30599659Sbenno.if !defined(MAKE_JUST_KERNELS)
306126474Sgrehan	@echo ">> ${target} started on `LC_ALL=C date`"
307126474Sgrehan	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
308126474Sgrehan	    ${MAKE} ${JFLAG} buildworld \
309126474Sgrehan	    TARGET=${target} \
310126474Sgrehan	    > _.${target}.buildworld 2>&1 || \
311126474Sgrehan	    (echo "${target} world failed," \
312126474Sgrehan	    "check _.${target}.buildworld for details" | ${MAKEFAIL}))
313126474Sgrehan	@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
314126474Sgrehan.endif
315126474Sgrehan.if !defined(MAKE_JUST_WORLDS)
316126474Sgrehan.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
317126474Sgrehan	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
318126474Sgrehan	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
319126474Sgrehan	    (echo "${target} 'make LINT' failed," \
320126474Sgrehan	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
321126474Sgrehan.endif
322126474Sgrehan	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
323126474Sgrehan	    universe_kernels
324132520Sgrehan.endif
325126474Sgrehan	@echo ">> ${target} completed on `LC_ALL=C date`"
326126474Sgrehan.endfor
327126474Sgrehanuniverse_kernels: universe_kernconfs
328126474Sgrehan.if !defined(TARGET)
329126474SgrehanTARGET!=	uname -m
330126474Sgrehan.endif
331126474SgrehanKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
33299659Sbenno		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
33399659Sbenno		! -name DEFAULTS ! -name NOTES
33499659Sbennouniverse_kernconfs:
335111028Sjeff.for kernel in ${KERNCONFS}
33699659Sbenno	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
337126474Sgrehan	    ${MAKE} ${JFLAG} buildkernel \
338126474Sgrehan	    TARGET=${TARGET} \
339126474Sgrehan	    KERNCONF=${kernel} \
340126474Sgrehan	    > _.${TARGET}.${kernel} 2>&1 || \
341126474Sgrehan	    (echo "${TARGET} ${kernel} kernel failed," \
342126474Sgrehan	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
343126474Sgrehan.endfor
344126474Sgrehanuniverse: universe_epilogue
345126474Sgrehanuniverse_epilogue:
346126474Sgrehan	@echo "--------------------------------------------------------------"
347126474Sgrehan	@echo ">>> make universe completed on `LC_ALL=C date`"
348126474Sgrehan	@echo "                      (started ${STARTTIME})"
349126474Sgrehan	@echo "--------------------------------------------------------------"
350126474Sgrehan.if defined(DOING_TINDERBOX)
351126474Sgrehan	@if [ -e ${FAILFILE} ] ; then \
352126474Sgrehan		echo "Tinderbox failed:" ;\
353126474Sgrehan		cat ${FAILFILE} ;\
35499659Sbenno		exit 1 ;\
355	fi
356.endif
357.endif
358