1# 2# $FreeBSD$ 3# 4# The user-driven targets are: 5# 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 11# upgrades. 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. 16# installkernel.debug 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. 42# 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} 48# 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. 55# 56# Most of the user-driven targets (as listed above) are implemented in 57# Makefile.inc1. The exceptions are universe, tinderbox and targets. 58# 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. 62# 63# For individuals wanting to build from the sources currently on their 64# system, the simple instructions are: 65# 66# 1. `cd /usr/src' (or to the directory containing your source tree). 67# 2. Define `HISTORICAL_MAKE_WORLD' variable (see README). 68# 3. `make world' 69# 70# For individuals wanting to upgrade their sources (even if only a 71# delta of a few days): 72# 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). 79# 6. `mergemaster -p' 80# 7. `make installworld' 81# 8. `mergemaster' (you may wish to use -i, along with -U or -F). 82# 9. `make delete-old' 83# 10. `reboot' 84# 11. `make delete-old-libs' (in case no 3rd party program uses them anymore) 85# 86# See src/UPDATING `COMMON ITEMS' for more complete information. 87# 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 91# buildkernel target. 92# 93# Define the user-driven targets. These are listed here in alphabetical 94# order, but that's not important. 95# 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. 99# 100# For more information, see the build(7) manual page. 101# 102.if ${MK_META_MODE:Uno} == "yes" 103# targets/Makefile plays the role of top-level 104.include "targets/Makefile" 105.else 106 107TGTS= all all-man buildenv buildenvvars buildkernel buildworld \ 108 check-old check-old-dirs check-old-files check-old-libs \ 109 checkdpadd clean cleandepend cleandir \ 110 delete-old delete-old-dirs delete-old-files delete-old-libs \ 111 depend distribute distributekernel distributekernel.debug \ 112 distributeworld distrib-dirs distribution doxygen \ 113 everything hier hierarchy install installcheck installkernel \ 114 installkernel.debug packagekernel packageworld \ 115 reinstallkernel reinstallkernel.debug \ 116 installworld kernel-toolchain libraries lint maninstall \ 117 obj objlink regress rerelease showconfig tags toolchain update \ 118 _worldtmp _legacy _bootstrap-tools _cleanobj _obj \ 119 _build-tools _cross-tools _includes _libraries _depend \ 120 build32 builddtb distribute32 install32 xdev xdev-build xdev-install \ 121 xdev-links native-xtools \ 122 123TGTS+= ${SUBDIR_TARGETS} 124 125BITGTS= files includes 126BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/} 127TGTS+= ${BITGTS} 128 129.ORDER: buildworld installworld 130.ORDER: buildworld distributeworld 131.ORDER: buildworld buildkernel 132.ORDER: buildkernel installkernel 133.ORDER: buildkernel installkernel.debug 134.ORDER: buildkernel reinstallkernel 135.ORDER: buildkernel reinstallkernel.debug 136 137PATH= /sbin:/bin:/usr/sbin:/usr/bin 138MAKEOBJDIRPREFIX?= /usr/obj 139_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \ 140 ${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \ 141 -f /dev/null -V MAKEOBJDIRPREFIX dummy 142.if !empty(_MAKEOBJDIRPREFIX) 143.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\ 144 (in make.conf(5)) or command-line variable. 145.endif 146 147# We often need to use the tree's version of make to build it. 148# Choices add to complexity though. 149# We cannot blindly use a make which may not be the one we want 150# so be exlicit - until all choice is removed. 151WANT_MAKE= bmake 152MYMAKE= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE} 153.if defined(.PARSEDIR) 154HAVE_MAKE= bmake 155.else 156HAVE_MAKE= fmake 157.endif 158.if exists(${MYMAKE}) 159SUB_MAKE:= ${MYMAKE} -m ${.CURDIR}/share/mk 160.elif ${WANT_MAKE} != ${HAVE_MAKE} 161# It may not exist yet but we may cause it to. 162# In the case of fmake, upgrade_checks may cause a newer version to be built. 163SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \ 164 -m ${.CURDIR}/share/mk 165.else 166SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk 167.endif 168 169_MAKE= PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} 170 171# Guess machine architecture from machine type, and vice versa. 172.if !defined(TARGET_ARCH) && defined(TARGET) 173_TARGET_ARCH= ${TARGET:S/pc98/i386/:S/arm64/aarch64/} 174.elif !defined(TARGET) && defined(TARGET_ARCH) && \ 175 ${TARGET_ARCH} != ${MACHINE_ARCH} 176_TARGET= ${TARGET_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/aarch64/arm64/:C/powerpc64/powerpc/} 177.endif 178.if defined(TARGET) && !defined(_TARGET) 179_TARGET=${TARGET} 180.endif 181.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH) 182_TARGET_ARCH=${TARGET_ARCH} 183.endif 184# for historical compatibility for xdev targets 185.if defined(XDEV) 186_TARGET= ${XDEV} 187.endif 188.if defined(XDEV_ARCH) 189_TARGET_ARCH= ${XDEV_ARCH} 190.endif 191# Otherwise, default to current machine type and architecture. 192_TARGET?= ${MACHINE} 193_TARGET_ARCH?= ${MACHINE_ARCH} 194 195# 196# Make sure we have an up-to-date make(1). Only world and buildworld 197# should do this as those are the initial targets used for upgrades. 198# The user can define ALWAYS_CHECK_MAKE to have this check performed 199# for all targets. 200# 201.if defined(ALWAYS_CHECK_MAKE) 202${TGTS}: upgrade_checks 203.else 204buildworld: upgrade_checks 205.endif 206 207# 208# This 'cleanworld' target is not included in TGTS, because it is not a 209# recursive target. All of the work for it is done right here. It is 210# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be 211# created by bsd.obj.mk, except that we don't want to .include that file 212# in this makefile. 213# 214# In the following, the first 'rm' in a series will usually remove all 215# files and directories. If it does not, then there are probably some 216# files with file flags set, so this unsets them and tries the 'rm' a 217# second time. There are situations where this target will be cleaning 218# some directories via more than one method, but that duplication is 219# needed to correctly handle all the possible situations. Removing all 220# files without file flags set in the first 'rm' instance saves time, 221# because 'chflags' will need to operate on fewer files afterwards. 222# 223BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 224cleanworld: 225.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR} 226.if exists(${BW_CANONICALOBJDIR}/) 227 -rm -rf ${BW_CANONICALOBJDIR}/* 228 -chflags -R 0 ${BW_CANONICALOBJDIR} 229 rm -rf ${BW_CANONICALOBJDIR}/* 230.endif 231 # To be safe in this case, fall back to a 'make cleandir' 232 ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir 233.else 234 -rm -rf ${.OBJDIR}/* 235 -chflags -R 0 ${.OBJDIR} 236 rm -rf ${.OBJDIR}/* 237.endif 238 239# 240# Handle the user-driven targets, using the source relative mk files. 241# 242 243.if empty(.MAKEFLAGS:M-n) 244# skip this for -n to avoid changing previous behavior of 245# 'make -n buildworld' etc. 246${TGTS}: .MAKE 247tinderbox toolchains kernel-toolchains: .MAKE 248.endif 249 250${TGTS}: 251 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET} 252 253# The historic default "all" target creates files which may cause stale 254# or (in the cross build case) unlinkable results. Fail with an error 255# when no target is given. The users can explicitly specify "all" 256# if they want the historic behavior. 257.MAIN: _guard 258 259_guard: 260 @echo 261 @echo "Explicit target required (use \"all\" for historic behavior)" 262 @echo 263 @false 264 265STARTTIME!= LC_ALL=C date 266CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo 267.if !empty(CHECK_TIME) 268.error check your date/time: ${STARTTIME} 269.endif 270 271.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR) 272# 273# world 274# 275# Attempt to rebuild and reinstall everything. This target is not to be 276# used for upgrading an existing FreeBSD system, because the kernel is 277# not included. One can argue that this target doesn't build everything 278# then. 279# 280world: upgrade_checks 281 @echo "--------------------------------------------------------------" 282 @echo ">>> make world started on ${STARTTIME}" 283 @echo "--------------------------------------------------------------" 284.if target(pre-world) 285 @echo 286 @echo "--------------------------------------------------------------" 287 @echo ">>> Making 'pre-world' target" 288 @echo "--------------------------------------------------------------" 289 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world 290.endif 291 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld 292 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld 293.if target(post-world) 294 @echo 295 @echo "--------------------------------------------------------------" 296 @echo ">>> Making 'post-world' target" 297 @echo "--------------------------------------------------------------" 298 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world 299.endif 300 @echo 301 @echo "--------------------------------------------------------------" 302 @echo ">>> make world completed on `LC_ALL=C date`" 303 @echo " (started ${STARTTIME})" 304 @echo "--------------------------------------------------------------" 305.else 306world: 307 @echo "WARNING: make world will overwrite your existing FreeBSD" 308 @echo "installation without also building and installing a new" 309 @echo "kernel. This can be dangerous. Please read the handbook," 310 @echo "'Rebuilding world', for how to upgrade your system." 311 @echo "Define DESTDIR to where you want to install FreeBSD," 312 @echo "including /, to override this warning and proceed as usual." 313 @echo "" 314 @echo "Bailing out now..." 315 @false 316.endif 317 318# 319# kernel 320# 321# Short hand for `make buildkernel installkernel' 322# 323kernel: buildkernel installkernel 324 325# 326# Perform a few tests to determine if the installed tools are adequate 327# for building the world. 328# 329# Note: if we ever need to care about the version of bmake, simply testing 330# MAKE_VERSION against a required version should suffice. 331# 332upgrade_checks: 333.if ${HAVE_MAKE} != ${WANT_MAKE} 334 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,}) 335.endif 336 337# 338# Upgrade make(1) to the current version using the installed 339# headers, libraries and tools. Also, allow the location of 340# the system bsdmake-like utility to be overridden. 341# 342MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \ 343 DESTDIR= \ 344 INSTALL="sh ${.CURDIR}/tools/install.sh" 345MMAKE= ${MMAKEENV} ${MAKE} \ 346 -DNO_MAN -DNO_SHARED \ 347 -DNO_CPU_CFLAGS -DNO_WERROR \ 348 MK_TESTS=no \ 349 DESTDIR= PROGNAME=${MYMAKE:T} 350 351bmake: .PHONY 352 @echo 353 @echo "--------------------------------------------------------------" 354 @echo ">>> Building an up-to-date ${.TARGET}(1)" 355 @echo "--------------------------------------------------------------" 356 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \ 357 ${MMAKE} obj && \ 358 ${MMAKE} depend && \ 359 ${MMAKE} all && \ 360 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR= 361 362tinderbox toolchains kernel-toolchains: upgrade_checks 363 364tinderbox: 365 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe 366 367toolchains: 368 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe 369 370kernel-toolchains: 371 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe 372 373# 374# universe 375# 376# Attempt to rebuild *everything* for all supported architectures, 377# with a reasonable chance of success, regardless of how old your 378# existing system is. 379# 380.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets) 381# XXX Add arm64 to universe only if we have an external binutils installed. 382# It does not build with the in-tree linker. 383.if exists(/usr/local/aarch64-freebsd/bin/ld) 384UNIVERSE_arm64=arm64 385.elif empty(${TARGETS}) 386universe: universe_arm64_skip 387universe_epilogue: universe_arm64_skip 388universe_arm64_skip: universe_prologue 389 @echo ">> arm64 skipped - install aarch64-binutils port or package to build" 390.endif 391TARGETS?=amd64 arm ${UNIVERSE_arm64} i386 mips pc98 powerpc sparc64 392TARGET_ARCHES_arm?= arm armeb armv6 armv6hf 393TARGET_ARCHES_arm64?= aarch64 394TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32 395TARGET_ARCHES_powerpc?= powerpc powerpc64 396TARGET_ARCHES_pc98?= i386 397.for target in ${TARGETS} 398TARGET_ARCHES_${target}?= ${target} 399.endfor 400 401.if defined(UNIVERSE_TARGET) 402MAKE_JUST_WORLDS= YES 403.else 404UNIVERSE_TARGET?= buildworld 405.endif 406KERNSRCDIR?= ${.CURDIR}/sys 407 408targets: 409 @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets" 410.for target in ${TARGETS} 411.for target_arch in ${TARGET_ARCHES_${target}} 412 @echo " ${target}/${target_arch}" 413.endfor 414.endfor 415 416.if defined(DOING_TINDERBOX) 417FAILFILE=${.CURDIR}/_.tinderbox.failed 418MAKEFAIL=tee -a ${FAILFILE} 419.else 420MAKEFAIL=cat 421.endif 422 423universe_prologue: upgrade_checks 424universe: universe_prologue 425universe_prologue: 426 @echo "--------------------------------------------------------------" 427 @echo ">>> make universe started on ${STARTTIME}" 428 @echo "--------------------------------------------------------------" 429.if defined(DOING_TINDERBOX) 430 @rm -f ${FAILFILE} 431.endif 432.for target in ${TARGETS} 433universe: universe_${target} 434universe_epilogue: universe_${target} 435universe_${target}: universe_${target}_prologue 436universe_${target}_prologue: universe_prologue 437 @echo ">> ${target} started on `LC_ALL=C date`" 438.if !defined(MAKE_JUST_KERNELS) 439.for target_arch in ${TARGET_ARCHES_${target}} 440universe_${target}: universe_${target}_${target_arch} 441universe_${target}_${target_arch}: universe_${target}_prologue .MAKE 442 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`" 443 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ 444 ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \ 445 TARGET=${target} \ 446 TARGET_ARCH=${target_arch} \ 447 > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \ 448 (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \ 449 "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \ 450 ${MAKEFAIL})) 451 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`" 452.endfor 453.endif 454.if !defined(MAKE_JUST_WORLDS) 455# If we are building world and kernels wait for the required worlds to finish 456.if !defined(MAKE_JUST_KERNELS) 457.for target_arch in ${TARGET_ARCHES_${target}} 458universe_${target}_kernels: universe_${target}_${target_arch} 459.endfor 460.endif 461universe_${target}: universe_${target}_kernels 462universe_${target}_kernels: universe_${target}_prologue .MAKE 463.if exists(${KERNSRCDIR}/${target}/conf/NOTES) 464 @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \ 465 ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \ 466 (echo "${target} 'make LINT' failed," \ 467 "check _.${target}.makeLINT for details"| ${MAKEFAIL})) 468.endif 469 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \ 470 universe_kernels 471.endif 472 @echo ">> ${target} completed on `LC_ALL=C date`" 473.endfor 474universe_kernels: universe_kernconfs 475.if !defined(TARGET) 476TARGET!= uname -m 477.endif 478.if defined(MAKE_ALL_KERNELS) 479_THINNER=cat 480.else 481_THINNER=xargs grep -L "^.NO_UNIVERSE" || true 482.endif 483KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \ 484 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \ 485 ! -name DEFAULTS ! -name NOTES | \ 486 ${_THINNER} 487universe_kernconfs: 488.for kernel in ${KERNCONFS} 489TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \ 490 config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \ 491 grep -v WARNING: | cut -f 2 492.if empty(TARGET_ARCH_${kernel}) 493.error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old." 494.endif 495universe_kernconfs: universe_kernconf_${TARGET}_${kernel} 496universe_kernconf_${TARGET}_${kernel}: .MAKE 497 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ 498 ${SUB_MAKE} ${JFLAG} buildkernel \ 499 TARGET=${TARGET} \ 500 TARGET_ARCH=${TARGET_ARCH_${kernel}} \ 501 KERNCONF=${kernel} \ 502 > _.${TARGET}.${kernel} 2>&1 || \ 503 (echo "${TARGET} ${kernel} kernel failed," \ 504 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL})) 505.endfor 506universe: universe_epilogue 507universe_epilogue: 508 @echo "--------------------------------------------------------------" 509 @echo ">>> make universe completed on `LC_ALL=C date`" 510 @echo " (started ${STARTTIME})" 511 @echo "--------------------------------------------------------------" 512.if defined(DOING_TINDERBOX) 513 @if [ -e ${FAILFILE} ] ; then \ 514 echo "Tinderbox failed:" ;\ 515 cat ${FAILFILE} ;\ 516 exit 1 ;\ 517 fi 518.endif 519.endif 520 521buildLINT: 522 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT 523 524# This makefile does not run in meta mode 525.MAKE.MODE= normal 526# Normally the things we run from here don't either. 527# Using -DWITH_META_FILES 528# we can buildworld with meta files created which are useful 529# for debugging, but without any of the rest of a meta mode build. 530MK_META_MODE= no 531MK_STAGING= no 532# tell meta.autodep.mk to not even think about updating anything. 533UPDATE_DEPENDFILE= NO 534.export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE 535 536.if make(universe) 537# we do not want a failure of one branch abort all. 538MAKE_JOB_ERROR_TOKEN= no 539.export MAKE_JOB_ERROR_TOKEN 540.endif 541 542.endif # META_MODE 543