Makefile revision 159831
1339640Smm#
2339640Smm# $FreeBSD: head/Makefile 159831 2006-06-21 09:53:42Z obrien $
3339640Smm#
4339640Smm# The user-driven targets are:
5339640Smm#
6339640Smm# universe            - *Really* build *everything* (buildworld and
7339640Smm#                       all kernels on all architectures).
8339640Smm# buildworld          - Rebuild *everything*, including glue to help do
9339640Smm#                       upgrades.
10339640Smm# installworld        - Install everything built by "buildworld".
11339640Smm# world               - buildworld + installworld, no kernel.
12339640Smm# buildkernel         - Rebuild the kernel and the kernel-modules.
13339640Smm# installkernel       - Install the kernel and the kernel-modules.
14339640Smm# installkernel.debug
15339640Smm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
16339640Smm# reinstallkernel.debug
17339640Smm# kernel              - buildkernel + installkernel.
18339640Smm# doxygen             - Build API documentation of the kernel, needs doxygen.
19339640Smm# update              - Convenient way to update your source tree (cvs).
20339640Smm# check-old           - Print a list of old files/directories in the system.
21339640Smm# delete-old          - Delete obsolete files and directories interactively.
22339640Smm# delete-old-libs     - Delete obsolete libraries interactively.
23339640Smm#
24339640Smm# This makefile is simple by design. The FreeBSD make automatically reads
25339640Smm# the /usr/share/mk/sys.mk unless the -m argument is specified on the
26339640Smm# command line. By keeping this makefile simple, it doesn't matter too
27339640Smm# much how different the installed mk files are from those in the source
28339640Smm# tree. This makefile executes a child make process, forcing it to use
29339640Smm# the mk files from the source tree which are supposed to DTRT.
30339640Smm#
31339640Smm# The user-driven targets (as listed above) are implemented in Makefile.inc1.
32339640Smm#
33339640Smm# If you want to build your system from source be sure that /usr/obj has
34339640Smm# at least 400MB of diskspace available.
35339640Smm#
36339640Smm# For individuals wanting to build from the sources currently on their
37339640Smm# system, the simple instructions are:
38339640Smm#
39339640Smm# 1.  `cd /usr/src'  (or to the directory containing your source tree).
40339640Smm# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
41339640Smm# 3.  `make world'
42339640Smm#
43339640Smm# For individuals wanting to upgrade their sources (even if only a
44339640Smm# delta of a few days):
45339640Smm#
46339640Smm#  1.  `cd /usr/src'       (or to the directory containing your source tree).
47339640Smm#  2.  `make buildworld'
48339640Smm#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
49339640Smm#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
50339640Smm#       [steps 3. & 4. can be combined by using the "kernel" target]
51339640Smm#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
52339640Smm#  6.  `mergemaster -p'
53339640Smm#  7.  `make installworld'
54339640Smm#  8.  `make delete-old'
55339640Smm#  9.  `mergemaster'
56339640Smm# 10.  `reboot'
57339640Smm# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
58339640Smm#
59339640Smm# See src/UPDATING `COMMON ITEMS' for more complete information.
60339640Smm#
61339640Smm# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
62339640Smm# cross build world for other architectures using the buildworld target,
63339640Smm# and once the world is built you can cross build a kernel using the
64339640Smm# buildkernel target.
65339640Smm#
66339640Smm# Define the user-driven targets. These are listed here in alphabetical
67339640Smm# order, but that's not important.
68339640Smm#
69339640Smm# Targets that begin with underscore are internal targets intended for
70339640Smm# developer convenience only.  They are intentionally not documented and
71339640Smm# completely subject to change without notice.
72339640Smm#
73339640SmmTGTS=	all all-man buildenv buildenvvars buildkernel buildworld check-old \
74339640Smm	checkdpadd clean cleandepend cleandir delete-old delete-old-libs \
75339640Smm	depend distribute distributeworld distrib-dirs distribution doxygen \
76339640Smm	everything hierarchy install installcheck installkernel \
77339640Smm	installkernel.debug reinstallkernel reinstallkernel.debug \
78339640Smm	installworld kernel-toolchain libraries lint maninstall \
79339640Smm	obj objlink regress rerelease showconfig tags toolchain update \
80339640Smm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
81339640Smm	_build-tools _cross-tools _includes _libraries _depend \
82339640Smm	build32 distribute32 install32
83339640SmmTGTS+=	${SUBDIR_TARGETS}
84339640Smm
85339640SmmBITGTS=	files includes
86339640SmmBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
87339640SmmTGTS+=	${BITGTS}
88339640Smm
89339640Smm.ORDER: buildworld installworld
90339640Smm.ORDER: buildworld distributeworld
91339640Smm.ORDER: buildworld buildkernel
92339640Smm.ORDER: buildkernel installkernel
93339640Smm.ORDER: buildkernel installkernel.debug
94339640Smm.ORDER: buildkernel reinstallkernel
95339640Smm.ORDER: buildkernel reinstallkernel.debug
96339640Smm
97339640SmmPATH=	/sbin:/bin:/usr/sbin:/usr/bin
98339640SmmMAKEOBJDIRPREFIX?=	/usr/obj
99339640Smm_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
100339640Smm    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
101339640Smm    -f /dev/null -V MAKEOBJDIRPREFIX dummy
102339640Smm.if !empty(_MAKEOBJDIRPREFIX)
103339640Smm.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
104339640Smm	(in make.conf(5)) or command-line variable.
105339640Smm.endif
106339640SmmMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
107339640SmmBINMAKE= \
108339640Smm	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
109339640Smm	-m ${.CURDIR}/share/mk
110339640Smm_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
111339640Smm
112339640Smm#
113339640Smm# Make sure we have an up-to-date make(1). Only world and buildworld
114339640Smm# should do this as those are the initial targets used for upgrades.
115339640Smm# The user can define ALWAYS_CHECK_MAKE to have this check performed
116339640Smm# for all targets.
117339640Smm#
118339640Smm.if defined(ALWAYS_CHECK_MAKE)
119339640Smm${TGTS}: upgrade_checks
120339640Smm.else
121339640Smmbuildworld: upgrade_checks
122339640Smm.endif
123339640Smm
124339640Smm#
125339640Smm# This 'cleanworld' target is not included in TGTS, because it is not a
126339640Smm# recursive target.  All of the work for it is done right here.   It is
127339640Smm# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
128339640Smm# created by bsd.obj.mk, except that we don't want to .include that file
129339640Smm# in this makefile.  
130339640Smm#
131339640Smm# In the following, the first 'rm' in a series will usually remove all
132339640Smm# files and directories.  If it does not, then there are probably some
133339640Smm# files with chflags set, so this unsets them and tries the 'rm' a
134339640Smm# second time.  There are situations where this target will be cleaning
135339640Smm# some directories via more than one method, but that duplication is
136339640Smm# needed to correctly handle all the possible situations.
137339640Smm#
138339640SmmBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
139339640Smmcleanworld:
140339640Smm.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
141339640Smm.if exists(${BW_CANONICALOBJDIR}/)
142339640Smm	-rm -rf ${BW_CANONICALOBJDIR}/*
143339640Smm	chflags -R 0 ${BW_CANONICALOBJDIR}
144339640Smm	rm -rf ${BW_CANONICALOBJDIR}/*
145339640Smm.endif
146339640Smm	#   To be safe in this case, fall back to a 'make cleandir'
147339640Smm	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
148339640Smm.else
149339640Smm	-rm -rf ${.OBJDIR}/*
150339640Smm	chflags -R 0 ${.OBJDIR}
151339640Smm	rm -rf ${.OBJDIR}/*
152339640Smm.endif
153339640Smm
154339640Smm#
155339640Smm# Handle the user-driven targets, using the source relative mk files.
156339640Smm#
157339640Smm
158339640Smm${TGTS}:
159339640Smm	${_+_}@cd ${.CURDIR}; \
160339640Smm		${_MAKE} ${.TARGET}
161339640Smm
162339640Smm# Set a reasonable default
163339640Smm.MAIN:	all
164339640Smm
165339640SmmSTARTTIME!= LC_ALL=C date
166339640Smm
167339640Smm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
168339640Smm#
169339640Smm# world
170339640Smm#
171339640Smm# Attempt to rebuild and reinstall everything. This target is not to be
172339640Smm# used for upgrading an existing FreeBSD system, because the kernel is
173339640Smm# not included. One can argue that this target doesn't build everything
174339640Smm# then.
175339640Smm#
176339640Smmworld: upgrade_checks
177339640Smm	@echo "--------------------------------------------------------------"
178339640Smm	@echo ">>> make world started on ${STARTTIME}"
179339640Smm	@echo "--------------------------------------------------------------"
180339640Smm.if target(pre-world)
181339640Smm	@echo
182339640Smm	@echo "--------------------------------------------------------------"
183339640Smm	@echo ">>> Making 'pre-world' target"
184339640Smm	@echo "--------------------------------------------------------------"
185339640Smm	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
186339640Smm.endif
187339640Smm	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
188339640Smm	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
189339640Smm.if target(post-world)
190339640Smm	@echo
191339640Smm	@echo "--------------------------------------------------------------"
192339640Smm	@echo ">>> Making 'post-world' target"
193339640Smm	@echo "--------------------------------------------------------------"
194339640Smm	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
195339640Smm.endif
196339640Smm	@echo
197339640Smm	@echo "--------------------------------------------------------------"
198339640Smm	@echo ">>> make world completed on `LC_ALL=C date`"
199339640Smm	@echo "                   (started ${STARTTIME})"
200339640Smm	@echo "--------------------------------------------------------------"
201339640Smm.else
202339640Smmworld:
203339640Smm	@echo "WARNING: make world will overwrite your existing FreeBSD"
204339640Smm	@echo "installation without also building and installing a new"
205339640Smm	@echo "kernel.  This can be dangerous.  Please read the handbook,"
206339640Smm	@echo "'Rebuilding world', for how to upgrade your system."
207339640Smm	@echo "Define DESTDIR to where you want to install FreeBSD,"
208339640Smm	@echo "including /, to override this warning and proceed as usual."
209339640Smm	@echo "You may get the historical 'make world' behavior by defining"
210339640Smm	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
211339640Smm	@echo "before doing this."
212339640Smm	@echo ""
213339640Smm	@echo "Bailing out now..."
214339640Smm	@false
215339640Smm.endif
216339640Smm
217339640Smm#
218339640Smm# kernel
219339640Smm#
220339640Smm# Short hand for `make buildkernel installkernel'
221339640Smm#
222339640Smmkernel: buildkernel installkernel
223339640Smm
224339640Smm#
225339640Smm# Perform a few tests to determine if the installed tools are adequate
226339640Smm# for building the world.
227339640Smm#
228339640Smmupgrade_checks:
229339640Smm	@if ! (cd ${.CURDIR}/tools/build/make_check && \
230339640Smm	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
231339640Smm	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
232339640Smm	then \
233339640Smm	    (cd ${.CURDIR} && make make); \
234339640Smm	fi
235339640Smm
236339640Smm#
237339640Smm# Upgrade make(1) to the current version using the installed
238339640Smm# headers, libraries and tools.
239339640Smm#
240339640SmmMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
241339640Smm		DESTDIR= \
242339640Smm		INSTALL="sh ${.CURDIR}/tools/install.sh"
243339640SmmMMAKE=		${MMAKEENV} make \
244339640Smm		-D_UPGRADING \
245339640Smm		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
246339640Smm		-DNO_CPU_CFLAGS -DNO_WERROR
247339640Smm
248339640Smmmake: .PHONY
249339640Smm	@echo
250339640Smm	@echo "--------------------------------------------------------------"
251339640Smm	@echo ">>> Building an up-to-date make(1)"
252339640Smm	@echo "--------------------------------------------------------------"
253339640Smm	${_+_}@cd ${.CURDIR}/usr.bin/make; \
254339640Smm		${MMAKE} obj && \
255339640Smm		${MMAKE} depend && \
256339640Smm		${MMAKE} all && \
257339640Smm		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
258339640Smm
259339640Smm#
260339640Smm# universe
261339640Smm#
262339640Smm# Attempt to rebuild *everything* for all supported architectures,
263339640Smm# with a reasonable chance of success, regardless of how old your
264339640Smm# existing system is.
265339640Smm#
266339640Smm.if make(universe)
267339640Smmuniverse: universe_prologue
268339640Smmuniverse_prologue:
269339640Smm	@echo "--------------------------------------------------------------"
270339640Smm	@echo ">>> make universe started on ${STARTTIME}"
271339640Smm	@echo "--------------------------------------------------------------"
272339640Smm.for target in i386 i386:pc98 sparc64 ia64 amd64
273339640Smm.for arch in ${target:C/:.*$//}
274339640Smm.for mach in ${target:C/^.*://}
275339640SmmKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
276339640Smm		find [A-Z]*[A-Z] -type f -maxdepth 0 \
277339640Smm		! -name DEFAULTS ! -name LINT
278339640SmmKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
279339640Smmuniverse: universe_${mach}
280339640Smm.ORDER: universe_prologue universe_${mach} universe_epilogue
281339640Smmuniverse_${mach}:
282339640Smm	@echo ">> ${mach} started on `LC_ALL=C date`"
283339640Smm	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
284339640Smm	    TARGET_ARCH=${arch} TARGET=${mach} \
285339640Smm	    __MAKE_CONF=/dev/null \
286339640Smm	    > _.${mach}.buildworld 2>&1
287339640Smm	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
288339640Smm.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
289339640Smm	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
290339640Smm	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
291339640Smm.endif
292339640Smm.for kernel in ${KERNCONFS}
293339640Smm	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
294339640Smm	    TARGET_ARCH=${arch} TARGET=${mach} \
295339640Smm	    KERNCONF=${kernel} \
296339640Smm	    __MAKE_CONF=/dev/null \
297339640Smm	    > _.${mach}.${kernel} 2>&1
298339640Smm.endfor
299339640Smm	@echo ">> ${mach} completed on `LC_ALL=C date`"
300339640Smm.endfor
301339640Smm.endfor
302339640Smm.endfor
303339640Smmuniverse: universe_epilogue
304339640Smmuniverse_epilogue:
305339640Smm	@echo "--------------------------------------------------------------"
306339640Smm	@echo ">>> make universe completed on `LC_ALL=C date`"
307339640Smm	@echo "                      (started ${STARTTIME})"
308339640Smm	@echo "--------------------------------------------------------------"
309339640Smm.endif
310339640Smm