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
41 # "quick" way to test all kernel builds:
42 # _jflag=`sysctl -n hw.ncpu`
43 # _jflag=$(($_jflag * 2))
44 # [ $_jflag -gt 12 ] && _jflag=12
45 # make universe -DMAKE_JUST_KERNELS JFLAG=-j${_jflag}
47 # This makefile is simple by design. The FreeBSD make automatically reads
48 # the /usr/share/mk/sys.mk unless the -m argument is specified on the
49 # command line. By keeping this makefile simple, it doesn't matter too
50 # much how different the installed mk files are from those in the source
51 # tree. This makefile executes a child make process, forcing it to use
52 # the mk files from the source tree which are supposed to DTRT.
54 # Most of the user-driven targets (as listed above) are implemented in
55 # Makefile.inc1. The exceptions are universe, tinderbox and targets.
57 # If you want to build your system from source be sure that /usr/obj has
58 # at least 1GB of diskspace available. A complete 'universe' build requires
59 # about 15GB of space.
61 # For individuals wanting to build from the sources currently on their
62 # system, the simple instructions are:
64 # 1. `cd /usr/src' (or to the directory containing your source tree).
65 # 2. Define `HISTORICAL_MAKE_WORLD' variable (see README).
68 # For individuals wanting to upgrade their sources (even if only a
69 # delta of a few days):
71 # 1. `cd /usr/src' (or to the directory containing your source tree).
72 # 2. `make buildworld'
73 # 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
74 # 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
75 # [steps 3. & 4. can be combined by using the "kernel" target]
76 # 5. `reboot' (in single user mode: boot -s from the loader prompt).
78 # 7. `make installworld'
79 # 8. `mergemaster' (you may wish to use -i, along with -U or -F).
80 # 9. `make delete-old'
82 # 11. `make delete-old-libs' (in case no 3rd party program uses them anymore)
84 # See src/UPDATING `COMMON ITEMS' for more complete information.
86 # If TARGET=machine (e.g. powerpc, sparc64, ...) is specified you can
87 # cross build world for other machine types using the buildworld target,
88 # and once the world is built you can cross build a kernel using the
91 # Define the user-driven targets. These are listed here in alphabetical
92 # order, but that's not important.
94 # Targets that begin with underscore are internal targets intended for
95 # developer convenience only. They are intentionally not documented and
96 # completely subject to change without notice.
98 # For more information, see the build(7) manual page.
100 TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
101 check-old check-old-dirs check-old-files check-old-libs \
102 checkdpadd clean cleandepend cleandir \
103 delete-old delete-old-dirs delete-old-files delete-old-libs \
104 depend distribute distributekernel distributekernel.debug \
105 distributeworld distrib-dirs distribution doxygen \
106 everything hier hierarchy install installcheck installkernel \
107 installkernel.debug packagekernel packageworld \
108 reinstallkernel reinstallkernel.debug \
109 installworld kernel-toolchain libraries lint maninstall \
110 obj objlink regress rerelease showconfig tags toolchain update \
111 _worldtmp _legacy _bootstrap-tools _cleanobj _obj \
112 _build-tools _cross-tools _includes _libraries _depend \
113 build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
116 TGTS+= ${SUBDIR_TARGETS}
118 BITGTS= files includes
119 BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
122 .ORDER: buildworld installworld
123 .ORDER: buildworld distributeworld
124 .ORDER: buildworld buildkernel
125 .ORDER: buildkernel installkernel
126 .ORDER: buildkernel installkernel.debug
127 .ORDER: buildkernel reinstallkernel
128 .ORDER: buildkernel reinstallkernel.debug
130 PATH= /sbin:/bin:/usr/sbin:/usr/bin
131 MAKEOBJDIRPREFIX?= /usr/obj
132 _MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
133 ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
134 -f /dev/null -V MAKEOBJDIRPREFIX dummy
135 .if !empty(_MAKEOBJDIRPREFIX)
136 .error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
137 (in make.conf(5)) or command-line variable.
140 # We often need to use the tree's version of make to build it.
141 # Choices add to complexity though.
142 # We cannot blindly use a make which may not be the one we want
143 # so be exlicit - until all choice is removed.
145 MYMAKE= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE}
146 .if defined(.PARSEDIR)
151 .if exists(${MYMAKE})
152 SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk
153 .elif ${WANT_MAKE} != ${HAVE_MAKE}
154 # It may not exist yet but we may cause it to.
155 # In the case of fmake, upgrade_checks may cause a newer version to be built.
156 SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \
157 -m ${.CURDIR}/share/mk
159 SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk
162 _MAKE= PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH}
164 # Guess machine architecture from machine type, and vice versa.
165 .if !defined(TARGET_ARCH) && defined(TARGET)
166 _TARGET_ARCH= ${TARGET:S/pc98/i386/}
167 .elif !defined(TARGET) && defined(TARGET_ARCH) && \
168 ${TARGET_ARCH} != ${MACHINE_ARCH}
169 _TARGET= ${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/}
171 .if defined(TARGET) && !defined(_TARGET)
174 .if defined(TARGET_ARCH) && !defined(_TARGET_ARCH)
175 _TARGET_ARCH=${TARGET_ARCH}
177 # Otherwise, default to current machine type and architecture.
179 _TARGET_ARCH?= ${MACHINE_ARCH}
182 # Make sure we have an up-to-date make(1). Only world and buildworld
183 # should do this as those are the initial targets used for upgrades.
184 # The user can define ALWAYS_CHECK_MAKE to have this check performed
187 .if defined(ALWAYS_CHECK_MAKE)
188 ${TGTS}: upgrade_checks
190 buildworld: upgrade_checks
194 # This 'cleanworld' target is not included in TGTS, because it is not a
195 # recursive target. All of the work for it is done right here. It is
196 # expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
197 # created by bsd.obj.mk, except that we don't want to .include that file
200 # In the following, the first 'rm' in a series will usually remove all
201 # files and directories. If it does not, then there are probably some
202 # files with file flags set, so this unsets them and tries the 'rm' a
203 # second time. There are situations where this target will be cleaning
204 # some directories via more than one method, but that duplication is
205 # needed to correctly handle all the possible situations. Removing all
206 # files without file flags set in the first 'rm' instance saves time,
207 # because 'chflags' will need to operate on fewer files afterwards.
209 BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
211 .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
212 .if exists(${BW_CANONICALOBJDIR}/)
213 -rm -rf ${BW_CANONICALOBJDIR}/*
214 -chflags -R 0 ${BW_CANONICALOBJDIR}
215 rm -rf ${BW_CANONICALOBJDIR}/*
217 # To be safe in this case, fall back to a 'make cleandir'
218 ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
221 -chflags -R 0 ${.OBJDIR}
226 # Handle the user-driven targets, using the source relative mk files.
229 .if empty(.MAKEFLAGS:M-n)
230 # skip this for -n to avoid changing previous behavior of
231 # 'make -n buildworld' etc.
233 tinderbox toolchains kernel-toolchains: .MAKE
237 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET}
239 # The historic default "all" target creates files which may cause stale
240 # or (in the cross build case) unlinkable results. Fail with an error
241 # when no target is given. The users can explicitly specify "all"
242 # if they want the historic behavior.
247 @echo "Explicit target required (use \"all\" for historic behavior)"
251 STARTTIME!= LC_ALL=C date
252 CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo
253 .if !empty(CHECK_TIME)
254 .error check your date/time: ${STARTTIME}
257 .if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
261 # Attempt to rebuild and reinstall everything. This target is not to be
262 # used for upgrading an existing FreeBSD system, because the kernel is
263 # not included. One can argue that this target doesn't build everything
266 world: upgrade_checks
267 @echo "--------------------------------------------------------------"
268 @echo ">>> make world started on ${STARTTIME}"
269 @echo "--------------------------------------------------------------"
270 .if target(pre-world)
272 @echo "--------------------------------------------------------------"
273 @echo ">>> Making 'pre-world' target"
274 @echo "--------------------------------------------------------------"
275 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
277 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
278 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
279 .if target(post-world)
281 @echo "--------------------------------------------------------------"
282 @echo ">>> Making 'post-world' target"
283 @echo "--------------------------------------------------------------"
284 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
287 @echo "--------------------------------------------------------------"
288 @echo ">>> make world completed on `LC_ALL=C date`"
289 @echo " (started ${STARTTIME})"
290 @echo "--------------------------------------------------------------"
293 @echo "WARNING: make world will overwrite your existing FreeBSD"
294 @echo "installation without also building and installing a new"
295 @echo "kernel. This can be dangerous. Please read the handbook,"
296 @echo "'Rebuilding world', for how to upgrade your system."
297 @echo "Define DESTDIR to where you want to install FreeBSD,"
298 @echo "including /, to override this warning and proceed as usual."
300 @echo "Bailing out now..."
307 # Short hand for `make buildkernel installkernel'
309 kernel: buildkernel installkernel
312 # Perform a few tests to determine if the installed tools are adequate
313 # for building the world.
315 # Note: if we ever need to care about the version of bmake, simply testing
316 # MAKE_VERSION against a required version should suffice.
319 .if ${HAVE_MAKE} != ${WANT_MAKE}
320 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,})
324 # Upgrade make(1) to the current version using the installed
325 # headers, libraries and tools. Also, allow the location of
326 # the system bsdmake-like utility to be overridden.
328 MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \
330 INSTALL="sh ${.CURDIR}/tools/install.sh"
331 MMAKE= ${MMAKEENV} ${MAKE} \
332 -DNO_MAN -DNO_SHARED \
333 -DNO_CPU_CFLAGS -DNO_WERROR \
335 DESTDIR= PROGNAME=${MYMAKE:T}
339 @echo "--------------------------------------------------------------"
340 @echo ">>> Building an up-to-date ${.TARGET}(1)"
341 @echo "--------------------------------------------------------------"
342 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \
346 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR=
348 tinderbox toolchains kernel-toolchains: upgrade_checks
351 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe
354 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe
357 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe
362 # Attempt to rebuild *everything* for all supported architectures,
363 # with a reasonable chance of success, regardless of how old your
364 # existing system is.
366 .if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets)
367 TARGETS?=amd64 arm i386 mips pc98 powerpc sparc64
368 TARGET_ARCHES_arm?= arm armeb armv6 armv6hf
369 TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32
370 TARGET_ARCHES_powerpc?= powerpc powerpc64
371 TARGET_ARCHES_pc98?= i386
372 .for target in ${TARGETS}
373 TARGET_ARCHES_${target}?= ${target}
376 .if defined(UNIVERSE_TARGET)
377 MAKE_JUST_WORLDS= YES
379 UNIVERSE_TARGET?= buildworld
381 KERNSRCDIR?= ${.CURDIR}/sys
384 @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets"
385 .for target in ${TARGETS}
386 .for target_arch in ${TARGET_ARCHES_${target}}
387 @echo " ${target}/${target_arch}"
391 .if defined(DOING_TINDERBOX)
392 FAILFILE=${.CURDIR}/_.tinderbox.failed
393 MAKEFAIL=tee -a ${FAILFILE}
398 universe_prologue: upgrade_checks
399 universe: universe_prologue
401 @echo "--------------------------------------------------------------"
402 @echo ">>> make universe started on ${STARTTIME}"
403 @echo "--------------------------------------------------------------"
404 .if defined(DOING_TINDERBOX)
407 .for target in ${TARGETS}
408 universe: universe_${target}
409 universe_epilogue: universe_${target}
410 universe_${target}: universe_${target}_prologue
411 universe_${target}_prologue: universe_prologue
412 @echo ">> ${target} started on `LC_ALL=C date`"
413 .if !defined(MAKE_JUST_KERNELS)
414 .for target_arch in ${TARGET_ARCHES_${target}}
415 universe_${target}: universe_${target}_${target_arch}
416 universe_${target}_${target_arch}: universe_${target}_prologue .MAKE
417 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`"
418 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
419 ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \
421 TARGET_ARCH=${target_arch} \
422 > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \
423 (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \
424 "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \
426 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`"
429 .if !defined(MAKE_JUST_WORLDS)
430 # If we are building world and kernels wait for the required worlds to finish
431 .if !defined(MAKE_JUST_KERNELS)
432 .for target_arch in ${TARGET_ARCHES_${target}}
433 universe_${target}_kernels: universe_${target}_${target_arch}
436 universe_${target}: universe_${target}_kernels
437 universe_${target}_kernels: universe_${target}_prologue .MAKE
438 .if exists(${KERNSRCDIR}/${target}/conf/NOTES)
439 @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \
440 ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
441 (echo "${target} 'make LINT' failed," \
442 "check _.${target}.makeLINT for details"| ${MAKEFAIL}))
444 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \
447 @echo ">> ${target} completed on `LC_ALL=C date`"
449 universe_kernels: universe_kernconfs
453 .if defined(MAKE_ALL_KERNELS)
456 _THINNER=xargs grep -L "^.NO_UNIVERSE" || true
458 KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \
459 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
460 ! -name DEFAULTS ! -name NOTES | \
463 .for kernel in ${KERNCONFS}
464 TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \
465 config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \
466 grep -v WARNING: | cut -f 2
467 .if empty(TARGET_ARCH_${kernel})
468 .error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old."
470 universe_kernconfs: universe_kernconf_${TARGET}_${kernel}
471 universe_kernconf_${TARGET}_${kernel}: .MAKE
472 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
473 ${SUB_MAKE} ${JFLAG} buildkernel \
475 TARGET_ARCH=${TARGET_ARCH_${kernel}} \
477 > _.${TARGET}.${kernel} 2>&1 || \
478 (echo "${TARGET} ${kernel} kernel failed," \
479 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
481 universe: universe_epilogue
483 @echo "--------------------------------------------------------------"
484 @echo ">>> make universe completed on `LC_ALL=C date`"
485 @echo " (started ${STARTTIME})"
486 @echo "--------------------------------------------------------------"
487 .if defined(DOING_TINDERBOX)
488 @if [ -e ${FAILFILE} ] ; then \
489 echo "Tinderbox failed:" ;\
497 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT
499 .if defined(.PARSEDIR)
501 # we do not want a failure of one branch abort all.
502 MAKE_JOB_ERROR_TOKEN= no
503 .export MAKE_JOB_ERROR_TOKEN