Makefile revision 216520
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 216520 2010-12-18 14:34:05Z nwhitehorn $
32061Sjkh#
438666Sjb# The user-driven targets are:
532427Sjb#
6111131Sru# universe            - *Really* build *everything* (buildworld and
7111131Sru#                       all kernels on all architectures).
838666Sjb# buildworld          - Rebuild *everything*, including glue to help do
938666Sjb#                       upgrades.
1038666Sjb# installworld        - Install everything built by "buildworld".
11159363Strhodes# world               - buildworld + installworld, no kernel.
1264049Salex# buildkernel         - Rebuild the kernel and the kernel-modules.
1364049Salex# installkernel       - Install the kernel and the kernel-modules.
14116679Ssimokawa# installkernel.debug
1566071Smarkm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
16116679Ssimokawa# reinstallkernel.debug
1773504Sobrien# kernel              - buildkernel + installkernel.
18204661Simp# kernel-toolchain    - Builds the subset of world necessary to build a kernel
19158962Snetchild# doxygen             - Build API documentation of the kernel, needs doxygen.
2038666Sjb# update              - Convenient way to update your source tree (cvs).
21169597Sdes# check-old           - List obsolete directories/files/libraries.
22169597Sdes# check-old-dirs      - List obsolete directories.
23169597Sdes# check-old-files     - List obsolete files.
24169597Sdes# check-old-libs      - List obsolete libraries.
25169597Sdes# delete-old          - Delete obsolete directories/files/libraries.
26169597Sdes# delete-old-dirs     - Delete obsolete directories.
27169597Sdes# delete-old-files    - Delete obsolete files.
28169597Sdes# delete-old-libs     - Delete obsolete libraries.
2932427Sjb#
3038666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
31108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3238666Sjb# command line. By keeping this makefile simple, it doesn't matter too
3338666Sjb# much how different the installed mk files are from those in the source
3438666Sjb# tree. This makefile executes a child make process, forcing it to use
3538666Sjb# the mk files from the source tree which are supposed to DTRT.
3617308Speter#
3791606Skeramida# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3819175Sbde#
3996205Sjwd# If you want to build your system from source be sure that /usr/obj has
40177794Spav# at least 800MB of diskspace available.
4138042Sbde#
4296205Sjwd# For individuals wanting to build from the sources currently on their
4396205Sjwd# system, the simple instructions are:
4438042Sbde#
4596205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
46159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
47159363Strhodes# 3.  `make world'
4817308Speter#
4996205Sjwd# For individuals wanting to upgrade their sources (even if only a
5096205Sjwd# delta of a few days):
5117308Speter#
52148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
53148330Snetchild#  2.  `make buildworld'
54148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
55148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
56159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
57148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
58148330Snetchild#  6.  `mergemaster -p'
59148330Snetchild#  7.  `make installworld'
60148330Snetchild#  8.  `make delete-old'
61178653Srwatson#  9.  `mergemaster'                         (you may wish to use -U or -ai).
62148330Snetchild# 10.  `reboot'
63148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6496205Sjwd#
6596205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
6696205Sjwd#
67162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
68162147Sru# cross build world for other machine types using the buildworld target,
6998723Sdillon# and once the world is built you can cross build a kernel using the
7098723Sdillon# buildkernel target.
7198723Sdillon#
7238666Sjb# Define the user-driven targets. These are listed here in alphabetical
7338666Sjb# order, but that's not important.
7417308Speter#
75123311Speter# Targets that begin with underscore are internal targets intended for
76123311Speter# developer convenience only.  They are intentionally not documented and
77123311Speter# completely subject to change without notice.
78123311Speter#
79175833Sjhb# For more information, see the build(7) manual page.
80175833Sjhb#
81169597SdesTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
82169597Sdes	check-old check-old-dirs check-old-files check-old-libs \
83169597Sdes	checkdpadd clean cleandepend cleandir \
84169597Sdes	delete-old delete-old-dirs delete-old-files delete-old-libs \
85159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
86158962Snetchild	everything hierarchy install installcheck installkernel \
87158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
88158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
89156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
90123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
91137288Speter	_build-tools _cross-tools _includes _libraries _depend \
92209128Sraj	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
93209128Sraj
94156740SruTGTS+=	${SUBDIR_TARGETS}
952061Sjkh
9697769SruBITGTS=	files includes
9797252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
98119579SruTGTS+=	${BITGTS}
9997252Sru
10095730Sru.ORDER: buildworld installworld
10195793Sru.ORDER: buildworld distributeworld
102111617Sru.ORDER: buildworld buildkernel
10395730Sru.ORDER: buildkernel installkernel
104116679Ssimokawa.ORDER: buildkernel installkernel.debug
10595730Sru.ORDER: buildkernel reinstallkernel
106116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
10795730Sru
108110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
109107516SruMAKEOBJDIRPREFIX?=	/usr/obj
110138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
111156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
112138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
113133942Sru.if !empty(_MAKEOBJDIRPREFIX)
114133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
115156145Syar	(in make.conf(5)) or command-line variable.
116133942Sru.endif
117110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
118117234SruBINMAKE= \
119110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
120117229Sru	-m ${.CURDIR}/share/mk
121117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12254324Smarcel
12317308Speter#
124119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
125119519Smarcel# should do this as those are the initial targets used for upgrades.
126119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
127119519Smarcel# for all targets.
128119519Smarcel#
129119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
130119579Sru${TGTS}: upgrade_checks
131119519Smarcel.else
132119519Smarcelbuildworld: upgrade_checks
133119519Smarcel.endif
134119519Smarcel
135119519Smarcel#
136126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
137126024Sgad# recursive target.  All of the work for it is done right here.   It is
138126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
139126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
140126024Sgad# in this makefile.  
141126024Sgad#
142126024Sgad# In the following, the first 'rm' in a series will usually remove all
143126024Sgad# files and directories.  If it does not, then there are probably some
144126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
145126024Sgad# second time.  There are situations where this target will be cleaning
146126024Sgad# some directories via more than one method, but that duplication is
147126024Sgad# needed to correctly handle all the possible situations.
148126024Sgad#
149126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
150126031Sgadcleanworld:
151126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
152126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
153126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
154172744Sdelphij	-chflags -R 0 ${BW_CANONICALOBJDIR}
155126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
156126024Sgad.endif
157126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
158133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
159126024Sgad.else
160126024Sgad	-rm -rf ${.OBJDIR}/*
161172744Sdelphij	-chflags -R 0 ${.OBJDIR}
162126024Sgad	rm -rf ${.OBJDIR}/*
163126024Sgad.endif
164125885Sgad
165125885Sgad#
16638666Sjb# Handle the user-driven targets, using the source relative mk files.
16717308Speter#
168119519Smarcel
169119579Sru${TGTS}:
170133376Sharti	${_+_}@cd ${.CURDIR}; \
171110035Sru		${_MAKE} ${.TARGET}
1722302Spaul
17339206Sjkh# Set a reasonable default
17439206Sjkh.MAIN:	all
17539206Sjkh
176133945SruSTARTTIME!= LC_ALL=C date
177177609SruCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
178177609Sru.if !empty(CHECK_TIME)
179177609Sru.error check your date/time: ${STARTTIME}
180177609Sru.endif
181133945Sru
182132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18317308Speter#
18454324Smarcel# world
18554324Smarcel#
186132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
187132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
188132234Smarcel# not included. One can argue that this target doesn't build everything
189132234Smarcel# then.
19054324Smarcel#
19154324Smarcelworld: upgrade_checks
19254324Smarcel	@echo "--------------------------------------------------------------"
193118531Sru	@echo ">>> make world started on ${STARTTIME}"
19454324Smarcel	@echo "--------------------------------------------------------------"
19554324Smarcel.if target(pre-world)
19654324Smarcel	@echo
19754324Smarcel	@echo "--------------------------------------------------------------"
19854324Smarcel	@echo ">>> Making 'pre-world' target"
19954324Smarcel	@echo "--------------------------------------------------------------"
200133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20154324Smarcel.endif
202133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
203133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20454324Smarcel.if target(post-world)
20554324Smarcel	@echo
20654324Smarcel	@echo "--------------------------------------------------------------"
20754324Smarcel	@echo ">>> Making 'post-world' target"
20854324Smarcel	@echo "--------------------------------------------------------------"
209133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21054324Smarcel.endif
21154324Smarcel	@echo
21254324Smarcel	@echo "--------------------------------------------------------------"
213118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
214118531Sru	@echo "                   (started ${STARTTIME})"
21554324Smarcel	@echo "--------------------------------------------------------------"
216132234Smarcel.else
217132234Smarcelworld:
218132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
219132234Smarcel	@echo "installation without also building and installing a new"
220132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
221132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
222132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
223132234Smarcel	@echo "including /, to override this warning and proceed as usual."
224132358Smarkm	@echo ""
225132234Smarcel	@echo "Bailing out now..."
226132234Smarcel	@false
227132234Smarcel.endif
22854324Smarcel
22954324Smarcel#
23095730Sru# kernel
23195730Sru#
23295730Sru# Short hand for `make buildkernel installkernel'
23395730Sru#
23495730Srukernel: buildkernel installkernel
23595730Sru
23695730Sru#
23738666Sjb# Perform a few tests to determine if the installed tools are adequate
238107374Sru# for building the world.
23917308Speter#
24055678Smarcelupgrade_checks:
241143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
242138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
243117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
244110035Sru	then \
245174564Simp	    (cd ${.CURDIR} && ${MAKE} make); \
246110035Sru	fi
2472061Sjkh
24817308Speter#
249107516Sru# Upgrade make(1) to the current version using the installed
250174539Simp# headers, libraries and tools.  Also, allow the location of
251174539Simp# the system bsdmake-like utility to be overridden.
25255678Smarcel#
253107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
254107516Sru		DESTDIR= \
255107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
256174564SimpMMAKE=		${MMAKEENV} ${MAKE} \
257107516Sru		-D_UPGRADING \
258139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
259164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
260107516Sru
261122204Skrismake: .PHONY
26255678Smarcel	@echo
26355678Smarcel	@echo "--------------------------------------------------------------"
264116696Sru	@echo ">>> Building an up-to-date make(1)"
26555678Smarcel	@echo "--------------------------------------------------------------"
266133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
267107516Sru		${MMAKE} obj && \
268107516Sru		${MMAKE} depend && \
269107516Sru		${MMAKE} all && \
270107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27155678Smarcel
272185499Salfredtinderbox:
273185499Salfred	cd ${.CURDIR} && \
274216487Sjhb		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
275185499Salfred
27655678Smarcel#
277111131Sru# universe
278111131Sru#
279111131Sru# Attempt to rebuild *everything* for all supported architectures,
280133945Sru# with a reasonable chance of success, regardless of how old your
281111131Sru# existing system is.
282111131Sru#
283201815Sbz.if make(universe) || make(universe_kernels) || make(tinderbox)
284216520SnwhitehornTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
285216520SnwhitehornTARGET_ARCHES_arm?=	arm armeb
286216520SnwhitehornTARGET_ARCHES_mips?=	mipsel mipseb
287216520SnwhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
288216520SnwhitehornTARGET_ARCHES_pc98?=	i386
289216520SnwhitehornTARGET_ARCHES_sun4v?=	sparc64
290216520Snwhitehorn.for target in ${TARGETS}
291216520SnwhitehornTARGET_ARCHES_${target}?= ${target}
292216520Snwhitehorn.endfor
293168280Smarcel
294185499Salfred.if defined(DOING_TINDERBOX)
295185499SalfredFAILFILE=tinderbox.failed
296185499SalfredMAKEFAIL=tee -a ${FAILFILE}
297185499Salfred.else
298185499SalfredMAKEFAIL=cat
299185499Salfred.endif
300185499Salfred
301133945Sruuniverse: universe_prologue
302133945Sruuniverse_prologue:
303103985Sphk	@echo "--------------------------------------------------------------"
304103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
305103985Sphk	@echo "--------------------------------------------------------------"
306185499Salfred.if defined(DOING_TINDERBOX)
307185499Salfred	rm -f ${FAILFILE}
308185499Salfred.endif
309168280Smarcel.for target in ${TARGETS}
310162147Sruuniverse: universe_${target}
311162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
312216520Snwhitehornuniverse_${target}: universe_${target}_prologue
313216520Snwhitehornuniverse_${target}_prologue:
314216520Snwhitehorn	@echo ">> ${target} started on `LC_ALL=C date`"
315179232Sjb.if !defined(MAKE_JUST_KERNELS)
316216520Snwhitehorn.for target_arch in ${TARGET_ARCHES_${target}}
317216520Snwhitehornuniverse_${target}: universe_${target}_${target_arch}
318216520Snwhitehornuniverse_${target}_${target_arch}: universe_${target}_prologue
319216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
320185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
321202629Sed	    ${MAKE} ${JFLAG} buildworld \
322162147Sru	    TARGET=${target} \
323216520Snwhitehorn	    TARGET_ARCH=${target_arch} \
324216520Snwhitehorn	    > _.${target}.${target_arch}.buildworld 2>&1 || \
325216520Snwhitehorn	    (echo "${target}.${target_arch} world failed," \
326216520Snwhitehorn	    "check _.${target}.${target_arch}.buildworld for details" | \
327216520Snwhitehorn	    ${MAKEFAIL}))
328216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
329216520Snwhitehorn.endfor
330179232Sjb.endif
331205290Sdougb.if !defined(MAKE_JUST_WORLDS)
332162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
333185250Sdes	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
334185250Sdes	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
335185499Salfred	    (echo "${target} 'make LINT' failed," \
336185499Salfred	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
337103985Sphk.endif
338201815Sbz	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
339201815Sbz	    universe_kernels
340205290Sdougb.endif
341201815Sbz	@echo ">> ${target} completed on `LC_ALL=C date`"
342201815Sbz.endfor
343201815Sbzuniverse_kernels: universe_kernconfs
344202095Sbz.if !defined(TARGET)
345202095SbzTARGET!=	uname -m
346202095Sbz.endif
347201815SbzKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
348201815Sbz		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
349201815Sbz		! -name DEFAULTS ! -name NOTES
350201815Sbzuniverse_kernconfs:
351148154Sru.for kernel in ${KERNCONFS}
352216520SnwhitehornTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
353216520Snwhitehorn			config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} | \
354216520Snwhitehorn			cut -f 2
355216520Snwhitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
356216520Snwhitehornuniverse_kernconf_${TARGET}_${kernel}:
357185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
358185250Sdes	    ${MAKE} ${JFLAG} buildkernel \
359201815Sbz	    TARGET=${TARGET} \
360216520Snwhitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
361148154Sru	    KERNCONF=${kernel} \
362201815Sbz	    > _.${TARGET}.${kernel} 2>&1 || \
363201815Sbz	    (echo "${TARGET} ${kernel} kernel failed," \
364201815Sbz	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
365148154Sru.endfor
366133945Sruuniverse: universe_epilogue
367133945Sruuniverse_epilogue:
368103985Sphk	@echo "--------------------------------------------------------------"
369118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
370118531Sru	@echo "                      (started ${STARTTIME})"
371103985Sphk	@echo "--------------------------------------------------------------"
372185499Salfred.if defined(DOING_TINDERBOX)
373185499Salfred	@if [ -e ${FAILFILE} ] ; then \
374185499Salfred		echo "Tinderbox failed:" ;\
375185499Salfred		cat ${FAILFILE} ;\
376185499Salfred		exit 1 ;\
377185499Salfred	fi
378133945Sru.endif
379185499Salfred.endif
380