xref: /freebsd/Makefile (revision e8bad5dc)
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.
393540f0e1SJordan K. Hubbard#
40a7abf892SAlfred Perlstein# "quick" way to test all kernel builds:
41a7abf892SAlfred Perlstein# 	_jflag=`sysctl -n hw.ncpu`
42a7abf892SAlfred Perlstein# 	_jflag=$(($_jflag * 2))
43a7abf892SAlfred Perlstein# 	[ $_jflag -gt 12 ] && _jflag=12
440ff7433dSAlfred Perlstein# 	make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
45a7abf892SAlfred Perlstein#
4611fb97daSJohn Birrell# This makefile is simple by design. The FreeBSD make automatically reads
4711fb97daSJohn Birrell# the /usr/share/mk/sys.mk unless the -m argument is specified on the
4811fb97daSJohn Birrell# command line. By keeping this makefile simple, it doesn't matter too
4911fb97daSJohn Birrell# much how different the installed mk files are from those in the source
5011fb97daSJohn Birrell# tree. This makefile executes a child make process, forcing it to use
5111fb97daSJohn Birrell# the mk files from the source tree which are supposed to DTRT.
5211fb97daSJohn Birrell#
533acc4367SWarner Losh# Most of the user-driven targets (as listed above) are implemented in
54ff34e7e3SWarner Losh# Makefile.inc1.  The exceptions are universe, tinderbox and targets.
5511fb97daSJohn Birrell#
5676fdd728SJohn W. De Boskey# If you want to build your system from source be sure that /usr/obj has
5747c221b6SWarner Losh# at least 1GB of diskspace available.  A complete 'universe' build requires
5847c221b6SWarner Losh# about 15GB of space.
5911fb97daSJohn Birrell#
6076fdd728SJohn W. De Boskey# For individuals wanting to build from the sources currently on their
6176fdd728SJohn W. De Boskey# system, the simple instructions are:
6211fb97daSJohn Birrell#
6376fdd728SJohn W. De Boskey# 1.  `cd /usr/src'  (or to the directory containing your source tree).
64fb55e855STom Rhodes# 2.  Define `HISTORICAL_MAKE_WORLD' variable (see README).
65fb55e855STom Rhodes# 3.  `make world'
6611fb97daSJohn Birrell#
6776fdd728SJohn W. De Boskey# For individuals wanting to upgrade their sources (even if only a
6876fdd728SJohn W. De Boskey# delta of a few days):
6976fdd728SJohn W. De Boskey#
7076fdd728SJohn W. De Boskey#  1.  `cd /usr/src'       (or to the directory containing your source tree).
7176fdd728SJohn W. De Boskey#  2.  `make buildworld'
7276fdd728SJohn W. De Boskey#  3.  `make buildkernel KERNCONF=YOUR_KERNEL_HERE'     (default is GENERIC).
7376fdd728SJohn W. De Boskey#  4.  `make installkernel KERNCONF=YOUR_KERNEL_HERE'   (default is GENERIC).
742c5e89c2SDavid E. O'Brien#       [steps 3. & 4. can be combined by using the "kernel" target]
7576fdd728SJohn W. De Boskey#  5.  `reboot'        (in single user mode: boot -s from the loader prompt).
7676fdd728SJohn W. De Boskey#  6.  `mergemaster -p'
7776fdd728SJohn W. De Boskey#  7.  `make installworld'
78021a0587SChris Rees#  8.  `mergemaster'		(you may wish to use -i, along with -U or -F).
79021a0587SChris Rees#  9.  `make delete-old'
80e2a36081SAlexander Leidinger# 10.  `reboot'
81e2a36081SAlexander Leidinger# 11.  `make delete-old-libs' (in case no 3rd party program uses them anymore)
8276fdd728SJohn W. De Boskey#
8376fdd728SJohn W. De Boskey# See src/UPDATING `COMMON ITEMS' for more complete information.
8411fb97daSJohn Birrell#
851fde59f3SRuslan Ermilov# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
861fde59f3SRuslan Ermilov# cross build world for other machine types using the buildworld target,
87dbc3719dSMatthew Dillon# and once the world is built you can cross build a kernel using the
88dbc3719dSMatthew Dillon# buildkernel target.
89dbc3719dSMatthew Dillon#
9011fb97daSJohn Birrell# Define the user-driven targets. These are listed here in alphabetical
9111fb97daSJohn Birrell# order, but that's not important.
9211fb97daSJohn Birrell#
93ef7af95aSPeter Wemm# Targets that begin with underscore are internal targets intended for
94ef7af95aSPeter Wemm# developer convenience only.  They are intentionally not documented and
95ef7af95aSPeter Wemm# completely subject to change without notice.
96ef7af95aSPeter Wemm#
9779e19f08SJohn Baldwin# For more information, see the build(7) manual page.
9879e19f08SJohn Baldwin#
9932cd239bSDag-Erling SmørgravTGTS=	all all-man buildenv buildenvvars buildkernel buildworld \
10032cd239bSDag-Erling Smørgrav	check-old check-old-dirs check-old-files check-old-libs \
10132cd239bSDag-Erling Smørgrav	checkdpadd clean cleandepend cleandir \
10232cd239bSDag-Erling Smørgrav	delete-old delete-old-dirs delete-old-files delete-old-libs \
10399ad39c8SNathan Whitehorn	depend distribute distributekernel distributekernel.debug \
10499ad39c8SNathan Whitehorn	distributeworld distrib-dirs distribution doxygen \
105e324b4bcSDavid E. O'Brien	everything hier hierarchy install installcheck installkernel \
10699ad39c8SNathan Whitehorn	installkernel.debug packagekernel packageworld \
10799ad39c8SNathan Whitehorn	reinstallkernel reinstallkernel.debug \
108becc5c62SAlexander Leidinger	installworld kernel-toolchain libraries lint maninstall \
109c3ed02cfSRuslan Ermilov	obj objlink regress rerelease showconfig tags toolchain update \
110ef7af95aSPeter Wemm	_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
1111d9468eeSPeter Wemm	_build-tools _cross-tools _includes _libraries _depend \
1123c5326bfSRafal Jaworowski	build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
1133c5326bfSRafal Jaworowski
114902f7c5bSRuslan ErmilovTGTS+=	${SUBDIR_TARGETS}
1156e59a256SMarcel Moolenaar
116af2dc868SRuslan ErmilovBITGTS=	files includes
11728d2080aSRuslan ErmilovBITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
118b797df80SRuslan ErmilovTGTS+=	${BITGTS}
11928d2080aSRuslan Ermilov
120d672a609SRuslan Ermilov.ORDER: buildworld installworld
1218f1f55e9SRuslan Ermilov.ORDER: buildworld distributeworld
12220902bd3SRuslan Ermilov.ORDER: buildworld buildkernel
123d672a609SRuslan Ermilov.ORDER: buildkernel installkernel
1240147d2aaSHidetoshi Shimokawa.ORDER: buildkernel installkernel.debug
125d672a609SRuslan Ermilov.ORDER: buildkernel reinstallkernel
1260147d2aaSHidetoshi Shimokawa.ORDER: buildkernel reinstallkernel.debug
127d672a609SRuslan Ermilov
12876499f15SRuslan ErmilovPATH=	/sbin:/bin:/usr/sbin:/usr/bin
1292e84ab94SRuslan ErmilovMAKEOBJDIRPREFIX?=	/usr/obj
130e9bddef1SRuslan Ermilov_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
131f1fb2096SYaroslav Tykhiy    ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
1320ec443a0SRuslan Ermilov    -f /dev/null -V MAKEOBJDIRPREFIX dummy
1330ec443a0SRuslan Ermilov.if !empty(_MAKEOBJDIRPREFIX)
1340ec443a0SRuslan Ermilov.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
135f1fb2096SYaroslav Tykhiy	(in make.conf(5)) or command-line variable.
1360ec443a0SRuslan Ermilov.endif
1374234b977SSimon J. Gerraty
1384234b977SSimon J. Gerraty# We often need to use the tree's version of make to build it.
1394234b977SSimon J. Gerraty# Choices add to complexity though.
1404234b977SSimon J. Gerraty# We cannot blindly use a make which may not be the one we want
1414234b977SSimon J. Gerraty# so be exlicit - until all choice is removed.
1424234b977SSimon J. GerratyWANT_MAKE=	bmake
1434234b977SSimon J. GerratyMYMAKE=		${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
1444234b977SSimon J. Gerraty.if defined(.PARSEDIR)
1454234b977SSimon J. GerratyHAVE_MAKE=	bmake
1464234b977SSimon J. Gerraty.else
1474234b977SSimon J. GerratyHAVE_MAKE=	fmake
1484234b977SSimon J. Gerraty.endif
1494234b977SSimon J. Gerraty.if exists(${MYMAKE})
1504234b977SSimon J. GerratySUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
151d0312744SWarner Losh.elif ${WANT_MAKE} != ${HAVE_MAKE}
1524234b977SSimon J. Gerraty# It may not exist yet but we may cause it to.
1534234b977SSimon J. Gerraty# In the case of fmake, upgrade_checks may cause a newer version to be built.
1544234b977SSimon J. GerratySUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
1555dc63117SRuslan Ermilov	-m ${.CURDIR}/share/mk
1564234b977SSimon J. Gerraty.else
1574234b977SSimon J. GerratySUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
1584234b977SSimon J. Gerraty.endif
1594234b977SSimon J. Gerraty
1604234b977SSimon J. Gerraty_MAKE=	PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
161a962de47SPeter Wemm
162fda074e4SWarner Losh# Guess machine architecture from machine type, and vice versa.
163fda074e4SWarner Losh.if !defined(TARGET_ARCH) && defined(TARGET)
16484db023eSJuli Mallett_TARGET_ARCH=	${TARGET:S/pc98/i386/}
165fda074e4SWarner Losh.elif !defined(TARGET) && defined(TARGET_ARCH) && \
166fda074e4SWarner Losh    ${TARGET_ARCH} != ${MACHINE_ARCH}
16773279d41SAndrew Turner_TARGET=		${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
168fda074e4SWarner Losh.endif
169fda074e4SWarner Losh.if defined(TARGET) && !defined(_TARGET)
170fda074e4SWarner Losh_TARGET=${TARGET}
171fda074e4SWarner Losh.endif
172fda074e4SWarner Losh.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
173fda074e4SWarner Losh_TARGET_ARCH=${TARGET_ARCH}
174fda074e4SWarner Losh.endif
175fda074e4SWarner Losh# Otherwise, default to current machine type and architecture.
176fda074e4SWarner Losh_TARGET?=	${MACHINE}
177fda074e4SWarner Losh_TARGET_ARCH?=	${MACHINE_ARCH}
178fda074e4SWarner Losh
179a962de47SPeter Wemm#
180d911f786SMarcel Moolenaar# Make sure we have an up-to-date make(1). Only world and buildworld
181d911f786SMarcel Moolenaar# should do this as those are the initial targets used for upgrades.
182d911f786SMarcel Moolenaar# The user can define ALWAYS_CHECK_MAKE to have this check performed
183d911f786SMarcel Moolenaar# for all targets.
184d911f786SMarcel Moolenaar#
185d911f786SMarcel Moolenaar.if defined(ALWAYS_CHECK_MAKE)
186b797df80SRuslan Ermilov${TGTS}: upgrade_checks
187d911f786SMarcel Moolenaar.else
188d911f786SMarcel Moolenaarbuildworld: upgrade_checks
189d911f786SMarcel Moolenaar.endif
190d911f786SMarcel Moolenaar
191d911f786SMarcel Moolenaar#
192224f0698SGarance A Drosehn# This 'cleanworld' target is not included in TGTS, because it is not a
1931a974787SGarance A Drosehn# recursive target.  All of the work for it is done right here.   It is
1941a974787SGarance A Drosehn# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
1951a974787SGarance A Drosehn# created by bsd.obj.mk, except that we don't want to .include that file
1961a974787SGarance A Drosehn# in this makefile.
1971a974787SGarance A Drosehn#
1981a974787SGarance A Drosehn# In the following, the first 'rm' in a series will usually remove all
1991a974787SGarance A Drosehn# files and directories.  If it does not, then there are probably some
200f73031b4SGlen Barber# files with file flags set, so this unsets them and tries the 'rm' a
2011a974787SGarance A Drosehn# second time.  There are situations where this target will be cleaning
2021a974787SGarance A Drosehn# some directories via more than one method, but that duplication is
203123ba50fSGlen Barber# needed to correctly handle all the possible situations.  Removing all
204f73031b4SGlen Barber# files without file flags set in the first 'rm' instance saves time,
205f73031b4SGlen Barber# because 'chflags' will need to operate on fewer files afterwards.
2061a974787SGarance A Drosehn#
2071a974787SGarance A DrosehnBW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
208224f0698SGarance A Drosehncleanworld:
2091a974787SGarance A Drosehn.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
2101a974787SGarance A Drosehn.if exists(${BW_CANONICALOBJDIR}/)
2111a974787SGarance A Drosehn	-rm -rf ${BW_CANONICALOBJDIR}/*
21261858771SXin LI	-chflags -R 0 ${BW_CANONICALOBJDIR}
2131a974787SGarance A Drosehn	rm -rf ${BW_CANONICALOBJDIR}/*
2141a974787SGarance A Drosehn.endif
2151a974787SGarance A Drosehn	#   To be safe in this case, fall back to a 'make cleandir'
216088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
2171a974787SGarance A Drosehn.else
2181a974787SGarance A Drosehn	-rm -rf ${.OBJDIR}/*
21961858771SXin LI	-chflags -R 0 ${.OBJDIR}
2201a974787SGarance A Drosehn	rm -rf ${.OBJDIR}/*
2211a974787SGarance A Drosehn.endif
2222047c5d3SGarance A Drosehn
2232047c5d3SGarance A Drosehn#
22411fb97daSJohn Birrell# Handle the user-driven targets, using the source relative mk files.
225f3c4dd0dSBruce Evans#
226d911f786SMarcel Moolenaar
227d3187057SSimon J. Gerraty.if empty(.MAKEFLAGS:M-n)
228d3187057SSimon J. Gerraty# skip this for -n to avoid changing previous behavior of
229d3187057SSimon J. Gerraty# 'make -n buildworld' etc.
230d3187057SSimon J. Gerraty${TGTS}: .MAKE
231a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: .MAKE
232d3187057SSimon J. Gerraty.endif
233d3187057SSimon J. Gerraty
234b797df80SRuslan Ermilov${TGTS}:
235b3840844SWarner Losh	${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
236c3d9b0f0SRodney W. Grimes
2374b55d360SBrooks Davis# The historic default "all" target creates files which may cause stale
2384b55d360SBrooks Davis# or (in the cross build case) unlinkable results. Fail with an error
2394b55d360SBrooks Davis# when no target is given. The users can explicitly specify "all"
2404b55d360SBrooks Davis# if they want the historic behavior.
2414b55d360SBrooks Davis.MAIN:	_guard
2424b55d360SBrooks Davis
2434b55d360SBrooks Davis_guard:
2444b55d360SBrooks Davis	@echo
2454b55d360SBrooks Davis	@echo "Explicit target required (use \"all\" for historic behavior)"
2464b55d360SBrooks Davis	@echo
2474b55d360SBrooks Davis	@false
248ce53af53SJordan K. Hubbard
249afcf05e4SRuslan ErmilovSTARTTIME!= LC_ALL=C date
250f59c1f67SDavid E. O'BrienCHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
251ec51d61fSRuslan Ermilov.if !empty(CHECK_TIME)
252ec51d61fSRuslan Ermilov.error check your date/time: ${STARTTIME}
253ec51d61fSRuslan Ermilov.endif
254d18c9906SRuslan Ermilov
255d18c9906SRuslan Ermilov.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
2566e59a256SMarcel Moolenaar#
2576e59a256SMarcel Moolenaar# world
2586e59a256SMarcel Moolenaar#
2590a945825SMarcel Moolenaar# Attempt to rebuild and reinstall everything. This target is not to be
2600a945825SMarcel Moolenaar# used for upgrading an existing FreeBSD system, because the kernel is
2610a945825SMarcel Moolenaar# not included. One can argue that this target doesn't build everything
2620a945825SMarcel Moolenaar# then.
2636e59a256SMarcel Moolenaar#
2646e59a256SMarcel Moolenaarworld: upgrade_checks
2656e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2665ab77811SRuslan Ermilov	@echo ">>> make world started on ${STARTTIME}"
2676e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2686e59a256SMarcel Moolenaar.if target(pre-world)
2696e59a256SMarcel Moolenaar	@echo
2706e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2716e59a256SMarcel Moolenaar	@echo ">>> Making 'pre-world' target"
2726e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
273088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
2746e59a256SMarcel Moolenaar.endif
275088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
276088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
2776e59a256SMarcel Moolenaar.if target(post-world)
2786e59a256SMarcel Moolenaar	@echo
2796e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2806e59a256SMarcel Moolenaar	@echo ">>> Making 'post-world' target"
2816e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
282088cf0fbSHartmut Brandt	${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
2836e59a256SMarcel Moolenaar.endif
2846e59a256SMarcel Moolenaar	@echo
2856e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2865ab77811SRuslan Ermilov	@echo ">>> make world completed on `LC_ALL=C date`"
2875ab77811SRuslan Ermilov	@echo "                   (started ${STARTTIME})"
2886e59a256SMarcel Moolenaar	@echo "--------------------------------------------------------------"
2890a945825SMarcel Moolenaar.else
2900a945825SMarcel Moolenaarworld:
2910a945825SMarcel Moolenaar	@echo "WARNING: make world will overwrite your existing FreeBSD"
2920a945825SMarcel Moolenaar	@echo "installation without also building and installing a new"
2930a945825SMarcel Moolenaar	@echo "kernel.  This can be dangerous.  Please read the handbook,"
2941f6483e4SKen Smith	@echo "'Rebuilding world', for how to upgrade your system."
295954c5b43SMark Murray	@echo "Define DESTDIR to where you want to install FreeBSD,"
2960a945825SMarcel Moolenaar	@echo "including /, to override this warning and proceed as usual."
297954c5b43SMark Murray	@echo ""
2980a945825SMarcel Moolenaar	@echo "Bailing out now..."
2990a945825SMarcel Moolenaar	@false
3000a945825SMarcel Moolenaar.endif
3016e59a256SMarcel Moolenaar
302cf94fb21SBruce Evans#
303d672a609SRuslan Ermilov# kernel
304d672a609SRuslan Ermilov#
305d672a609SRuslan Ermilov# Short hand for `make buildkernel installkernel'
306d672a609SRuslan Ermilov#
307d672a609SRuslan Ermilovkernel: buildkernel installkernel
308d672a609SRuslan Ermilov
309d672a609SRuslan Ermilov#
31011fb97daSJohn Birrell# Perform a few tests to determine if the installed tools are adequate
311113cf9e6SRuslan Ermilov# for building the world.
31211fb97daSJohn Birrell#
3134234b977SSimon J. Gerraty# Note: if we ever need to care about the version of bmake, simply testing
3144234b977SSimon J. Gerraty# MAKE_VERSION against a required version should suffice.
3154234b977SSimon J. Gerraty#
31611fb97daSJohn Birrellupgrade_checks:
3174234b977SSimon J. Gerraty.if ${HAVE_MAKE} != ${WANT_MAKE}
3184234b977SSimon J. Gerraty	@(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
3190815243cSMarcel Moolenaar.endif
3206a8d432dSMark Murray
321a962de47SPeter Wemm#
3222e84ab94SRuslan Ermilov# Upgrade make(1) to the current version using the installed
3236029ad99SWarner Losh# headers, libraries and tools.  Also, allow the location of
3246029ad99SWarner Losh# the system bsdmake-like utility to be overridden.
325549f978aSMarcel Moolenaar#
3264234b977SSimon J. GerratyMMAKEENV=	MAKEOBJDIRPREFIX=${MYMAKE:H} \
3272e84ab94SRuslan Ermilov		DESTDIR= \
3282e84ab94SRuslan Ermilov		INSTALL="sh ${.CURDIR}/tools/install.sh"
329e2be0fd0SWarner LoshMMAKE=		${MMAKEENV} ${MAKE} \
33093654dcaSWarner Losh		-DNO_MAN -DNO_SHARED \
3315b79f581SJulio Merino		-DNO_CPU_CFLAGS -DNO_WERROR \
3324d9b013aSWarner Losh		DESTDIR= PROGNAME=${MYMAKE:T}
3332e84ab94SRuslan Ermilov
3344d9b013aSWarner Loshbmake: .PHONY
335549f978aSMarcel Moolenaar	@echo
336549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
3374d9b013aSWarner Losh	@echo ">>> Building an up-to-date ${.TARGET}(1)"
338549f978aSMarcel Moolenaar	@echo "--------------------------------------------------------------"
33913c9cf4cSSimon J. Gerraty	${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
340425df3c1SEd Maste		${MMAKE} obj && \
341425df3c1SEd Maste		${MMAKE} depend && \
342425df3c1SEd Maste		${MMAKE} all && \
3434d9b013aSWarner Losh		${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
344549f978aSMarcel Moolenaar
345a6822ce8SSimon J. Gerratytinderbox toolchains kernel-toolchains: upgrade_checks
346a6822ce8SSimon J. Gerraty
3474bb9ca57SAlfred Perlsteintinderbox:
348a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
3494e889921SJohn Baldwin
3504e889921SJohn Baldwintoolchains:
351a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
3524bb9ca57SAlfred Perlstein
3533e95821fSJuli Mallettkernel-toolchains:
354a6822ce8SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
3553e95821fSJuli Mallett
356549f978aSMarcel Moolenaar#
3571f4f7670SRuslan Ermilov# universe
3581f4f7670SRuslan Ermilov#
3591f4f7670SRuslan Ermilov# Attempt to rebuild *everything* for all supported architectures,
360d18c9906SRuslan Ermilov# with a reasonable chance of success, regardless of how old your
3611f4f7670SRuslan Ermilov# existing system is.
3621f4f7670SRuslan Ermilov#
36364fe77a5SWarner Losh.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
3644b547324SAttilio RaoTARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64
36573279d41SAndrew TurnerTARGET_ARCHES_arm?=	arm armeb armv6 armv6hf
36684db023eSJuli MallettTARGET_ARCHES_mips?=	mipsel mips mips64el mips64 mipsn32
3678e7c4a05SNathan WhitehornTARGET_ARCHES_powerpc?=	powerpc powerpc64
3688e7c4a05SNathan WhitehornTARGET_ARCHES_pc98?=	i386
3698e7c4a05SNathan Whitehorn.for target in ${TARGETS}
3708e7c4a05SNathan WhitehornTARGET_ARCHES_${target}?= ${target}
3718e7c4a05SNathan Whitehorn.endfor
3721bdb3fb9SMarcel Moolenaar
3734e889921SJohn Baldwin.if defined(UNIVERSE_TARGET)
3744e889921SJohn BaldwinMAKE_JUST_WORLDS=	YES
3754e889921SJohn Baldwin.else
3764e889921SJohn BaldwinUNIVERSE_TARGET?=	buildworld
3774e889921SJohn Baldwin.endif
378141aca1fSJohn BaldwinKERNSRCDIR?=		${.CURDIR}/sys
3794e889921SJohn Baldwin
38064fe77a5SWarner Loshtargets:
381f1d16bd8SBjoern A. Zeeb	@echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
38264fe77a5SWarner Losh.for target in ${TARGETS}
38364fe77a5SWarner Losh.for target_arch in ${TARGET_ARCHES_${target}}
38464fe77a5SWarner Losh	@echo "    ${target}/${target_arch}"
38564fe77a5SWarner Losh.endfor
38664fe77a5SWarner Losh.endfor
38764fe77a5SWarner Losh
3884bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
3892933a1ceSBjoern A. ZeebFAILFILE=${.CURDIR}/_.tinderbox.failed
3904bb9ca57SAlfred PerlsteinMAKEFAIL=tee -a ${FAILFILE}
3914bb9ca57SAlfred Perlstein.else
3924bb9ca57SAlfred PerlsteinMAKEFAIL=cat
3934bb9ca57SAlfred Perlstein.endif
3944bb9ca57SAlfred Perlstein
3954234b977SSimon J. Gerratyuniverse_prologue:  upgrade_checks
3964234b977SSimon J. Gerratyuniverse: universe_prologue
397d18c9906SRuslan Ermilovuniverse_prologue:
39877c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
39977c1699fSPoul-Henning Kamp	@echo ">>> make universe started on ${STARTTIME}"
40077c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4014bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4021ffa3abdSBjoern A. Zeeb	@rm -f ${FAILFILE}
4034bb9ca57SAlfred Perlstein.endif
4041bdb3fb9SMarcel Moolenaar.for target in ${TARGETS}
4051fde59f3SRuslan Ermilovuniverse: universe_${target}
4064234b977SSimon J. Gerratyuniverse_epilogue: universe_${target}
4078e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_prologue
4084234b977SSimon J. Gerratyuniverse_${target}_prologue: universe_prologue
4091fde59f3SRuslan Ermilov	@echo ">> ${target} started on `LC_ALL=C date`"
4108e7c4a05SNathan Whitehorn.if !defined(MAKE_JUST_KERNELS)
4118e7c4a05SNathan Whitehorn.for target_arch in ${TARGET_ARCHES_${target}}
4128e7c4a05SNathan Whitehornuniverse_${target}: universe_${target}_${target_arch}
413a6822ce8SSimon J. Gerratyuniverse_${target}_${target_arch}: universe_${target}_prologue .MAKE
4144e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
41533367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4164234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
4171fde59f3SRuslan Ermilov	    TARGET=${target} \
4188e7c4a05SNathan Whitehorn	    TARGET_ARCH=${target_arch} \
4194e889921SJohn Baldwin	    > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
4204e889921SJohn Baldwin	    (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
4214e889921SJohn Baldwin	    "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
4228e7c4a05SNathan Whitehorn	    ${MAKEFAIL}))
4234e889921SJohn Baldwin	@echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
4248e7c4a05SNathan Whitehorn.endfor
425139fb43dSJohn Birrell.endif
4263453d746SDoug Barton.if !defined(MAKE_JUST_WORLDS)
42710098a6eSAndrew Turner# If we are building world and kernels wait for the required worlds to finish
42810098a6eSAndrew Turner.if !defined(MAKE_JUST_KERNELS)
42910098a6eSAndrew Turner.for target_arch in ${TARGET_ARCHES_${target}}
43010098a6eSAndrew Turneruniverse_${target}_kernels: universe_${target}_${target_arch}
43110098a6eSAndrew Turner.endfor
43210098a6eSAndrew Turner.endif
43310098a6eSAndrew Turneruniverse_${target}: universe_${target}_kernels
434a6822ce8SSimon J. Gerratyuniverse_${target}_kernels: universe_${target}_prologue .MAKE
435141aca1fSJohn Baldwin.if exists(${KERNSRCDIR}/${target}/conf/NOTES)
436141aca1fSJohn Baldwin	@(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
4374234b977SSimon J. Gerraty	    ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
4384bb9ca57SAlfred Perlstein	    (echo "${target} 'make LINT' failed," \
4394bb9ca57SAlfred Perlstein	    "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
44077c1699fSPoul-Henning Kamp.endif
4414234b977SSimon J. Gerraty	@cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
4423c55ed70SBjoern A. Zeeb	    universe_kernels
4433453d746SDoug Barton.endif
4443c55ed70SBjoern A. Zeeb	@echo ">> ${target} completed on `LC_ALL=C date`"
4453c55ed70SBjoern A. Zeeb.endfor
4463c55ed70SBjoern A. Zeebuniverse_kernels: universe_kernconfs
4475f5bb1d1SBjoern A. Zeeb.if !defined(TARGET)
4485f5bb1d1SBjoern A. ZeebTARGET!=	uname -m
4495f5bb1d1SBjoern A. Zeeb.endif
4507621eebbSWarner Losh.if defined(MAKE_ALL_KERNELS)
4517621eebbSWarner Losh_THINNER=cat
4527621eebbSWarner Losh.else
453e8bad5dcSWarner Losh_THINNER=xargs grep -L "^.NO_UNIVERSE" || true
4547621eebbSWarner Losh.endif
455141aca1fSJohn BaldwinKERNCONFS!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
4563c55ed70SBjoern A. Zeeb		find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
4577621eebbSWarner Losh		! -name DEFAULTS ! -name NOTES | \
4587621eebbSWarner Losh		${_THINNER}
4593c55ed70SBjoern A. Zeebuniverse_kernconfs:
460dd0f3923SRuslan Ermilov.for kernel in ${KERNCONFS}
461141aca1fSJohn BaldwinTARGET_ARCH_${kernel}!=	cd ${KERNSRCDIR}/${TARGET}/conf && \
462141aca1fSJohn Baldwin	config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
46392f64fb9SWarner Losh	grep -v WARNING: | cut -f 2
46492f64fb9SWarner Losh.if empty(TARGET_ARCH_${kernel})
46592f64fb9SWarner Losh.error "Target architecture for ${TARGET}/conf/${kernel} unknown.  config(8) likely too old."
46692f64fb9SWarner Losh.endif
4678e7c4a05SNathan Whitehornuniverse_kernconfs: universe_kernconf_${TARGET}_${kernel}
468a6822ce8SSimon J. Gerratyuniverse_kernconf_${TARGET}_${kernel}: .MAKE
46933367c7fSDag-Erling Smørgrav	@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
4704234b977SSimon J. Gerraty	    ${SUB_MAKE} ${JFLAG} buildkernel \
4713c55ed70SBjoern A. Zeeb	    TARGET=${TARGET} \
4728e7c4a05SNathan Whitehorn	    TARGET_ARCH=${TARGET_ARCH_${kernel}} \
473dd0f3923SRuslan Ermilov	    KERNCONF=${kernel} \
4743c55ed70SBjoern A. Zeeb	    > _.${TARGET}.${kernel} 2>&1 || \
4753c55ed70SBjoern A. Zeeb	    (echo "${TARGET} ${kernel} kernel failed," \
4763c55ed70SBjoern A. Zeeb	    "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
477d18c9906SRuslan Ermilov.endfor
478d18c9906SRuslan Ermilovuniverse: universe_epilogue
479d18c9906SRuslan Ermilovuniverse_epilogue:
48077c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4815ab77811SRuslan Ermilov	@echo ">>> make universe completed on `LC_ALL=C date`"
4825ab77811SRuslan Ermilov	@echo "                      (started ${STARTTIME})"
48377c1699fSPoul-Henning Kamp	@echo "--------------------------------------------------------------"
4844bb9ca57SAlfred Perlstein.if defined(DOING_TINDERBOX)
4854bb9ca57SAlfred Perlstein	@if [ -e ${FAILFILE} ] ; then \
4864bb9ca57SAlfred Perlstein		echo "Tinderbox failed:" ;\
4874bb9ca57SAlfred Perlstein		cat ${FAILFILE} ;\
4884bb9ca57SAlfred Perlstein		exit 1 ;\
4894bb9ca57SAlfred Perlstein	fi
4904bb9ca57SAlfred Perlstein.endif
491d18c9906SRuslan Ermilov.endif
4923c4ee57dSMarcel Moolenaar
4933c4ee57dSMarcel MoolenaarbuildLINT:
4943c4ee57dSMarcel Moolenaar	${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
4957261834dSSimon J. Gerraty
4967261834dSSimon J. Gerraty.if defined(.PARSEDIR)
4977261834dSSimon J. Gerraty.if make(universe)
4987261834dSSimon J. Gerraty# we do not want a failure of one branch abort all.
4997261834dSSimon J. GerratyMAKE_JOB_ERROR_TOKEN= no
5007261834dSSimon J. Gerraty.export MAKE_JOB_ERROR_TOKEN
5017261834dSSimon J. Gerraty.endif
5027261834dSSimon J. Gerraty.endif
503