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 \ 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 246.if empty(.MAKEFLAGS:M-n) 247# skip this for -n to avoid changing previous behavior of 248# 'make -n buildworld' etc. 249${TGTS}: .MAKE 250tinderbox toolchains kernel-toolchains: .MAKE 251.endif 252 253${TGTS}: 254 ${_+_}@cd ${.CURDIR}; ${_MAKE} ${.TARGET} 255 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. 260.MAIN: _guard 261 262_guard: 263 @echo 264 @echo "Explicit target required (use \"all\" for historic behavior)" 265 @echo 266 @false 267 268STARTTIME!= LC_ALL=C date 269CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0s ; echo 270.if !empty(CHECK_TIME) 271.error check your date/time: ${STARTTIME} 272.endif 273 274.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR) 275# 276# world 277# 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 281# then. 282# 283world: upgrade_checks 284 @echo "--------------------------------------------------------------" 285 @echo ">>> make world started on ${STARTTIME}" 286 @echo "--------------------------------------------------------------" 287.if target(pre-world) 288 @echo 289 @echo "--------------------------------------------------------------" 290 @echo ">>> Making 'pre-world' target" 291 @echo "--------------------------------------------------------------" 292 ${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world 293.endif 294 ${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld 295 ${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld 296.if target(post-world) 297 @echo 298 @echo "--------------------------------------------------------------" 299 @echo ">>> Making 'post-world' target" 300 @echo "--------------------------------------------------------------" 301 ${_+_}@cd ${.CURDIR}; ${_MAKE} post-world 302.endif 303 @echo 304 @echo "--------------------------------------------------------------" 305 @echo ">>> make world completed on `LC_ALL=C date`" 306 @echo " (started ${STARTTIME})" 307 @echo "--------------------------------------------------------------" 308.else 309world: 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." 316 @echo "" 317 @echo "Bailing out now..." 318 @false 319.endif 320 321# 322# kernel 323# 324# Short hand for `make buildkernel installkernel' 325# 326kernel: buildkernel installkernel 327 328# 329# Perform a few tests to determine if the installed tools are adequate 330# for building the world. 331# 332# Note: if we ever need to care about the version of bmake, simply testing 333# MAKE_VERSION against a required version should suffice. 334# 335upgrade_checks: 336.if ${HAVE_MAKE} != ${WANT_MAKE} 337 @(cd ${.CURDIR} && ${MAKE} ${WANT_MAKE:S,^f,,}) 338.endif 339 340# 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. 344# 345MMAKEENV= MAKEOBJDIRPREFIX=${MYMAKE:H} \ 346 DESTDIR= \ 347 INSTALL="sh ${.CURDIR}/tools/install.sh" 348MMAKE= ${MMAKEENV} ${MAKE} \ 349 -DNO_MAN -DNO_SHARED \ 350 -DNO_CPU_CFLAGS -DNO_WERROR \ 351 MK_TESTS=no \ 352 DESTDIR= PROGNAME=${MYMAKE:T} 353 354bmake: .PHONY 355 @echo 356 @echo "--------------------------------------------------------------" 357 @echo ">>> Building an up-to-date ${.TARGET}(1)" 358 @echo "--------------------------------------------------------------" 359 ${_+_}@cd ${.CURDIR}/usr.bin/${.TARGET}; \ 360 ${MMAKE} obj && \ 361 ${MMAKE} depend && \ 362 ${MMAKE} all && \ 363 ${MMAKE} install DESTDIR=${MYMAKE:H} BINDIR= 364 365tinderbox toolchains kernel-toolchains: upgrade_checks 366 367tinderbox: 368 @cd ${.CURDIR} && ${SUB_MAKE} DOING_TINDERBOX=YES universe 369 370toolchains: 371 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=toolchain universe 372 373kernel-toolchains: 374 @cd ${.CURDIR} && ${SUB_MAKE} UNIVERSE_TARGET=kernel-toolchain universe 375 376# 377# universe 378# 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. 382# 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) 387UNIVERSE_arm64=arm64 388.elif empty(${TARGETS}) 389universe: universe_arm64_skip 390universe_epilogue: universe_arm64_skip 391universe_arm64_skip: universe_prologue 392 @echo ">> arm64 skipped - install aarch64-binutils port or package to build" 393.endif 394TARGETS?=amd64 arm ${UNIVERSE_arm64} i386 mips pc98 powerpc sparc64 395TARGET_ARCHES_arm?= arm armeb armv6 armv6hf 396TARGET_ARCHES_arm64?= aarch64 397TARGET_ARCHES_mips?= mipsel mips mips64el mips64 mipsn32 398TARGET_ARCHES_powerpc?= powerpc powerpc64 399TARGET_ARCHES_pc98?= i386 400.for target in ${TARGETS} 401TARGET_ARCHES_${target}?= ${target} 402.endfor 403 404.if defined(UNIVERSE_TARGET) 405MAKE_JUST_WORLDS= YES 406.else 407UNIVERSE_TARGET?= buildworld 408.endif 409KERNSRCDIR?= ${.CURDIR}/sys 410 411targets: .PHONY 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}" 416.endfor 417.endfor 418 419.if defined(DOING_TINDERBOX) 420FAILFILE=${.CURDIR}/_.tinderbox.failed 421MAKEFAIL=tee -a ${FAILFILE} 422.else 423MAKEFAIL=cat 424.endif 425 426universe_prologue: upgrade_checks 427universe: universe_prologue 428universe_prologue: 429 @echo "--------------------------------------------------------------" 430 @echo ">>> make universe started on ${STARTTIME}" 431 @echo "--------------------------------------------------------------" 432.if defined(DOING_TINDERBOX) 433 @rm -f ${FAILFILE} 434.endif 435.for target in ${TARGETS} 436universe: universe_${target} 437universe_epilogue: universe_${target} 438universe_${target}: universe_${target}_prologue 439universe_${target}_prologue: universe_prologue 440 @echo ">> ${target} started on `LC_ALL=C date`" 441universe_${target}_worlds: 442 443.if !defined(MAKE_JUST_KERNELS) 444universe_${target}_done: universe_${target}_worlds 445.for target_arch in ${TARGET_ARCHES_${target}} 446universe_${target}_worlds: universe_${target}_${target_arch} 447universe_${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} \ 451 TARGET=${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" | \ 456 ${MAKEFAIL})) 457 @echo ">> ${target}.${target_arch} ${UNIVERSE_TARGET} completed on `LC_ALL=C date`" 458.endfor 459.endif # !MAKE_JUST_KERNELS 460 461.if !defined(MAKE_JUST_WORLDS) 462universe_${target}_done: universe_${target}_kernels 463universe_${target}_kernels: universe_${target}_worlds 464universe_${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})) 470.endif 471 @cd ${.CURDIR} && ${SUB_MAKE} ${.MAKEFLAGS} TARGET=${target} \ 472 universe_kernels 473.endif # !MAKE_JUST_WORLDS 474 475# Tell the user the worlds and kernels have completed 476universe_${target}: universe_${target}_done 477universe_${target}_done: 478 @echo ">> ${target} completed on `LC_ALL=C date`" 479.endfor 480universe_kernels: universe_kernconfs 481.if !defined(TARGET) 482TARGET!= uname -m 483.endif 484.if defined(MAKE_ALL_KERNELS) 485_THINNER=cat 486.else 487_THINNER=xargs grep -L "^.NO_UNIVERSE" || true 488.endif 489KERNCONFS!= cd ${KERNSRCDIR}/${TARGET}/conf && \ 490 find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \ 491 ! -name DEFAULTS ! -name NOTES | \ 492 ${_THINNER} 493universe_kernconfs: 494.for kernel in ${KERNCONFS} 495TARGET_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." 500.endif 501universe_kernconfs: universe_kernconf_${TARGET}_${kernel} 502universe_kernconf_${TARGET}_${kernel}: .MAKE 503 @(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \ 504 ${SUB_MAKE} ${JFLAG} buildkernel \ 505 TARGET=${TARGET} \ 506 TARGET_ARCH=${TARGET_ARCH_${kernel}} \ 507 KERNCONF=${kernel} \ 508 > _.${TARGET}.${kernel} 2>&1 || \ 509 (echo "${TARGET} ${kernel} kernel failed," \ 510 "check _.${TARGET}.${kernel} for details"| ${MAKEFAIL})) 511.endfor 512universe: universe_epilogue 513universe_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:" ;\ 521 cat ${FAILFILE} ;\ 522 exit 1 ;\ 523 fi 524.endif 525.endif 526 527buildLINT: 528 ${MAKE} -C ${.CURDIR}/sys/${_TARGET}/conf LINT 529 530.if defined(.PARSEDIR) 531# This makefile does not run in meta mode 532.MAKE.MODE= normal 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. 537MK_META_MODE= no 538MK_STAGING= no 539# tell meta.autodep.mk to not even think about updating anything. 540UPDATE_DEPENDFILE= NO 541.if !make(showconfig) 542.export MK_META_MODE MK_STAGING UPDATE_DEPENDFILE 543.endif 544 545.if make(universe) 546# we do not want a failure of one branch abort all. 547MAKE_JOB_ERROR_TOKEN= no 548.export MAKE_JOB_ERROR_TOKEN 549.endif 550.endif # bmake 551 552.endif # META_MODE 553