1#	$NetBSD: Makefile,v 1.232 2025/05/27 14:05:19 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 && !defined(NOGCCISL))
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 ctfdump 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 .WAIT 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 what \
109	.WAIT yacc .WAIT awk .WAIT lex
110.if ${TOOLS_BUILDRUMP} == "no"
111SUBDIR+= xz-include .WAIT grep xz-lib pax .WAIT libprop
112
113SUBDIR += .WAIT texinfo \
114	.WAIT tic \
115	.WAIT ${TOOLCHAIN_BITS} \
116	${DTRACE_BITS} \
117		asn1_compile cksum compile_et db \
118		file lint1 slc \
119		makefs sortinfo \
120		.WAIT menuc mkcsmapper mkesdb mklocale mknod msgc \
121		.WAIT disklabel gpt \
122		.WAIT paxctl \
123		.WAIT fdisk \
124		.WAIT installboot \
125		pwd_mkdb strfile sunlabel vgrind zic
126.endif
127SUBDIR+= stat .WAIT config
128.if ${TOOLS_BUILDRUMP} == "no"
129SUBDIR+= xz-bin
130.endif
131
132.if ${MKLLVM} != "no" || ${MKLLVMRT} != "no"
133SUBDIR+= \
134	llvm .WAIT \
135	llvm-lib/libLLVMDemangle llvm-lib/libLLVMSupport llvm-lib/libLLVMTableGen .WAIT \
136	llvm-tblgen
137.endif
138.if ${MKLLVM} != "no"
139SUBDIR+= \
140	llvm-clang-tblgen
141.endif
142.if ${MKLLVM} != "no" && !defined(EXTERNAL_TOOLCHAIN)
143SUBDIR+= \
144	.WAIT llvm-include .WAIT \
145	llvm-lib .WAIT \
146	llvm-clang
147.endif
148
149.if ${MKMAN} != "no" || ${MKDOC} != "no" || ${MKHTML} != "no"
150. if ${MKGROFF} != "no"
151SUBDIR+=	groff
152. endif
153SUBDIR+=	mandoc
154.endif
155
156.if ${TOOLS_BUILDRUMP} == "no"
157
158.if ${MKMAINTAINERTOOLS:Uno} != "no"
159SUBDIR+=	autoconf .WAIT gettext
160.endif
161
162.if ${USE_PIGZGZIP} != "no"
163SUBDIR+=	pigz
164.endif
165
166.if ${MACHINE} == "hppa"
167SUBDIR+=	hppa-mkboot
168.endif
169
170.if ${MACHINE} == "ibmnws"
171SUBDIR+=	ibmnws-ncdcs
172.endif
173
174.if ${MACHINE} == "macppc"
175SUBDIR+=	macppc-fixcoff
176SUBDIR+=	macppc_installboot
177SUBDIR+=	macppc_mkboothfs
178.endif
179
180.if (${MACHINE} == "prep" || ${MACHINE} == "rs6000" || ${MACHINE} == "bebox")
181SUBDIR+=	powerpc-mkbootimage
182.endif
183
184.if ${MACHINE_CPU} == "arm"
185SUBDIR+=	arm-elf2aout
186.endif
187
188.if ${MACHINE_CPU} == "m68k"
189SUBDIR+=	m68k-elf2aout
190.endif
191
192.if !empty(MACHINE_ARCH:Mmips*)
193SUBDIR+=	mips-elf2ecoff
194.endif
195
196.if (${MACHINE} == "sgimips")
197SUBDIR+=	sgivol
198.endif
199
200.if ${MACHINE} == "acorn32"
201SUBDIR+=	sparkcrc
202.endif
203
204.if (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64")
205SUBDIR+=	fgen
206.endif
207
208.if ${MACHINE} == "amiga"
209SUBDIR+=	amiga-elf2bb
210SUBDIR+=	amiga-txlt
211.endif
212
213.if ${MACHINE} == "hp300"
214SUBDIR+=	hp300-mkboot
215.endif
216
217.if ${MACHINE} == "vax"
218SUBDIR+=	libmopcopy .WAIT vax-mopcopy
219.endif
220
221.if ${MACHINE} == "evbarm" \
222    && ${MACHINE_CPU} == "arm" \
223    && ${TARGET_ENDIANNESS} == "1234"
224SUBDIR+=	elftosb
225.endif
226
227.if ${MACHINE} == "evbarm" || ${MACHINE} == "evbmips" || \
228    ${MACHINE} == "evbppc" || ${MACHINE} == "evbsh3" || \
229    ${MACHINE} == "sandpoint" || \
230    ${MACHINE_CPU} == "riscv"
231SUBDIR+=	mkubootimage
232SUBDIR+=	libfdt .WAIT
233SUBDIR+=	dtc
234.endif
235
236.if ${MACHINE} == "mvme68k"
237SUBDIR+=	mvme68k-wrtvid
238.endif
239
240.if ${MACHINE} == "mac68k" || ${MACHINE} == "macppc"
241SUBDIR+=	mkhybrid
242.endif
243
244.if ${MKX11} != "no"
245SUBDIR+=	makestrs
246SUBDIR+=	makekeys
247.endif
248
249SUBDIR+= cvslatest
250
251.endif # TOOLS_BUILDRUMP == no
252
253check_MKTOOLS: .PHONY .NOTMAIN
254.if ${MKTOOLS:Uyes} == "no"
255	@echo '*** WARNING: "MKTOOLS" is set to "no"; this will prevent building and'
256	@echo '*** updating your host toolchain.  This should be used only as a'
257	@echo '*** temporary workaround for toolchain problems, as it will result'
258	@echo '*** in version skew and build errors over time!'
259.endif
260
261.if ${MKTOOLS:Uyes} == "no" || ${USETOOLS} != "yes"	# {
262SUBDIR= # empty
263realall realdepend install: check_MKTOOLS
264.endif							# }
265
266.include <bsd.subdir.mk>
267.include <bsd.buildinstall.mk>
268.include <bsd.obj.mk>
269
270.if !defined(PREVIOUSTOOLDIR)
271.  if exists(PREVIOUSTOOLDIR)
272PREVIOUSTOOLDIR!=	cat PREVIOUSTOOLDIR
273.  else
274PREVIOUSTOOLDIR=
275.  endif
276.endif
277
278CLEANFILES+=	PREVIOUSTOOLDIR
279
280realall realdepend: .MAKE
281.if !empty(PREVIOUSTOOLDIR) && "${PREVIOUSTOOLDIR}" != "${TOOLDIR}"
282	@echo "*** WARNING: TOOLDIR has moved?"
283	@echo "*** PREVIOUSTOOLDIR '${PREVIOUSTOOLDIR}'"
284	@echo "***     !=  TOOLDIR '${TOOLDIR}'"
285	@echo "*** Cleaning mis-matched tools"
286	rm -f PREVIOUSTOOLDIR
287	(cd ${.CURDIR} && ${MAKE} PREVIOUSTOOLDIR=${TOOLDIR} cleandir)
288.endif
289	echo ${TOOLDIR} >PREVIOUSTOOLDIR
290
291cleandir:
292	rm -f ${CLEANFILES}
293