1 # $NetBSD: Makefile,v 1.316 2015/07/23 08:03:25 mrg 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/images.
68 # RELEASEDIR must already have been populated by `make release'
71 # Create CD-ROM image with source in RELEASEDIR/images.
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 # params: record the values of variables that might affect the
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).
106 .if
${.MAKEFLAGS
:M
${.CURDIR
}/share
/mk
} == ""
107 .MAKEFLAGS
: -m
${.CURDIR
}/share
/mk
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}.
118 .
include <bsd.own.mk
>
121 # Sanity check: make sure that "make build" is not invoked simultaneously
122 # with a standard recursive target.
125 .if make
(build
) || make
(release
) || make
(snapshot
)
126 .for targ in
${TARGETS
:Nobj
:Ncleandir
}
127 .if make
(${targ}) && !target
(.BEGIN
)
129 @echo
'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
136 # _SUBDIR is used to set SUBDIR, after removing directories that have
137 # BUILD_${dir}=no, or that have no ${dir}/Makefile.
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
144 # the minix subdir depends on some other things (e.g. lib/)
145 _SUBDIR
+= .WAIT minix
146 .
endif # defined(__MINIX)
148 .for
dir in
${_SUBDIR}
149 .if
"${dir}" == ".WAIT" \
150 ||
(${BUILD_
${dir}:Uyes
} != "no" && exists
(${dir}/Makefile
))
156 regression-tests
: .PHONY .MAKE
157 @echo Running regression tests...
158 ${MAKEDIRTARGET} regress regress
161 .if
${MKUNPRIVED} != "no"
162 NOPOSTINSTALL
= # defined
165 afterinstall
: .PHONY .MAKE
167 .if
!defined
(__MINIX
)
168 ${MAKEDIRTARGET} share
/man makedb
170 ${MAKEDIRTARGET} minix
/man makedb
171 .
endif # !defined(__MINIX)
173 .if
(${MKUNPRIVED} != "no" && ${MKINFO} != "no")
174 ${MAKEDIRTARGET} gnu
/usr.bin
/texinfo
/install-info infodir-meta
176 .if
!defined
(NOPOSTINSTALL
)
177 ${MAKEDIRTARGET} . postinstall-check
180 _POSTINSTALL
= ${.CURDIR
}/usr.sbin
/postinstall
/postinstall \
181 -m
${MACHINE} -a
${MACHINE_ARCH}
185 HOST_SH
=${HOST_SH
:Q
} \
187 PWD_MKDB
=${TOOL_PWD_MKDB
:Q
} \
192 _POSTINSTALL_X11
=-x
${X11SRCDIR
:Q
}
195 postinstall-check
: .PHONY
196 @echo
" === Post installation checks ==="
197 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} ${_POSTINSTALL_X11} -d
${DESTDIR}/ check; if
[ $$?
-gt
1 ]; then exit
1; fi
198 @echo
" ================================"
200 postinstall-fix
: .NOTMAIN .PHONY
201 @echo
" === Post installation fixes ==="
202 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} ${_POSTINSTALL_X11} -d
${DESTDIR}/ fix
203 @echo
" ==============================="
205 postinstall-fix-obsolete
: .NOTMAIN .PHONY
206 @echo
" === Removing obsolete files ==="
207 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} ${_POSTINSTALL_X11} -d
${DESTDIR}/ fix obsolete
208 @echo
" ==============================="
210 postinstall-fix-obsolete_stand
: .NOTMAIN .PHONY
211 @echo
" === Removing obsolete files ==="
212 ${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s
${.CURDIR
} ${_POSTINSTALL_X11} -d
${DESTDIR}/ fix obsolete_stand
213 @echo
" ==============================="
217 # Targets (in order!) called by "make build".
219 BUILDTARGETS
+= check-tools
220 .if
${MKUPDATE} == "no" && !defined
(NOCLEANDIR
)
221 BUILDTARGETS
+= cleandir
223 .if
${MKOBJDIRS} != "no"
224 BUILDTARGETS
+= do-top-obj
226 .if
${USETOOLS} == "yes" # {
227 .if
${MKOBJDIRS} != "no"
228 BUILDTARGETS
+= do-tools-obj
230 BUILDTARGETS
+= do-tools
231 .
endif # USETOOLS # }
232 BUILDTARGETS
+= params
233 .if
${MKOBJDIRS} != "no"
236 BUILDTARGETS
+= clean_METALOG
237 .if
!defined
(NODISTRIBDIRS
)
238 BUILDTARGETS
+= do-distrib-dirs
240 .if
!defined
(NOINCLUDES
)
241 BUILDTARGETS
+= includes
243 BUILDTARGETS
+= do-lib
244 .if
!defined
(__MINIX
)
245 # LSC Not used in MINIX3
246 BUILDTARGETS
+= do-compat-lib
247 .
endif # !defined(__MINIX)
249 BUILDTARGETS
+= do-x11
251 BUILDTARGETS
+= do-build
252 .if
${MKEXTSRC} != "no"
253 BUILDTARGETS
+= do-extsrc
256 .if defined
(__MINIX
) && ${MKSRC} == "yes"
257 BUILDTARGETS
+= do-installsrc
258 .
endif # defined(__MINIX)
260 BUILDTARGETS
+= do-obsolete
263 # Enforce proper ordering of some rules.
266 .ORDER
: ${BUILDTARGETS}
267 includes-lib
: .PHONY includes-include includes-sys
268 includes-gnu
: .PHONY includes-lib
271 # Record the values of variables that might affect the build.
272 # If no values have changed, avoid updating the timestamp
273 # of the params file.
275 # This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>.
277 .
include "${NETBSDSRCDIR}/etc/Makefile.params"
278 CLEANDIRFILES
+= params
280 ${_MKMSG_CREATE} params
281 @
${PRINT_PARAMS} >${.TARGET
}.new
282 @if cmp
-s
${.TARGET
}.new
${.TARGET
} > /dev
/null
2>&1; then \
283 : "params is unchanged" ; \
284 rm ${.TARGET
}.new
; \
286 : "params has changed or is new" ; \
287 mv
${.TARGET
}.new
${.TARGET
} ; \
291 # Display current make(1) parameters
293 show-params
: .PHONY .MAKE
297 # Build the system and install into DESTDIR.
303 world
: build .PHONY .MAKE
304 ${MAKEDIRTARGET} . etcfiles
306 @echo
"WARNING: The 'world' target is obsolete, please use 'build' instead."
309 etcfiles
: .PHONY .MAKE
310 ${MAKEDIRTARGET} etc install-etc-files-safe DESTDIR
=${DESTDIR
:U
/}
312 etcforce
: .PHONY .MAKE
313 ${MAKEDIRTARGET} etc install-etc-files DESTDIR
=${DESTDIR
:U
/}
315 .
endif # defined(__MINIX)
318 .if defined
(BUILD_DONE
)
319 @echo
"Build already installed into ${DESTDIR}"
321 @echo
"Build started at: ${START_TIME}"
322 .for tgt in
${BUILDTARGETS}
323 ${MAKEDIRTARGET} .
${tgt}
325 ${MAKEDIRTARGET} etc install-etc-release
327 ${MAKEDIRTARGET} etc install-etc-files-safe DESTDIR
=${DESTDIR
:U
/}
328 ${MAKEDIRTARGET} releasetools do-hdboot
329 .
endif # defined(__MINIX)
330 @echo
"Build started at: ${START_TIME}"
331 @printf
"Build finished at: " && date
335 # Build a full distribution, but not a release (i.e. no sets into
336 # ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != /
339 distribution buildworld
: .PHONY .MAKE
340 .if make
(buildworld
) && \
341 (!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
342 @echo
"Won't make ${.TARGET} with DESTDIR=/"
345 ${MAKEDIRTARGET} . build NOPOSTINSTALL
=1
346 ${MAKEDIRTARGET} etc distribution INSTALL_DONE
=1
347 .if defined
(DESTDIR
) && ${DESTDIR} != "" && ${DESTDIR} != "/"
348 ${MAKEDIRTARGET} . postinstall-fix-obsolete
349 ${MAKEDIRTARGET} . postinstall-fix-obsolete_stand
350 ${MAKEDIRTARGET} distrib
/sets checkflist
352 @echo
"make ${.TARGET} started at: ${START_TIME}"
353 @printf
"make ${.TARGET} finished at: " && date
356 # Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
357 # If installing to /, ensures that the host's operating system is NetBSD and
358 # the host's `uname -m` == ${MACHINE}.
361 HOST_UNAME_S
!= uname
-s
362 .if
${HOST_OSTYPE
:C
/\
-.
*//} != "Minix"
363 HOST_UNAME_M
!= uname
-m
365 HOST_UNAME_M
:= ${MACHINE}
368 installworld
: .PHONY .MAKE
369 .if
(!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
370 @echo
"Can't make ${.TARGET} to DESTDIR=/"
373 .if
!defined
(INSTALLWORLDDIR
) || \
374 ${INSTALLWORLDDIR} == "" ||
${INSTALLWORLDDIR} == "/"
375 .if
(${HOST_UNAME_S} != "NetBSD") && (${HOST_UNAME_S} != "Minix")
376 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to Minix with INSTALLWORLDDIR=/"
379 .if
(${HOST_UNAME_M} != ${MACHINE})
380 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
384 ${MAKEDIRTARGET} distrib
/sets installsets \
385 INSTALLDIR
=${INSTALLWORLDDIR
:U
/} INSTALLSETS
=${INSTALLSETS
:Q
}
386 ${MAKEDIRTARGET} . postinstall-check DESTDIR
=${INSTALLWORLDDIR}
387 @echo
"make ${.TARGET} started at: ${START_TIME}"
388 @printf
"make ${.TARGET} finished at: " && date
391 # Install modules from $DESTDIR to $INSTALLMODULESDIR
393 installmodules
: .PHONY .MAKE
394 .if
(!defined
(DESTDIR
) ||
${DESTDIR} == "" ||
${DESTDIR} == "/")
395 @echo
"Can't make ${.TARGET} to DESTDIR=/"
398 .if
!defined
(INSTALLMODULESDIR
) || \
399 ${INSTALLMODULESDIR} == "" ||
${INSTALLMODULESDIR} == "/"
400 .if
(${HOST_UNAME_S} != "NetBSD")
401 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/"
404 .if
(${HOST_UNAME_M} != ${MACHINE})
405 @echo
"Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
409 ${MAKEDIRTARGET} sys
/modules
install DESTDIR
=${INSTALLMODULESDIR
:U
/}
410 @echo
"make ${.TARGET} started at: ${START_TIME}"
411 @printf
"make ${.TARGET} finished at: " && date
414 # Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
417 .for tgt in sets sourcesets syspkgs
419 ${MAKEDIRTARGET} distrib
/sets
${tgt}
423 # Build a release or snapshot (implies "make distribution"). Note that
424 # in this case, the set lists will be checked before the tar files
428 release snapshot
: .PHONY .MAKE
429 ${MAKEDIRTARGET} . distribution
430 ${MAKEDIRTARGET} etc release DISTRIBUTION_DONE
=1
431 @echo
"make ${.TARGET} started at: ${START_TIME}"
432 @printf
"make ${.TARGET} finished at: " && date
435 # Create a CD-ROM image.
439 ${MAKEDIRTARGET} distrib iso_image
440 ${MAKEDIRTARGET} etc iso-image
441 @echo
"make ${.TARGET} started at: ${START_TIME}"
442 @printf
"make ${.TARGET} finished at: " && date
444 iso-image-source
: .PHONY
445 ${MAKEDIRTARGET} distrib iso_image CDSOURCE
=true
446 ${MAKEDIRTARGET} etc iso-image
447 @echo
"make ${.TARGET} started at: ${START_TIME}"
448 @printf
"make ${.TARGET} finished at: " && date
451 # Create bootable live images.
455 ${MAKEDIRTARGET} etc live-image
456 @echo
"make ${.TARGET} started at: ${START_TIME}"
457 @printf
"make ${.TARGET} finished at: " && date
460 # Create bootable installation images.
463 install-image
: .PHONY
464 ${MAKEDIRTARGET} etc install-image
465 @echo
"make ${.TARGET} started at: ${START_TIME}"
466 @printf
"make ${.TARGET} finished at: " && date
469 # Special components of the "make build" process.
473 .if
${TOOLCHAIN_MISSING} != "no" && !defined
(EXTERNAL_TOOLCHAIN
)
474 @echo
'*** WARNING: Building on MACHINE=${MACHINE} with missing toolchain.'
475 @echo
'*** May result in a failed build or corrupt binaries!'
476 .elif defined
(EXTERNAL_TOOLCHAIN
)
477 @echo
'*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
479 .if defined
(NBUILDJOBS
)
480 @echo
'*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
483 # Delete or sanitise a leftover METALOG from a previous build.
484 clean_METALOG
: .PHONY .MAKE
485 .if
${MKUPDATE} != "no"
486 ${MAKEDIRTARGET} distrib
/sets clean_METALOG
489 do-distrib-dirs
: .PHONY .MAKE
490 .if
!defined
(DESTDIR
) ||
${DESTDIR} == ""
491 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR
=/
493 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR
=${DESTDIR}
496 .for targ in cleandir obj includes
497 do-
${targ}: .PHONY
${targ}
501 do-tools
: .PHONY .MAKE
502 ${MAKEDIRTARGET} tools build_install
505 ${MAKEDIRTARGET} lib build_install
507 do-compat-lib
: .PHONY .MAKE
508 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS
="../../../lib"
510 do-top-obj
: .PHONY .MAKE
511 ${MAKEDIRTARGET} . obj NOSUBDIR
=
513 do-tools-obj
: .PHONY .MAKE
514 ${MAKEDIRTARGET} tools obj
516 do-build
: .PHONY .MAKE
517 .for targ in dependall
install
518 ${MAKEDIRTARGET} .
${targ} BUILD_tools
=no BUILD_lib
=no
523 ${MAKEDIRTARGET} external
/mit
/xorg
/tools
all
524 ${MAKEDIRTARGET} external
/mit
/xorg
/lib build_install
525 .if
${MKCOMPATX11} != "no"
526 ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS
="../../../external/mit/xorg/lib"
529 @echo
"MKX11 is not enabled"
533 do-extsrc
: .PHONY .MAKE
534 .if
${MKEXTSRC} != "no"
535 ${MAKEDIRTARGET} extsrc build
537 @echo
"MKEXTSRC is not enabled"
541 do-obsolete
: .PHONY .MAKE
542 ${MAKEDIRTARGET} etc install-obsolete-lists
545 # Speedup stubs for some subtrees that don't need to run these rules.
546 # (Tells <bsd.subdir.mk> not to recurse for them.)
549 .for
dir in bin etc distrib games libexec regress sbin usr.bin usr.sbin tools
550 includes-
${dir}: .PHONY
553 .for
dir in etc distrib regress
554 install-
${dir}: .PHONY
561 cd
${.CURDIR
} && git ls-tree
-r HEAD
--name-only |
tar czf
${.OBJDIR
}/$(SRCTAR
) -T
-
562 ${INSTALL_FILE} ${.OBJDIR
}/$(SRCTAR
) ${DESTDIR}/usr
/src
/
563 .
endif # defined(__MINIX)
566 # XXX this needs to change when distrib Makefiles are recursion compliant
567 # XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
569 dependall-distrib depend-distrib all-distrib
: .PHONY
572 .
include <bsd.obj.mk
>
573 .
include <bsd.kernobj.mk
>
574 .
include <bsd.subdir.mk
>