4 # The user-driven targets are:
6 # universe - *Really* build *everything* (buildworld and
7 # all kernels on all architectures).
8 # tinderbox - Same as universe, but presents a list of failed build
9 # targets and exits with an error if there were any.
10 # buildworld - Rebuild *everything*, including glue to help do
12 # installworld - Install everything built by "buildworld".
13 # world - buildworld + installworld, no kernel.
14 # buildkernel - Rebuild the kernel and the kernel-modules.
15 # installkernel - Install the kernel and the kernel-modules.
17 # reinstallkernel - Reinstall the kernel and the kernel-modules.
18 # reinstallkernel.debug
19 # kernel - buildkernel + installkernel.
20 # kernel-toolchain - Builds the subset of world necessary to build a kernel
21 # kernel-toolchains - Build kernel-toolchain for all universe targets.
22 # doxygen - Build API documentation of the kernel, needs doxygen.
23 # update - Convenient way to update your source tree(s).
24 # check-old - List obsolete directories/files/libraries.
25 # check-old-dirs - List obsolete directories.
26 # check-old-files - List obsolete files.
27 # check-old-libs - List obsolete libraries.
28 # delete-old - Delete obsolete directories/files.
29 # delete-old-dirs - Delete obsolete directories.
30 # delete-old-files - Delete obsolete files.
31 # delete-old-libs - Delete obsolete libraries.
32 # targets - Print a list of supported TARGET/TARGET_ARCH pairs
33 # for world and kernel targets.
34 # toolchains - Build a toolchain for all world and kernel targets.
35 # xdev - xdev-build + xdev-install for the architecture
36 # specified with XDEV and XDEV_ARCH.
37 # xdev-build - Build cross-development tools.
38 # xdev-install - Install cross-development tools.
39 # xdev-links - Create traditional links in /usr/bin for cc, etc
40 # native-xtools - Create host binaries that produce target objects
41 # for use in qemu user-mode jails.
43 # "quick" way to test all kernel builds:
44 # _jflag=`sysctl -n hw.ncpu`
45 # _jflag=$(($_jflag * 2))
46 # [ $_jflag -gt 12 ] && _jflag=12
47 # make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
49 # This makefile is simple by design. The FreeBSD make automatically reads
50 # the /usr/share/mk/sys.mk unless the -m argument is specified on the
51 # command line. By keeping this makefile simple, it doesn't matter too
52 # much how different the installed mk files are from those in the source
53 # tree. This makefile executes a child make process, forcing it to use
54 # the mk files from the source tree which are supposed to DTRT.
56 # Most of the user-driven targets (as listed above) are implemented in
57 # Makefile.inc1. The exceptions are universe, tinderbox and targets.
59 # If you want to build your system from source be sure that /usr/obj has
60 # at least 1GB of diskspace available. A complete 'universe' build requires
61 # about 15GB of space.
63 # For individuals wanting to build from the sources currently on their
64 # system, the simple instructions are:
66 # 1. `cd /usr/src' (or to the directory containing your source tree).
67 # 2. Define `HISTORICAL_MAKE_WORLD' variable (see README).
70 # For individuals wanting to upgrade their sources (even if only a
71 # delta of a few days):
73 # 1. `cd /usr/src' (or to the directory containing your source tree).
74 # 2. `make buildworld'
75 # 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
76 # 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
77 # [steps 3. & 4. can be combined by using the "kernel" target]
78 # 5. `reboot' (in single user mode: boot -s from the loader prompt).
80 # 7. `make installworld'
81 # 8. `mergemaster' (you may wish to use -i, along with -U or -F).
82 # 9. `make delete-old'
84 # 11. `make delete-old-libs' (in case no 3rd party program uses them anymore)
86 # See src/UPDATING `COMMON ITEMS' for more complete information.
88 # If TARGET=machine (e.g. powerpc, sparc64, ...) is specified you can
89 # cross build world for other machine types using the buildworld target,
90 # and once the world is built you can cross build a kernel using the
93 # Define the user-driven targets. These are listed here in alphabetical
94 # order, but that's not important.
96 # Targets that begin with underscore are internal targets intended for
97 # developer convenience only. They are intentionally not documented and
98 # completely subject to change without notice.
100 # For more information, see the build(7) manual page.
103 # Note: we use this awkward construct to be compatible with FreeBSD's
104 # old make used in 10.0 and 9.2 and earlier.
105 .if defined(MK_META_MODE) && ${MK_META_MODE} == "yes"
106 # targets/Makefile plays the role of top-level
107 .include "targets/Makefile"
110 TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
111 check-old check-old-dirs check-old-files check-old-libs \
112 checkdpadd clean cleandepend cleandir \
113 delete-old delete-old-dirs delete-old-files delete-old-libs \
114 depend distribute distributekernel distributekernel.debug \
115 distributeworld distrib-dirs distribution doxygen \
116 everything hier hierarchy install installcheck installkernel \
117 installkernel.debug packagekernel packageworld \
118 reinstallkernel reinstallkernel.debug \
119 installworld kernel-toolchain libraries lint maninstall \
120 obj objlink regress rerelease showconfig tags toolchain update \
121 _worldtmp _legacy _bootstrap-tools _cleanobj _obj \
122 _build-tools _cross-tools _includes _libraries _depend \
123 build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
124 xdev-links native-xtools \
126 TGTS+= ${SUBDIR_TARGETS}
128 BITGTS= files includes
129 BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
132 .ORDER: buildworld installworld
133 .ORDER: buildworld distributeworld
134 .ORDER: buildworld buildkernel
135 .ORDER: buildkernel installkernel
136 .ORDER: buildkernel installkernel.debug
137 .ORDER: buildkernel reinstallkernel
138 .ORDER: buildkernel reinstallkernel.debug
140 PATH= /sbin:/bin:/usr/sbin:/usr/bin
141 MAKEOBJDIRPREFIX?= /usr/obj
142 _MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
143 ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
144 -f /dev/null -V MAKEOBJDIRPREFIX dummy
145 .if !empty(_MAKEOBJDIRPREFIX)
146 .error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
147 (in make.conf(5)) or command-line variable.
150 # We often need to use the tree's version of make to build it.
151 # Choices add to complexity though.
152 # We cannot blindly use a make which may not be the one we want
153 # so be exlicit - until all choice is removed.
155 MYMAKE= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
156 .if defined(.PARSEDIR)
161 .if exists(${MYMAKE})
162 SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
163 .elif ${WANT_MAKE} != ${HAVE_MAKE}
164 # It may not exist yet but we may cause it to.
165 # In the case of fmake, upgrade_checks may cause a newer version to be built.
166 SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
167 -m ${.CURDIR}/share/mk
169 SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
172 _MAKE= PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
174 # Guess machine architecture from machine type, and vice versa.
175 .if !defined(TARGET_ARCH) && defined(TARGET)
176 _TARGET_ARCH= ${TARGET:S/pc98/i386/:S/arm64/aarch64/}
177 .elif !defined(TARGET) && defined(TARGET_ARCH) && \
178 ${TARGET_ARCH} != ${MACHINE_ARCH}
179 _TARGET= ${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/aarch64/arm64/:C/powerpc64/powerpc/}
181 .if defined(TARGET) && !defined(_TARGET)
184 .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
185 _TARGET_ARCH=${TARGET_ARCH}
187 # for historical compatibility for xdev targets
191 .if defined(XDEV_ARCH)
192 _TARGET_ARCH= ${XDEV_ARCH}
194 # Otherwise, default to current machine type and architecture.
196 _TARGET_ARCH?= ${MACHINE_ARCH}
199 # Make sure we have an up-to-date make(1). Only world and buildworld
200 # should do this as those are the initial targets used for upgrades.
201 # The user can define ALWAYS_CHECK_MAKE to have this check performed
204 .if defined(ALWAYS_CHECK_MAKE)
205 ${TGTS}: upgrade_checks
207 buildworld: upgrade_checks
211 # This 'cleanworld' target is not included in TGTS, because it is not a
212 # recursive target. All of the work for it is done right here. It is
213 # expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
214 # created by bsd.obj.mk, except that we don't want to .include that file
217 # In the following, the first 'rm' in a series will usually remove all
218 # files and directories. If it does not, then there are probably some
219 # files with file flags set, so this unsets them and tries the 'rm' a
220 # second time. There are situations where this target will be cleaning
221 # some directories via more than one method, but that duplication is
222 # needed to correctly handle all the possible situations. Removing all
223 # files without file flags set in the first 'rm' instance saves time,
224 # because 'chflags' will need to operate on fewer files afterwards.
226 BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
228 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
229 .if exists(${BW_CANONICALOBJDIR}/)
230 -rm -rf ${BW_CANONICALOBJDIR}/*
231 -chflags -R 0 ${BW_CANONICALOBJDIR}
232 rm -rf ${BW_CANONICALOBJDIR}/*
234 # To be safe in this case, fall back to a 'make cleandir'
235 ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
238 -chflags -R 0 ${.OBJDIR}
243 # Handle the user-driven targets, using the source relative mk files.
246 .if empty(.MAKEFLAGS:M-n)
247 # skip this for -n to avoid changing previous behavior of
248 # 'make -n buildworld' etc.
250 tinderbox toolchains kernel-toolchains: .MAKE
254 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
256 # The historic default "all" target creates files which may cause stale
257 # or (in the cross build case) unlinkable results. Fail with an error
258 # when no target is given. The users can explicitly specify "all"
259 # if they want the historic behavior.
264 @echo "Explicit target required (use \"all\" for historic behavior)"
268 STARTTIME!= LC_ALL=C date
269 CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
270 .if !empty(CHECK_TIME)
271 .error check your date/time: ${STARTTIME}
274 .if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
278 # Attempt to rebuild and reinstall everything. This target is not to be
279 # used for upgrading an existing FreeBSD system, because the kernel is
280 # not included. One can argue that this target doesn't build everything
283 world: upgrade_checks
284 @echo "--------------------------------------------------------------"
285 @echo ">>> make world started on ${STARTTIME}"
286 @echo "--------------------------------------------------------------"
287 .if target(pre-world)
289 @echo "--------------------------------------------------------------"
290 @echo ">>> Making 'pre-world' target"
291 @echo "--------------------------------------------------------------"
292 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
294 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
295 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
296 .if target(post-world)
298 @echo "--------------------------------------------------------------"
299 @echo ">>> Making 'post-world' target"
300 @echo "--------------------------------------------------------------"
301 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
304 @echo "--------------------------------------------------------------"
305 @echo ">>> make world completed on `LC_ALL=C date`"
306 @echo " (started ${STARTTIME})"
307 @echo "--------------------------------------------------------------"
310 @echo "WARNING: make world will overwrite your existing FreeBSD"
311 @echo "installation without also building and installing a new"
312 @echo "kernel. This can be dangerous. Please read the handbook,"
313 @echo "'Rebuilding world', for how to upgrade your system."
314 @echo "Define DESTDIR to where you want to install FreeBSD,"
315 @echo "including /, to override this warning and proceed as usual."
317 @echo "Bailing out now..."
324 # Short hand for `make buildkernel installkernel'
326 kernel: buildkernel installkernel
329 # Perform a few tests to determine if the installed tools are adequate
330 # for building the world.
332 # Note: if we ever need to care about the version of bmake, simply testing
333 # MAKE_VERSION against a required version should suffice.
336 .if ${HAVE_MAKE} != ${WANT_MAKE}
337 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
341 # Upgrade make(1) to the current version using the installed
342 # headers, libraries and tools. Also, allow the location of
343 # the system bsdmake-like utility to be overridden.
345 MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \
347 INSTALL="sh ${.CURDIR}/tools/install.sh"
348 MMAKE= ${MMAKEENV} ${MAKE} \
349 -DNO_MAN -DNO_SHARED \
350 -DNO_CPU_CFLAGS -DNO_WERROR \
352 DESTDIR= PROGNAME=${MYMAKE:T}
356 @echo "--------------------------------------------------------------"
357 @echo ">>> Building an up-to-date ${.TARGET}(1)"
358 @echo "--------------------------------------------------------------"
359 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
363 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
365 tinderbox toolchains kernel-toolchains: upgrade_checks
368 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
371 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
374 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
379 # Attempt to rebuild *everything* for all supported architectures,
380 # with a reasonable chance of success, regardless of how old your
381 # existing system is.
383 .if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
384 # XXX Add arm64 to universe only if we have an external binutils installed.
385 # It does not build with the in-tree linker.
386 .if exists(/usr/local/aarch64-freebsd/bin/ld)
388 .elif empty(${TARGETS})
389 universe: universe_arm64_skip
390 universe_epilogue: universe_arm64_skip
391 universe_arm64_skip: universe_prologue
392 @echo ">> arm64 skipped - install aarch64-binutils port or package to build"
394 TARGETS?=amd64 arm ${UNIVERSE_arm64} i386 mips pc98 powerpc sparc64
395 TARGET_ARCHES_arm?= arm armeb armv6 armv6hf
396 TARGET_ARCHES_arm64?= aarch64
397 TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32
398 TARGET_ARCHES_powerpc?= powerpc powerpc64
399 TARGET_ARCHES_pc98?= i386
400 .for target in ${TARGETS}
401 TARGET_ARCHES_${target}?= ${target}
404 .if defined(UNIVERSE_TARGET)
405 MAKE_JUST_WORLDS= YES
407 UNIVERSE_TARGET?= buildworld
409 KERNSRCDIR?= ${.CURDIR}/sys
412 @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
413 .for target in ${TARGETS}
414 .for target_arch in ${TARGET_ARCHES_${target}}
415 @echo " ${target}/${target_arch}"
419 .if defined(DOING_TINDERBOX)
420 FAILFILE=${.CURDIR}/_.tinderbox.failed
421 MAKEFAIL=tee -a ${FAILFILE}
426 universe_prologue: upgrade_checks
427 universe: universe_prologue
429 @echo "--------------------------------------------------------------"
430 @echo ">>> make universe started on ${STARTTIME}"
431 @echo "--------------------------------------------------------------"
432 .if defined(DOING_TINDERBOX)
435 .for target in ${TARGETS}
436 universe: universe_${target}
437 universe_epilogue: universe_${target}
438 universe_${target}: universe_${target}_prologue
439 universe_${target}_prologue: universe_prologue
440 @echo ">> ${target} started on `LC_ALL=C date`"
441 universe_${target}_worlds:
443 .if !defined(MAKE_JUST_KERNELS)
444 universe_${target}_done: universe_${target}_worlds
445 .for target_arch in ${TARGET_ARCHES_${target}}
446 universe_${target}_worlds: universe_${target}_${target_arch}
447 universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
448 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
449 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
450 ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
452 TARGET_ARCH=${target_arch} \
453 > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
454 (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
455 "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
457 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
459 .endif # !MAKE_JUST_KERNELS
461 .if !defined(MAKE_JUST_WORLDS)
462 universe_${target}_done: universe_${target}_kernels
463 universe_${target}_kernels: universe_${target}_worlds
464 universe_${target}_kernels: universe_${target}_prologue .MAKE
465 .if exists(${KERNSRCDIR}/${target}/conf/NOTES)
466 @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
467 ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
468 (echo "${target} 'make LINT' failed," \
469 "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
471 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
473 .endif # !MAKE_JUST_WORLDS
475 # Tell the user the worlds and kernels have completed
476 universe_${target}: universe_${target}_done
477 universe_${target}_done:
478 @echo ">> ${target} completed on `LC_ALL=C date`"
480 universe_kernels: universe_kernconfs
484 .if defined(MAKE_ALL_KERNELS)
487 _THINNER=xargs grep -L "^.NO_UNIVERSE" || true
489 KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \
490 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
491 ! -name DEFAULTS ! -name NOTES | \
494 .for kernel in ${KERNCONFS}
495 TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \
496 config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
497 grep -v WARNING: | cut -f 2
498 .if empty(TARGET_ARCH_${kernel})
499 .error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old."
501 universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
502 universe_kernconf_${TARGET}_${kernel}: .MAKE
503 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
504 ${SUB_MAKE} ${JFLAG} buildkernel \
506 TARGET_ARCH=${TARGET_ARCH_${kernel}} \
508 > _.${TARGET}.${kernel} 2>&1 || \
509 (echo "${TARGET} ${kernel} kernel failed," \
510 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
512 universe: universe_epilogue
514 @echo "--------------------------------------------------------------"
515 @echo ">>> make universe completed on `LC_ALL=C date`"
516 @echo " (started ${STARTTIME})"
517 @echo "--------------------------------------------------------------"
518 .if defined(DOING_TINDERBOX)
519 @if [ -e ${FAILFILE} ] ; then \
520 echo "Tinderbox failed:" ;\
528 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
530 .if defined(.PARSEDIR)
531 # This makefile does not run in meta mode
533 # Normally the things we run from here don't either.
534 # Using -DWITH_META_FILES
535 # we can buildworld with meta files created which are useful
536 # for debugging, but without any of the rest of a meta mode build.
539 # tell meta.autodep.mk to not even think about updating anything.
540 UPDATE_DEPENDFILE= NO
541 .export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE
544 # we do not want a failure of one branch abort all.
545 MAKE_JOB_ERROR_TOKEN= no
546 .export MAKE_JOB_ERROR_TOKEN