Makefile revision 1.328
1# $NetBSD: Makefile,v 1.328 2019/08/23 06:38:27 kamil 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 include external crypto/external bin 140_SUBDIR+= games libexec sbin usr.bin 141_SUBDIR+= usr.sbin share sys etc tests compat 142_SUBDIR+= .WAIT rescue .WAIT distrib regress 143 144.for dir in ${_SUBDIR} 145.if "${dir}" == ".WAIT" \ 146 || (${BUILD_${dir}:Uyes} != "no" && exists(${dir}/Makefile)) 147SUBDIR+= ${dir} 148.endif 149.endfor 150 151.if exists(regress) 152regression-tests: .PHONY .MAKE 153 @echo Running regression tests... 154 ${MAKEDIRTARGET} regress regress 155.endif 156 157.if ${MKUNPRIVED} != "no" 158NOPOSTINSTALL= # defined 159.endif 160 161afterinstall: .PHONY .MAKE 162.if ${MKMAN} != "no" 163 ${MAKEDIRTARGET} share/man makedb 164.endif 165.if (${MKUNPRIVED} != "no" && ${MKINFO} != "no") 166 ${MAKEDIRTARGET} external/gpl2/texinfo/bin/install-info infodir-meta 167.endif 168.if !defined(NOPOSTINSTALL) 169 ${MAKEDIRTARGET} . postinstall-check 170.endif 171 172_POSTINSTALL= ${:!cd ${.CURDIR}/usr.sbin/postinstall && \ 173 ${MAKE} print-objdir!}/postinstall \ 174 -m ${MACHINE} -a ${MACHINE_ARCH} 175_POSTINSTALL_ENV= \ 176 AWK=${TOOL_AWK:Q} \ 177 DB=${TOOL_DB:Q} \ 178 HOST_SH=${HOST_SH:Q} \ 179 MAKE=${MAKE:Q} \ 180 PWD_MKDB=${TOOL_PWD_MKDB:Q} \ 181 SED=${TOOL_SED:Q} \ 182 STAT=${TOOL_STAT:Q} 183 184.if ${MKX11} != "no" 185_POSTINSTALL_X11=-x ${X11SRCDIR:Q} 186.endif 187 188postinstall-check: .PHONY 189 @echo " === Post installation checks ===" 190 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi 191 @echo " ================================" 192 193postinstall-fix: .NOTMAIN .PHONY 194 @echo " === Post installation fixes ===" 195 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix 196 @echo " ===============================" 197 198postinstall-fix-obsolete: .NOTMAIN .PHONY 199 @echo " === Removing obsolete files ===" 200 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete 201 @echo " ===============================" 202 203postinstall-fix-obsolete_stand: .NOTMAIN .PHONY 204 @echo " === Removing obsolete files ===" 205 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete_stand 206 @echo " ===============================" 207 208 209# 210# Targets (in order!) called by "make build". 211# 212BUILDTARGETS+= check-tools 213.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR) 214BUILDTARGETS+= cleandir 215.endif 216.if ${MKOBJDIRS} != "no" 217BUILDTARGETS+= do-top-obj 218.endif 219.if ${USETOOLS} == "yes" # { 220.if ${MKOBJDIRS} != "no" 221BUILDTARGETS+= do-tools-obj 222.endif 223BUILDTARGETS+= do-tools 224.endif # USETOOLS # } 225BUILDTARGETS+= params 226.if ${MKOBJDIRS} != "no" 227BUILDTARGETS+= obj 228.endif 229BUILDTARGETS+= clean_METALOG 230.if !defined(NODISTRIBDIRS) 231BUILDTARGETS+= do-distrib-dirs 232.endif 233.if !defined(NOINCLUDES) 234BUILDTARGETS+= includes 235.endif 236BUILDTARGETS+= do-lib 237BUILDTARGETS+= do-compat-lib 238.if ${MKLLVM} != "no" 239BUILDTARGETS+= do-sanitizer-includes 240BUILDTARGETS+= do-sanitizer-lib 241.if ${MKSANITIZER:Uno} == "yes" 242BUILDTARGETS+= do-sanitizer-tools 243.endif 244.endif 245.if ${MKX11} != "no" 246BUILDTARGETS+= do-x11 247.endif 248.if !defined(NOBINARIES) 249BUILDTARGETS+= do-build 250.if ${MKEXTSRC} != "no" 251BUILDTARGETS+= do-extsrc 252.endif 253BUILDTARGETS+= do-obsolete 254.endif 255 256# 257# Enforce proper ordering of some rules. 258# 259 260.ORDER: ${BUILDTARGETS} 261includes-lib: .PHONY includes-include includes-sys 262 263# 264# Record the values of variables that might affect the build. 265# If no values have changed, avoid updating the timestamp 266# of the params file. 267# 268# This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>. 269# 270.include "${NETBSDSRCDIR}/etc/Makefile.params" 271CLEANDIRFILES+= params 272params: .EXEC 273 ${_MKMSG_CREATE} params 274 @${PRINT_PARAMS} >${.TARGET}.new 275 @if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \ 276 : "params is unchanged" ; \ 277 rm ${.TARGET}.new ; \ 278 else \ 279 : "params has changed or is new" ; \ 280 mv ${.TARGET}.new ${.TARGET} ; \ 281 fi 282 283# 284# Display current make(1) parameters 285# 286show-params: .PHONY .MAKE 287 @${PRINT_PARAMS} 288 289# 290# Build the system and install into DESTDIR. 291# 292 293START_TIME!= date 294 295build: .PHONY .MAKE 296.if defined(BUILD_DONE) 297 @echo "Build already installed into ${DESTDIR}" 298.else 299 @echo "Build started at: ${START_TIME}" 300.for tgt in ${BUILDTARGETS} 301 ${MAKEDIRTARGET} . ${tgt} 302.endfor 303 ${MAKEDIRTARGET} etc install-etc-release 304 @echo "Build started at: ${START_TIME}" 305 @printf "Build finished at: " && date 306.endif 307 308# 309# Build a full distribution, but not a release (i.e. no sets into 310# ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != / 311# 312 313distribution buildworld: .PHONY .MAKE 314.if make(buildworld) && \ 315 (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 316 @echo "Won't make ${.TARGET} with DESTDIR=/" 317 @false 318.endif 319 ${MAKEDIRTARGET} . build NOPOSTINSTALL=1 320 ${MAKEDIRTARGET} etc distribution INSTALL_DONE=1 321.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/" 322 ${MAKEDIRTARGET} . postinstall-fix-obsolete 323 ${MAKEDIRTARGET} . postinstall-fix-obsolete_stand 324 ${MAKEDIRTARGET} distrib/sets checkflist 325.endif 326 @echo "make ${.TARGET} started at: ${START_TIME}" 327 @printf "make ${.TARGET} finished at: " && date 328 329# 330# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/') 331# If installing to /, ensures that the host's operating system is NetBSD and 332# the host's `uname -m` == ${MACHINE}. 333# 334 335HOST_UNAME_S!= uname -s 336HOST_UNAME_M!= uname -m 337 338installworld: .PHONY .MAKE 339.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 340 @echo "Can't make ${.TARGET} to DESTDIR=/" 341 @false 342.endif 343.if !defined(INSTALLWORLDDIR) || \ 344 ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/" 345.if (${HOST_UNAME_S} != "NetBSD") 346 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/" 347 @false 348.endif 349.if (${HOST_UNAME_M} != ${MACHINE}) 350 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/" 351 @false 352.endif 353.endif 354 ${MAKEDIRTARGET} distrib/sets installsets \ 355 INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q} 356 ${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR} 357 @echo "make ${.TARGET} started at: ${START_TIME}" 358 @printf "make ${.TARGET} finished at: " && date 359 360# 361# Install modules from $DESTDIR to $INSTALLMODULESDIR 362# 363installmodules: .PHONY .MAKE 364.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") 365 @echo "Can't make ${.TARGET} to DESTDIR=/" 366 @false 367.endif 368.if !defined(INSTALLMODULESDIR) || \ 369 ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/" 370.if (${HOST_UNAME_S} != "NetBSD") 371 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/" 372 @false 373.endif 374.if (${HOST_UNAME_M} != ${MACHINE}) 375 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/" 376 @false 377.endif 378.endif 379 ${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/} 380 @echo "make ${.TARGET} started at: ${START_TIME}" 381 @printf "make ${.TARGET} finished at: " && date 382 383# 384# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR 385# 386 387.for tgt in sets sourcesets syspkgs 388${tgt}: .PHONY .MAKE 389 ${MAKEDIRTARGET} distrib/sets ${tgt} 390.endfor 391 392# 393# Build a release or snapshot (implies "make distribution"). Note that 394# in this case, the set lists will be checked before the tar files 395# are made. 396# 397 398release snapshot: .PHONY .MAKE 399 ${MAKEDIRTARGET} . distribution 400 ${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1 401 @echo "make ${.TARGET} started at: ${START_TIME}" 402 @printf "make ${.TARGET} finished at: " && date 403 404# 405# Create a CD-ROM image. 406# 407 408iso-image: .PHONY 409 ${MAKEDIRTARGET} distrib iso_image 410 ${MAKEDIRTARGET} etc iso-image 411 @echo "make ${.TARGET} started at: ${START_TIME}" 412 @printf "make ${.TARGET} finished at: " && date 413 414iso-image-source: .PHONY 415 ${MAKEDIRTARGET} distrib iso_image CDSOURCE=true 416 ${MAKEDIRTARGET} etc iso-image 417 @echo "make ${.TARGET} started at: ${START_TIME}" 418 @printf "make ${.TARGET} finished at: " && date 419 420# 421# Create bootable live images. 422# 423 424live-image: .PHONY 425 ${MAKEDIRTARGET} etc live-image 426 @echo "make ${.TARGET} started at: ${START_TIME}" 427 @printf "make ${.TARGET} finished at: " && date 428 429# 430# Create bootable installation images. 431# 432 433install-image: .PHONY 434 ${MAKEDIRTARGET} etc install-image 435 @echo "make ${.TARGET} started at: ${START_TIME}" 436 @printf "make ${.TARGET} finished at: " && date 437 438# 439# Special components of the "make build" process. 440# 441 442check-tools: .PHONY 443.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN) 444 @echo '*** WARNING: Building on MACHINE=${MACHINE} with missing toolchain.' 445 @echo '*** May result in a failed build or corrupt binaries!' 446.elif defined(EXTERNAL_TOOLCHAIN) 447 @echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.' 448.endif 449.if defined(NBUILDJOBS) 450 @echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!' 451.endif 452 453# Delete or sanitise a leftover METALOG from a previous build. 454clean_METALOG: .PHONY .MAKE 455.if ${MKUPDATE} != "no" 456 ${MAKEDIRTARGET} distrib/sets clean_METALOG 457.endif 458 459do-distrib-dirs: .PHONY .MAKE 460.if !defined(DESTDIR) || ${DESTDIR} == "" 461 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/ 462.else 463 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR} 464.endif 465 466.for targ in cleandir obj includes 467do-${targ}: .PHONY ${targ} 468 @true 469.endfor 470 471do-tools: .PHONY .MAKE 472 ${MAKEDIRTARGET} tools build_install 473 474do-lib: .PHONY .MAKE 475 ${MAKEDIRTARGET} lib build_install 476 477do-compat-lib: .PHONY .MAKE 478 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib" 479 480do-sanitizer-includes: .PHONY .MAKE 481 ${MAKEDIRTARGET} external/bsd/compiler_rt/lib/clang/include includes 482 ${MAKEDIRTARGET} external/bsd/compiler_rt/lib/clang/share includes 483 484do-sanitizer-lib: .PHONY .MAKE 485 ${MAKEDIRTARGET} external/bsd/compiler_rt/lib/clang/lib build_install 486 487do-sanitizer-tools: .PHONY .MAKE 488.if !exists(${TOOLDIR}/lib/clang) 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