Makefile revision 217123
184865Sobrien#
2218822Sdim# $FreeBSD: head/Makefile 217123 2011-01-07 20:26:33Z imp $
3218822Sdim#
484865Sobrien# The user-driven targets are:
584865Sobrien#
684865Sobrien# universe            - *Really* build *everything* (buildworld and
784865Sobrien#                       all kernels on all architectures).
884865Sobrien# buildworld          - Rebuild *everything*, including glue to help do
984865Sobrien#                       upgrades.
1084865Sobrien# installworld        - Install everything built by "buildworld".
1184865Sobrien# world               - buildworld + installworld, no kernel.
1284865Sobrien# buildkernel         - Rebuild the kernel and the kernel-modules.
1384865Sobrien# installkernel       - Install the kernel and the kernel-modules.
1484865Sobrien# installkernel.debug
1584865Sobrien# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1684865Sobrien# reinstallkernel.debug
1784865Sobrien# kernel              - buildkernel + installkernel.
1884865Sobrien# kernel-toolchain    - Builds the subset of world necessary to build a kernel
1984865Sobrien# doxygen             - Build API documentation of the kernel, needs doxygen.
20218822Sdim# update              - Convenient way to update your source tree (cvs).
21218822Sdim# check-old           - List obsolete directories/files/libraries.
2284865Sobrien# check-old-dirs      - List obsolete directories.
23104834Sobrien# check-old-files     - List obsolete files.
24104834Sobrien# check-old-libs      - List obsolete libraries.
2584865Sobrien# delete-old          - Delete obsolete directories/files/libraries.
2684865Sobrien# delete-old-dirs     - Delete obsolete directories.
2784865Sobrien# delete-old-files    - Delete obsolete files.
2884865Sobrien# delete-old-libs     - Delete obsolete libraries.
2984865Sobrien#
3084865Sobrien# This makefile is simple by design. The FreeBSD make automatically reads
3189857Sobrien# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3284865Sobrien# command line. By keeping this makefile simple, it doesn't matter too
3384865Sobrien# much how different the installed mk files are from those in the source
3489857Sobrien# tree. This makefile executes a child make process, forcing it to use
3584865Sobrien# the mk files from the source tree which are supposed to DTRT.
3684865Sobrien#
37130561Sobrien# The user-driven targets (as listed above) are implemented in Makefile.inc1.
38130561Sobrien#
39130561Sobrien# If you want to build your system from source be sure that /usr/obj has
40130561Sobrien# at least 800MB of diskspace available.
41130561Sobrien#
42130561Sobrien# For individuals wanting to build from the sources currently on their
43130561Sobrien# system, the simple instructions are:
44130561Sobrien#
45130561Sobrien# 1.  `cd /usr/src'  (or to the directory containing your source tree).
46130561Sobrien# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
47130561Sobrien# 3.  `make world'
48130561Sobrien#
49130561Sobrien# For individuals wanting to upgrade their sources (even if only a
50130561Sobrien# delta of a few days):
51130561Sobrien#
52130561Sobrien#  1.  `cd /usr/src'       (or to the directory containing your source tree).
53130561Sobrien#  2.  `make buildworld'
54130561Sobrien#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
55130561Sobrien#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
56130561Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
57130561Sobrien#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
5884865Sobrien#  6.  `mergemaster -p'
5984865Sobrien#  7.  `make installworld'
6084865Sobrien#  8.  `make delete-old'
6184865Sobrien#  9.  `mergemaster'                         (you may wish to use -U or -ai).
6284865Sobrien# 10.  `reboot'
6384865Sobrien# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6484865Sobrien#
6584865Sobrien# See src/UPDATING `COMMON ITEMS' for more complete information.
6684865Sobrien#
6784865Sobrien# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
6884865Sobrien# cross build world for other machine types using the buildworld target,
6984865Sobrien# and once the world is built you can cross build a kernel using the
7084865Sobrien# buildkernel target.
7184865Sobrien#
7284865Sobrien# Define the user-driven targets. These are listed here in alphabetical
7384865Sobrien# order, but that's not important.
7484865Sobrien#
7584865Sobrien# Targets that begin with underscore are internal targets intended for
7684865Sobrien# developer convenience only.  They are intentionally not documented and
7784865Sobrien# completely subject to change without notice.
78218822Sdim#
79218822Sdim# For more information, see the build(7) manual page.
8084865Sobrien#
8184865SobrienTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
82218822Sdim	check-old check-old-dirs check-old-files check-old-libs \
83218822Sdim	checkdpadd clean cleandepend cleandir \
84218822Sdim	delete-old delete-old-dirs delete-old-files delete-old-libs \
85130561Sobrien	depend distribute distributeworld distrib-dirs distribution doxygen \
86130561Sobrien	everything hierarchy install installcheck installkernel \
8784865Sobrien	installkernel.debug reinstallkernel reinstallkernel.debug \
8884865Sobrien	installworld kernel-toolchain libraries lint maninstall \
8984865Sobrien	obj objlink regress rerelease showconfig tags toolchain update \
9084865Sobrien	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
9184865Sobrien	_build-tools _cross-tools _includes _libraries _depend \
9284865Sobrien	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
9384865Sobrien
9484865SobrienTGTS+=	${SUBDIR_TARGETS}
9584865Sobrien
9684865SobrienBITGTS=	files includes
97130561SobrienBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
98130561SobrienTGTS+=	${BITGTS}
99130561Sobrien
10084865Sobrien.ORDER: buildworld installworld
101218822Sdim.ORDER: buildworld distributeworld
10284865Sobrien.ORDER: buildworld buildkernel
10384865Sobrien.ORDER: buildkernel installkernel
10484865Sobrien.ORDER: buildkernel installkernel.debug
10584865Sobrien.ORDER: buildkernel reinstallkernel
10684865Sobrien.ORDER: buildkernel reinstallkernel.debug
10784865Sobrien
10884865SobrienPATH=	/sbin:/bin:/usr/sbin:/usr/bin
10984865SobrienMAKEOBJDIRPREFIX?=	/usr/obj
11084865Sobrien_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
11184865Sobrien    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
11289857Sobrien    -f /dev/null -V MAKEOBJDIRPREFIX dummy
11384865Sobrien.if !empty(_MAKEOBJDIRPREFIX)
11484865Sobrien.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
11584865Sobrien	(in make.conf(5)) or command-line variable.
11684865Sobrien.endif
11784865SobrienMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
11889857SobrienBINMAKE= \
119130561Sobrien	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
120130561Sobrien	-m ${.CURDIR}/share/mk
121130561Sobrien_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
122130561Sobrien
12384865Sobrien#
12484865Sobrien# Make sure we have an up-to-date make(1). Only world and buildworld
12584865Sobrien# should do this as those are the initial targets used for upgrades.
12684865Sobrien# The user can define ALWAYS_CHECK_MAKE to have this check performed
12784865Sobrien# for all targets.
128130561Sobrien#
129130561Sobrien.if defined(ALWAYS_CHECK_MAKE)
130130561Sobrien${TGTS}: upgrade_checks
13184865Sobrien.else
132218822Sdimbuildworld: upgrade_checks
13384865Sobrien.endif
134130561Sobrien
13584865Sobrien#
13684865Sobrien# This 'cleanworld' target is not included in TGTS, because it is not a
13784865Sobrien# recursive target.  All of the work for it is done right here.   It is
13884865Sobrien# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
139130561Sobrien# created by bsd.obj.mk, except that we don't want to .include that file
140130561Sobrien# in this makefile.  
14189857Sobrien#
14284865Sobrien# In the following, the first 'rm' in a series will usually remove all
14389857Sobrien# files and directories.  If it does not, then there are probably some
14484865Sobrien# files with chflags set, so this unsets them and tries the 'rm' a
145130561Sobrien# second time.  There are situations where this target will be cleaning
14689857Sobrien# some directories via more than one method, but that duplication is
14784865Sobrien# needed to correctly handle all the possible situations.
14884865Sobrien#
14984865SobrienBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
15084865Sobriencleanworld:
15184865Sobrien.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
15284865Sobrien.if exists(${BW_CANONICALOBJDIR}/)
153130561Sobrien	-rm -rf ${BW_CANONICALOBJDIR}/*
15484865Sobrien	-chflags -R 0 ${BW_CANONICALOBJDIR}
15584865Sobrien	rm -rf ${BW_CANONICALOBJDIR}/*
15684865Sobrien.endif
15789857Sobrien	#   To be safe in this case, fall back to a 'make cleandir'
158130561Sobrien	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
159130561Sobrien.else
16084865Sobrien	-rm -rf ${.OBJDIR}/*
161130561Sobrien	-chflags -R 0 ${.OBJDIR}
162130561Sobrien	rm -rf ${.OBJDIR}/*
163130561Sobrien.endif
164130561Sobrien
165218822Sdim#
166218822Sdim# Handle the user-driven targets, using the source relative mk files.
167218822Sdim#
168218822Sdim
169218822Sdim${TGTS}:
170218822Sdim	${_+_}@cd ${.CURDIR}; \
171218822Sdim		${_MAKE} ${.TARGET}
172218822Sdim
17384865Sobrien# Set a reasonable default
17484865Sobrien.MAIN:	all
17584865Sobrien
17684865SobrienSTARTTIME!= LC_ALL=C date
17784865SobrienCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
17884865Sobrien.if !empty(CHECK_TIME)
17984865Sobrien.error check your date/time: ${STARTTIME}
18084865Sobrien.endif
18184865Sobrien
18284865Sobrien.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18384865Sobrien#
18484865Sobrien# world
18584865Sobrien#
18684865Sobrien# Attempt to rebuild and reinstall everything. This target is not to be
18784865Sobrien# used for upgrading an existing FreeBSD system, because the kernel is
18884865Sobrien# not included. One can argue that this target doesn't build everything
18984865Sobrien# then.
19084865Sobrien#
19184865Sobrienworld: upgrade_checks
19284865Sobrien	@echo "--------------------------------------------------------------"
19384865Sobrien	@echo ">>> make world started on ${STARTTIME}"
19484865Sobrien	@echo "--------------------------------------------------------------"
19584865Sobrien.if target(pre-world)
19684865Sobrien	@echo
19784865Sobrien	@echo "--------------------------------------------------------------"
19884865Sobrien	@echo ">>> Making 'pre-world' target"
19984865Sobrien	@echo "--------------------------------------------------------------"
20084865Sobrien	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20184865Sobrien.endif
20284865Sobrien	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
20384865Sobrien	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20484865Sobrien.if target(post-world)
20584865Sobrien	@echo
20684865Sobrien	@echo "--------------------------------------------------------------"
20784865Sobrien	@echo ">>> Making 'post-world' target"
20884865Sobrien	@echo "--------------------------------------------------------------"
20984865Sobrien	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21084865Sobrien.endif
21184865Sobrien	@echo
21284865Sobrien	@echo "--------------------------------------------------------------"
21384865Sobrien	@echo ">>> make world completed on `LC_ALL=C date`"
21484865Sobrien	@echo "                   (started ${STARTTIME})"
21584865Sobrien	@echo "--------------------------------------------------------------"
21684865Sobrien.else
21784865Sobrienworld:
21884865Sobrien	@echo "WARNING: make world will overwrite your existing FreeBSD"
21984865Sobrien	@echo "installation without also building and installing a new"
22084865Sobrien	@echo "kernel.  This can be dangerous.  Please read the handbook,"
22184865Sobrien	@echo "'Rebuilding world', for how to upgrade your system."
22284865Sobrien	@echo "Define DESTDIR to where you want to install FreeBSD,"
22384865Sobrien	@echo "including /, to override this warning and proceed as usual."
22484865Sobrien	@echo ""
22584865Sobrien	@echo "Bailing out now..."
22684865Sobrien	@false
227130561Sobrien.endif
22884865Sobrien
22984865Sobrien#
23084865Sobrien# kernel
23184865Sobrien#
23284865Sobrien# Short hand for `make buildkernel installkernel'
23384865Sobrien#
23484865Sobrienkernel: buildkernel installkernel
23584865Sobrien
23684865Sobrien#
23784865Sobrien# Perform a few tests to determine if the installed tools are adequate
23884865Sobrien# for building the world.
23984865Sobrien#
24084865Sobrienupgrade_checks:
24184865Sobrien	@if ! (cd ${.CURDIR}/tools/build/make_check && \
24284865Sobrien	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
24384865Sobrien	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
244218822Sdim	then \
24584865Sobrien	    (cd ${.CURDIR} && ${MAKE} make); \
24684865Sobrien	fi
24784865Sobrien
24884865Sobrien#
24984865Sobrien# Upgrade make(1) to the current version using the installed
25084865Sobrien# headers, libraries and tools.  Also, allow the location of
25184865Sobrien# the system bsdmake-like utility to be overridden.
252218822Sdim#
25384865SobrienMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
25484865Sobrien		DESTDIR= \
255218822Sdim		INSTALL="sh ${.CURDIR}/tools/install.sh"
256218822SdimMMAKE=		${MMAKEENV} ${MAKE} \
257218822Sdim		-D_UPGRADING \
258218822Sdim		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
259218822Sdim		-DNO_CPU_CFLAGS -DNO_WERROR
260218822Sdim
261218822Sdimmake: .PHONY
262218822Sdim	@echo
263218822Sdim	@echo "--------------------------------------------------------------"
264218822Sdim	@echo ">>> Building an up-to-date make(1)"
265218822Sdim	@echo "--------------------------------------------------------------"
266218822Sdim	${_+_}@cd ${.CURDIR}/usr.bin/make; \
267218822Sdim		${MMAKE} obj && \
26884865Sobrien		${MMAKE} depend && \
26984865Sobrien		${MMAKE} all && \
27084865Sobrien		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27184865Sobrien
27284865Sobrientinderbox:
27384865Sobrien	cd ${.CURDIR} && \
27484865Sobrien		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
27584865Sobrien
27684865Sobrien#
27784865Sobrien# universe
27884865Sobrien#
27984865Sobrien# Attempt to rebuild *everything* for all supported architectures,
28084865Sobrien# with a reasonable chance of success, regardless of how old your
28184865Sobrien# existing system is.
282218822Sdim#
283218822Sdim.if make(universe) || make(universe_kernels) || make(tinderbox)
284218822SdimTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
285218822SdimTARGET_ARCHES_arm?=	arm armeb
286218822SdimTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
287218822SdimTARGET_ARCHES_powerpc?=	powerpc powerpc64
28884865SobrienTARGET_ARCHES_pc98?=	i386
28984865SobrienTARGET_ARCHES_sun4v?=	sparc64
29084865Sobrien.for target in ${TARGETS}
29184865SobrienTARGET_ARCHES_${target}?= ${target}
29284865Sobrien.endfor
29384865Sobrien
29484865Sobrien.if defined(DOING_TINDERBOX)
29584865SobrienFAILFILE=tinderbox.failed
29684865SobrienMAKEFAIL=tee -a ${FAILFILE}
29784865Sobrien.else
29884865SobrienMAKEFAIL=cat
29984865Sobrien.endif
30084865Sobrien
30184865Sobrienuniverse: universe_prologue
30284865Sobrienuniverse_prologue:
30384865Sobrien	@echo "--------------------------------------------------------------"
30484865Sobrien	@echo ">>> make universe started on ${STARTTIME}"
30584865Sobrien	@echo "--------------------------------------------------------------"
30684865Sobrien.if defined(DOING_TINDERBOX)
307130561Sobrien	rm -f ${FAILFILE}
30884865Sobrien.endif
309130561Sobrien.for target in ${TARGETS}
310130561Sobrienuniverse: universe_${target}
31184865Sobrien.ORDER: universe_prologue universe_${target} universe_epilogue
31289857Sobrienuniverse_${target}: universe_${target}_prologue
31389857Sobrienuniverse_${target}_prologue:
31489857Sobrien	@echo ">> ${target} started on `LC_ALL=C date`"
315130561Sobrien.if !defined(MAKE_JUST_KERNELS)
316130561Sobrien.for target_arch in ${TARGET_ARCHES_${target}}
317130561Sobrienuniverse_${target}: universe_${target}_${target_arch}
318218822Sdimuniverse_${target}_${target_arch}: universe_${target}_prologue
319130561Sobrien	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
320	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
321	    ${MAKE} ${JFLAG} buildworld \
322	    TARGET=${target} \
323	    TARGET_ARCH=${target_arch} \
324	    > _.${target}.${target_arch}.buildworld 2>&1 || \
325	    (echo "${target}.${target_arch} world failed," \
326	    "check _.${target}.${target_arch}.buildworld for details" | \
327	    ${MAKEFAIL}))
328	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
329.endfor
330.endif
331.if !defined(MAKE_JUST_WORLDS)
332.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
333	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
334	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
335	    (echo "${target} 'make LINT' failed," \
336	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
337.endif
338	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
339	    universe_kernels
340.endif
341	@echo ">> ${target} completed on `LC_ALL=C date`"
342.endfor
343universe_kernels: universe_kernconfs
344.if !defined(TARGET)
345TARGET!=	uname -m
346.endif
347KERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
348		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
349		! -name DEFAULTS ! -name NOTES
350universe_kernconfs:
351.for kernel in ${KERNCONFS}
352TARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
353	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
354	grep -v WARNING: | cut -f 2
355.if empty(TARGET_ARCH_${kernel})
356.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
357.endif
358universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
359universe_kernconf_${TARGET}_${kernel}:
360	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
361	    ${MAKE} ${JFLAG} buildkernel \
362	    TARGET=${TARGET} \
363	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
364	    KERNCONF=${kernel} \
365	    > _.${TARGET}.${kernel} 2>&1 || \
366	    (echo "${TARGET} ${kernel} kernel failed," \
367	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
368.endfor
369universe: universe_epilogue
370universe_epilogue:
371	@echo "--------------------------------------------------------------"
372	@echo ">>> make universe completed on `LC_ALL=C date`"
373	@echo "                      (started ${STARTTIME})"
374	@echo "--------------------------------------------------------------"
375.if defined(DOING_TINDERBOX)
376	@if [ -e ${FAILFILE} ] ; then \
377		echo "Tinderbox failed:" ;\
378		cat ${FAILFILE} ;\
379		exit 1 ;\
380	fi
381.endif
382.endif
383