xref: /freebsd/Makefile (revision 75872267)
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#
10232cd239bSDag-Erling SmørgravTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
10332cd239bSDag-Erling Smørgrav	check-old check-old-dirs check-old-files check-old-libs \
10432cd239bSDag-Erling Smørgrav	checkdpadd clean cleandepend cleandir \
10532cd239bSDag-Erling Smørgrav	delete-old delete-old-dirs delete-old-files delete-old-libs \
10699ad39c8SNathan Whitehorn	depend distribute distributekernel distributekernel.debug \
10799ad39c8SNathan Whitehorn	distributeworld distrib-dirs distribution doxygen \
108e324b4bcSDavid E. O'Brien	everything hier hierarchy install installcheck installkernel \
10999ad39c8SNathan Whitehorn	installkernel.debug packagekernel packageworld \
11099ad39c8SNathan Whitehorn	reinstallkernel reinstallkernel.debug \
111becc5c62SAlexander Leidinger	installworld kernel-toolchain libraries lint maninstall \
112c3ed02cfSRuslan Ermilov	obj objlink regress rerelease showconfig tags toolchain update \
113ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
1141d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
1153c5326bfSRafal Jaworowski	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
11675872267SWarner Losh	xdev-links native-xtools \
1173c5326bfSRafal Jaworowski
118902f7c5bSRuslan ErmilovTGTS+=	${SUBDIR_TARGETS}
1196e59a256SMarcel Moolenaar
120af2dc868SRuslan ErmilovBITGTS=	files includes
12128d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
122b797df80SRuslan ErmilovTGTS+=	${BITGTS}
12328d2080aSRuslan Ermilov
124d672a609SRuslan Ermilov.ORDER: buildworld installworld
1258f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
12620902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
127d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
1280147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
129d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
1300147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
131d672a609SRuslan Ermilov
13276499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
1332e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
134e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
135f1fb2096SYaroslav Tykhiy    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
1360ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
1370ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
1380ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
139f1fb2096SYaroslav Tykhiy	(in make.conf(5)) or command-line variable.
1400ec443a0SRuslan Ermilov.endif
1414234b977SSimon J. Gerraty
1424234b977SSimon J. Gerraty# We often need to use the tree's version of make to build it.
1434234b977SSimon J. Gerraty# Choices add to complexity though.
1444234b977SSimon J. Gerraty# We cannot blindly use a make which may not be the one we want
1454234b977SSimon J. Gerraty# so be exlicit - until all choice is removed.
1464234b977SSimon J. GerratyWANT_MAKE=	bmake
1474234b977SSimon J. GerratyMYMAKE=		${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
1484234b977SSimon J. Gerraty.if defined(.PARSEDIR)
1494234b977SSimon J. GerratyHAVE_MAKE=	bmake
1504234b977SSimon J. Gerraty.else
1514234b977SSimon J. GerratyHAVE_MAKE=	fmake
1524234b977SSimon J. Gerraty.endif
1534234b977SSimon J. Gerraty.if exists(${MYMAKE})
1544234b977SSimon J. GerratySUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
155d0312744SWarner Losh.elif ${WANT_MAKE} != ${HAVE_MAKE}
1564234b977SSimon J. Gerraty# It may not exist yet but we may cause it to.
1574234b977SSimon J. Gerraty# In the case of fmake, upgrade_checks may cause a newer version to be built.
1584234b977SSimon J. GerratySUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
1595dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
1604234b977SSimon J. Gerraty.else
1614234b977SSimon J. GerratySUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
1624234b977SSimon J. Gerraty.endif
1634234b977SSimon J. Gerraty
1644234b977SSimon J. Gerraty_MAKE=	PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
165a962de47SPeter Wemm
166fda074e4SWarner Losh# Guess machine architecture from machine type, and vice versa.
167fda074e4SWarner Losh.if !defined(TARGET_ARCH) && defined(TARGET)
16884db023eSJuli Mallett_TARGET_ARCH=	${TARGET:S/pc98/i386/}
169fda074e4SWarner Losh.elif !defined(TARGET) && defined(TARGET_ARCH) && \
170fda074e4SWarner Losh    ${TARGET_ARCH} != ${MACHINE_ARCH}
17173279d41SAndrew Turner_TARGET=		${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
172fda074e4SWarner Losh.endif
173fda074e4SWarner Losh.if defined(TARGET) && !defined(_TARGET)
174fda074e4SWarner Losh_TARGET=${TARGET}
175fda074e4SWarner Losh.endif
176fda074e4SWarner Losh.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
177fda074e4SWarner Losh_TARGET_ARCH=${TARGET_ARCH}
178fda074e4SWarner Losh.endif
1790aafd404SWarner Losh# for historical compatibility for xdev targets
1800aafd404SWarner Losh.if defined(XDEV)
1810aafd404SWarner Losh_TARGET=	${XDEV}
1820aafd404SWarner Losh.endif
1830aafd404SWarner Losh.if defined(XDEV_ARCH)
1840aafd404SWarner Losh_TARGET_ARCH=	${XDEV_ARCH}
1850aafd404SWarner Losh.endif
186fda074e4SWarner Losh# Otherwise, default to current machine type and architecture.
187fda074e4SWarner Losh_TARGET?=	${MACHINE}
188fda074e4SWarner Losh_TARGET_ARCH?=	${MACHINE_ARCH}
189fda074e4SWarner Losh
190a962de47SPeter Wemm#
191d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
192d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
193d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
194d911f786SMarcel Moolenaar# for all targets.
195d911f786SMarcel Moolenaar#
196d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
197b797df80SRuslan Ermilov${TGTS}: upgrade_checks
198d911f786SMarcel Moolenaar.else
199d911f786SMarcel Moolenaarbuildworld: upgrade_checks
200d911f786SMarcel Moolenaar.endif
201d911f786SMarcel Moolenaar
202d911f786SMarcel Moolenaar#
203224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
2041a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
2051a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
2061a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
2071a974787SGarance A Drosehn# in this makefile.
2081a974787SGarance A Drosehn#
2091a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
2101a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
211f73031b4SGlen Barber# files with file flags set, so this unsets them and tries the 'rm' a
2121a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
2131a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
214123ba50fSGlen Barber# needed to correctly handle all the possible situations.  Removing all
215f73031b4SGlen Barber# files without file flags set in the first 'rm' instance saves time,
216f73031b4SGlen Barber# because 'chflags' will need to operate on fewer files afterwards.
2171a974787SGarance A Drosehn#
2181a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
219224f0698SGarance A Drosehncleanworld:
2201a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2211a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
2221a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
22361858771SXin LI	-chflags -R 0 ${BW_CANONICALOBJDIR}
2241a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
2251a974787SGarance A Drosehn.endif
2261a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
227088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
2281a974787SGarance A Drosehn.else
2291a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
23061858771SXin LI	-chflags -R 0 ${.OBJDIR}
2311a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
2321a974787SGarance A Drosehn.endif
2332047c5d3SGarance A Drosehn
2342047c5d3SGarance A Drosehn#
23511fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
236f3c4dd0dSBruce Evans#
237d911f786SMarcel Moolenaar
238d3187057SSimon J. Gerraty.if empty(.MAKEFLAGS:M-n)
239d3187057SSimon J. Gerraty# skip this for -n to avoid changing previous behavior of
240d3187057SSimon J. Gerraty# 'make -n buildworld' etc.
241d3187057SSimon J. Gerraty${TGTS}: .MAKE
242a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: .MAKE
243d3187057SSimon J. Gerraty.endif
244d3187057SSimon J. Gerraty
245b797df80SRuslan Ermilov${TGTS}:
246b3840844SWarner Losh	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
247c3d9b0f0SRodney W. Grimes
2484b55d360SBrooks Davis# The historic default "all" target creates files which may cause stale
2494b55d360SBrooks Davis# or (in the cross build case) unlinkable results. Fail with an error
2504b55d360SBrooks Davis# when no target is given. The users can explicitly specify "all"
2514b55d360SBrooks Davis# if they want the historic behavior.
2524b55d360SBrooks Davis.MAIN:	_guard
2534b55d360SBrooks Davis
2544b55d360SBrooks Davis_guard:
2554b55d360SBrooks Davis	@echo
2564b55d360SBrooks Davis	@echo "Explicit target required (use \"all\" for historic behavior)"
2574b55d360SBrooks Davis	@echo
2584b55d360SBrooks Davis	@false
259ce53af53SJordan K. Hubbard
260afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
261f59c1f67SDavid E. O'BrienCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
262ec51d61fSRuslan Ermilov.if !empty(CHECK_TIME)
263ec51d61fSRuslan Ermilov.error check your date/time: ${STARTTIME}
264ec51d61fSRuslan Ermilov.endif
265d18c9906SRuslan Ermilov
266d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
2676e59a256SMarcel Moolenaar#
2686e59a256SMarcel Moolenaar# world
2696e59a256SMarcel Moolenaar#
2700a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
2710a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
2720a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
2730a945825SMarcel Moolenaar# then.
2746e59a256SMarcel Moolenaar#
2756e59a256SMarcel Moolenaarworld: upgrade_checks
2766e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2775ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
2786e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2796e59a256SMarcel Moolenaar.if target(pre-world)
2806e59a256SMarcel Moolenaar	@echo
2816e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2826e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
2836e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
284088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
2856e59a256SMarcel Moolenaar.endif
286088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
287088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
2886e59a256SMarcel Moolenaar.if target(post-world)
2896e59a256SMarcel Moolenaar	@echo
2906e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2916e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
2926e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
293088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
2946e59a256SMarcel Moolenaar.endif
2956e59a256SMarcel Moolenaar	@echo
2966e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2975ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
2985ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
2996e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
3000a945825SMarcel Moolenaar.else
3010a945825SMarcel Moolenaarworld:
3020a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
3030a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
3040a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
3051f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
306954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
3070a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
308954c5b43SMark Murray	@echo ""
3090a945825SMarcel Moolenaar	@echo "Bailing out now..."
3100a945825SMarcel Moolenaar	@false
3110a945825SMarcel Moolenaar.endif
3126e59a256SMarcel Moolenaar
313cf94fb21SBruce Evans#
314d672a609SRuslan Ermilov# kernel
315d672a609SRuslan Ermilov#
316d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
317d672a609SRuslan Ermilov#
318d672a609SRuslan Ermilovkernel: buildkernel installkernel
319d672a609SRuslan Ermilov
320d672a609SRuslan Ermilov#
32111fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
322113cf9e6SRuslan Ermilov# for building the world.
32311fb97daSJohn Birrell#
3244234b977SSimon J. Gerraty# Note: if we ever need to care about the version of bmake, simply testing
3254234b977SSimon J. Gerraty# MAKE_VERSION against a required version should suffice.
3264234b977SSimon J. Gerraty#
32711fb97daSJohn Birrellupgrade_checks:
3284234b977SSimon J. Gerraty.if ${HAVE_MAKE} != ${WANT_MAKE}
3294234b977SSimon J. Gerraty	@(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
3300815243cSMarcel Moolenaar.endif
3316a8d432dSMark Murray
332a962de47SPeter Wemm#
3332e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
3346029ad99SWarner Losh# headers, libraries and tools.  Also, allow the location of
3356029ad99SWarner Losh# the system bsdmake-like utility to be overridden.
336549f978aSMarcel Moolenaar#
3374234b977SSimon J. GerratyMMAKEENV=	MAKEOBJDIRPREFIX=${MYMAKE:H} \
3382e84ab94SRuslan Ermilov		DESTDIR= \
3392e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
340e2be0fd0SWarner LoshMMAKE=		${MMAKEENV} ${MAKE} \
34193654dcaSWarner Losh		-DNO_MAN -DNO_SHARED \
3425b79f581SJulio Merino		-DNO_CPU_CFLAGS -DNO_WERROR \
3431dd381bfSJulio Merino		MK_TESTS=no \
3444d9b013aSWarner Losh		DESTDIR= PROGNAME=${MYMAKE:T}
3452e84ab94SRuslan Ermilov
3464d9b013aSWarner Loshbmake: .PHONY
347549f978aSMarcel Moolenaar	@echo
348549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
3494d9b013aSWarner Losh	@echo ">>> Building an up-to-date ${.TARGET}(1)"
350549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
35113c9cf4cSSimon J. Gerraty	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
352425df3c1SEd Maste		${MMAKE} obj && \
353425df3c1SEd Maste		${MMAKE} depend && \
354425df3c1SEd Maste		${MMAKE} all && \
3554d9b013aSWarner Losh		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
356549f978aSMarcel Moolenaar
357a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: upgrade_checks
358a6822ce8SSimon J. Gerraty
3594bb9ca57SAlfred Perlsteintinderbox:
360a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
3614e889921SJohn Baldwin
3624e889921SJohn Baldwintoolchains:
363a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
3644bb9ca57SAlfred Perlstein
3653e95821fSJuli Mallettkernel-toolchains:
366a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
3673e95821fSJuli Mallett
368549f978aSMarcel Moolenaar#
3691f4f7670SRuslan Ermilov# universe
3701f4f7670SRuslan Ermilov#
3711f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
372d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
3731f4f7670SRuslan Ermilov# existing system is.
3741f4f7670SRuslan Ermilov#
37564fe77a5SWarner Losh.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
37650f73640SMarcel MoolenaarTARGETS?=amd64 arm i386 mips pc98 powerpc sparc64
37773279d41SAndrew TurnerTARGET_ARCHES_arm?=	arm armeb armv6 armv6hf
37884db023eSJuli MallettTARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32
3798e7c4a05SNathan WhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
3808e7c4a05SNathan WhitehornTARGET_ARCHES_pc98?=	i386
3818e7c4a05SNathan Whitehorn.for target in ${TARGETS}
3828e7c4a05SNathan WhitehornTARGET_ARCHES_${target}?= ${target}
3838e7c4a05SNathan Whitehorn.endfor
3841bdb3fb9SMarcel Moolenaar
3854e889921SJohn Baldwin.if defined(UNIVERSE_TARGET)
3864e889921SJohn BaldwinMAKE_JUST_WORLDS=	YES
3874e889921SJohn Baldwin.else
3884e889921SJohn BaldwinUNIVERSE_TARGET?=	buildworld
3894e889921SJohn Baldwin.endif
390141aca1fSJohn BaldwinKERNSRCDIR?=		${.CURDIR}/sys
3914e889921SJohn Baldwin
39264fe77a5SWarner Loshtargets:
393f1d16bd8SBjoern A. Zeeb	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
39464fe77a5SWarner Losh.for target in ${TARGETS}
39564fe77a5SWarner Losh.for target_arch in ${TARGET_ARCHES_${target}}
39664fe77a5SWarner Losh	@echo "    ${target}/${target_arch}"
39764fe77a5SWarner Losh.endfor
39864fe77a5SWarner Losh.endfor
39964fe77a5SWarner Losh
4004bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4012933a1ceSBjoern A. ZeebFAILFILE=${.CURDIR}/_.tinderbox.failed
4024bb9ca57SAlfred PerlsteinMAKEFAIL=tee -a ${FAILFILE}
4034bb9ca57SAlfred Perlstein.else
4044bb9ca57SAlfred PerlsteinMAKEFAIL=cat
4054bb9ca57SAlfred Perlstein.endif
4064bb9ca57SAlfred Perlstein
4074234b977SSimon J. Gerratyuniverse_prologue:  upgrade_checks
4084234b977SSimon J. Gerratyuniverse: universe_prologue
409d18c9906SRuslan Ermilovuniverse_prologue:
41077c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
41177c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
41277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4134bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4141ffa3abdSBjoern A. Zeeb	@rm -f ${FAILFILE}
4154bb9ca57SAlfred Perlstein.endif
4161bdb3fb9SMarcel Moolenaar.for target in ${TARGETS}
4171fde59f3SRuslan Ermilovuniverse: universe_${target}
4184234b977SSimon J. Gerratyuniverse_epilogue: universe_${target}
4198e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_prologue
4204234b977SSimon J. Gerratyuniverse_${target}_prologue: universe_prologue
4211fde59f3SRuslan Ermilov	@echo ">> ${target} started on `LC_ALL=C date`"
4228e7c4a05SNathan Whitehorn.if !defined(MAKE_JUST_KERNELS)
4238e7c4a05SNathan Whitehorn.for target_arch in ${TARGET_ARCHES_${target}}
4248e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_${target_arch}
425a6822ce8SSimon J. Gerratyuniverse_${target}_${target_arch}: universe_${target}_prologue .MAKE
4264e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
42733367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4284234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
4291fde59f3SRuslan Ermilov	    TARGET=${target} \
4308e7c4a05SNathan Whitehorn	    TARGET_ARCH=${target_arch} \
4314e889921SJohn Baldwin	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
4324e889921SJohn Baldwin	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
4334e889921SJohn Baldwin	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
4348e7c4a05SNathan Whitehorn	    ${MAKEFAIL}))
4354e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
4368e7c4a05SNathan Whitehorn.endfor
437139fb43dSJohn Birrell.endif
4383453d746SDoug Barton.if !defined(MAKE_JUST_WORLDS)
43910098a6eSAndrew Turner# If we are building world and kernels wait for the required worlds to finish
44010098a6eSAndrew Turner.if !defined(MAKE_JUST_KERNELS)
44110098a6eSAndrew Turner.for target_arch in ${TARGET_ARCHES_${target}}
44210098a6eSAndrew Turneruniverse_${target}_kernels: universe_${target}_${target_arch}
44310098a6eSAndrew Turner.endfor
44410098a6eSAndrew Turner.endif
44510098a6eSAndrew Turneruniverse_${target}: universe_${target}_kernels
446a6822ce8SSimon J. Gerratyuniverse_${target}_kernels: universe_${target}_prologue .MAKE
447141aca1fSJohn Baldwin.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
448141aca1fSJohn Baldwin	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
4494234b977SSimon J. Gerraty	    ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
4504bb9ca57SAlfred Perlstein	    (echo "${target} 'make LINT' failed," \
4514bb9ca57SAlfred Perlstein	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
45277c1699fSPoul-Henning Kamp.endif
4534234b977SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
4543c55ed70SBjoern A. Zeeb	    universe_kernels
4553453d746SDoug Barton.endif
4563c55ed70SBjoern A. Zeeb	@echo ">> ${target} completed on `LC_ALL=C date`"
4573c55ed70SBjoern A. Zeeb.endfor
4583c55ed70SBjoern A. Zeebuniverse_kernels: universe_kernconfs
4595f5bb1d1SBjoern A. Zeeb.if !defined(TARGET)
4605f5bb1d1SBjoern A. ZeebTARGET!=	uname -m
4615f5bb1d1SBjoern A. Zeeb.endif
4627621eebbSWarner Losh.if defined(MAKE_ALL_KERNELS)
4637621eebbSWarner Losh_THINNER=cat
4647621eebbSWarner Losh.else
465e8bad5dcSWarner Losh_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
4667621eebbSWarner Losh.endif
467141aca1fSJohn BaldwinKERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
4683c55ed70SBjoern A. Zeeb		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
4697621eebbSWarner Losh		! -name DEFAULTS ! -name NOTES | \
4707621eebbSWarner Losh		${_THINNER}
4713c55ed70SBjoern A. Zeebuniverse_kernconfs:
472dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
473141aca1fSJohn BaldwinTARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
474141aca1fSJohn Baldwin	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
47592f64fb9SWarner Losh	grep -v WARNING: | cut -f 2
47692f64fb9SWarner Losh.if empty(TARGET_ARCH_${kernel})
47792f64fb9SWarner Losh.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
47892f64fb9SWarner Losh.endif
4798e7c4a05SNathan Whitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
480a6822ce8SSimon J. Gerratyuniverse_kernconf_${TARGET}_${kernel}: .MAKE
48133367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4824234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} buildkernel \
4833c55ed70SBjoern A. Zeeb	    TARGET=${TARGET} \
4848e7c4a05SNathan Whitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
485dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
4863c55ed70SBjoern A. Zeeb	    > _.${TARGET}.${kernel} 2>&1 || \
4873c55ed70SBjoern A. Zeeb	    (echo "${TARGET} ${kernel} kernel failed," \
4883c55ed70SBjoern A. Zeeb	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
489d18c9906SRuslan Ermilov.endfor
490d18c9906SRuslan Ermilovuniverse: universe_epilogue
491d18c9906SRuslan Ermilovuniverse_epilogue:
49277c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4935ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
4945ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
49577c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4964bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4974bb9ca57SAlfred Perlstein	@if [ -e ${FAILFILE} ] ; then \
4984bb9ca57SAlfred Perlstein		echo "Tinderbox failed:" ;\
4994bb9ca57SAlfred Perlstein		cat ${FAILFILE} ;\
5004bb9ca57SAlfred Perlstein		exit 1 ;\
5014bb9ca57SAlfred Perlstein	fi
5024bb9ca57SAlfred Perlstein.endif
503d18c9906SRuslan Ermilov.endif
5043c4ee57dSMarcel Moolenaar
5053c4ee57dSMarcel MoolenaarbuildLINT:
5063c4ee57dSMarcel Moolenaar	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
5077261834dSSimon J. Gerraty
5087261834dSSimon J. Gerraty.if defined(.PARSEDIR)
5097261834dSSimon J. Gerraty.if make(universe)
5107261834dSSimon J. Gerraty# we do not want a failure of one branch abort all.
5117261834dSSimon J. GerratyMAKE_JOB_ERROR_TOKEN= no
5127261834dSSimon J. Gerraty.export MAKE_JOB_ERROR_TOKEN
5137261834dSSimon J. Gerraty.endif
5147261834dSSimon J. Gerraty.endif
515