xref: /freebsd/Makefile (revision 0ec443a0)
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#
656bde859fSRuslan ErmilovTGTS=	all all-man buildkernel buildworld checkdpadd clean \
668f1f55e9SRuslan Ermilov	cleandepend cleandir depend distribute distributeworld everything \
670147d2aaSHidetoshi Shimokawa	hierarchy install installcheck installkernel installkernel.debug\
68829340b1SRuslan Ermilov	reinstallkernel reinstallkernel.debug installworld \
6943fc6762SDag-Erling Smørgrav	kernel-toolchain libraries lint maninstall \
70839274c7SRuslan Ermilov	obj objlink regress rerelease tags toolchain update \
71ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
72ef7af95aSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend
736e59a256SMarcel Moolenaar
74af2dc868SRuslan ErmilovBITGTS=	files includes
7528d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
76b797df80SRuslan ErmilovTGTS+=	${BITGTS}
7728d2080aSRuslan Ermilov
78d672a609SRuslan Ermilov.ORDER: buildworld installworld
798f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
8020902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
81d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
820147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
83d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
840147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
85d672a609SRuslan Ermilov
8676499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
872e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
880ec443a0SRuslan Ermilov_MAKEOBJDIRPREFIX!= env -i PATH=${PATH} MAKEFLAGS="${.MAKEFLAGS}" ${MAKE} \
890ec443a0SRuslan Ermilov		-f /dev/null -V MAKEOBJDIRPREFIX dummy
900ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
910ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
920ec443a0SRuslan Ermilov	(in /etc/make.conf) or command-line variable.
930ec443a0SRuslan Ermilov.endif
9476499f15SRuslan ErmilovMAKEPATH=	${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
95ead4296eSRuslan ErmilovBINMAKE= \
9676499f15SRuslan Ermilov	`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
975dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
98ead4296eSRuslan Ermilov_MAKE=	PATH=${PATH} ${BINMAKE} -f Makefile.inc1
99a962de47SPeter Wemm
100a962de47SPeter Wemm#
101d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
102d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
103d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
104d911f786SMarcel Moolenaar# for all targets.
105d911f786SMarcel Moolenaar#
106d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
107b797df80SRuslan Ermilov${TGTS}: upgrade_checks
108d911f786SMarcel Moolenaar.else
109d911f786SMarcel Moolenaarbuildworld: upgrade_checks
110d911f786SMarcel Moolenaar.endif
111d911f786SMarcel Moolenaar
112d911f786SMarcel Moolenaar#
113224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
1141a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
1151a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
1161a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
1171a974787SGarance A Drosehn# in this makefile.
1181a974787SGarance A Drosehn#
1191a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
1201a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
1211a974787SGarance A Drosehn# files with chflags set, so this unsets them and tries the 'rm' a
1221a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
1231a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
1241a974787SGarance A Drosehn# needed to correctly handle all the possible situations.
1251a974787SGarance A Drosehn#
1261a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
127224f0698SGarance A Drosehncleanworld:
1281a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
1291a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
1301a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
1311a974787SGarance A Drosehn	chflags -R 0 ${BW_CANONICALOBJDIR}
1321a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
1331a974787SGarance A Drosehn.endif
1341a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
135088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
1361a974787SGarance A Drosehn.else
1371a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
1381a974787SGarance A Drosehn	chflags -R 0 ${.OBJDIR}
1391a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
1401a974787SGarance A Drosehn.endif
1412047c5d3SGarance A Drosehn
1422047c5d3SGarance A Drosehn#
14311fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
144f3c4dd0dSBruce Evans#
145d911f786SMarcel Moolenaar
146b797df80SRuslan Ermilov${TGTS}:
147088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; \
14876499f15SRuslan Ermilov		${_MAKE} ${.TARGET}
149c3d9b0f0SRodney W. Grimes
150ce53af53SJordan K. Hubbard# Set a reasonable default
151ce53af53SJordan K. Hubbard.MAIN:	all
152ce53af53SJordan K. Hubbard
153954c5b43SMark Murray.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
1546e14763eSRuslan Ermilov.if make(world)
155afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
1566e14763eSRuslan Ermilov.endif
1576e59a256SMarcel Moolenaar#
1586e59a256SMarcel Moolenaar# world
1596e59a256SMarcel Moolenaar#
1600a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
1610a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
1620a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
1630a945825SMarcel Moolenaar# then.
1646e59a256SMarcel Moolenaar#
1656e59a256SMarcel Moolenaarworld: upgrade_checks
1666e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1675ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
1686e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1696e59a256SMarcel Moolenaar.if target(pre-world)
1706e59a256SMarcel Moolenaar	@echo
1716e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1726e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
1736e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
174088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
1756e59a256SMarcel Moolenaar.endif
176088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
177088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
1786e59a256SMarcel Moolenaar.if target(post-world)
1796e59a256SMarcel Moolenaar	@echo
1806e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1816e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
1826e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
183088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
1846e59a256SMarcel Moolenaar.endif
1856e59a256SMarcel Moolenaar	@echo
1866e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1875ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
1885ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
1896e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
1900a945825SMarcel Moolenaar.else
1910a945825SMarcel Moolenaarworld:
1920a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
1930a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
1940a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
1951f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
196954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
1970a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
198954c5b43SMark Murray	@echo "You may get the historical 'make world' behavior by defining"
199954c5b43SMark Murray	@echo "HISTORICAL_MAKE_WORLD.  You should understand the implications"
200954c5b43SMark Murray	@echo "before doing this."
201954c5b43SMark Murray	@echo ""
2020a945825SMarcel Moolenaar	@echo "Bailing out now..."
2030a945825SMarcel Moolenaar	@false
2040a945825SMarcel Moolenaar.endif
2056e59a256SMarcel Moolenaar
206cf94fb21SBruce Evans#
207d672a609SRuslan Ermilov# kernel
208d672a609SRuslan Ermilov#
209d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
210d672a609SRuslan Ermilov#
211d672a609SRuslan Ermilovkernel: buildkernel installkernel
212d672a609SRuslan Ermilov
213d672a609SRuslan Ermilov#
21411fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
215113cf9e6SRuslan Ermilov# for building the world.
21611fb97daSJohn Birrell#
21711fb97daSJohn Birrellupgrade_checks:
21876499f15SRuslan Ermilov	@if ! (cd ${.CURDIR}/tools/regression/usr.bin/make && \
219ef2c779bSRuslan Ermilov	    PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
22076499f15SRuslan Ermilov	then \
22176499f15SRuslan Ermilov	    (cd ${.CURDIR} && make make); \
22276499f15SRuslan Ermilov	fi
2236a8d432dSMark Murray
224a962de47SPeter Wemm#
2252e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
226113cf9e6SRuslan Ermilov# headers, libraries and tools.
227549f978aSMarcel Moolenaar#
2282e84ab94SRuslan ErmilovMMAKEENV=	MAKEOBJDIRPREFIX=${MAKEPATH} \
2292e84ab94SRuslan Ermilov		DESTDIR= \
2302e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
2312e84ab94SRuslan ErmilovMMAKE=		${MMAKEENV} make \
2322e84ab94SRuslan Ermilov		-D_UPGRADING \
2332e84ab94SRuslan Ermilov		-DNOMAN -DNOSHARED \
2342e84ab94SRuslan Ermilov		-DNO_CPU_CFLAGS -DNO_WERROR
2352e84ab94SRuslan Ermilov
2362a6e9f88SKris Kennawaymake: .PHONY
237549f978aSMarcel Moolenaar	@echo
238549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
239b31745f5SRuslan Ermilov	@echo ">>> Building an up-to-date make(1)"
240549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
241088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}/usr.bin/make; \
2422e84ab94SRuslan Ermilov		${MMAKE} obj && \
2432e84ab94SRuslan Ermilov		${MMAKE} depend && \
2442e84ab94SRuslan Ermilov		${MMAKE} all && \
2452e84ab94SRuslan Ermilov		${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
246549f978aSMarcel Moolenaar
247549f978aSMarcel Moolenaar#
2481f4f7670SRuslan Ermilov# universe
2491f4f7670SRuslan Ermilov#
2501f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
2511f4f7670SRuslan Ermilov# with reasonable chance of success, regardless of how old your
2521f4f7670SRuslan Ermilov# existing system is.
2531f4f7670SRuslan Ermilov#
2541f4f7670SRuslan Ermilovi386_mach=	pc98
25577c1699fSPoul-Henning Kampuniverse:
25677c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
25777c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
25877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
259506f4c06SJohan Karlsson.for arch in i386 sparc64 alpha ia64 amd64
2601f4f7670SRuslan Ermilov.for mach in ${arch} ${${arch}_mach}
2611f4f7670SRuslan Ermilov	@echo ">> ${mach} started on `LC_ALL=C date`"
2620d4e175dSPoul-Henning Kamp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildworld \
2631f4f7670SRuslan Ermilov	    TARGET_ARCH=${arch} TARGET=${mach} \
26477c1699fSPoul-Henning Kamp	    __MAKE_CONF=/dev/null \
2651f4f7670SRuslan Ermilov	    > _.${mach}.buildworld 2>&1
2661f4f7670SRuslan Ermilov	@echo ">> ${mach} buildworld completed on `LC_ALL=C date`"
2671f4f7670SRuslan Ermilov.if exists(${.CURDIR}/sys/${mach}/conf/NOTES)
2681f4f7670SRuslan Ermilov	-cd ${.CURDIR}/sys/${mach}/conf && ${MAKE} LINT \
269301c4069SRuslan Ermilov	    > ${.CURDIR}/_.${mach}.makeLINT 2>&1
27077c1699fSPoul-Henning Kamp.endif
2710d4e175dSPoul-Henning Kamp	cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernels TARGET_ARCH=${arch} TARGET=${mach}
2721f4f7670SRuslan Ermilov	@echo ">> ${mach} completed on `LC_ALL=C date`"
27377c1699fSPoul-Henning Kamp.endfor
2741f4f7670SRuslan Ermilov.endfor
27577c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
2765ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
2775ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
27877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
27977c1699fSPoul-Henning Kamp
2806e14763eSRuslan Ermilov.if make(buildkernels)
2811f4f7670SRuslan ErmilovKERNCONFS!=	cd ${.CURDIR}/sys/${TARGET}/conf && \
2821f4f7670SRuslan Ermilov		find [A-Z]*[A-Z] -type f -maxdepth 0 ! -name NOTES
2836e14763eSRuslan Ermilov.endif
28477c1699fSPoul-Henning Kamp
28577c1699fSPoul-Henning Kampbuildkernels:
2861f4f7670SRuslan Ermilov.for kernel in ${KERNCONFS}
2870d4e175dSPoul-Henning Kamp	-cd ${.CURDIR} && ${MAKE} ${JFLAG} buildkernel \
2881f4f7670SRuslan Ermilov	    KERNCONF=${kernel} \
28977c1699fSPoul-Henning Kamp	    __MAKE_CONF=/dev/null \
2901f4f7670SRuslan Ermilov	    > _.${TARGET}.${kernel} 2>&1
29177c1699fSPoul-Henning Kamp.endfor
292