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