xref: /freebsd/Makefile (revision e07b2be5)
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#
10235c9a2a9SWarner Losh
10335c9a2a9SWarner Losh# Note: we use this awkward construct to be compatible with FreeBSD's
10435c9a2a9SWarner Losh# old make used in 10.0 and 9.2 and earlier.
1051c9b3241SSimon J. Gerraty.if defined(MK_META_MODE) && ${MK_META_MODE} == "yes" && !make(showconfig)
106aa9bd11dSSimon J. Gerraty# targets/Makefile plays the role of top-level
107aa9bd11dSSimon J. Gerraty.include "targets/Makefile"
108aa9bd11dSSimon J. Gerraty.else
109aa9bd11dSSimon J. Gerraty
11032cd239bSDag-Erling SmørgravTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
11132cd239bSDag-Erling Smørgrav	check-old check-old-dirs check-old-files check-old-libs \
11232cd239bSDag-Erling Smørgrav	checkdpadd clean cleandepend cleandir \
11332cd239bSDag-Erling Smørgrav	delete-old delete-old-dirs delete-old-files delete-old-libs \
11499ad39c8SNathan Whitehorn	depend distribute distributekernel distributekernel.debug \
11599ad39c8SNathan Whitehorn	distributeworld distrib-dirs distribution doxygen \
116e324b4bcSDavid E. O'Brien	everything hier hierarchy install installcheck installkernel \
11799ad39c8SNathan Whitehorn	installkernel.debug packagekernel packageworld \
11899ad39c8SNathan Whitehorn	reinstallkernel reinstallkernel.debug \
119becc5c62SAlexander Leidinger	installworld kernel-toolchain libraries lint maninstall \
120c3ed02cfSRuslan Ermilov	obj objlink regress rerelease showconfig tags toolchain update \
121ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
1221d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
1233c5326bfSRafal Jaworowski	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
1242bcf1d42SBaptiste Daroussin	xdev-links native-xtools installconfig \
1253c5326bfSRafal Jaworowski
126902f7c5bSRuslan ErmilovTGTS+=	${SUBDIR_TARGETS}
1276e59a256SMarcel Moolenaar
128af2dc868SRuslan ErmilovBITGTS=	files includes
12928d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
130b797df80SRuslan ErmilovTGTS+=	${BITGTS}
13128d2080aSRuslan Ermilov
132d672a609SRuslan Ermilov.ORDER: buildworld installworld
1338f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
13420902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
135d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
1360147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
137d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
1380147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
139d672a609SRuslan Ermilov
14076499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
1412e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
142e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
143f1fb2096SYaroslav Tykhiy    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
1440ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
1450ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
1460ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
147f1fb2096SYaroslav Tykhiy	(in make.conf(5)) or command-line variable.
1480ec443a0SRuslan Ermilov.endif
1494234b977SSimon J. Gerraty
1504234b977SSimon J. Gerraty# We often need to use the tree's version of make to build it.
1514234b977SSimon J. Gerraty# Choices add to complexity though.
1524234b977SSimon J. Gerraty# We cannot blindly use a make which may not be the one we want
1534234b977SSimon J. Gerraty# so be exlicit - until all choice is removed.
1544234b977SSimon J. GerratyWANT_MAKE=	bmake
1554234b977SSimon J. GerratyMYMAKE=		${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
1564234b977SSimon J. Gerraty.if defined(.PARSEDIR)
1574234b977SSimon J. GerratyHAVE_MAKE=	bmake
1584234b977SSimon J. Gerraty.else
1594234b977SSimon J. GerratyHAVE_MAKE=	fmake
1604234b977SSimon J. Gerraty.endif
1614234b977SSimon J. Gerraty.if exists(${MYMAKE})
1624234b977SSimon J. GerratySUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
163d0312744SWarner Losh.elif ${WANT_MAKE} != ${HAVE_MAKE}
1644234b977SSimon J. Gerraty# It may not exist yet but we may cause it to.
1654234b977SSimon J. Gerraty# In the case of fmake, upgrade_checks may cause a newer version to be built.
1664234b977SSimon J. GerratySUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
1675dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
1684234b977SSimon J. Gerraty.else
1694234b977SSimon J. GerratySUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
1704234b977SSimon J. Gerraty.endif
1714234b977SSimon J. Gerraty
1724234b977SSimon J. Gerraty_MAKE=	PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
173a962de47SPeter Wemm
174fda074e4SWarner Losh# Guess machine architecture from machine type, and vice versa.
175fda074e4SWarner Losh.if !defined(TARGET_ARCH) && defined(TARGET)
1768daa8167SAndrew Turner_TARGET_ARCH=	${TARGET:S/pc98/i386/:S/arm64/aarch64/}
177fda074e4SWarner Losh.elif !defined(TARGET) && defined(TARGET_ARCH) && \
178fda074e4SWarner Losh    ${TARGET_ARCH} != ${MACHINE_ARCH}
17928e1e3e2SWarner Losh_TARGET=		${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/aarch64/arm64/:C/powerpc64/powerpc/}
180fda074e4SWarner Losh.endif
181fda074e4SWarner Losh.if defined(TARGET) && !defined(_TARGET)
182fda074e4SWarner Losh_TARGET=${TARGET}
183fda074e4SWarner Losh.endif
184fda074e4SWarner Losh.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
185fda074e4SWarner Losh_TARGET_ARCH=${TARGET_ARCH}
186fda074e4SWarner Losh.endif
1870aafd404SWarner Losh# for historical compatibility for xdev targets
1880aafd404SWarner Losh.if defined(XDEV)
1890aafd404SWarner Losh_TARGET=	${XDEV}
1900aafd404SWarner Losh.endif
1910aafd404SWarner Losh.if defined(XDEV_ARCH)
1920aafd404SWarner Losh_TARGET_ARCH=	${XDEV_ARCH}
1930aafd404SWarner Losh.endif
194fda074e4SWarner Losh# Otherwise, default to current machine type and architecture.
195fda074e4SWarner Losh_TARGET?=	${MACHINE}
196fda074e4SWarner Losh_TARGET_ARCH?=	${MACHINE_ARCH}
197fda074e4SWarner Losh
198a962de47SPeter Wemm#
199d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
200d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
201d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
202d911f786SMarcel Moolenaar# for all targets.
203d911f786SMarcel Moolenaar#
204d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
205b797df80SRuslan Ermilov${TGTS}: upgrade_checks
206d911f786SMarcel Moolenaar.else
207d911f786SMarcel Moolenaarbuildworld: upgrade_checks
208d911f786SMarcel Moolenaar.endif
209d911f786SMarcel Moolenaar
210d911f786SMarcel Moolenaar#
211224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
2121a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
2131a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2141a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
2151a974787SGarance A Drosehn# in this makefile.
2161a974787SGarance A Drosehn#
2171a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
2181a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
219f73031b4SGlen Barber# files with file flags set, so this unsets them and tries the 'rm' a
2201a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
2211a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
222123ba50fSGlen Barber# needed to correctly handle all the possible situations.  Removing all
223f73031b4SGlen Barber# files without file flags set in the first 'rm' instance saves time,
224f73031b4SGlen Barber# because 'chflags' will need to operate on fewer files afterwards.
2251a974787SGarance A Drosehn#
2261a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
227224f0698SGarance A Drosehncleanworld:
2281a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2291a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
2301a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
23161858771SXin LI	-chflags -R 0 ${BW_CANONICALOBJDIR}
2321a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
2331a974787SGarance A Drosehn.endif
2341a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
235088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
2361a974787SGarance A Drosehn.else
2371a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
23861858771SXin LI	-chflags -R 0 ${.OBJDIR}
2391a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
2401a974787SGarance A Drosehn.endif
2412047c5d3SGarance A Drosehn
2422047c5d3SGarance A Drosehn#
24311fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
244f3c4dd0dSBruce Evans#
245d911f786SMarcel Moolenaar
246fa5e9cbbSBryan Drewery.if !(!empty(.MAKEFLAGS:M-n) && ${.MAKEFLAGS:M-n} == "-n")
247d3187057SSimon J. Gerraty# skip this for -n to avoid changing previous behavior of
248fa5e9cbbSBryan Drewery# 'make -n buildworld' etc.  Using -n -n will run it.
249d3187057SSimon J. Gerraty${TGTS}: .MAKE
250a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: .MAKE
251d3187057SSimon J. Gerraty.endif
252d3187057SSimon J. Gerraty
253ba831a2cSBryan Drewery${TGTS}: .PHONY
254b3840844SWarner Losh	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
255c3d9b0f0SRodney W. Grimes
2564b55d360SBrooks Davis# The historic default "all" target creates files which may cause stale
2574b55d360SBrooks Davis# or (in the cross build case) unlinkable results. Fail with an error
2584b55d360SBrooks Davis# when no target is given. The users can explicitly specify "all"
2594b55d360SBrooks Davis# if they want the historic behavior.
2604b55d360SBrooks Davis.MAIN:	_guard
2614b55d360SBrooks Davis
262824f98d3SBryan Drewery_guard: .PHONY
2634b55d360SBrooks Davis	@echo
264e07b2be5SBryan Drewery	@echo "Explicit target required.  Likely \"${SUBDIR_OVERRIDE:Dall:Ubuildworld}\" is wanted.  See build(7)."
2654b55d360SBrooks Davis	@echo
2664b55d360SBrooks Davis	@false
267ce53af53SJordan K. Hubbard
268afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
269f59c1f67SDavid E. O'BrienCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
270ec51d61fSRuslan Ermilov.if !empty(CHECK_TIME)
271ec51d61fSRuslan Ermilov.error check your date/time: ${STARTTIME}
272ec51d61fSRuslan Ermilov.endif
273d18c9906SRuslan Ermilov
274d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
2756e59a256SMarcel Moolenaar#
2766e59a256SMarcel Moolenaar# world
2776e59a256SMarcel Moolenaar#
2780a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
2790a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
2800a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
2810a945825SMarcel Moolenaar# then.
2826e59a256SMarcel Moolenaar#
2836e59a256SMarcel Moolenaarworld: upgrade_checks
2846e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2855ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
2866e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2876e59a256SMarcel Moolenaar.if target(pre-world)
2886e59a256SMarcel Moolenaar	@echo
2896e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2906e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
2916e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
292088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
2936e59a256SMarcel Moolenaar.endif
294088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
295088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
2966e59a256SMarcel Moolenaar.if target(post-world)
2976e59a256SMarcel Moolenaar	@echo
2986e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2996e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
3006e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
301088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
3026e59a256SMarcel Moolenaar.endif
3036e59a256SMarcel Moolenaar	@echo
3046e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
3055ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
3065ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
3076e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
3080a945825SMarcel Moolenaar.else
3090a945825SMarcel Moolenaarworld:
3100a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
3110a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
3120a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
3131f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
314954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
3150a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
316954c5b43SMark Murray	@echo ""
3170a945825SMarcel Moolenaar	@echo "Bailing out now..."
3180a945825SMarcel Moolenaar	@false
3190a945825SMarcel Moolenaar.endif
3206e59a256SMarcel Moolenaar
321cf94fb21SBruce Evans#
322d672a609SRuslan Ermilov# kernel
323d672a609SRuslan Ermilov#
324d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
325d672a609SRuslan Ermilov#
326d672a609SRuslan Ermilovkernel: buildkernel installkernel
327d672a609SRuslan Ermilov
328d672a609SRuslan Ermilov#
32911fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
330113cf9e6SRuslan Ermilov# for building the world.
33111fb97daSJohn Birrell#
3324234b977SSimon J. Gerraty# Note: if we ever need to care about the version of bmake, simply testing
3334234b977SSimon J. Gerraty# MAKE_VERSION against a required version should suffice.
3344234b977SSimon J. Gerraty#
33511fb97daSJohn Birrellupgrade_checks:
3364234b977SSimon J. Gerraty.if ${HAVE_MAKE} != ${WANT_MAKE}
3374234b977SSimon J. Gerraty	@(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
3380815243cSMarcel Moolenaar.endif
3396a8d432dSMark Murray
340a962de47SPeter Wemm#
3412e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
3426029ad99SWarner Losh# headers, libraries and tools.  Also, allow the location of
3436029ad99SWarner Losh# the system bsdmake-like utility to be overridden.
344549f978aSMarcel Moolenaar#
3454234b977SSimon J. GerratyMMAKEENV=	MAKEOBJDIRPREFIX=${MYMAKE:H} \
3462e84ab94SRuslan Ermilov		DESTDIR= \
3472e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
348e2be0fd0SWarner LoshMMAKE=		${MMAKEENV} ${MAKE} \
34993654dcaSWarner Losh		-DNO_MAN -DNO_SHARED \
3505b79f581SJulio Merino		-DNO_CPU_CFLAGS -DNO_WERROR \
3511dd381bfSJulio Merino		MK_TESTS=no \
3524d9b013aSWarner Losh		DESTDIR= PROGNAME=${MYMAKE:T}
3532e84ab94SRuslan Ermilov
3544d9b013aSWarner Loshbmake: .PHONY
355549f978aSMarcel Moolenaar	@echo
356549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
3574d9b013aSWarner Losh	@echo ">>> Building an up-to-date ${.TARGET}(1)"
358549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
35913c9cf4cSSimon J. Gerraty	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
360425df3c1SEd Maste		${MMAKE} obj && \
361425df3c1SEd Maste		${MMAKE} depend && \
362425df3c1SEd Maste		${MMAKE} all && \
3634d9b013aSWarner Losh		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
364549f978aSMarcel Moolenaar
365a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: upgrade_checks
366549f978aSMarcel Moolenaar
3674bb9ca57SAlfred Perlsteintinderbox:
368a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
3694e889921SJohn Baldwin
3704e889921SJohn Baldwintoolchains:
371a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
3724bb9ca57SAlfred Perlstein
3733e95821fSJuli Mallettkernel-toolchains:
374a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
3753e95821fSJuli Mallett
376549f978aSMarcel Moolenaar#
3771f4f7670SRuslan Ermilov# universe
3781f4f7670SRuslan Ermilov#
3791f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
380d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
3811f4f7670SRuslan Ermilov# existing system is.
3821f4f7670SRuslan Ermilov#
38364fe77a5SWarner Losh.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
384a87f765bSBryan DreweryTARGETS?=amd64 arm arm64 i386 mips pc98 powerpc sparc64
385a87f765bSBryan Drewery_UNIVERSE_TARGETS=	${TARGETS}
38673279d41SAndrew TurnerTARGET_ARCHES_arm?=	arm armeb armv6 armv6hf
387504f34b3SEd MasteTARGET_ARCHES_arm64?=	aarch64
38884db023eSJuli MallettTARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32
3898e7c4a05SNathan WhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
3908e7c4a05SNathan WhitehornTARGET_ARCHES_pc98?=	i386
391a87f765bSBryan Drewery.for target in ${TARGETS}
3928e7c4a05SNathan WhitehornTARGET_ARCHES_${target}?= ${target}
3938e7c4a05SNathan Whitehorn.endfor
3941bdb3fb9SMarcel Moolenaar
395a87f765bSBryan Drewery# XXX Add arm64 to universe only if we have an external binutils installed.
396a87f765bSBryan Drewery# It does not build with the in-tree linker.
397a87f765bSBryan Drewery.if !exists(/usr/local/aarch64-freebsd/bin/ld) && empty(${TARGETS})
398a87f765bSBryan Drewery_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:Narm64}
399a87f765bSBryan Dreweryuniverse: universe_arm64_skip
400a87f765bSBryan Dreweryuniverse_epilogue: universe_arm64_skip
401a87f765bSBryan Dreweryuniverse_arm64_skip: universe_prologue
402a87f765bSBryan Drewery	@echo ">> arm64 skipped - install aarch64-binutils port or package to build"
403a87f765bSBryan Drewery.endif
404a87f765bSBryan Drewery
4054e889921SJohn Baldwin.if defined(UNIVERSE_TARGET)
4064e889921SJohn BaldwinMAKE_JUST_WORLDS=	YES
4074e889921SJohn Baldwin.else
4084e889921SJohn BaldwinUNIVERSE_TARGET?=	buildworld
4094e889921SJohn Baldwin.endif
410141aca1fSJohn BaldwinKERNSRCDIR?=		${.CURDIR}/sys
4114e889921SJohn Baldwin
41265faab7fSSimon J. Gerratytargets:	.PHONY
413f1d16bd8SBjoern A. Zeeb	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
414a87f765bSBryan Drewery.for target in ${TARGETS}
41564fe77a5SWarner Losh.for target_arch in ${TARGET_ARCHES_${target}}
41664fe77a5SWarner Losh	@echo "    ${target}/${target_arch}"
41764fe77a5SWarner Losh.endfor
41864fe77a5SWarner Losh.endfor
41964fe77a5SWarner Losh
4204bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4212933a1ceSBjoern A. ZeebFAILFILE=${.CURDIR}/_.tinderbox.failed
4224bb9ca57SAlfred PerlsteinMAKEFAIL=tee -a ${FAILFILE}
4234bb9ca57SAlfred Perlstein.else
4244bb9ca57SAlfred PerlsteinMAKEFAIL=cat
4254bb9ca57SAlfred Perlstein.endif
4264bb9ca57SAlfred Perlstein
4274234b977SSimon J. Gerratyuniverse_prologue:  upgrade_checks
4284234b977SSimon J. Gerratyuniverse: universe_prologue
429d18c9906SRuslan Ermilovuniverse_prologue:
43077c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
43177c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
43277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4334bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4341ffa3abdSBjoern A. Zeeb	@rm -f ${FAILFILE}
4354bb9ca57SAlfred Perlstein.endif
436a87f765bSBryan Drewery.for target in ${_UNIVERSE_TARGETS}
4371fde59f3SRuslan Ermilovuniverse: universe_${target}
4384234b977SSimon J. Gerratyuniverse_epilogue: universe_${target}
4398e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_prologue
4404234b977SSimon J. Gerratyuniverse_${target}_prologue: universe_prologue
4411fde59f3SRuslan Ermilov	@echo ">> ${target} started on `LC_ALL=C date`"
442149da95cSAndrew Turneruniverse_${target}_worlds:
443149da95cSAndrew Turner
4448e7c4a05SNathan Whitehorn.if !defined(MAKE_JUST_KERNELS)
445d667f112SAndrew Turneruniverse_${target}_done: universe_${target}_worlds
4468e7c4a05SNathan Whitehorn.for target_arch in ${TARGET_ARCHES_${target}}
447149da95cSAndrew Turneruniverse_${target}_worlds: universe_${target}_${target_arch}
448a6822ce8SSimon J. Gerratyuniverse_${target}_${target_arch}: universe_${target}_prologue .MAKE
4494e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
45033367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4514234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
4521fde59f3SRuslan Ermilov	    TARGET=${target} \
4538e7c4a05SNathan Whitehorn	    TARGET_ARCH=${target_arch} \
4544e889921SJohn Baldwin	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
4554e889921SJohn Baldwin	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
4564e889921SJohn Baldwin	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
4578e7c4a05SNathan Whitehorn	    ${MAKEFAIL}))
4584e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
4598e7c4a05SNathan Whitehorn.endfor
4606cdaf31eSAndrew Turner.endif # !MAKE_JUST_KERNELS
4616cdaf31eSAndrew Turner
4623453d746SDoug Barton.if !defined(MAKE_JUST_WORLDS)
4631272c4aaSAndrew Turneruniverse_${target}_done: universe_${target}_kernels
464149da95cSAndrew Turneruniverse_${target}_kernels: universe_${target}_worlds
465a6822ce8SSimon J. Gerratyuniverse_${target}_kernels: universe_${target}_prologue .MAKE
466141aca1fSJohn Baldwin.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
467141aca1fSJohn Baldwin	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
4684234b977SSimon J. Gerraty	    ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
4694bb9ca57SAlfred Perlstein	    (echo "${target} 'make LINT' failed," \
4704bb9ca57SAlfred Perlstein	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
47177c1699fSPoul-Henning Kamp.endif
4724234b977SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
4733c55ed70SBjoern A. Zeeb	    universe_kernels
4746cdaf31eSAndrew Turner.endif # !MAKE_JUST_WORLDS
4751272c4aaSAndrew Turner
4761272c4aaSAndrew Turner# Tell the user the worlds and kernels have completed
4771272c4aaSAndrew Turneruniverse_${target}: universe_${target}_done
4781272c4aaSAndrew Turneruniverse_${target}_done:
4793c55ed70SBjoern A. Zeeb	@echo ">> ${target} completed on `LC_ALL=C date`"
4803c55ed70SBjoern A. Zeeb.endfor
4813c55ed70SBjoern A. Zeebuniverse_kernels: universe_kernconfs
4825f5bb1d1SBjoern A. Zeeb.if !defined(TARGET)
4835f5bb1d1SBjoern A. ZeebTARGET!=	uname -m
4845f5bb1d1SBjoern A. Zeeb.endif
4857621eebbSWarner Losh.if defined(MAKE_ALL_KERNELS)
4867621eebbSWarner Losh_THINNER=cat
4877621eebbSWarner Losh.else
488e8bad5dcSWarner Losh_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
4897621eebbSWarner Losh.endif
490141aca1fSJohn BaldwinKERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
4913c55ed70SBjoern A. Zeeb		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
4927621eebbSWarner Losh		! -name DEFAULTS ! -name NOTES | \
4937621eebbSWarner Losh		${_THINNER}
4943c55ed70SBjoern A. Zeebuniverse_kernconfs:
495dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
496141aca1fSJohn BaldwinTARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
497141aca1fSJohn Baldwin	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
49892f64fb9SWarner Losh	grep -v WARNING: | cut -f 2
49992f64fb9SWarner Losh.if empty(TARGET_ARCH_${kernel})
50092f64fb9SWarner Losh.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
50192f64fb9SWarner Losh.endif
5028e7c4a05SNathan Whitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
503a6822ce8SSimon J. Gerratyuniverse_kernconf_${TARGET}_${kernel}: .MAKE
50433367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
5054234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} buildkernel \
5063c55ed70SBjoern A. Zeeb	    TARGET=${TARGET} \
5078e7c4a05SNathan Whitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
508dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
5093c55ed70SBjoern A. Zeeb	    > _.${TARGET}.${kernel} 2>&1 || \
5103c55ed70SBjoern A. Zeeb	    (echo "${TARGET} ${kernel} kernel failed," \
5113c55ed70SBjoern A. Zeeb	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
512d18c9906SRuslan Ermilov.endfor
513d18c9906SRuslan Ermilovuniverse: universe_epilogue
514d18c9906SRuslan Ermilovuniverse_epilogue:
51577c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
5165ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
5175ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
51877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
5194bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
5204bb9ca57SAlfred Perlstein	@if [ -e ${FAILFILE} ] ; then \
5214bb9ca57SAlfred Perlstein		echo "Tinderbox failed:" ;\
5224bb9ca57SAlfred Perlstein		cat ${FAILFILE} ;\
5234bb9ca57SAlfred Perlstein		exit 1 ;\
5244bb9ca57SAlfred Perlstein	fi
5254bb9ca57SAlfred Perlstein.endif
526d18c9906SRuslan Ermilov.endif
5273c4ee57dSMarcel Moolenaar
5283c4ee57dSMarcel MoolenaarbuildLINT:
5293c4ee57dSMarcel Moolenaar	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
5305a968130SSimon J. Gerraty
53135c9a2a9SWarner Losh.if defined(.PARSEDIR)
5321b169702SSimon J. Gerraty# This makefile does not run in meta mode
5335a968130SSimon J. Gerraty.MAKE.MODE= normal
5341b169702SSimon J. Gerraty# Normally the things we run from here don't either.
5351fc3d968SSimon J. Gerraty# Using -DWITH_META_FILES
5361b169702SSimon J. Gerraty# we can buildworld with meta files created which are useful
5371b169702SSimon J. Gerraty# for debugging, but without any of the rest of a meta mode build.
5381fc3d968SSimon J. GerratyMK_META_MODE= no
5391fc3d968SSimon J. GerratyMK_STAGING= no
5401fc3d968SSimon J. Gerraty# tell meta.autodep.mk to not even think about updating anything.
5411b169702SSimon J. GerratyUPDATE_DEPENDFILE= NO
5421c9b3241SSimon J. Gerraty.if !make(showconfig)
5431fc3d968SSimon J. Gerraty.export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE
5441c9b3241SSimon J. Gerraty.endif
545d466a5b0SSimon J. Gerraty
5467261834dSSimon J. Gerraty.if make(universe)
5477261834dSSimon J. Gerraty# we do not want a failure of one branch abort all.
5487261834dSSimon J. GerratyMAKE_JOB_ERROR_TOKEN= no
5497261834dSSimon J. Gerraty.export MAKE_JOB_ERROR_TOKEN
5507261834dSSimon J. Gerraty.endif
55135c9a2a9SWarner Losh.endif # bmake
5521fc3d968SSimon J. Gerraty
5531fc3d968SSimon J. Gerraty.endif				# META_MODE
554