xref: /netbsd-src/tools/Makefile (revision f206dfe9d3db1b9558bd69fdff5e51d9d41da982)
1#	$NetBSD: Makefile,v 1.227 2024/10/23 00:45:58 kalvisd 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 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
175SUBDIR+=	macppc_installboot
176SUBDIR+=	macppc_mkboothfs
177.endif
178
179.if (${MACHINE} == "prep" || ${MACHINE} == "rs6000" || ${MACHINE} == "bebox")
180SUBDIR+=	powerpc-mkbootimage
181.endif
182
183.if ${MACHINE_CPU} == "arm"
184SUBDIR+=	arm-elf2aout
185.endif
186
187.if ${MACHINE_CPU} == "m68k"
188SUBDIR+=	m68k-elf2aout
189.endif
190
191.if !empty(MACHINE_ARCH:Mmips*)
192SUBDIR+=	mips-elf2ecoff
193.endif
194
195.if (${MACHINE} == "sgimips")
196SUBDIR+=	sgivol
197.endif
198
199.if ${MACHINE} == "acorn32"
200SUBDIR+=	sparkcrc
201.endif
202
203.if (${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64")
204SUBDIR+=	fgen
205.endif
206
207.if ${MACHINE} == "amiga"
208SUBDIR+=	amiga-elf2bb
209SUBDIR+=	amiga-txlt
210.endif
211
212.if ${MACHINE} == "hp300"
213SUBDIR+=	hp300-mkboot
214.endif
215
216.if ${MACHINE} == "vax"
217SUBDIR+=	libmopcopy vax-mopcopy
218.endif
219
220.if ${MACHINE} == "evbarm" \
221    && ${MACHINE_CPU} == "arm" \
222    && ${TARGET_ENDIANNESS} == "1234"
223SUBDIR+=	elftosb
224.endif
225
226.if ${MACHINE} == "evbarm" || ${MACHINE} == "evbmips" || \
227    ${MACHINE} == "evbppc" || ${MACHINE} == "evbsh3" || \
228    ${MACHINE} == "sandpoint" || \
229    ${MACHINE_CPU} == "riscv"
230SUBDIR+=	mkubootimage
231SUBDIR+=	libfdt .WAIT
232SUBDIR+=	dtc
233.endif
234
235.if ${MACHINE} == "mvme68k"
236SUBDIR+=	mvme68k-wrtvid
237.endif
238
239.if ${MACHINE} == "mac68k" || ${MACHINE} == "macppc"
240SUBDIR+=	mkhybrid
241.endif
242
243.if ${MKX11} != "no"
244SUBDIR+=	makestrs
245SUBDIR+=	makekeys
246.endif
247
248SUBDIR+= cvslatest
249
250.endif # TOOLS_BUILDRUMP == no
251
252check_MKTOOLS: .PHONY .NOTMAIN
253.if ${MKTOOLS:Uyes} == "no"
254	@echo '*** WARNING: "MKTOOLS" is set to "no"; this will prevent building and'
255	@echo '*** updating your host toolchain.  This should be used only as a'
256	@echo '*** temporary workaround for toolchain problems, as it will result'
257	@echo '*** in version skew and build errors over time!'
258.endif
259
260.if ${MKTOOLS:Uyes} == "no" || ${USETOOLS} != "yes"	# {
261SUBDIR= # empty
262realall realdepend install: check_MKTOOLS
263.endif							# }
264
265.include <bsd.subdir.mk>
266.include <bsd.buildinstall.mk>
267.include <bsd.obj.mk>
268
269.if !defined(PREVIOUSTOOLDIR)
270.  if exists(PREVIOUSTOOLDIR)
271PREVIOUSTOOLDIR!=	cat PREVIOUSTOOLDIR
272.  else
273PREVIOUSTOOLDIR=
274.  endif
275.endif
276
277CLEANFILES+=	PREVIOUSTOOLDIR
278
279realall realdepend: .MAKE
280.if !empty(PREVIOUSTOOLDIR) && "${PREVIOUSTOOLDIR}" != "${TOOLDIR}"
281	@echo "*** WARNING: TOOLDIR has moved?"
282	@echo "*** PREVIOUSTOOLDIR '${PREVIOUSTOOLDIR}'"
283	@echo "***     !=  TOOLDIR '${TOOLDIR}'"
284	@echo "*** Cleaning mis-matched tools"
285	rm -f PREVIOUSTOOLDIR
286	(cd ${.CURDIR} && ${MAKE} PREVIOUSTOOLDIR=${TOOLDIR} cleandir)
287.endif
288	echo ${TOOLDIR} >PREVIOUSTOOLDIR
289
290cleandir:
291	rm -f ${CLEANFILES}
292