1 # $NetBSD: Makefile,v 1.299 2012/08/17 16:22:27 joerg Exp $
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
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.
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
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'.
34 # See mk.conf(5) for more details.
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.
43 # Builds a full release of NetBSD in DESTDIR, including the /etc
44 # configuration files.
46 # As per `make distribution', except that it ensures that DESTDIR
47 # is not the root directory.
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.
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.)
57 # Runs the regression tests in "regress" on this host.
59 # Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
62 # Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
64 # Populate ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/syspkgs
67 # Create CD-ROM image in RELEASEDIR/iso.
68 # RELEASEDIR must already have been populated by `make release'
71 # Create CD-ROM image with source in RELEASEDIR/iso.
72 # RELEASEDIR must already have been populated by
73 # `make release sourcesets' or equivalent.
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'
80 # Create bootable installation image for USB stick etc.
81 # in RELEASEDIR/installimage.
82 # RELEASEDIR must already have been populated by `make release'
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 # obj: creates object directories.
91 # do-distrib-dirs: creates the distribution directories.
92 # includes: installs include files.
93 # do-tools-compat: builds the "libnbcompat" library; needed for some
94 # random host tool programs in the source tree.
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).
107 .if
${.MAKEFLAGS
:M
${.CURDIR
}/share
/mk
} == ""
108 .MAKEFLAGS
: -m
${.CURDIR
}/share
/mk
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}.
119 .
include <bsd.own.mk
>
122 # Sanity check: make sure that "make build" is not invoked simultaneously
123 # with a standard recursive target.
126 .if make
(build
) || make
(release
) || make
(snapshot
)
127 .for targ in
${TARGETS
:Nobj
:Ncleandir
}
128 .if make
(${targ}) && !target
(.BEGIN
)
130 @echo
'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
137 # _SUBDIR is used to set SUBDIR, after removing directories that have
138 # BUILD_${dir}=no, or that have no ${dir}/Makefile.
140 _SUBDIR
= tools lib .WAIT
include gnu external crypto
/external bin games
141 _SUBDIR
+= libexec sbin usr.bin
142 _SUBDIR
+= commands man
143 _SUBDIR
+= common drivers kernel servers
144 _SUBDIR
+= usr.sbin share rescue sys etc
test tests compat .WAIT distrib regress
150 .for
dir in
${_SUBDIR}
151 .if
"${dir}" == ".WAIT" \
152 ||
(${BUILD_
${dir}:Uyes
} != "no" && exists
(${dir}/Makefile
))
158 regression-tests
: .PHONY .MAKE
159 @echo Running regression tests...
160 ${MAKEDIRTARGET} regress regress
163 .if
${MKUNPRIVED} != "no"
164 NOPOSTINSTALL
= # defined
167 afterinstall
: .PHONY .MAKE
169 .if
!defined
(__MINIX
)
170 ${MAKEDIRTARGET} share
/man makedb
172 ${MAKEDIRTARGET} man makedb
173 .
endif # !defined(__MINIX)
175 .if
(${MKUNPRIVED} != "no" && ${MKINFO} != "no")
176 ${MAKEDIRTARGET} gnu
/usr.bin
/texinfo
/install-info infodir-meta
178 .if
!defined
(NOPOSTINSTALL
)
179 ${MAKEDIRTARGET} . postinstall-check
182 _POSTINSTALL
= ${.CURDIR
}/usr.sbin
/postinstall
/postinstall
186 HOST_SH
=${HOST_SH
:Q
} \
188 PWD_MKDB
=${TOOL_PWD_MKDB
:Q
} \
191 postinstall-check
: .PHONY
192 @echo
" === Post installation checks ==="
193 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} -d
${DESTDIR}/ check; if
[ $$?
-gt
1 ]; then exit
1; fi
194 @echo
" ================================"
196 postinstall-fix
: .NOTMAIN .PHONY
197 @echo
" === Post installation fixes ==="
198 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} -d
${DESTDIR}/ fix
199 @echo
" ==============================="
201 postinstall-fix-obsolete
: .NOTMAIN .PHONY
202 @echo
" === Removing obsolete files ==="
203 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} -d
${DESTDIR}/ fix obsolete
204 @echo
" ==============================="
208 # Targets (in order!) called by "make build".
210 .if defined
(HAVE_GCC
)
211 .if
${HAVE_GCC} == "4"
213 BUILD_CC_LIB_BASEDIR
= gnu
/lib
214 BUILD_CC_LIB_BASETARGET
= gnu-lib
217 BUILD_CC_LIB_BASEDIR
= external
/gpl3
/gcc
/lib
218 BUILD_CC_LIB_BASETARGET
= external-gpl3-gcc-lib
222 BUILDTARGETS
+= check-tools
223 .if
${MKUPDATE} == "no" && !defined
(NOCLEANDIR
)
224 BUILDTARGETS
+= cleandir
226 .if
${MKOBJDIRS} != "no"
227 BUILDTARGETS
+= do-top-obj
229 .if
${USETOOLS} == "yes" # {
230 .if
${MKOBJDIRS} != "no"
231 BUILDTARGETS
+= do-tools-obj
233 BUILDTARGETS
+= do-tools
234 .
endif # USETOOLS # }
235 .if
${MKOBJDIRS} != "no"
238 BUILDTARGETS
+= clean_METALOG
239 .if
!defined
(NODISTRIBDIRS
)
240 BUILDTARGETS
+= do-distrib-dirs
242 .if
!defined
(NOINCLUDES
)
243 BUILDTARGETS
+= includes
245 BUILDTARGETS
+= do-lib
246 .if
!defined
(__MINIX
)
247 # LSC Not used in MINIX3
248 BUILDTARGETS
+= do-compat-lib
249 .
endif # !defined(__MINIX)
250 BUILDTARGETS
+= do-build
252 BUILDTARGETS
+= do-x11
254 .if
${MKEXTSRC} != "no"
255 BUILDTARGETS
+= do-extsrc
257 BUILDTARGETS
+= do-obsolete
260 # Enforce proper ordering of some rules.
263 .ORDER
: ${BUILDTARGETS}
264 includes-lib
: .PHONY includes-include includes-sys
265 includes-gnu
: .PHONY includes-lib
268 # Build the system and install into DESTDIR.
274 world
: build .PHONY .MAKE
275 ${MAKEDIRTARGET} . etcfiles
277 @echo
"WARNING: The 'world' target is obsolete, please use 'build' instead."
280 etcfiles
: .PHONY .MAKE
281 ${MAKEDIRTARGET} etc install-etc-files-safe DESTDIR
=${DESTDIR
:U
/}
283 etcforce
: .PHONY .MAKE
284 ${MAKEDIRTARGET} etc install-etc-files DESTDIR
=${DESTDIR
:U
/}
286 .
endif # defined(__MINIX)
289 .if defined
(BUILD_DONE
)
290 @echo
"Build already installed into ${DESTDIR}"
292 @echo
"Build started at: ${START_TIME}"
293 .for tgt in
${BUILDTARGETS}
294 ${MAKEDIRTARGET} .
${tgt}
296 ${MAKEDIRTARGET} etc install-etc-release
298 ${MAKEDIRTARGET} etc install-etc-files-safe DESTDIR
=${DESTDIR
:U
/}
299 ${MAKEDIRTARGET} releasetools do-hdboot
300 .
endif # defined(__MINIX)
301 @echo
"Build started at: ${START_TIME}"
302 @printf
"Build finished at: " && date
306 # Build a full distribution, but not a release (i.e. no sets into
307 # ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != /
310 distribution buildworld
: .PHONY .MAKE
311 .if make
(buildworld
) && \
312 (!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
313 @echo
"Won't make ${.TARGET} with DESTDIR=/"
316 ${MAKEDIRTARGET} . build NOPOSTINSTALL
=1
317 ${MAKEDIRTARGET} etc distribution INSTALL_DONE
=1
318 .if defined
(DESTDIR
) && ${DESTDIR} != "" && ${DESTDIR} != "/"
319 ${MAKEDIRTARGET} . postinstall-fix-obsolete
320 ${MAKEDIRTARGET} distrib
/sets checkflist
322 @echo
"make ${.TARGET} started at: ${START_TIME}"
323 @printf
"make ${.TARGET} finished at: " && date
326 # Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
327 # If installing to /, ensures that the host's operating system is NetBSD and
328 # the host's `uname -m` == ${MACHINE}.
331 HOST_UNAME_S
!= uname
-s
332 .if
${HOST_OSTYPE
:C
/\
-.
*//} != "Minix"
333 HOST_UNAME_M
!= uname
-m
335 HOST_UNAME_M
:= ${MACHINE}
338 installworld
: .PHONY .MAKE
339 .if
(!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
340 @echo
"Can't make ${.TARGET} to DESTDIR=/"
343 .if
!defined
(INSTALLWORLDDIR
) || \
344 ${INSTALLWORLDDIR} == "" ||
${INSTALLWORLDDIR} == "/"
345 .if
(${HOST_UNAME_S} != "Minix")
346 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to Minix with INSTALLWORLDDIR=/"
349 .if
(${HOST_UNAME_M} != ${MACHINE})
350 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
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
361 # Install modules from $DESTDIR to $INSTALLMODULESDIR
363 installmodules
: .PHONY .MAKE
364 .if
(!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
365 @echo
"Can't make ${.TARGET} to DESTDIR=/"
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=/"
374 .if
(${HOST_UNAME_M} != ${MACHINE})
375 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
379 ${MAKEDIRTARGET} sys
/modules
install DESTDIR
=${INSTALLMODULESDIR
:U
/}
380 @echo
"make ${.TARGET} started at: ${START_TIME}"
381 @printf
"make ${.TARGET} finished at: " && date
384 # Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
387 .for tgt in sets sourcesets syspkgs
389 ${MAKEDIRTARGET} distrib
/sets
${tgt}
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
398 release 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
405 # Create a CD-ROM image.
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
414 iso-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
421 # Create bootable live images.
425 ${MAKEDIRTARGET} etc live-image
426 @echo
"make ${.TARGET} started at: ${START_TIME}"
427 @printf
"make ${.TARGET} finished at: " && date
430 # Create bootable installation images.
433 install-image
: .PHONY
434 ${MAKEDIRTARGET} etc install-image
435 @echo
"make ${.TARGET} started at: ${START_TIME}"
436 @printf
"make ${.TARGET} finished at: " && date
439 # Special components of the "make build" process.
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}.'
449 .if defined
(NBUILDJOBS
)
450 @echo
'*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
453 # Delete or sanitise a leftover METALOG from a previous build.
454 clean_METALOG
: .PHONY .MAKE
455 .if
${MKUPDATE} != "no"
456 ${MAKEDIRTARGET} distrib
/sets clean_METALOG
459 do-distrib-dirs
: .PHONY .MAKE
460 .if
!defined
(DESTDIR
) ||
${DESTDIR} == ""
461 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR
=/
463 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR
=${DESTDIR}
466 .for targ in cleandir obj includes
467 do-
${targ}: .PHONY
${targ}
471 .for
dir in tools tools
/compat
472 do-
${dir:S
/\
//-/g
}: .PHONY .MAKE
473 .for targ in dependall
install
474 ${MAKEDIRTARGET} ${dir} ${targ}
479 ${MAKEDIRTARGET} lib build_install
481 do-compat-lib
: .PHONY .MAKE
482 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS
="../../../lib"
484 do-top-obj
: .PHONY .MAKE
485 ${MAKEDIRTARGET} . obj NOSUBDIR
=
487 do-tools-obj
: .PHONY .MAKE
488 ${MAKEDIRTARGET} tools obj
490 do-build
: .PHONY .MAKE
491 .for targ in dependall
install
492 ${MAKEDIRTARGET} .
${targ} BUILD_tools
=no BUILD_lib
=no
497 .if
${X11FLAVOUR} == "Xorg"
498 ${MAKEDIRTARGET} external
/mit
/xorg build
500 ${MAKEDIRTARGET} x11 build
503 @echo
"MKX11 is not enabled"
507 do-extsrc
: .PHONY .MAKE
508 .if
${MKEXTSRC} != "no"
509 ${MAKEDIRTARGET} extsrc build
511 @echo
"MKEXTSRC is not enabled"
515 do-obsolete
: .PHONY .MAKE
516 ${MAKEDIRTARGET} etc install-obsolete-lists
519 # Speedup stubs for some subtrees that don't need to run these rules.
520 # (Tells <bsd.subdir.mk> not to recurse for them.)
523 .for
dir in bin etc distrib games libexec regress sbin usr.bin usr.sbin tools
524 includes-
${dir}: .PHONY
527 .for
dir in etc distrib regress
528 install-
${dir}: .PHONY
533 # XXX this needs to change when distrib Makefiles are recursion compliant
534 # XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
536 dependall-distrib depend-distrib all-distrib
: .PHONY
539 .
include <bsd.sys.mk
>
540 .
include <bsd.obj.mk
>
541 .
include <bsd.kernobj.mk
>
542 .
include <bsd.subdir.mk
>
545 # Display current make(1) parameters
548 ${MAKEDIRTARGET} etc params