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