Makefile revision 1.217
1#	$NetBSD: Makefile,v 1.217 2003/07/21 02:01:42 lukem 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 build', and then tars up the DESTDIR files
54#	into RELEASEDIR/${MACHINE}, 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}/${MACHINE}/binary/sets from ${DESTDIR}
60#   sourcesets:
61#	Populate ${RELEASEDIR}/source/sets from ${NETBSDSRCDIR}
62#
63# Targets invoked by `make build,' in order:
64#   cleandir:        cleans the tree.
65#   obj:             creates object directories.
66#   do-tools:        builds host toolchain.
67#   do-distrib-dirs: creates the distribution directories.
68#   includes:        installs include files.
69#   do-tools-compat: builds the "libnbcompat" library; needed for some
70#                    random host tool programs in the source tree.
71#   do-gnu-lib-libgcc: builds and installs prerequisites from gnu/lib/libgcc
72#   do-lib-csu:      builds and installs prerequisites from lib/csu.
73#   do-lib-libc:     builds and installs prerequisites from lib/libc.
74#   do-lib:          builds and installs prerequisites from lib.
75#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
76#   do-ld.so:        builds and installs prerequisites from libexec/ld.*_so.
77#   do-build:        builds and installs the entire system.
78#   do-obsolete:     builds and installs the entire system.
79#
80
81.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
82.MAKEFLAGS: -m ${.CURDIR}/share/mk
83.endif
84
85#
86# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
87# not be the top level objdir, because "make obj" can happen in the *middle*
88# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
89# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
90#
91_SRC_TOP_OBJ_=
92
93.include <bsd.own.mk>
94
95#
96# Sanity check: make sure that "make build" is not invoked simultaneously
97# with a standard recursive target.
98#
99
100.if make(build) || make(release) || make(snapshot)
101.for targ in ${TARGETS:Nobj:Ncleandir}
102.if make(${targ}) && !target(.BEGIN)
103.BEGIN:
104	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
105	@false
106.endif
107.endfor
108.endif
109
110_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
111_SUBDIR+=	usr.sbin share rescue sys etc .WAIT distrib regress
112
113#
114# Weed out directories that don't exist.
115#
116
117.for dir in ${_SUBDIR}
118.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
119SUBDIR+=	${dir}
120.endif
121.endfor
122
123.if exists(regress)
124regression-tests:
125	@echo Running regression tests...
126	@(cd ${.CURDIR}/regress && ${MAKE} regress)
127.endif
128
129.if ${MKUNPRIVED} != "no"
130NOPOSTINSTALL=	# defined
131.endif
132
133afterinstall:
134.if ${MKMAN} != "no"
135	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
136.endif
137.if (${MKUNPRIVED} != "no" && ${MKINFO} != "no")
138	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
139.endif
140.if !defined(NOPOSTINSTALL)
141	(cd ${.CURDIR} && ${MAKE} postinstall-check)
142.endif
143
144postinstall-check:
145	@echo "   === Post installation checks ==="
146	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
147	@echo "   ================================"
148
149postinstall-fix: .NOTMAIN
150	@echo "   === Post installation fixes ==="
151	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
152	@echo "   ==============================="
153
154postinstall-fix-obsolete: .NOTMAIN
155	@echo "   === Removing obsolete files ==="
156	${HOST_SH} ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix obsolete
157	@echo "   ==============================="
158
159
160#
161# Targets (in order!) called by "make build".
162#
163
164BUILDTARGETS+=	check-tools
165.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
166BUILDTARGETS+=	cleandir
167.endif
168.if ${MKOBJDIRS} != "no"
169BUILDTARGETS+=	obj
170.endif
171.if ${USETOOLS} == "yes"
172BUILDTARGETS+=	do-tools
173.endif
174.if !defined(NODISTRIBDIRS)
175BUILDTARGETS+=	do-distrib-dirs
176.endif
177.if !defined(NOINCLUDES)
178BUILDTARGETS+=	includes
179.endif
180BUILDTARGETS+=	do-tools-compat
181.if ${MKGCC} != "no"
182BUILDTARGETS+=	do-gnu-lib-libgcc
183.endif
184BUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.so do-build
185BUILDTARGETS+=	do-obsolete
186
187#
188# Enforce proper ordering of some rules.
189#
190
191.ORDER:		${BUILDTARGETS}
192includes-lib:	includes-include includes-sys
193includes-gnu:	includes-lib
194
195#
196# Build the system and install into DESTDIR.
197#
198
199START_TIME!=	date
200
201build:
202.if defined(BUILD_DONE)
203	@echo "Build already installed into ${DESTDIR}"
204.else
205	@echo "Build started at: ${START_TIME}"
206.for tgt in ${BUILDTARGETS}
207	@(cd ${.CURDIR} && ${MAKE} ${tgt})
208.endfor
209	@echo   "Build started at:  ${START_TIME}"
210	@printf "Build finished at: " && date
211.endif
212
213#
214# Build a full distribution, but not a release (i.e. no sets into
215# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
216#
217
218distribution buildworld:
219.if make(buildworld) && \
220    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
221	@echo "Won't make ${.TARGET} with DESTDIR=/"
222	@false
223.endif
224	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
225	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
226.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
227	(cd ${.CURDIR} && ${MAKE} postinstall-fix-obsolete)
228	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
229.endif
230	@echo   "make ${.TARGET} started at:  ${START_TIME}"
231	@printf "make ${.TARGET} finished at: " && date
232
233#
234# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
235# If installing to /, ensures that the host's operating system is NetBSD and
236# the host's `uname -m` == ${MACHINE}.
237#
238
239HOST_UNAME_S!=	uname -s
240HOST_UNAME_M!=	uname -m
241
242installworld:
243.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
244	@echo "Can't make ${.TARGET} to DESTDIR=/"
245	@false
246.endif
247.if !defined(INSTALLWORLDDIR) || \
248    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
249.if (${HOST_UNAME_S} != "NetBSD")
250	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLWORLDDIR=/"
251	@false
252.endif
253.if (${HOST_UNAME_M} != ${MACHINE})
254	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
255	@false
256.endif
257.endif
258	(cd ${.CURDIR}/distrib/sets && \
259	    ${MAKE} INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS= installsets)
260	(cd ${.CURDIR} && \
261	    ${MAKE} DESTDIR=${INSTALLWORLDDIR} postinstall-check)
262	@echo   "make ${.TARGET} started at:  ${START_TIME}"
263	@printf "make ${.TARGET} finished at: " && date
264
265#
266# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
267#
268
269.for tgt in sets sourcesets
270${tgt}:
271	(cd ${.CURDIR}/distrib/sets && ${MAKE} $@)
272.endfor
273
274#
275# Build a release or snapshot (implies "make build").  Note that
276# in this case, the set lists will be checked before the tar files
277# are made.
278#
279
280release snapshot:
281	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
282	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
283	@echo   "make ${.TARGET} started at:  ${START_TIME}"
284	@printf "make ${.TARGET} finished at: " && date
285
286#
287# Special components of the "make build" process.
288#
289
290check-tools:
291.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
292	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
293	@echo '*** May result in a failed build or corrupt binaries!'
294.elif defined(EXTERNAL_TOOLCHAIN)
295	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
296.endif
297.if defined(NBUILDJOBS)
298	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
299.endif
300
301do-distrib-dirs:
302.if !defined(DESTDIR) || ${DESTDIR} == ""
303	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
304.else
305	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
306.endif
307
308.for targ in cleandir obj includes
309do-${targ}: ${targ}
310	@true
311.endfor
312
313.for dir in tools tools/compat lib/csu gnu/lib/libgcc lib/libc lib gnu/lib
314do-${dir:S/\//-/g}:
315.for targ in dependall install
316	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
317.endfor
318.endfor
319
320do-ld.so:
321.for targ in dependall install
322.if (${OBJECT_FMT} == "a.out")
323	(cd ${.CURDIR}/libexec/ld.aout_so && ${MAKE} ${targ})
324.endif
325.if (${OBJECT_FMT} == "ELF")
326	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
327.endif
328.endfor
329
330do-build:
331.for targ in dependall install
332	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
333.endfor
334
335do-obsolete:
336	(cd ${.CURDIR}/etc && ${MAKE} install-obsolete-lists)
337
338#
339# Speedup stubs for some subtrees that don't need to run these rules.
340# (Tells <bsd.subdir.mk> not to recurse for them.)
341#
342
343.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
344includes-${dir}:
345	@true
346.endfor
347.for dir in etc distrib regress
348install-${dir}:
349	@true
350.endfor
351
352#
353# XXX this needs to change when distrib Makefiles are recursion compliant
354# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
355#
356dependall-distrib depend-distrib all-distrib:
357	@true
358
359.include <bsd.sys.mk>
360.include <bsd.obj.mk>
361.include <bsd.kernobj.mk>
362.include <bsd.subdir.mk>
363
364build-docs: ${.CURDIR}/BUILDING
365${.CURDIR}/BUILDING: doc/BUILDING.mdoc
366	${TOOL_GROFF} -mdoc -Tascii -P-bou $> >$@
367
368
369#
370# Display current make(1) parameters
371#
372params:
373.for var in	BSDSRCDIR BSDOBJDIR BUILDID DESTDIR EXTERNAL_TOOLCHAIN \
374		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
375		MACHINE MACHINE_ARCH MAKECONF MAKEFLAGS \
376		MAKEOBJDIR MAKEOBJDIRPREFIX \
377		MKOBJDIRS MKUNPRIVED MKUPDATE \
378		RELEASEDIR TOOLCHAIN_MISSING TOOLDIR \
379		USETOOLS
380.if defined(${var})
381	@printf "%20s = '%-s'\n" ${var} ${${var}:Q}
382.else
383	@printf "%20s = (undefined)\n" ${var}
384.endif
385.endfor
386