Makefile revision 1.195
1#	$NetBSD: Makefile,v 1.195 2003/01/02 23:15:27 atatat 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 set to `no', will prevent building of manual pages.
23#   MKOBJDIRS, if not set to `no', will build object directories at
24#	an appropriate point in a build.
25#   MKSHARE, if set to `no', will prevent building and installing
26#	anything in /usr/share.
27#   UPDATE, if defined, 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# Targets:
35#   build:
36#	Builds a full release of NetBSD in DESTDIR.  If BUILD_DONE is
37#	set, this is an empty target.
38#   release:
39#	Does a `make build,' and then tars up the DESTDIR files
40#	into RELEASEDIR, in release(7) format. (See etc/Makefile for
41#	more information on this.)
42#   regression-tests:
43#	Runs the regression tests in "regress" on this host.
44#
45# Targets invoked by `make build,' in order:
46#   cleandir:        cleans the tree.
47#   obj:             creates object directories.
48#   do-tools:        builds host toolchain.
49#   do-distrib-dirs: creates the distribution directories.
50#   includes:        installs include files.
51#   do-lib-csu:      builds and installs prerequisites from lib/csu.
52#   do-lib-libc:     builds and installs prerequisites from lib/libc.
53#   do-lib:          builds and installs prerequisites from lib.
54#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
55#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
56#   do-build:        builds and installs the entire system.
57#
58
59.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
60.MAKEFLAGS: -m ${.CURDIR}/share/mk
61.endif
62
63#
64# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
65# not be the top level objdir, because "make obj" can happen in the *middle*
66# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
67# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
68#
69_SRC_TOP_OBJ_=
70
71.include <bsd.own.mk>
72
73#
74# Sanity check: make sure that "make build" is not invoked simultaneously
75# with a standard recursive target.
76#
77
78.if make(build) || make(release) || make(snapshot)
79.for targ in ${TARGETS:Nobj:Ncleandir}
80.if make(${targ}) && !target(.BEGIN)
81.BEGIN:
82	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
83	@false
84.endif
85.endfor
86.endif
87
88_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
89_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
90
91#
92# Weed out directories that don't exist.
93#
94
95.for dir in ${_SUBDIR}
96.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
97SUBDIR+=	${dir}
98.endif
99.endfor
100
101.if exists(regress)
102regression-tests:
103	@echo Running regression tests...
104	@(cd ${.CURDIR}/regress && ${MAKE} regress)
105.endif
106
107.if defined(UNPRIVED)
108NOPOSTINSTALL=	# defined
109.endif
110
111afterinstall:
112.if ${MKMAN} != "no"
113	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
114.endif
115.if defined(UNPRIVED) && (${MKINFO} != "no")
116	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
117.endif
118.if !defined(NOPOSTINSTALL)
119	(cd ${.CURDIR} && ${MAKE} postinstall-check)
120.endif
121
122postinstall-check:
123	@echo "   === Post installation checks ==="
124	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
125	@echo "   ================================"
126
127postinstall-fix: .NOTMAIN
128	@echo "   === Post installation fixes ==="
129	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
130	@echo "   ================================"
131
132
133#
134# Targets (in order!) called by "make build".
135#
136
137BUILDTARGETS+=	check-tools
138.if !defined(UPDATE) && !defined(NOCLEANDIR)
139BUILDTARGETS+=	cleandir
140.endif
141.if ${MKOBJDIRS} != "no"
142BUILDTARGETS+=	obj
143.endif
144.if ${USETOOLS} == "yes"
145BUILDTARGETS+=	do-tools
146.endif
147.if !defined(NODISTRIBDIRS)
148BUILDTARGETS+=	do-distrib-dirs
149.endif
150.if !defined(NOINCLUDES)
151BUILDTARGETS+=	includes
152.endif
153BUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
154
155#
156# Enforce proper ordering of some rules.
157#
158
159.ORDER:		${BUILDTARGETS}
160includes-lib:	includes-include includes-sys
161includes-gnu:	includes-lib
162
163#
164# Build the system and install into DESTDIR.
165#
166
167START_TIME!=	date
168
169build:
170.if defined(BUILD_DONE)
171	@echo "Build already installed into ${DESTDIR}"
172.else
173	@echo "Build started at: ${START_TIME}"
174.for tgt in ${BUILDTARGETS}
175	@(cd ${.CURDIR} && ${MAKE} ${tgt})
176.endfor
177	@echo   "Build started at:  ${START_TIME}"
178	@printf "Build finished at: " && date
179.endif
180
181#
182# Build a full distribution, but not a release (i.e. no sets into
183# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
184#
185
186distribution buildworld:
187.if make(buildworld) && \
188    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
189	@echo "Won't make ${.TARGET} with DESTDIR=/"
190	@false
191.endif
192	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
193	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
194.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
195	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
196.endif
197	@echo   "make ${.TARGET} started at:  ${START_TIME}"
198	@printf "make ${.TARGET} finished at: " && date
199
200#
201# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
202# If installing to /, ensures that the host's operating system is NetBSD and
203# the host's `uname -m` == ${MACHINE}.
204#
205
206HOST_UNAME_S!=	uname -s
207HOST_UNAME_M!=	uname -m
208
209installworld:
210.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
211	@echo "Can't make ${.TARGET} to DESTDIR=/"
212	@false
213.endif
214.if !defined(INSTALLWORLDDIR) || \
215    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
216.if (${HOST_UNAME_S} != "NetBSD")
217	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
218	@false
219.endif
220.if (${HOST_UNAME_M} != ${MACHINE})
221	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
222	@false
223.endif
224.endif
225	(cd ${.CURDIR}/distrib/sets && \
226	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
227	(cd ${.CURDIR} && \
228	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
229	@echo   "make ${.TARGET} started at:  ${START_TIME}"
230	@printf "make ${.TARGET} finished at: " && date
231
232#
233# Build a release or snapshot (implies "make build").  Note that
234# in this case, the set lists will be checked before the tar files
235# are made.
236#
237
238release snapshot:
239	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
240	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
241	@echo   "make ${.TARGET} started at:  ${START_TIME}"
242	@printf "make ${.TARGET} finished at: " && date
243
244#
245# Special components of the "make build" process.
246#
247
248check-tools:
249.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
250	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
251	@echo '*** May result in a failed build or corrupt binaries!'
252.elif defined(EXTERNAL_TOOLCHAIN)
253	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
254.endif
255.if defined(NBUILDJOBS)
256	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
257.endif
258
259do-distrib-dirs:
260.if !defined(DESTDIR) || ${DESTDIR} == ""
261	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
262.else
263	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
264.endif
265
266.for targ in cleandir obj includes
267do-${targ}: ${targ}
268	@true
269.endfor
270
271.for dir in tools lib/csu lib/libc lib gnu/lib
272do-${dir:S/\//-/}:
273.for targ in dependall install
274	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
275.endfor
276.endfor
277
278do-ld.so:
279.for targ in dependall install
280.if (${OBJECT_FMT} == "a.out")
281	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
282.endif
283.if (${OBJECT_FMT} == "ELF")
284	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
285.endif
286.endfor
287
288do-build:
289.for targ in dependall install
290	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
291.endfor
292
293#
294# Speedup stubs for some subtrees that don't need to run these rules.
295# (Tells <bsd.subdir.mk> not to recurse for them.)
296#
297
298.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
299includes-${dir}:
300	@true
301.endfor
302.for dir in etc distrib regress
303install-${dir}:
304	@true
305.endfor
306
307#
308# XXX this needs to change when distrib Makefiles are recursion compliant
309# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
310#
311dependall-distrib depend-distrib all-distrib:
312	@true
313
314#
315# we don't want the obj target in etc invoked as part of the normal
316# course of events because that makes it too early.  therefore, define
317# a neutral version of the target that bsd.subdir.mk would create.
318#
319obj-etc:
320	@true
321
322.include <bsd.obj.mk>
323.include <bsd.subdir.mk>
324
325#
326# now, make a "real" target that will recurse into etc to enact the
327# obj target, and .USE it onto the end of the obj handling for the
328# current directory.  note that this is only done if we already have
329# commands for the obj target (we won't if we're not making objdirs),
330# and only if etc is a target subdirectory.
331#
332.if commands(obj) && (${SUBDIR:Metc} == "etc")
333real-obj-etc: .USE
334	@(echo "obj ===> etc"; \
335		cd ${.CURDIR}/etc && ${MAKE} obj)
336obj: real-obj-etc
337.endif
338
339build-docs: ${.CURDIR}/BUILDING
340${.CURDIR}/BUILDING: doc/BUILDING.mdoc
341	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
342