Makefile revision 217754
111820Sjulian#
211820Sjulian# $FreeBSD: head/Makefile 217754 2011-01-23 16:28:44Z bz $
311820Sjulian#
411820Sjulian# The user-driven targets are:
511820Sjulian#
611820Sjulian# universe            - *Really* build *everything* (buildworld and
711820Sjulian#                       all kernels on all architectures).
811820Sjulian# tinderbox           - Same as universe, but presents a list of failed build
911820Sjulian#                       targets and exits with an error if there were any.
1011820Sjulian# buildworld          - Rebuild *everything*, including glue to help do
1111820Sjulian#                       upgrades.
1211820Sjulian# installworld        - Install everything built by "buildworld".
1311820Sjulian# world               - buildworld + installworld, no kernel.
1411820Sjulian# buildkernel         - Rebuild the kernel and the kernel-modules.
1511820Sjulian# installkernel       - Install the kernel and the kernel-modules.
1611820Sjulian# installkernel.debug
1711820Sjulian# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1811820Sjulian# reinstallkernel.debug
1911820Sjulian# kernel              - buildkernel + installkernel.
2011820Sjulian# kernel-toolchain    - Builds the subset of world necessary to build a kernel
2111820Sjulian# doxygen             - Build API documentation of the kernel, needs doxygen.
2211820Sjulian# update              - Convenient way to update your source tree (cvs).
2311820Sjulian# check-old           - List obsolete directories/files/libraries.
2411820Sjulian# check-old-dirs      - List obsolete directories.
2511820Sjulian# check-old-files     - List obsolete files.
2611820Sjulian# check-old-libs      - List obsolete libraries.
2711820Sjulian# delete-old          - Delete obsolete directories/files/libraries.
2811820Sjulian# delete-old-dirs     - Delete obsolete directories.
2911820Sjulian# delete-old-files    - Delete obsolete files.
3011820Sjulian# delete-old-libs     - Delete obsolete libraries.
3150479Speter# targets             - Print a list of supported TARGET/TARGET_ARCH pairs.
3211820Sjulian#
3311820Sjulian# This makefile is simple by design. The FreeBSD make automatically reads
3411820Sjulian# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3511820Sjulian# command line. By keeping this makefile simple, it doesn't matter too
3611820Sjulian# much how different the installed mk files are from those in the source
3711820Sjulian# tree. This makefile executes a child make process, forcing it to use
3811820Sjulian# the mk files from the source tree which are supposed to DTRT.
3945988Sjhay#
4011820Sjulian# Most of the user-driven targets (as listed above) are implemented in
4111820Sjulian# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
4211820Sjulian#
4311820Sjulian# If you want to build your system from source be sure that /usr/obj has
4411820Sjulian# at least 1GB of diskspace available.  A complete 'universe' build requires
4511820Sjulian# about 15GB of space.
4611820Sjulian#
4711820Sjulian# For individuals wanting to build from the sources currently on their
4811820Sjulian# system, the simple instructions are:
4927244Sjhay#
5027244Sjhay# 1.  `cd /usr/src'  (or to the directory containing your source tree).
5111820Sjulian# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
5211820Sjulian# 3.  `make world'
5311820Sjulian#
5411820Sjulian# For individuals wanting to upgrade their sources (even if only a
5511820Sjulian# delta of a few days):
5611820Sjulian#
5711820Sjulian#  1.  `cd /usr/src'       (or to the directory containing your source tree).
5811820Sjulian#  2.  `make buildworld'
5911820Sjulian#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
6011820Sjulian#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
6111820Sjulian#       [steps 3. & 4. can be combined by using the "kernel" target]
6211820Sjulian#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
6311820Sjulian#  6.  `mergemaster -p'
6411820Sjulian#  7.  `make installworld'
6511820Sjulian#  8.  `make delete-old'
6611820Sjulian#  9.  `mergemaster'                         (you may wish to use -U or -ai).
6711820Sjulian# 10.  `reboot'
6811820Sjulian# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6911820Sjulian#
7011820Sjulian# See src/UPDATING `COMMON ITEMS' for more complete information.
7111820Sjulian#
7211820Sjulian# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
7311820Sjulian# cross build world for other machine types using the buildworld target,
7411820Sjulian# and once the world is built you can cross build a kernel using the
7511820Sjulian# buildkernel target.
7611820Sjulian#
7711820Sjulian# Define the user-driven targets. These are listed here in alphabetical
7811820Sjulian# order, but that's not important.
7911820Sjulian#
8011820Sjulian# Targets that begin with underscore are internal targets intended for
8111820Sjulian# developer convenience only.  They are intentionally not documented and
8245988Sjhay# completely subject to change without notice.
8345988Sjhay#
8411820Sjulian# For more information, see the build(7) manual page.
8511820Sjulian#
8611820SjulianTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
8711820Sjulian	check-old check-old-dirs check-old-files check-old-libs \
8811820Sjulian	checkdpadd clean cleandepend cleandir \
8911820Sjulian	delete-old delete-old-dirs delete-old-files delete-old-libs \
9011820Sjulian	depend distribute distributeworld distrib-dirs distribution doxygen \
9111820Sjulian	everything hierarchy install installcheck installkernel \
9211820Sjulian	installkernel.debug reinstallkernel reinstallkernel.debug \
9311820Sjulian	installworld kernel-toolchain libraries lint maninstall \
9411820Sjulian	obj objlink regress rerelease showconfig tags toolchain update \
9511820Sjulian	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
9611820Sjulian	_build-tools _cross-tools _includes _libraries _depend \
9711820Sjulian	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
9811820Sjulian
9911820SjulianTGTS+=	${SUBDIR_TARGETS}
10011820Sjulian
10111820SjulianBITGTS=	files includes
10211820SjulianBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
10311820SjulianTGTS+=	${BITGTS}
10411820Sjulian
10511820Sjulian.ORDER: buildworld installworld
10611820Sjulian.ORDER: buildworld distributeworld
10711820Sjulian.ORDER: buildworld buildkernel
10811820Sjulian.ORDER: buildkernel installkernel
10911820Sjulian.ORDER: buildkernel installkernel.debug
11011820Sjulian.ORDER: buildkernel reinstallkernel
11111820Sjulian.ORDER: buildkernel reinstallkernel.debug
11211820Sjulian
11327244SjhayPATH=	/sbin:/bin:/usr/sbin:/usr/bin
11411820SjulianMAKEOBJDIRPREFIX?=	/usr/obj
11511820Sjulian_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
11611820Sjulian    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
11711820Sjulian    -f /dev/null -V MAKEOBJDIRPREFIX dummy
11811820Sjulian.if !empty(_MAKEOBJDIRPREFIX)
11911820Sjulian.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
12011820Sjulian	(in make.conf(5)) or command-line variable.
12111820Sjulian.endif
12211820SjulianMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
12311820SjulianBINMAKE= \
12411820Sjulian	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
12511820Sjulian	-m ${.CURDIR}/share/mk
12611820Sjulian_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12711820Sjulian
12811820Sjulian#
12911820Sjulian# Make sure we have an up-to-date make(1). Only world and buildworld
13011820Sjulian# should do this as those are the initial targets used for upgrades.
13111820Sjulian# The user can define ALWAYS_CHECK_MAKE to have this check performed
13211820Sjulian# for all targets.
13311820Sjulian#
13411820Sjulian.if defined(ALWAYS_CHECK_MAKE)
13527244Sjhay${TGTS}: upgrade_checks
13627244Sjhay.else
13727244Sjhaybuildworld: upgrade_checks
13827244Sjhay.endif
139228990Suqs
14027244Sjhay#
14127244Sjhay# This 'cleanworld' target is not included in TGTS, because it is not a
14227244Sjhay# recursive target.  All of the work for it is done right here.   It is
14327244Sjhay# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
14427244Sjhay# created by bsd.obj.mk, except that we don't want to .include that file
14527244Sjhay# in this makefile.  
14627244Sjhay#
14711820Sjulian# In the following, the first 'rm' in a series will usually remove all
14811820Sjulian# files and directories.  If it does not, then there are probably some
14927244Sjhay# files with chflags set, so this unsets them and tries the 'rm' a
15027244Sjhay# second time.  There are situations where this target will be cleaning
15111820Sjulian# some directories via more than one method, but that duplication is
15227244Sjhay# needed to correctly handle all the possible situations.
15311820Sjulian#
15411820SjulianBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
15511820Sjuliancleanworld:
15611820Sjulian.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
15711820Sjulian.if exists(${BW_CANONICALOBJDIR}/)
15811820Sjulian	-rm -rf ${BW_CANONICALOBJDIR}/*
15911820Sjulian	-chflags -R 0 ${BW_CANONICALOBJDIR}
16011820Sjulian	rm -rf ${BW_CANONICALOBJDIR}/*
16111820Sjulian.endif
16211820Sjulian	#   To be safe in this case, fall back to a 'make cleandir'
16311820Sjulian	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
16411820Sjulian.else
16511820Sjulian	-rm -rf ${.OBJDIR}/*
16611820Sjulian	-chflags -R 0 ${.OBJDIR}
16711820Sjulian	rm -rf ${.OBJDIR}/*
16811820Sjulian.endif
16911820Sjulian
17011820Sjulian#
17111820Sjulian# Handle the user-driven targets, using the source relative mk files.
17211820Sjulian#
17311820Sjulian
17411820Sjulian${TGTS}:
17511820Sjulian	${_+_}@cd ${.CURDIR}; \
17611820Sjulian		${_MAKE} ${.TARGET}
17711820Sjulian
17811820Sjulian# Set a reasonable default
17911820Sjulian.MAIN:	all
18012620Sjulian
18111820SjulianSTARTTIME!= LC_ALL=C date
18211820SjulianCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
18311820Sjulian.if !empty(CHECK_TIME)
18411820Sjulian.error check your date/time: ${STARTTIME}
18511820Sjulian.endif
18611820Sjulian
18727244Sjhay.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18827244Sjhay#
18927244Sjhay# world
19027244Sjhay#
19127244Sjhay# Attempt to rebuild and reinstall everything. This target is not to be
19227244Sjhay# used for upgrading an existing FreeBSD system, because the kernel is
19327244Sjhay# not included. One can argue that this target doesn't build everything
19427244Sjhay# then.
19527244Sjhay#
19627244Sjhayworld: upgrade_checks
19727244Sjhay	@echo "--------------------------------------------------------------"
19811820Sjulian	@echo ">>> make world started on ${STARTTIME}"
19927244Sjhay	@echo "--------------------------------------------------------------"
20011820Sjulian.if target(pre-world)
20111820Sjulian	@echo
20227244Sjhay	@echo "--------------------------------------------------------------"
20327244Sjhay	@echo ">>> Making 'pre-world' target"
20427244Sjhay	@echo "--------------------------------------------------------------"
20527244Sjhay	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20627244Sjhay.endif
20727244Sjhay	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
20827244Sjhay	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20927244Sjhay.if target(post-world)
21027244Sjhay	@echo
21127244Sjhay	@echo "--------------------------------------------------------------"
21227244Sjhay	@echo ">>> Making 'post-world' target"
21311820Sjulian	@echo "--------------------------------------------------------------"
21411820Sjulian	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21511820Sjulian.endif
216	@echo
217	@echo "--------------------------------------------------------------"
218	@echo ">>> make world completed on `LC_ALL=C date`"
219	@echo "                   (started ${STARTTIME})"
220	@echo "--------------------------------------------------------------"
221.else
222world:
223	@echo "WARNING: make world will overwrite your existing FreeBSD"
224	@echo "installation without also building and installing a new"
225	@echo "kernel.  This can be dangerous.  Please read the handbook,"
226	@echo "'Rebuilding world', for how to upgrade your system."
227	@echo "Define DESTDIR to where you want to install FreeBSD,"
228	@echo "including /, to override this warning and proceed as usual."
229	@echo ""
230	@echo "Bailing out now..."
231	@false
232.endif
233
234#
235# kernel
236#
237# Short hand for `make buildkernel installkernel'
238#
239kernel: buildkernel installkernel
240
241#
242# Perform a few tests to determine if the installed tools are adequate
243# for building the world.
244#
245upgrade_checks:
246	@if ! (cd ${.CURDIR}/tools/build/make_check && \
247	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
248	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
249	then \
250	    (cd ${.CURDIR} && ${MAKE} make); \
251	fi
252
253#
254# Upgrade make(1) to the current version using the installed
255# headers, libraries and tools.  Also, allow the location of
256# the system bsdmake-like utility to be overridden.
257#
258MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
259		DESTDIR= \
260		INSTALL="sh ${.CURDIR}/tools/install.sh"
261MMAKE=		${MMAKEENV} ${MAKE} \
262		-D_UPGRADING \
263		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
264		-DNO_CPU_CFLAGS -DNO_WERROR
265
266make: .PHONY
267	@echo
268	@echo "--------------------------------------------------------------"
269	@echo ">>> Building an up-to-date make(1)"
270	@echo "--------------------------------------------------------------"
271	${_+_}@cd ${.CURDIR}/usr.bin/make; \
272		${MMAKE} obj && \
273		${MMAKE} depend && \
274		${MMAKE} all && \
275		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
276
277tinderbox:
278	@cd ${.CURDIR} && \
279		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
280
281#
282# universe
283#
284# Attempt to rebuild *everything* for all supported architectures,
285# with a reasonable chance of success, regardless of how old your
286# existing system is.
287#
288.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
289TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
290TARGET_ARCHES_arm?=	arm armeb
291TARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
292TARGET_ARCHES_powerpc?=	powerpc powerpc64
293TARGET_ARCHES_pc98?=	i386
294TARGET_ARCHES_sun4v?=	sparc64
295.for target in ${TARGETS}
296TARGET_ARCHES_${target}?= ${target}
297.endfor
298
299targets:
300	@echo "Supported TARGETS/TARGET_ARCH pairs"
301.for target in ${TARGETS}
302.for target_arch in ${TARGET_ARCHES_${target}}
303	@echo "    ${target}/${target_arch}"
304.endfor
305.endfor
306
307.if defined(DOING_TINDERBOX)
308FAILFILE=${.CURDIR}/_.tinderbox.failed
309MAKEFAIL=tee -a ${FAILFILE}
310.else
311MAKEFAIL=cat
312.endif
313
314universe: universe_prologue
315universe_prologue:
316	@echo "--------------------------------------------------------------"
317	@echo ">>> make universe started on ${STARTTIME}"
318	@echo "--------------------------------------------------------------"
319.if defined(DOING_TINDERBOX)
320	@rm -f ${FAILFILE}
321.endif
322.for target in ${TARGETS}
323universe: universe_${target}
324.ORDER: universe_prologue universe_${target} universe_epilogue
325universe_${target}: universe_${target}_prologue
326universe_${target}_prologue:
327	@echo ">> ${target} started on `LC_ALL=C date`"
328.if !defined(MAKE_JUST_KERNELS)
329.for target_arch in ${TARGET_ARCHES_${target}}
330universe_${target}: universe_${target}_${target_arch}
331universe_${target}_${target_arch}: universe_${target}_prologue
332	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
333	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
334	    ${MAKE} ${JFLAG} buildworld \
335	    TARGET=${target} \
336	    TARGET_ARCH=${target_arch} \
337	    > _.${target}.${target_arch}.buildworld 2>&1 || \
338	    (echo "${target}.${target_arch} world failed," \
339	    "check _.${target}.${target_arch}.buildworld for details" | \
340	    ${MAKEFAIL}))
341	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
342.endfor
343.endif
344.if !defined(MAKE_JUST_WORLDS)
345.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
346	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
347	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
348	    (echo "${target} 'make LINT' failed," \
349	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
350.endif
351	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
352	    universe_kernels
353.endif
354	@echo ">> ${target} completed on `LC_ALL=C date`"
355.endfor
356universe_kernels: universe_kernconfs
357.if !defined(TARGET)
358TARGET!=	uname -m
359.endif
360KERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
361		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
362		! -name DEFAULTS ! -name NOTES
363universe_kernconfs:
364.for kernel in ${KERNCONFS}
365TARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
366	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
367	grep -v WARNING: | cut -f 2
368.if empty(TARGET_ARCH_${kernel})
369.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
370.endif
371universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
372universe_kernconf_${TARGET}_${kernel}:
373	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
374	    ${MAKE} ${JFLAG} buildkernel \
375	    TARGET=${TARGET} \
376	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
377	    KERNCONF=${kernel} \
378	    > _.${TARGET}.${kernel} 2>&1 || \
379	    (echo "${TARGET} ${kernel} kernel failed," \
380	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
381.endfor
382universe: universe_epilogue
383universe_epilogue:
384	@echo "--------------------------------------------------------------"
385	@echo ">>> make universe completed on `LC_ALL=C date`"
386	@echo "                      (started ${STARTTIME})"
387	@echo "--------------------------------------------------------------"
388.if defined(DOING_TINDERBOX)
389	@if [ -e ${FAILFILE} ] ; then \
390		echo "Tinderbox failed:" ;\
391		cat ${FAILFILE} ;\
392		exit 1 ;\
393	fi
394.endif
395.endif
396