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