Makefile revision 156145
133965Sjdp#
2218822Sdim# $FreeBSD: head/Makefile 156145 2006-03-01 13:07:17Z yar $
3218822Sdim#
433965Sjdp# The user-driven targets are:
533965Sjdp#
633965Sjdp# universe            - *Really* build *everything* (buildworld and
733965Sjdp#                       all kernels on all architectures).
833965Sjdp# buildworld          - Rebuild *everything*, including glue to help do
933965Sjdp#                       upgrades.
1033965Sjdp# installworld        - Install everything built by "buildworld".
1133965Sjdp# world               - buildworld + installworld.
1233965Sjdp# buildkernel         - Rebuild the kernel and the kernel-modules.
1333965Sjdp# installkernel       - Install the kernel and the kernel-modules.
1433965Sjdp# installkernel.debug
1533965Sjdp# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1633965Sjdp# reinstallkernel.debug
1733965Sjdp# kernel              - buildkernel + installkernel.
1833965Sjdp# update              - Convenient way to update your source tree (cvs).
19218822Sdim# check-old           - Print a list of old files/directories in the system.
20218822Sdim# delete-old          - Delete obsolete files and directories interactively.
2133965Sjdp# delete-old-libs     - Delete obsolete libraries interactively.
2233965Sjdp#
2333965Sjdp# This makefile is simple by design. The FreeBSD make automatically reads
2433965Sjdp# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2533965Sjdp# command line. By keeping this makefile simple, it doesn't matter too
2633965Sjdp# much how different the installed mk files are from those in the source
2733965Sjdp# tree. This makefile executes a child make process, forcing it to use
2833965Sjdp# the mk files from the source tree which are supposed to DTRT.
29218822Sdim#
30104834Sobrien# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3133965Sjdp#
3233965Sjdp# If you want to build your system from source be sure that /usr/obj has
3333965Sjdp# at least 400MB of diskspace available.
34104834Sobrien#
35104834Sobrien# For individuals wanting to build from the sources currently on their
3633965Sjdp# system, the simple instructions are:
3733965Sjdp#
3833965Sjdp# 1.  `cd /usr/src'  (or to the directory containing your source tree).
3933965Sjdp# 2.  `make world'
4033965Sjdp#
4133965Sjdp# For individuals wanting to upgrade their sources (even if only a
4238889Sjdp# delta of a few days):
4338889Sjdp#
4438889Sjdp#  1.  `cd /usr/src'       (or to the directory containing your source tree).
4538889Sjdp#  2.  `make buildworld'
46130561Sobrien#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
47130561Sobrien#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
48130561Sobrien#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
49130561Sobrien#  6.  `mergemaster -p'
50218822Sdim#  7.  `make installworld'
51218822Sdim#  8.  `make delete-old'
52218822Sdim#  9.  `mergemaster'
53218822Sdim# 10.  `reboot'
54218822Sdim# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
55130561Sobrien#
56130561Sobrien# See src/UPDATING `COMMON ITEMS' for more complete information.
57130561Sobrien#
58130561Sobrien# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
59130561Sobrien# cross build world for other architectures using the buildworld target,
60130561Sobrien# and once the world is built you can cross build a kernel using the
61130561Sobrien# buildkernel target.
6289857Sobrien#
63130561Sobrien# Define the user-driven targets. These are listed here in alphabetical
64130561Sobrien# order, but that's not important.
65130561Sobrien#
6689857Sobrien# Targets that begin with underscore are internal targets intended for
67130561Sobrien# developer convenience only.  They are intentionally not documented and
6889857Sobrien# completely subject to change without notice.
69130561Sobrien#
7089857SobrienTGTS=	all all-man buildenv buildkernel buildworld check-old checkdpadd \
71130561Sobrien	clean cleandepend cleandir delete-old delete-old-libs depend \
7289857Sobrien	distribute distributeworld distrib-dirs distribution everything \
73130561Sobrien	hierarchy install installcheck installkernel installkernel.debug\
74130561Sobrien	reinstallkernel reinstallkernel.debug installworld \
75130561Sobrien	kernel-toolchain libraries lint maninstall \
76130561Sobrien	obj objlink regress rerelease tags toolchain update \
77130561Sobrien	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
78130561Sobrien	_build-tools _cross-tools _includes _libraries _depend \
79130561Sobrien	build32 distribute32 install32
80130561Sobrien
81130561SobrienBITGTS=	files includes
82130561SobrienBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
83130561SobrienTGTS+=	${BITGTS}
84130561Sobrien
85130561Sobrien.ORDER: buildworld installworld
86130561Sobrien.ORDER: buildworld distributeworld
87130561Sobrien.ORDER: buildworld buildkernel
88130561Sobrien.ORDER: buildkernel installkernel
89130561Sobrien.ORDER: buildkernel installkernel.debug
90130561Sobrien.ORDER: buildkernel reinstallkernel
91130561Sobrien.ORDER: buildkernel reinstallkernel.debug
9233965Sjdp
9333965SjdpPATH=	/sbin:/bin:/usr/sbin:/usr/bin
9433965SjdpMAKEOBJDIRPREFIX?=	/usr/obj
9533965Sjdp_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
9633965Sjdp    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
9733965Sjdp    -f /dev/null -V MAKEOBJDIRPREFIX dummy
9833965Sjdp.if !empty(_MAKEOBJDIRPREFIX)
99104834Sobrien.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
10033965Sjdp	(in make.conf(5)) or command-line variable.
10133965Sjdp.endif
10233965SjdpMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
10333965SjdpBINMAKE= \
10433965Sjdp	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
10533965Sjdp	-m ${.CURDIR}/share/mk
10633965Sjdp_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
10733965Sjdp
10833965Sjdp#
10933965Sjdp# Make sure we have an up-to-date make(1). Only world and buildworld
11033965Sjdp# should do this as those are the initial targets used for upgrades.
11133965Sjdp# The user can define ALWAYS_CHECK_MAKE to have this check performed
11233965Sjdp# for all targets.
113130561Sobrien#
11433965Sjdp.if defined(ALWAYS_CHECK_MAKE)
11533965Sjdp${TGTS}: upgrade_checks
11689857Sobrien.else
11789857Sobrienbuildworld: upgrade_checks
11833965Sjdp.endif
11933965Sjdp
12033965Sjdp#
12133965Sjdp# This 'cleanworld' target is not included in TGTS, because it is not a
12233965Sjdp# recursive target.  All of the work for it is done right here.   It is
123130561Sobrien# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
12433965Sjdp# created by bsd.obj.mk, except that we don't want to .include that file
12533965Sjdp# in this makefile.  
12689857Sobrien#
12789857Sobrien# In the following, the first 'rm' in a series will usually remove all
12833965Sjdp# files and directories.  If it does not, then there are probably some
12933965Sjdp# files with chflags set, so this unsets them and tries the 'rm' a
13033965Sjdp# second time.  There are situations where this target will be cleaning
13133965Sjdp# some directories via more than one method, but that duplication is
132130561Sobrien# needed to correctly handle all the possible situations.
13333965Sjdp#
13433965SjdpBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
13533965Sjdpcleanworld:
13633965Sjdp.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
13733965Sjdp.if exists(${BW_CANONICALOBJDIR}/)
13833965Sjdp	-rm -rf ${BW_CANONICALOBJDIR}/*
13933965Sjdp	chflags -R 0 ${BW_CANONICALOBJDIR}
14033965Sjdp	rm -rf ${BW_CANONICALOBJDIR}/*
14133965Sjdp.endif
14233965Sjdp	#   To be safe in this case, fall back to a 'make cleandir'
14333965Sjdp	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
14433965Sjdp.else
14533965Sjdp	-rm -rf ${.OBJDIR}/*
14633965Sjdp	chflags -R 0 ${.OBJDIR}
147130561Sobrien	rm -rf ${.OBJDIR}/*
14833965Sjdp.endif
14933965Sjdp
15033965Sjdp#
15189857Sobrien# Handle the user-driven targets, using the source relative mk files.
15233965Sjdp#
15333965Sjdp
15433965Sjdp${TGTS}:
15533965Sjdp	${_+_}@cd ${.CURDIR}; \
15633965Sjdp		${_MAKE} ${.TARGET}
15733965Sjdp
15833965Sjdp# Set a reasonable default
15933965Sjdp.MAIN:	all
16033965Sjdp
16133965SjdpSTARTTIME!= LC_ALL=C date
162218822Sdim
16333965Sjdp.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
16433965Sjdp#
16533965Sjdp# world
16633965Sjdp#
16733965Sjdp# Attempt to rebuild and reinstall everything. This target is not to be
16889857Sobrien# used for upgrading an existing FreeBSD system, because the kernel is
16933965Sjdp# not included. One can argue that this target doesn't build everything
17033965Sjdp# then.
17133965Sjdp#
17233965Sjdpworld: upgrade_checks
17333965Sjdp	@echo "--------------------------------------------------------------"
17433965Sjdp	@echo ">>> make world started on ${STARTTIME}"
17533965Sjdp	@echo "--------------------------------------------------------------"
17689857Sobrien.if target(pre-world)
17789857Sobrien	@echo
17889857Sobrien	@echo "--------------------------------------------------------------"
17933965Sjdp	@echo ">>> Making 'pre-world' target"
18033965Sjdp	@echo "--------------------------------------------------------------"
18133965Sjdp	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
18233965Sjdp.endif
18333965Sjdp	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
18433965Sjdp	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
185218822Sdim.if target(post-world)
18633965Sjdp	@echo
18733965Sjdp	@echo "--------------------------------------------------------------"
18833965Sjdp	@echo ">>> Making 'post-world' target"
18933965Sjdp	@echo "--------------------------------------------------------------"
19038889Sjdp	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
19133965Sjdp.endif
19233965Sjdp	@echo
19333965Sjdp	@echo "--------------------------------------------------------------"
19433965Sjdp	@echo ">>> make world completed on `LC_ALL=C date`"
19533965Sjdp	@echo "                   (started ${STARTTIME})"
19689857Sobrien	@echo "--------------------------------------------------------------"
19733965Sjdp.else
19833965Sjdpworld:
19933965Sjdp	@echo "WARNING: make world will overwrite your existing FreeBSD"
20033965Sjdp	@echo "installation without also building and installing a new"
20189857Sobrien	@echo "kernel.  This can be dangerous.  Please read the handbook,"
20233965Sjdp	@echo "'Rebuilding world', for how to upgrade your system."
20333965Sjdp	@echo "Define DESTDIR to where you want to install FreeBSD,"
20433965Sjdp	@echo "including /, to override this warning and proceed as usual."
20533965Sjdp	@echo "You may get the historical 'make world' behavior by defining"
20633965Sjdp	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
20733965Sjdp	@echo "before doing this."
20833965Sjdp	@echo ""
20933965Sjdp	@echo "Bailing out now..."
21033965Sjdp	@false
21133965Sjdp.endif
21233965Sjdp
21333965Sjdp#
21433965Sjdp# kernel
21533965Sjdp#
21633965Sjdp# Short hand for `make buildkernel installkernel'
21733965Sjdp#
21833965Sjdpkernel: buildkernel installkernel
21933965Sjdp
22033965Sjdp#
22133965Sjdp# Perform a few tests to determine if the installed tools are adequate
22233965Sjdp# for building the world.
22333965Sjdp#
22433965Sjdpupgrade_checks:
22533965Sjdp	@if ! (cd ${.CURDIR}/tools/build/make_check && \
226218822Sdim	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
22733965Sjdp	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
22833965Sjdp	then \
22933965Sjdp	    (cd ${.CURDIR} && make make); \
23033965Sjdp	fi
23189857Sobrien
23233965Sjdp#
23333965Sjdp# Upgrade make(1) to the current version using the installed
23433965Sjdp# headers, libraries and tools.
23589857Sobrien#
23633965SjdpMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
23789857Sobrien		DESTDIR= \
23833965Sjdp		INSTALL="sh ${.CURDIR}/tools/install.sh"
23933965SjdpMMAKE=		${MMAKEENV} make \
24033965Sjdp		-D_UPGRADING \
24133965Sjdp		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
24233965Sjdp		-DNO_CPU_CFLAGS -DNO_WERROR
243218822Sdim
244218822Sdimmake: .PHONY
24533965Sjdp	@echo
24633965Sjdp	@echo "--------------------------------------------------------------"
24789857Sobrien	@echo ">>> Building an up-to-date make(1)"
24833965Sjdp	@echo "--------------------------------------------------------------"
24933965Sjdp	${_+_}@cd ${.CURDIR}/usr.bin/make; \
25089857Sobrien		${MMAKE} obj && \
25133965Sjdp		${MMAKE} depend && \
25233965Sjdp		${MMAKE} all && \
25333965Sjdp		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
254218822Sdim
25533965Sjdp#
25633965Sjdp# universe
25733965Sjdp#
25833965Sjdp# Attempt to rebuild *everything* for all supported architectures,
25933965Sjdp# with a reasonable chance of success, regardless of how old your
26089857Sobrien# existing system is.
26133965Sjdp#
26233965Sjdp.if make(universe)
26333965Sjdpuniverse: universe_prologue
26433965Sjdpuniverse_prologue:
26533965Sjdp	@echo "--------------------------------------------------------------"
26633965Sjdp	@echo ">>> make universe started on ${STARTTIME}"
26733965Sjdp	@echo "--------------------------------------------------------------"
26889857Sobrien.for target in i386 i386:pc98 sparc64 alpha ia64 amd64
26933965Sjdp.for arch in ${target:C/:.*$//}
27033965Sjdp.for mach in ${target:C/^.*://}
27133965SjdpKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
27233965Sjdp		find [A-Z]*[A-Z] -type f -maxdepth 0 \
27389857Sobrien		! -name DEFAULTS ! -name LINT
27433965SjdpKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
27533965Sjdpuniverse: universe_${mach}
27633965Sjdp.ORDER: universe_prologue universe_${mach} universe_epilogue
27733965Sjdpuniverse_${mach}:
27833965Sjdp	@echo ">> ${mach} started on `LC_ALL=C date`"
27933965Sjdp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
28033965Sjdp	    TARGET_ARCH=${arch} TARGET=${mach} \
28133965Sjdp	    __MAKE_CONF=/dev/null \
28233965Sjdp	    > _.${mach}.buildworld 2>&1
28333965Sjdp	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
28433965Sjdp.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
28533965Sjdp	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
28633965Sjdp	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
28733965Sjdp.endif
28833965Sjdp.for kernel in ${KERNCONFS}
28933965Sjdp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
29033965Sjdp	    TARGET_ARCH=${arch} TARGET=${mach} \
29133965Sjdp	    KERNCONF=${kernel} \
29233965Sjdp	    __MAKE_CONF=/dev/null \
293130561Sobrien	    > _.${mach}.${kernel} 2>&1
29433965Sjdp.endfor
29589857Sobrien	@echo ">> ${mach} completed on `LC_ALL=C date`"
29633965Sjdp.endfor
29789857Sobrien.endfor
29889857Sobrien.endfor
29989857Sobrienuniverse: universe_epilogue
30089857Sobrienuniverse_epilogue:
30189857Sobrien	@echo "--------------------------------------------------------------"
30289857Sobrien	@echo ">>> make universe completed on `LC_ALL=C date`"
30333965Sjdp	@echo "                      (started ${STARTTIME})"
30433965Sjdp	@echo "--------------------------------------------------------------"
30533965Sjdp.endif
30633965Sjdp