Makefile revision 216487
1139804Simp#
293835Stmm# $FreeBSD: head/Makefile 216487 2010-12-16 15:27:13Z jhb $
393835Stmm#
493835Stmm# The user-driven targets are:
593835Stmm#
693835Stmm# universe            - *Really* build *everything* (buildworld and
793835Stmm#                       all kernels on all architectures).
893835Stmm# buildworld          - Rebuild *everything*, including glue to help do
993835Stmm#                       upgrades.
1093835Stmm# installworld        - Install everything built by "buildworld".
1193835Stmm# world               - buildworld + installworld, no kernel.
1293835Stmm# buildkernel         - Rebuild the kernel and the kernel-modules.
1393835Stmm# installkernel       - Install the kernel and the kernel-modules.
1493835Stmm# installkernel.debug
1593835Stmm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1693835Stmm# reinstallkernel.debug
1793835Stmm# kernel              - buildkernel + installkernel.
1893835Stmm# kernel-toolchain    - Builds the subset of world necessary to build a kernel
1993835Stmm# doxygen             - Build API documentation of the kernel, needs doxygen.
2093835Stmm# update              - Convenient way to update your source tree (cvs).
2193835Stmm# check-old           - List obsolete directories/files/libraries.
2293835Stmm# check-old-dirs      - List obsolete directories.
2393835Stmm# check-old-files     - List obsolete files.
2493835Stmm# check-old-libs      - List obsolete libraries.
2593835Stmm# delete-old          - Delete obsolete directories/files/libraries.
2693835Stmm# delete-old-dirs     - Delete obsolete directories.
2793835Stmm# delete-old-files    - Delete obsolete files.
2893835Stmm# delete-old-libs     - Delete obsolete libraries.
2993835Stmm#
3093835Stmm# This makefile is simple by design. The FreeBSD make automatically reads
3193835Stmm# the /usr/share/mk/sys.mk unless the -m argument is specified on the
3293835Stmm# command line. By keeping this makefile simple, it doesn't matter too
3393835Stmm# much how different the installed mk files are from those in the source
3493835Stmm# tree. This makefile executes a child make process, forcing it to use
3593835Stmm# the mk files from the source tree which are supposed to DTRT.
3693835Stmm#
3793835Stmm# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3893835Stmm#
3993835Stmm# If you want to build your system from source be sure that /usr/obj has
4093835Stmm# at least 800MB of diskspace available.
4193835Stmm#
4293835Stmm# For individuals wanting to build from the sources currently on their
4393835Stmm# system, the simple instructions are:
4493835Stmm#
4593835Stmm# 1.  `cd /usr/src'  (or to the directory containing your source tree).
4693835Stmm# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
4793835Stmm# 3.  `make world'
4893835Stmm#
4993835Stmm# For individuals wanting to upgrade their sources (even if only a
50116182Sobrien# delta of a few days):
51116182Sobrien#
52116182Sobrien#  1.  `cd /usr/src'       (or to the directory containing your source tree).
5393835Stmm#  2.  `make buildworld'
5493835Stmm#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
5593835Stmm#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
5693835Stmm#       [steps 3. & 4. can be combined by using the "kernel" target]
5793835Stmm#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
5893835Stmm#  6.  `mergemaster -p'
5993835Stmm#  7.  `make installworld'
6093835Stmm#  8.  `make delete-old'
6193835Stmm#  9.  `mergemaster'                         (you may wish to use -U or -ai).
6293835Stmm# 10.  `reboot'
6393835Stmm# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
6493835Stmm#
65211230Sjkim# See src/UPDATING `COMMON ITEMS' for more complete information.
6693835Stmm#
67178429Sphk# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
68178429Sphk# cross build world for other machine types using the buildworld target,
69211228Sjkim# and once the world is built you can cross build a kernel using the
70211228Sjkim# buildkernel target.
71178429Sphk#
7293835Stmm# Define the user-driven targets. These are listed here in alphabetical
73158450Sphk# order, but that's not important.
7493835Stmm#
7593835Stmm# Targets that begin with underscore are internal targets intended for
7693835Stmm# developer convenience only.  They are intentionally not documented and
7793835Stmm# completely subject to change without notice.
78211228Sjkim#
7993835Stmm# For more information, see the build(7) manual page.
8093835Stmm#
8193835StmmTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
8293835Stmm	check-old check-old-dirs check-old-files check-old-libs \
8393835Stmm	checkdpadd clean cleandepend cleandir \
84211228Sjkim	delete-old delete-old-dirs delete-old-files delete-old-libs \
85211228Sjkim	depend distribute distributeworld distrib-dirs distribution doxygen \
86211228Sjkim	everything hierarchy install installcheck installkernel \
87211228Sjkim	installkernel.debug reinstallkernel reinstallkernel.debug \
8893835Stmm	installworld kernel-toolchain libraries lint maninstall \
8993835Stmm	obj objlink regress rerelease showconfig tags toolchain update \
9093835Stmm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
91211230Sjkim	_build-tools _cross-tools _includes _libraries _depend \
92211230Sjkim	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
93211228Sjkim
9493835StmmTGTS+=	${SUBDIR_TARGETS}
95211230Sjkim
96211230SjkimBITGTS=	files includes
9793835StmmBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
9893835StmmTGTS+=	${BITGTS}
9993835Stmm
10093835Stmm.ORDER: buildworld installworld
10193835Stmm.ORDER: buildworld distributeworld
10293835Stmm.ORDER: buildworld buildkernel
10393835Stmm.ORDER: buildkernel installkernel
10493835Stmm.ORDER: buildkernel installkernel.debug
10593835Stmm.ORDER: buildkernel reinstallkernel
10693835Stmm.ORDER: buildkernel reinstallkernel.debug
10793835Stmm
10893835StmmPATH=	/sbin:/bin:/usr/sbin:/usr/bin
10993835StmmMAKEOBJDIRPREFIX?=	/usr/obj
11093835Stmm_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
11193835Stmm    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
112211228Sjkim    -f /dev/null -V MAKEOBJDIRPREFIX dummy
11393835Stmm.if !empty(_MAKEOBJDIRPREFIX)
11493835Stmm.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
11593835Stmm	(in make.conf(5)) or command-line variable.
11693835Stmm.endif
11793835StmmMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
118190337SjkimBINMAKE= \
11993835Stmm	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
120178429Sphk	-m ${.CURDIR}/share/mk
12193835Stmm_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
12293835Stmm
12393835Stmm#
12493835Stmm# Make sure we have an up-to-date make(1). Only world and buildworld
125190337Sjkim# should do this as those are the initial targets used for upgrades.
12693835Stmm# The user can define ALWAYS_CHECK_MAKE to have this check performed
12793835Stmm# for all targets.
128190337Sjkim#
129190337Sjkim.if defined(ALWAYS_CHECK_MAKE)
130190337Sjkim${TGTS}: upgrade_checks
13193835Stmm.else
13293835Stmmbuildworld: upgrade_checks
133162970Sphk.endif
134211230Sjkim
135190337Sjkim#
136190337Sjkim# This 'cleanworld' target is not included in TGTS, because it is not a
13793835Stmm# recursive target.  All of the work for it is done right here.   It is
138190337Sjkim# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
139190337Sjkim# created by bsd.obj.mk, except that we don't want to .include that file
140211228Sjkim# in this makefile.  
141211228Sjkim#
142211228Sjkim# In the following, the first 'rm' in a series will usually remove all
14393835Stmm# files and directories.  If it does not, then there are probably some
14493835Stmm# files with chflags set, so this unsets them and tries the 'rm' a
14593835Stmm# second time.  There are situations where this target will be cleaning
14693835Stmm# some directories via more than one method, but that duplication is
14793835Stmm# needed to correctly handle all the possible situations.
14893835Stmm#
14993835StmmBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
150188055Simpcleanworld:
15193835Stmm.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
15293835Stmm.if exists(${BW_CANONICALOBJDIR}/)
15393835Stmm	-rm -rf ${BW_CANONICALOBJDIR}/*
15493835Stmm	-chflags -R 0 ${BW_CANONICALOBJDIR}
15593835Stmm	rm -rf ${BW_CANONICALOBJDIR}/*
15693835Stmm.endif
15793835Stmm	#   To be safe in this case, fall back to a 'make cleandir'
15893835Stmm	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
159211230Sjkim.else
160162970Sphk	-rm -rf ${.OBJDIR}/*
161178429Sphk	-chflags -R 0 ${.OBJDIR}
162211228Sjkim	rm -rf ${.OBJDIR}/*
16393835Stmm.endif
16493835Stmm
16593835Stmm#
166# Handle the user-driven targets, using the source relative mk files.
167#
168
169${TGTS}:
170	${_+_}@cd ${.CURDIR}; \
171		${_MAKE} ${.TARGET}
172
173# Set a reasonable default
174.MAIN:	all
175
176STARTTIME!= LC_ALL=C date
177CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
178.if !empty(CHECK_TIME)
179.error check your date/time: ${STARTTIME}
180.endif
181
182.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
183#
184# world
185#
186# Attempt to rebuild and reinstall everything. This target is not to be
187# used for upgrading an existing FreeBSD system, because the kernel is
188# not included. One can argue that this target doesn't build everything
189# then.
190#
191world: upgrade_checks
192	@echo "--------------------------------------------------------------"
193	@echo ">>> make world started on ${STARTTIME}"
194	@echo "--------------------------------------------------------------"
195.if target(pre-world)
196	@echo
197	@echo "--------------------------------------------------------------"
198	@echo ">>> Making 'pre-world' target"
199	@echo "--------------------------------------------------------------"
200	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
201.endif
202	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
203	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
204.if target(post-world)
205	@echo
206	@echo "--------------------------------------------------------------"
207	@echo ">>> Making 'post-world' target"
208	@echo "--------------------------------------------------------------"
209	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
210.endif
211	@echo
212	@echo "--------------------------------------------------------------"
213	@echo ">>> make world completed on `LC_ALL=C date`"
214	@echo "                   (started ${STARTTIME})"
215	@echo "--------------------------------------------------------------"
216.else
217world:
218	@echo "WARNING: make world will overwrite your existing FreeBSD"
219	@echo "installation without also building and installing a new"
220	@echo "kernel.  This can be dangerous.  Please read the handbook,"
221	@echo "'Rebuilding world', for how to upgrade your system."
222	@echo "Define DESTDIR to where you want to install FreeBSD,"
223	@echo "including /, to override this warning and proceed as usual."
224	@echo ""
225	@echo "Bailing out now..."
226	@false
227.endif
228
229#
230# kernel
231#
232# Short hand for `make buildkernel installkernel'
233#
234kernel: buildkernel installkernel
235
236#
237# Perform a few tests to determine if the installed tools are adequate
238# for building the world.
239#
240upgrade_checks:
241	@if ! (cd ${.CURDIR}/tools/build/make_check && \
242	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
243	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
244	then \
245	    (cd ${.CURDIR} && ${MAKE} make); \
246	fi
247
248#
249# Upgrade make(1) to the current version using the installed
250# headers, libraries and tools.  Also, allow the location of
251# the system bsdmake-like utility to be overridden.
252#
253MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
254		DESTDIR= \
255		INSTALL="sh ${.CURDIR}/tools/install.sh"
256MMAKE=		${MMAKEENV} ${MAKE} \
257		-D_UPGRADING \
258		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
259		-DNO_CPU_CFLAGS -DNO_WERROR
260
261make: .PHONY
262	@echo
263	@echo "--------------------------------------------------------------"
264	@echo ">>> Building an up-to-date make(1)"
265	@echo "--------------------------------------------------------------"
266	${_+_}@cd ${.CURDIR}/usr.bin/make; \
267		${MMAKE} obj && \
268		${MMAKE} depend && \
269		${MMAKE} all && \
270		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
271
272tinderbox:
273	cd ${.CURDIR} && \
274		DOING_TINDERBOX=YES ${MAKE} JFLAG=${JFLAG} universe
275
276#
277# universe
278#
279# Attempt to rebuild *everything* for all supported architectures,
280# with a reasonable chance of success, regardless of how old your
281# existing system is.
282#
283.if make(universe) || make(universe_kernels) || make(tinderbox)
284TARGETS?=amd64 i386 ia64 pc98 powerpc sparc64 sun4v mips
285
286.if defined(DOING_TINDERBOX)
287FAILFILE=tinderbox.failed
288MAKEFAIL=tee -a ${FAILFILE}
289.else
290MAKEFAIL=cat
291.endif
292
293universe: universe_prologue
294universe_prologue:
295	@echo "--------------------------------------------------------------"
296	@echo ">>> make universe started on ${STARTTIME}"
297	@echo "--------------------------------------------------------------"
298.if defined(DOING_TINDERBOX)
299	rm -f ${FAILFILE}
300.endif
301.for target in ${TARGETS}
302universe: universe_${target}
303.ORDER: universe_prologue universe_${target} universe_epilogue
304universe_${target}:
305.if !defined(MAKE_JUST_KERNELS)
306	@echo ">> ${target} started on `LC_ALL=C date`"
307	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
308	    ${MAKE} ${JFLAG} buildworld \
309	    TARGET=${target} \
310	    > _.${target}.buildworld 2>&1 || \
311	    (echo "${target} world failed," \
312	    "check _.${target}.buildworld for details" | ${MAKEFAIL}))
313	@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
314.endif
315.if !defined(MAKE_JUST_WORLDS)
316.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
317	@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
318	    ${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
319	    (echo "${target} 'make LINT' failed," \
320	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
321.endif
322	@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
323	    universe_kernels
324.endif
325	@echo ">> ${target} completed on `LC_ALL=C date`"
326.endfor
327universe_kernels: universe_kernconfs
328.if !defined(TARGET)
329TARGET!=	uname -m
330.endif
331KERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
332		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
333		! -name DEFAULTS ! -name NOTES
334universe_kernconfs:
335.for kernel in ${KERNCONFS}
336	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
337	    ${MAKE} ${JFLAG} buildkernel \
338	    TARGET=${TARGET} \
339	    KERNCONF=${kernel} \
340	    > _.${TARGET}.${kernel} 2>&1 || \
341	    (echo "${TARGET} ${kernel} kernel failed," \
342	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
343.endfor
344universe: universe_epilogue
345universe_epilogue:
346	@echo "--------------------------------------------------------------"
347	@echo ">>> make universe completed on `LC_ALL=C date`"
348	@echo "                      (started ${STARTTIME})"
349	@echo "--------------------------------------------------------------"
350.if defined(DOING_TINDERBOX)
351	@if [ -e ${FAILFILE} ] ; then \
352		echo "Tinderbox failed:" ;\
353		cat ${FAILFILE} ;\
354		exit 1 ;\
355	fi
356.endif
357.endif
358