xref: /freebsd/Makefile (revision dd0f3923)
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).
193540f0e1SJordan K. Hubbard#
2011fb97daSJohn Birrell# This makefile is simple by design. The FreeBSD make automatically reads
2111fb97daSJohn Birrell# the /usr/share/mk/sys.mk unless the -m argument is specified on the
2211fb97daSJohn Birrell# command line. By keeping this makefile simple, it doesn't matter too
2311fb97daSJohn Birrell# much how different the installed mk files are from those in the source
2411fb97daSJohn Birrell# tree. This makefile executes a child make process, forcing it to use
2511fb97daSJohn Birrell# the mk files from the source tree which are supposed to DTRT.
2611fb97daSJohn Birrell#
27912422f0SGiorgos Keramidas# The user-driven targets (as listed above) are implemented in Makefile.inc1.
2811fb97daSJohn Birrell#
2976fdd728SJohn W. De Boskey# If you want to build your system from source be sure that /usr/obj has
3076fdd728SJohn W. De Boskey# at least 400MB of diskspace available.
3111fb97daSJohn Birrell#
3276fdd728SJohn W. De Boskey# For individuals wanting to build from the sources currently on their
3376fdd728SJohn W. De Boskey# system, the simple instructions are:
3411fb97daSJohn Birrell#
3576fdd728SJohn W. De Boskey# 1.  `cd /usr/src'  (or to the directory containing your source tree).
3676fdd728SJohn W. De Boskey# 2.  `make world'
3711fb97daSJohn Birrell#
3876fdd728SJohn W. De Boskey# For individuals wanting to upgrade their sources (even if only a
3976fdd728SJohn W. De Boskey# delta of a few days):
4076fdd728SJohn W. De Boskey#
4176fdd728SJohn W. De Boskey# 1.  `cd /usr/src'       (or to the directory containing your source tree).
4276fdd728SJohn W. De Boskey# 2.  `make buildworld'
4376fdd728SJohn W. De Boskey# 3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
4476fdd728SJohn W. De Boskey# 4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
4576fdd728SJohn W. De Boskey# 5.  `reboot'        (in single user mode: boot -s from the loader prompt).
4676fdd728SJohn W. De Boskey# 6.  `mergemaster -p'
4776fdd728SJohn W. De Boskey# 7.  `make installworld'
4876fdd728SJohn W. De Boskey# 8.  `mergemaster'
4976fdd728SJohn W. De Boskey# 9.  `reboot'
5076fdd728SJohn W. De Boskey#
5176fdd728SJohn W. De Boskey# See src/UPDATING `COMMON ITEMS' for more complete information.
5211fb97daSJohn Birrell#
531b71212bSMatthew Dillon# If TARGET_ARCH=arch (e.g. ia64, sparc64, ...) is specified you can
54dbc3719dSMatthew Dillon# cross build world for other architectures using the buildworld target,
55dbc3719dSMatthew Dillon# and once the world is built you can cross build a kernel using the
56dbc3719dSMatthew Dillon# buildkernel target.
57dbc3719dSMatthew Dillon#
5811fb97daSJohn Birrell# Define the user-driven targets. These are listed here in alphabetical
5911fb97daSJohn Birrell# order, but that's not important.
6011fb97daSJohn Birrell#
61ef7af95aSPeter Wemm# Targets that begin with underscore are internal targets intended for
62ef7af95aSPeter Wemm# developer convenience only.  They are intentionally not documented and
63ef7af95aSPeter Wemm# completely subject to change without notice.
64ef7af95aSPeter Wemm#
6520bfae84SRuslan ErmilovTGTS=	all all-man buildenv buildkernel buildworld checkdpadd clean \
669bdd3e84SRuslan Ermilov	cleandepend cleandir depend distribute distributeworld \
67a59f6433SRuslan Ermilov	distrib-dirs distribution everything \
680147d2aaSHidetoshi Shimokawa	hierarchy install installcheck installkernel installkernel.debug\
69829340b1SRuslan Ermilov	reinstallkernel reinstallkernel.debug installworld \
7043fc6762SDag-Erling Smørgrav	kernel-toolchain libraries lint maninstall \
71839274c7SRuslan Ermilov	obj objlink regress rerelease tags toolchain update \
72ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
731d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
74ece6831dSRuslan Ermilov	build32 distribute32 install32
756e59a256SMarcel Moolenaar
76af2dc868SRuslan ErmilovBITGTS=	files includes
7728d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
78b797df80SRuslan ErmilovTGTS+=	${BITGTS}
7928d2080aSRuslan Ermilov
80d672a609SRuslan Ermilov.ORDER: buildworld installworld
818f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
8220902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
83d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
840147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
85d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
860147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
87d672a609SRuslan Ermilov
8876499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
892e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
90e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
91e9bddef1SRuslan Ermilov    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} \
920ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
930ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
940ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
950ec443a0SRuslan Ermilov	(in /etc/make.conf) or command-line variable.
960ec443a0SRuslan Ermilov.endif
9776499f15SRuslan ErmilovMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
98ead4296eSRuslan ErmilovBINMAKE= \
9976499f15SRuslan Ermilov	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
1005dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
101ead4296eSRuslan Ermilov_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
102a962de47SPeter Wemm
103a962de47SPeter Wemm#
104d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
105d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
106d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
107d911f786SMarcel Moolenaar# for all targets.
108d911f786SMarcel Moolenaar#
109d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
110b797df80SRuslan Ermilov${TGTS}: upgrade_checks
111d911f786SMarcel Moolenaar.else
112d911f786SMarcel Moolenaarbuildworld: upgrade_checks
113d911f786SMarcel Moolenaar.endif
114d911f786SMarcel Moolenaar
115d911f786SMarcel Moolenaar#
116224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
1171a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
1181a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
1191a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
1201a974787SGarance A Drosehn# in this makefile.
1211a974787SGarance A Drosehn#
1221a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
1231a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
1241a974787SGarance A Drosehn# files with chflags set, so this unsets them and tries the 'rm' a
1251a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
1261a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
1271a974787SGarance A Drosehn# needed to correctly handle all the possible situations.
1281a974787SGarance A Drosehn#
1291a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
130224f0698SGarance A Drosehncleanworld:
1311a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
1321a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
1331a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
1341a974787SGarance A Drosehn	chflags -R 0 ${BW_CANONICALOBJDIR}
1351a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
1361a974787SGarance A Drosehn.endif
1371a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
138088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
1391a974787SGarance A Drosehn.else
1401a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
1411a974787SGarance A Drosehn	chflags -R 0 ${.OBJDIR}
1421a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
1431a974787SGarance A Drosehn.endif
1442047c5d3SGarance A Drosehn
1452047c5d3SGarance A Drosehn#
14611fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
147f3c4dd0dSBruce Evans#
148d911f786SMarcel Moolenaar
149b797df80SRuslan Ermilov${TGTS}:
150088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; \
15176499f15SRuslan Ermilov		${_MAKE} ${.TARGET}
152c3d9b0f0SRodney W. Grimes
153ce53af53SJordan K. Hubbard# Set a reasonable default
154ce53af53SJordan K. Hubbard.MAIN:	all
155ce53af53SJordan K. Hubbard
156afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
157d18c9906SRuslan Ermilov
158d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
1596e59a256SMarcel Moolenaar#
1606e59a256SMarcel Moolenaar# world
1616e59a256SMarcel Moolenaar#
1620a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
1630a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
1640a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
1650a945825SMarcel Moolenaar# then.
1666e59a256SMarcel Moolenaar#
1676e59a256SMarcel Moolenaarworld: upgrade_checks
1686e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1695ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
1706e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1716e59a256SMarcel Moolenaar.if target(pre-world)
1726e59a256SMarcel Moolenaar	@echo
1736e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1746e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
1756e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
176088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
1776e59a256SMarcel Moolenaar.endif
178088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
179088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
1806e59a256SMarcel Moolenaar.if target(post-world)
1816e59a256SMarcel Moolenaar	@echo
1826e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1836e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
1846e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
185088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
1866e59a256SMarcel Moolenaar.endif
1876e59a256SMarcel Moolenaar	@echo
1886e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1895ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
1905ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
1916e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1920a945825SMarcel Moolenaar.else
1930a945825SMarcel Moolenaarworld:
1940a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
1950a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
1960a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
1971f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
198954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
1990a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
200954c5b43SMark Murray	@echo "You may get the historical 'make world' behavior by defining"
201954c5b43SMark Murray	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
202954c5b43SMark Murray	@echo "before doing this."
203954c5b43SMark Murray	@echo ""
2040a945825SMarcel Moolenaar	@echo "Bailing out now..."
2050a945825SMarcel Moolenaar	@false
2060a945825SMarcel Moolenaar.endif
2076e59a256SMarcel Moolenaar
208cf94fb21SBruce Evans#
209d672a609SRuslan Ermilov# kernel
210d672a609SRuslan Ermilov#
211d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
212d672a609SRuslan Ermilov#
213d672a609SRuslan Ermilovkernel: buildkernel installkernel
214d672a609SRuslan Ermilov
215d672a609SRuslan Ermilov#
21611fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
217113cf9e6SRuslan Ermilov# for building the world.
21811fb97daSJohn Birrell#
21911fb97daSJohn Birrellupgrade_checks:
220012a8b3fSHartmut Brandt	@if ! (cd ${.CURDIR}/tools/build/make_check && \
22189f087e8SHartmut Brandt	    PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
222ef2c779bSRuslan Ermilov	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
22376499f15SRuslan Ermilov	then \
22476499f15SRuslan Ermilov	    (cd ${.CURDIR} && make make); \
22576499f15SRuslan Ermilov	fi
2266a8d432dSMark Murray
227a962de47SPeter Wemm#
2282e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
229113cf9e6SRuslan Ermilov# headers, libraries and tools.
230549f978aSMarcel Moolenaar#
2312e84ab94SRuslan ErmilovMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
2322e84ab94SRuslan Ermilov		DESTDIR= \
2332e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
2342e84ab94SRuslan ErmilovMMAKE=		${MMAKEENV} make \
2352e84ab94SRuslan Ermilov		-D_UPGRADING \
23683c7ade9SRuslan Ermilov		-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
2372e84ab94SRuslan Ermilov		-DNO_CPU_CFLAGS -DNO_WERROR
2382e84ab94SRuslan Ermilov
2392a6e9f88SKris Kennawaymake: .PHONY
240549f978aSMarcel Moolenaar	@echo
241549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
242b31745f5SRuslan Ermilov	@echo ">>> Building an up-to-date make(1)"
243549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
244088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}/usr.bin/make; \
2452e84ab94SRuslan Ermilov		${MMAKE} obj && \
2462e84ab94SRuslan Ermilov		${MMAKE} depend && \
2472e84ab94SRuslan Ermilov		${MMAKE} all && \
2482e84ab94SRuslan Ermilov		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
249549f978aSMarcel Moolenaar
250549f978aSMarcel Moolenaar#
2511f4f7670SRuslan Ermilov# universe
2521f4f7670SRuslan Ermilov#
2531f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
254d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
2551f4f7670SRuslan Ermilov# existing system is.
2561f4f7670SRuslan Ermilov#
257dd0f3923SRuslan Ermilov.if make(universe)
258d18c9906SRuslan Ermilovuniverse: universe_prologue
259d18c9906SRuslan Ermilovuniverse_prologue:
26077c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
26177c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
26277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
263d18c9906SRuslan Ermilov.for target in i386 i386:pc98 sparc64 alpha ia64 amd64
264d18c9906SRuslan Ermilov.for arch in ${target:C/:.*$//}
265d18c9906SRuslan Ermilov.for mach in ${target:C/^.*://}
266dd0f3923SRuslan ErmilovKERNCONFS!=	cd ${.CURDIR}/sys/${mach}/conf && \
267dd0f3923SRuslan Ermilov		find [A-Z]*[A-Z] -type f -maxdepth 0
268dd0f3923SRuslan ErmilovKERNCONFS:=	${KERNCONFS:S/^NOTES$/LINT/}
269d18c9906SRuslan Ermilovuniverse: universe_${mach}
270d18c9906SRuslan Ermilov.ORDER: universe_prologue universe_${mach} universe_epilogue
271d18c9906SRuslan Ermilovuniverse_${mach}:
2721f4f7670SRuslan Ermilov	@echo ">> ${mach} started on `LC_ALL=C date`"
2730d4e175dSPoul-Henning Kamp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
2741f4f7670SRuslan Ermilov	    TARGET_ARCH=${arch} TARGET=${mach} \
27577c1699fSPoul-Henning Kamp	    __MAKE_CONF=/dev/null \
2761f4f7670SRuslan Ermilov	    > _.${mach}.buildworld 2>&1
2771f4f7670SRuslan Ermilov	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
2781f4f7670SRuslan Ermilov.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
2791f4f7670SRuslan Ermilov	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
280301c4069SRuslan Ermilov	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
28177c1699fSPoul-Henning Kamp.endif
282dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
283dd0f3923SRuslan Ermilov	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
284dd0f3923SRuslan Ermilov	    TARGET_ARCH=${arch} TARGET=${mach} \
285dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
286dd0f3923SRuslan Ermilov	    __MAKE_CONF=/dev/null \
287dd0f3923SRuslan Ermilov	    > _.${mach}.${kernel} 2>&1
288dd0f3923SRuslan Ermilov.endfor
2891f4f7670SRuslan Ermilov	@echo ">> ${mach} completed on `LC_ALL=C date`"
29077c1699fSPoul-Henning Kamp.endfor
2911f4f7670SRuslan Ermilov.endfor
292d18c9906SRuslan Ermilov.endfor
293d18c9906SRuslan Ermilovuniverse: universe_epilogue
294d18c9906SRuslan Ermilovuniverse_epilogue:
29577c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
2965ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
2975ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
29877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
299d18c9906SRuslan Ermilov.endif
300