1#	$NetBSD: Makefile,v 1.219 2024/04/01 02:22:38 christos Exp $
2
3.include <bsd.own.mk>
4.include <bsd.endian.mk>
5
6# Make sure that the ordered build/install processing applies when using
7# plain make.
8.MAIN: build_install
9
10# TOOLDIR must be valid, unless MKTOOLS=no
11.if ${MKTOOLS:Uyes} != "no"
12.  if "${TOOLDIR}" == ""
13.    error TOOLDIR is undefined or empty
14.  elif ${TOOLDIR:tW:M/*} == ""
15.    error TOOLDIR '${TOOLDIR}' is not an absolute path
16.  endif
17.endif # MKTOOLS != no
18
19# TOOLS_BUILDRUMP == yes builds only the subset of the tools required
20# for building rump kernels and the hypervisor.  It is typically used
21# when building rump kernels targeted for non-NetBSD systems (via
22# buildrump.sh), and should not be set for a regular "make build".
23TOOLS_BUILDRUMP?=no
24
25.if ${TOOLCHAIN_MISSING} == "no"
26. if (defined(HAVE_GCC) && ${HAVE_GCC} > 0) || \
27     (defined(HAVE_GDB) && ${HAVE_GDB} > 0 && ${MKCROSSGDB:Uno} != "no")
28TOOLCHAIN_BITS+= gmake .WAIT
29TOOLCHAIN_BITS+= gmp .WAIT
30TOOLCHAIN_BITS+= mpfr .WAIT
31TOOLCHAIN_BITS+= mpc .WAIT
32.  if (defined(HAVE_GCC) && ${HAVE_GCC} >= 12)
33TOOLCHAIN_BITS+= isl .WAIT
34.  endif
35. endif
36
37TOOLCHAIN_BITS+= binutils .WAIT
38
39. if defined(HAVE_GCC) && ${HAVE_GCC} > 0
40TOOLCHAIN_BITS+= gcc
41. endif
42
43. if defined(HAVE_GDB) && ${HAVE_GDB} > 0 && ${MKCROSSGDB:Uno} != "no"
44TOOLCHAIN_BITS+= gdb
45. endif
46
47TOOLCHAIN_BITS+= .WAIT
48.endif
49
50.if defined(HAVE_PCC)
51. if ${TOOLCHAIN_MISSING} == "no"
52TOOLCHAIN_BITS+= pcc
53. endif
54.endif
55
56.if ${TOOLCHAIN_MISSING} == "no" || defined(EXTERNAL_TOOLCHAIN)
57TOOLCHAIN_BITS+= dbsym mdsetimage
58.endif
59
60DTRACE_BITS=
61.if ${MKDTRACE} != "no" || ${MKCTF} != "no"
62DTRACE_BITS+= .WAIT elftoolchain/common
63DTRACE_BITS+= .WAIT elftoolchain/libelf
64DTRACE_BITS+= .WAIT elftoolchain/libdwarf
65DTRACE_BITS+= .WAIT libctf
66.endif
67.if ${MKCTF} != "no"
68DTRACE_BITS+= .WAIT ctfconvert ctfmerge
69.endif
70
71LINT_BITS=
72.if ${MKLINT} != "no"
73LINT_BITS= lint lint2
74.endif
75
76# All of host-mkdep, compat, and binstall are needed before anything
77# else.  Within this group, they must be built in a specific order, and
78# all of them must be built before any of them is installed.  They may
79# be installed in any order.  This can't be expressed using the .WAIT
80# notation inside the SUBDIR list.
81#
82# XXX .ORDER does not work when multiple targets are passed on the
83# make command line without "-j", so use dependencies in addition to .ORDER.
84#
85.ORDER: dependall-host-mkdep dependall-compat dependall-binstall \
86	dependall-date
87.if make(dependall-host-mkdep) && make(dependall-compat)
88dependall-compat: dependall-host-mkdep
89.endif
90.if make(dependall-compat) && make(dependall-binstall)
91dependall-binstall: dependall-compat
92.endif
93.if make(dependall-date)
94dependall-date: dependall-host-mkdep dependall-compat
95.endif
96
97# Dependencies in SUBDIR below ordered to maximize parallel ability.
98# See above for special treatment for host-mkdep, compat, and binstall.
99#
100SUBDIR=	host-mkdep compat binstall date \
101	.WAIT mktemp .WAIT sed .WAIT genassym
102.if ${TOOLS_BUILDRUMP} == "no"
103SUBDIR+= cap_mkdb crunchgen ctags gencat hexdump \
104		${LINT_BITS} \
105		makewhatis mtree nbperf .WAIT uudecode
106.endif
107
108SUBDIR+= cat gzip rpcgen join lorder m4 mkdep tsort .WAIT yacc .WAIT awk .WAIT lex
109.if ${TOOLS_BUILDRUMP} == "no"
110SUBDIR+= xz-include .WAIT grep xz-lib pax .WAIT libprop
111
112SUBDIR += .WAIT texinfo \
113	.WAIT tic \
114	.WAIT ${TOOLCHAIN_BITS} \
115	${DTRACE_BITS} \
116		asn1_compile cksum compile_et db \
117		file lint1 slc \
118		makefs sortinfo \
119		.WAIT menuc mkcsmapper mkesdb mklocale mknod msgc \
120		.WAIT disklabel gpt \
121		.WAIT paxctl \
122		.WAIT fdisk \
123		.WAIT installboot \
124		pwd_mkdb strfile sunlabel vgrind zic
125.endif
126SUBDIR+= stat .WAIT config
127.if ${TOOLS_BUILDRUMP} == "no"
128SUBDIR+= xz-bin
129.endif
130
131.if ${MKLLVM} != "no" || ${MKLLVMRT} != "no"
132SUBDIR+= \
133	llvm .WAIT \
134	llvm-lib/libLLVMDemangle llvm-lib/libLLVMSupport llvm-lib/libLLVMTableGen .WAIT \
135	llvm-tblgen
136.endif
137.if ${MKLLVM} != "no"
138SUBDIR+= \
139	llvm-clang-tblgen
140.endif
141.if ${MKLLVM} != "no" && !defined(EXTERNAL_TOOLCHAIN)
142SUBDIR+= \
143	.WAIT llvm-include .WAIT \
144	llvm-lib .WAIT \
145	llvm-clang
146.endif
147
148.if ${MKMAN} != "no" || ${MKDOC} != "no" || ${MKHTML} != "no"
149. if ${MKGROFF} != "no"
150SUBDIR+=	groff
151. endif
152SUBDIR+=	mandoc
153.endif
154
155.if ${TOOLS_BUILDRUMP} == "no"
156
157.if ${MKMAINTAINERTOOLS:Uno} != "no"
158SUBDIR+=	autoconf .WAIT gettext
159.endif
160
161.if ${USE_PIGZGZIP} != "no"
162SUBDIR+=	pigz
163.endif
164
165.if ${MACHINE} == "hppa"
166SUBDIR+=	hppa-mkboot
167.endif
168
169.if ${MACHINE} == "ibmnws"
170SUBDIR+=	ibmnws-ncdcs
171.endif
172
173.if ${MACHINE} == "macppc"
174SUBDIR+=	macppc-fixcoff
175.endif
176
177.if (${MACHINE} == "prep" || ${MACHINE} == "rs6000" || ${MACHINE} == "bebox")
178SUBDIR+=	powerpc-mkbootimage
179.endif
180
181.if ${MACHINE_CPU} == "arm"
182SUBDIR+=	arm-elf2aout
183.endif
184
185.if ${MACHINE_CPU} == "m68k"
186SUBDIR+=	m68k-elf2aout
187.endif
188
189.if !empty(MACHINE_ARCH:Mmips*)
190SUBDIR+=	mips-elf2ecoff
191.endif
192
193.if (${MACHINE} == "sgimips")
194SUBDIR+=	sgivol
195.endif
196
197.if ${MACHINE} == "acorn32"
198SUBDIR+=	sparkcrc
199.endif
200
201.if (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64")
202SUBDIR+=	fgen
203.endif
204
205.if ${MACHINE} == "amiga"
206SUBDIR+=	amiga-elf2bb
207SUBDIR+=	amiga-txlt
208.endif
209
210.if ${MACHINE} == "hp300"
211SUBDIR+=	hp300-mkboot
212.endif
213
214.if ${MACHINE} == "evbarm" \
215    && ${MACHINE_CPU} == "arm" \
216    && ${TARGET_ENDIANNESS} == "1234"
217SUBDIR+=	elftosb
218.endif
219
220.if ${MACHINE} == "evbarm" || ${MACHINE} == "evbmips" || \
221    ${MACHINE} == "evbppc" || ${MACHINE} == "evbsh3" || \
222    ${MACHINE} == "sandpoint"
223SUBDIR+=	mkubootimage
224.endif
225
226.if ${MACHINE} == "evbarm" || ${MACHINE} == "evbmips" || \
227    ${MACHINE} == "evbppc" || ${MACHINE} == "evbsh3" || \
228    ${MACHINE} == "sandpoint" || \
229    ${MACHINE_CPU} == "riscv"
230SUBDIR+=	libfdt .WAIT
231SUBDIR+=	dtc
232.endif
233
234.if ${MACHINE} == "mvme68k"
235SUBDIR+=	mvme68k-wrtvid
236.endif
237
238.if ${MKX11} != "no"
239SUBDIR+=	makestrs
240SUBDIR+=	makekeys
241.endif
242
243SUBDIR+= cvslatest
244
245.endif # TOOLS_BUILDRUMP == no
246
247check_MKTOOLS: .PHONY .NOTMAIN
248.if ${MKTOOLS:Uyes} == "no"
249	@echo '*** WARNING: "MKTOOLS" is set to "no"; this will prevent building and'
250	@echo '*** updating your host toolchain.  This should be used only as a'
251	@echo '*** temporary workaround for toolchain problems, as it will result'
252	@echo '*** in version skew and build errors over time!'
253.endif
254
255.if ${MKTOOLS:Uyes} == "no" || ${USETOOLS} != "yes"	# {
256SUBDIR= # empty
257realall realdepend install: check_MKTOOLS
258.endif							# }
259
260.include <bsd.subdir.mk>
261.include <bsd.buildinstall.mk>
262.include <bsd.obj.mk>
263
264.if !defined(PREVIOUSTOOLDIR)
265.  if exists(PREVIOUSTOOLDIR)
266PREVIOUSTOOLDIR!=	cat PREVIOUSTOOLDIR
267.  else
268PREVIOUSTOOLDIR=
269.  endif
270.endif
271
272CLEANFILES+=	PREVIOUSTOOLDIR
273
274realall realdepend: .MAKE
275.if !empty(PREVIOUSTOOLDIR) && "${PREVIOUSTOOLDIR}" != "${TOOLDIR}"
276	@echo "*** WARNING: TOOLDIR has moved?"
277	@echo "*** PREVIOUSTOOLDIR '${PREVIOUSTOOLDIR}'"
278	@echo "***     !=  TOOLDIR '${TOOLDIR}'"
279	@echo "*** Cleaning mis-matched tools"
280	rm -f PREVIOUSTOOLDIR
281	(cd ${.CURDIR} && ${MAKE} PREVIOUSTOOLDIR=${TOOLDIR} cleandir)
282.endif
283	echo ${TOOLDIR} >PREVIOUSTOOLDIR
284
285cleandir:
286	rm -f ${CLEANFILES}
287