Makefile revision 217125
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 217125 2011-01-07 20:36:27Z imp $
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.
29217125Simp# targets             - Print a list of supported TARGET/TARGET_ARCH pairs.
3032427Sjb#
3138666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
32108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3338666Sjb# command line. By keeping this makefile simple, it doesn't matter too
3438666Sjb# much how different the installed mk files are from those in the source
3538666Sjb# tree. This makefile executes a child make process, forcing it to use
3638666Sjb# the mk files from the source tree which are supposed to DTRT.
3717308Speter#
3891606Skeramida# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3919175Sbde#
4096205Sjwd# If you want to build your system from source be sure that /usr/obj has
41177794Spav# at least 800MB of diskspace available.
4238042Sbde#
4396205Sjwd# For individuals wanting to build from the sources currently on their
4496205Sjwd# system, the simple instructions are:
4538042Sbde#
4696205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
47159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
48159363Strhodes# 3.  `make world'
4917308Speter#
5096205Sjwd# For individuals wanting to upgrade their sources (even if only a
5196205Sjwd# delta of a few days):
5217308Speter#
53148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
54148330Snetchild#  2.  `make buildworld'
55148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
56148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
57159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
58148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
59148330Snetchild#  6.  `mergemaster -p'
60148330Snetchild#  7.  `make installworld'
61148330Snetchild#  8.  `make delete-old'
62178653Srwatson#  9.  `mergemaster'                         (you may wish to use -U or -ai).
63148330Snetchild# 10.  `reboot'
64148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6596205Sjwd#
6696205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
6796205Sjwd#
68162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
69162147Sru# cross build world for other machine types using the buildworld target,
7098723Sdillon# and once the world is built you can cross build a kernel using the
7198723Sdillon# buildkernel target.
7298723Sdillon#
7338666Sjb# Define the user-driven targets. These are listed here in alphabetical
7438666Sjb# order, but that's not important.
7517308Speter#
76123311Speter# Targets that begin with underscore are internal targets intended for
77123311Speter# developer convenience only.  They are intentionally not documented and
78123311Speter# completely subject to change without notice.
79123311Speter#
80175833Sjhb# For more information, see the build(7) manual page.
81175833Sjhb#
82169597SdesTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
83169597Sdes	check-old check-old-dirs check-old-files check-old-libs \
84169597Sdes	checkdpadd clean cleandepend cleandir \
85169597Sdes	delete-old delete-old-dirs delete-old-files delete-old-libs \
86159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
87158962Snetchild	everything hierarchy install installcheck installkernel \
88158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
89158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
90156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
91123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
92137288Speter	_build-tools _cross-tools _includes _libraries _depend \
93209128Sraj	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
94209128Sraj
95156740SruTGTS+=	${SUBDIR_TARGETS}
962061Sjkh
9797769SruBITGTS=	files includes
9897252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
99119579SruTGTS+=	${BITGTS}
10097252Sru
10195730Sru.ORDER: buildworld installworld
10295793Sru.ORDER: buildworld distributeworld
103111617Sru.ORDER: buildworld buildkernel
10495730Sru.ORDER: buildkernel installkernel
105116679Ssimokawa.ORDER: buildkernel installkernel.debug
10695730Sru.ORDER: buildkernel reinstallkernel
107116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
10895730Sru
109110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
110107516SruMAKEOBJDIRPREFIX?=	/usr/obj
111138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
112156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
113138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
114133942Sru.if !empty(_MAKEOBJDIRPREFIX)
115133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
116156145Syar	(in make.conf(5)) or command-line variable.
117133942Sru.endif
118110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
119117234SruBINMAKE= \
120110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
121117229Sru	-m ${.CURDIR}/share/mk
122117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12354324Smarcel
12417308Speter#
125119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
126119519Smarcel# should do this as those are the initial targets used for upgrades.
127119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
128119519Smarcel# for all targets.
129119519Smarcel#
130119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
131119579Sru${TGTS}: upgrade_checks
132119519Smarcel.else
133119519Smarcelbuildworld: upgrade_checks
134119519Smarcel.endif
135119519Smarcel
136119519Smarcel#
137126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
138126024Sgad# recursive target.  All of the work for it is done right here.   It is
139126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
140126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
141126024Sgad# in this makefile.  
142126024Sgad#
143126024Sgad# In the following, the first 'rm' in a series will usually remove all
144126024Sgad# files and directories.  If it does not, then there are probably some
145126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
146126024Sgad# second time.  There are situations where this target will be cleaning
147126024Sgad# some directories via more than one method, but that duplication is
148126024Sgad# needed to correctly handle all the possible situations.
149126024Sgad#
150126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
151126031Sgadcleanworld:
152126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
153126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
154126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
155172744Sdelphij	-chflags -R 0 ${BW_CANONICALOBJDIR}
156126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
157126024Sgad.endif
158126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
159133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
160126024Sgad.else
161126024Sgad	-rm -rf ${.OBJDIR}/*
162172744Sdelphij	-chflags -R 0 ${.OBJDIR}
163126024Sgad	rm -rf ${.OBJDIR}/*
164126024Sgad.endif
165125885Sgad
166125885Sgad#
16738666Sjb# Handle the user-driven targets, using the source relative mk files.
16817308Speter#
169119519Smarcel
170119579Sru${TGTS}:
171133376Sharti	${_+_}@cd ${.CURDIR}; \
172110035Sru		${_MAKE} ${.TARGET}
1732302Spaul
17439206Sjkh# Set a reasonable default
17539206Sjkh.MAIN:	all
17639206Sjkh
177133945SruSTARTTIME!= LC_ALL=C date
178177609SruCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
179177609Sru.if !empty(CHECK_TIME)
180177609Sru.error check your date/time: ${STARTTIME}
181177609Sru.endif
182133945Sru
183132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
18417308Speter#
18554324Smarcel# world
18654324Smarcel#
187132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
188132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
189132234Smarcel# not included. One can argue that this target doesn't build everything
190132234Smarcel# then.
19154324Smarcel#
19254324Smarcelworld: upgrade_checks
19354324Smarcel	@echo "--------------------------------------------------------------"
194118531Sru	@echo ">>> make world started on ${STARTTIME}"
19554324Smarcel	@echo "--------------------------------------------------------------"
19654324Smarcel.if target(pre-world)
19754324Smarcel	@echo
19854324Smarcel	@echo "--------------------------------------------------------------"
19954324Smarcel	@echo ">>> Making 'pre-world' target"
20054324Smarcel	@echo "--------------------------------------------------------------"
201133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
20254324Smarcel.endif
203133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
204133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
20554324Smarcel.if target(post-world)
20654324Smarcel	@echo
20754324Smarcel	@echo "--------------------------------------------------------------"
20854324Smarcel	@echo ">>> Making 'post-world' target"
20954324Smarcel	@echo "--------------------------------------------------------------"
210133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
21154324Smarcel.endif
21254324Smarcel	@echo
21354324Smarcel	@echo "--------------------------------------------------------------"
214118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
215118531Sru	@echo "                   (started ${STARTTIME})"
21654324Smarcel	@echo "--------------------------------------------------------------"
217132234Smarcel.else
218132234Smarcelworld:
219132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
220132234Smarcel	@echo "installation without also building and installing a new"
221132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
222132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
223132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
224132234Smarcel	@echo "including /, to override this warning and proceed as usual."
225132358Smarkm	@echo ""
226132234Smarcel	@echo "Bailing out now..."
227132234Smarcel	@false
228132234Smarcel.endif
22954324Smarcel
23054324Smarcel#
23195730Sru# kernel
23295730Sru#
23395730Sru# Short hand for `make buildkernel installkernel'
23495730Sru#
23595730Srukernel: buildkernel installkernel
23695730Sru
23795730Sru#
23838666Sjb# Perform a few tests to determine if the installed tools are adequate
239107374Sru# for building the world.
24017308Speter#
24155678Smarcelupgrade_checks:
242143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
243138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
244117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
245110035Sru	then \
246174564Simp	    (cd ${.CURDIR} && ${MAKE} make); \
247110035Sru	fi
2482061Sjkh
24917308Speter#
250107516Sru# Upgrade make(1) to the current version using the installed
251174539Simp# headers, libraries and tools.  Also, allow the location of
252174539Simp# the system bsdmake-like utility to be overridden.
25355678Smarcel#
254107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
255107516Sru		DESTDIR= \
256107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
257174564SimpMMAKE=		${MMAKEENV} ${MAKE} \
258107516Sru		-D_UPGRADING \
259139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
260164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
261107516Sru
262122204Skrismake: .PHONY
26355678Smarcel	@echo
26455678Smarcel	@echo "--------------------------------------------------------------"
265116696Sru	@echo ">>> Building an up-to-date make(1)"
26655678Smarcel	@echo "--------------------------------------------------------------"
267133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
268107516Sru		${MMAKE} obj && \
269107516Sru		${MMAKE} depend && \
270107516Sru		${MMAKE} all && \
271107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
27255678Smarcel
273185499Salfredtinderbox:
274185499Salfred	cd ${.CURDIR} && \
275216487Sjhb		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
276185499Salfred
27755678Smarcel#
278111131Sru# universe
279111131Sru#
280111131Sru# Attempt to rebuild *everything* for all supported architectures,
281133945Sru# with a reasonable chance of success, regardless of how old your
282111131Sru# existing system is.
283111131Sru#
284217125Simp.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
285216520SnwhitehornTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
286216520SnwhitehornTARGET_ARCHES_arm?=	arm armeb
287217123SimpTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
288216520SnwhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
289216520SnwhitehornTARGET_ARCHES_pc98?=	i386
290216520SnwhitehornTARGET_ARCHES_sun4v?=	sparc64
291216520Snwhitehorn.for target in ${TARGETS}
292216520SnwhitehornTARGET_ARCHES_${target}?= ${target}
293216520Snwhitehorn.endfor
294168280Smarcel
295217125Simptargets:
296217125Simp	@echo "Supported TARGET/TARGET_ARCH pairs"
297217125Simp.for target in ${TARGETS}
298217125Simp.for target_arch in ${TARGET_ARCHES_${target}}
299217125Simp	@echo "    ${target}/${target_arch}"
300217125Simp.endfor
301217125Simp.endfor
302217125Simp
303185499Salfred.if defined(DOING_TINDERBOX)
304185499SalfredFAILFILE=tinderbox.failed
305185499SalfredMAKEFAIL=tee -a ${FAILFILE}
306185499Salfred.else
307185499SalfredMAKEFAIL=cat
308185499Salfred.endif
309185499Salfred
310133945Sruuniverse: universe_prologue
311133945Sruuniverse_prologue:
312103985Sphk	@echo "--------------------------------------------------------------"
313103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
314103985Sphk	@echo "--------------------------------------------------------------"
315185499Salfred.if defined(DOING_TINDERBOX)
316185499Salfred	rm -f ${FAILFILE}
317185499Salfred.endif
318168280Smarcel.for target in ${TARGETS}
319162147Sruuniverse: universe_${target}
320162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
321216520Snwhitehornuniverse_${target}: universe_${target}_prologue
322216520Snwhitehornuniverse_${target}_prologue:
323216520Snwhitehorn	@echo ">> ${target} started on `LC_ALL=C date`"
324179232Sjb.if !defined(MAKE_JUST_KERNELS)
325216520Snwhitehorn.for target_arch in ${TARGET_ARCHES_${target}}
326216520Snwhitehornuniverse_${target}: universe_${target}_${target_arch}
327216520Snwhitehornuniverse_${target}_${target_arch}: universe_${target}_prologue
328216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
329185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
330202629Sed	    ${MAKE} ${JFLAG} buildworld \
331162147Sru	    TARGET=${target} \
332216520Snwhitehorn	    TARGET_ARCH=${target_arch} \
333216520Snwhitehorn	    > _.${target}.${target_arch}.buildworld 2>&1 || \
334216520Snwhitehorn	    (echo "${target}.${target_arch} world failed," \
335216520Snwhitehorn	    "check _.${target}.${target_arch}.buildworld for details" | \
336216520Snwhitehorn	    ${MAKEFAIL}))
337216520Snwhitehorn	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
338216520Snwhitehorn.endfor
339179232Sjb.endif
340205290Sdougb.if !defined(MAKE_JUST_WORLDS)
341162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
342185250Sdes	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
343185250Sdes	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
344185499Salfred	    (echo "${target} 'make LINT' failed," \
345185499Salfred	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
346103985Sphk.endif
347201815Sbz	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
348201815Sbz	    universe_kernels
349205290Sdougb.endif
350201815Sbz	@echo ">> ${target} completed on `LC_ALL=C date`"
351201815Sbz.endfor
352201815Sbzuniverse_kernels: universe_kernconfs
353202095Sbz.if !defined(TARGET)
354202095SbzTARGET!=	uname -m
355202095Sbz.endif
356201815SbzKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
357201815Sbz		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
358201815Sbz		! -name DEFAULTS ! -name NOTES
359201815Sbzuniverse_kernconfs:
360148154Sru.for kernel in ${KERNCONFS}
361216520SnwhitehornTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
362216685Simp	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
363216934Simp	grep -v WARNING: | cut -f 2
364216934Simp.if empty(TARGET_ARCH_${kernel})
365216934Simp.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
366216934Simp.endif
367216520Snwhitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
368216520Snwhitehornuniverse_kernconf_${TARGET}_${kernel}:
369185250Sdes	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
370185250Sdes	    ${MAKE} ${JFLAG} buildkernel \
371201815Sbz	    TARGET=${TARGET} \
372216520Snwhitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
373148154Sru	    KERNCONF=${kernel} \
374201815Sbz	    > _.${TARGET}.${kernel} 2>&1 || \
375201815Sbz	    (echo "${TARGET} ${kernel} kernel failed," \
376201815Sbz	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
377148154Sru.endfor
378133945Sruuniverse: universe_epilogue
379133945Sruuniverse_epilogue:
380103985Sphk	@echo "--------------------------------------------------------------"
381118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
382118531Sru	@echo "                      (started ${STARTTIME})"
383103985Sphk	@echo "--------------------------------------------------------------"
384185499Salfred.if defined(DOING_TINDERBOX)
385185499Salfred	@if [ -e ${FAILFILE} ] ; then \
386185499Salfred		echo "Tinderbox failed:" ;\
387185499Salfred		cat ${FAILFILE} ;\
388185499Salfred		exit 1 ;\
389185499Salfred	fi
390133945Sru.endif
391185499Salfred.endif
392