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