xref: /minix/Makefile (revision 0a6a1f1d)
1#	$NetBSD: Makefile,v 1.316 2015/07/23 08:03:25 mrg 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
102#   do-extsrc:       builds and installs extsrc if ${MKEXTSRC} != "no".
103#   do-obsolete:     installs the obsolete sets (for the postinstall-* targets).
104#
105
106.if ${.MAKEFLAGS:M${.CURDIR}/share/mk} == ""
107.MAKEFLAGS: -m ${.CURDIR}/share/mk
108.endif
109
110#
111# If _SRC_TOP_OBJ_ gets set here, we will end up with a directory that may
112# not be the top level objdir, because "make obj" can happen in the *middle*
113# of "make build" (long after <bsd.own.mk> is calculated it).  So, pre-set
114# _SRC_TOP_OBJ_ here so it will not be added to ${.MAKEOVERRIDES}.
115#
116_SRC_TOP_OBJ_=
117
118.include <bsd.own.mk>
119
120#
121# Sanity check: make sure that "make build" is not invoked simultaneously
122# with a standard recursive target.
123#
124
125.if make(build) || make(release) || make(snapshot)
126.for targ in ${TARGETS:Nobj:Ncleandir}
127.if make(${targ}) && !target(.BEGIN)
128.BEGIN:
129	@echo 'BUILD ABORTED: "make build" and "make ${targ}" are mutually exclusive.'
130	@false
131.endif
132.endfor
133.endif
134
135#
136# _SUBDIR is used to set SUBDIR, after removing directories that have
137# BUILD_${dir}=no, or that have no ${dir}/Makefile.
138#
139_SUBDIR=	tools lib include gnu external crypto/external bin games
140_SUBDIR+=	libexec sbin usr.bin
141_SUBDIR+=	usr.sbin share sys etc tests compat
142_SUBDIR+=	.WAIT rescue .WAIT distrib regress
143.if defined(__MINIX)
144# the minix subdir depends on some other things (e.g. lib/)
145_SUBDIR+=	.WAIT minix
146.endif # defined(__MINIX)
147
148.for dir in ${_SUBDIR}
149.if "${dir}" == ".WAIT" \
150	|| (${BUILD_${dir}:Uyes} != "no" && exists(${dir}/Makefile))
151SUBDIR+=	${dir}
152.endif
153.endfor
154
155.if exists(regress)
156regression-tests: .PHONY .MAKE
157	@echo Running regression tests...
158	${MAKEDIRTARGET} regress regress
159.endif
160
161.if ${MKUNPRIVED} != "no"
162NOPOSTINSTALL=	# defined
163.endif
164
165afterinstall: .PHONY .MAKE
166.if ${MKMAN} != "no"
167.if !defined(__MINIX)
168	${MAKEDIRTARGET} share/man makedb
169.else
170	${MAKEDIRTARGET} minix/man makedb
171.endif # !defined(__MINIX)
172.endif
173.if (${MKUNPRIVED} != "no" && ${MKINFO} != "no")
174	${MAKEDIRTARGET} gnu/usr.bin/texinfo/install-info infodir-meta
175.endif
176.if !defined(NOPOSTINSTALL)
177	${MAKEDIRTARGET} . postinstall-check
178.endif
179
180_POSTINSTALL=	${.CURDIR}/usr.sbin/postinstall/postinstall \
181		-m ${MACHINE} -a ${MACHINE_ARCH}
182_POSTINSTALL_ENV= \
183	AWK=${TOOL_AWK:Q}		\
184	DB=${TOOL_DB:Q}			\
185	HOST_SH=${HOST_SH:Q}		\
186	MAKE=${MAKE:Q}			\
187	PWD_MKDB=${TOOL_PWD_MKDB:Q}	\
188	SED=${TOOL_SED:Q}		\
189	STAT=${TOOL_STAT:Q}
190
191.if ${MKX11} != "no"
192_POSTINSTALL_X11=-x ${X11SRCDIR:Q}
193.endif
194
195postinstall-check: .PHONY
196	@echo "   === Post installation checks ==="
197	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ check; if [ $$? -gt 1 ]; then exit 1; fi
198	@echo "   ================================"
199
200postinstall-fix: .NOTMAIN .PHONY
201	@echo "   === Post installation fixes ==="
202	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix
203	@echo "   ==============================="
204
205postinstall-fix-obsolete: .NOTMAIN .PHONY
206	@echo "   === Removing obsolete files ==="
207	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete
208	@echo "   ==============================="
209
210postinstall-fix-obsolete_stand: .NOTMAIN .PHONY
211	@echo "   === Removing obsolete files ==="
212	${_POSTINSTALL_ENV} ${HOST_SH} ${_POSTINSTALL} -s ${.CURDIR} ${_POSTINSTALL_X11} -d ${DESTDIR}/ fix obsolete_stand
213	@echo "   ==============================="
214
215
216#
217# Targets (in order!) called by "make build".
218#
219BUILDTARGETS+=	check-tools
220.if ${MKUPDATE} == "no" && !defined(NOCLEANDIR)
221BUILDTARGETS+=	cleandir
222.endif
223.if ${MKOBJDIRS} != "no"
224BUILDTARGETS+=	do-top-obj
225.endif
226.if ${USETOOLS} == "yes"	# {
227.if ${MKOBJDIRS} != "no"
228BUILDTARGETS+=	do-tools-obj
229.endif
230BUILDTARGETS+=	do-tools
231.endif # USETOOLS		# }
232BUILDTARGETS+=	params
233.if ${MKOBJDIRS} != "no"
234BUILDTARGETS+=	obj
235.endif
236BUILDTARGETS+=	clean_METALOG
237.if !defined(NODISTRIBDIRS)
238BUILDTARGETS+=	do-distrib-dirs
239.endif
240.if !defined(NOINCLUDES)
241BUILDTARGETS+=	includes
242.endif
243BUILDTARGETS+=	do-lib
244.if !defined(__MINIX)
245# LSC Not used in MINIX3
246BUILDTARGETS+=	do-compat-lib
247.endif # !defined(__MINIX)
248.if ${MKX11} != "no"
249BUILDTARGETS+=	do-x11
250.endif
251BUILDTARGETS+=	do-build
252.if ${MKEXTSRC} != "no"
253BUILDTARGETS+=	do-extsrc
254.endif
255
256.if defined(__MINIX) && ${MKSRC} == "yes"
257BUILDTARGETS+=	do-installsrc
258.endif # defined(__MINIX)
259
260BUILDTARGETS+=	do-obsolete
261
262#
263# Enforce proper ordering of some rules.
264#
265
266.ORDER:		${BUILDTARGETS}
267includes-lib:	.PHONY includes-include includes-sys
268includes-gnu:	.PHONY includes-lib
269
270#
271# Record the values of variables that might affect the build.
272# If no values have changed, avoid updating the timestamp
273# of the params file.
274#
275# This is referenced by _NETBSD_VERSION_DEPENDS in <bsd.own.mk>.
276#
277.include "${NETBSDSRCDIR}/etc/Makefile.params"
278CLEANDIRFILES+= params
279params: .EXEC
280	${_MKMSG_CREATE} params
281	@${PRINT_PARAMS} >${.TARGET}.new
282	@if cmp -s ${.TARGET}.new ${.TARGET} > /dev/null 2>&1; then \
283		: "params is unchanged" ; \
284		rm ${.TARGET}.new ; \
285	else \
286		: "params has changed or is new" ; \
287		mv ${.TARGET}.new ${.TARGET} ; \
288	fi
289
290#
291# Display current make(1) parameters
292#
293show-params: .PHONY .MAKE
294	@${PRINT_PARAMS}
295
296#
297# Build the system and install into DESTDIR.
298#
299
300START_TIME!=	date
301
302.if defined(__MINIX)
303world: build .PHONY .MAKE
304	${MAKEDIRTARGET} . etcfiles
305	@echo "WARNING: "
306	@echo "WARNING: The 'world' target is obsolete, please use 'build' instead."
307	@echo "WARNING: "
308
309etcfiles: .PHONY .MAKE
310	${MAKEDIRTARGET} etc install-etc-files-safe  DESTDIR=${DESTDIR:U/}
311
312etcforce: .PHONY .MAKE
313	${MAKEDIRTARGET} etc install-etc-files  DESTDIR=${DESTDIR:U/}
314
315.endif # defined(__MINIX)
316
317build: .PHONY .MAKE
318.if defined(BUILD_DONE)
319	@echo "Build already installed into ${DESTDIR}"
320.else
321	@echo "Build started at: ${START_TIME}"
322.for tgt in ${BUILDTARGETS}
323	${MAKEDIRTARGET} . ${tgt}
324.endfor
325	${MAKEDIRTARGET} etc install-etc-release
326.if defined(__MINIX)
327	${MAKEDIRTARGET} etc install-etc-files-safe DESTDIR=${DESTDIR:U/}
328	${MAKEDIRTARGET} releasetools do-hdboot
329.endif # defined(__MINIX)
330	@echo   "Build started at:  ${START_TIME}"
331	@printf "Build finished at: " && date
332.endif
333
334#
335# Build a full distribution, but not a release (i.e. no sets into
336# ${RELEASEDIR}).  "buildworld" enforces a build to ${DESTDIR} != /
337#
338
339distribution buildworld: .PHONY .MAKE
340.if make(buildworld) && \
341    (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
342	@echo "Won't make ${.TARGET} with DESTDIR=/"
343	@false
344.endif
345	${MAKEDIRTARGET} . build NOPOSTINSTALL=1
346	${MAKEDIRTARGET} etc distribution INSTALL_DONE=1
347.if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/"
348	${MAKEDIRTARGET} . postinstall-fix-obsolete
349	${MAKEDIRTARGET} . postinstall-fix-obsolete_stand
350	${MAKEDIRTARGET} distrib/sets checkflist
351.endif
352	@echo   "make ${.TARGET} started at:  ${START_TIME}"
353	@printf "make ${.TARGET} finished at: " && date
354
355#
356# Install the distribution from $DESTDIR to $INSTALLWORLDDIR (defaults to `/')
357# If installing to /, ensures that the host's operating system is NetBSD and
358# the host's `uname -m` == ${MACHINE}.
359#
360
361HOST_UNAME_S!=	uname -s
362.if ${HOST_OSTYPE:C/\-.*//} != "Minix"
363HOST_UNAME_M!=	uname -m
364.else
365HOST_UNAME_M:= ${MACHINE}
366.endif
367
368installworld: .PHONY .MAKE
369.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
370	@echo "Can't make ${.TARGET} to DESTDIR=/"
371	@false
372.endif
373.if !defined(INSTALLWORLDDIR) || \
374    ${INSTALLWORLDDIR} == "" || ${INSTALLWORLDDIR} == "/"
375.if (${HOST_UNAME_S} != "NetBSD") && (${HOST_UNAME_S} != "Minix")
376	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to Minix with INSTALLWORLDDIR=/"
377	@false
378.endif
379.if (${HOST_UNAME_M} != ${MACHINE})
380	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLWORLDDIR=/"
381	@false
382.endif
383.endif
384	${MAKEDIRTARGET} distrib/sets installsets \
385		INSTALLDIR=${INSTALLWORLDDIR:U/} INSTALLSETS=${INSTALLSETS:Q}
386	${MAKEDIRTARGET} . postinstall-check DESTDIR=${INSTALLWORLDDIR}
387	@echo   "make ${.TARGET} started at:  ${START_TIME}"
388	@printf "make ${.TARGET} finished at: " && date
389
390#
391# Install modules from $DESTDIR to $INSTALLMODULESDIR
392#
393installmodules: .PHONY .MAKE
394.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/")
395	@echo "Can't make ${.TARGET} to DESTDIR=/"
396	@false
397.endif
398.if !defined(INSTALLMODULESDIR) || \
399    ${INSTALLMODULESDIR} == "" || ${INSTALLMODULESDIR} == "/"
400.if (${HOST_UNAME_S} != "NetBSD")
401	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_S} to NetBSD with INSTALLMODULESDIR=/"
402	@false
403.endif
404.if (${HOST_UNAME_M} != ${MACHINE})
405	@echo "Won't cross-make ${.TARGET} from ${HOST_UNAME_M} to ${MACHINE} with INSTALLMODULESDIR=/"
406	@false
407.endif
408.endif
409	${MAKEDIRTARGET} sys/modules install DESTDIR=${INSTALLMODULESDIR:U/}
410	@echo   "make ${.TARGET} started at:  ${START_TIME}"
411	@printf "make ${.TARGET} finished at: " && date
412
413#
414# Create sets from $DESTDIR or $NETBSDSRCDIR into $RELEASEDIR
415#
416
417.for tgt in sets sourcesets syspkgs
418${tgt}: .PHONY .MAKE
419	${MAKEDIRTARGET} distrib/sets ${tgt}
420.endfor
421
422#
423# Build a release or snapshot (implies "make distribution").  Note that
424# in this case, the set lists will be checked before the tar files
425# are made.
426#
427
428release snapshot: .PHONY .MAKE
429	${MAKEDIRTARGET} . distribution
430	${MAKEDIRTARGET} etc release DISTRIBUTION_DONE=1
431	@echo   "make ${.TARGET} started at:  ${START_TIME}"
432	@printf "make ${.TARGET} finished at: " && date
433
434#
435# Create a CD-ROM image.
436#
437
438iso-image: .PHONY
439	${MAKEDIRTARGET} distrib iso_image
440	${MAKEDIRTARGET} etc iso-image
441	@echo   "make ${.TARGET} started at:  ${START_TIME}"
442	@printf "make ${.TARGET} finished at: " && date
443
444iso-image-source: .PHONY
445	${MAKEDIRTARGET} distrib iso_image CDSOURCE=true
446	${MAKEDIRTARGET} etc iso-image
447	@echo   "make ${.TARGET} started at:  ${START_TIME}"
448	@printf "make ${.TARGET} finished at: " && date
449
450#
451# Create bootable live images.
452#
453
454live-image: .PHONY
455	${MAKEDIRTARGET} etc live-image
456	@echo   "make ${.TARGET} started at:  ${START_TIME}"
457	@printf "make ${.TARGET} finished at: " && date
458
459#
460# Create bootable installation images.
461#
462
463install-image: .PHONY
464	${MAKEDIRTARGET} etc install-image
465	@echo   "make ${.TARGET} started at:  ${START_TIME}"
466	@printf "make ${.TARGET} finished at: " && date
467
468#
469# Special components of the "make build" process.
470#
471
472check-tools: .PHONY
473.if ${TOOLCHAIN_MISSING} != "no" && !defined(EXTERNAL_TOOLCHAIN)
474	@echo '*** WARNING:  Building on MACHINE=${MACHINE} with missing toolchain.'
475	@echo '*** May result in a failed build or corrupt binaries!'
476.elif defined(EXTERNAL_TOOLCHAIN)
477	@echo '*** Using external toolchain rooted at ${EXTERNAL_TOOLCHAIN}.'
478.endif
479.if defined(NBUILDJOBS)
480	@echo '*** WARNING: NBUILDJOBS is obsolete; use -j directly instead!'
481.endif
482
483# Delete or sanitise a leftover METALOG from a previous build.
484clean_METALOG: .PHONY .MAKE
485.if ${MKUPDATE} != "no"
486	${MAKEDIRTARGET} distrib/sets clean_METALOG
487.endif
488
489do-distrib-dirs: .PHONY .MAKE
490.if !defined(DESTDIR) || ${DESTDIR} == ""
491	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=/
492.else
493	${MAKEDIRTARGET} etc distrib-dirs DESTDIR=${DESTDIR}
494.endif
495
496.for targ in cleandir obj includes
497do-${targ}: .PHONY ${targ}
498	@true
499.endfor
500
501do-tools: .PHONY .MAKE
502	${MAKEDIRTARGET} tools build_install
503
504do-lib: .PHONY .MAKE
505	${MAKEDIRTARGET} lib build_install
506
507do-compat-lib: .PHONY .MAKE
508	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib"
509
510do-top-obj: .PHONY .MAKE
511	${MAKEDIRTARGET} . obj NOSUBDIR=
512
513do-tools-obj: .PHONY .MAKE
514	${MAKEDIRTARGET} tools obj
515
516do-build: .PHONY .MAKE
517.for targ in dependall install
518	${MAKEDIRTARGET} . ${targ} BUILD_tools=no BUILD_lib=no
519.endfor
520
521do-x11: .PHONY .MAKE
522.if ${MKX11} != "no"
523	${MAKEDIRTARGET} external/mit/xorg/tools all
524	${MAKEDIRTARGET} external/mit/xorg/lib build_install
525.if ${MKCOMPATX11} != "no"
526	${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../external/mit/xorg/lib"
527.endif
528.else
529	@echo "MKX11 is not enabled"
530	@false
531.endif
532
533do-extsrc: .PHONY .MAKE
534.if ${MKEXTSRC} != "no"
535	${MAKEDIRTARGET} extsrc build
536.else
537	@echo "MKEXTSRC is not enabled"
538	@false
539.endif
540
541do-obsolete: .PHONY .MAKE
542	${MAKEDIRTARGET} etc install-obsolete-lists
543
544#
545# Speedup stubs for some subtrees that don't need to run these rules.
546# (Tells <bsd.subdir.mk> not to recurse for them.)
547#
548
549.for dir in bin etc distrib games libexec regress sbin usr.bin usr.sbin tools
550includes-${dir}: .PHONY
551	@true
552.endfor
553.for dir in etc distrib regress
554install-${dir}: .PHONY
555	@true
556.endfor
557
558.if defined(__MINIX)
559SRCTAR=src.tar.gz
560do-installsrc:
561	cd ${.CURDIR} && git ls-tree -r HEAD --name-only | tar czf ${.OBJDIR}/$(SRCTAR) -T -
562	${INSTALL_FILE} ${.OBJDIR}/$(SRCTAR) ${DESTDIR}/usr/src/
563.endif # defined(__MINIX)
564
565#
566# XXX this needs to change when distrib Makefiles are recursion compliant
567# XXX many distrib subdirs need "cd etc && make snap_pre snap_kern" first...
568#
569dependall-distrib depend-distrib all-distrib: .PHONY
570	@true
571
572.include <bsd.obj.mk>
573.include <bsd.kernobj.mk>
574.include <bsd.subdir.mk>
575