Makefile revision 168280
12061Sjkh#
250479Speter# $FreeBSD: head/Makefile 168280 2007-04-02 21:32:44Z marcel $
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).
50159831Sobrien#       [steps 3. & 4. can be combined by using the "kernel" target]
51148330Snetchild#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
52148330Snetchild#  6.  `mergemaster -p'
53148330Snetchild#  7.  `make installworld'
54148330Snetchild#  8.  `make delete-old'
55148330Snetchild#  9.  `mergemaster'
56148330Snetchild# 10.  `reboot'
57148330Snetchild# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
5896205Sjwd#
5996205Sjwd# See src/UPDATING `COMMON ITEMS' for more complete information.
6096205Sjwd#
61162147Sru# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
62162147Sru# cross build world for other machine types using the buildworld target,
6398723Sdillon# and once the world is built you can cross build a kernel using the
6498723Sdillon# buildkernel target.
6598723Sdillon#
6638666Sjb# Define the user-driven targets. These are listed here in alphabetical
6738666Sjb# order, but that's not important.
6817308Speter#
69123311Speter# Targets that begin with underscore are internal targets intended for
70123311Speter# developer convenience only.  They are intentionally not documented and
71123311Speter# completely subject to change without notice.
72123311Speter#
73159349SimpTGTS=	all all-man buildenv buildenvvars buildkernel buildworld check-old \
74159349Simp	checkdpadd clean cleandepend cleandir delete-old delete-old-libs \
75159349Simp	depend distribute distributeworld distrib-dirs distribution doxygen \
76158962Snetchild	everything hierarchy install installcheck installkernel \
77158962Snetchild	installkernel.debug reinstallkernel reinstallkernel.debug \
78158962Snetchild	installworld kernel-toolchain libraries lint maninstall \
79156840Sru	obj objlink regress rerelease showconfig tags toolchain update \
80123311Speter	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
81137288Speter	_build-tools _cross-tools _includes _libraries _depend \
82147425Sru	build32 distribute32 install32
83156740SruTGTS+=	${SUBDIR_TARGETS}
842061Sjkh
8597769SruBITGTS=	files includes
8697252SruBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
87119579SruTGTS+=	${BITGTS}
8897252Sru
8995730Sru.ORDER: buildworld installworld
9095793Sru.ORDER: buildworld distributeworld
91111617Sru.ORDER: buildworld buildkernel
9295730Sru.ORDER: buildkernel installkernel
93116679Ssimokawa.ORDER: buildkernel installkernel.debug
9495730Sru.ORDER: buildkernel reinstallkernel
95116679Ssimokawa.ORDER: buildkernel reinstallkernel.debug
9695730Sru
97110035SruPATH=	/sbin:/bin:/usr/sbin:/usr/bin
98107516SruMAKEOBJDIRPREFIX?=	/usr/obj
99138921Sru_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
100156145Syar    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
101138921Sru    -f /dev/null -V MAKEOBJDIRPREFIX dummy
102133942Sru.if !empty(_MAKEOBJDIRPREFIX)
103133942Sru.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
104156145Syar	(in make.conf(5)) or command-line variable.
105133942Sru.endif
106110035SruMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
107117234SruBINMAKE= \
108110035Sru	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
109117229Sru	-m ${.CURDIR}/share/mk
110117234Sru_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
11154324Smarcel
11217308Speter#
113119519Smarcel# Make sure we have an up-to-date make(1). Only world and buildworld
114119519Smarcel# should do this as those are the initial targets used for upgrades.
115119519Smarcel# The user can define ALWAYS_CHECK_MAKE to have this check performed
116119519Smarcel# for all targets.
117119519Smarcel#
118119519Smarcel.if defined(ALWAYS_CHECK_MAKE)
119119579Sru${TGTS}: upgrade_checks
120119519Smarcel.else
121119519Smarcelbuildworld: upgrade_checks
122119519Smarcel.endif
123119519Smarcel
124119519Smarcel#
125126031Sgad# This 'cleanworld' target is not included in TGTS, because it is not a
126126024Sgad# recursive target.  All of the work for it is done right here.   It is
127126024Sgad# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
128126024Sgad# created by bsd.obj.mk, except that we don't want to .include that file
129126024Sgad# in this makefile.  
130126024Sgad#
131126024Sgad# In the following, the first 'rm' in a series will usually remove all
132126024Sgad# files and directories.  If it does not, then there are probably some
133126024Sgad# files with chflags set, so this unsets them and tries the 'rm' a
134126024Sgad# second time.  There are situations where this target will be cleaning
135126024Sgad# some directories via more than one method, but that duplication is
136126024Sgad# needed to correctly handle all the possible situations.
137126024Sgad#
138126024SgadBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
139126031Sgadcleanworld:
140126024Sgad.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
141126024Sgad.if exists(${BW_CANONICALOBJDIR}/)
142126024Sgad	-rm -rf ${BW_CANONICALOBJDIR}/*
143126024Sgad	chflags -R 0 ${BW_CANONICALOBJDIR}
144126024Sgad	rm -rf ${BW_CANONICALOBJDIR}/*
145126024Sgad.endif
146126024Sgad	#   To be safe in this case, fall back to a 'make cleandir'
147133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
148126024Sgad.else
149126024Sgad	-rm -rf ${.OBJDIR}/*
150126024Sgad	chflags -R 0 ${.OBJDIR}
151126024Sgad	rm -rf ${.OBJDIR}/*
152126024Sgad.endif
153125885Sgad
154125885Sgad#
15538666Sjb# Handle the user-driven targets, using the source relative mk files.
15617308Speter#
157119519Smarcel
158119579Sru${TGTS}:
159133376Sharti	${_+_}@cd ${.CURDIR}; \
160110035Sru		${_MAKE} ${.TARGET}
1612302Spaul
16239206Sjkh# Set a reasonable default
16339206Sjkh.MAIN:	all
16439206Sjkh
165133945SruSTARTTIME!= LC_ALL=C date
166133945Sru
167132358Smarkm.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
16817308Speter#
16954324Smarcel# world
17054324Smarcel#
171132234Smarcel# Attempt to rebuild and reinstall everything. This target is not to be
172132234Smarcel# used for upgrading an existing FreeBSD system, because the kernel is
173132234Smarcel# not included. One can argue that this target doesn't build everything
174132234Smarcel# then.
17554324Smarcel#
17654324Smarcelworld: upgrade_checks
17754324Smarcel	@echo "--------------------------------------------------------------"
178118531Sru	@echo ">>> make world started on ${STARTTIME}"
17954324Smarcel	@echo "--------------------------------------------------------------"
18054324Smarcel.if target(pre-world)
18154324Smarcel	@echo
18254324Smarcel	@echo "--------------------------------------------------------------"
18354324Smarcel	@echo ">>> Making 'pre-world' target"
18454324Smarcel	@echo "--------------------------------------------------------------"
185133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
18654324Smarcel.endif
187133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
188133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
18954324Smarcel.if target(post-world)
19054324Smarcel	@echo
19154324Smarcel	@echo "--------------------------------------------------------------"
19254324Smarcel	@echo ">>> Making 'post-world' target"
19354324Smarcel	@echo "--------------------------------------------------------------"
194133376Sharti	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
19554324Smarcel.endif
19654324Smarcel	@echo
19754324Smarcel	@echo "--------------------------------------------------------------"
198118531Sru	@echo ">>> make world completed on `LC_ALL=C date`"
199118531Sru	@echo "                   (started ${STARTTIME})"
20054324Smarcel	@echo "--------------------------------------------------------------"
201132234Smarcel.else
202132234Smarcelworld:
203132234Smarcel	@echo "WARNING: make world will overwrite your existing FreeBSD"
204132234Smarcel	@echo "installation without also building and installing a new"
205132234Smarcel	@echo "kernel.  This can be dangerous.  Please read the handbook,"
206132588Skensmith	@echo "'Rebuilding world', for how to upgrade your system."
207132358Smarkm	@echo "Define DESTDIR to where you want to install FreeBSD,"
208132234Smarcel	@echo "including /, to override this warning and proceed as usual."
209132358Smarkm	@echo ""
210132234Smarcel	@echo "Bailing out now..."
211132234Smarcel	@false
212132234Smarcel.endif
21354324Smarcel
21454324Smarcel#
21595730Sru# kernel
21695730Sru#
21795730Sru# Short hand for `make buildkernel installkernel'
21895730Sru#
21995730Srukernel: buildkernel installkernel
22095730Sru
22195730Sru#
22238666Sjb# Perform a few tests to determine if the installed tools are adequate
223107374Sru# for building the world.
22417308Speter#
22555678Smarcelupgrade_checks:
226143032Sharti	@if ! (cd ${.CURDIR}/tools/build/make_check && \
227138515Sharti	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
228117793Sru	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
229110035Sru	then \
230110035Sru	    (cd ${.CURDIR} && make make); \
231110035Sru	fi
2322061Sjkh
23317308Speter#
234107516Sru# Upgrade make(1) to the current version using the installed
235107374Sru# headers, libraries and tools.
23655678Smarcel#
237107516SruMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
238107516Sru		DESTDIR= \
239107516Sru		INSTALL="sh ${.CURDIR}/tools/install.sh"
240107516SruMMAKE=		${MMAKEENV} make \
241107516Sru		-D_UPGRADING \
242139112Sru		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
243164470Sjb		-DNO_CPU_CFLAGS -DNO_WERROR
244107516Sru
245122204Skrismake: .PHONY
24655678Smarcel	@echo
24755678Smarcel	@echo "--------------------------------------------------------------"
248116696Sru	@echo ">>> Building an up-to-date make(1)"
24955678Smarcel	@echo "--------------------------------------------------------------"
250133376Sharti	${_+_}@cd ${.CURDIR}/usr.bin/make; \
251107516Sru		${MMAKE} obj && \
252107516Sru		${MMAKE} depend && \
253107516Sru		${MMAKE} all && \
254107516Sru		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
25555678Smarcel
25655678Smarcel#
257111131Sru# universe
258111131Sru#
259111131Sru# Attempt to rebuild *everything* for all supported architectures,
260133945Sru# with a reasonable chance of success, regardless of how old your
261111131Sru# existing system is.
262111131Sru#
263148154Sru.if make(universe)
264168280SmarcelTARGETS?=amd64 arm i386 ia64 pc98 powerpc sparc64 sun4v
265168280Smarcel
266133945Sruuniverse: universe_prologue
267133945Sruuniverse_prologue:
268103985Sphk	@echo "--------------------------------------------------------------"
269103985Sphk	@echo ">>> make universe started on ${STARTTIME}"
270103985Sphk	@echo "--------------------------------------------------------------"
271168280Smarcel.for target in ${TARGETS}
272162147SruKERNCONFS!=	cd ${.CURDIR}/sys/${target}/conf && \
273152879Sru		find [A-Z]*[A-Z] -type f -maxdepth 0 \
274152880Sru		! -name DEFAULTS ! -name LINT
275148154SruKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
276162147Sruuniverse: universe_${target}
277162147Sru.ORDER: universe_prologue universe_${target} universe_epilogue
278162147Sruuniverse_${target}:
279162147Sru	@echo ">> ${target} started on `LC_ALL=C date`"
280131876Sphk	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
281162147Sru	    TARGET=${target} \
282111131Sru	    __MAKE_CONF=/dev/null \
283162147Sru	    > _.${target}.buildworld 2>&1
284162147Sru	@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
285162147Sru.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
286162147Sru	-cd ${.CURDIR}/sys/${target}/conf && ${MAKE} LINT \
287162147Sru	    > ${.CURDIR}/_.${target}.makeLINT 2>&1
288103985Sphk.endif
289148154Sru.for kernel in ${KERNCONFS}
290148154Sru	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
291162147Sru	    TARGET=${target} \
292148154Sru	    KERNCONF=${kernel} \
293148154Sru	    __MAKE_CONF=/dev/null \
294162147Sru	    > _.${target}.${kernel} 2>&1
295148154Sru.endfor
296162147Sru	@echo ">> ${target} completed on `LC_ALL=C date`"
297103985Sphk.endfor
298133945Sruuniverse: universe_epilogue
299133945Sruuniverse_epilogue:
300103985Sphk	@echo "--------------------------------------------------------------"
301118531Sru	@echo ">>> make universe completed on `LC_ALL=C date`"
302118531Sru	@echo "                      (started ${STARTTIME})"
303103985Sphk	@echo "--------------------------------------------------------------"
304133945Sru.endif
305