Makefile revision 159363
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 159363 2006-06-07 03:33:48Z trhodes $
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".
11159363Strhodes# world               - buildworld + installworld, no kernel.
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.
18158962Snetchild# doxygen             - Build API documentation of the kernel, needs doxygen.
1938666Sjb# update              - Convenient way to update your source tree (cvs).
20148330Snetchild# check-old           - Print a list of old files/directories in the system.
21148330Snetchild# delete-old          - Delete obsolete files and directories interactively.
22148330Snetchild# delete-old-libs     - Delete obsolete libraries interactively.
2332427Sjb#
2438666Sjb# This makefile is simple by design. The FreeBSD make automatically reads
25108451Sschweikh# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2638666Sjb# command line. By keeping this makefile simple, it doesn't matter too
2738666Sjb# much how different the installed mk files are from those in the source
2838666Sjb# tree. This makefile executes a child make process, forcing it to use
2938666Sjb# the mk files from the source tree which are supposed to DTRT.
3017308Speter#
3191606Skeramida# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3219175Sbde#
3396205Sjwd# If you want to build your system from source be sure that /usr/obj has
3496205Sjwd# at least 400MB of diskspace available.
3538042Sbde#
3696205Sjwd# For individuals wanting to build from the sources currently on their
3796205Sjwd# system, the simple instructions are:
3838042Sbde#
3996205Sjwd# 1.  `cd /usr/src'  (or to the directory containing your source tree).
40159363Strhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
41159363Strhodes# 3.  `make world'
4217308Speter#
4396205Sjwd# For individuals wanting to upgrade their sources (even if only a
4496205Sjwd# delta of a few days):
4517308Speter#
46148330Snetchild#  1.  `cd /usr/src'       (or to the directory containing your source tree).
47148330Snetchild#  2.  `make buildworld'
48148330Snetchild#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
49148330Snetchild#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
50148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
51148330Snetchild#  6.  `mergemaster -p'
52148330Snetchild#  7.  `make installworld'
53148330Snetchild#  8.  `make delete-old'
54148330Snetchild#  9.  `mergemaster'
55148330Snetchild# 10.  `reboot'
56148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
5796205Sjwd#
5896205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
5996205Sjwd#
6098775Sdillon# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
6198723Sdillon# cross build world for other architectures using the buildworld target,
6298723Sdillon# and once the world is built you can cross build a kernel using the
6398723Sdillon# buildkernel target.
6498723Sdillon#
6538666Sjb# Define the user-driven targets. These are listed here in alphabetical
6638666Sjb# order, but that's not important.
6717308Speter#
68123311Speter# Targets that begin with underscore are internal targets intended for
69123311Speter# developer convenience only.  They are intentionally not documented and
70123311Speter# completely subject to change without notice.
71123311Speter#
72159349SimpTGTS=	all all-man buildenv buildenvvars buildkernel buildworld check-old \
73159349Simp	checkdpadd clean cleandepend cleandir delete-old delete-old-libs \
74159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
75158962Snetchild	everything hierarchy install installcheck installkernel \
76158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
77158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
78156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
79123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
80137288Speter	_build-tools _cross-tools _includes _libraries _depend \
81147425Sru	build32 distribute32 install32
82156740SruTGTS+=	${SUBDIR_TARGETS}
832061Sjkh
8497769SruBITGTS=	files includes
8597252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
86119579SruTGTS+=	${BITGTS}
8797252Sru
8895730Sru.ORDER: buildworld installworld
8995793Sru.ORDER: buildworld distributeworld
90111617Sru.ORDER: buildworld buildkernel
9195730Sru.ORDER: buildkernel installkernel
92116679Ssimokawa.ORDER: buildkernel installkernel.debug
9395730Sru.ORDER: buildkernel reinstallkernel
94116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
9595730Sru
96110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
97107516SruMAKEOBJDIRPREFIX?=	/usr/obj
98138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
99156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
100138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
101133942Sru.if !empty(_MAKEOBJDIRPREFIX)
102133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
103156145Syar	(in make.conf(5)) or command-line variable.
104133942Sru.endif
105110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
106117234SruBINMAKE= \
107110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
108117229Sru	-m ${.CURDIR}/share/mk
109117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
11054324Smarcel
11117308Speter#
112119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
113119519Smarcel# should do this as those are the initial targets used for upgrades.
114119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
115119519Smarcel# for all targets.
116119519Smarcel#
117119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
118119579Sru${TGTS}: upgrade_checks
119119519Smarcel.else
120119519Smarcelbuildworld: upgrade_checks
121119519Smarcel.endif
122119519Smarcel
123119519Smarcel#
124126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
125126024Sgad# recursive target.  All of the work for it is done right here.   It is
126126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
127126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
128126024Sgad# in this makefile.  
129126024Sgad#
130126024Sgad# In the following, the first 'rm' in a series will usually remove all
131126024Sgad# files and directories.  If it does not, then there are probably some
132126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
133126024Sgad# second time.  There are situations where this target will be cleaning
134126024Sgad# some directories via more than one method, but that duplication is
135126024Sgad# needed to correctly handle all the possible situations.
136126024Sgad#
137126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
138126031Sgadcleanworld:
139126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
140126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
141126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
142126024Sgad	chflags -R 0 ${BW_CANONICALOBJDIR}
143126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
144126024Sgad.endif
145126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
146133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
147126024Sgad.else
148126024Sgad	-rm -rf ${.OBJDIR}/*
149126024Sgad	chflags -R 0 ${.OBJDIR}
150126024Sgad	rm -rf ${.OBJDIR}/*
151126024Sgad.endif
152125885Sgad
153125885Sgad#
15438666Sjb# Handle the user-driven targets, using the source relative mk files.
15517308Speter#
156119519Smarcel
157119579Sru${TGTS}:
158133376Sharti	${_+_}@cd ${.CURDIR}; \
159110035Sru		${_MAKE} ${.TARGET}
1602302Spaul
16139206Sjkh# Set a reasonable default
16239206Sjkh.MAIN:	all
16339206Sjkh
164133945SruSTARTTIME!= LC_ALL=C date
165133945Sru
166132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
16717308Speter#
16854324Smarcel# world
16954324Smarcel#
170132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
171132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
172132234Smarcel# not included. One can argue that this target doesn't build everything
173132234Smarcel# then.
17454324Smarcel#
17554324Smarcelworld: upgrade_checks
17654324Smarcel	@echo "--------------------------------------------------------------"
177118531Sru	@echo ">>> make world started on ${STARTTIME}"
17854324Smarcel	@echo "--------------------------------------------------------------"
17954324Smarcel.if target(pre-world)
18054324Smarcel	@echo
18154324Smarcel	@echo "--------------------------------------------------------------"
18254324Smarcel	@echo ">>> Making 'pre-world' target"
18354324Smarcel	@echo "--------------------------------------------------------------"
184133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
18554324Smarcel.endif
186133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
187133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
18854324Smarcel.if target(post-world)
18954324Smarcel	@echo
19054324Smarcel	@echo "--------------------------------------------------------------"
19154324Smarcel	@echo ">>> Making 'post-world' target"
19254324Smarcel	@echo "--------------------------------------------------------------"
193133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
19454324Smarcel.endif
19554324Smarcel	@echo
19654324Smarcel	@echo "--------------------------------------------------------------"
197118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
198118531Sru	@echo "                   (started ${STARTTIME})"
19954324Smarcel	@echo "--------------------------------------------------------------"
200132234Smarcel.else
201132234Smarcelworld:
202132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
203132234Smarcel	@echo "installation without also building and installing a new"
204132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
205132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
206132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
207132234Smarcel	@echo "including /, to override this warning and proceed as usual."
208132358Smarkm	@echo "You may get the historical 'make world' behavior by defining"
209132358Smarkm	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
210132358Smarkm	@echo "before doing this."
211132358Smarkm	@echo ""
212132234Smarcel	@echo "Bailing out now..."
213132234Smarcel	@false
214132234Smarcel.endif
21554324Smarcel
21654324Smarcel#
21795730Sru# kernel
21895730Sru#
21995730Sru# Short hand for `make buildkernel installkernel'
22095730Sru#
22195730Srukernel: buildkernel installkernel
22295730Sru
22395730Sru#
22438666Sjb# Perform a few tests to determine if the installed tools are adequate
225107374Sru# for building the world.
22617308Speter#
22755678Smarcelupgrade_checks:
228143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
229138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
230117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
231110035Sru	then \
232110035Sru	    (cd ${.CURDIR} && make make); \
233110035Sru	fi
2342061Sjkh
23517308Speter#
236107516Sru# Upgrade make(1) to the current version using the installed
237107374Sru# headers, libraries and tools.
23855678Smarcel#
239107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
240107516Sru		DESTDIR= \
241107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
242107516SruMMAKE=		${MMAKEENV} make \
243107516Sru		-D_UPGRADING \
244139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
245107516Sru		-DNO_CPU_CFLAGS -DNO_WERROR
246107516Sru
247122204Skrismake: .PHONY
24855678Smarcel	@echo
24955678Smarcel	@echo "--------------------------------------------------------------"
250116696Sru	@echo ">>> Building an up-to-date make(1)"
25155678Smarcel	@echo "--------------------------------------------------------------"
252133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
253107516Sru		${MMAKE} obj && \
254107516Sru		${MMAKE} depend && \
255107516Sru		${MMAKE} all && \
256107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
25755678Smarcel
25855678Smarcel#
259111131Sru# universe
260111131Sru#
261111131Sru# Attempt to rebuild *everything* for all supported architectures,
262133945Sru# with a reasonable chance of success, regardless of how old your
263111131Sru# existing system is.
264111131Sru#
265148154Sru.if make(universe)
266133945Sruuniverse: universe_prologue
267133945Sruuniverse_prologue:
268103985Sphk	@echo "--------------------------------------------------------------"
269103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
270103985Sphk	@echo "--------------------------------------------------------------"
271158453Sjhb.for target in i386 i386:pc98 sparc64 ia64 amd64
272133945Sru.for arch in ${target:C/:.*$//}
273133945Sru.for mach in ${target:C/^.*://}
274148154SruKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
275152879Sru		find [A-Z]*[A-Z] -type f -maxdepth 0 \
276152880Sru		! -name DEFAULTS ! -name LINT
277148154SruKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
278133945Sruuniverse: universe_${mach}
279133945Sru.ORDER: universe_prologue universe_${mach} universe_epilogue
280133945Sruuniverse_${mach}:
281111131Sru	@echo ">> ${mach} started on `LC_ALL=C date`"
282131876Sphk	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
283111131Sru	    TARGET_ARCH=${arch} TARGET=${mach} \
284111131Sru	    __MAKE_CONF=/dev/null \
285111131Sru	    > _.${mach}.buildworld 2>&1
286111131Sru	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
287111131Sru.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
288111131Sru	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
289111133Sru	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
290103985Sphk.endif
291148154Sru.for kernel in ${KERNCONFS}
292148154Sru	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
293148154Sru	    TARGET_ARCH=${arch} TARGET=${mach} \
294148154Sru	    KERNCONF=${kernel} \
295148154Sru	    __MAKE_CONF=/dev/null \
296148154Sru	    > _.${mach}.${kernel} 2>&1
297148154Sru.endfor
298111131Sru	@echo ">> ${mach} completed on `LC_ALL=C date`"
299103985Sphk.endfor
300111131Sru.endfor
301133945Sru.endfor
302133945Sruuniverse: universe_epilogue
303133945Sruuniverse_epilogue:
304103985Sphk	@echo "--------------------------------------------------------------"
305118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
306118531Sru	@echo "                      (started ${STARTTIME})"
307103985Sphk	@echo "--------------------------------------------------------------"
308133945Sru.endif
309