xref: /freebsd/Makefile (revision 6cdaf31e)
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).
8eee8163bSBjoern A. Zeeb# tinderbox           - Same as universe, but presents a list of failed build
9eee8163bSBjoern A. Zeeb#                       targets and exits with an error if there were any.
1011fb97daSJohn Birrell# buildworld          - Rebuild *everything*, including glue to help do
1111fb97daSJohn Birrell#                       upgrades.
1211fb97daSJohn Birrell# installworld        - Install everything built by "buildworld".
13fb55e855STom Rhodes# world               - buildworld + installworld, no kernel.
1400eb8cbdSAlexander Langer# buildkernel         - Rebuild the kernel and the kernel-modules.
1500eb8cbdSAlexander Langer# installkernel       - Install the kernel and the kernel-modules.
160147d2aaSHidetoshi Shimokawa# installkernel.debug
17737ffab7SMark Murray# reinstallkernel     - Reinstall the kernel and the kernel-modules.
180147d2aaSHidetoshi Shimokawa# reinstallkernel.debug
19bc4311beSDavid E. O'Brien# kernel              - buildkernel + installkernel.
20589fec8bSWarner Losh# kernel-toolchain    - Builds the subset of world necessary to build a kernel
213e95821fSJuli Mallett# kernel-toolchains   - Build kernel-toolchain for all universe targets.
22becc5c62SAlexander Leidinger# doxygen             - Build API documentation of the kernel, needs doxygen.
2369c488cdSRuslan Ermilov# update              - Convenient way to update your source tree(s).
2432cd239bSDag-Erling Smørgrav# check-old           - List obsolete directories/files/libraries.
2532cd239bSDag-Erling Smørgrav# check-old-dirs      - List obsolete directories.
2632cd239bSDag-Erling Smørgrav# check-old-files     - List obsolete files.
2732cd239bSDag-Erling Smørgrav# check-old-libs      - List obsolete libraries.
28262eab04SSergey Kandaurov# delete-old          - Delete obsolete directories/files.
2932cd239bSDag-Erling Smørgrav# delete-old-dirs     - Delete obsolete directories.
3032cd239bSDag-Erling Smørgrav# delete-old-files    - Delete obsolete files.
3132cd239bSDag-Erling Smørgrav# delete-old-libs     - Delete obsolete libraries.
32f1d16bd8SBjoern A. Zeeb# targets             - Print a list of supported TARGET/TARGET_ARCH pairs
33f1d16bd8SBjoern A. Zeeb#                       for world and kernel targets.
344e889921SJohn Baldwin# toolchains          - Build a toolchain for all world and kernel targets.
352eabb61cSChristian Brueffer# xdev                - xdev-build + xdev-install for the architecture
362eabb61cSChristian Brueffer#                       specified with XDEV and XDEV_ARCH.
372eabb61cSChristian Brueffer# xdev-build          - Build cross-development tools.
382eabb61cSChristian Brueffer# xdev-install        - Install cross-development tools.
399e488366SWarner Losh# xdev-links          - Create traditional links in /usr/bin for cc, etc
4075872267SWarner Losh# native-xtools       - Create host binaries that produce target objects
4175872267SWarner Losh#                       for use in qemu user-mode jails.
423540f0e1SJordan K. Hubbard#
43a7abf892SAlfred Perlstein# "quick" way to test all kernel builds:
44a7abf892SAlfred Perlstein# 	_jflag=`sysctl -n hw.ncpu`
45a7abf892SAlfred Perlstein# 	_jflag=$(($_jflag * 2))
46a7abf892SAlfred Perlstein# 	[ $_jflag -gt 12 ] && _jflag=12
470ff7433dSAlfred Perlstein# 	make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
48a7abf892SAlfred Perlstein#
4911fb97daSJohn Birrell# This makefile is simple by design. The FreeBSD make automatically reads
5011fb97daSJohn Birrell# the /usr/share/mk/sys.mk unless the -m argument is specified on the
5111fb97daSJohn Birrell# command line. By keeping this makefile simple, it doesn't matter too
5211fb97daSJohn Birrell# much how different the installed mk files are from those in the source
5311fb97daSJohn Birrell# tree. This makefile executes a child make process, forcing it to use
5411fb97daSJohn Birrell# the mk files from the source tree which are supposed to DTRT.
5511fb97daSJohn Birrell#
563acc4367SWarner Losh# Most of the user-driven targets (as listed above) are implemented in
57ff34e7e3SWarner Losh# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
5811fb97daSJohn Birrell#
5976fdd728SJohn W. De Boskey# If you want to build your system from source be sure that /usr/obj has
6047c221b6SWarner Losh# at least 1GB of diskspace available.  A complete 'universe' build requires
6147c221b6SWarner Losh# about 15GB of space.
6211fb97daSJohn Birrell#
6376fdd728SJohn W. De Boskey# For individuals wanting to build from the sources currently on their
6476fdd728SJohn W. De Boskey# system, the simple instructions are:
6511fb97daSJohn Birrell#
6676fdd728SJohn W. De Boskey# 1.  `cd /usr/src'  (or to the directory containing your source tree).
67fb55e855STom Rhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
68fb55e855STom Rhodes# 3.  `make world'
6911fb97daSJohn Birrell#
7076fdd728SJohn W. De Boskey# For individuals wanting to upgrade their sources (even if only a
7176fdd728SJohn W. De Boskey# delta of a few days):
7276fdd728SJohn W. De Boskey#
7376fdd728SJohn W. De Boskey#  1.  `cd /usr/src'       (or to the directory containing your source tree).
7476fdd728SJohn W. De Boskey#  2.  `make buildworld'
7576fdd728SJohn W. De Boskey#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
7676fdd728SJohn W. De Boskey#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
772c5e89c2SDavid E. O'Brien#       [steps 3. & 4. can be combined by using the "kernel" target]
7876fdd728SJohn W. De Boskey#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
7976fdd728SJohn W. De Boskey#  6.  `mergemaster -p'
8076fdd728SJohn W. De Boskey#  7.  `make installworld'
81021a0587SChris Rees#  8.  `mergemaster'		(you may wish to use -i, along with -U or -F).
82021a0587SChris Rees#  9.  `make delete-old'
83e2a36081SAlexander Leidinger# 10.  `reboot'
84e2a36081SAlexander Leidinger# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
8576fdd728SJohn W. De Boskey#
8676fdd728SJohn W. De Boskey# See src/UPDATING `COMMON ITEMS' for more complete information.
8711fb97daSJohn Birrell#
8850f73640SMarcel Moolenaar# If TARGET=machine (e.g. powerpc, sparc64, ...) is specified you can
891fde59f3SRuslan Ermilov# cross build world for other machine types using the buildworld target,
90dbc3719dSMatthew Dillon# and once the world is built you can cross build a kernel using the
91dbc3719dSMatthew Dillon# buildkernel target.
92dbc3719dSMatthew Dillon#
9311fb97daSJohn Birrell# Define the user-driven targets. These are listed here in alphabetical
9411fb97daSJohn Birrell# order, but that's not important.
9511fb97daSJohn Birrell#
96ef7af95aSPeter Wemm# Targets that begin with underscore are internal targets intended for
97ef7af95aSPeter Wemm# developer convenience only.  They are intentionally not documented and
98ef7af95aSPeter Wemm# completely subject to change without notice.
99ef7af95aSPeter Wemm#
10079e19f08SJohn Baldwin# For more information, see the build(7) manual page.
10179e19f08SJohn Baldwin#
102054fbb2fSCraig Rodrigues.if ${MK_META_MODE:Uno} == "yes"
103aa9bd11dSSimon J. Gerraty# targets/Makefile plays the role of top-level
104aa9bd11dSSimon J. Gerraty.include "targets/Makefile"
105aa9bd11dSSimon J. Gerraty.else
106aa9bd11dSSimon J. Gerraty
10732cd239bSDag-Erling SmørgravTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
10832cd239bSDag-Erling Smørgrav	check-old check-old-dirs check-old-files check-old-libs \
10932cd239bSDag-Erling Smørgrav	checkdpadd clean cleandepend cleandir \
11032cd239bSDag-Erling Smørgrav	delete-old delete-old-dirs delete-old-files delete-old-libs \
11199ad39c8SNathan Whitehorn	depend distribute distributekernel distributekernel.debug \
11299ad39c8SNathan Whitehorn	distributeworld distrib-dirs distribution doxygen \
113e324b4bcSDavid E. O'Brien	everything hier hierarchy install installcheck installkernel \
11499ad39c8SNathan Whitehorn	installkernel.debug packagekernel packageworld \
11599ad39c8SNathan Whitehorn	reinstallkernel reinstallkernel.debug \
116becc5c62SAlexander Leidinger	installworld kernel-toolchain libraries lint maninstall \
117c3ed02cfSRuslan Ermilov	obj objlink regress rerelease showconfig tags toolchain update \
118ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
1191d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
1203c5326bfSRafal Jaworowski	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
12175872267SWarner Losh	xdev-links native-xtools \
1223c5326bfSRafal Jaworowski
123902f7c5bSRuslan ErmilovTGTS+=	${SUBDIR_TARGETS}
1246e59a256SMarcel Moolenaar
125af2dc868SRuslan ErmilovBITGTS=	files includes
12628d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
127b797df80SRuslan ErmilovTGTS+=	${BITGTS}
12828d2080aSRuslan Ermilov
129d672a609SRuslan Ermilov.ORDER: buildworld installworld
1308f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
13120902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
132d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
1330147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
134d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
1350147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
136d672a609SRuslan Ermilov
13776499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
1382e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
139e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
140f1fb2096SYaroslav Tykhiy    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
1410ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
1420ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
1430ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
144f1fb2096SYaroslav Tykhiy	(in make.conf(5)) or command-line variable.
1450ec443a0SRuslan Ermilov.endif
1464234b977SSimon J. Gerraty
1474234b977SSimon J. Gerraty# We often need to use the tree's version of make to build it.
1484234b977SSimon J. Gerraty# Choices add to complexity though.
1494234b977SSimon J. Gerraty# We cannot blindly use a make which may not be the one we want
1504234b977SSimon J. Gerraty# so be exlicit - until all choice is removed.
1514234b977SSimon J. GerratyWANT_MAKE=	bmake
1524234b977SSimon J. GerratyMYMAKE=		${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
1534234b977SSimon J. Gerraty.if defined(.PARSEDIR)
1544234b977SSimon J. GerratyHAVE_MAKE=	bmake
1554234b977SSimon J. Gerraty.else
1564234b977SSimon J. GerratyHAVE_MAKE=	fmake
1574234b977SSimon J. Gerraty.endif
1584234b977SSimon J. Gerraty.if exists(${MYMAKE})
1594234b977SSimon J. GerratySUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
160d0312744SWarner Losh.elif ${WANT_MAKE} != ${HAVE_MAKE}
1614234b977SSimon J. Gerraty# It may not exist yet but we may cause it to.
1624234b977SSimon J. Gerraty# In the case of fmake, upgrade_checks may cause a newer version to be built.
1634234b977SSimon J. GerratySUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
1645dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
1654234b977SSimon J. Gerraty.else
1664234b977SSimon J. GerratySUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
1674234b977SSimon J. Gerraty.endif
1684234b977SSimon J. Gerraty
1694234b977SSimon J. Gerraty_MAKE=	PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
170a962de47SPeter Wemm
171fda074e4SWarner Losh# Guess machine architecture from machine type, and vice versa.
172fda074e4SWarner Losh.if !defined(TARGET_ARCH) && defined(TARGET)
1738daa8167SAndrew Turner_TARGET_ARCH=	${TARGET:S/pc98/i386/:S/arm64/aarch64/}
174fda074e4SWarner Losh.elif !defined(TARGET) && defined(TARGET_ARCH) && \
175fda074e4SWarner Losh    ${TARGET_ARCH} != ${MACHINE_ARCH}
17628e1e3e2SWarner Losh_TARGET=		${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/aarch64/arm64/:C/powerpc64/powerpc/}
177fda074e4SWarner Losh.endif
178fda074e4SWarner Losh.if defined(TARGET) && !defined(_TARGET)
179fda074e4SWarner Losh_TARGET=${TARGET}
180fda074e4SWarner Losh.endif
181fda074e4SWarner Losh.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
182fda074e4SWarner Losh_TARGET_ARCH=${TARGET_ARCH}
183fda074e4SWarner Losh.endif
1840aafd404SWarner Losh# for historical compatibility for xdev targets
1850aafd404SWarner Losh.if defined(XDEV)
1860aafd404SWarner Losh_TARGET=	${XDEV}
1870aafd404SWarner Losh.endif
1880aafd404SWarner Losh.if defined(XDEV_ARCH)
1890aafd404SWarner Losh_TARGET_ARCH=	${XDEV_ARCH}
1900aafd404SWarner Losh.endif
191fda074e4SWarner Losh# Otherwise, default to current machine type and architecture.
192fda074e4SWarner Losh_TARGET?=	${MACHINE}
193fda074e4SWarner Losh_TARGET_ARCH?=	${MACHINE_ARCH}
194fda074e4SWarner Losh
195a962de47SPeter Wemm#
196d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
197d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
198d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
199d911f786SMarcel Moolenaar# for all targets.
200d911f786SMarcel Moolenaar#
201d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
202b797df80SRuslan Ermilov${TGTS}: upgrade_checks
203d911f786SMarcel Moolenaar.else
204d911f786SMarcel Moolenaarbuildworld: upgrade_checks
205d911f786SMarcel Moolenaar.endif
206d911f786SMarcel Moolenaar
207d911f786SMarcel Moolenaar#
208224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
2091a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
2101a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2111a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
2121a974787SGarance A Drosehn# in this makefile.
2131a974787SGarance A Drosehn#
2141a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
2151a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
216f73031b4SGlen Barber# files with file flags set, so this unsets them and tries the 'rm' a
2171a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
2181a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
219123ba50fSGlen Barber# needed to correctly handle all the possible situations.  Removing all
220f73031b4SGlen Barber# files without file flags set in the first 'rm' instance saves time,
221f73031b4SGlen Barber# because 'chflags' will need to operate on fewer files afterwards.
2221a974787SGarance A Drosehn#
2231a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
224224f0698SGarance A Drosehncleanworld:
2251a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2261a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
2271a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
22861858771SXin LI	-chflags -R 0 ${BW_CANONICALOBJDIR}
2291a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
2301a974787SGarance A Drosehn.endif
2311a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
232088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
2331a974787SGarance A Drosehn.else
2341a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
23561858771SXin LI	-chflags -R 0 ${.OBJDIR}
2361a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
2371a974787SGarance A Drosehn.endif
2382047c5d3SGarance A Drosehn
2392047c5d3SGarance A Drosehn#
24011fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
241f3c4dd0dSBruce Evans#
242d911f786SMarcel Moolenaar
243d3187057SSimon J. Gerraty.if empty(.MAKEFLAGS:M-n)
244d3187057SSimon J. Gerraty# skip this for -n to avoid changing previous behavior of
245d3187057SSimon J. Gerraty# 'make -n buildworld' etc.
246d3187057SSimon J. Gerraty${TGTS}: .MAKE
247a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: .MAKE
248d3187057SSimon J. Gerraty.endif
249d3187057SSimon J. Gerraty
250b797df80SRuslan Ermilov${TGTS}:
251b3840844SWarner Losh	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
252c3d9b0f0SRodney W. Grimes
2534b55d360SBrooks Davis# The historic default "all" target creates files which may cause stale
2544b55d360SBrooks Davis# or (in the cross build case) unlinkable results. Fail with an error
2554b55d360SBrooks Davis# when no target is given. The users can explicitly specify "all"
2564b55d360SBrooks Davis# if they want the historic behavior.
2574b55d360SBrooks Davis.MAIN:	_guard
2584b55d360SBrooks Davis
2594b55d360SBrooks Davis_guard:
2604b55d360SBrooks Davis	@echo
2614b55d360SBrooks Davis	@echo "Explicit target required (use \"all\" for historic behavior)"
2624b55d360SBrooks Davis	@echo
2634b55d360SBrooks Davis	@false
264ce53af53SJordan K. Hubbard
265afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
266f59c1f67SDavid E. O'BrienCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
267ec51d61fSRuslan Ermilov.if !empty(CHECK_TIME)
268ec51d61fSRuslan Ermilov.error check your date/time: ${STARTTIME}
269ec51d61fSRuslan Ermilov.endif
270d18c9906SRuslan Ermilov
271d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
2726e59a256SMarcel Moolenaar#
2736e59a256SMarcel Moolenaar# world
2746e59a256SMarcel Moolenaar#
2750a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
2760a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
2770a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
2780a945825SMarcel Moolenaar# then.
2796e59a256SMarcel Moolenaar#
2806e59a256SMarcel Moolenaarworld: upgrade_checks
2816e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2825ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
2836e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2846e59a256SMarcel Moolenaar.if target(pre-world)
2856e59a256SMarcel Moolenaar	@echo
2866e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2876e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
2886e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
289088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
2906e59a256SMarcel Moolenaar.endif
291088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
292088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
2936e59a256SMarcel Moolenaar.if target(post-world)
2946e59a256SMarcel Moolenaar	@echo
2956e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2966e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
2976e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
298088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
2996e59a256SMarcel Moolenaar.endif
3006e59a256SMarcel Moolenaar	@echo
3016e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
3025ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
3035ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
3046e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
3050a945825SMarcel Moolenaar.else
3060a945825SMarcel Moolenaarworld:
3070a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
3080a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
3090a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
3101f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
311954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
3120a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
313954c5b43SMark Murray	@echo ""
3140a945825SMarcel Moolenaar	@echo "Bailing out now..."
3150a945825SMarcel Moolenaar	@false
3160a945825SMarcel Moolenaar.endif
3176e59a256SMarcel Moolenaar
318cf94fb21SBruce Evans#
319d672a609SRuslan Ermilov# kernel
320d672a609SRuslan Ermilov#
321d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
322d672a609SRuslan Ermilov#
323d672a609SRuslan Ermilovkernel: buildkernel installkernel
324d672a609SRuslan Ermilov
325d672a609SRuslan Ermilov#
32611fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
327113cf9e6SRuslan Ermilov# for building the world.
32811fb97daSJohn Birrell#
3294234b977SSimon J. Gerraty# Note: if we ever need to care about the version of bmake, simply testing
3304234b977SSimon J. Gerraty# MAKE_VERSION against a required version should suffice.
3314234b977SSimon J. Gerraty#
33211fb97daSJohn Birrellupgrade_checks:
3334234b977SSimon J. Gerraty.if ${HAVE_MAKE} != ${WANT_MAKE}
3344234b977SSimon J. Gerraty	@(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
3350815243cSMarcel Moolenaar.endif
3366a8d432dSMark Murray
337a962de47SPeter Wemm#
3382e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
3396029ad99SWarner Losh# headers, libraries and tools.  Also, allow the location of
3406029ad99SWarner Losh# the system bsdmake-like utility to be overridden.
341549f978aSMarcel Moolenaar#
3424234b977SSimon J. GerratyMMAKEENV=	MAKEOBJDIRPREFIX=${MYMAKE:H} \
3432e84ab94SRuslan Ermilov		DESTDIR= \
3442e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
345e2be0fd0SWarner LoshMMAKE=		${MMAKEENV} ${MAKE} \
34693654dcaSWarner Losh		-DNO_MAN -DNO_SHARED \
3475b79f581SJulio Merino		-DNO_CPU_CFLAGS -DNO_WERROR \
3481dd381bfSJulio Merino		MK_TESTS=no \
3494d9b013aSWarner Losh		DESTDIR= PROGNAME=${MYMAKE:T}
3502e84ab94SRuslan Ermilov
3514d9b013aSWarner Loshbmake: .PHONY
352549f978aSMarcel Moolenaar	@echo
353549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
3544d9b013aSWarner Losh	@echo ">>> Building an up-to-date ${.TARGET}(1)"
355549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
35613c9cf4cSSimon J. Gerraty	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
357425df3c1SEd Maste		${MMAKE} obj && \
358425df3c1SEd Maste		${MMAKE} depend && \
359425df3c1SEd Maste		${MMAKE} all && \
3604d9b013aSWarner Losh		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
361549f978aSMarcel Moolenaar
362a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: upgrade_checks
363549f978aSMarcel Moolenaar
3644bb9ca57SAlfred Perlsteintinderbox:
365a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
3664e889921SJohn Baldwin
3674e889921SJohn Baldwintoolchains:
368a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
3694bb9ca57SAlfred Perlstein
3703e95821fSJuli Mallettkernel-toolchains:
371a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
3723e95821fSJuli Mallett
373549f978aSMarcel Moolenaar#
3741f4f7670SRuslan Ermilov# universe
3751f4f7670SRuslan Ermilov#
3761f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
377d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
3781f4f7670SRuslan Ermilov# existing system is.
3791f4f7670SRuslan Ermilov#
38064fe77a5SWarner Losh.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
381f384739dSEd Maste# XXX Add arm64 to universe only if we have an external binutils installed.
3823f29603dSEnji Cooper# It does not build with the in-tree linker.
383f384739dSEd Maste.if exists(/usr/local/aarch64-freebsd/bin/ld)
384504f34b3SEd MasteUNIVERSE_arm64=arm64
385504f34b3SEd Maste.elif empty(${TARGETS})
386f384739dSEd Masteuniverse: universe_arm64_skip
387f384739dSEd Masteuniverse_epilogue: universe_arm64_skip
388f384739dSEd Masteuniverse_arm64_skip: universe_prologue
389f384739dSEd Maste	@echo ">> arm64 skipped - install aarch64-binutils port or package to build"
390f384739dSEd Maste.endif
391504f34b3SEd MasteTARGETS?=amd64 arm ${UNIVERSE_arm64} i386 mips pc98 powerpc sparc64
39273279d41SAndrew TurnerTARGET_ARCHES_arm?=	arm armeb armv6 armv6hf
393504f34b3SEd MasteTARGET_ARCHES_arm64?=	aarch64
39484db023eSJuli MallettTARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32
3958e7c4a05SNathan WhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
3968e7c4a05SNathan WhitehornTARGET_ARCHES_pc98?=	i386
3978e7c4a05SNathan Whitehorn.for target in ${TARGETS}
3988e7c4a05SNathan WhitehornTARGET_ARCHES_${target}?= ${target}
3998e7c4a05SNathan Whitehorn.endfor
4001bdb3fb9SMarcel Moolenaar
4014e889921SJohn Baldwin.if defined(UNIVERSE_TARGET)
4024e889921SJohn BaldwinMAKE_JUST_WORLDS=	YES
4034e889921SJohn Baldwin.else
4044e889921SJohn BaldwinUNIVERSE_TARGET?=	buildworld
4054e889921SJohn Baldwin.endif
406141aca1fSJohn BaldwinKERNSRCDIR?=		${.CURDIR}/sys
4074e889921SJohn Baldwin
40864fe77a5SWarner Loshtargets:
409f1d16bd8SBjoern A. Zeeb	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
41064fe77a5SWarner Losh.for target in ${TARGETS}
41164fe77a5SWarner Losh.for target_arch in ${TARGET_ARCHES_${target}}
41264fe77a5SWarner Losh	@echo "    ${target}/${target_arch}"
41364fe77a5SWarner Losh.endfor
41464fe77a5SWarner Losh.endfor
41564fe77a5SWarner Losh
4164bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4172933a1ceSBjoern A. ZeebFAILFILE=${.CURDIR}/_.tinderbox.failed
4184bb9ca57SAlfred PerlsteinMAKEFAIL=tee -a ${FAILFILE}
4194bb9ca57SAlfred Perlstein.else
4204bb9ca57SAlfred PerlsteinMAKEFAIL=cat
4214bb9ca57SAlfred Perlstein.endif
4224bb9ca57SAlfred Perlstein
4234234b977SSimon J. Gerratyuniverse_prologue:  upgrade_checks
4244234b977SSimon J. Gerratyuniverse: universe_prologue
425d18c9906SRuslan Ermilovuniverse_prologue:
42677c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
42777c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
42877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4294bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4301ffa3abdSBjoern A. Zeeb	@rm -f ${FAILFILE}
4314bb9ca57SAlfred Perlstein.endif
4321bdb3fb9SMarcel Moolenaar.for target in ${TARGETS}
4331fde59f3SRuslan Ermilovuniverse: universe_${target}
4344234b977SSimon J. Gerratyuniverse_epilogue: universe_${target}
4358e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_prologue
4364234b977SSimon J. Gerratyuniverse_${target}_prologue: universe_prologue
4371fde59f3SRuslan Ermilov	@echo ">> ${target} started on `LC_ALL=C date`"
4388e7c4a05SNathan Whitehorn.if !defined(MAKE_JUST_KERNELS)
4398e7c4a05SNathan Whitehorn.for target_arch in ${TARGET_ARCHES_${target}}
4408e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_${target_arch}
441a6822ce8SSimon J. Gerratyuniverse_${target}_${target_arch}: universe_${target}_prologue .MAKE
4424e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
44333367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4444234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
4451fde59f3SRuslan Ermilov	    TARGET=${target} \
4468e7c4a05SNathan Whitehorn	    TARGET_ARCH=${target_arch} \
4474e889921SJohn Baldwin	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
4484e889921SJohn Baldwin	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
4494e889921SJohn Baldwin	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
4508e7c4a05SNathan Whitehorn	    ${MAKEFAIL}))
4514e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
4528e7c4a05SNathan Whitehorn.endfor
4536cdaf31eSAndrew Turner.endif # !MAKE_JUST_KERNELS
4546cdaf31eSAndrew Turner
4553453d746SDoug Barton.if !defined(MAKE_JUST_WORLDS)
45610098a6eSAndrew Turner# If we are building world and kernels wait for the required worlds to finish
45710098a6eSAndrew Turner.if !defined(MAKE_JUST_KERNELS)
45810098a6eSAndrew Turner.for target_arch in ${TARGET_ARCHES_${target}}
45910098a6eSAndrew Turneruniverse_${target}_kernels: universe_${target}_${target_arch}
46010098a6eSAndrew Turner.endfor
46110098a6eSAndrew Turner.endif
46210098a6eSAndrew Turneruniverse_${target}: universe_${target}_kernels
463a6822ce8SSimon J. Gerratyuniverse_${target}_kernels: universe_${target}_prologue .MAKE
464141aca1fSJohn Baldwin.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
465141aca1fSJohn Baldwin	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
4664234b977SSimon J. Gerraty	    ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
4674bb9ca57SAlfred Perlstein	    (echo "${target} 'make LINT' failed," \
4684bb9ca57SAlfred Perlstein	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
46977c1699fSPoul-Henning Kamp.endif
4704234b977SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
4713c55ed70SBjoern A. Zeeb	    universe_kernels
4726cdaf31eSAndrew Turner.endif # !MAKE_JUST_WORLDS
4733c55ed70SBjoern A. Zeeb	@echo ">> ${target} completed on `LC_ALL=C date`"
4743c55ed70SBjoern A. Zeeb.endfor
4753c55ed70SBjoern A. Zeebuniverse_kernels: universe_kernconfs
4765f5bb1d1SBjoern A. Zeeb.if !defined(TARGET)
4775f5bb1d1SBjoern A. ZeebTARGET!=	uname -m
4785f5bb1d1SBjoern A. Zeeb.endif
4797621eebbSWarner Losh.if defined(MAKE_ALL_KERNELS)
4807621eebbSWarner Losh_THINNER=cat
4817621eebbSWarner Losh.else
482e8bad5dcSWarner Losh_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
4837621eebbSWarner Losh.endif
484141aca1fSJohn BaldwinKERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
4853c55ed70SBjoern A. Zeeb		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
4867621eebbSWarner Losh		! -name DEFAULTS ! -name NOTES | \
4877621eebbSWarner Losh		${_THINNER}
4883c55ed70SBjoern A. Zeebuniverse_kernconfs:
489dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
490141aca1fSJohn BaldwinTARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
491141aca1fSJohn Baldwin	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
49292f64fb9SWarner Losh	grep -v WARNING: | cut -f 2
49392f64fb9SWarner Losh.if empty(TARGET_ARCH_${kernel})
49492f64fb9SWarner Losh.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
49592f64fb9SWarner Losh.endif
4968e7c4a05SNathan Whitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
497a6822ce8SSimon J. Gerratyuniverse_kernconf_${TARGET}_${kernel}: .MAKE
49833367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4994234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} buildkernel \
5003c55ed70SBjoern A. Zeeb	    TARGET=${TARGET} \
5018e7c4a05SNathan Whitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
502dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
5033c55ed70SBjoern A. Zeeb	    > _.${TARGET}.${kernel} 2>&1 || \
5043c55ed70SBjoern A. Zeeb	    (echo "${TARGET} ${kernel} kernel failed," \
5053c55ed70SBjoern A. Zeeb	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
506d18c9906SRuslan Ermilov.endfor
507d18c9906SRuslan Ermilovuniverse: universe_epilogue
508d18c9906SRuslan Ermilovuniverse_epilogue:
50977c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
5105ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
5115ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
51277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
5134bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
5144bb9ca57SAlfred Perlstein	@if [ -e ${FAILFILE} ] ; then \
5154bb9ca57SAlfred Perlstein		echo "Tinderbox failed:" ;\
5164bb9ca57SAlfred Perlstein		cat ${FAILFILE} ;\
5174bb9ca57SAlfred Perlstein		exit 1 ;\
5184bb9ca57SAlfred Perlstein	fi
5194bb9ca57SAlfred Perlstein.endif
520d18c9906SRuslan Ermilov.endif
5213c4ee57dSMarcel Moolenaar
5223c4ee57dSMarcel MoolenaarbuildLINT:
5233c4ee57dSMarcel Moolenaar	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
5245a968130SSimon J. Gerraty
5251b169702SSimon J. Gerraty# This makefile does not run in meta mode
5265a968130SSimon J. Gerraty.MAKE.MODE= normal
5271b169702SSimon J. Gerraty# Normally the things we run from here don't either.
5281fc3d968SSimon J. Gerraty# Using -DWITH_META_FILES
5291b169702SSimon J. Gerraty# we can buildworld with meta files created which are useful
5301b169702SSimon J. Gerraty# for debugging, but without any of the rest of a meta mode build.
5311fc3d968SSimon J. GerratyMK_META_MODE= no
5321fc3d968SSimon J. GerratyMK_STAGING= no
5331fc3d968SSimon J. Gerraty# tell meta.autodep.mk to not even think about updating anything.
5341b169702SSimon J. GerratyUPDATE_DEPENDFILE= NO
5351fc3d968SSimon J. Gerraty.export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE
536d466a5b0SSimon J. Gerraty
5377261834dSSimon J. Gerraty.if make(universe)
5387261834dSSimon J. Gerraty# we do not want a failure of one branch abort all.
5397261834dSSimon J. GerratyMAKE_JOB_ERROR_TOKEN= no
5407261834dSSimon J. Gerraty.export MAKE_JOB_ERROR_TOKEN
5417261834dSSimon J. Gerraty.endif
5421fc3d968SSimon J. Gerraty
5431fc3d968SSimon J. Gerraty.endif				# META_MODE
544