Makefile revision 1.187
1#	$NetBSD: Makefile,v 1.187 2002/09/17 23:18:25 thorpej Exp $
2
3# This is the top-level makefile for building NetBSD. For an outline of
4# how to build a snapshot or release, as well as other release engineering
5# information, see http://www.netbsd.org/developers/releng/index.html
6#
7# Not everything you can set or do is documented in this makefile. In
8# particular, you should review the files in /usr/share/mk (especially
9# bsd.README) for general information on building programs and writing
10# Makefiles within this structure, and see the comments in src/etc/Makefile
11# for further information on installation and release set options.
12#
13# Variables listed below can be set on the make command line (highest
14# priority), in /etc/mk.conf (middle priority), or in the environment
15# (lowest priority).
16#
17# Variables:
18#   DESTDIR is the target directory for installation of the compiled
19#	software. It defaults to /. Note that programs are built against
20#	libraries installed in DESTDIR.
21#   MKMAN, if set to `no', will prevent building of manual pages.
22#   MKOBJDIRS, if not set to `no', will build object directories at
23#	an appropriate point in a build.
24#   MKSHARE, if set to `no', will prevent building and installing
25#	anything in /usr/share.
26#   UPDATE, if defined, will avoid a `make cleandir' at the start of
27#	`make build', as well as having the effects listed in
28#	/usr/share/mk/bsd.README.
29#   NOCLEANDIR, if defined, will avoid a `make cleandir' at the start
30#	of the `make build'.
31#   NOINCLUDES will avoid the `make includes' usually done by `make build'.
32#
33# Targets:
34#   build:
35#	Builds a full release of NetBSD in DESTDIR.  If BUILD_DONE is
36#	set, this is an empty target.
37#   release:
38#	Does a `make build,' and then tars up the DESTDIR files
39#	into RELEASEDIR, in release(7) format. (See etc/Makefile for
40#	more information on this.)
41#   regression-tests:
42#	Runs the regression tests in "regress" on this host.
43#
44# Targets invoked by `make build,' in order:
45#   cleandir:        cleans the tree.
46#   obj:             creates object directories.
47#   do-tools:        builds host toolchain.
48#   do-distrib-dirs: creates the distribution directories.
49#   includes:        installs include files.
50#   do-lib-csu:      builds and installs prerequisites from lib/csu.
51#   do-lib-libc:     builds and installs prerequisites from lib/libc.
52#   do-lib:          builds and installs prerequisites from lib.
53#   do-gnu-lib:      builds and installs prerequisites from gnu/lib.
54#   do-ld.elf_so:    builds and installs prerequisites from libexec/ld.elf_so
55#   do-build:        builds and installs the entire system.
56
57.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
58.MAKEFLAGS: -m ${.CURDIR}/share/mk
59.endif
60
61# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
62# not be the top level objdir, because "make obj" can happen in the *middle*
63# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
64# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
65_SRC_TOP_OBJ_=
66
67.include <bsd.own.mk>
68
69# Sanity check: make sure that "make build" is not invoked simultaneously
70# with a standard recursive target.
71
72.if make(build) || make(release) || make(snapshot)
73.for targ in ${TARGETS:Nobj:Ncleandir}
74.if make(${targ}) && !target(.BEGIN)
75.BEGIN:
76	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
77	@false
78.endif
79.endfor
80.endif
81
82_SUBDIR=	tools lib include gnu bin games libexec sbin usr.bin
83_SUBDIR+=	usr.sbin share rescue sys etc distrib regress
84
85# Weed out directories that don't exist.
86
87.for dir in ${_SUBDIR}
88.if exists(${dir}/Makefile) && (${BUILD_${dir}:Uyes} != "no")
89SUBDIR+=	${dir}
90.endif
91.endfor
92
93.if exists(regress)
94regression-tests:
95	@echo Running regression tests...
96	@(cd ${.CURDIR}/regress && ${MAKE} regress)
97.endif
98
99.if defined(UNPRIVED)
100NOPOSTINSTALL=	# defined
101.endif
102
103afterinstall:
104.if ${MKMAN} != "no"
105	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
106.endif
107.if defined(UNPRIVED) && (${MKINFO} != "no")
108	(cd ${.CURDIR}/gnu/usr.bin/texinfo/install-info && ${MAKE} infodir-meta)
109.endif
110.if !defined(NOPOSTINSTALL)
111	(cd ${.CURDIR} && ${MAKE} postinstall-check)
112.endif
113
114postinstall-check:
115	@echo "   === Post installation checks ==="
116	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ check
117	@echo "   ================================"
118
119postinstall-fix: .NOTMAIN
120	@echo "   === Post installation fixes ==="
121	sh ${.CURDIR}/etc/postinstall -s ${.CURDIR} -d ${DESTDIR}/ fix
122	@echo "   ================================"
123
124
125# Targets (in order!) called by "make build".
126
127BUILDTARGETS+=	check-tools
128.if !defined(UPDATE) && !defined(NOCLEANDIR)
129BUILDTARGETS+=	cleandir
130.endif
131.if ${MKOBJDIRS} != "no"
132BUILDTARGETS+=	obj
133.endif
134.if ${USETOOLS} == "yes"
135BUILDTARGETS+=	do-tools
136.endif
137.if !defined(NODISTRIBDIRS)
138BUILDTARGETS+=	do-distrib-dirs
139.endif
140.if !defined(NOINCLUDES)
141BUILDTARGETS+=	includes
142.endif
143BUILDTARGETS+=	do-lib-csu do-lib-libc do-lib do-gnu-lib do-ld.elf_so do-build
144
145# Enforce proper ordering of some rules.
146
147.ORDER:		${BUILDTARGETS}
148includes-lib:	includes-include includes-sys
149includes-gnu:	includes-lib
150
151# Build the system and install into DESTDIR.
152
153build:
154.if defined(BUILD_DONE)
155	@echo "Build already installed into ${DESTDIR}"
156.else
157	@printf "Build started at: " && date
158.for tgt in ${BUILDTARGETS}
159	@(cd ${.CURDIR} && ${MAKE} ${tgt})
160.endfor
161	@printf "Build finished at: " && date
162.endif
163
164# Build a full distribution, but not a release (i.e. no sets into
165# ${RELEASEDIR}).
166
167distribution:
168	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
169	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 distribution)
170.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
171	(cd ${.CURDIR}/distrib/sets && ${MAKE} checkflist)
172.endif
173	@printf "make ${.TARGET} finished at: " && date
174
175# Build a release or snapshot (implies "make build").  Note that
176# in this case, the set lists will be checked before the tar files
177# are made.
178
179release snapshot:
180	(cd ${.CURDIR} && ${MAKE} NOPOSTINSTALL=1 build)
181	(cd ${.CURDIR}/etc && ${MAKE} INSTALL_DONE=1 release)
182	@printf "make ${.TARGET} finished at: " && date
183
184# Special components of the "make build" process.
185
186check-tools:
187.if ${TOOLCHAIN_MISSING} == "yes" && !defined(EXTERNAL_TOOLCHAIN)
188	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
189	@echo '*** May result in a failed build or corrupt binaries!'
190.elif defined(EXTERNAL_TOOLCHAIN)
191	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
192.endif
193.if defined(NBUILDJOBS)
194	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
195.endif
196
197do-distrib-dirs:
198.if !defined(DESTDIR) || ${DESTDIR} == ""
199	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
200.else
201	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=${DESTDIR} distrib-dirs)
202.endif
203
204.for dir in tools lib/csu lib/libc lib gnu/lib
205do-${dir:S/\//-/}:
206.for targ in dependall install
207	(cd ${.CURDIR}/${dir} && ${MAKE} ${targ})
208.endfor
209.endfor
210
211do-ld.elf_so:
212.for targ in dependall install
213	(cd ${.CURDIR}/libexec/ld.elf_so && ${MAKE} ${targ})
214.endfor
215
216do-build:
217.for targ in dependall install
218	(cd ${.CURDIR} && ${MAKE} ${targ} BUILD_tools=no BUILD_lib=no)
219.endfor
220
221# Speedup stubs for some subtrees that don't need to run these rules.
222# (Tells <bsd.subdir.mk> not to recurse for them.)
223
224.for dir in bin etc distrib games libexec regress sbin usr.sbin tools
225includes-${dir}:
226	@true
227.endfor
228.for dir in etc distrib regress
229install-${dir}:
230	@true
231.endfor
232
233# XXX this needs to change when distrib Makefiles are recursion compliant
234dependall-distrib depend-distrib all-distrib:
235	@true
236
237.include <bsd.obj.mk>
238.include <bsd.subdir.mk>
239
240build-docs: ${.CURDIR}/BUILDING
241${.CURDIR}/BUILDING: BUILDING.mdoc
242	groff -mdoc -Tascii -P-b -P-u -P-o $> >$@
243