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