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 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" && !make(showconfig) 106# targets/Makefile plays the role of top-level 107.include "targets/Makefile" 108.else 109 110TGTS= 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 installconfig \ 125 126TGTS+= ${SUBDIR_TARGETS} 127 128BITGTS= files includes 129BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/} 130TGTS+= ${BITGTS} 131 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 139 140PATH= /sbin:/bin:/usr/sbin:/usr/bin 141MAKEOBJDIRPREFIX?= /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. 148.endif 149 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. 154WANT_MAKE= bmake 155MYMAKE= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}/${WANT_MAKE} 156.if defined(.PARSEDIR) 157HAVE_MAKE= bmake 158.else 159HAVE_MAKE= fmake 160.endif 161.if exists(${MYMAKE}) 162SUB_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. 166SUB_MAKE= `test -x ${MYMAKE} && echo ${MYMAKE} || echo ${MAKE}` \ 167 -m ${.CURDIR}/share/mk 168.else 169SUB_MAKE= ${MAKE} -m ${.CURDIR}/share/mk 170.endif 171 172_MAKE= PATH=${PATH} ${SUB_MAKE} -f Makefile.inc1 TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} 173 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/} 180.endif 181.if defined(TARGET) && !defined(_TARGET) 182_TARGET=${TARGET} 183.endif 184.if defined(TARGET_ARCH) && !defined(_TARGET_ARCH) 185_TARGET_ARCH=${TARGET_ARCH} 186.endif 187# for historical compatibility for xdev targets 188.if defined(XDEV) 189_TARGET= ${XDEV} 190.endif 191.if defined(XDEV_ARCH) 192_TARGET_ARCH= ${XDEV_ARCH} 193.endif 194# Otherwise, default to current machine type and architecture. 195_TARGET?= ${MACHINE} 196_TARGET_ARCH?= ${MACHINE_ARCH} 197 198# 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 202# for all targets. 203# 204.if defined(ALWAYS_CHECK_MAKE) 205${TGTS}: upgrade_checks 206.else 207buildworld: upgrade_checks 208.endif 209 210# 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 215# in this makefile. 216# 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. 225# 226BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 227cleanworld: 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}/* 233.endif 234 # To be safe in this case, fall back to a 'make cleandir' 235 ${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir 236.else 237 -rm -rf ${.OBJDIR}/* 238 -chflags -R 0 ${.OBJDIR} 239 rm -rf ${.OBJDIR}/* 240.endif 241 242# 243# Handle the user-driven targets, using the source relative mk files. 244# 245 246tinderbox toolchains kernel-toolchains: .MAKE 247${TGTS}: .PHONY .MAKE 248 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET} 249 250# The historic default "all" target creates files which may cause stale 251# or (in the cross build case) unlinkable results. Fail with an error 252# when no target is given. The users can explicitly specify "all" 253# if they want the historic behavior. 254.MAIN: _guard 255 256_guard: .PHONY 257 @echo 258 @echo "Explicit target required. Likely \"${SUBDIR_OVERRIDE:Dall:Ubuildworld}\" is wanted. See build(7)." 259 @echo 260 @false 261 262STARTTIME!= LC_ALL=C date 263CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo 264.if !empty(CHECK_TIME) 265.error check your date/time: ${STARTTIME} 266.endif 267 268.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR) 269# 270# world 271# 272# Attempt to rebuild and reinstall everything. This target is not to be 273# used for upgrading an existing FreeBSD system, because the kernel is 274# not included. One can argue that this target doesn't build everything 275# then. 276# 277world: upgrade_checks 278 @echo "--------------------------------------------------------------" 279 @echo ">>> make world started on ${STARTTIME}" 280 @echo "--------------------------------------------------------------" 281.if target(pre-world) 282 @echo 283 @echo "--------------------------------------------------------------" 284 @echo ">>> Making 'pre-world' target" 285 @echo "--------------------------------------------------------------" 286 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world 287.endif 288 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld 289 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld 290.if target(post-world) 291 @echo 292 @echo "--------------------------------------------------------------" 293 @echo ">>> Making 'post-world' target" 294 @echo "--------------------------------------------------------------" 295 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world 296.endif 297 @echo 298 @echo "--------------------------------------------------------------" 299 @echo ">>> make world completed on `LC_ALL=C date`" 300 @echo " (started ${STARTTIME})" 301 @echo "--------------------------------------------------------------" 302.else 303world: 304 @echo "WARNING: make world will overwrite your existing FreeBSD" 305 @echo "installation without also building and installing a new" 306 @echo "kernel. This can be dangerous. Please read the handbook," 307 @echo "'Rebuilding world', for how to upgrade your system." 308 @echo "Define DESTDIR to where you want to install FreeBSD," 309 @echo "including /, to override this warning and proceed as usual." 310 @echo "" 311 @echo "Bailing out now..." 312 @false 313.endif 314 315# 316# kernel 317# 318# Short hand for `make buildkernel installkernel' 319# 320kernel: buildkernel installkernel 321 322# 323# Perform a few tests to determine if the installed tools are adequate 324# for building the world. 325# 326# Note: if we ever need to care about the version of bmake, simply testing 327# MAKE_VERSION against a required version should suffice. 328# 329upgrade_checks: 330.if ${HAVE_MAKE} != ${WANT_MAKE} 331 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,}) 332.endif 333 334# 335# Upgrade make(1) to the current version using the installed 336# headers, libraries and tools. Also, allow the location of 337# the system bsdmake-like utility to be overridden. 338# 339MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \ 340 DESTDIR= \ 341 INSTALL="sh ${.CURDIR}/tools/install.sh" 342MMAKE= ${MMAKEENV} ${MAKE} \ 343 -DNO_MAN -DNO_SHARED \ 344 -DNO_CPU_CFLAGS -DNO_WERROR \ 345 MK_TESTS=no \ 346 DESTDIR= PROGNAME=${MYMAKE:T} 347 348bmake: .PHONY 349 @echo 350 @echo "--------------------------------------------------------------" 351 @echo ">>> Building an up-to-date ${.TARGET}(1)" 352 @echo "--------------------------------------------------------------" 353 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \ 354 ${MMAKE} obj && \ 355 ${MMAKE} depend && \ 356 ${MMAKE} all && \ 357 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR= 358 359tinderbox toolchains kernel-toolchains: upgrade_checks 360 361tinderbox: 362 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe 363 364toolchains: 365 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe 366 367kernel-toolchains: 368 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe 369 370# 371# universe 372# 373# Attempt to rebuild *everything* for all supported architectures, 374# with a reasonable chance of success, regardless of how old your 375# existing system is. 376# 377.if make(universe) || make(universe_kernels) || make(tinderbox) || make(targets) 378TARGETS?=amd64 arm arm64 i386 mips pc98 powerpc sparc64 379_UNIVERSE_TARGETS= ${TARGETS} 380TARGET_ARCHES_arm?= arm armeb armv6 armv6hf 381TARGET_ARCHES_arm64?= aarch64 382TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32 383TARGET_ARCHES_powerpc?= powerpc powerpc64 384TARGET_ARCHES_pc98?= i386 385.for target in ${TARGETS} 386TARGET_ARCHES_${target}?= ${target} 387.endfor 388 389# XXX Add arm64 to universe only if we have an external binutils installed. 390# It does not build with the in-tree linker. 391.if !exists(/usr/local/aarch64-freebsd/bin/ld) && empty(${TARGETS}) 392_UNIVERSE_TARGETS:= ${_UNIVERSE_TARGETS:Narm64} 393universe: universe_arm64_skip 394universe_epilogue: universe_arm64_skip 395universe_arm64_skip: universe_prologue 396 @echo ">> arm64 skipped - install aarch64-binutils port or package to build" 397.endif 398 399.if defined(UNIVERSE_TARGET) 400MAKE_JUST_WORLDS= YES 401.else 402UNIVERSE_TARGET?= buildworld 403.endif 404KERNSRCDIR?= ${.CURDIR}/sys 405 406targets: .PHONY 407 @echo "Supported TARGET/TARGET_ARCH pairs for world and kernel targets" 408.for target in ${TARGETS} 409.for target_arch in ${TARGET_ARCHES_${target}} 410 @echo " ${target}/${target_arch}" 411.endfor 412.endfor 413 414.if defined(DOING_TINDERBOX) 415FAILFILE=${.CURDIR}/_.tinderbox.failed 416MAKEFAIL=tee -a ${FAILFILE} 417.else 418MAKEFAIL=cat 419.endif 420 421universe_prologue: upgrade_checks 422universe: universe_prologue 423universe_prologue: 424 @echo "--------------------------------------------------------------" 425 @echo ">>> make universe started on ${STARTTIME}" 426 @echo "--------------------------------------------------------------" 427.if defined(DOING_TINDERBOX) 428 @rm -f ${FAILFILE} 429.endif 430.for target in ${_UNIVERSE_TARGETS} 431universe: universe_${target} 432universe_epilogue: universe_${target} 433universe_${target}: universe_${target}_prologue 434universe_${target}_prologue: universe_prologue 435 @echo ">> ${target} started on `LC_ALL=C date`" 436universe_${target}_worlds: 437 438.if !defined(MAKE_JUST_KERNELS) 439universe_${target}_done: universe_${target}_worlds 440.for target_arch in ${TARGET_ARCHES_${target}} 441universe_${target}_worlds: universe_${target}_${target_arch} 442universe_${target}_${target_arch}: universe_${target}_prologue .MAKE 443 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} started on `LC_ALL=C date`" 444 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ 445 ${SUB_MAKE} ${JFLAG} ${UNIVERSE_TARGET} \ 446 TARGET=${target} \ 447 TARGET_ARCH=${target_arch} \ 448 > _.${target}.${target_arch}.${UNIVERSE_TARGET} 2>&1 || \ 449 (echo "${target}.${target_arch} ${UNIVERSE_TARGET} failed," \ 450 "check _.${target}.${target_arch}.${UNIVERSE_TARGET} for details" | \ 451 ${MAKEFAIL})) 452 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`" 453.endfor 454.endif # !MAKE_JUST_KERNELS 455 456.if !defined(MAKE_JUST_WORLDS) 457universe_${target}_done: universe_${target}_kernels 458universe_${target}_kernels: universe_${target}_worlds 459universe_${target}_kernels: universe_${target}_prologue .MAKE 460.if exists(${KERNSRCDIR}/${target}/conf/NOTES) 461 @(cd ${KERNSRCDIR}/${target}/conf && env __MAKE_CONF=/dev/null \ 462 ${SUB_MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \ 463 (echo "${target} 'make LINT' failed," \ 464 "check _.${target}.makeLINT for details"| ${MAKEFAIL})) 465.endif 466 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \ 467 universe_kernels 468.endif # !MAKE_JUST_WORLDS 469 470# Tell the user the worlds and kernels have completed 471universe_${target}: universe_${target}_done 472universe_${target}_done: 473 @echo ">> ${target} completed on `LC_ALL=C date`" 474.endfor 475universe_kernels: universe_kernconfs 476.if !defined(TARGET) 477TARGET!= uname -m 478.endif 479.if defined(MAKE_ALL_KERNELS) 480_THINNER=cat 481.else 482_THINNER=xargs grep -L "^.NO_UNIVERSE" || true 483.endif 484KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \ 485 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \ 486 ! -name DEFAULTS ! -name NOTES | \ 487 ${_THINNER} 488universe_kernconfs: 489.for kernel in ${KERNCONFS} 490TARGET_ARCH_${kernel}!= cd ${KERNSRCDIR}/${TARGET}/conf && \ 491 config -m ${KERNSRCDIR}/${TARGET}/conf/${kernel} 2> /dev/null | \ 492 grep -v WARNING: | cut -f 2 493.if empty(TARGET_ARCH_${kernel}) 494.error "Target architecture for ${TARGET}/conf/${kernel} unknown. config(8) likely too old." 495.endif 496universe_kernconfs: universe_kernconf_${TARGET}_${kernel} 497universe_kernconf_${TARGET}_${kernel}: .MAKE 498 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ 499 ${SUB_MAKE} ${JFLAG} buildkernel \ 500 TARGET=${TARGET} \ 501 TARGET_ARCH=${TARGET_ARCH_${kernel}} \ 502 KERNCONF=${kernel} \ 503 > _.${TARGET}.${kernel} 2>&1 || \ 504 (echo "${TARGET} ${kernel} kernel failed," \ 505 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL})) 506.endfor 507universe: universe_epilogue 508universe_epilogue: 509 @echo "--------------------------------------------------------------" 510 @echo ">>> make universe completed on `LC_ALL=C date`" 511 @echo " (started ${STARTTIME})" 512 @echo "--------------------------------------------------------------" 513.if defined(DOING_TINDERBOX) 514 @if [ -e ${FAILFILE} ] ; then \ 515 echo "Tinderbox failed:" ;\ 516 cat ${FAILFILE} ;\ 517 exit 1 ;\ 518 fi 519.endif 520.endif 521 522buildLINT: 523 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT 524 525.if defined(.PARSEDIR) 526# This makefile does not run in meta mode 527.MAKE.MODE= normal 528# Normally the things we run from here don't either. 529# Using -DWITH_META_FILES 530# we can buildworld with meta files created which are useful 531# for debugging, but without any of the rest of a meta mode build. 532MK_META_MODE= no 533MK_STAGING= no 534# tell meta.autodep.mk to not even think about updating anything. 535UPDATE_DEPENDFILE= NO 536.if !make(showconfig) 537.export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE 538.endif 539 540.if make(universe) 541# we do not want a failure of one branch abort all. 542MAKE_JOB_ERROR_TOKEN= no 543.export MAKE_JOB_ERROR_TOKEN 544.endif 545.endif # bmake 546 547.endif # META_MODE 548