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