Makefile revision 159831
1#
2# $FreeBSD: head/Makefile 159831 2006-06-21 09:53:42Z obrien $
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# doxygen             - Build API documentation of the kernel, needs doxygen.
19# update              - Convenient way to update your source tree (cvs).
20# check-old           - Print a list of old files/directories in the system.
21# delete-old          - Delete obsolete files and directories interactively.
22# delete-old-libs     - Delete obsolete libraries interactively.
23#
24# This makefile is simple by design. The FreeBSD make automatically reads
25# the /usr/share/mk/sys.mk unless the -m argument is specified on the
26# command line. By keeping this makefile simple, it doesn't matter too
27# much how different the installed mk files are from those in the source
28# tree. This makefile executes a child make process, forcing it to use
29# the mk files from the source tree which are supposed to DTRT.
30#
31# The user-driven targets (as listed above) are implemented in Makefile.inc1.
32#
33# If you want to build your system from source be sure that /usr/obj has
34# at least 400MB of diskspace available.
35#
36# For individuals wanting to build from the sources currently on their
37# system, the simple instructions are:
38#
39# 1.  `cd /usr/src'  (or to the directory containing your source tree).
40# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
41# 3.  `make world'
42#
43# For individuals wanting to upgrade their sources (even if only a
44# delta of a few days):
45#
46#  1.  `cd /usr/src'       (or to the directory containing your source tree).
47#  2.  `make buildworld'
48#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
49#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
50#       [steps 3. & 4. can be combined by using the "kernel" target]
51#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
52#  6.  `mergemaster -p'
53#  7.  `make installworld'
54#  8.  `make delete-old'
55#  9.  `mergemaster'
56# 10.  `reboot'
57# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
58#
59# See src/UPDATING `COMMON ITEMS' for more complete information.
60#
61# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
62# cross build world for other architectures using the buildworld target,
63# and once the world is built you can cross build a kernel using the
64# buildkernel target.
65#
66# Define the user-driven targets. These are listed here in alphabetical
67# order, but that's not important.
68#
69# Targets that begin with underscore are internal targets intended for
70# developer convenience only.  They are intentionally not documented and
71# completely subject to change without notice.
72#
73TGTS=	all all-man buildenv buildenvvars buildkernel buildworld check-old \
74	checkdpadd clean cleandepend cleandir delete-old delete-old-libs \
75	depend distribute distributeworld distrib-dirs distribution doxygen \
76	everything hierarchy install installcheck installkernel \
77	installkernel.debug reinstallkernel reinstallkernel.debug \
78	installworld kernel-toolchain libraries lint maninstall \
79	obj objlink regress rerelease showconfig tags toolchain update \
80	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
81	_build-tools _cross-tools _includes _libraries _depend \
82	build32 distribute32 install32
83TGTS+=	${SUBDIR_TARGETS}
84
85BITGTS=	files includes
86BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
87TGTS+=	${BITGTS}
88
89.ORDER: buildworld installworld
90.ORDER: buildworld distributeworld
91.ORDER: buildworld buildkernel
92.ORDER: buildkernel installkernel
93.ORDER: buildkernel installkernel.debug
94.ORDER: buildkernel reinstallkernel
95.ORDER: buildkernel reinstallkernel.debug
96
97PATH=	/sbin:/bin:/usr/sbin:/usr/bin
98MAKEOBJDIRPREFIX?=	/usr/obj
99_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
100    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
101    -f /dev/null -V MAKEOBJDIRPREFIX dummy
102.if !empty(_MAKEOBJDIRPREFIX)
103.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
104	(in make.conf(5)) or command-line variable.
105.endif
106MAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
107BINMAKE= \
108	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
109	-m ${.CURDIR}/share/mk
110_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
111
112#
113# Make sure we have an up-to-date make(1). Only world and buildworld
114# should do this as those are the initial targets used for upgrades.
115# The user can define ALWAYS_CHECK_MAKE to have this check performed
116# for all targets.
117#
118.if defined(ALWAYS_CHECK_MAKE)
119${TGTS}: upgrade_checks
120.else
121buildworld: upgrade_checks
122.endif
123
124#
125# This 'cleanworld' target is not included in TGTS, because it is not a
126# recursive target.  All of the work for it is done right here.   It is
127# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
128# created by bsd.obj.mk, except that we don't want to .include that file
129# in this makefile.  
130#
131# In the following, the first 'rm' in a series will usually remove all
132# files and directories.  If it does not, then there are probably some
133# files with chflags set, so this unsets them and tries the 'rm' a
134# second time.  There are situations where this target will be cleaning
135# some directories via more than one method, but that duplication is
136# needed to correctly handle all the possible situations.
137#
138BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
139cleanworld:
140.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
141.if exists(${BW_CANONICALOBJDIR}/)
142	-rm -rf ${BW_CANONICALOBJDIR}/*
143	chflags -R 0 ${BW_CANONICALOBJDIR}
144	rm -rf ${BW_CANONICALOBJDIR}/*
145.endif
146	#   To be safe in this case, fall back to a 'make cleandir'
147	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
148.else
149	-rm -rf ${.OBJDIR}/*
150	chflags -R 0 ${.OBJDIR}
151	rm -rf ${.OBJDIR}/*
152.endif
153
154#
155# Handle the user-driven targets, using the source relative mk files.
156#
157
158${TGTS}:
159	${_+_}@cd ${.CURDIR}; \
160		${_MAKE} ${.TARGET}
161
162# Set a reasonable default
163.MAIN:	all
164
165STARTTIME!= LC_ALL=C date
166
167.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
168#
169# world
170#
171# Attempt to rebuild and reinstall everything. This target is not to be
172# used for upgrading an existing FreeBSD system, because the kernel is
173# not included. One can argue that this target doesn't build everything
174# then.
175#
176world: upgrade_checks
177	@echo "--------------------------------------------------------------"
178	@echo ">>> make world started on ${STARTTIME}"
179	@echo "--------------------------------------------------------------"
180.if target(pre-world)
181	@echo
182	@echo "--------------------------------------------------------------"
183	@echo ">>> Making 'pre-world' target"
184	@echo "--------------------------------------------------------------"
185	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
186.endif
187	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
188	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
189.if target(post-world)
190	@echo
191	@echo "--------------------------------------------------------------"
192	@echo ">>> Making 'post-world' target"
193	@echo "--------------------------------------------------------------"
194	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
195.endif
196	@echo
197	@echo "--------------------------------------------------------------"
198	@echo ">>> make world completed on `LC_ALL=C date`"
199	@echo "                   (started ${STARTTIME})"
200	@echo "--------------------------------------------------------------"
201.else
202world:
203	@echo "WARNING: make world will overwrite your existing FreeBSD"
204	@echo "installation without also building and installing a new"
205	@echo "kernel.  This can be dangerous.  Please read the handbook,"
206	@echo "'Rebuilding world', for how to upgrade your system."
207	@echo "Define DESTDIR to where you want to install FreeBSD,"
208	@echo "including /, to override this warning and proceed as usual."
209	@echo "You may get the historical 'make world' behavior by defining"
210	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
211	@echo "before doing this."
212	@echo ""
213	@echo "Bailing out now..."
214	@false
215.endif
216
217#
218# kernel
219#
220# Short hand for `make buildkernel installkernel'
221#
222kernel: buildkernel installkernel
223
224#
225# Perform a few tests to determine if the installed tools are adequate
226# for building the world.
227#
228upgrade_checks:
229	@if ! (cd ${.CURDIR}/tools/build/make_check && \
230	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
231	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
232	then \
233	    (cd ${.CURDIR} && make make); \
234	fi
235
236#
237# Upgrade make(1) to the current version using the installed
238# headers, libraries and tools.
239#
240MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
241		DESTDIR= \
242		INSTALL="sh ${.CURDIR}/tools/install.sh"
243MMAKE=		${MMAKEENV} make \
244		-D_UPGRADING \
245		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
246		-DNO_CPU_CFLAGS -DNO_WERROR
247
248make: .PHONY
249	@echo
250	@echo "--------------------------------------------------------------"
251	@echo ">>> Building an up-to-date make(1)"
252	@echo "--------------------------------------------------------------"
253	${_+_}@cd ${.CURDIR}/usr.bin/make; \
254		${MMAKE} obj && \
255		${MMAKE} depend && \
256		${MMAKE} all && \
257		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
258
259#
260# universe
261#
262# Attempt to rebuild *everything* for all supported architectures,
263# with a reasonable chance of success, regardless of how old your
264# existing system is.
265#
266.if make(universe)
267universe: universe_prologue
268universe_prologue:
269	@echo "--------------------------------------------------------------"
270	@echo ">>> make universe started on ${STARTTIME}"
271	@echo "--------------------------------------------------------------"
272.for target in i386 i386:pc98 sparc64 ia64 amd64
273.for arch in ${target:C/:.*$//}
274.for mach in ${target:C/^.*://}
275KERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
276		find [A-Z]*[A-Z] -type f -maxdepth 0 \
277		! -name DEFAULTS ! -name LINT
278KERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
279universe: universe_${mach}
280.ORDER: universe_prologue universe_${mach} universe_epilogue
281universe_${mach}:
282	@echo ">> ${mach} started on `LC_ALL=C date`"
283	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
284	    TARGET_ARCH=${arch} TARGET=${mach} \
285	    __MAKE_CONF=/dev/null \
286	    > _.${mach}.buildworld 2>&1
287	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
288.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
289	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
290	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
291.endif
292.for kernel in ${KERNCONFS}
293	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
294	    TARGET_ARCH=${arch} TARGET=${mach} \
295	    KERNCONF=${kernel} \
296	    __MAKE_CONF=/dev/null \
297	    > _.${mach}.${kernel} 2>&1
298.endfor
299	@echo ">> ${mach} completed on `LC_ALL=C date`"
300.endfor
301.endfor
302.endfor
303universe: universe_epilogue
304universe_epilogue:
305	@echo "--------------------------------------------------------------"
306	@echo ">>> make universe completed on `LC_ALL=C date`"
307	@echo "                      (started ${STARTTIME})"
308	@echo "--------------------------------------------------------------"
309.endif
310