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