Makefile revision 1.332
1# $NetBSD: Makefile,v 1.332 2020/05/15 16:34:44 christos Exp $ 2 3# 4# This is the top-level makefile for building NetBSD. For an outline of 5# how to build a snapshot or release, as well as other release engineering 6# information, see http://www.NetBSD.org/developers/releng/index.html 7# 8# Not everything you can set or do is documented in this makefile. In 9# particular, you should review the files in /usr/share/mk (especially 10# bsd.README) for general information on building programs and writing 11# Makefiles within this structure, and see the comments in src/etc/Makefile 12# for further information on installation and release set options. 13# 14# Variables listed below can be set on the make command line (highest 15# priority), in /etc/mk.conf (middle priority), or in the environment 16# (lowest priority). 17# 18# Variables: 19# DESTDIR is the target directory for installation of the compiled 20# software. It defaults to /. Note that programs are built against 21# libraries installed in DESTDIR. 22# MKMAN, if `no', will prevent building of manual pages. 23# MKOBJDIRS, if not `no', will build object directories at 24# an appropriate point in a build. 25# MKSHARE, if `no', will prevent building and installing 26# anything in /usr/share. 27# MKUPDATE, if not `no', will avoid a `make cleandir' at the start of 28# `make build', as well as having the effects listed in 29# /usr/share/mk/bsd.README. 30# NOCLEANDIR, if defined, will avoid a `make cleandir' at the start 31# of the `make build'. 32# NOINCLUDES will avoid the `make includes' usually done by `make build'. 33# NOBINARIES will not build binaries, only includes and libraries 34# 35# See mk.conf(5) for more details. 36# 37# 38# Targets: 39# build: 40# Builds a full release of NetBSD in DESTDIR, except for the 41# /etc configuration files. 42# If BUILD_DONE is set, this is an empty target. 43# distribution: 44# Builds a full release of NetBSD in DESTDIR, including the /etc 45# configuration files. 46# buildworld: 47# As per `make distribution', except that it ensures that DESTDIR 48# is not the root directory. 49# installworld: 50# Install the distribution from DESTDIR to INSTALLWORLDDIR (which 51# defaults to the root directory). Ensures that INSTALLWORLDDIR 52# is not the root directory if cross compiling. 53# release: 54# Does a `make distribution', and then tars up the DESTDIR files 55# into ${RELEASEDIR}/${RELEASEMACHINEDIR}, in release(7) format. 56# (See etc/Makefile for more information on this.) 57# regression-tests: 58# Runs the regression tests in "regress" on this host. 59# sets: 60# Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 61# from ${DESTDIR} 62# sourcesets: 63# Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR} 64# syspkgs: 65# Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs 66# from ${DESTDIR} 67# iso-image: 68# Create CD-ROM image in RELEASEDIR/images. 69# RELEASEDIR must already have been populated by `make release' 70# or equivalent. 71# iso-image-source: 72# Create CD-ROM image with source in RELEASEDIR/images. 73# RELEASEDIR must already have been populated by 74# `make release sourcesets' or equivalent. 75# live-image: 76# Create bootable live image for emulators or USB stick etc. 77# in RELEASEDIR/liveimage. 78# RELEASEDIR must already have been populated by `make release' 79# or equivalent. 80# install-image: 81# Create bootable installation image for USB stick etc. 82# in RELEASEDIR/installimage. 83# RELEASEDIR must already have been populated by `make release' 84# or equivalent. 85# 86# Targets invoked by `make build,' in order: 87# cleandir: cleans the tree. 88# do-top-obj: creates the top level object directory. 89# do-tools-obj: creates object directories for the host toolchain. 90# do-tools: builds host toolchain. 91# params: record the values of variables that might affect the 92# build. 93# obj: creates object directories. 94# do-distrib-dirs: creates the distribution directories. 95# includes: installs include files. 96# do-lib: builds and installs prerequisites from lib. 97# do-compat-lib: builds and installs prerequisites from compat/lib 98# if ${MKCOMPAT} != "no". 99# do-x11: builds and installs X11 tools and libraries 100# from src/external/mit/xorg if ${MKX11} != "no". 101# do-build: builds and installs the entire system. 102# do-extsrc: builds and installs extsrc if ${MKEXTSRC} != "no". 103# do-obsolete: installs the obsolete sets (for the postinstall-* targets). 104# 105 106.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == "" 107.MAKEFLAGS: -m ${.CURDIR}/share/mk 108.endif 109 110# 111# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may 112# not be the top level objdir, because "make obj" can happen in the *middle* 113# of "make build" (long after <bsd.own.mk> is calculated it). So, pre-set 114# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}. 115# 116_SRC_TOP_OBJ_= 117 118.include <bsd.own.mk> 119 120# 121# Sanity check: make sure that "make build" is not invoked simultaneously 122# with a standard recursive target. 123# 124 125.if make(build) || make(release) || make(snapshot) 126.for targ in ${TARGETS:Nobj:Ncleandir} 127.if make(${targ}) && !target(.BEGIN) 128.BEGIN: 129 @echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.' 130 @false 131.endif 132.endfor 133.endif 134 135# 136# _SUBDIR is used to set SUBDIR, after removing directories that have 137# BUILD_${dir}=no, or that have no ${dir}/Makefile. 138# 139_SUBDIR= tools .WAIT lib 140.if ${MKLLVM} != "no" 141_SUBDIR+= external/bsd/compiler_rt 142.endif 143_SUBDIR+= include external crypto/external bin 144_SUBDIR+= games libexec sbin usr.bin 145_SUBDIR+= usr.sbin share sys etc tests compat 146_SUBDIR+= .WAIT rescue .WAIT distrib regress 147 148.for dir in ${_SUBDIR} 149.if "${dir}" == ".WAIT" \ 150 || (${BUILD_${dir}:Uyes} != "no" && exists(${dir}/Makefile)) 151SUBDIR+= ${dir} 152.endif 153.endfor 154 155.if exists(regress) 156regression-tests: .PHONY .MAKE 157 @echo Running regression tests... 158 ${MAKEDIRTARGET} regress regress 159.endif 160 161.if ${MKUNPRIVED} != "no" 162NOPOSTINSTALL= # defined 163.endif 164 165afterinstall: .PHONY .MAKE 166.if ${MKMAN} != "no" 167 ${MAKEDIRTARGET} share/man makedb 168.endif 169.if (${MKUNPRIVED} != "no" && ${MKINFO} != "no") 170 ${MAKEDIRTARGET} external/gpl2/texinfo/bin/install-info infodir-meta 171.endif 172.if !defined(NOPOSTINSTALL) 173 ${MAKEDIRTARGET} . postinstall-check 174.endif 175 176_POSTINSTALL= ${:!cd ${.CURDIR}/usr.sbin/postinstall && \ 177 ${MAKE} print-objdir!}/postinstall \ 178 -m ${MACHINE} -a ${MACHINE_ARCH} 179_POSTINSTALL_ENV= \ 180 AWK=${TOOL_AWK:Q} \ 181 DB=${TOOL_DB:Q} \ 182 HOST_SH=${HOST_SH:Q} \ 183 MAKE=${MAKE:Q} \ 184 PWD_MKDB=${TOOL_PWD_MKDB:Q} \ 185 SED=${TOOL_SED:Q} \ 186 STAT=${TOOL_STAT:Q} 187 188.if ${MKX11} != "no" 189_POSTINSTALL_X11=-x ${X11SRCDIR:Q} 190.endif 191 192postinstall-check: .PHONY 193 @echo " === Post installation checks ===" 194 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi 195 @echo " ================================" 196 197postinstall-fix: .NOTMAIN .PHONY 198 @echo " === Post installation fixes ===" 199 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix 200 @echo " ===============================" 201 202postinstall-fix-obsolete: .NOTMAIN .PHONY 203 @echo " === Removing obsolete files ===" 204 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete 205 @echo " ===============================" 206 207postinstall-fix-obsolete_stand: .NOTMAIN .PHONY 208 @echo " === Removing obsolete files ===" 209 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete_stand 210 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete_stand_debug 211 @echo " ===============================" 212 213 214# 215# Targets (in order!) called by "make build". 216# 217BUILDTARGETS+= check-tools 218.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR) 219BUILDTARGETS+= cleandir 220.endif 221.if ${MKOBJDIRS} != "no" 222BUILDTARGETS+= do-top-obj 223.endif 224.if ${USETOOLS} == "yes" # { 225.if ${MKOBJDIRS} != "no" 226BUILDTARGETS+= do-tools-obj 227.endif 228BUILDTARGETS+= do-tools 229.endif # USETOOLS # } 230BUILDTARGETS+= params 231.if ${MKOBJDIRS} != "no" 232BUILDTARGETS+= obj 233.endif 234BUILDTARGETS+= clean_METALOG 235.if !defined(NODISTRIBDIRS) 236BUILDTARGETS+= do-distrib-dirs 237.endif 238.if !defined(NOINCLUDES) 239BUILDTARGETS+= includes 240.endif 241BUILDTARGETS+= do-lib 242BUILDTARGETS+= do-compat-lib 243.if ${MKLLVM} != "no" 244BUILDTARGETS+= do-sanitizer 245.if ${MKSANITIZER:Uno} == "yes" 246BUILDTARGETS+= do-sanitizer-tools 247.endif 248.endif 249.if ${MKX11} != "no" 250BUILDTARGETS+= do-x11 251.endif 252.if !defined(NOBINARIES) 253BUILDTARGETS+= do-build 254.if ${MKEXTSRC} != "no" 255BUILDTARGETS+= do-extsrc 256.endif 257BUILDTARGETS+= do-obsolete 258.endif 259 260# 261# Enforce proper ordering of some rules. 262# 263 264.ORDER: ${BUILDTARGETS} 265includes-lib: .PHONY includes-include includes-sys 266 267# 268# Record the values of variables that might affect the build. 269# If no values have changed, avoid updating the timestamp 270# of the params file. 271# 272# This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>. 273# 274.include "${NETBSDSRCDIR}/etc/Makefile.params" 275CLEANDIRFILES+= params 276params: .EXEC 277 ${_MKMSG_CREATE} params 278 @${PRINT_PARAMS} >${.TARGET}.new 279 @if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \ 280 : "params is unchanged" ; \ 281 rm ${.TARGET}.new ; \ 282 else \ 283 : "params has changed or is new" ; \ 284 mv ${.TARGET}.new ${.TARGET} ; \ 285 fi 286 287# 288# Display current make(1) parameters 289# 290show-params: .PHONY .MAKE 291 @${PRINT_PARAMS} 292 293# 294# Build the system and install into DESTDIR. 295# 296 297START_TIME!= date 298 299build: .PHONY .MAKE 300.if defined(BUILD_DONE) 301 @echo "Build already installed into ${DESTDIR}" 302.else 303 @echo "Build started at: ${START_TIME}" 304.for tgt in ${BUILDTARGETS} 305 ${MAKEDIRTARGET} . ${tgt} 306.endfor 307 ${MAKEDIRTARGET} etc install-etc-release 308 @echo "Build started at: ${START_TIME}" 309 @printf "Build finished at: " && date 310.endif 311 312# 313# Build a full distribution, but not a release (i.e. no sets into 314# ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != / 315# 316 317distribution buildworld: .PHONY .MAKE 318.if make(buildworld) && \ 319 (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 320 @echo "Won't make ${.TARGET} with DESTDIR=/" 321 @false 322.endif 323 ${MAKEDIRTARGET} . build NOPOSTINSTALL=1 324 ${MAKEDIRTARGET} etc distribution INSTALL_DONE=1 325.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/" 326 ${MAKEDIRTARGET} . postinstall-fix-obsolete 327 ${MAKEDIRTARGET} . postinstall-fix-obsolete_stand 328 ${MAKEDIRTARGET} distrib/sets checkflist 329.endif 330 @echo "make ${.TARGET} started at: ${START_TIME}" 331 @printf "make ${.TARGET} finished at: " && date 332 333# 334# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/') 335# If installing to /, ensures that the host's operating system is NetBSD and 336# the host's `uname -m` == ${MACHINE}. 337# 338 339HOST_UNAME_S!= uname -s 340HOST_UNAME_M!= uname -m 341 342installworld: .PHONY .MAKE 343.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 344 @echo "Can't make ${.TARGET} to DESTDIR=/" 345 @false 346.endif 347.if !defined(INSTALLWORLDDIR) || \ 348 ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/" 349.if (${HOST_UNAME_S} != "NetBSD") 350 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/" 351 @false 352.endif 353.if (${HOST_UNAME_M} != ${MACHINE}) 354 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/" 355 @false 356.endif 357.endif 358 ${MAKEDIRTARGET} distrib/sets installsets \ 359 INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q} 360 ${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR} 361 @echo "make ${.TARGET} started at: ${START_TIME}" 362 @printf "make ${.TARGET} finished at: " && date 363 364# 365# Install modules from $DESTDIR to $INSTALLMODULESDIR 366# 367installmodules: .PHONY .MAKE 368.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 369 @echo "Can't make ${.TARGET} to DESTDIR=/" 370 @false 371.endif 372.if !defined(INSTALLMODULESDIR) || \ 373 ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/" 374.if (${HOST_UNAME_S} != "NetBSD") 375 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/" 376 @false 377.endif 378.if (${HOST_UNAME_M} != ${MACHINE}) 379 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/" 380 @false 381.endif 382.endif 383 ${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/} 384 @echo "make ${.TARGET} started at: ${START_TIME}" 385 @printf "make ${.TARGET} finished at: " && date 386 387# 388# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR 389# 390 391.for tgt in sets sourcesets syspkgs 392${tgt}: .PHONY .MAKE 393 ${MAKEDIRTARGET} distrib/sets ${tgt} 394.endfor 395 396# 397# Build a release or snapshot (implies "make distribution"). Note that 398# in this case, the set lists will be checked before the tar files 399# are made. 400# 401 402release snapshot: .PHONY .MAKE 403 ${MAKEDIRTARGET} . distribution 404 ${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1 405 @echo "make ${.TARGET} started at: ${START_TIME}" 406 @printf "make ${.TARGET} finished at: " && date 407 408# 409# Create a CD-ROM image. 410# 411 412iso-image: .PHONY 413 ${MAKEDIRTARGET} distrib iso_image 414 ${MAKEDIRTARGET} etc iso-image 415 @echo "make ${.TARGET} started at: ${START_TIME}" 416 @printf "make ${.TARGET} finished at: " && date 417 418iso-image-source: .PHONY 419 ${MAKEDIRTARGET} distrib iso_image CDSOURCE=true 420 ${MAKEDIRTARGET} etc iso-image 421 @echo "make ${.TARGET} started at: ${START_TIME}" 422 @printf "make ${.TARGET} finished at: " && date 423 424# 425# Create bootable live images. 426# 427 428live-image: .PHONY 429 ${MAKEDIRTARGET} etc live-image 430 @echo "make ${.TARGET} started at: ${START_TIME}" 431 @printf "make ${.TARGET} finished at: " && date 432 433# 434# Create bootable installation images. 435# 436 437install-image: .PHONY 438 ${MAKEDIRTARGET} etc install-image 439 @echo "make ${.TARGET} started at: ${START_TIME}" 440 @printf "make ${.TARGET} finished at: " && date 441 442# 443# Special components of the "make build" process. 444# 445 446check-tools: .PHONY 447.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN) 448 @echo '*** WARNING: Building on MACHINE=${MACHINE} with missing toolchain.' 449 @echo '*** May result in a failed build or corrupt binaries!' 450.elif defined(EXTERNAL_TOOLCHAIN) 451 @echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.' 452.endif 453.if defined(NBUILDJOBS) 454 @echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!' 455.endif 456 457# Delete or sanitise a leftover METALOG from a previous build. 458clean_METALOG: .PHONY .MAKE 459.if ${MKUPDATE} != "no" 460 ${MAKEDIRTARGET} distrib/sets clean_METALOG 461.endif 462 463do-distrib-dirs: .PHONY .MAKE 464.if !defined(DESTDIR) || ${DESTDIR} == "" 465 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/ 466.else 467 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR} 468.endif 469 470.for targ in cleandir obj includes 471do-${targ}: .PHONY ${targ} 472 @true 473.endfor 474 475do-tools: .PHONY .MAKE 476 ${MAKEDIRTARGET} tools build_install 477 478do-lib: .PHONY .MAKE 479 ${MAKEDIRTARGET} lib build_install 480 481do-compat-lib: .PHONY .MAKE 482 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib" 483 484do-sanitizer: .PHONY .MAKE 485 ${MAKEDIRTARGET} external/bsd/compiler_rt build_install 486 487do-sanitizer-tools: .PHONY .MAKE 488.if !exists(${TOOLDIR}/lib/clang) && ${HAVE_LLVM:Uno} == "yes" 489 mkdir -p ${TOOLDIR}/lib/clang 490 cd ${DESTDIR}/usr/lib/clang && \ 491 ${TOOL_PAX} -rw . ${TOOLDIR}/lib/clang 492.endif 493 494do-top-obj: .PHONY .MAKE 495 ${MAKEDIRTARGET} . obj NOSUBDIR= 496 497do-tools-obj: .PHONY .MAKE 498 ${MAKEDIRTARGET} tools obj 499 500do-build: .PHONY .MAKE 501.for targ in dependall install 502 ${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no 503.endfor 504 505do-x11: .PHONY .MAKE 506.if ${MKX11} != "no" 507 ${MAKEDIRTARGET} external/mit/xorg/tools all 508 ${MAKEDIRTARGET} external/mit/xorg/lib build_install 509.if ${MKCOMPATX11} != "no" 510 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../external/mit/xorg/lib" 511.endif 512.else 513 @echo "MKX11 is not enabled" 514 @false 515.endif 516 517do-extsrc: .PHONY .MAKE 518.if ${MKEXTSRC} != "no" 519 ${MAKEDIRTARGET} extsrc build 520.else 521 @echo "MKEXTSRC is not enabled" 522 @false 523.endif 524 525do-obsolete: .PHONY .MAKE 526 ${MAKEDIRTARGET} etc install-obsolete-lists 527 528# 529# Speedup stubs for some subtrees that don't need to run these rules. 530# (Tells <bsd.subdir.mk> not to recurse for them.) 531# 532 533.for dir in bin etc distrib games libexec regress sbin usr.bin usr.sbin tools 534includes-${dir}: .PHONY 535 @true 536.endfor 537.for dir in etc distrib regress 538install-${dir}: .PHONY 539 @true 540.endfor 541 542# 543# XXX this needs to change when distrib Makefiles are recursion compliant 544# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first... 545# 546dependall-distrib depend-distrib all-distrib: .PHONY 547 @true 548 549.include <bsd.obj.mk> 550.include <bsd.kernobj.mk> 551.include <bsd.subdir.mk> 552.include <bsd.clean.mk> 553