Makefile revision 1.259 1 # $NetBSD: Makefile,v 1.259 2008/10/16 09:43:12 pooka 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 the not 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 #
75 # Targets invoked by `make build,' in order:
76 # cleandir: cleans the tree.
77 # obj: creates object directories.
78 # do-tools: builds host toolchain.
79 # do-distrib-dirs: creates the distribution directories.
80 # includes: installs include files.
81 # do-tools-compat: builds the "libnbcompat" library; needed for some
82 # random host tool programs in the source tree.
83 # do-lib-csu: builds and installs prerequisites from lib/csu.
84 # do-libgcc: builds and installs prerequisites from
85 # gnu/lib/crtstuff${LIBGCC_EXT} (if necessary) and
86 # gnu/lib/libgcc${LIBGCC_EXT}.
87 # do-libpcc: builds and install prerequisites from
88 # external/bsd/pcc/crtstuff and external/bsd/pcc/libpcc.
89 # do-lib-libc: builds and installs prerequisites from lib/libc.
90 # do-lib: builds and installs prerequisites from lib.
91 # do-gnu-lib: builds and installs prerequisites from gnu/lib.
92 # do-external-lib: builds and installs prerequisites from external/lib.
93 # do-sys-rump-fs-lib: builds and installs prerequisites from sys/rump/fs/lib
94 # do-sys-rump-net-lib: builds and installs prerequisites from sys/rump/net/lib
95 # do-ld.so: builds and installs prerequisites from libexec/ld.*_so.
96 # do-build: builds and installs the entire system.
97 # do-x11: builds and installs X11; either
98 # X11R7 from src/external/mit/xorg if ${MKXORG} != "no"
99 # or X11R6 from src/x11 if ${MKX11} != "no"
100 # do-obsolete: installs the obsolete sets (for the postinstall-* targets).
101 #
102
103 .if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
104 .MAKEFLAGS: -m ${.CURDIR}/share/mk
105 .endif
106
107 #
108 # If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
109 # not be the top level objdir, because "make obj" can happen in the *middle*
110 # of "make build" (long after <bsd.own.mk> is calculated it). So, pre-set
111 # _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
112 #
113 _SRC_TOP_OBJ_=
114
115 .include <bsd.own.mk>
116
117 #
118 # Sanity check: make sure that "make build" is not invoked simultaneously
119 # with a standard recursive target.
120 #
121
122 .if make(build) || make(release) || make(snapshot)
123 .for targ in ${TARGETS:Nobj:Ncleandir}
124 .if make(${targ}) && !target(.BEGIN)
125 .BEGIN:
126 @echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
127 @false
128 .endif
129 .endfor
130 .endif
131
132 _SUBDIR= tools lib include gnu external bin games libexec sbin usr.bin
133 _SUBDIR+= usr.sbin share rescue sys etc tests .WAIT distrib regress
134
135 #
136 # Weed out directories that don't exist.
137 #
138
139 .for dir in ${_SUBDIR}
140 .if ("${dir}" == ".WAIT") || exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
141 SUBDIR+= ${dir}
142 .endif
143 .endfor
144
145 .if exists(regress)
146 regression-tests: .PHONY .MAKE
147 @echo Running regression tests...
148 ${MAKEDIRTARGET} regress regress
149 .endif
150
151 .if ${MKUNPRIVED} != "no"
152 NOPOSTINSTALL= # defined
153 .endif
154
155 afterinstall: .PHONY .MAKE
156 .if ${MKMAN} != "no"
157 ${MAKEDIRTARGET} share/man makedb
158 .endif
159 .if (${MKUNPRIVED} != "no" && ${MKINFO} != "no")
160 ${MAKEDIRTARGET} gnu/usr.bin/texinfo/install-info infodir-meta
161 .endif
162 .if !defined(NOPOSTINSTALL)
163 ${MAKEDIRTARGET} . postinstall-check
164 .endif
165
166 _POSTINSTALL= ${.CURDIR}/usr.sbin/postinstall/postinstall
167
168 postinstall-check: .PHONY
169 @echo " === Post installation checks ==="
170 ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi
171 @echo " ================================"
172
173 postinstall-fix: .NOTMAIN .PHONY
174 @echo " === Post installation fixes ==="
175 ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ fix
176 @echo " ==============================="
177
178 postinstall-fix-obsolete: .NOTMAIN .PHONY
179 @echo " === Removing obsolete files ==="
180 ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} -d ${DESTDIR}/ fix obsolete
181 @echo " ==============================="
182
183
184 #
185 # Targets (in order!) called by "make build".
186 #
187 .if defined(HAVE_GCC)
188 .if ${HAVE_GCC} == "3"
189 LIBGCC_EXT=3
190 .else
191 LIBGCC_EXT=4
192 .endif
193 .endif
194
195 BUILDTARGETS+= check-tools
196 .if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
197 BUILDTARGETS+= cleandir
198 .endif
199 .if ${MKOBJDIRS} != "no"
200 BUILDTARGETS+= obj
201 .endif
202 .if ${USETOOLS} == "yes"
203 BUILDTARGETS+= do-tools
204 .endif
205 .if !defined(NODISTRIBDIRS)
206 BUILDTARGETS+= do-distrib-dirs
207 .endif
208 .if !defined(NOINCLUDES)
209 BUILDTARGETS+= includes
210 .endif
211 BUILDTARGETS+= do-tools-compat
212 BUILDTARGETS+= do-lib-csu
213 .if ${MKGCC} != "no"
214 BUILDTARGETS+= do-libgcc
215 .endif
216 .if ${MKPCC} != "no"
217 BUILDTARGET+= do-libpcc
218 .endif
219 BUILDTARGETS+= do-lib-libc
220 BUILDTARGETS+= do-lib do-gnu-lib do-external-lib
221 BUILDTARGETS+= do-sys-rump-fs-lib do-sys-rump-net-lib
222 BUILDTARGETS+= do-ld.so
223 BUILDTARGETS+= do-build
224 .if ${MKX11} != "no" || ${MKXORG} != "no"
225 BUILDTARGETS+= do-x11
226 .endif
227 BUILDTARGETS+= do-obsolete
228
229 #
230 # Enforce proper ordering of some rules.
231 #
232
233 .ORDER: ${BUILDTARGETS}
234 includes-lib: .PHONY includes-include includes-sys
235 includes-gnu: .PHONY includes-lib
236
237 #
238 # Build the system and install into DESTDIR.
239 #
240
241 START_TIME!= date
242
243 build: .PHONY .MAKE
244 .if defined(BUILD_DONE)
245 @echo "Build already installed into ${DESTDIR}"
246 .else
247 @echo "Build started at: ${START_TIME}"
248 .for tgt in ${BUILDTARGETS}
249 ${MAKEDIRTARGET} . ${tgt}
250 .endfor
251 ${MAKEDIRTARGET} etc install-etc-release
252 @echo "Build started at: ${START_TIME}"
253 @printf "Build finished at: " && date
254 .endif
255
256 #
257 # Build a full distribution, but not a release (i.e. no sets into
258 # ${RELEASEDIR}). "buildworld" enforces a build to ${DESTDIR} != /
259 #
260
261 distribution buildworld: .PHONY .MAKE
262 .if make(buildworld) && \
263 (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
264 @echo "Won't make ${.TARGET} with DESTDIR=/"
265 @false
266 .endif
267 ${MAKEDIRTARGET} . build NOPOSTINSTALL=1
268 ${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
269 .if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
270 ${MAKEDIRTARGET} . postinstall-fix-obsolete
271 ${MAKEDIRTARGET} distrib/sets checkflist
272 .endif
273 @echo "make ${.TARGET} started at: ${START_TIME}"
274 @printf "make ${.TARGET} finished at: " && date
275
276 #
277 # Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
278 # If installing to /, ensures that the host's operating system is NetBSD and
279 # the host's `uname -m` == ${MACHINE}.
280 #
281
282 HOST_UNAME_S!= uname -s
283 HOST_UNAME_M!= uname -m
284
285 installworld: .PHONY .MAKE
286 .if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
287 @echo "Can't make ${.TARGET} to DESTDIR=/"
288 @false
289 .endif
290 .if !defined(INSTALLWORLDDIR) || \
291 ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
292 .if (${HOST_UNAME_S} != "NetBSD")
293 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
294 @false
295 .endif
296 .if (${HOST_UNAME_M} != ${MACHINE})
297 @echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
298 @false
299 .endif
300 .endif
301 ${MAKEDIRTARGET} distrib/sets installsets \
302 INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=
303 ${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
304 @echo "make ${.TARGET} started at: ${START_TIME}"
305 @printf "make ${.TARGET} finished at: " && date
306
307 #
308 # Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
309 #
310
311 .for tgt in sets sourcesets syspkgs
312 ${tgt}: .PHONY .MAKE
313 ${MAKEDIRTARGET} distrib/sets ${tgt}
314 .endfor
315
316 #
317 # Build a release or snapshot (implies "make distribution"). Note that
318 # in this case, the set lists will be checked before the tar files
319 # are made.
320 #
321
322 release snapshot: .PHONY .MAKE
323 ${MAKEDIRTARGET} . distribution
324 ${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
325 @echo "make ${.TARGET} started at: ${START_TIME}"
326 @printf "make ${.TARGET} finished at: " && date
327
328 #
329 # Create a CD-ROM image.
330 #
331
332 iso-image: .PHONY
333 ${MAKEDIRTARGET} distrib iso_image
334 ${MAKEDIRTARGET} etc iso-image
335 @echo "make ${.TARGET} started at: ${START_TIME}"
336 @printf "make ${.TARGET} finished at: " && date
337
338 iso-image-source: .PHONY
339 ${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
340 ${MAKEDIRTARGET} etc iso-image
341 @echo "make ${.TARGET} started at: ${START_TIME}"
342 @printf "make ${.TARGET} finished at: " && date
343
344 #
345 # Special components of the "make build" process.
346 #
347
348 check-tools: .PHONY
349 .if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
350 @echo '*** WARNING: Building on MACHINE=${MACHINE} with missing toolchain.'
351 @echo '*** May result in a failed build or corrupt binaries!'
352 .elif defined(EXTERNAL_TOOLCHAIN)
353 @echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
354 .endif
355 .if defined(NBUILDJOBS)
356 @echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
357 .endif
358
359 do-distrib-dirs: .PHONY .MAKE
360 .if !defined(DESTDIR) || ${DESTDIR} == ""
361 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
362 .else
363 ${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
364 .endif
365
366 .for targ in cleandir obj includes
367 do-${targ}: .PHONY ${targ}
368 @true
369 .endfor
370
371 .if defined(HAVE_GCC)
372 BUILD_CC_LIB= gnu/lib/crtstuff${LIBGCC_EXT}
373 BUILD_CC_LIB+= gnu/lib/libgcc${LIBGCC_EXT}
374 .elif defined(HAVE_PCC)
375 BUILD_CC_LIB+= external/bsd/pcc/crtstuff
376 BUILD_CC_LIB+= external/bsd/pcc/libpcc
377 .endif
378
379 .for dir in tools tools/compat lib/csu ${BUILD_CC_LIB} lib/libc lib/libdes lib gnu/lib external/lib sys/rump/fs/lib sys/rump/net/lib
380 do-${dir:S/\//-/g}: .PHONY .MAKE
381 .for targ in dependall install
382 ${MAKEDIRTARGET} ${dir} ${targ}
383 .endfor
384 .endfor
385
386 do-libgcc: .PHONY .MAKE
387 .if defined(HAVE_GCC)
388 .if ${MKGCC} != "no"
389 .if (${HAVE_GCC} == "3" || ${HAVE_GCC} == "4")
390 ${MAKEDIRTARGET} . do-gnu-lib-crtstuff${LIBGCC_EXT}
391 .endif
392 ${MAKEDIRTARGET} . do-gnu-lib-libgcc${LIBGCC_EXT}
393 .endif
394 .endif
395
396 do-libpcc: .PHONY .MAKE
397 .if defined(HAVE_PCC)
398 .if ${MKPCC} != "no"
399 ${MAKEDIRTARGET} . do-pcc-lib-crtstuff
400 ${MAKEDIRTARGET} . do-pcc-lib-libpcc
401 .endif
402 .endif
403
404 do-ld.so: .PHONY .MAKE
405 .for targ in dependall install
406 .if (${OBJECT_FMT} == "a.out")
407 ${MAKEDIRTARGET} libexec/ld.aout_so ${targ}
408 .endif
409 .if (${OBJECT_FMT} == "ELF")
410 ${MAKEDIRTARGET} libexec/ld.elf_so ${targ}
411 .endif
412 .endfor
413
414 do-build: .PHONY .MAKE
415 .for targ in dependall install
416 ${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
417 .endfor
418
419 do-x11: .PHONY .MAKE
420 .if ${MKXORG} != "no"
421 ${MAKEDIRTARGET} external/mit/xorg build
422 .elif ${MKX11} != "no"
423 ${MAKEDIRTARGET} x11 build
424 .else
425 @echo "Neither MKX11 or MKXORG is enabled"
426 @false
427 .endif
428
429 do-obsolete: .PHONY .MAKE
430 ${MAKEDIRTARGET} etc install-obsolete-lists
431
432 #
433 # Speedup stubs for some subtrees that don't need to run these rules.
434 # (Tells <bsd.subdir.mk> not to recurse for them.)
435 #
436
437 .for dir in bin etc distrib games libexec regress sbin usr.sbin tools
438 includes-${dir}: .PHONY
439 @true
440 .endfor
441 .for dir in etc distrib regress
442 install-${dir}: .PHONY
443 @true
444 .endfor
445
446 #
447 # XXX this needs to change when distrib Makefiles are recursion compliant
448 # XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
449 #
450 dependall-distrib depend-distrib all-distrib: .PHONY
451 @true
452
453 .include <bsd.sys.mk>
454 .include <bsd.obj.mk>
455 .include <bsd.kernobj.mk>
456 .include <bsd.subdir.mk>
457
458 build-docs: .PHONY ${.CURDIR}/BUILDING
459 ${.CURDIR}/BUILDING: doc/BUILDING.mdoc
460 ${_MKMSG_CREATE} ${.TARGET}
461 ${TOOL_GROFF} -mdoc -Tascii -P-bou $> >$@
462
463
464 #
465 # Display current make(1) parameters
466 #
467 params: .PHONY .MAKE
468 ${MAKEDIRTARGET} etc params
469