Makefile revision 217294
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 217294 2011-01-11 22:57:41Z 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
43177794Spav# at least 800MB of diskspace available.
4438042Sbde#
4596205Sjwd# For individuals wanting to build from the sources currently on their
4696205Sjwd# system, the simple instructions are:
4738042Sbde#
4896205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
49159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
50159363Strhodes# 3.  `make world'
5117308Speter#
5296205Sjwd# For individuals wanting to upgrade their sources (even if only a
5396205Sjwd# delta of a few days):
5417308Speter#
55148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
56148330Snetchild#  2.  `make buildworld'
57148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
58148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
59159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
60148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
61148330Snetchild#  6.  `mergemaster -p'
62148330Snetchild#  7.  `make installworld'
63148330Snetchild#  8.  `make delete-old'
64178653Srwatson#  9.  `mergemaster'                         (you may wish to use -U or -ai).
65148330Snetchild# 10.  `reboot'
66148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6796205Sjwd#
6896205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
6996205Sjwd#
70162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
71162147Sru# cross build world for other machine types using the buildworld target,
7298723Sdillon# and once the world is built you can cross build a kernel using the
7398723Sdillon# buildkernel target.
7498723Sdillon#
7538666Sjb# Define the user-driven targets. These are listed here in alphabetical
7638666Sjb# order, but that's not important.
7717308Speter#
78123311Speter# Targets that begin with underscore are internal targets intended for
79123311Speter# developer convenience only.  They are intentionally not documented and
80123311Speter# completely subject to change without notice.
81123311Speter#
82175833Sjhb# For more information, see the build(7) manual page.
83175833Sjhb#
84169597SdesTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
85169597Sdes	check-old check-old-dirs check-old-files check-old-libs \
86169597Sdes	checkdpadd clean cleandepend cleandir \
87169597Sdes	delete-old delete-old-dirs delete-old-files delete-old-libs \
88159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
89158962Snetchild	everything hierarchy install installcheck installkernel \
90158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
91158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
92156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
93123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
94137288Speter	_build-tools _cross-tools _includes _libraries _depend \
95209128Sraj	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
96209128Sraj
97156740SruTGTS+=	${SUBDIR_TARGETS}
982061Sjkh
9997769SruBITGTS=	files includes
10097252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
101119579SruTGTS+=	${BITGTS}
10297252Sru
10395730Sru.ORDER: buildworld installworld
10495793Sru.ORDER: buildworld distributeworld
105111617Sru.ORDER: buildworld buildkernel
10695730Sru.ORDER: buildkernel installkernel
107116679Ssimokawa.ORDER: buildkernel installkernel.debug
10895730Sru.ORDER: buildkernel reinstallkernel
109116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
11095730Sru
111110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
112107516SruMAKEOBJDIRPREFIX?=	/usr/obj
113138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
114156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
115138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
116133942Sru.if !empty(_MAKEOBJDIRPREFIX)
117133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
118156145Syar	(in make.conf(5)) or command-line variable.
119133942Sru.endif
120110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
121117234SruBINMAKE= \
122110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
123117229Sru	-m ${.CURDIR}/share/mk
124117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12554324Smarcel
12617308Speter#
127119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
128119519Smarcel# should do this as those are the initial targets used for upgrades.
129119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
130119519Smarcel# for all targets.
131119519Smarcel#
132119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
133119579Sru${TGTS}: upgrade_checks
134119519Smarcel.else
135119519Smarcelbuildworld: upgrade_checks
136119519Smarcel.endif
137119519Smarcel
138119519Smarcel#
139126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
140126024Sgad# recursive target.  All of the work for it is done right here.   It is
141126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
142126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
143126024Sgad# in this makefile.  
144126024Sgad#
145126024Sgad# In the following, the first 'rm' in a series will usually remove all
146126024Sgad# files and directories.  If it does not, then there are probably some
147126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
148126024Sgad# second time.  There are situations where this target will be cleaning
149126024Sgad# some directories via more than one method, but that duplication is
150126024Sgad# needed to correctly handle all the possible situations.
151126024Sgad#
152126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
153126031Sgadcleanworld:
154126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
155126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
156126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
157172744Sdelphij	-chflags -R 0 ${BW_CANONICALOBJDIR}
158126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
159126024Sgad.endif
160126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
161133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
162126024Sgad.else
163126024Sgad	-rm -rf ${.OBJDIR}/*
164172744Sdelphij	-chflags -R 0 ${.OBJDIR}
165126024Sgad	rm -rf ${.OBJDIR}/*
166126024Sgad.endif
167125885Sgad
168125885Sgad#
16938666Sjb# Handle the user-driven targets, using the source relative mk files.
17017308Speter#
171119519Smarcel
172119579Sru${TGTS}:
173133376Sharti	${_+_}@cd ${.CURDIR}; \
174110035Sru		${_MAKE} ${.TARGET}
1752302Spaul
17639206Sjkh# Set a reasonable default
17739206Sjkh.MAIN:	all
17839206Sjkh
179133945SruSTARTTIME!= LC_ALL=C date
180177609SruCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
181177609Sru.if !empty(CHECK_TIME)
182177609Sru.error check your date/time: ${STARTTIME}
183177609Sru.endif
184133945Sru
185132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18617308Speter#
18754324Smarcel# world
18854324Smarcel#
189132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
190132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
191132234Smarcel# not included. One can argue that this target doesn't build everything
192132234Smarcel# then.
19354324Smarcel#
19454324Smarcelworld: upgrade_checks
19554324Smarcel	@echo "--------------------------------------------------------------"
196118531Sru	@echo ">>> make world started on ${STARTTIME}"
19754324Smarcel	@echo "--------------------------------------------------------------"
19854324Smarcel.if target(pre-world)
19954324Smarcel	@echo
20054324Smarcel	@echo "--------------------------------------------------------------"
20154324Smarcel	@echo ">>> Making 'pre-world' target"
20254324Smarcel	@echo "--------------------------------------------------------------"
203133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20454324Smarcel.endif
205133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
206133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20754324Smarcel.if target(post-world)
20854324Smarcel	@echo
20954324Smarcel	@echo "--------------------------------------------------------------"
21054324Smarcel	@echo ">>> Making 'post-world' target"
21154324Smarcel	@echo "--------------------------------------------------------------"
212133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21354324Smarcel.endif
21454324Smarcel	@echo
21554324Smarcel	@echo "--------------------------------------------------------------"
216118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
217118531Sru	@echo "                   (started ${STARTTIME})"
21854324Smarcel	@echo "--------------------------------------------------------------"
219132234Smarcel.else
220132234Smarcelworld:
221132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
222132234Smarcel	@echo "installation without also building and installing a new"
223132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
224132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
225132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
226132234Smarcel	@echo "including /, to override this warning and proceed as usual."
227132358Smarkm	@echo ""
228132234Smarcel	@echo "Bailing out now..."
229132234Smarcel	@false
230132234Smarcel.endif
23154324Smarcel
23254324Smarcel#
23395730Sru# kernel
23495730Sru#
23595730Sru# Short hand for `make buildkernel installkernel'
23695730Sru#
23795730Srukernel: buildkernel installkernel
23895730Sru
23995730Sru#
24038666Sjb# Perform a few tests to determine if the installed tools are adequate
241107374Sru# for building the world.
24217308Speter#
24355678Smarcelupgrade_checks:
244143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
245138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
246117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
247110035Sru	then \
248174564Simp	    (cd ${.CURDIR} && ${MAKE} make); \
249110035Sru	fi
2502061Sjkh
25117308Speter#
252107516Sru# Upgrade make(1) to the current version using the installed
253174539Simp# headers, libraries and tools.  Also, allow the location of
254174539Simp# the system bsdmake-like utility to be overridden.
25555678Smarcel#
256107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
257107516Sru		DESTDIR= \
258107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
259174564SimpMMAKE=		${MMAKEENV} ${MAKE} \
260107516Sru		-D_UPGRADING \
261139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
262164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
263107516Sru
264122204Skrismake: .PHONY
26555678Smarcel	@echo
26655678Smarcel	@echo "--------------------------------------------------------------"
267116696Sru	@echo ">>> Building an up-to-date make(1)"
26855678Smarcel	@echo "--------------------------------------------------------------"
269133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
270107516Sru		${MMAKE} obj && \
271107516Sru		${MMAKE} depend && \
272107516Sru		${MMAKE} all && \
273107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27455678Smarcel
275185499Salfredtinderbox:
276185499Salfred	cd ${.CURDIR} && \
277216487Sjhb		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
278185499Salfred
27955678Smarcel#
280111131Sru# universe
281111131Sru#
282111131Sru# Attempt to rebuild *everything* for all supported architectures,
283133945Sru# with a reasonable chance of success, regardless of how old your
284111131Sru# existing system is.
285111131Sru#
286217125Simp.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
287216520SnwhitehornTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
288216520SnwhitehornTARGET_ARCHES_arm?=	arm armeb
289217123SimpTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
290216520SnwhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
291216520SnwhitehornTARGET_ARCHES_pc98?=	i386
292216520SnwhitehornTARGET_ARCHES_sun4v?=	sparc64
293216520Snwhitehorn.for target in ${TARGETS}
294216520SnwhitehornTARGET_ARCHES_${target}?= ${target}
295216520Snwhitehorn.endfor
296168280Smarcel
297217125Simptargets:
298217125Simp	@echo "Supported TARGET/TARGET_ARCH pairs"
299217125Simp.for target in ${TARGETS}
300217125Simp.for target_arch in ${TARGET_ARCHES_${target}}
301217125Simp	@echo "    ${target}/${target_arch}"
302217125Simp.endfor
303217125Simp.endfor
304217125Simp
305185499Salfred.if defined(DOING_TINDERBOX)
306185499SalfredFAILFILE=tinderbox.failed
307185499SalfredMAKEFAIL=tee -a ${FAILFILE}
308185499Salfred.else
309185499SalfredMAKEFAIL=cat
310185499Salfred.endif
311185499Salfred
312133945Sruuniverse: universe_prologue
313133945Sruuniverse_prologue:
314103985Sphk	@echo "--------------------------------------------------------------"
315103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
316103985Sphk	@echo "--------------------------------------------------------------"
317185499Salfred.if defined(DOING_TINDERBOX)
318185499Salfred	rm -f ${FAILFILE}
319185499Salfred.endif
320168280Smarcel.for target in ${TARGETS}
321162147Sruuniverse: universe_${target}
322162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
323216520Snwhitehornuniverse_${target}: universe_${target}_prologue
324216520Snwhitehornuniverse_${target}_prologue:
325216520Snwhitehorn	@echo ">> ${target} started on `LC_ALL=C date`"
326179232Sjb.if !defined(MAKE_JUST_KERNELS)
327216520Snwhitehorn.for target_arch in ${TARGET_ARCHES_${target}}
328216520Snwhitehornuniverse_${target}: universe_${target}_${target_arch}
329216520Snwhitehornuniverse_${target}_${target_arch}: universe_${target}_prologue
330216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
331185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
332202629Sed	    ${MAKE} ${JFLAG} buildworld \
333162147Sru	    TARGET=${target} \
334216520Snwhitehorn	    TARGET_ARCH=${target_arch} \
335216520Snwhitehorn	    > _.${target}.${target_arch}.buildworld 2>&1 || \
336216520Snwhitehorn	    (echo "${target}.${target_arch} world failed," \
337216520Snwhitehorn	    "check _.${target}.${target_arch}.buildworld for details" | \
338216520Snwhitehorn	    ${MAKEFAIL}))
339216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
340216520Snwhitehorn.endfor
341179232Sjb.endif
342205290Sdougb.if !defined(MAKE_JUST_WORLDS)
343162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
344185250Sdes	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
345185250Sdes	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
346185499Salfred	    (echo "${target} 'make LINT' failed," \
347185499Salfred	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
348103985Sphk.endif
349201815Sbz	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
350201815Sbz	    universe_kernels
351205290Sdougb.endif
352201815Sbz	@echo ">> ${target} completed on `LC_ALL=C date`"
353201815Sbz.endfor
354201815Sbzuniverse_kernels: universe_kernconfs
355202095Sbz.if !defined(TARGET)
356202095SbzTARGET!=	uname -m
357202095Sbz.endif
358201815SbzKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
359201815Sbz		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
360201815Sbz		! -name DEFAULTS ! -name NOTES
361201815Sbzuniverse_kernconfs:
362148154Sru.for kernel in ${KERNCONFS}
363216520SnwhitehornTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
364216685Simp	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
365216934Simp	grep -v WARNING: | cut -f 2
366216934Simp.if empty(TARGET_ARCH_${kernel})
367216934Simp.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
368216934Simp.endif
369216520Snwhitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
370216520Snwhitehornuniverse_kernconf_${TARGET}_${kernel}:
371185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
372185250Sdes	    ${MAKE} ${JFLAG} buildkernel \
373201815Sbz	    TARGET=${TARGET} \
374216520Snwhitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
375148154Sru	    KERNCONF=${kernel} \
376201815Sbz	    > _.${TARGET}.${kernel} 2>&1 || \
377201815Sbz	    (echo "${TARGET} ${kernel} kernel failed," \
378201815Sbz	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
379148154Sru.endfor
380133945Sruuniverse: universe_epilogue
381133945Sruuniverse_epilogue:
382103985Sphk	@echo "--------------------------------------------------------------"
383118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
384118531Sru	@echo "                      (started ${STARTTIME})"
385103985Sphk	@echo "--------------------------------------------------------------"
386185499Salfred.if defined(DOING_TINDERBOX)
387185499Salfred	@if [ -e ${FAILFILE} ] ; then \
388185499Salfred		echo "Tinderbox failed:" ;\
389185499Salfred		cat ${FAILFILE} ;\
390185499Salfred		exit 1 ;\
391185499Salfred	fi
392133945Sru.endif
393185499Salfred.endif
394