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