Makefile revision 156145
1193880Syongari#
2193880Syongari# $FreeBSD: head/Makefile 156145 2006-03-01 13:07:17Z yar $
3193880Syongari#
4193880Syongari# The user-driven targets are:
5193880Syongari#
6193880Syongari# universe            - *Really* build *everything* (buildworld and
7193880Syongari#                       all kernels on all architectures).
8193880Syongari# buildworld          - Rebuild *everything*, including glue to help do
9193880Syongari#                       upgrades.
10193880Syongari# installworld        - Install everything built by "buildworld".
11193880Syongari# world               - buildworld + installworld.
12193880Syongari# buildkernel         - Rebuild the kernel and the kernel-modules.
13193880Syongari# installkernel       - Install the kernel and the kernel-modules.
14193880Syongari# installkernel.debug
15193880Syongari# reinstallkernel     - Reinstall the kernel and the kernel-modules.
16193880Syongari# reinstallkernel.debug
17193880Syongari# kernel              - buildkernel + installkernel.
18193880Syongari# update              - Convenient way to update your source tree (cvs).
19193880Syongari# check-old           - Print a list of old files/directories in the system.
20193880Syongari# delete-old          - Delete obsolete files and directories interactively.
21193880Syongari# delete-old-libs     - Delete obsolete libraries interactively.
22193880Syongari#
23193880Syongari# This makefile is simple by design. The FreeBSD make automatically reads
24193880Syongari# the /usr/share/mk/sys.mk unless the -m argument is specified on the
25193880Syongari# command line. By keeping this makefile simple, it doesn't matter too
26193880Syongari# much how different the installed mk files are from those in the source
27193880Syongari# tree. This makefile executes a child make process, forcing it to use
28211105Syongari# the mk files from the source tree which are supposed to DTRT.
29193880Syongari#
30193880Syongari# The user-driven targets (as listed above) are implemented in Makefile.inc1.
31193880Syongari#
32193880Syongari# If you want to build your system from source be sure that /usr/obj has
33193880Syongari# at least 400MB of diskspace available.
34193880Syongari#
35193880Syongari# For individuals wanting to build from the sources currently on their
36193880Syongari# system, the simple instructions are:
37193880Syongari#
38193880Syongari# 1.  `cd /usr/src'  (or to the directory containing your source tree).
39193880Syongari# 2.  `make world'
40193880Syongari#
41193880Syongari# For individuals wanting to upgrade their sources (even if only a
42193880Syongari# delta of a few days):
43193880Syongari#
44193880Syongari#  1.  `cd /usr/src'       (or to the directory containing your source tree).
45193880Syongari#  2.  `make buildworld'
46193880Syongari#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
47193880Syongari#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
48193880Syongari#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
49193880Syongari#  6.  `mergemaster -p'
50193880Syongari#  7.  `make installworld'
51193880Syongari#  8.  `make delete-old'
52193880Syongari#  9.  `mergemaster'
53193880Syongari# 10.  `reboot'
54193880Syongari# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
55193880Syongari#
56193880Syongari# See src/UPDATING `COMMON ITEMS' for more complete information.
57193880Syongari#
58193880Syongari# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
59193880Syongari# cross build world for other architectures using the buildworld target,
60193880Syongari# and once the world is built you can cross build a kernel using the
61193880Syongari# buildkernel target.
62193880Syongari#
63193880Syongari# Define the user-driven targets. These are listed here in alphabetical
64193880Syongari# order, but that's not important.
65193880Syongari#
66193880Syongari# Targets that begin with underscore are internal targets intended for
67193880Syongari# developer convenience only.  They are intentionally not documented and
68193880Syongari# completely subject to change without notice.
69193880Syongari#
70193880SyongariTGTS=	all all-man buildenv buildkernel buildworld check-old checkdpadd \
71193880Syongari	clean cleandepend cleandir delete-old delete-old-libs depend \
72193880Syongari	distribute distributeworld distrib-dirs distribution everything \
73193880Syongari	hierarchy install installcheck installkernel installkernel.debug\
74193880Syongari	reinstallkernel reinstallkernel.debug installworld \
75193880Syongari	kernel-toolchain libraries lint maninstall \
76193880Syongari	obj objlink regress rerelease tags toolchain update \
77193880Syongari	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
78193880Syongari	_build-tools _cross-tools _includes _libraries _depend \
79193880Syongari	build32 distribute32 install32
80193880Syongari
81193880SyongariBITGTS=	files includes
82193880SyongariBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
83193880SyongariTGTS+=	${BITGTS}
84193880Syongari
85193880Syongari.ORDER: buildworld installworld
86193880Syongari.ORDER: buildworld distributeworld
87193880Syongari.ORDER: buildworld buildkernel
88193880Syongari.ORDER: buildkernel installkernel
89193880Syongari.ORDER: buildkernel installkernel.debug
90193880Syongari.ORDER: buildkernel reinstallkernel
91193880Syongari.ORDER: buildkernel reinstallkernel.debug
92193880Syongari
93193880SyongariPATH=	/sbin:/bin:/usr/sbin:/usr/bin
94193880SyongariMAKEOBJDIRPREFIX?=	/usr/obj
95193880Syongari_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
96193880Syongari    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
97193880Syongari    -f /dev/null -V MAKEOBJDIRPREFIX dummy
98193880Syongari.if !empty(_MAKEOBJDIRPREFIX)
99193880Syongari.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
100211105Syongari	(in make.conf(5)) or command-line variable.
101211105Syongari.endif
102193880SyongariMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
103211105SyongariBINMAKE= \
104211105Syongari	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
105211105Syongari	-m ${.CURDIR}/share/mk
106211105Syongari_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
107211105Syongari
108211105Syongari#
109211105Syongari# Make sure we have an up-to-date make(1). Only world and buildworld
110211105Syongari# should do this as those are the initial targets used for upgrades.
111211105Syongari# The user can define ALWAYS_CHECK_MAKE to have this check performed
112211105Syongari# for all targets.
113211105Syongari#
114193880Syongari.if defined(ALWAYS_CHECK_MAKE)
115193880Syongari${TGTS}: upgrade_checks
116211105Syongari.else
117193880Syongaribuildworld: upgrade_checks
118193880Syongari.endif
119193880Syongari
120193880Syongari#
121193880Syongari# This 'cleanworld' target is not included in TGTS, because it is not a
122193880Syongari# recursive target.  All of the work for it is done right here.   It is
123193880Syongari# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
124193880Syongari# created by bsd.obj.mk, except that we don't want to .include that file
125211105Syongari# in this makefile.  
126211105Syongari#
127193880Syongari# In the following, the first 'rm' in a series will usually remove all
128193880Syongari# files and directories.  If it does not, then there are probably some
129193880Syongari# files with chflags set, so this unsets them and tries the 'rm' a
130193880Syongari# second time.  There are situations where this target will be cleaning
131193880Syongari# some directories via more than one method, but that duplication is
132193880Syongari# needed to correctly handle all the possible situations.
133193880Syongari#
134193880SyongariBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
135193880Syongaricleanworld:
136193880Syongari.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
137193880Syongari.if exists(${BW_CANONICALOBJDIR}/)
138193880Syongari	-rm -rf ${BW_CANONICALOBJDIR}/*
139193880Syongari	chflags -R 0 ${BW_CANONICALOBJDIR}
140193880Syongari	rm -rf ${BW_CANONICALOBJDIR}/*
141193880Syongari.endif
142193880Syongari	#   To be safe in this case, fall back to a 'make cleandir'
143193880Syongari	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
144193880Syongari.else
145193880Syongari	-rm -rf ${.OBJDIR}/*
146193880Syongari	chflags -R 0 ${.OBJDIR}
147193880Syongari	rm -rf ${.OBJDIR}/*
148193880Syongari.endif
149193880Syongari
150193880Syongari#
151193880Syongari# Handle the user-driven targets, using the source relative mk files.
152193880Syongari#
153193880Syongari
154193880Syongari${TGTS}:
155193880Syongari	${_+_}@cd ${.CURDIR}; \
156193880Syongari		${_MAKE} ${.TARGET}
157193880Syongari
158193880Syongari# Set a reasonable default
159193880Syongari.MAIN:	all
160193880Syongari
161193880SyongariSTARTTIME!= LC_ALL=C date
162216925Sjhb
163193880Syongari.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
164193880Syongari#
165193880Syongari# world
166193880Syongari#
167193880Syongari# Attempt to rebuild and reinstall everything. This target is not to be
168193880Syongari# used for upgrading an existing FreeBSD system, because the kernel is
169193880Syongari# not included. One can argue that this target doesn't build everything
170193880Syongari# then.
171193880Syongari#
172193880Syongariworld: upgrade_checks
173193880Syongari	@echo "--------------------------------------------------------------"
174193880Syongari	@echo ">>> make world started on ${STARTTIME}"
175193880Syongari	@echo "--------------------------------------------------------------"
176193880Syongari.if target(pre-world)
177193880Syongari	@echo
178193880Syongari	@echo "--------------------------------------------------------------"
179193880Syongari	@echo ">>> Making 'pre-world' target"
180193880Syongari	@echo "--------------------------------------------------------------"
181193880Syongari	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
182193880Syongari.endif
183193880Syongari	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
184193880Syongari	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
185193880Syongari.if target(post-world)
186193880Syongari	@echo
187193880Syongari	@echo "--------------------------------------------------------------"
188193880Syongari	@echo ">>> Making 'post-world' target"
189193880Syongari	@echo "--------------------------------------------------------------"
190193880Syongari	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
191193880Syongari.endif
192193880Syongari	@echo
193193880Syongari	@echo "--------------------------------------------------------------"
194193880Syongari	@echo ">>> make world completed on `LC_ALL=C date`"
195193880Syongari	@echo "                   (started ${STARTTIME})"
196193880Syongari	@echo "--------------------------------------------------------------"
197193880Syongari.else
198193880Syongariworld:
199193880Syongari	@echo "WARNING: make world will overwrite your existing FreeBSD"
200193880Syongari	@echo "installation without also building and installing a new"
201193880Syongari	@echo "kernel.  This can be dangerous.  Please read the handbook,"
202193880Syongari	@echo "'Rebuilding world', for how to upgrade your system."
203193880Syongari	@echo "Define DESTDIR to where you want to install FreeBSD,"
204193880Syongari	@echo "including /, to override this warning and proceed as usual."
205193880Syongari	@echo "You may get the historical 'make world' behavior by defining"
206193880Syongari	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
207193880Syongari	@echo "before doing this."
208193880Syongari	@echo ""
209193880Syongari	@echo "Bailing out now..."
210193880Syongari	@false
211193880Syongari.endif
212193880Syongari
213193880Syongari#
214193880Syongari# kernel
215193880Syongari#
216193880Syongari# Short hand for `make buildkernel installkernel'
217193880Syongari#
218193880Syongarikernel: buildkernel installkernel
219193880Syongari
220193880Syongari#
221193880Syongari# Perform a few tests to determine if the installed tools are adequate
222193880Syongari# for building the world.
223193880Syongari#
224193880Syongariupgrade_checks:
225193880Syongari	@if ! (cd ${.CURDIR}/tools/build/make_check && \
226193880Syongari	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
227193880Syongari	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
228193880Syongari	then \
229193880Syongari	    (cd ${.CURDIR} && make make); \
230193880Syongari	fi
231193880Syongari
232193880Syongari#
233193880Syongari# Upgrade make(1) to the current version using the installed
234193880Syongari# headers, libraries and tools.
235193880Syongari#
236193880SyongariMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
237197600Syongari		DESTDIR= \
238197600Syongari		INSTALL="sh ${.CURDIR}/tools/install.sh"
239197600SyongariMMAKE=		${MMAKEENV} make \
240197600Syongari		-D_UPGRADING \
241197600Syongari		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
242197600Syongari		-DNO_CPU_CFLAGS -DNO_WERROR
243197600Syongari
244197600Syongarimake: .PHONY
245197600Syongari	@echo
246197600Syongari	@echo "--------------------------------------------------------------"
247193880Syongari	@echo ">>> Building an up-to-date make(1)"
248193880Syongari	@echo "--------------------------------------------------------------"
249193880Syongari	${_+_}@cd ${.CURDIR}/usr.bin/make; \
250193880Syongari		${MMAKE} obj && \
251193880Syongari		${MMAKE} depend && \
252193880Syongari		${MMAKE} all && \
253193880Syongari		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
254193880Syongari
255193880Syongari#
256193880Syongari# universe
257193880Syongari#
258193880Syongari# Attempt to rebuild *everything* for all supported architectures,
259193880Syongari# with a reasonable chance of success, regardless of how old your
260193880Syongari# existing system is.
261193880Syongari#
262193880Syongari.if make(universe)
263193880Syongariuniverse: universe_prologue
264193880Syongariuniverse_prologue:
265193880Syongari	@echo "--------------------------------------------------------------"
266193880Syongari	@echo ">>> make universe started on ${STARTTIME}"
267193880Syongari	@echo "--------------------------------------------------------------"
268193880Syongari.for target in i386 i386:pc98 sparc64 alpha ia64 amd64
269193880Syongari.for arch in ${target:C/:.*$//}
270193880Syongari.for mach in ${target:C/^.*://}
271193880SyongariKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
272193880Syongari		find [A-Z]*[A-Z] -type f -maxdepth 0 \
273193880Syongari		! -name DEFAULTS ! -name LINT
274193880SyongariKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
275193880Syongariuniverse: universe_${mach}
276193880Syongari.ORDER: universe_prologue universe_${mach} universe_epilogue
277193880Syongariuniverse_${mach}:
278193880Syongari	@echo ">> ${mach} started on `LC_ALL=C date`"
279193880Syongari	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
280193880Syongari	    TARGET_ARCH=${arch} TARGET=${mach} \
281193880Syongari	    __MAKE_CONF=/dev/null \
282193880Syongari	    > _.${mach}.buildworld 2>&1
283193880Syongari	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
284193880Syongari.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
285193880Syongari	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
286193880Syongari	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
287193880Syongari.endif
288193880Syongari.for kernel in ${KERNCONFS}
289193880Syongari	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
290193880Syongari	    TARGET_ARCH=${arch} TARGET=${mach} \
291193880Syongari	    KERNCONF=${kernel} \
292193880Syongari	    __MAKE_CONF=/dev/null \
293193880Syongari	    > _.${mach}.${kernel} 2>&1
294193880Syongari.endfor
295193880Syongari	@echo ">> ${mach} completed on `LC_ALL=C date`"
296193880Syongari.endfor
297193880Syongari.endfor
298193880Syongari.endfor
299193880Syongariuniverse: universe_epilogue
300193880Syongariuniverse_epilogue:
301193880Syongari	@echo "--------------------------------------------------------------"
302193880Syongari	@echo ">>> make universe completed on `LC_ALL=C date`"
303193880Syongari	@echo "                      (started ${STARTTIME})"
304193880Syongari	@echo "--------------------------------------------------------------"
305193880Syongari.endif
306193880Syongari