Makefile revision 177794
1186681Sed#
2186681Sed# $FreeBSD: head/Makefile 177794 2008-03-31 13:32:55Z pav $
3186681Sed#
4186681Sed# The user-driven targets are:
5186681Sed#
6186681Sed# universe            - *Really* build *everything* (buildworld and
7186681Sed#                       all kernels on all architectures).
8186681Sed# buildworld          - Rebuild *everything*, including glue to help do
9186681Sed#                       upgrades.
10186681Sed# installworld        - Install everything built by "buildworld".
11186681Sed# world               - buildworld + installworld, no kernel.
12186681Sed# buildkernel         - Rebuild the kernel and the kernel-modules.
13186681Sed# installkernel       - Install the kernel and the kernel-modules.
14186681Sed# installkernel.debug
15186681Sed# reinstallkernel     - Reinstall the kernel and the kernel-modules.
16186681Sed# reinstallkernel.debug
17186681Sed# kernel              - buildkernel + installkernel.
18186681Sed# doxygen             - Build API documentation of the kernel, needs doxygen.
19186681Sed# update              - Convenient way to update your source tree (cvs).
20186681Sed# check-old           - List obsolete directories/files/libraries.
21186681Sed# check-old-dirs      - List obsolete directories.
22186681Sed# check-old-files     - List obsolete files.
23186681Sed# check-old-libs      - List obsolete libraries.
24186681Sed# delete-old          - Delete obsolete directories/files/libraries.
25186681Sed# delete-old-dirs     - Delete obsolete directories.
26186681Sed# delete-old-files    - Delete obsolete files.
27186681Sed# delete-old-libs     - Delete obsolete libraries.
28186681Sed#
29186681Sed# This makefile is simple by design. The FreeBSD make automatically reads
30186681Sed# the /usr/share/mk/sys.mk unless the -m argument is specified on the
31186681Sed# command line. By keeping this makefile simple, it doesn't matter too
32186681Sed# much how different the installed mk files are from those in the source
33186681Sed# tree. This makefile executes a child make process, forcing it to use
34186681Sed# the mk files from the source tree which are supposed to DTRT.
35186681Sed#
36186681Sed# The user-driven targets (as listed above) are implemented in Makefile.inc1.
37186681Sed#
38186681Sed# If you want to build your system from source be sure that /usr/obj has
39186681Sed# at least 800MB of diskspace available.
40186681Sed#
41186681Sed# For individuals wanting to build from the sources currently on their
42186681Sed# system, the simple instructions are:
43186681Sed#
44186681Sed# 1.  `cd /usr/src'  (or to the directory containing your source tree).
45186681Sed# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
46186681Sed# 3.  `make world'
47186681Sed#
48186681Sed# For individuals wanting to upgrade their sources (even if only a
49186681Sed# delta of a few days):
50186681Sed#
51186681Sed#  1.  `cd /usr/src'       (or to the directory containing your source tree).
52186681Sed#  2.  `make buildworld'
53186681Sed#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
54186681Sed#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
55186681Sed#       [steps 3. & 4. can be combined by using the "kernel" target]
56186681Sed#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
57186681Sed#  6.  `mergemaster -p'
58186681Sed#  7.  `make installworld'
59186681Sed#  8.  `make delete-old'
60186681Sed#  9.  `mergemaster'
61186681Sed# 10.  `reboot'
62186681Sed# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
63186681Sed#
64186681Sed# See src/UPDATING `COMMON ITEMS' for more complete information.
65186681Sed#
66186681Sed# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
67186681Sed# cross build world for other machine types using the buildworld target,
68186681Sed# and once the world is built you can cross build a kernel using the
69186681Sed# buildkernel target.
70186681Sed#
71186681Sed# Define the user-driven targets. These are listed here in alphabetical
72186681Sed# order, but that's not important.
73186681Sed#
74187469Sed# Targets that begin with underscore are internal targets intended for
75187469Sed# developer convenience only.  They are intentionally not documented and
76187469Sed# completely subject to change without notice.
77187469Sed#
78187469Sed# For more information, see the build(7) manual page.
79187469Sed#
80187469SedTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
81187469Sed	check-old check-old-dirs check-old-files check-old-libs \
82187469Sed	checkdpadd clean cleandepend cleandir \
83187469Sed	delete-old delete-old-dirs delete-old-files delete-old-libs \
84186681Sed	depend distribute distributeworld distrib-dirs distribution doxygen \
85186681Sed	everything hierarchy install installcheck installkernel \
86186681Sed	installkernel.debug reinstallkernel reinstallkernel.debug \
87186681Sed	installworld kernel-toolchain libraries lint maninstall \
88186681Sed	obj objlink regress rerelease showconfig tags toolchain update \
89186681Sed	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
90186681Sed	_build-tools _cross-tools _includes _libraries _depend \
91197853Sed	build32 distribute32 install32
92186681SedTGTS+=	${SUBDIR_TARGETS}
93186681Sed
94186681SedBITGTS=	files includes
95186681SedBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
96186681SedTGTS+=	${BITGTS}
97186681Sed
98186681Sed.ORDER: buildworld installworld
99186681Sed.ORDER: buildworld distributeworld
100186681Sed.ORDER: buildworld buildkernel
101186681Sed.ORDER: buildkernel installkernel
102186681Sed.ORDER: buildkernel installkernel.debug
103186681Sed.ORDER: buildkernel reinstallkernel
104187373Sed.ORDER: buildkernel reinstallkernel.debug
105187373Sed
106193184SedPATH=	/sbin:/bin:/usr/sbin:/usr/bin
107186681SedMAKEOBJDIRPREFIX?=	/usr/obj
108197481Sed_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
109214817Sed    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
110186681Sed    -f /dev/null -V MAKEOBJDIRPREFIX dummy
111186681Sed.if !empty(_MAKEOBJDIRPREFIX)
112186681Sed.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
113186681Sed	(in make.conf(5)) or command-line variable.
114.endif
115MAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
116BINMAKE= \
117	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
118	-m ${.CURDIR}/share/mk
119_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
120
121#
122# Make sure we have an up-to-date make(1). Only world and buildworld
123# should do this as those are the initial targets used for upgrades.
124# The user can define ALWAYS_CHECK_MAKE to have this check performed
125# for all targets.
126#
127.if defined(ALWAYS_CHECK_MAKE)
128${TGTS}: upgrade_checks
129.else
130buildworld: upgrade_checks
131.endif
132
133#
134# This 'cleanworld' target is not included in TGTS, because it is not a
135# recursive target.  All of the work for it is done right here.   It is
136# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
137# created by bsd.obj.mk, except that we don't want to .include that file
138# in this makefile.  
139#
140# In the following, the first 'rm' in a series will usually remove all
141# files and directories.  If it does not, then there are probably some
142# files with chflags set, so this unsets them and tries the 'rm' a
143# second time.  There are situations where this target will be cleaning
144# some directories via more than one method, but that duplication is
145# needed to correctly handle all the possible situations.
146#
147BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
148cleanworld:
149.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
150.if exists(${BW_CANONICALOBJDIR}/)
151	-rm -rf ${BW_CANONICALOBJDIR}/*
152	-chflags -R 0 ${BW_CANONICALOBJDIR}
153	rm -rf ${BW_CANONICALOBJDIR}/*
154.endif
155	#   To be safe in this case, fall back to a 'make cleandir'
156	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
157.else
158	-rm -rf ${.OBJDIR}/*
159	-chflags -R 0 ${.OBJDIR}
160	rm -rf ${.OBJDIR}/*
161.endif
162
163#
164# Handle the user-driven targets, using the source relative mk files.
165#
166
167${TGTS}:
168	${_+_}@cd ${.CURDIR}; \
169		${_MAKE} ${.TARGET}
170
171# Set a reasonable default
172.MAIN:	all
173
174STARTTIME!= LC_ALL=C date
175CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
176.if !empty(CHECK_TIME)
177.error check your date/time: ${STARTTIME}
178.endif
179
180.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
181#
182# world
183#
184# Attempt to rebuild and reinstall everything. This target is not to be
185# used for upgrading an existing FreeBSD system, because the kernel is
186# not included. One can argue that this target doesn't build everything
187# then.
188#
189world: upgrade_checks
190	@echo "--------------------------------------------------------------"
191	@echo ">>> make world started on ${STARTTIME}"
192	@echo "--------------------------------------------------------------"
193.if target(pre-world)
194	@echo
195	@echo "--------------------------------------------------------------"
196	@echo ">>> Making 'pre-world' target"
197	@echo "--------------------------------------------------------------"
198	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
199.endif
200	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
201	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
202.if target(post-world)
203	@echo
204	@echo "--------------------------------------------------------------"
205	@echo ">>> Making 'post-world' target"
206	@echo "--------------------------------------------------------------"
207	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
208.endif
209	@echo
210	@echo "--------------------------------------------------------------"
211	@echo ">>> make world completed on `LC_ALL=C date`"
212	@echo "                   (started ${STARTTIME})"
213	@echo "--------------------------------------------------------------"
214.else
215world:
216	@echo "WARNING: make world will overwrite your existing FreeBSD"
217	@echo "installation without also building and installing a new"
218	@echo "kernel.  This can be dangerous.  Please read the handbook,"
219	@echo "'Rebuilding world', for how to upgrade your system."
220	@echo "Define DESTDIR to where you want to install FreeBSD,"
221	@echo "including /, to override this warning and proceed as usual."
222	@echo ""
223	@echo "Bailing out now..."
224	@false
225.endif
226
227#
228# kernel
229#
230# Short hand for `make buildkernel installkernel'
231#
232kernel: buildkernel installkernel
233
234#
235# Perform a few tests to determine if the installed tools are adequate
236# for building the world.
237#
238upgrade_checks:
239	@if ! (cd ${.CURDIR}/tools/build/make_check && \
240	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
241	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
242	then \
243	    (cd ${.CURDIR} && ${MAKE} make); \
244	fi
245
246#
247# Upgrade make(1) to the current version using the installed
248# headers, libraries and tools.  Also, allow the location of
249# the system bsdmake-like utility to be overridden.
250#
251MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
252		DESTDIR= \
253		INSTALL="sh ${.CURDIR}/tools/install.sh"
254MMAKE=		${MMAKEENV} ${MAKE} \
255		-D_UPGRADING \
256		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
257		-DNO_CPU_CFLAGS -DNO_WERROR
258
259make: .PHONY
260	@echo
261	@echo "--------------------------------------------------------------"
262	@echo ">>> Building an up-to-date make(1)"
263	@echo "--------------------------------------------------------------"
264	${_+_}@cd ${.CURDIR}/usr.bin/make; \
265		${MMAKE} obj && \
266		${MMAKE} depend && \
267		${MMAKE} all && \
268		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
269
270#
271# universe
272#
273# Attempt to rebuild *everything* for all supported architectures,
274# with a reasonable chance of success, regardless of how old your
275# existing system is.
276#
277.if make(universe)
278TARGETS?=amd64 arm i386 ia64 pc98 powerpc sparc64 sun4v
279
280universe: universe_prologue
281universe_prologue:
282	@echo "--------------------------------------------------------------"
283	@echo ">>> make universe started on ${STARTTIME}"
284	@echo "--------------------------------------------------------------"
285.for target in ${TARGETS}
286KERNCONFS!=	cd ${.CURDIR}/sys/${target}/conf && \
287		find [A-Z]*[A-Z] -type f -maxdepth 0 \
288		! -name DEFAULTS ! -name LINT
289KERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
290universe: universe_${target}
291.ORDER: universe_prologue universe_${target} universe_epilogue
292universe_${target}:
293	@echo ">> ${target} started on `LC_ALL=C date`"
294	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
295	    TARGET=${target} \
296	    __MAKE_CONF=/dev/null \
297	    > _.${target}.buildworld 2>&1
298	@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
299.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
300	-cd ${.CURDIR}/sys/${target}/conf && ${MAKE} LINT \
301	    > ${.CURDIR}/_.${target}.makeLINT 2>&1
302.endif
303.for kernel in ${KERNCONFS}
304	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
305	    TARGET=${target} \
306	    KERNCONF=${kernel} \
307	    __MAKE_CONF=/dev/null \
308	    > _.${target}.${kernel} 2>&1
309.endfor
310	@echo ">> ${target} completed on `LC_ALL=C date`"
311.endfor
312universe: universe_epilogue
313universe_epilogue:
314	@echo "--------------------------------------------------------------"
315	@echo ">>> make universe completed on `LC_ALL=C date`"
316	@echo "                      (started ${STARTTIME})"
317	@echo "--------------------------------------------------------------"
318.endif
319