Makefile revision 132588
191094Sdes#
2115619Sdes# $FreeBSD: head/Makefile 132588 2004-07-23 21:21:34Z kensmith $
3228690Sdes#
491094Sdes# The user-driven targets are:
591094Sdes#
691094Sdes# universe            - *Really* build *everything* (buildworld and
799158Sdes#                       all kernels on all architectures).
899158Sdes# buildworld          - Rebuild *everything*, including glue to help do
999158Sdes#                       upgrades.
1091094Sdes# installworld        - Install everything built by "buildworld".
1191094Sdes# world               - buildworld + installworld.
1291094Sdes# buildkernel         - Rebuild the kernel and the kernel-modules.
1391094Sdes# installkernel       - Install the kernel and the kernel-modules.
1491094Sdes# installkernel.debug
1591094Sdes# reinstallkernel     - Reinstall the kernel and the kernel-modules.
1691094Sdes# reinstallkernel.debug
1791094Sdes# kernel              - buildkernel + installkernel.
1891094Sdes# update              - Convenient way to update your source tree (cvs).
1991094Sdes#
2091094Sdes# This makefile is simple by design. The FreeBSD make automatically reads
2191094Sdes# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2291094Sdes# command line. By keeping this makefile simple, it doesn't matter too
2391094Sdes# much how different the installed mk files are from those in the source
2491094Sdes# tree. This makefile executes a child make process, forcing it to use
2591094Sdes# the mk files from the source tree which are supposed to DTRT.
2691094Sdes#
2791094Sdes# The user-driven targets (as listed above) are implemented in Makefile.inc1.
2891094Sdes#
2991094Sdes# If you want to build your system from source be sure that /usr/obj has
3091094Sdes# at least 400MB of diskspace available.
3191094Sdes#
3291094Sdes# For individuals wanting to build from the sources currently on their
3391094Sdes# system, the simple instructions are:
3491094Sdes#
35263421Sdes# 1.  `cd /usr/src'  (or to the directory containing your source tree).
3691094Sdes# 2.  `make world'
3791094Sdes#
38228690Sdes# For individuals wanting to upgrade their sources (even if only a
39228690Sdes# delta of a few days):
40228690Sdes#
41228690Sdes# 1.  `cd /usr/src'       (or to the directory containing your source tree).
4291094Sdes# 2.  `make buildworld'
4391094Sdes# 3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
4491094Sdes# 4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
4591094Sdes# 5.  `reboot'        (in single user mode: boot -s from the loader prompt).
4691094Sdes# 6.  `mergemaster -p'
4791094Sdes# 7.  `make installworld'
4891094Sdes# 8.  `mergemaster'
4991094Sdes# 9.  `reboot'
5091094Sdes#
5191094Sdes# See src/UPDATING `COMMON ITEMS' for more complete information.
5291094Sdes#
5391094Sdes# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
5491094Sdes# cross build world for other architectures using the buildworld target,
5591094Sdes# and once the world is built you can cross build a kernel using the
5691094Sdes# buildkernel target.
5791094Sdes#
5891094Sdes# Define the user-driven targets. These are listed here in alphabetical
5991094Sdes# order, but that's not important.
6091094Sdes#
6191094Sdes# Targets that begin with underscore are internal targets intended for
6291094Sdes# developer convenience only.  They are intentionally not documented and
6391094Sdes# completely subject to change without notice.
6499158Sdes#
6591094SdesTGTS=	all all-man buildkernel buildworld checkdpadd clean \
66110503Sdes	cleandepend cleandir depend distribute distributeworld everything \
6791094Sdes	hierarchy install installcheck installkernel installkernel.debug\
68107937Sdes	reinstallkernel reinstallkernel.debug installworld \
6991094Sdes	kernel-toolchain libraries lint maninstall \
70114438Sdes	obj objlink regress rerelease tags toolchain update \
7191094Sdes	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
7291094Sdes	_build-tools _cross-tools _includes _libraries _depend
73228690Sdes
74228690SdesBITGTS=	files includes
75228690SdesBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
76228690SdesTGTS+=	${BITGTS}
7791094Sdes
7891094Sdes.ORDER: buildworld installworld
7991094Sdes.ORDER: buildworld distributeworld
8091094Sdes.ORDER: buildworld buildkernel
8191094Sdes.ORDER: buildkernel installkernel
8291094Sdes.ORDER: buildkernel installkernel.debug
8391094Sdes.ORDER: buildkernel reinstallkernel
8491094Sdes.ORDER: buildkernel reinstallkernel.debug
8593982Sdes
86228690SdesPATH=	/sbin:/bin:/usr/sbin:/usr/bin
87114438SdesMAKEOBJDIRPREFIX?=	/usr/obj
88114438SdesMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
8999158SdesBINMAKE= \
9099158Sdes	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
9191094Sdes	-m ${.CURDIR}/share/mk
9299158Sdes_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
9399158Sdes
9499158Sdes#
9591094Sdes# Make sure we have an up-to-date make(1). Only world and buildworld
9699158Sdes# should do this as those are the initial targets used for upgrades.
9791094Sdes# The user can define ALWAYS_CHECK_MAKE to have this check performed
9891094Sdes# for all targets.
99107937Sdes#
10091094Sdes.if defined(ALWAYS_CHECK_MAKE)
10191094Sdes${TGTS}: upgrade_checks
10299158Sdes.else
103115619Sdesbuildworld: upgrade_checks
10491094Sdes.endif
10599158Sdes
10699158Sdes#
107107937Sdes# This 'cleanworld' target is not included in TGTS, because it is not a
10899158Sdes# recursive target.  All of the work for it is done right here.   It is
10999158Sdes# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
11099158Sdes# created by bsd.obj.mk, except that we don't want to .include that file
11199158Sdes# in this makefile.  
11291094Sdes#
113107937Sdes# In the following, the first 'rm' in a series will usually remove all
11491094Sdes# files and directories.  If it does not, then there are probably some
11591100Sdes# files with chflags set, so this unsets them and tries the 'rm' a
11691100Sdes# second time.  There are situations where this target will be cleaning
11791100Sdes# some directories via more than one method, but that duplication is
11891100Sdes# needed to correctly handle all the possible situations.
11991100Sdes#
12091100SdesBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
12191100Sdescleanworld:
12291100Sdes.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
12391100Sdes.if exists(${BW_CANONICALOBJDIR}/)
12491100Sdes	-rm -rf ${BW_CANONICALOBJDIR}/*
12591100Sdes	chflags -R 0 ${BW_CANONICALOBJDIR}
12691100Sdes	rm -rf ${BW_CANONICALOBJDIR}/*
12791100Sdes.endif
12891100Sdes	#   To be safe in this case, fall back to a 'make cleandir'
12991100Sdes	@cd ${.CURDIR}; ${_MAKE} cleandir
130.else
131	-rm -rf ${.OBJDIR}/*
132	chflags -R 0 ${.OBJDIR}
133	rm -rf ${.OBJDIR}/*
134.endif
135
136#
137# Handle the user-driven targets, using the source relative mk files.
138#
139
140${TGTS}:
141	@cd ${.CURDIR}; \
142		${_MAKE} ${.TARGET}
143
144# Set a reasonable default
145.MAIN:	all
146
147.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
148.if make(world)
149STARTTIME!= LC_ALL=C date
150.endif
151#
152# world
153#
154# Attempt to rebuild and reinstall everything. This target is not to be
155# used for upgrading an existing FreeBSD system, because the kernel is
156# not included. One can argue that this target doesn't build everything
157# then.
158#
159world: upgrade_checks
160	@echo "--------------------------------------------------------------"
161	@echo ">>> make world started on ${STARTTIME}"
162	@echo "--------------------------------------------------------------"
163.if target(pre-world)
164	@echo
165	@echo "--------------------------------------------------------------"
166	@echo ">>> Making 'pre-world' target"
167	@echo "--------------------------------------------------------------"
168	@cd ${.CURDIR}; ${_MAKE} pre-world
169.endif
170	@cd ${.CURDIR}; ${_MAKE} buildworld
171	@cd ${.CURDIR}; ${_MAKE} -B installworld
172.if target(post-world)
173	@echo
174	@echo "--------------------------------------------------------------"
175	@echo ">>> Making 'post-world' target"
176	@echo "--------------------------------------------------------------"
177	@cd ${.CURDIR}; ${_MAKE} post-world
178.endif
179	@echo
180	@echo "--------------------------------------------------------------"
181	@echo ">>> make world completed on `LC_ALL=C date`"
182	@echo "                   (started ${STARTTIME})"
183	@echo "--------------------------------------------------------------"
184.else
185world:
186	@echo "WARNING: make world will overwrite your existing FreeBSD"
187	@echo "installation without also building and installing a new"
188	@echo "kernel.  This can be dangerous.  Please read the handbook,"
189	@echo "'Rebuilding world', for how to upgrade your system."
190	@echo "Define DESTDIR to where you want to install FreeBSD,"
191	@echo "including /, to override this warning and proceed as usual."
192	@echo "You may get the historical 'make world' behavior by defining"
193	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
194	@echo "before doing this."
195	@echo ""
196	@echo "Bailing out now..."
197	@false
198.endif
199
200#
201# kernel
202#
203# Short hand for `make buildkernel installkernel'
204#
205kernel: buildkernel installkernel
206
207#
208# Perform a few tests to determine if the installed tools are adequate
209# for building the world.
210#
211upgrade_checks:
212	@if ! (cd ${.CURDIR}/tools/regression/usr.bin/make && \
213	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
214	then \
215	    (cd ${.CURDIR} && make make); \
216	fi
217
218#
219# Upgrade make(1) to the current version using the installed
220# headers, libraries and tools.
221#
222MMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
223		DESTDIR= \
224		INSTALL="sh ${.CURDIR}/tools/install.sh"
225MMAKE=		${MMAKEENV} make \
226		-D_UPGRADING \
227		-DNOMAN -DNOSHARED \
228		-DNO_CPU_CFLAGS -DNO_WERROR
229
230make: .PHONY
231	@echo
232	@echo "--------------------------------------------------------------"
233	@echo ">>> Building an up-to-date make(1)"
234	@echo "--------------------------------------------------------------"
235	@cd ${.CURDIR}/usr.bin/make; \
236		${MMAKE} obj && \
237		${MMAKE} depend && \
238		${MMAKE} all && \
239		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
240
241#
242# universe
243#
244# Attempt to rebuild *everything* for all supported architectures,
245# with reasonable chance of success, regardless of how old your
246# existing system is.
247#
248i386_mach=	pc98
249universe:
250	@echo "--------------------------------------------------------------"
251	@echo ">>> make universe started on ${STARTTIME}"
252	@echo "--------------------------------------------------------------"
253.for arch in i386 sparc64 alpha ia64 amd64
254.for mach in ${arch} ${${arch}_mach}
255	@echo ">> ${mach} started on `LC_ALL=C date`"
256	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
257	    TARGET_ARCH=${arch} TARGET=${mach} \
258	    __MAKE_CONF=/dev/null \
259	    > _.${mach}.buildworld 2>&1
260	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
261.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
262	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
263	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
264.endif
265	cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernels TARGET_ARCH=${arch} TARGET=${mach}
266	@echo ">> ${mach} completed on `LC_ALL=C date`"
267.endfor
268.endfor
269	@echo "--------------------------------------------------------------"
270	@echo ">>> make universe completed on `LC_ALL=C date`"
271	@echo "                      (started ${STARTTIME})"
272	@echo "--------------------------------------------------------------"
273
274.if make(buildkernels)
275KERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
276		find [A-Z]*[A-Z] -type f -maxdepth 0 ! -name NOTES
277.endif
278
279buildkernels:
280.for kernel in ${KERNCONFS}
281	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
282	    KERNCONF=${kernel} \
283	    __MAKE_CONF=/dev/null \
284	    > _.${TARGET}.${kernel} 2>&1
285.endfor
286