Makefile revision 232907
1#
2# $FreeBSD: head/Makefile 232907 2012-03-13 00:38:49Z jmallett $
3#
4# The user-driven targets are:
5#
6# universe            - *Really* build *everything* (buildworld and
7#                       all kernels on all architectures).
8# tinderbox           - Same as universe, but presents a list of failed build
9#                       targets and exits with an error if there were any.
10# buildworld          - Rebuild *everything*, including glue to help do
11#                       upgrades.
12# installworld        - Install everything built by "buildworld".
13# world               - buildworld + installworld, no kernel.
14# buildkernel         - Rebuild the kernel and the kernel-modules.
15# installkernel       - Install the kernel and the kernel-modules.
16# installkernel.debug
17# reinstallkernel     - Reinstall the kernel and the kernel-modules.
18# reinstallkernel.debug
19# kernel              - buildkernel + installkernel.
20# kernel-toolchain    - Builds the subset of world necessary to build a kernel
21# kernel-toolchains   - Build kernel-toolchain for all universe targets.
22# doxygen             - Build API documentation of the kernel, needs doxygen.
23# update              - Convenient way to update your source tree(s).
24# check-old           - List obsolete directories/files/libraries.
25# check-old-dirs      - List obsolete directories.
26# check-old-files     - List obsolete files.
27# check-old-libs      - List obsolete libraries.
28# delete-old          - Delete obsolete directories/files.
29# delete-old-dirs     - Delete obsolete directories.
30# delete-old-files    - Delete obsolete files.
31# delete-old-libs     - Delete obsolete libraries.
32# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
33#                       for world and kernel targets.
34# toolchains          - Build a toolchain for all world and kernel targets.
35#
36# This makefile is simple by design. The FreeBSD make automatically reads
37# the /usr/share/mk/sys.mk unless the -m argument is specified on the
38# command line. By keeping this makefile simple, it doesn't matter too
39# much how different the installed mk files are from those in the source
40# tree. This makefile executes a child make process, forcing it to use
41# the mk files from the source tree which are supposed to DTRT.
42#
43# Most of the user-driven targets (as listed above) are implemented in
44# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
45#
46# If you want to build your system from source be sure that /usr/obj has
47# at least 1GB of diskspace available.  A complete 'universe' build requires
48# about 15GB of space.
49#
50# For individuals wanting to build from the sources currently on their
51# system, the simple instructions are:
52#
53# 1.  `cd /usr/src'  (or to the directory containing your source tree).
54# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
55# 3.  `make world'
56#
57# For individuals wanting to upgrade their sources (even if only a
58# delta of a few days):
59#
60#  1.  `cd /usr/src'       (or to the directory containing your source tree).
61#  2.  `make buildworld'
62#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
63#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
64#       [steps 3. & 4. can be combined by using the "kernel" target]
65#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
66#  6.  `mergemaster -p'
67#  7.  `make installworld'
68#  8.  `make delete-old'
69#  9.  `mergemaster'		(you may wish to use -i, along with -U or -F).
70# 10.  `reboot'
71# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
72#
73# See src/UPDATING `COMMON ITEMS' for more complete information.
74#
75# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
76# cross build world for other machine types using the buildworld target,
77# and once the world is built you can cross build a kernel using the
78# buildkernel target.
79#
80# Define the user-driven targets. These are listed here in alphabetical
81# order, but that's not important.
82#
83# Targets that begin with underscore are internal targets intended for
84# developer convenience only.  They are intentionally not documented and
85# completely subject to change without notice.
86#
87# For more information, see the build(7) manual page.
88#
89TGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
90	check-old check-old-dirs check-old-files check-old-libs \
91	checkdpadd clean cleandepend cleandir \
92	delete-old delete-old-dirs delete-old-files delete-old-libs \
93	depend distribute distributekernel distributekernel.debug \
94	distributeworld distrib-dirs distribution doxygen \
95	everything hierarchy install installcheck installkernel \
96	installkernel.debug packagekernel packageworld \
97	reinstallkernel reinstallkernel.debug \
98	installworld kernel-toolchain libraries lint maninstall \
99	obj objlink regress rerelease showconfig tags toolchain update \
100	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
101	_build-tools _cross-tools _includes _libraries _depend \
102	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
103
104TGTS+=	${SUBDIR_TARGETS}
105
106BITGTS=	files includes
107BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
108TGTS+=	${BITGTS}
109
110.ORDER: buildworld installworld
111.ORDER: buildworld distributeworld
112.ORDER: buildworld buildkernel
113.ORDER: buildkernel installkernel
114.ORDER: buildkernel installkernel.debug
115.ORDER: buildkernel reinstallkernel
116.ORDER: buildkernel reinstallkernel.debug
117
118PATH=	/sbin:/bin:/usr/sbin:/usr/bin
119MAKEOBJDIRPREFIX?=	/usr/obj
120_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
121    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
122    -f /dev/null -V MAKEOBJDIRPREFIX dummy
123.if !empty(_MAKEOBJDIRPREFIX)
124.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
125	(in make.conf(5)) or command-line variable.
126.endif
127MAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
128BINMAKE= \
129	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
130	-m ${.CURDIR}/share/mk
131_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
132
133# Guess machine architecture from machine type, and vice versa.
134.if !defined(TARGET_ARCH) && defined(TARGET)
135_TARGET_ARCH=	${TARGET:S/pc98/i386/:S/mips/mipsel/}
136.elif !defined(TARGET) && defined(TARGET_ARCH) && \
137    ${TARGET_ARCH} != ${MACHINE_ARCH}
138_TARGET=		${TARGET_ARCH:C/mips.*e[lb]/mips/:C/armeb/arm/}
139.endif
140# Legacy names, for a transition period mips:mips -> mipsel:mips
141.if defined(TARGET) && defined(TARGET_ARCH) && \
142    ${TARGET_ARCH} == "mips" && ${TARGET} == "mips"
143.warning "TARGET_ARCH of mips is deprecated in favor of mipsel or mipseb"
144.if defined(TARGET_BIG_ENDIAN)
145_TARGET_ARCH=mipseb
146.else
147_TARGET_ARCH=mipsel
148.endif
149.endif
150# arm with TARGET_BIG_ENDIAN -> armeb
151.if defined(TARGET_ARCH) && ${TARGET_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
152.warning "TARGET_ARCH of arm with TARGET_BIG_ENDIAN is deprecated.  use armeb"
153_TARGET_ARCH=armeb
154.endif
155.if defined(TARGET) && !defined(_TARGET)
156_TARGET=${TARGET}
157.endif
158.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
159_TARGET_ARCH=${TARGET_ARCH}
160.endif
161# Otherwise, default to current machine type and architecture.
162_TARGET?=	${MACHINE}
163_TARGET_ARCH?=	${MACHINE_ARCH}
164
165#
166# Make sure we have an up-to-date make(1). Only world and buildworld
167# should do this as those are the initial targets used for upgrades.
168# The user can define ALWAYS_CHECK_MAKE to have this check performed
169# for all targets.
170#
171.if defined(ALWAYS_CHECK_MAKE)
172${TGTS}: upgrade_checks
173.else
174buildworld: upgrade_checks
175.endif
176
177#
178# This 'cleanworld' target is not included in TGTS, because it is not a
179# recursive target.  All of the work for it is done right here.   It is
180# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
181# created by bsd.obj.mk, except that we don't want to .include that file
182# in this makefile.  
183#
184# In the following, the first 'rm' in a series will usually remove all
185# files and directories.  If it does not, then there are probably some
186# files with file flags set, so this unsets them and tries the 'rm' a
187# second time.  There are situations where this target will be cleaning
188# some directories via more than one method, but that duplication is
189# needed to correctly handle all the possible situations.  Removing all
190# files without file flags set in the first 'rm' instance saves time,
191# because 'chflags' will need to operate on fewer files afterwards.
192#
193BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
194cleanworld:
195.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
196.if exists(${BW_CANONICALOBJDIR}/)
197	-rm -rf ${BW_CANONICALOBJDIR}/*
198	-chflags -R 0 ${BW_CANONICALOBJDIR}
199	rm -rf ${BW_CANONICALOBJDIR}/*
200.endif
201	#   To be safe in this case, fall back to a 'make cleandir'
202	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
203.else
204	-rm -rf ${.OBJDIR}/*
205	-chflags -R 0 ${.OBJDIR}
206	rm -rf ${.OBJDIR}/*
207.endif
208
209#
210# Handle the user-driven targets, using the source relative mk files.
211#
212
213${TGTS}:
214	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
215
216# Set a reasonable default
217.MAIN:	all
218
219STARTTIME!= LC_ALL=C date
220CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s
221.if !empty(CHECK_TIME)
222.error check your date/time: ${STARTTIME}
223.endif
224
225.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
226#
227# world
228#
229# Attempt to rebuild and reinstall everything. This target is not to be
230# used for upgrading an existing FreeBSD system, because the kernel is
231# not included. One can argue that this target doesn't build everything
232# then.
233#
234world: upgrade_checks
235	@echo "--------------------------------------------------------------"
236	@echo ">>> make world started on ${STARTTIME}"
237	@echo "--------------------------------------------------------------"
238.if target(pre-world)
239	@echo
240	@echo "--------------------------------------------------------------"
241	@echo ">>> Making 'pre-world' target"
242	@echo "--------------------------------------------------------------"
243	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
244.endif
245	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
246	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
247.if target(post-world)
248	@echo
249	@echo "--------------------------------------------------------------"
250	@echo ">>> Making 'post-world' target"
251	@echo "--------------------------------------------------------------"
252	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
253.endif
254	@echo
255	@echo "--------------------------------------------------------------"
256	@echo ">>> make world completed on `LC_ALL=C date`"
257	@echo "                   (started ${STARTTIME})"
258	@echo "--------------------------------------------------------------"
259.else
260world:
261	@echo "WARNING: make world will overwrite your existing FreeBSD"
262	@echo "installation without also building and installing a new"
263	@echo "kernel.  This can be dangerous.  Please read the handbook,"
264	@echo "'Rebuilding world', for how to upgrade your system."
265	@echo "Define DESTDIR to where you want to install FreeBSD,"
266	@echo "including /, to override this warning and proceed as usual."
267	@echo ""
268	@echo "Bailing out now..."
269	@false
270.endif
271
272#
273# kernel
274#
275# Short hand for `make buildkernel installkernel'
276#
277kernel: buildkernel installkernel
278
279#
280# Perform a few tests to determine if the installed tools are adequate
281# for building the world.
282#
283upgrade_checks:
284	@if ! (cd ${.CURDIR}/tools/build/make_check && \
285	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
286	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
287	then \
288	    (cd ${.CURDIR} && ${MAKE} make); \
289	fi
290
291#
292# Upgrade make(1) to the current version using the installed
293# headers, libraries and tools.  Also, allow the location of
294# the system bsdmake-like utility to be overridden.
295#
296MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
297		DESTDIR= \
298		INSTALL="sh ${.CURDIR}/tools/install.sh"
299MMAKE=		${MMAKEENV} ${MAKE} \
300		-D_UPGRADING \
301		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
302		-DNO_CPU_CFLAGS -DNO_WERROR
303
304make: .PHONY
305	@echo
306	@echo "--------------------------------------------------------------"
307	@echo ">>> Building an up-to-date make(1)"
308	@echo "--------------------------------------------------------------"
309	${_+_}@cd ${.CURDIR}/usr.bin/make; \
310		${MMAKE} obj && \
311		${MMAKE} depend && \
312		${MMAKE} all && \
313		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
314
315tinderbox:
316	@cd ${.CURDIR} && ${MAKE} DOING_TINDERBOX=YES universe
317
318toolchains:
319	@cd ${.CURDIR} && ${MAKE} UNIVERSE_TARGET=toolchain universe
320
321kernel-toolchains:
322	@cd ${.CURDIR} && ${MAKE} UNIVERSE_TARGET=kernel-toolchain universe
323
324#
325# universe
326#
327# Attempt to rebuild *everything* for all supported architectures,
328# with a reasonable chance of success, regardless of how old your
329# existing system is.
330#
331.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
332TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64
333TARGET_ARCHES_arm?=	arm armeb
334TARGET_ARCHES_mips?=	mipsel mipseb mips64el mips64eb mipsn32eb
335TARGET_ARCHES_powerpc?=	powerpc powerpc64
336TARGET_ARCHES_pc98?=	i386
337.for target in ${TARGETS}
338TARGET_ARCHES_${target}?= ${target}
339.endfor
340
341.if defined(UNIVERSE_TARGET)
342MAKE_JUST_WORLDS=	YES
343.else
344UNIVERSE_TARGET?=	buildworld
345.endif
346KERNSRCDIR?=		${.CURDIR}/sys
347
348targets:
349	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
350.for target in ${TARGETS}
351.for target_arch in ${TARGET_ARCHES_${target}}
352	@echo "    ${target}/${target_arch}"
353.endfor
354.endfor
355
356.if defined(DOING_TINDERBOX)
357FAILFILE=${.CURDIR}/_.tinderbox.failed
358MAKEFAIL=tee -a ${FAILFILE}
359.else
360MAKEFAIL=cat
361.endif
362
363universe: universe_prologue
364universe_prologue:
365	@echo "--------------------------------------------------------------"
366	@echo ">>> make universe started on ${STARTTIME}"
367	@echo "--------------------------------------------------------------"
368.if defined(DOING_TINDERBOX)
369	@rm -f ${FAILFILE}
370.endif
371.for target in ${TARGETS}
372universe: universe_${target}
373.ORDER: universe_prologue universe_${target} universe_epilogue
374universe_${target}: universe_${target}_prologue
375universe_${target}_prologue:
376	@echo ">> ${target} started on `LC_ALL=C date`"
377.if !defined(MAKE_JUST_KERNELS)
378.for target_arch in ${TARGET_ARCHES_${target}}
379universe_${target}: universe_${target}_${target_arch}
380universe_${target}_${target_arch}: universe_${target}_prologue
381	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
382	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
383	    ${MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
384	    TARGET=${target} \
385	    TARGET_ARCH=${target_arch} \
386	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
387	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
388	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
389	    ${MAKEFAIL}))
390	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
391.endfor
392.endif
393.if !defined(MAKE_JUST_WORLDS)
394.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
395	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
396	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
397	    (echo "${target} 'make LINT' failed," \
398	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
399.endif
400	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
401	    universe_kernels
402.endif
403	@echo ">> ${target} completed on `LC_ALL=C date`"
404.endfor
405universe_kernels: universe_kernconfs
406.if !defined(TARGET)
407TARGET!=	uname -m
408.endif
409KERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
410		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
411		! -name DEFAULTS ! -name NOTES
412universe_kernconfs:
413.for kernel in ${KERNCONFS}
414TARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
415	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
416	grep -v WARNING: | cut -f 2
417.if empty(TARGET_ARCH_${kernel})
418.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
419.endif
420universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
421universe_kernconf_${TARGET}_${kernel}:
422	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
423	    ${MAKE} ${JFLAG} buildkernel \
424	    TARGET=${TARGET} \
425	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
426	    KERNCONF=${kernel} \
427	    > _.${TARGET}.${kernel} 2>&1 || \
428	    (echo "${TARGET} ${kernel} kernel failed," \
429	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
430.endfor
431universe: universe_epilogue
432universe_epilogue:
433	@echo "--------------------------------------------------------------"
434	@echo ">>> make universe completed on `LC_ALL=C date`"
435	@echo "                      (started ${STARTTIME})"
436	@echo "--------------------------------------------------------------"
437.if defined(DOING_TINDERBOX)
438	@if [ -e ${FAILFILE} ] ; then \
439		echo "Tinderbox failed:" ;\
440		cat ${FAILFILE} ;\
441		exit 1 ;\
442	fi
443.endif
444.endif
445