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