Makefile revision 217294
1178825Sdfr#
2233294Sstas# $FreeBSD: head/Makefile 217294 2011-01-11 22:57:41Z imp $
3233294Sstas#
4233294Sstas# The user-driven targets are:
5178825Sdfr#
6233294Sstas# universe            - *Really* build *everything* (buildworld and
7233294Sstas#                       all kernels on all architectures).
8233294Sstas# tinderbox           - Same as universe, but stop on first failure.
9178825Sdfr# buildworld          - Rebuild *everything*, including glue to help do
10233294Sstas#                       upgrades.
11233294Sstas# installworld        - Install everything built by "buildworld".
12178825Sdfr# world               - buildworld + installworld, no kernel.
13233294Sstas# buildkernel         - Rebuild the kernel and the kernel-modules.
14233294Sstas# installkernel       - Install the kernel and the kernel-modules.
15233294Sstas# installkernel.debug
16178825Sdfr# reinstallkernel     - Reinstall the kernel and the kernel-modules.
17233294Sstas# reinstallkernel.debug
18233294Sstas# kernel              - buildkernel + installkernel.
19233294Sstas# kernel-toolchain    - Builds the subset of world necessary to build a kernel
20178825Sdfr# doxygen             - Build API documentation of the kernel, needs doxygen.
21233294Sstas# update              - Convenient way to update your source tree (cvs).
22233294Sstas# check-old           - List obsolete directories/files/libraries.
23233294Sstas# check-old-dirs      - List obsolete directories.
24233294Sstas# check-old-files     - List obsolete files.
25233294Sstas# check-old-libs      - List obsolete libraries.
26233294Sstas# delete-old          - Delete obsolete directories/files/libraries.
27233294Sstas# delete-old-dirs     - Delete obsolete directories.
28233294Sstas# delete-old-files    - Delete obsolete files.
29233294Sstas# delete-old-libs     - Delete obsolete libraries.
30233294Sstas# targets             - Print a list of supported TARGET/TARGET_ARCH pairs.
31233294Sstas#
32178825Sdfr# This makefile is simple by design. The FreeBSD make automatically reads
33178825Sdfr# the /usr/share/mk/sys.mk unless the -m argument is specified on the
34178825Sdfr# command line. By keeping this makefile simple, it doesn't matter too
35178825Sdfr# much how different the installed mk files are from those in the source
36178825Sdfr# tree. This makefile executes a child make process, forcing it to use
37233294Sstas# the mk files from the source tree which are supposed to DTRT.
38233294Sstas#
39178825Sdfr# Most of the user-driven targets (as listed above) are implemented in
40178825Sdfr# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
41178825Sdfr#
42178825Sdfr# If you want to build your system from source be sure that /usr/obj has
43178825Sdfr# at least 800MB of diskspace available.
44178825Sdfr#
45178825Sdfr# For individuals wanting to build from the sources currently on their
46178825Sdfr# system, the simple instructions are:
47178825Sdfr#
48178825Sdfr# 1.  `cd /usr/src'  (or to the directory containing your source tree).
49233294Sstas# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
50178825Sdfr# 3.  `make world'
51178825Sdfr#
52178825Sdfr# For individuals wanting to upgrade their sources (even if only a
53178825Sdfr# delta of a few days):
54178825Sdfr#
55178825Sdfr#  1.  `cd /usr/src'       (or to the directory containing your source tree).
56178825Sdfr#  2.  `make buildworld'
57233294Sstas#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
58178825Sdfr#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
59178825Sdfr#       [steps 3. & 4. can be combined by using the "kernel" target]
60178825Sdfr#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
61178825Sdfr#  6.  `mergemaster -p'
62178825Sdfr#  7.  `make installworld'
63178825Sdfr#  8.  `make delete-old'
64178825Sdfr#  9.  `mergemaster'                         (you may wish to use -U or -ai).
65233294Sstas# 10.  `reboot'
66178825Sdfr# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
67178825Sdfr#
68178825Sdfr# See src/UPDATING `COMMON ITEMS' for more complete information.
69178825Sdfr#
70178825Sdfr# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
71178825Sdfr# cross build world for other machine types using the buildworld target,
72178825Sdfr# and once the world is built you can cross build a kernel using the
73178825Sdfr# buildkernel target.
74178825Sdfr#
75178825Sdfr# Define the user-driven targets. These are listed here in alphabetical
76178825Sdfr# order, but that's not important.
77178825Sdfr#
78178825Sdfr# Targets that begin with underscore are internal targets intended for
79233294Sstas# developer convenience only.  They are intentionally not documented and
80178825Sdfr# completely subject to change without notice.
81178825Sdfr#
82178825Sdfr# For more information, see the build(7) manual page.
83178825Sdfr#
84178825SdfrTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
85178825Sdfr	check-old check-old-dirs check-old-files check-old-libs \
86233294Sstas	checkdpadd clean cleandepend cleandir \
87233294Sstas	delete-old delete-old-dirs delete-old-files delete-old-libs \
88178825Sdfr	depend distribute distributeworld distrib-dirs distribution doxygen \
89178825Sdfr	everything hierarchy install installcheck installkernel \
90178825Sdfr	installkernel.debug reinstallkernel reinstallkernel.debug \
91178825Sdfr	installworld kernel-toolchain libraries lint maninstall \
92178825Sdfr	obj objlink regress rerelease showconfig tags toolchain update \
93178825Sdfr	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
94178825Sdfr	_build-tools _cross-tools _includes _libraries _depend \
95178825Sdfr	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
96178825Sdfr
97178825SdfrTGTS+=	${SUBDIR_TARGETS}
98178825Sdfr
99233294SstasBITGTS=	files includes
100178825SdfrBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
101178825SdfrTGTS+=	${BITGTS}
102233294Sstas
103178825Sdfr.ORDER: buildworld installworld
104178825Sdfr.ORDER: buildworld distributeworld
105178825Sdfr.ORDER: buildworld buildkernel
106178825Sdfr.ORDER: buildkernel installkernel
107178825Sdfr.ORDER: buildkernel installkernel.debug
108178825Sdfr.ORDER: buildkernel reinstallkernel
109233294Sstas.ORDER: buildkernel reinstallkernel.debug
110178825Sdfr
111178825SdfrPATH=	/sbin:/bin:/usr/sbin:/usr/bin
112178825SdfrMAKEOBJDIRPREFIX?=	/usr/obj
113233294Sstas_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
114178825Sdfr    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
115178825Sdfr    -f /dev/null -V MAKEOBJDIRPREFIX dummy
116178825Sdfr.if !empty(_MAKEOBJDIRPREFIX)
117178825Sdfr.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
118178825Sdfr	(in make.conf(5)) or command-line variable.
119233294Sstas.endif
120178825SdfrMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
121178825SdfrBINMAKE= \
122178825Sdfr	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
123178825Sdfr	-m ${.CURDIR}/share/mk
124233294Sstas_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
125178825Sdfr
126178825Sdfr#
127178825Sdfr# Make sure we have an up-to-date make(1). Only world and buildworld
128178825Sdfr# should do this as those are the initial targets used for upgrades.
129178825Sdfr# The user can define ALWAYS_CHECK_MAKE to have this check performed
130233294Sstas# for all targets.
131178825Sdfr#
132178825Sdfr.if defined(ALWAYS_CHECK_MAKE)
133178825Sdfr${TGTS}: upgrade_checks
134178825Sdfr.else
135178825Sdfrbuildworld: upgrade_checks
136233294Sstas.endif
137178825Sdfr
138178825Sdfr#
139178825Sdfr# This 'cleanworld' target is not included in TGTS, because it is not a
140178825Sdfr# recursive target.  All of the work for it is done right here.   It is
141233294Sstas# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
142178825Sdfr# created by bsd.obj.mk, except that we don't want to .include that file
143178825Sdfr# in this makefile.  
144178825Sdfr#
145178825Sdfr# In the following, the first 'rm' in a series will usually remove all
146233294Sstas# files and directories.  If it does not, then there are probably some
147178825Sdfr# files with chflags set, so this unsets them and tries the 'rm' a
148178825Sdfr# second time.  There are situations where this target will be cleaning
149178825Sdfr# some directories via more than one method, but that duplication is
150178825Sdfr# needed to correctly handle all the possible situations.
151178825Sdfr#
152178825SdfrBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
153178825Sdfrcleanworld:
154233294Sstas.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
155178825Sdfr.if exists(${BW_CANONICALOBJDIR}/)
156178825Sdfr	-rm -rf ${BW_CANONICALOBJDIR}/*
157178825Sdfr	-chflags -R 0 ${BW_CANONICALOBJDIR}
158178825Sdfr	rm -rf ${BW_CANONICALOBJDIR}/*
159178825Sdfr.endif
160178825Sdfr	#   To be safe in this case, fall back to a 'make cleandir'
161233294Sstas	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
162178825Sdfr.else
163178825Sdfr	-rm -rf ${.OBJDIR}/*
164178825Sdfr	-chflags -R 0 ${.OBJDIR}
165178825Sdfr	rm -rf ${.OBJDIR}/*
166178825Sdfr.endif
167233294Sstas
168178825Sdfr#
169178825Sdfr# Handle the user-driven targets, using the source relative mk files.
170178825Sdfr#
171178825Sdfr
172233294Sstas${TGTS}:
173178825Sdfr	${_+_}@cd ${.CURDIR}; \
174178825Sdfr		${_MAKE} ${.TARGET}
175178825Sdfr
176178825Sdfr# Set a reasonable default
177178825Sdfr.MAIN:	all
178233294Sstas
179178825SdfrSTARTTIME!= LC_ALL=C date
180178825SdfrCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
181178825Sdfr.if !empty(CHECK_TIME)
182178825Sdfr.error check your date/time: ${STARTTIME}
183178825Sdfr.endif
184178825Sdfr
185233294Sstas.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
186178825Sdfr#
187178825Sdfr# world
188178825Sdfr#
189178825Sdfr# Attempt to rebuild and reinstall everything. This target is not to be
190178825Sdfr# used for upgrading an existing FreeBSD system, because the kernel is
191233294Sstas# not included. One can argue that this target doesn't build everything
192178825Sdfr# then.
193178825Sdfr#
194178825Sdfrworld: upgrade_checks
195178825Sdfr	@echo "--------------------------------------------------------------"
196233294Sstas	@echo ">>> make world started on ${STARTTIME}"
197178825Sdfr	@echo "--------------------------------------------------------------"
198178825Sdfr.if target(pre-world)
199178825Sdfr	@echo
200178825Sdfr	@echo "--------------------------------------------------------------"
201178825Sdfr	@echo ">>> Making 'pre-world' target"
202233294Sstas	@echo "--------------------------------------------------------------"
203178825Sdfr	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
204178825Sdfr.endif
205178825Sdfr	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
206178825Sdfr	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
207178825Sdfr.if target(post-world)
208178825Sdfr	@echo
209178825Sdfr	@echo "--------------------------------------------------------------"
210178825Sdfr	@echo ">>> Making 'post-world' target"
211233294Sstas	@echo "--------------------------------------------------------------"
212178825Sdfr	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
213178825Sdfr.endif
214178825Sdfr	@echo
215178825Sdfr	@echo "--------------------------------------------------------------"
216178825Sdfr	@echo ">>> make world completed on `LC_ALL=C date`"
217233294Sstas	@echo "                   (started ${STARTTIME})"
218178825Sdfr	@echo "--------------------------------------------------------------"
219178825Sdfr.else
220178825Sdfrworld:
221178825Sdfr	@echo "WARNING: make world will overwrite your existing FreeBSD"
222233294Sstas	@echo "installation without also building and installing a new"
223178825Sdfr	@echo "kernel.  This can be dangerous.  Please read the handbook,"
224178825Sdfr	@echo "'Rebuilding world', for how to upgrade your system."
225178825Sdfr	@echo "Define DESTDIR to where you want to install FreeBSD,"
226178825Sdfr	@echo "including /, to override this warning and proceed as usual."
227233294Sstas	@echo ""
228178825Sdfr	@echo "Bailing out now..."
229178825Sdfr	@false
230178825Sdfr.endif
231178825Sdfr
232178825Sdfr#
233178825Sdfr# kernel
234178825Sdfr#
235178825Sdfr# Short hand for `make buildkernel installkernel'
236178825Sdfr#
237178825Sdfrkernel: buildkernel installkernel
238178825Sdfr
239178825Sdfr#
240178825Sdfr# Perform a few tests to determine if the installed tools are adequate
241178825Sdfr# for building the world.
242178825Sdfr#
243178825Sdfrupgrade_checks:
244178825Sdfr	@if ! (cd ${.CURDIR}/tools/build/make_check && \
245178825Sdfr	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
246178825Sdfr	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
247233294Sstas	then \
248178825Sdfr	    (cd ${.CURDIR} && ${MAKE} make); \
249178825Sdfr	fi
250178825Sdfr
251178825Sdfr#
252178825Sdfr# Upgrade make(1) to the current version using the installed
253178825Sdfr# headers, libraries and tools.  Also, allow the location of
254178825Sdfr# the system bsdmake-like utility to be overridden.
255178825Sdfr#
256178825SdfrMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
257178825Sdfr		DESTDIR= \
258178825Sdfr		INSTALL="sh ${.CURDIR}/tools/install.sh"
259178825SdfrMMAKE=		${MMAKEENV} ${MAKE} \
260178825Sdfr		-D_UPGRADING \
261178825Sdfr		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
262178825Sdfr		-DNO_CPU_CFLAGS -DNO_WERROR
263178825Sdfr
264178825Sdfrmake: .PHONY
265178825Sdfr	@echo
266178825Sdfr	@echo "--------------------------------------------------------------"
267178825Sdfr	@echo ">>> Building an up-to-date make(1)"
268178825Sdfr	@echo "--------------------------------------------------------------"
269178825Sdfr	${_+_}@cd ${.CURDIR}/usr.bin/make; \
270178825Sdfr		${MMAKE} obj && \
271178825Sdfr		${MMAKE} depend && \
272178825Sdfr		${MMAKE} all && \
273178825Sdfr		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
274178825Sdfr
275178825Sdfrtinderbox:
276178825Sdfr	cd ${.CURDIR} && \
277233294Sstas		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
278178825Sdfr
279178825Sdfr#
280178825Sdfr# universe
281178825Sdfr#
282178825Sdfr# Attempt to rebuild *everything* for all supported architectures,
283178825Sdfr# with a reasonable chance of success, regardless of how old your
284178825Sdfr# existing system is.
285233294Sstas#
286233294Sstas.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
287178825SdfrTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
288178825SdfrTARGET_ARCHES_arm?=	arm armeb
289178825SdfrTARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb
290178825SdfrTARGET_ARCHES_powerpc?=	powerpc powerpc64
291178825SdfrTARGET_ARCHES_pc98?=	i386
292233294SstasTARGET_ARCHES_sun4v?=	sparc64
293178825Sdfr.for target in ${TARGETS}
294178825SdfrTARGET_ARCHES_${target}?= ${target}
295178825Sdfr.endfor
296178825Sdfr
297178825Sdfrtargets:
298178825Sdfr	@echo "Supported TARGET/TARGET_ARCH pairs"
299178825Sdfr.for target in ${TARGETS}
300178825Sdfr.for target_arch in ${TARGET_ARCHES_${target}}
301178825Sdfr	@echo "    ${target}/${target_arch}"
302178825Sdfr.endfor
303178825Sdfr.endfor
304178825Sdfr
305178825Sdfr.if defined(DOING_TINDERBOX)
306233294SstasFAILFILE=tinderbox.failed
307233294SstasMAKEFAIL=tee -a ${FAILFILE}
308178825Sdfr.else
309178825SdfrMAKEFAIL=cat
310178825Sdfr.endif
311178825Sdfr
312178825Sdfruniverse: universe_prologue
313178825Sdfruniverse_prologue:
314178825Sdfr	@echo "--------------------------------------------------------------"
315178825Sdfr	@echo ">>> make universe started on ${STARTTIME}"
316178825Sdfr	@echo "--------------------------------------------------------------"
317178825Sdfr.if defined(DOING_TINDERBOX)
318233294Sstas	rm -f ${FAILFILE}
319178825Sdfr.endif
320178825Sdfr.for target in ${TARGETS}
321178825Sdfruniverse: universe_${target}
322178825Sdfr.ORDER: universe_prologue universe_${target} universe_epilogue
323178825Sdfruniverse_${target}: universe_${target}_prologue
324178825Sdfruniverse_${target}_prologue:
325178825Sdfr	@echo ">> ${target} started on `LC_ALL=C date`"
326178825Sdfr.if !defined(MAKE_JUST_KERNELS)
327178825Sdfr.for target_arch in ${TARGET_ARCHES_${target}}
328233294Sstasuniverse_${target}: universe_${target}_${target_arch}
329233294Sstasuniverse_${target}_${target_arch}: universe_${target}_prologue
330178825Sdfr	@echo ">> ${target}.${target_arch} buildworld started on `LC_ALL=C date`"
331178825Sdfr	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
332178825Sdfr	    ${MAKE} ${JFLAG} buildworld \
333178825Sdfr	    TARGET=${target} \
334178825Sdfr	    TARGET_ARCH=${target_arch} \
335178825Sdfr	    > _.${target}.${target_arch}.buildworld 2>&1 || \
336178825Sdfr	    (echo "${target}.${target_arch} world failed," \
337178825Sdfr	    "check _.${target}.${target_arch}.buildworld for details" | \
338178825Sdfr	    ${MAKEFAIL}))
339178825Sdfr	@echo ">> ${target}.${target_arch} buildworld completed on `LC_ALL=C date`"
340178825Sdfr.endfor
341233294Sstas.endif
342233294Sstas.if !defined(MAKE_JUST_WORLDS)
343178825Sdfr.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
344178825Sdfr	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
345178825Sdfr	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
346178825Sdfr	    (echo "${target} 'make LINT' failed," \
347178825Sdfr	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
348178825Sdfr.endif
349178825Sdfr	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
350178825Sdfr	    universe_kernels
351178825Sdfr.endif
352178825Sdfr	@echo ">> ${target} completed on `LC_ALL=C date`"
353178825Sdfr.endfor
354178825Sdfruniverse_kernels: universe_kernconfs
355178825Sdfr.if !defined(TARGET)
356178825SdfrTARGET!=	uname -m
357178825Sdfr.endif
358178825SdfrKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
359178825Sdfr		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
360178825Sdfr		! -name DEFAULTS ! -name NOTES
361178825Sdfruniverse_kernconfs:
362178825Sdfr.for kernel in ${KERNCONFS}
363233294SstasTARGET_ARCH_${kernel}!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
364233294Sstas	config -m ${.CURDIR}/sys/${TARGET}/conf/${kernel} 2> /dev/null | \
365178825Sdfr	grep -v WARNING: | cut -f 2
366178825Sdfr.if empty(TARGET_ARCH_${kernel})
367178825Sdfr.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
368178825Sdfr.endif
369178825Sdfruniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
370178825Sdfruniverse_kernconf_${TARGET}_${kernel}:
371178825Sdfr	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
372178825Sdfr	    ${MAKE} ${JFLAG} buildkernel \
373178825Sdfr	    TARGET=${TARGET} \
374178825Sdfr	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
375178825Sdfr	    KERNCONF=${kernel} \
376178825Sdfr	    > _.${TARGET}.${kernel} 2>&1 || \
377178825Sdfr	    (echo "${TARGET} ${kernel} kernel failed," \
378178825Sdfr	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
379178825Sdfr.endfor
380233294Sstasuniverse: universe_epilogue
381178825Sdfruniverse_epilogue:
382178825Sdfr	@echo "--------------------------------------------------------------"
383233294Sstas	@echo ">>> make universe completed on `LC_ALL=C date`"
384233294Sstas	@echo "                      (started ${STARTTIME})"
385178825Sdfr	@echo "--------------------------------------------------------------"
386178825Sdfr.if defined(DOING_TINDERBOX)
387178825Sdfr	@if [ -e ${FAILFILE} ] ; then \
388233294Sstas		echo "Tinderbox failed:" ;\
389178825Sdfr		cat ${FAILFILE} ;\
390178825Sdfr		exit 1 ;\
391178825Sdfr	fi
392178825Sdfr.endif
393178825Sdfr.endif
394178825Sdfr