xref: /freebsd/Makefile (revision 902f7c5b)
13540f0e1SJordan K. Hubbard#
297d92980SPeter Wemm# $FreeBSD$
3cf763a57SJohn Birrell#
411fb97daSJohn Birrell# The user-driven targets are:
5cf763a57SJohn Birrell#
61f4f7670SRuslan Ermilov# universe            - *Really* build *everything* (buildworld and
71f4f7670SRuslan Ermilov#                       all kernels on all architectures).
811fb97daSJohn Birrell# buildworld          - Rebuild *everything*, including glue to help do
911fb97daSJohn Birrell#                       upgrades.
1011fb97daSJohn Birrell# installworld        - Install everything built by "buildworld".
1111fb97daSJohn Birrell# world               - buildworld + installworld.
1200eb8cbdSAlexander Langer# buildkernel         - Rebuild the kernel and the kernel-modules.
1300eb8cbdSAlexander Langer# installkernel       - Install the kernel and the kernel-modules.
140147d2aaSHidetoshi Shimokawa# installkernel.debug
15737ffab7SMark Murray# reinstallkernel     - Reinstall the kernel and the kernel-modules.
160147d2aaSHidetoshi Shimokawa# reinstallkernel.debug
17bc4311beSDavid E. O'Brien# kernel              - buildkernel + installkernel.
1811fb97daSJohn Birrell# update              - Convenient way to update your source tree (cvs).
19e2a36081SAlexander Leidinger# check-old           - Print a list of old files/directories in the system.
20e2a36081SAlexander Leidinger# delete-old          - Delete obsolete files and directories interactively.
21e2a36081SAlexander Leidinger# delete-old-libs     - Delete obsolete libraries interactively.
223540f0e1SJordan K. Hubbard#
2311fb97daSJohn Birrell# This makefile is simple by design. The FreeBSD make automatically reads
2411fb97daSJohn Birrell# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2511fb97daSJohn Birrell# command line. By keeping this makefile simple, it doesn't matter too
2611fb97daSJohn Birrell# much how different the installed mk files are from those in the source
2711fb97daSJohn Birrell# tree. This makefile executes a child make process, forcing it to use
2811fb97daSJohn Birrell# the mk files from the source tree which are supposed to DTRT.
2911fb97daSJohn Birrell#
30912422f0SGiorgos Keramidas# The user-driven targets (as listed above) are implemented in Makefile.inc1.
3111fb97daSJohn Birrell#
3276fdd728SJohn W. De Boskey# If you want to build your system from source be sure that /usr/obj has
3376fdd728SJohn W. De Boskey# at least 400MB of diskspace available.
3411fb97daSJohn Birrell#
3576fdd728SJohn W. De Boskey# For individuals wanting to build from the sources currently on their
3676fdd728SJohn W. De Boskey# system, the simple instructions are:
3711fb97daSJohn Birrell#
3876fdd728SJohn W. De Boskey# 1.  `cd /usr/src'  (or to the directory containing your source tree).
3976fdd728SJohn W. De Boskey# 2.  `make world'
4011fb97daSJohn Birrell#
4176fdd728SJohn W. De Boskey# For individuals wanting to upgrade their sources (even if only a
4276fdd728SJohn W. De Boskey# delta of a few days):
4376fdd728SJohn W. De Boskey#
4476fdd728SJohn W. De Boskey#  1.  `cd /usr/src'       (or to the directory containing your source tree).
4576fdd728SJohn W. De Boskey#  2.  `make buildworld'
4676fdd728SJohn W. De Boskey#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
4776fdd728SJohn W. De Boskey#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
4876fdd728SJohn W. De Boskey#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
4976fdd728SJohn W. De Boskey#  6.  `mergemaster -p'
5076fdd728SJohn W. De Boskey#  7.  `make installworld'
51e2a36081SAlexander Leidinger#  8.  `make delete-old'
52e2a36081SAlexander Leidinger#  9.  `mergemaster'
53e2a36081SAlexander Leidinger# 10.  `reboot'
54e2a36081SAlexander Leidinger# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
5576fdd728SJohn W. De Boskey#
5676fdd728SJohn W. De Boskey# See src/UPDATING `COMMON ITEMS' for more complete information.
5711fb97daSJohn Birrell#
581b71212bSMatthew Dillon# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
59dbc3719dSMatthew Dillon# cross build world for other architectures using the buildworld target,
60dbc3719dSMatthew Dillon# and once the world is built you can cross build a kernel using the
61dbc3719dSMatthew Dillon# buildkernel target.
62dbc3719dSMatthew Dillon#
6311fb97daSJohn Birrell# Define the user-driven targets. These are listed here in alphabetical
6411fb97daSJohn Birrell# order, but that's not important.
6511fb97daSJohn Birrell#
66ef7af95aSPeter Wemm# Targets that begin with underscore are internal targets intended for
67ef7af95aSPeter Wemm# developer convenience only.  They are intentionally not documented and
68ef7af95aSPeter Wemm# completely subject to change without notice.
69ef7af95aSPeter Wemm#
70e2a36081SAlexander LeidingerTGTS=	all all-man buildenv buildkernel buildworld check-old checkdpadd \
71e2a36081SAlexander Leidinger	clean cleandepend cleandir delete-old delete-old-libs depend \
72e2a36081SAlexander Leidinger	distribute distributeworld distrib-dirs distribution everything \
730147d2aaSHidetoshi Shimokawa	hierarchy install installcheck installkernel installkernel.debug\
74829340b1SRuslan Ermilov	reinstallkernel reinstallkernel.debug installworld \
7543fc6762SDag-Erling Smørgrav	kernel-toolchain libraries lint maninstall \
76839274c7SRuslan Ermilov	obj objlink regress rerelease tags toolchain update \
77ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
781d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
79ece6831dSRuslan Ermilov	build32 distribute32 install32
80902f7c5bSRuslan ErmilovTGTS+=	${SUBDIR_TARGETS}
816e59a256SMarcel Moolenaar
82af2dc868SRuslan ErmilovBITGTS=	files includes
8328d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
84b797df80SRuslan ErmilovTGTS+=	${BITGTS}
8528d2080aSRuslan Ermilov
86d672a609SRuslan Ermilov.ORDER: buildworld installworld
878f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
8820902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
89d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
900147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
91d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
920147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
93d672a609SRuslan Ermilov
9476499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
952e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
96e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
97f1fb2096SYaroslav Tykhiy    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
980ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
990ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
1000ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
101f1fb2096SYaroslav Tykhiy	(in make.conf(5)) or command-line variable.
1020ec443a0SRuslan Ermilov.endif
10376499f15SRuslan ErmilovMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
104ead4296eSRuslan ErmilovBINMAKE= \
10576499f15SRuslan Ermilov	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
1065dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
107ead4296eSRuslan Ermilov_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
108a962de47SPeter Wemm
109a962de47SPeter Wemm#
110d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
111d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
112d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
113d911f786SMarcel Moolenaar# for all targets.
114d911f786SMarcel Moolenaar#
115d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
116b797df80SRuslan Ermilov${TGTS}: upgrade_checks
117d911f786SMarcel Moolenaar.else
118d911f786SMarcel Moolenaarbuildworld: upgrade_checks
119d911f786SMarcel Moolenaar.endif
120d911f786SMarcel Moolenaar
121d911f786SMarcel Moolenaar#
122224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
1231a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
1241a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
1251a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
1261a974787SGarance A Drosehn# in this makefile.
1271a974787SGarance A Drosehn#
1281a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
1291a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
1301a974787SGarance A Drosehn# files with chflags set, so this unsets them and tries the 'rm' a
1311a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
1321a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
1331a974787SGarance A Drosehn# needed to correctly handle all the possible situations.
1341a974787SGarance A Drosehn#
1351a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
136224f0698SGarance A Drosehncleanworld:
1371a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
1381a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
1391a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
1401a974787SGarance A Drosehn	chflags -R 0 ${BW_CANONICALOBJDIR}
1411a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
1421a974787SGarance A Drosehn.endif
1431a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
144088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
1451a974787SGarance A Drosehn.else
1461a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
1471a974787SGarance A Drosehn	chflags -R 0 ${.OBJDIR}
1481a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
1491a974787SGarance A Drosehn.endif
1502047c5d3SGarance A Drosehn
1512047c5d3SGarance A Drosehn#
15211fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
153f3c4dd0dSBruce Evans#
154d911f786SMarcel Moolenaar
155b797df80SRuslan Ermilov${TGTS}:
156088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; \
15776499f15SRuslan Ermilov		${_MAKE} ${.TARGET}
158c3d9b0f0SRodney W. Grimes
159ce53af53SJordan K. Hubbard# Set a reasonable default
160ce53af53SJordan K. Hubbard.MAIN:	all
161ce53af53SJordan K. Hubbard
162afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
163d18c9906SRuslan Ermilov
164d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
1656e59a256SMarcel Moolenaar#
1666e59a256SMarcel Moolenaar# world
1676e59a256SMarcel Moolenaar#
1680a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
1690a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
1700a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
1710a945825SMarcel Moolenaar# then.
1726e59a256SMarcel Moolenaar#
1736e59a256SMarcel Moolenaarworld: upgrade_checks
1746e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1755ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
1766e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1776e59a256SMarcel Moolenaar.if target(pre-world)
1786e59a256SMarcel Moolenaar	@echo
1796e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1806e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
1816e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
182088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
1836e59a256SMarcel Moolenaar.endif
184088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
185088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
1866e59a256SMarcel Moolenaar.if target(post-world)
1876e59a256SMarcel Moolenaar	@echo
1886e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1896e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
1906e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
191088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
1926e59a256SMarcel Moolenaar.endif
1936e59a256SMarcel Moolenaar	@echo
1946e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1955ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
1965ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
1976e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1980a945825SMarcel Moolenaar.else
1990a945825SMarcel Moolenaarworld:
2000a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
2010a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
2020a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
2031f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
204954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
2050a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
206954c5b43SMark Murray	@echo "You may get the historical 'make world' behavior by defining"
207954c5b43SMark Murray	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
208954c5b43SMark Murray	@echo "before doing this."
209954c5b43SMark Murray	@echo ""
2100a945825SMarcel Moolenaar	@echo "Bailing out now..."
2110a945825SMarcel Moolenaar	@false
2120a945825SMarcel Moolenaar.endif
2136e59a256SMarcel Moolenaar
214cf94fb21SBruce Evans#
215d672a609SRuslan Ermilov# kernel
216d672a609SRuslan Ermilov#
217d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
218d672a609SRuslan Ermilov#
219d672a609SRuslan Ermilovkernel: buildkernel installkernel
220d672a609SRuslan Ermilov
221d672a609SRuslan Ermilov#
22211fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
223113cf9e6SRuslan Ermilov# for building the world.
22411fb97daSJohn Birrell#
22511fb97daSJohn Birrellupgrade_checks:
226012a8b3fSHartmut Brandt	@if ! (cd ${.CURDIR}/tools/build/make_check && \
22789f087e8SHartmut Brandt	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
228ef2c779bSRuslan Ermilov	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
22976499f15SRuslan Ermilov	then \
23076499f15SRuslan Ermilov	    (cd ${.CURDIR} && make make); \
23176499f15SRuslan Ermilov	fi
2326a8d432dSMark Murray
233a962de47SPeter Wemm#
2342e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
235113cf9e6SRuslan Ermilov# headers, libraries and tools.
236549f978aSMarcel Moolenaar#
2372e84ab94SRuslan ErmilovMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
2382e84ab94SRuslan Ermilov		DESTDIR= \
2392e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
2402e84ab94SRuslan ErmilovMMAKE=		${MMAKEENV} make \
2412e84ab94SRuslan Ermilov		-D_UPGRADING \
24283c7ade9SRuslan Ermilov		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
2432e84ab94SRuslan Ermilov		-DNO_CPU_CFLAGS -DNO_WERROR
2442e84ab94SRuslan Ermilov
2452a6e9f88SKris Kennawaymake: .PHONY
246549f978aSMarcel Moolenaar	@echo
247549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
248b31745f5SRuslan Ermilov	@echo ">>> Building an up-to-date make(1)"
249549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
250088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}/usr.bin/make; \
2512e84ab94SRuslan Ermilov		${MMAKE} obj && \
2522e84ab94SRuslan Ermilov		${MMAKE} depend && \
2532e84ab94SRuslan Ermilov		${MMAKE} all && \
2542e84ab94SRuslan Ermilov		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
255549f978aSMarcel Moolenaar
256549f978aSMarcel Moolenaar#
2571f4f7670SRuslan Ermilov# universe
2581f4f7670SRuslan Ermilov#
2591f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
260d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
2611f4f7670SRuslan Ermilov# existing system is.
2621f4f7670SRuslan Ermilov#
263dd0f3923SRuslan Ermilov.if make(universe)
264d18c9906SRuslan Ermilovuniverse: universe_prologue
265d18c9906SRuslan Ermilovuniverse_prologue:
26677c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
26777c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
26877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
269d18c9906SRuslan Ermilov.for target in i386 i386:pc98 sparc64 alpha ia64 amd64
270d18c9906SRuslan Ermilov.for arch in ${target:C/:.*$//}
271d18c9906SRuslan Ermilov.for mach in ${target:C/^.*://}
272dd0f3923SRuslan ErmilovKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
273d72ae1eaSRuslan Ermilov		find [A-Z]*[A-Z] -type f -maxdepth 0 \
274e9729318SRuslan Ermilov		! -name DEFAULTS ! -name LINT
275dd0f3923SRuslan ErmilovKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
276d18c9906SRuslan Ermilovuniverse: universe_${mach}
277d18c9906SRuslan Ermilov.ORDER: universe_prologue universe_${mach} universe_epilogue
278d18c9906SRuslan Ermilovuniverse_${mach}:
2791f4f7670SRuslan Ermilov	@echo ">> ${mach} started on `LC_ALL=C date`"
2800d4e175dSPoul-Henning Kamp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
2811f4f7670SRuslan Ermilov	    TARGET_ARCH=${arch} TARGET=${mach} \
28277c1699fSPoul-Henning Kamp	    __MAKE_CONF=/dev/null \
2831f4f7670SRuslan Ermilov	    > _.${mach}.buildworld 2>&1
2841f4f7670SRuslan Ermilov	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
2851f4f7670SRuslan Ermilov.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
2861f4f7670SRuslan Ermilov	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
287301c4069SRuslan Ermilov	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
28877c1699fSPoul-Henning Kamp.endif
289dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
290dd0f3923SRuslan Ermilov	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
291dd0f3923SRuslan Ermilov	    TARGET_ARCH=${arch} TARGET=${mach} \
292dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
293dd0f3923SRuslan Ermilov	    __MAKE_CONF=/dev/null \
294dd0f3923SRuslan Ermilov	    > _.${mach}.${kernel} 2>&1
295dd0f3923SRuslan Ermilov.endfor
2961f4f7670SRuslan Ermilov	@echo ">> ${mach} completed on `LC_ALL=C date`"
29777c1699fSPoul-Henning Kamp.endfor
2981f4f7670SRuslan Ermilov.endfor
299d18c9906SRuslan Ermilov.endfor
300d18c9906SRuslan Ermilovuniverse: universe_epilogue
301d18c9906SRuslan Ermilovuniverse_epilogue:
30277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
3035ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
3045ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
30577c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
306d18c9906SRuslan Ermilov.endif
307