Makefile revision 136671
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 136671 2004-10-18 17:47:31Z ru $
32061Sjkh#
438666Sjb# The user-driven targets are:
532427Sjb#
6111131Sru# universe            - *Really* build *everything* (buildworld and
7111131Sru#                       all kernels on all architectures).
838666Sjb# buildworld          - Rebuild *everything*, including glue to help do
938666Sjb#                       upgrades.
1038666Sjb# installworld        - Install everything built by "buildworld".
1138666Sjb# world               - buildworld + installworld.
1264049Salex# buildkernel         - Rebuild the kernel and the kernel-modules.
1364049Salex# installkernel       - Install the kernel and the kernel-modules.
14116679Ssimokawa# installkernel.debug
1566071Smarkm# reinstallkernel     - Reinstall the kernel and the kernel-modules.
16116679Ssimokawa# reinstallkernel.debug
1773504Sobrien# kernel              - buildkernel + installkernel.
1838666Sjb# update              - Convenient way to update your source tree (cvs).
1932427Sjb#
2038666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
21108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2238666Sjb# command line. By keeping this makefile simple, it doesn't matter too
2338666Sjb# much how different the installed mk files are from those in the source
2438666Sjb# tree. This makefile executes a child make process, forcing it to use
2538666Sjb# the mk files from the source tree which are supposed to DTRT.
2617308Speter#
2791606Skeramida# The user-driven targets (as listed above) are implemented in Makefile.inc1.
2819175Sbde#
2996205Sjwd# If you want to build your system from source be sure that /usr/obj has
3096205Sjwd# at least 400MB of diskspace available.
3138042Sbde#
3296205Sjwd# For individuals wanting to build from the sources currently on their
3396205Sjwd# system, the simple instructions are:
3438042Sbde#
3596205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
3696205Sjwd# 2.  `make world'
3717308Speter#
3896205Sjwd# For individuals wanting to upgrade their sources (even if only a
3996205Sjwd# delta of a few days):
4017308Speter#
4196205Sjwd# 1.  `cd /usr/src'       (or to the directory containing your source tree).
4296205Sjwd# 2.  `make buildworld'
4396205Sjwd# 3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
4496205Sjwd# 4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
4596205Sjwd# 5.  `reboot'        (in single user mode: boot -s from the loader prompt).
4696205Sjwd# 6.  `mergemaster -p'
4796205Sjwd# 7.  `make installworld'
4896205Sjwd# 8.  `mergemaster'
4996205Sjwd# 9.  `reboot'
5096205Sjwd#
5196205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
5296205Sjwd#
5398775Sdillon# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
5498723Sdillon# cross build world for other architectures using the buildworld target,
5598723Sdillon# and once the world is built you can cross build a kernel using the
5698723Sdillon# buildkernel target.
5798723Sdillon#
5838666Sjb# Define the user-driven targets. These are listed here in alphabetical
5938666Sjb# order, but that's not important.
6017308Speter#
61123311Speter# Targets that begin with underscore are internal targets intended for
62123311Speter# developer convenience only.  They are intentionally not documented and
63123311Speter# completely subject to change without notice.
64123311Speter#
6595509SruTGTS=	all all-man buildkernel buildworld checkdpadd clean \
6695793Sru	cleandepend cleandir depend distribute distributeworld everything \
67116679Ssimokawa	hierarchy install installcheck installkernel installkernel.debug\
68120760Sru	reinstallkernel reinstallkernel.debug installworld \
69128189Sdes	kernel-toolchain libraries lint maninstall \
70127360Sru	obj objlink regress rerelease tags toolchain update \
71123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
72123311Speter	_build-tools _cross-tools _includes _libraries _depend
732061Sjkh
7497769SruBITGTS=	files includes
7597252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
76119579SruTGTS+=	${BITGTS}
7797252Sru
7895730Sru.ORDER: buildworld installworld
7995793Sru.ORDER: buildworld distributeworld
80111617Sru.ORDER: buildworld buildkernel
8195730Sru.ORDER: buildkernel installkernel
82116679Ssimokawa.ORDER: buildkernel installkernel.debug
8395730Sru.ORDER: buildkernel reinstallkernel
84116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
8595730Sru
86110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
87107516SruMAKEOBJDIRPREFIX?=	/usr/obj
88136671Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i \
89136671Sru		PATH=${PATH} MAKEFLAGS="${.MAKEFLAGS}" ${MAKE} \
90133942Sru		-f /dev/null -V MAKEOBJDIRPREFIX dummy
91133942Sru.if !empty(_MAKEOBJDIRPREFIX)
92133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
93133942Sru	(in /etc/make.conf) or command-line variable.
94133942Sru.endif
95110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
96117234SruBINMAKE= \
97110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
98117229Sru	-m ${.CURDIR}/share/mk
99117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
10054324Smarcel
10117308Speter#
102119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
103119519Smarcel# should do this as those are the initial targets used for upgrades.
104119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
105119519Smarcel# for all targets.
106119519Smarcel#
107119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
108119579Sru${TGTS}: upgrade_checks
109119519Smarcel.else
110119519Smarcelbuildworld: upgrade_checks
111119519Smarcel.endif
112119519Smarcel
113119519Smarcel#
114126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
115126024Sgad# recursive target.  All of the work for it is done right here.   It is
116126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
117126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
118126024Sgad# in this makefile.  
119126024Sgad#
120126024Sgad# In the following, the first 'rm' in a series will usually remove all
121126024Sgad# files and directories.  If it does not, then there are probably some
122126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
123126024Sgad# second time.  There are situations where this target will be cleaning
124126024Sgad# some directories via more than one method, but that duplication is
125126024Sgad# needed to correctly handle all the possible situations.
126126024Sgad#
127126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
128126031Sgadcleanworld:
129126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
130126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
131126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
132126024Sgad	chflags -R 0 ${BW_CANONICALOBJDIR}
133126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
134126024Sgad.endif
135126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
136133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
137126024Sgad.else
138126024Sgad	-rm -rf ${.OBJDIR}/*
139126024Sgad	chflags -R 0 ${.OBJDIR}
140126024Sgad	rm -rf ${.OBJDIR}/*
141126024Sgad.endif
142125885Sgad
143125885Sgad#
14438666Sjb# Handle the user-driven targets, using the source relative mk files.
14517308Speter#
146119519Smarcel
147119579Sru${TGTS}:
148133376Sharti	${_+_}@cd ${.CURDIR}; \
149110035Sru		${_MAKE} ${.TARGET}
1502302Spaul
15139206Sjkh# Set a reasonable default
15239206Sjkh.MAIN:	all
15339206Sjkh
154133945SruSTARTTIME!= LC_ALL=C date
155133945Sru
156132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
15717308Speter#
15854324Smarcel# world
15954324Smarcel#
160132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
161132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
162132234Smarcel# not included. One can argue that this target doesn't build everything
163132234Smarcel# then.
16454324Smarcel#
16554324Smarcelworld: upgrade_checks
16654324Smarcel	@echo "--------------------------------------------------------------"
167118531Sru	@echo ">>> make world started on ${STARTTIME}"
16854324Smarcel	@echo "--------------------------------------------------------------"
16954324Smarcel.if target(pre-world)
17054324Smarcel	@echo
17154324Smarcel	@echo "--------------------------------------------------------------"
17254324Smarcel	@echo ">>> Making 'pre-world' target"
17354324Smarcel	@echo "--------------------------------------------------------------"
174133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
17554324Smarcel.endif
176133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
177133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
17854324Smarcel.if target(post-world)
17954324Smarcel	@echo
18054324Smarcel	@echo "--------------------------------------------------------------"
18154324Smarcel	@echo ">>> Making 'post-world' target"
18254324Smarcel	@echo "--------------------------------------------------------------"
183133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
18454324Smarcel.endif
18554324Smarcel	@echo
18654324Smarcel	@echo "--------------------------------------------------------------"
187118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
188118531Sru	@echo "                   (started ${STARTTIME})"
18954324Smarcel	@echo "--------------------------------------------------------------"
190132234Smarcel.else
191132234Smarcelworld:
192132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
193132234Smarcel	@echo "installation without also building and installing a new"
194132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
195132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
196132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
197132234Smarcel	@echo "including /, to override this warning and proceed as usual."
198132358Smarkm	@echo "You may get the historical 'make world' behavior by defining"
199132358Smarkm	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
200132358Smarkm	@echo "before doing this."
201132358Smarkm	@echo ""
202132234Smarcel	@echo "Bailing out now..."
203132234Smarcel	@false
204132234Smarcel.endif
20554324Smarcel
20654324Smarcel#
20795730Sru# kernel
20895730Sru#
20995730Sru# Short hand for `make buildkernel installkernel'
21095730Sru#
21195730Srukernel: buildkernel installkernel
21295730Sru
21395730Sru#
21438666Sjb# Perform a few tests to determine if the installed tools are adequate
215107374Sru# for building the world.
21617308Speter#
21755678Smarcelupgrade_checks:
218110035Sru	@if ! (cd ${.CURDIR}/tools/regression/usr.bin/make && \
219117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
220110035Sru	then \
221110035Sru	    (cd ${.CURDIR} && make make); \
222110035Sru	fi
2232061Sjkh
22417308Speter#
225107516Sru# Upgrade make(1) to the current version using the installed
226107374Sru# headers, libraries and tools.
22755678Smarcel#
228107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
229107516Sru		DESTDIR= \
230107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
231107516SruMMAKE=		${MMAKEENV} make \
232107516Sru		-D_UPGRADING \
233107516Sru		-DNOMAN -DNOSHARED \
234107516Sru		-DNO_CPU_CFLAGS -DNO_WERROR
235107516Sru
236122204Skrismake: .PHONY
23755678Smarcel	@echo
23855678Smarcel	@echo "--------------------------------------------------------------"
239116696Sru	@echo ">>> Building an up-to-date make(1)"
24055678Smarcel	@echo "--------------------------------------------------------------"
241133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
242107516Sru		${MMAKE} obj && \
243107516Sru		${MMAKE} depend && \
244107516Sru		${MMAKE} all && \
245107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
24655678Smarcel
24755678Smarcel#
248111131Sru# universe
249111131Sru#
250111131Sru# Attempt to rebuild *everything* for all supported architectures,
251133945Sru# with a reasonable chance of success, regardless of how old your
252111131Sru# existing system is.
253111131Sru#
254133945Sruuniverse: universe_prologue
255133945Sruuniverse_prologue:
256103985Sphk	@echo "--------------------------------------------------------------"
257103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
258103985Sphk	@echo "--------------------------------------------------------------"
259133945Sru.for target in i386 i386:pc98 sparc64 alpha ia64 amd64
260133945Sru.for arch in ${target:C/:.*$//}
261133945Sru.for mach in ${target:C/^.*://}
262133945Sruuniverse: universe_${mach}
263133945Sru.ORDER: universe_prologue universe_${mach} universe_epilogue
264133945Sruuniverse_${mach}:
265111131Sru	@echo ">> ${mach} started on `LC_ALL=C date`"
266131876Sphk	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
267111131Sru	    TARGET_ARCH=${arch} TARGET=${mach} \
268111131Sru	    __MAKE_CONF=/dev/null \
269111131Sru	    > _.${mach}.buildworld 2>&1
270111131Sru	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
271111131Sru.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
272111131Sru	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
273111133Sru	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
274103985Sphk.endif
275133945Sru	cd ${.CURDIR} && ${MAKE} buildkernels TARGET_ARCH=${arch} TARGET=${mach}
276111131Sru	@echo ">> ${mach} completed on `LC_ALL=C date`"
277103985Sphk.endfor
278111131Sru.endfor
279133945Sru.endfor
280133945Sruuniverse: universe_epilogue
281133945Sruuniverse_epilogue:
282103985Sphk	@echo "--------------------------------------------------------------"
283118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
284118531Sru	@echo "                      (started ${STARTTIME})"
285103985Sphk	@echo "--------------------------------------------------------------"
286103985Sphk
287126485Sru.if make(buildkernels)
288111131SruKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
289111131Sru		find [A-Z]*[A-Z] -type f -maxdepth 0 ! -name NOTES
290103985Sphkbuildkernels:
291111131Sru.for kernel in ${KERNCONFS}
292131876Sphk	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
293111131Sru	    KERNCONF=${kernel} \
294111131Sru	    __MAKE_CONF=/dev/null \
295111131Sru	    > _.${TARGET}.${kernel} 2>&1
296103985Sphk.endfor
297133945Sru.endif
298