Makefile revision 217815
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 217815 2011-01-25 08:13:31Z bz $
32061Sjkh#
438666Sjb# The user-driven targets are:
532427Sjb#
6111131Sru# universe            - *Really* build *everything* (buildworld and
7111131Sru#                       all kernels on all architectures).
8217733Sbz# tinderbox           - Same as universe, but presents a list of failed build
9217733Sbz#                       targets and exits with an error if there were any.
1038666Sjb# buildworld          - Rebuild *everything*, including glue to help do
1138666Sjb#                       upgrades.
1238666Sjb# installworld        - Install everything built by "buildworld".
13159363Strhodes# world               - buildworld + installworld, no kernel.
1464049Salex# buildkernel         - Rebuild the kernel and the kernel-modules.
1564049Salex# installkernel       - Install the kernel and the kernel-modules.
16116679Ssimokawa# installkernel.debug
1766071Smarkm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
18116679Ssimokawa# reinstallkernel.debug
1973504Sobrien# kernel              - buildkernel + installkernel.
20204661Simp# kernel-toolchain    - Builds the subset of world necessary to build a kernel
21158962Snetchild# doxygen             - Build API documentation of the kernel, needs doxygen.
2238666Sjb# update              - Convenient way to update your source tree (cvs).
23169597Sdes# check-old           - List obsolete directories/files/libraries.
24169597Sdes# check-old-dirs      - List obsolete directories.
25169597Sdes# check-old-files     - List obsolete files.
26169597Sdes# check-old-libs      - List obsolete libraries.
27169597Sdes# delete-old          - Delete obsolete directories/files/libraries.
28169597Sdes# delete-old-dirs     - Delete obsolete directories.
29169597Sdes# delete-old-files    - Delete obsolete files.
30169597Sdes# delete-old-libs     - Delete obsolete libraries.
31217815Sbz# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
32217815Sbz#                       for world and kernel targets.
3332427Sjb#
3438666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
35108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3638666Sjb# command line. By keeping this makefile simple, it doesn't matter too
3738666Sjb# much how different the installed mk files are from those in the source
3838666Sjb# tree. This makefile executes a child make process, forcing it to use
3938666Sjb# the mk files from the source tree which are supposed to DTRT.
4017308Speter#
41217273Simp# Most of the user-driven targets (as listed above) are implemented in
42217294Simp# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
4319175Sbde#
4496205Sjwd# If you want to build your system from source be sure that /usr/obj has
45217297Simp# at least 1GB of diskspace available.  A complete 'universe' build requires
46217297Simp# about 15GB of space.
4738042Sbde#
4896205Sjwd# For individuals wanting to build from the sources currently on their
4996205Sjwd# system, the simple instructions are:
5038042Sbde#
5196205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
52159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
53159363Strhodes# 3.  `make world'
5417308Speter#
5596205Sjwd# For individuals wanting to upgrade their sources (even if only a
5696205Sjwd# delta of a few days):
5717308Speter#
58148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
59148330Snetchild#  2.  `make buildworld'
60148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
61148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
62159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
63148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
64148330Snetchild#  6.  `mergemaster -p'
65148330Snetchild#  7.  `make installworld'
66148330Snetchild#  8.  `make delete-old'
67178653Srwatson#  9.  `mergemaster'                         (you may wish to use -U or -ai).
68148330Snetchild# 10.  `reboot'
69148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
7096205Sjwd#
7196205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
7296205Sjwd#
73162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
74162147Sru# cross build world for other machine types using the buildworld target,
7598723Sdillon# and once the world is built you can cross build a kernel using the
7698723Sdillon# buildkernel target.
7798723Sdillon#
7838666Sjb# Define the user-driven targets. These are listed here in alphabetical
7938666Sjb# order, but that's not important.
8017308Speter#
81123311Speter# Targets that begin with underscore are internal targets intended for
82123311Speter# developer convenience only.  They are intentionally not documented and
83123311Speter# completely subject to change without notice.
84123311Speter#
85175833Sjhb# For more information, see the build(7) manual page.
86175833Sjhb#
87169597SdesTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
88169597Sdes	check-old check-old-dirs check-old-files check-old-libs \
89169597Sdes	checkdpadd clean cleandepend cleandir \
90169597Sdes	delete-old delete-old-dirs delete-old-files delete-old-libs \
91159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
92158962Snetchild	everything hierarchy install installcheck installkernel \
93158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
94158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
95156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
96123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
97137288Speter	_build-tools _cross-tools _includes _libraries _depend \
98209128Sraj	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
99209128Sraj
100156740SruTGTS+=	${SUBDIR_TARGETS}
1012061Sjkh
10297769SruBITGTS=	files includes
10397252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
104119579SruTGTS+=	${BITGTS}
10597252Sru
10695730Sru.ORDER: buildworld installworld
10795793Sru.ORDER: buildworld distributeworld
108111617Sru.ORDER: buildworld buildkernel
10995730Sru.ORDER: buildkernel installkernel
110116679Ssimokawa.ORDER: buildkernel installkernel.debug
11195730Sru.ORDER: buildkernel reinstallkernel
112116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
11395730Sru
114110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
115107516SruMAKEOBJDIRPREFIX?=	/usr/obj
116138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
117156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
118138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
119133942Sru.if !empty(_MAKEOBJDIRPREFIX)
120133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
121156145Syar	(in make.conf(5)) or command-line variable.
122133942Sru.endif
123110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
124117234SruBINMAKE= \
125110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
126117229Sru	-m ${.CURDIR}/share/mk
127117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12854324Smarcel
12917308Speter#
130119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
131119519Smarcel# should do this as those are the initial targets used for upgrades.
132119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
133119519Smarcel# for all targets.
134119519Smarcel#
135119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
136119579Sru${TGTS}: upgrade_checks
137119519Smarcel.else
138119519Smarcelbuildworld: upgrade_checks
139119519Smarcel.endif
140119519Smarcel
141119519Smarcel#
142126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
143126024Sgad# recursive target.  All of the work for it is done right here.   It is
144126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
145126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
146126024Sgad# in this makefile.  
147126024Sgad#
148126024Sgad# In the following, the first 'rm' in a series will usually remove all
149126024Sgad# files and directories.  If it does not, then there are probably some
150126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
151126024Sgad# second time.  There are situations where this target will be cleaning
152126024Sgad# some directories via more than one method, but that duplication is
153126024Sgad# needed to correctly handle all the possible situations.
154126024Sgad#
155126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
156126031Sgadcleanworld:
157126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
158126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
159126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
160172744Sdelphij	-chflags -R 0 ${BW_CANONICALOBJDIR}
161126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
162126024Sgad.endif
163126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
164133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
165126024Sgad.else
166126024Sgad	-rm -rf ${.OBJDIR}/*
167172744Sdelphij	-chflags -R 0 ${.OBJDIR}
168126024Sgad	rm -rf ${.OBJDIR}/*
169126024Sgad.endif
170125885Sgad
171125885Sgad#
17238666Sjb# Handle the user-driven targets, using the source relative mk files.
17317308Speter#
174119519Smarcel
175119579Sru${TGTS}:
176133376Sharti	${_+_}@cd ${.CURDIR}; \
177110035Sru		${_MAKE} ${.TARGET}
1782302Spaul
17939206Sjkh# Set a reasonable default
18039206Sjkh.MAIN:	all
18139206Sjkh
182133945SruSTARTTIME!= LC_ALL=C date
183177609SruCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
184177609Sru.if !empty(CHECK_TIME)
185177609Sru.error check your date/time: ${STARTTIME}
186177609Sru.endif
187133945Sru
188132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18917308Speter#
19054324Smarcel# world
19154324Smarcel#
192132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
193132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
194132234Smarcel# not included. One can argue that this target doesn't build everything
195132234Smarcel# then.
19654324Smarcel#
19754324Smarcelworld: upgrade_checks
19854324Smarcel	@echo "--------------------------------------------------------------"
199118531Sru	@echo ">>> make world started on ${STARTTIME}"
20054324Smarcel	@echo "--------------------------------------------------------------"
20154324Smarcel.if target(pre-world)
20254324Smarcel	@echo
20354324Smarcel	@echo "--------------------------------------------------------------"
20454324Smarcel	@echo ">>> Making 'pre-world' target"
20554324Smarcel	@echo "--------------------------------------------------------------"
206133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20754324Smarcel.endif
208133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
209133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
21054324Smarcel.if target(post-world)
21154324Smarcel	@echo
21254324Smarcel	@echo "--------------------------------------------------------------"
21354324Smarcel	@echo ">>> Making 'post-world' target"
21454324Smarcel	@echo "--------------------------------------------------------------"
215133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21654324Smarcel.endif
21754324Smarcel	@echo
21854324Smarcel	@echo "--------------------------------------------------------------"
219118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
220118531Sru	@echo "                   (started ${STARTTIME})"
22154324Smarcel	@echo "--------------------------------------------------------------"
222132234Smarcel.else
223132234Smarcelworld:
224132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
225132234Smarcel	@echo "installation without also building and installing a new"
226132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
227132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
228132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
229132234Smarcel	@echo "including /, to override this warning and proceed as usual."
230132358Smarkm	@echo ""
231132234Smarcel	@echo "Bailing out now..."
232132234Smarcel	@false
233132234Smarcel.endif
23454324Smarcel
23554324Smarcel#
23695730Sru# kernel
23795730Sru#
23895730Sru# Short hand for `make buildkernel installkernel'
23995730Sru#
24095730Srukernel: buildkernel installkernel
24195730Sru
24295730Sru#
24338666Sjb# Perform a few tests to determine if the installed tools are adequate
244107374Sru# for building the world.
24517308Speter#
24655678Smarcelupgrade_checks:
247143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
248138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
249117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
250110035Sru	then \
251174564Simp	    (cd ${.CURDIR} && ${MAKE} make); \
252110035Sru	fi
2532061Sjkh
25417308Speter#
255107516Sru# Upgrade make(1) to the current version using the installed
256174539Simp# headers, libraries and tools.  Also, allow the location of
257174539Simp# the system bsdmake-like utility to be overridden.
25855678Smarcel#
259107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
260107516Sru		DESTDIR= \
261107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
262174564SimpMMAKE=		${MMAKEENV} ${MAKE} \
263107516Sru		-D_UPGRADING \
264139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
265164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
266107516Sru
267122204Skrismake: .PHONY
26855678Smarcel	@echo
26955678Smarcel	@echo "--------------------------------------------------------------"
270116696Sru	@echo ">>> Building an up-to-date make(1)"
27155678Smarcel	@echo "--------------------------------------------------------------"
272133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
273107516Sru		${MMAKE} obj && \
274107516Sru		${MMAKE} depend && \
275107516Sru		${MMAKE} all && \
276107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27755678Smarcel
278185499Salfredtinderbox:
279217754Sbz	@cd ${.CURDIR} && \
280216487Sjhb		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
281185499Salfred
28255678Smarcel#
283111131Sru# universe
284111131Sru#
285111131Sru# Attempt to rebuild *everything* for all supported architectures,
286133945Sru# with a reasonable chance of success, regardless of how old your
287111131Sru# existing system is.
288111131Sru#
289217125Simp.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
290216520SnwhitehornTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
291216520SnwhitehornTARGET_ARCHES_arm?=	arm armeb
292217123SimpTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
293216520SnwhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
294216520SnwhitehornTARGET_ARCHES_pc98?=	i386
295216520SnwhitehornTARGET_ARCHES_sun4v?=	sparc64
296216520Snwhitehorn.for target in ${TARGETS}
297216520SnwhitehornTARGET_ARCHES_${target}?= ${target}
298216520Snwhitehorn.endfor
299168280Smarcel
300217125Simptargets:
301217815Sbz	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
302217125Simp.for target in ${TARGETS}
303217125Simp.for target_arch in ${TARGET_ARCHES_${target}}
304217125Simp	@echo "    ${target}/${target_arch}"
305217125Simp.endfor
306217125Simp.endfor
307217125Simp
308185499Salfred.if defined(DOING_TINDERBOX)
309217735SbzFAILFILE=${.CURDIR}/_.tinderbox.failed
310185499SalfredMAKEFAIL=tee -a ${FAILFILE}
311185499Salfred.else
312185499SalfredMAKEFAIL=cat
313185499Salfred.endif
314185499Salfred
315133945Sruuniverse: universe_prologue
316133945Sruuniverse_prologue:
317103985Sphk	@echo "--------------------------------------------------------------"
318103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
319103985Sphk	@echo "--------------------------------------------------------------"
320185499Salfred.if defined(DOING_TINDERBOX)
321217754Sbz	@rm -f ${FAILFILE}
322185499Salfred.endif
323168280Smarcel.for target in ${TARGETS}
324162147Sruuniverse: universe_${target}
325162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
326216520Snwhitehornuniverse_${target}: universe_${target}_prologue
327216520Snwhitehornuniverse_${target}_prologue:
328216520Snwhitehorn	@echo ">> ${target} started on `LC_ALL=C date`"
329179232Sjb.if !defined(MAKE_JUST_KERNELS)
330216520Snwhitehorn.for target_arch in ${TARGET_ARCHES_${target}}
331216520Snwhitehornuniverse_${target}: universe_${target}_${target_arch}
332216520Snwhitehornuniverse_${target}_${target_arch}: universe_${target}_prologue
333216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
334185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
335202629Sed	    ${MAKE} ${JFLAG} buildworld \
336162147Sru	    TARGET=${target} \
337216520Snwhitehorn	    TARGET_ARCH=${target_arch} \
338216520Snwhitehorn	    > _.${target}.${target_arch}.buildworld 2>&1 || \
339216520Snwhitehorn	    (echo "${target}.${target_arch} world failed," \
340216520Snwhitehorn	    "check _.${target}.${target_arch}.buildworld for details" | \
341216520Snwhitehorn	    ${MAKEFAIL}))
342216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
343216520Snwhitehorn.endfor
344179232Sjb.endif
345205290Sdougb.if !defined(MAKE_JUST_WORLDS)
346162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
347185250Sdes	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
348185250Sdes	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
349185499Salfred	    (echo "${target} 'make LINT' failed," \
350185499Salfred	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
351103985Sphk.endif
352201815Sbz	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
353201815Sbz	    universe_kernels
354205290Sdougb.endif
355201815Sbz	@echo ">> ${target} completed on `LC_ALL=C date`"
356201815Sbz.endfor
357201815Sbzuniverse_kernels: universe_kernconfs
358202095Sbz.if !defined(TARGET)
359202095SbzTARGET!=	uname -m
360202095Sbz.endif
361201815SbzKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
362201815Sbz		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
363201815Sbz		! -name DEFAULTS ! -name NOTES
364201815Sbzuniverse_kernconfs:
365148154Sru.for kernel in ${KERNCONFS}
366216520SnwhitehornTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
367216685Simp	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
368216934Simp	grep -v WARNING: | cut -f 2
369216934Simp.if empty(TARGET_ARCH_${kernel})
370216934Simp.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
371216934Simp.endif
372216520Snwhitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
373216520Snwhitehornuniverse_kernconf_${TARGET}_${kernel}:
374185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
375185250Sdes	    ${MAKE} ${JFLAG} buildkernel \
376201815Sbz	    TARGET=${TARGET} \
377216520Snwhitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
378148154Sru	    KERNCONF=${kernel} \
379201815Sbz	    > _.${TARGET}.${kernel} 2>&1 || \
380201815Sbz	    (echo "${TARGET} ${kernel} kernel failed," \
381201815Sbz	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
382148154Sru.endfor
383133945Sruuniverse: universe_epilogue
384133945Sruuniverse_epilogue:
385103985Sphk	@echo "--------------------------------------------------------------"
386118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
387118531Sru	@echo "                      (started ${STARTTIME})"
388103985Sphk	@echo "--------------------------------------------------------------"
389185499Salfred.if defined(DOING_TINDERBOX)
390185499Salfred	@if [ -e ${FAILFILE} ] ; then \
391185499Salfred		echo "Tinderbox failed:" ;\
392185499Salfred		cat ${FAILFILE} ;\
393185499Salfred		exit 1 ;\
394185499Salfred	fi
395133945Sru.endif
396185499Salfred.endif
397