Makefile revision 217297
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 217297 2011-01-12 04:59:29Z imp $
32061Sjkh#
438666Sjb# The user-driven targets are:
532427Sjb#
6111131Sru# universe            - *Really* build *everything* (buildworld and
7111131Sru#                       all kernels on all architectures).
8217273Simp# tinderbox           - Same as universe, but stop on first failure.
938666Sjb# buildworld          - Rebuild *everything*, including glue to help do
1038666Sjb#                       upgrades.
1138666Sjb# installworld        - Install everything built by "buildworld".
12159363Strhodes# world               - buildworld + installworld, no kernel.
1364049Salex# buildkernel         - Rebuild the kernel and the kernel-modules.
1464049Salex# installkernel       - Install the kernel and the kernel-modules.
15116679Ssimokawa# installkernel.debug
1666071Smarkm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
17116679Ssimokawa# reinstallkernel.debug
1873504Sobrien# kernel              - buildkernel + installkernel.
19204661Simp# kernel-toolchain    - Builds the subset of world necessary to build a kernel
20158962Snetchild# doxygen             - Build API documentation of the kernel, needs doxygen.
2138666Sjb# update              - Convenient way to update your source tree (cvs).
22169597Sdes# check-old           - List obsolete directories/files/libraries.
23169597Sdes# check-old-dirs      - List obsolete directories.
24169597Sdes# check-old-files     - List obsolete files.
25169597Sdes# check-old-libs      - List obsolete libraries.
26169597Sdes# delete-old          - Delete obsolete directories/files/libraries.
27169597Sdes# delete-old-dirs     - Delete obsolete directories.
28169597Sdes# delete-old-files    - Delete obsolete files.
29169597Sdes# delete-old-libs     - Delete obsolete libraries.
30217125Simp# targets             - Print a list of supported TARGET/TARGET_ARCH pairs.
3132427Sjb#
3238666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
33108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3438666Sjb# command line. By keeping this makefile simple, it doesn't matter too
3538666Sjb# much how different the installed mk files are from those in the source
3638666Sjb# tree. This makefile executes a child make process, forcing it to use
3738666Sjb# the mk files from the source tree which are supposed to DTRT.
3817308Speter#
39217273Simp# Most of the user-driven targets (as listed above) are implemented in
40217294Simp# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
4119175Sbde#
4296205Sjwd# If you want to build your system from source be sure that /usr/obj has
43217297Simp# at least 1GB of diskspace available.  A complete 'universe' build requires
44217297Simp# about 15GB of space.
4538042Sbde#
4696205Sjwd# For individuals wanting to build from the sources currently on their
4796205Sjwd# system, the simple instructions are:
4838042Sbde#
4996205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
50159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
51159363Strhodes# 3.  `make world'
5217308Speter#
5396205Sjwd# For individuals wanting to upgrade their sources (even if only a
5496205Sjwd# delta of a few days):
5517308Speter#
56148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
57148330Snetchild#  2.  `make buildworld'
58148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
59148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
60159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
61148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
62148330Snetchild#  6.  `mergemaster -p'
63148330Snetchild#  7.  `make installworld'
64148330Snetchild#  8.  `make delete-old'
65178653Srwatson#  9.  `mergemaster'                         (you may wish to use -U or -ai).
66148330Snetchild# 10.  `reboot'
67148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6896205Sjwd#
6996205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
7096205Sjwd#
71162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
72162147Sru# cross build world for other machine types using the buildworld target,
7398723Sdillon# and once the world is built you can cross build a kernel using the
7498723Sdillon# buildkernel target.
7598723Sdillon#
7638666Sjb# Define the user-driven targets. These are listed here in alphabetical
7738666Sjb# order, but that's not important.
7817308Speter#
79123311Speter# Targets that begin with underscore are internal targets intended for
80123311Speter# developer convenience only.  They are intentionally not documented and
81123311Speter# completely subject to change without notice.
82123311Speter#
83175833Sjhb# For more information, see the build(7) manual page.
84175833Sjhb#
85169597SdesTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
86169597Sdes	check-old check-old-dirs check-old-files check-old-libs \
87169597Sdes	checkdpadd clean cleandepend cleandir \
88169597Sdes	delete-old delete-old-dirs delete-old-files delete-old-libs \
89159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
90158962Snetchild	everything hierarchy install installcheck installkernel \
91158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
92158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
93156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
94123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
95137288Speter	_build-tools _cross-tools _includes _libraries _depend \
96209128Sraj	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
97209128Sraj
98156740SruTGTS+=	${SUBDIR_TARGETS}
992061Sjkh
10097769SruBITGTS=	files includes
10197252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
102119579SruTGTS+=	${BITGTS}
10397252Sru
10495730Sru.ORDER: buildworld installworld
10595793Sru.ORDER: buildworld distributeworld
106111617Sru.ORDER: buildworld buildkernel
10795730Sru.ORDER: buildkernel installkernel
108116679Ssimokawa.ORDER: buildkernel installkernel.debug
10995730Sru.ORDER: buildkernel reinstallkernel
110116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
11195730Sru
112110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
113107516SruMAKEOBJDIRPREFIX?=	/usr/obj
114138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
115156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
116138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
117133942Sru.if !empty(_MAKEOBJDIRPREFIX)
118133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
119156145Syar	(in make.conf(5)) or command-line variable.
120133942Sru.endif
121110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
122117234SruBINMAKE= \
123110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
124117229Sru	-m ${.CURDIR}/share/mk
125117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12654324Smarcel
12717308Speter#
128119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
129119519Smarcel# should do this as those are the initial targets used for upgrades.
130119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
131119519Smarcel# for all targets.
132119519Smarcel#
133119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
134119579Sru${TGTS}: upgrade_checks
135119519Smarcel.else
136119519Smarcelbuildworld: upgrade_checks
137119519Smarcel.endif
138119519Smarcel
139119519Smarcel#
140126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
141126024Sgad# recursive target.  All of the work for it is done right here.   It is
142126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
143126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
144126024Sgad# in this makefile.  
145126024Sgad#
146126024Sgad# In the following, the first 'rm' in a series will usually remove all
147126024Sgad# files and directories.  If it does not, then there are probably some
148126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
149126024Sgad# second time.  There are situations where this target will be cleaning
150126024Sgad# some directories via more than one method, but that duplication is
151126024Sgad# needed to correctly handle all the possible situations.
152126024Sgad#
153126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
154126031Sgadcleanworld:
155126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
156126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
157126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
158172744Sdelphij	-chflags -R 0 ${BW_CANONICALOBJDIR}
159126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
160126024Sgad.endif
161126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
162133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
163126024Sgad.else
164126024Sgad	-rm -rf ${.OBJDIR}/*
165172744Sdelphij	-chflags -R 0 ${.OBJDIR}
166126024Sgad	rm -rf ${.OBJDIR}/*
167126024Sgad.endif
168125885Sgad
169125885Sgad#
17038666Sjb# Handle the user-driven targets, using the source relative mk files.
17117308Speter#
172119519Smarcel
173119579Sru${TGTS}:
174133376Sharti	${_+_}@cd ${.CURDIR}; \
175110035Sru		${_MAKE} ${.TARGET}
1762302Spaul
17739206Sjkh# Set a reasonable default
17839206Sjkh.MAIN:	all
17939206Sjkh
180133945SruSTARTTIME!= LC_ALL=C date
181177609SruCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
182177609Sru.if !empty(CHECK_TIME)
183177609Sru.error check your date/time: ${STARTTIME}
184177609Sru.endif
185133945Sru
186132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18717308Speter#
18854324Smarcel# world
18954324Smarcel#
190132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
191132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
192132234Smarcel# not included. One can argue that this target doesn't build everything
193132234Smarcel# then.
19454324Smarcel#
19554324Smarcelworld: upgrade_checks
19654324Smarcel	@echo "--------------------------------------------------------------"
197118531Sru	@echo ">>> make world started on ${STARTTIME}"
19854324Smarcel	@echo "--------------------------------------------------------------"
19954324Smarcel.if target(pre-world)
20054324Smarcel	@echo
20154324Smarcel	@echo "--------------------------------------------------------------"
20254324Smarcel	@echo ">>> Making 'pre-world' target"
20354324Smarcel	@echo "--------------------------------------------------------------"
204133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20554324Smarcel.endif
206133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
207133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20854324Smarcel.if target(post-world)
20954324Smarcel	@echo
21054324Smarcel	@echo "--------------------------------------------------------------"
21154324Smarcel	@echo ">>> Making 'post-world' target"
21254324Smarcel	@echo "--------------------------------------------------------------"
213133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21454324Smarcel.endif
21554324Smarcel	@echo
21654324Smarcel	@echo "--------------------------------------------------------------"
217118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
218118531Sru	@echo "                   (started ${STARTTIME})"
21954324Smarcel	@echo "--------------------------------------------------------------"
220132234Smarcel.else
221132234Smarcelworld:
222132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
223132234Smarcel	@echo "installation without also building and installing a new"
224132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
225132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
226132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
227132234Smarcel	@echo "including /, to override this warning and proceed as usual."
228132358Smarkm	@echo ""
229132234Smarcel	@echo "Bailing out now..."
230132234Smarcel	@false
231132234Smarcel.endif
23254324Smarcel
23354324Smarcel#
23495730Sru# kernel
23595730Sru#
23695730Sru# Short hand for `make buildkernel installkernel'
23795730Sru#
23895730Srukernel: buildkernel installkernel
23995730Sru
24095730Sru#
24138666Sjb# Perform a few tests to determine if the installed tools are adequate
242107374Sru# for building the world.
24317308Speter#
24455678Smarcelupgrade_checks:
245143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
246138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
247117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
248110035Sru	then \
249174564Simp	    (cd ${.CURDIR} && ${MAKE} make); \
250110035Sru	fi
2512061Sjkh
25217308Speter#
253107516Sru# Upgrade make(1) to the current version using the installed
254174539Simp# headers, libraries and tools.  Also, allow the location of
255174539Simp# the system bsdmake-like utility to be overridden.
25655678Smarcel#
257107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
258107516Sru		DESTDIR= \
259107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
260174564SimpMMAKE=		${MMAKEENV} ${MAKE} \
261107516Sru		-D_UPGRADING \
262139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
263164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
264107516Sru
265122204Skrismake: .PHONY
26655678Smarcel	@echo
26755678Smarcel	@echo "--------------------------------------------------------------"
268116696Sru	@echo ">>> Building an up-to-date make(1)"
26955678Smarcel	@echo "--------------------------------------------------------------"
270133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
271107516Sru		${MMAKE} obj && \
272107516Sru		${MMAKE} depend && \
273107516Sru		${MMAKE} all && \
274107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27555678Smarcel
276185499Salfredtinderbox:
277185499Salfred	cd ${.CURDIR} && \
278216487Sjhb		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
279185499Salfred
28055678Smarcel#
281111131Sru# universe
282111131Sru#
283111131Sru# Attempt to rebuild *everything* for all supported architectures,
284133945Sru# with a reasonable chance of success, regardless of how old your
285111131Sru# existing system is.
286111131Sru#
287217125Simp.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
288216520SnwhitehornTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
289216520SnwhitehornTARGET_ARCHES_arm?=	arm armeb
290217123SimpTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
291216520SnwhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
292216520SnwhitehornTARGET_ARCHES_pc98?=	i386
293216520SnwhitehornTARGET_ARCHES_sun4v?=	sparc64
294216520Snwhitehorn.for target in ${TARGETS}
295216520SnwhitehornTARGET_ARCHES_${target}?= ${target}
296216520Snwhitehorn.endfor
297168280Smarcel
298217125Simptargets:
299217125Simp	@echo "Supported TARGET/TARGET_ARCH pairs"
300217125Simp.for target in ${TARGETS}
301217125Simp.for target_arch in ${TARGET_ARCHES_${target}}
302217125Simp	@echo "    ${target}/${target_arch}"
303217125Simp.endfor
304217125Simp.endfor
305217125Simp
306185499Salfred.if defined(DOING_TINDERBOX)
307185499SalfredFAILFILE=tinderbox.failed
308185499SalfredMAKEFAIL=tee -a ${FAILFILE}
309185499Salfred.else
310185499SalfredMAKEFAIL=cat
311185499Salfred.endif
312185499Salfred
313133945Sruuniverse: universe_prologue
314133945Sruuniverse_prologue:
315103985Sphk	@echo "--------------------------------------------------------------"
316103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
317103985Sphk	@echo "--------------------------------------------------------------"
318185499Salfred.if defined(DOING_TINDERBOX)
319185499Salfred	rm -f ${FAILFILE}
320185499Salfred.endif
321168280Smarcel.for target in ${TARGETS}
322162147Sruuniverse: universe_${target}
323162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
324216520Snwhitehornuniverse_${target}: universe_${target}_prologue
325216520Snwhitehornuniverse_${target}_prologue:
326216520Snwhitehorn	@echo ">> ${target} started on `LC_ALL=C date`"
327179232Sjb.if !defined(MAKE_JUST_KERNELS)
328216520Snwhitehorn.for target_arch in ${TARGET_ARCHES_${target}}
329216520Snwhitehornuniverse_${target}: universe_${target}_${target_arch}
330216520Snwhitehornuniverse_${target}_${target_arch}: universe_${target}_prologue
331216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
332185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
333202629Sed	    ${MAKE} ${JFLAG} buildworld \
334162147Sru	    TARGET=${target} \
335216520Snwhitehorn	    TARGET_ARCH=${target_arch} \
336216520Snwhitehorn	    > _.${target}.${target_arch}.buildworld 2>&1 || \
337216520Snwhitehorn	    (echo "${target}.${target_arch} world failed," \
338216520Snwhitehorn	    "check _.${target}.${target_arch}.buildworld for details" | \
339216520Snwhitehorn	    ${MAKEFAIL}))
340216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
341216520Snwhitehorn.endfor
342179232Sjb.endif
343205290Sdougb.if !defined(MAKE_JUST_WORLDS)
344162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
345185250Sdes	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
346185250Sdes	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
347185499Salfred	    (echo "${target} 'make LINT' failed," \
348185499Salfred	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
349103985Sphk.endif
350201815Sbz	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
351201815Sbz	    universe_kernels
352205290Sdougb.endif
353201815Sbz	@echo ">> ${target} completed on `LC_ALL=C date`"
354201815Sbz.endfor
355201815Sbzuniverse_kernels: universe_kernconfs
356202095Sbz.if !defined(TARGET)
357202095SbzTARGET!=	uname -m
358202095Sbz.endif
359201815SbzKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
360201815Sbz		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
361201815Sbz		! -name DEFAULTS ! -name NOTES
362201815Sbzuniverse_kernconfs:
363148154Sru.for kernel in ${KERNCONFS}
364216520SnwhitehornTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
365216685Simp	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
366216934Simp	grep -v WARNING: | cut -f 2
367216934Simp.if empty(TARGET_ARCH_${kernel})
368216934Simp.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
369216934Simp.endif
370216520Snwhitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
371216520Snwhitehornuniverse_kernconf_${TARGET}_${kernel}:
372185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
373185250Sdes	    ${MAKE} ${JFLAG} buildkernel \
374201815Sbz	    TARGET=${TARGET} \
375216520Snwhitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
376148154Sru	    KERNCONF=${kernel} \
377201815Sbz	    > _.${TARGET}.${kernel} 2>&1 || \
378201815Sbz	    (echo "${TARGET} ${kernel} kernel failed," \
379201815Sbz	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
380148154Sru.endfor
381133945Sruuniverse: universe_epilogue
382133945Sruuniverse_epilogue:
383103985Sphk	@echo "--------------------------------------------------------------"
384118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
385118531Sru	@echo "                      (started ${STARTTIME})"
386103985Sphk	@echo "--------------------------------------------------------------"
387185499Salfred.if defined(DOING_TINDERBOX)
388185499Salfred	@if [ -e ${FAILFILE} ] ; then \
389185499Salfred		echo "Tinderbox failed:" ;\
390185499Salfred		cat ${FAILFILE} ;\
391185499Salfred		exit 1 ;\
392185499Salfred	fi
393133945Sru.endif
394185499Salfred.endif
395