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