xref: /netbsd-src/share/mk/bsd.own.mk (revision 2f62cc9c12bc202c40224f32c879f81443fee079)
1#	$NetBSD: bsd.own.mk,v 1.1388 2024/07/13 03:38:12 rin Exp $
2
3# This needs to be before bsd.init.mk
4.if defined(BSD_MK_COMPAT_FILE)
5.include <${BSD_MK_COMPAT_FILE}>
6.endif
7
8.if !defined(_BSD_OWN_MK_)
9_BSD_OWN_MK_=1
10
11MAKECONF?=	/etc/mk.conf
12.-include "${MAKECONF}"
13
14#
15# CPU model, derived from MACHINE_ARCH
16#
17MACHINE_CPU=	${MACHINE_ARCH:C/mips.*e[bl]/mips/:C/sh3e[bl]/sh3/:S/coldfire/m68k/:S/m68000/m68k/:C/e?arm.*/arm/:S/powerpc64/powerpc/:S/aarch64eb/aarch64/:S/or1knd/or1k/:C/riscv../riscv/}
18
19.if (${MACHINE_ARCH} == "mips64el" || \
20     ${MACHINE_ARCH} == "mips64eb" || \
21     ${MACHINE_ARCH} == "mipsn64el" || \
22     ${MACHINE_ARCH} == "mipsn64eb")
23MACHINE_MIPS64= 	1
24.else
25MACHINE_MIPS64= 	0
26.endif
27
28#
29# Subdirectory used below ${RELEASEDIR} when building a release
30#
31.if \
32    ${MACHINE:Mevbarm} || \
33    ${MACHINE:Mevbmips} || \
34    ${MACHINE:Mevbsh3} || \
35    ${MACHINE:Mriscv}
36RELEASEMACHINEDIR?=	${MACHINE}-${MACHINE_ARCH}
37.else
38RELEASEMACHINEDIR?=	${MACHINE}
39.endif
40
41#
42# Subdirectory or path component used for the following paths:
43#   distrib/${RELEASEMACHINE}
44#   distrib/notes/${RELEASEMACHINE}
45#   etc/etc.${RELEASEMACHINE}
46# Used when building a release.
47#
48RELEASEMACHINE?=	${MACHINE}
49
50#
51# NEED_OWN_INSTALL_TARGET is set to "no" by pkgsrc/mk/bsd.pkg.mk to
52# ensure that things defined by <bsd.own.mk> (default targets,
53# INSTALL_FILE, etc.) are not conflicting with bsd.pkg.mk.
54#
55NEED_OWN_INSTALL_TARGET?=	yes
56
57#
58# This lists the platforms which do not have working in-tree toolchains.  For
59# the in-tree gcc toolchain, this list is empty.
60#
61# If some future port is not supported by the in-tree toolchain, this should
62# be set to "yes" for that port only.
63#
64# .if ${MACHINE} == "playstation2"
65# TOOLCHAIN_MISSING?=	yes
66# .endif
67
68TOOLCHAIN_MISSING?=	no
69
70#
71# GCC Using platforms.
72#
73.if ${MKGCC:Uyes} != "no"						# {
74
75#
76# What GCC is used?
77#
78.if \
79    ${MACHINE_CPU} == "aarch64" || \
80    ${MACHINE_CPU} == "arm" || \
81    ${MACHINE_CPU} == "mips" || \
82    ${MACHINE_CPU} == "powerpc" || \
83    ${MACHINE_CPU} == "riscv" || \
84    ${MACHINE_ARCH} == "x86_64" || \
85    ${MACHINE_ARCH} == "i386" || \
86    ${MACHINE} == "hppa" || \
87    ${MACHINE} == "sparc" || \
88    ${MACHINE} == "sparc64" || \
89    ${MACHINE} == "ia64" || \
90    ${MACHINE} == "alpha"
91HAVE_GCC?=	12
92.endif
93HAVE_GCC?=	10
94
95#
96# Platforms that can't run a modern GCC natively
97.if ${MACHINE_ARCH} == "m68000"
98MKGCCCMDS?=	no
99.endif
100
101#
102# We import the old gcc as "gcc.old" when upgrading.  EXTERNAL_GCC_SUBDIR is
103# set to the relevant subdirectory in src/external/gpl3 for his HAVE_GCC.
104#
105.if ${HAVE_GCC} == 10
106EXTERNAL_GCC_SUBDIR?=	gcc.old
107.elif ${HAVE_GCC} == 12
108EXTERNAL_GCC_SUBDIR?=	gcc
109.else
110EXTERNAL_GCC_SUBDIR?=	/does/not/exist
111.endif
112
113.else	# MKGCC == no							# } {
114MKGCCCMDS?=	no
115.endif	# MKGCC == no							# }
116
117#
118# What binutils is used?
119#
120.if \
121    ${MACHINE_CPU} == "mips" || \
122    ${MACHINE_ARCH} == "x86_64"
123HAVE_BINUTILS?= 242
124.else
125HAVE_BINUTILS?=	239
126.endif
127
128.if ${HAVE_BINUTILS} == 242
129EXTERNAL_BINUTILS_SUBDIR=	binutils
130.elif ${HAVE_BINUTILS} == 239
131EXTERNAL_BINUTILS_SUBDIR=	binutils.old
132.else
133EXTERNAL_BINUTILS_SUBDIR=	/does/not/exist
134.endif
135
136#
137# What GDB is used?
138#
139HAVE_GDB?=	1320
140
141.if ${HAVE_GDB} == 1320
142EXTERNAL_GDB_SUBDIR=		gdb
143.elif ${HAVE_GDB} == 1100
144EXTERNAL_GDB_SUBDIR=		gdb.old
145.else
146EXTERNAL_GDB_SUBDIR=		/does/not/exist
147.endif
148
149#
150# What OpenSSL is used?
151#
152HAVE_OPENSSL?=	30
153
154.if ${HAVE_OPENSSL} == 30
155EXTERNAL_OPENSSL_SUBDIR=openssl
156.elif ${HAVE_OPENSSL} == 11
157EXTERNAL_OPENSSL_SUBDIR=openssl.old
158.else
159EXTERNAL_OPENSSL_SUBDIR=/does/not/exist
160.endif
161
162#
163# Does the platform support ACPI?
164#
165.if ${MACHINE} == "i386" || \
166    ${MACHINE} == "amd64" || \
167    ${MACHINE} == "ia64" || \
168    ${MACHINE_ARCH:Maarch64*}
169HAVE_ACPI=	yes
170.else
171HAVE_ACPI=	no
172.endif
173
174#
175# Does the platform support UEFI?
176#
177.if ${MACHINE} == "i386" || \
178    ${MACHINE} == "amd64" || \
179    ${MACHINE} == "ia64" || \
180    ${MACHINE_ARCH:Mearmv7*} || \
181    ${MACHINE_ARCH:Maarch64*} || \
182    ${MACHINE_ARCH} == "riscv64"
183HAVE_UEFI=	yes
184.else
185HAVE_UEFI=	no
186.endif
187
188#
189# Does the platform support NVMM?
190#
191.if ${MACHINE_ARCH} == "x86_64"
192HAVE_NVMM=	yes
193.else
194HAVE_NVMM=	no
195.endif
196
197
198.if ${MACHINE_ARCH:Mearm*}
199_LIBC_COMPILER_RT.${MACHINE_ARCH}=	yes
200.endif
201
202_LIBC_COMPILER_RT.aarch64=	yes
203_LIBC_COMPILER_RT.aarch64eb=	yes
204_LIBC_COMPILER_RT.i386=		yes
205_LIBC_COMPILER_RT.powerpc=	yes
206_LIBC_COMPILER_RT.powerpc64=	yes
207_LIBC_COMPILER_RT.sparc=	yes
208_LIBC_COMPILER_RT.sparc64=	yes
209_LIBC_COMPILER_RT.x86_64=	yes
210
211.if ${HAVE_LLVM:Uno} == "yes" && ${_LIBC_COMPILER_RT.${MACHINE_ARCH}:Uno} == "yes"
212HAVE_LIBGCC?=	no
213.else
214HAVE_LIBGCC?=	yes
215.endif
216
217
218# Should libgcc have unwinding code?
219.if ${HAVE_LLVM:Uno} == "yes" || ${MACHINE_ARCH:Mearm*}
220HAVE_LIBGCC_EH?=	no
221.else
222HAVE_LIBGCC_EH?=	yes
223.endif
224
225# Coverity does not like SSP
226.if defined(COVERITY_TOP_CONFIG) || \
227    ${MACHINE} == "alpha" || \
228    ${MACHINE} == "hppa" || \
229    ${MACHINE} == "ia64" || \
230    ${MACHINE_CPU} == "mips"
231HAVE_SSP?=	no
232.else
233HAVE_SSP?=	yes
234.if !defined(NOFORT) && ${USE_FORT:Uno} != "no"
235USE_SSP?=	yes
236.endif
237.endif
238
239#
240# What version of jemalloc we use (100 is the one
241# built-in to libc from 2005 (pre version 3).
242#
243.if ${MACHINE_ARCH} == "vax" || ${MACHINE} == "sun2"
244HAVE_JEMALLOC?=		100
245.else
246HAVE_JEMALLOC?=		510
247.endif
248
249.if empty(.MAKEFLAGS:tW:M*-V .OBJDIR*)
250.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR)
251PRINTOBJDIR=	${MAKE} -r -V .OBJDIR -f /dev/null xxx
252.else
253PRINTOBJDIR=	${MAKE} -V .OBJDIR
254.endif
255.else
256PRINTOBJDIR=	echo /error/bsd.own.mk/PRINTOBJDIR # avoid infinite recursion
257.endif
258
259#
260# Make sure we set _NETBSD_REVISIONID in CPPFLAGS if requested.
261#
262.ifdef NETBSD_REVISIONID
263_NETBSD_REVISIONID_STR=	"${NETBSD_REVISIONID}"
264CPPFLAGS+=	-D_NETBSD_REVISIONID=${_NETBSD_REVISIONID_STR:Q}
265.endif
266
267#
268# Determine if running in the NetBSD source tree by checking for the
269# existence of build.sh and tools/ in the current or a parent directory,
270# and setting _SRC_TOP_ to the result.
271#
272.if !defined(_SRC_TOP_)			# {
273_SRC_TOP_!= cd "${.CURDIR}"; while :; do \
274		here=$$(pwd); \
275		[ -f build.sh  ] && [ -d tools ] && { echo $$here; break; }; \
276		case $$here in /) echo ""; break;; esac; \
277		cd ..; done
278
279.MAKEOVERRIDES+=	_SRC_TOP_
280
281.endif					# }
282
283#
284# If _SRC_TOP_ != "", we're within the NetBSD source tree.
285# * Set defaults for NETBSDSRCDIR and _SRC_TOP_OBJ_.
286# * Define _NETBSD_VERSION_DEPENDS.  Targets that depend on the
287#   NetBSD version, or on variables defined at build time, can
288#   declare a dependency on ${_NETBSD_VERSION_DEPENDS}.
289#
290.if (${_SRC_TOP_} != "")		# {
291
292NETBSDSRCDIR?=	${_SRC_TOP_}
293
294.if !defined(_SRC_TOP_OBJ_)
295_SRC_TOP_OBJ_!=		cd "${_SRC_TOP_}" && ${PRINTOBJDIR}
296.MAKEOVERRIDES+=	_SRC_TOP_OBJ_
297.endif
298
299_NETBSD_VERSION_DEPENDS=	${_SRC_TOP_OBJ_}/params
300_NETBSD_VERSION_DEPENDS+=	${NETBSDSRCDIR}/sys/sys/param.h
301_NETBSD_VERSION_DEPENDS+=	${NETBSDSRCDIR}/sys/conf/newvers.sh
302_NETBSD_VERSION_DEPENDS+=	${NETBSDSRCDIR}/sys/conf/osrelease.sh
303${_SRC_TOP_OBJ_}/params: .NOTMAIN .OPTIONAL # created by top level "make build"
304
305.endif	# _SRC_TOP_ != ""		# }
306
307
308.if (${_SRC_TOP_} != "") && \
309    (${TOOLCHAIN_MISSING} == "no" || defined(EXTERNAL_TOOLCHAIN))
310USETOOLS?=	yes
311.endif
312USETOOLS?=	no
313
314
315.if ${MACHINE_ARCH} == "mips" || ${MACHINE_ARCH} == "mips64" || \
316    ${MACHINE_ARCH} == "sh3"
317.BEGIN:
318	@echo "Must set MACHINE_ARCH to one of ${MACHINE_ARCH}eb or ${MACHINE_ARCH}el"
319	@false
320.elif defined(REQUIRETOOLS) && \
321      (${TOOLCHAIN_MISSING} == "no" || defined(EXTERNAL_TOOLCHAIN)) && \
322      ${USETOOLS} == "no"
323.BEGIN:
324	@echo "USETOOLS=no, but this component requires a version-specific host toolchain"
325	@false
326.endif
327
328#
329# Host platform information; may be overridden
330#
331.include <bsd.host.mk>
332
333.if ${USETOOLS} == "yes"						# {
334
335#
336# Provide a default for TOOLDIR.
337#
338.if !defined(TOOLDIR)
339TOOLDIR:=	${_SRC_TOP_OBJ_}/tooldir.${HOST_OSTYPE}
340.MAKEOVERRIDES+= TOOLDIR
341.endif
342
343#
344# This is the prefix used for the NetBSD-sourced tools.
345#
346_TOOL_PREFIX?=	nb
347
348#
349# If an external toolchain base is specified, use it.
350#
351.if defined(EXTERNAL_TOOLCHAIN)						# {
352AR=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-ar
353AS=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-as
354ELFEDIT=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-elfedit
355LD=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-ld
356NM=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-nm
357OBJCOPY=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-objcopy
358OBJDUMP=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-objdump
359RANLIB=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-ranlib
360READELF=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-readelf
361SIZE=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-size
362STRINGS=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-strings
363STRIP=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-strip
364
365TOOL_CC.gcc=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-gcc
366TOOL_CPP.gcc=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-cpp
367TOOL_CXX.gcc=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-c++
368TOOL_FC.gcc=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-gfortran
369TOOL_OBJC.gcc=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-gcc
370
371TOOL_CC.clang=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang
372TOOL_CPP.clang=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang-cpp
373TOOL_CXX.clang=		${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang++
374TOOL_OBJC.clang=	${EXTERNAL_TOOLCHAIN}/bin/${MACHINE_GNU_PLATFORM}-clang
375.else									# } {
376# Define default locations for common tools.
377.if ${USETOOLS_BINUTILS:Uyes} == "yes"					#  {
378AR=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ar
379AS=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-as
380ELFEDIT=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-elfedit
381LD=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ld
382NM=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-nm
383OBJCOPY=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-objcopy
384OBJDUMP=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-objdump
385RANLIB=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-ranlib
386READELF=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-readelf
387SIZE=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-size
388STRINGS=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-strings
389STRIP=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-strip
390
391# GCC supports C, C++, Fortran and Objective C
392TOOL_CC.gcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-gcc
393TOOL_CPP.gcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-cpp
394TOOL_CXX.gcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-c++
395TOOL_FC.gcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-gfortran
396TOOL_OBJC.gcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-gcc
397.endif									#  }
398
399# Clang supports C, C++ and Objective C
400TOOL_CC.clang=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang
401TOOL_CPP.clang=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang-cpp
402TOOL_CXX.clang=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang++
403TOOL_OBJC.clang=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-clang
404
405# PCC supports C and Fortran
406TOOL_CC.pcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-pcc
407TOOL_CPP.pcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-pcpp
408TOOL_CXX.pcc=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-p++
409.endif	# EXTERNAL_TOOLCHAIN						# }
410
411#
412# Make sure DESTDIR is set, so that builds with these tools always
413# get appropriate -nostdinc, -nostdlib, etc. handling.  The default is
414# <empty string>, meaning start from /, the root directory.
415#
416DESTDIR?=
417
418# Don't append another copy of sysroot (coming from COMPATCPPFLAGS etc.)
419# because it confuses Coverity. Still we need to cov-configure specially
420# for each specific sysroot argument.
421# Also don't add a sysroot at all if a rumpkernel build.
422.if !defined(HOSTPROG) && !defined(HOSTLIB) && !defined(RUMPRUN)
423.  if ${DESTDIR} != ""
424.	if empty(CPPFLAGS:M*--sysroot=*)
425CPPFLAGS+=	--sysroot=${DESTDIR}
426.	endif
427LDFLAGS+=	--sysroot=${DESTDIR}
428.  else
429.	if empty(CPPFLAGS:M*--sysroot=*)
430CPPFLAGS+=	--sysroot=/
431.	endif
432LDFLAGS+=	--sysroot=/
433.  endif
434.endif
435
436DBSYM=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-dbsym
437ARM_ELF2AOUT=	${TOOLDIR}/bin/${_TOOL_PREFIX}arm-elf2aout
438M68K_ELF2AOUT=	${TOOLDIR}/bin/${_TOOL_PREFIX}m68k-elf2aout
439MIPS_ELF2ECOFF=	${TOOLDIR}/bin/${_TOOL_PREFIX}mips-elf2ecoff
440INSTALL=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-install
441LEX=		${TOOLDIR}/bin/${_TOOL_PREFIX}lex
442LINT=		CC=${CC:Q} ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-lint
443LORDER=		NM=${NM:Q} MKTEMP=${TOOL_MKTEMP:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}lorder
444MKDEP=		CC=${CC:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}mkdep
445MKDEPCXX=	CC=${CXX:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}mkdep
446PAXCTL=		${TOOLDIR}/bin/${_TOOL_PREFIX}paxctl
447TSORT=		${TOOLDIR}/bin/${_TOOL_PREFIX}tsort -q
448YACC=		${TOOLDIR}/bin/${_TOOL_PREFIX}yacc
449
450TOOL_AMIGAAOUT2BB=	${TOOLDIR}/bin/${_TOOL_PREFIX}amiga-aout2bb
451TOOL_AMIGAELF2BB=	${TOOLDIR}/bin/${_TOOL_PREFIX}amiga-elf2bb
452TOOL_AMIGATXLT=		${TOOLDIR}/bin/${_TOOL_PREFIX}amiga-txlt
453TOOL_ASN1_COMPILE=	${TOOLDIR}/bin/${_TOOL_PREFIX}asn1_compile
454TOOL_AWK=		${TOOLDIR}/bin/${_TOOL_PREFIX}awk
455TOOL_CAP_MKDB=		${TOOLDIR}/bin/${_TOOL_PREFIX}cap_mkdb
456TOOL_CAT=		${TOOLDIR}/bin/${_TOOL_PREFIX}cat
457TOOL_CKSUM=		${TOOLDIR}/bin/${_TOOL_PREFIX}cksum
458TOOL_CLANG_TBLGEN=	${TOOLDIR}/bin/${_TOOL_PREFIX}clang-tblgen
459TOOL_COMPILE_ET=	${TOOLDIR}/bin/${_TOOL_PREFIX}compile_et
460TOOL_CONFIG=		${TOOLDIR}/bin/${_TOOL_PREFIX}config
461TOOL_CRUNCHGEN=		MAKE=${.MAKE:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}crunchgen
462TOOL_CTAGS=		${TOOLDIR}/bin/${_TOOL_PREFIX}ctags
463TOOL_CTFCONVERT=	${TOOLDIR}/bin/${_TOOL_PREFIX}ctfconvert
464TOOL_CTFMERGE=		${TOOLDIR}/bin/${_TOOL_PREFIX}ctfmerge
465TOOL_CVSLATEST=		${TOOLDIR}/bin/${_TOOL_PREFIX}cvslatest
466TOOL_DATE=		${TOOLDIR}/bin/${_TOOL_PREFIX}date
467TOOL_DB=		${TOOLDIR}/bin/${_TOOL_PREFIX}db
468TOOL_DISKLABEL=		${TOOLDIR}/bin/${_TOOL_PREFIX}disklabel
469TOOL_DTC=		${TOOLDIR}/bin/${_TOOL_PREFIX}dtc
470TOOL_EQN=		${TOOLDIR}/bin/${_TOOL_PREFIX}eqn
471TOOL_FDISK=		${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-fdisk
472TOOL_FGEN=		${TOOLDIR}/bin/${_TOOL_PREFIX}fgen
473TOOL_GENASSYM=		${TOOLDIR}/bin/${_TOOL_PREFIX}genassym
474TOOL_GENCAT=		${TOOLDIR}/bin/${_TOOL_PREFIX}gencat
475TOOL_GMAKE=		${TOOLDIR}/bin/${_TOOL_PREFIX}gmake
476TOOL_GPT=		${TOOLDIR}/bin/${_TOOL_PREFIX}gpt
477TOOL_GREP=		${TOOLDIR}/bin/${_TOOL_PREFIX}grep
478GROFF_SHARE_PATH=	${TOOLDIR}/share/groff
479TOOL_GROFF_ENV= \
480    GROFF_ENCODING= \
481    GROFF_BIN_PATH=${TOOLDIR}/lib/groff \
482    GROFF_FONT_PATH=${GROFF_SHARE_PATH}/site-font:${GROFF_SHARE_PATH}/font \
483    GROFF_TMAC_PATH=${GROFF_SHARE_PATH}/site-tmac:${GROFF_SHARE_PATH}/tmac
484TOOL_GROFF=		${TOOL_GROFF_ENV} ${TOOLDIR}/bin/${_TOOL_PREFIX}groff ${GROFF_FLAGS}
485TOOL_GROPS=		${TOOL_GROFF_ENV} ${TOOLDIR}/lib/groff/grops
486
487TOOL_HEXDUMP=		${TOOLDIR}/bin/${_TOOL_PREFIX}hexdump
488TOOL_HP300MKBOOT=	${TOOLDIR}/bin/${_TOOL_PREFIX}hp300-mkboot
489TOOL_HPPAMKBOOT=	${TOOLDIR}/bin/${_TOOL_PREFIX}hppa-mkboot
490TOOL_INDXBIB=		${TOOLDIR}/bin/${_TOOL_PREFIX}indxbib
491TOOL_INSTALLBOOT=	${TOOLDIR}/bin/${_TOOL_PREFIX}installboot
492TOOL_INSTALL_INFO=	${TOOLDIR}/bin/${_TOOL_PREFIX}install-info
493TOOL_JOIN=		${TOOLDIR}/bin/${_TOOL_PREFIX}join
494TOOL_LLVM_TBLGEN=	${TOOLDIR}/bin/${_TOOL_PREFIX}llvm-tblgen
495TOOL_M4=		${TOOLDIR}/bin/${_TOOL_PREFIX}m4
496TOOL_MACPPCFIXCOFF=	${TOOLDIR}/bin/${_TOOL_PREFIX}macppc-fixcoff
497TOOL_MACPPCINSTALLBOOT=	${TOOLDIR}/bin/${_TOOL_PREFIX}macppc_installboot
498TOOL_MAKEFS=		${TOOLDIR}/bin/${_TOOL_PREFIX}makefs
499TOOL_MAKEINFO=		${TOOLDIR}/bin/${_TOOL_PREFIX}makeinfo
500TOOL_MAKEKEYS=		${TOOLDIR}/bin/${_TOOL_PREFIX}makekeys
501TOOL_MAKESTRS=		${TOOLDIR}/bin/${_TOOL_PREFIX}makestrs
502TOOL_MAKEWHATIS=	${TOOLDIR}/bin/${_TOOL_PREFIX}makewhatis
503TOOL_MANDOC_ASCII=	${TOOLDIR}/bin/${_TOOL_PREFIX}mandoc -Tascii
504TOOL_MANDOC_HTML=	${TOOLDIR}/bin/${_TOOL_PREFIX}mandoc -Thtml
505TOOL_MANDOC_LINT=	${TOOLDIR}/bin/${_TOOL_PREFIX}mandoc -Tlint
506TOOL_MDSETIMAGE=	${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-mdsetimage
507TOOL_MENUC=		MENUDEF=${TOOLDIR}/share/misc ${TOOLDIR}/bin/${_TOOL_PREFIX}menuc
508TOOL_ARMELF2AOUT=	${TOOLDIR}/bin/${_TOOL_PREFIX}arm-elf2aout
509TOOL_M68KELF2AOUT=	${TOOLDIR}/bin/${_TOOL_PREFIX}m68k-elf2aout
510TOOL_MIPSELF2ECOFF=	${TOOLDIR}/bin/${_TOOL_PREFIX}mips-elf2ecoff
511TOOL_MKCSMAPPER=	${TOOLDIR}/bin/${_TOOL_PREFIX}mkcsmapper
512TOOL_MKESDB=		${TOOLDIR}/bin/${_TOOL_PREFIX}mkesdb
513TOOL_MKHYBRID=		${TOOLDIR}/bin/${_TOOL_PREFIX}mkhybrid
514TOOL_MKLOCALE=		${TOOLDIR}/bin/${_TOOL_PREFIX}mklocale
515TOOL_MKMAGIC=		${TOOLDIR}/bin/${_TOOL_PREFIX}file
516TOOL_MKNOD=		${TOOLDIR}/bin/${_TOOL_PREFIX}mknod
517TOOL_MKTEMP=		${TOOLDIR}/bin/${_TOOL_PREFIX}mktemp
518TOOL_MKUBOOTIMAGE=	${TOOLDIR}/bin/${_TOOL_PREFIX}mkubootimage
519TOOL_ELFTOSB=		${TOOLDIR}/bin/${_TOOL_PREFIX}elftosb
520TOOL_MSGC=		MSGDEF=${TOOLDIR}/share/misc ${TOOLDIR}/bin/${_TOOL_PREFIX}msgc
521TOOL_MTREE=		${TOOLDIR}/bin/${_TOOL_PREFIX}mtree
522TOOL_MVME68KWRTVID=	${TOOLDIR}/bin/${_TOOL_PREFIX}mvme68k-wrtvid
523TOOL_NBPERF=		${TOOLDIR}/bin/${_TOOL_PREFIX}perf
524TOOL_NCDCS=		${TOOLDIR}/bin/${_TOOL_PREFIX}ibmnws-ncdcs
525TOOL_PAX=		${TOOLDIR}/bin/${_TOOL_PREFIX}pax
526TOOL_PIC=		${TOOLDIR}/bin/${_TOOL_PREFIX}pic
527TOOL_PIGZ=		${TOOLDIR}/bin/${_TOOL_PREFIX}pigz
528TOOL_XZ=		${TOOLDIR}/bin/${_TOOL_PREFIX}xz
529TOOL_PKG_CREATE=	${TOOLDIR}/bin/${_TOOL_PREFIX}pkg_create
530TOOL_POWERPCMKBOOTIMAGE=${TOOLDIR}/bin/${_TOOL_PREFIX}powerpc-mkbootimage
531TOOL_PWD_MKDB=		${TOOLDIR}/bin/${_TOOL_PREFIX}pwd_mkdb
532TOOL_REFER=		${TOOLDIR}/bin/${_TOOL_PREFIX}refer
533TOOL_ROFF_ASCII=	${TOOL_GROFF_ENV} ${TOOLDIR}/bin/${_TOOL_PREFIX}nroff
534TOOL_ROFF_DOCASCII=	${TOOL_GROFF} -Tascii
535TOOL_ROFF_DOCHTML=	${TOOL_GROFF} -Thtml
536TOOL_ROFF_DVI=		${TOOL_GROFF} -Tdvi ${ROFF_PAGESIZE}
537TOOL_ROFF_HTML=		${TOOL_GROFF} -Tlatin1 -mdoc2html
538TOOL_ROFF_PS=		${TOOL_GROFF} -Tps ${ROFF_PAGESIZE}
539TOOL_ROFF_RAW=		${TOOL_GROFF} -Z
540TOOL_RPCGEN=		RPCGEN_CPP=${CPP:Q} ${TOOLDIR}/bin/${_TOOL_PREFIX}rpcgen
541TOOL_SED=		${TOOLDIR}/bin/${_TOOL_PREFIX}sed
542TOOL_SLC=		${TOOLDIR}/bin/${_TOOL_PREFIX}slc
543TOOL_SOELIM=		${TOOLDIR}/bin/${_TOOL_PREFIX}soelim
544TOOL_SORTINFO=		${TOOLDIR}/bin/${_TOOL_PREFIX}sortinfo
545TOOL_SPARKCRC=		${TOOLDIR}/bin/${_TOOL_PREFIX}sparkcrc
546TOOL_STAT=		${TOOLDIR}/bin/${_TOOL_PREFIX}stat
547TOOL_STRFILE=		${TOOLDIR}/bin/${_TOOL_PREFIX}strfile
548TOOL_SUNLABEL=		${TOOLDIR}/bin/${_TOOL_PREFIX}sunlabel
549TOOL_TBL=		${TOOLDIR}/bin/${_TOOL_PREFIX}tbl
550TOOL_TIC=		${TOOLDIR}/bin/${_TOOL_PREFIX}tic
551TOOL_UUDECODE=		${TOOLDIR}/bin/${_TOOL_PREFIX}uudecode
552TOOL_VGRIND=		${TOOLDIR}/bin/${_TOOL_PREFIX}vgrind -f
553TOOL_VFONTEDPR=		${TOOLDIR}/libexec/${_TOOL_PREFIX}vfontedpr
554TOOL_ZIC=		${TOOLDIR}/bin/${_TOOL_PREFIX}zic
555
556.else	# USETOOLS != yes						# } {
557
558# Clang supports C, C++ and Objective C
559TOOL_CC.clang=		clang
560TOOL_CPP.clang=		clang-cpp
561TOOL_CXX.clang=		clang++
562TOOL_OBJC.clang=	clang
563
564# GCC supports C, C++, Fortran and Objective C
565TOOL_CC.gcc=		gcc
566TOOL_CPP.gcc=		cpp
567TOOL_CXX.gcc=		c++
568TOOL_FC.gcc=		gfortran
569TOOL_OBJC.gcc=		gcc
570
571# PCC supports C and Fortran
572TOOL_CC.pcc=		pcc
573TOOL_CPP.pcc=		pcpp
574TOOL_CXX.pcc=		p++
575
576TOOL_AMIGAAOUT2BB=	amiga-aout2bb
577TOOL_AMIGAELF2BB=	amiga-elf2bb
578TOOL_AMIGATXLT=		amiga-txlt
579TOOL_ASN1_COMPILE=	asn1_compile
580TOOL_AWK=		awk
581TOOL_CAP_MKDB=		cap_mkdb
582TOOL_CAT=		cat
583TOOL_CKSUM=		cksum
584TOOL_CLANG_TBLGEN=	clang-tblgen
585TOOL_COMPILE_ET=	compile_et
586TOOL_CONFIG=		config
587TOOL_CRUNCHGEN=		crunchgen
588TOOL_CTAGS=		ctags
589TOOL_CTFCONVERT=	ctfconvert
590TOOL_CTFMERGE=		ctfmerge
591TOOL_CVSLATEST=		cvslatest
592TOOL_DATE=		date
593TOOL_DB=		db
594TOOL_DISKLABEL=		disklabel
595TOOL_DTC=		dtc
596TOOL_EQN=		eqn
597TOOL_FDISK=		fdisk
598TOOL_FGEN=		fgen
599TOOL_GENASSYM=		genassym
600TOOL_GENCAT=		gencat
601TOOL_GMAKE=		gmake
602TOOL_GPT=		gpt
603TOOL_GREP=		grep
604TOOL_GROFF=		groff
605TOOL_GROPS=		grops
606TOOL_HEXDUMP=		hexdump
607TOOL_HP300MKBOOT=	hp300-mkboot
608TOOL_HPPAMKBOOT=	hppa-mkboot
609TOOL_INDXBIB=		indxbib
610TOOL_INSTALLBOOT=	installboot
611TOOL_INSTALL_INFO=	install-info
612TOOL_JOIN=		join
613TOOL_LLVM_TBLGEN=	llvm-tblgen
614TOOL_M4=		m4
615TOOL_MACPPCFIXCOFF=	macppc-fixcoff
616TOOL_MAKEFS=		makefs
617TOOL_MAKEINFO=		makeinfo
618TOOL_MAKEKEYS=		makekeys
619TOOL_MAKESTRS=		makestrs
620TOOL_MAKEWHATIS=	/usr/libexec/makewhatis
621TOOL_MANDOC_ASCII=	mandoc -Tascii
622TOOL_MANDOC_HTML=	mandoc -Thtml
623TOOL_MANDOC_LINT=	mandoc -Tlint
624TOOL_MDSETIMAGE=	mdsetimage
625TOOL_MENUC=		menuc
626TOOL_ARMELF2AOUT=	arm-elf2aout
627TOOL_M68KELF2AOUT=	m68k-elf2aout
628TOOL_MIPSELF2ECOFF=	mips-elf2ecoff
629TOOL_MKCSMAPPER=	mkcsmapper
630TOOL_MKESDB=		mkesdb
631TOOL_MKLOCALE=		mklocale
632TOOL_MKMAGIC=		file
633TOOL_MKNOD=		mknod
634TOOL_MKTEMP=		mktemp
635TOOL_MKUBOOTIMAGE=	mkubootimage
636TOOL_ELFTOSB=		elftosb
637TOOL_MSGC=		msgc
638TOOL_MTREE=		mtree
639TOOL_MVME68KWRTVID=	wrtvid
640TOOL_NBPERF=		nbperf
641TOOL_NCDCS=		ncdcs
642TOOL_PAX=		pax
643TOOL_PIC=		pic
644TOOL_PIGZ=		pigz
645TOOL_XZ=		xz
646TOOL_PKG_CREATE=	pkg_create
647TOOL_POWERPCMKBOOTIMAGE=powerpc-mkbootimage
648TOOL_PWD_MKDB=		pwd_mkdb
649TOOL_REFER=		refer
650TOOL_ROFF_ASCII=	nroff
651TOOL_ROFF_DOCASCII=	${TOOL_GROFF} -Tascii
652TOOL_ROFF_DOCHTML=	${TOOL_GROFF} -Thtml
653TOOL_ROFF_DVI=		${TOOL_GROFF} -Tdvi ${ROFF_PAGESIZE}
654TOOL_ROFF_HTML=		${TOOL_GROFF} -Tlatin1 -mdoc2html
655TOOL_ROFF_PS=		${TOOL_GROFF} -Tps ${ROFF_PAGESIZE}
656TOOL_ROFF_RAW=		${TOOL_GROFF} -Z
657TOOL_RPCGEN=		rpcgen
658TOOL_SED=		sed
659TOOL_SOELIM=		soelim
660TOOL_SORTINFO=		sortinfo
661TOOL_SPARKCRC=		sparkcrc
662TOOL_STAT=		stat
663TOOL_STRFILE=		strfile
664TOOL_SUNLABEL=		sunlabel
665TOOL_TBL=		tbl
666TOOL_TIC=		tic
667TOOL_UUDECODE=		uudecode
668TOOL_VGRIND=		vgrind -f
669TOOL_VFONTEDPR=		/usr/libexec/vfontedpr
670TOOL_ZIC=		zic
671
672.endif	# USETOOLS != yes						# }
673
674# Standalone code should not be compiled with PIE or CTF
675# Should create a better test
676.if defined(BINDIR) && ${BINDIR} == "/usr/mdec"
677NOPIE=			# defined
678NOCTF=			# defined
679.elif ${MACHINE} == "sun2"
680NOPIE=			# we don't have PIC, so no PIE
681.endif
682
683# Fallback to ensure that all variables are defined to something
684TOOL_CC.false=		false
685TOOL_CPP.false=		false
686TOOL_CXX.false=		false
687TOOL_FC.false=		false
688TOOL_OBJC.false=	false
689
690AVAILABLE_COMPILER?=	${HAVE_PCC:Dpcc} ${HAVE_LLVM:Dclang} ${HAVE_GCC:Dgcc} false
691
692.for _t in CC CPP CXX FC OBJC
693ACTIVE_${_t}=	${AVAILABLE_COMPILER:@.c.@ ${ !defined(UNSUPPORTED_COMPILER.${.c.}) && defined(TOOL_${_t}.${.c.}) :? ${.c.} : }@:[1]}
694SUPPORTED_${_t}=${AVAILABLE_COMPILER:Nfalse:@.c.@ ${ !defined(UNSUPPORTED_COMPILER.${.c.}) && defined(TOOL_${_t}.${.c.}) :? ${.c.} : }@}
695.endfor
696# make bugs prevent moving this into the .for loop
697CC=		${TOOL_CC.${ACTIVE_CC}}
698CPP=		${TOOL_CPP.${ACTIVE_CPP}}
699CXX=		${TOOL_CXX.${ACTIVE_CXX}}
700FC=		${TOOL_FC.${ACTIVE_FC}}
701OBJC=		${TOOL_OBJC.${ACTIVE_OBJC}}
702
703#
704# Clang and GCC compiler-specific options, usually to disable warnings.
705# The naming convention is "CC" + the compiler flag converted
706# to upper case, with '-' and '=' changed to '_' a la `tr -=a-z __A-Z`.
707# For variable naming purposes, treat -Werror=FLAG as -WFLAG,
708# and -Wno-error=FLAG as -Wno-FLAG (usually from Clang).
709#
710# E.g., CC_WNO_ADDRESS_OF_PACKED_MEMBER contains
711# both -Wno-error=address-of-packed-member for Clang,
712# and -Wno-address-of-packed-member for GCC 9+.
713#
714# Use these with e.g.
715#	COPTS.foo.c+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}
716#
717CC_WNO_ADDRESS_OF_PACKED_MEMBER=${${ACTIVE_CC} == "clang" :? -Wno-error=address-of-packed-member :} \
718				${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -Wno-address-of-packed-member :}
719
720CC_WNO_ARRAY_BOUNDS=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-array-bounds :}
721CC_WNO_CAST_FUNCTION_TYPE=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-cast-function-type :}
722CC_WNO_FORMAT_OVERFLOW=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-format-overflow :}
723CC_WNO_FORMAT_TRUNCATION=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-format-truncation :}
724CC_WNO_IMPLICIT_FALLTHROUGH=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-implicit-fallthrough :}
725CC_WNO_MAYBE_UNINITIALIZED=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-maybe-uninitialized :}
726CC_WNO_MISSING_TEMPLATE_KEYWORD=${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-missing-template-keyword :}
727CC_WNO_REGISTER=		${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-register :}
728CC_WNO_RETURN_LOCAL_ADDR=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-return-local-addr :}
729CC_WNO_STRINGOP_OVERFLOW=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 7:? -Wno-stringop-overflow :}
730CC_WNO_STRINGOP_OVERREAD=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 12:? -Wno-stringop-overread :}
731CC_WNO_STRINGOP_TRUNCATION=	${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -Wno-stringop-truncation :}
732
733# For each ${MACHINE_CPU}, list the ports that use it.
734MACHINES.aarch64=	evbarm
735MACHINES.alpha=		alpha
736MACHINES.arm=		acorn32 cats epoc32 evbarm hpcarm \
737			iyonix netwinder shark zaurus
738MACHINES.coldfire=	evbcf
739MACHINES.i386=		i386
740MACHINES.ia64=		ia64
741MACHINES.hppa=		hppa
742MACHINES.m68000=	sun2
743MACHINES.m68k=		amiga atari cesfic hp300 luna68k mac68k \
744			mvme68k news68k next68k sun3 virt68k x68k
745MACHINES.mips=		algor arc cobalt emips evbmips ews4800mips \
746			hpcmips mipsco newsmips pmax sbmips sgimips
747MACHINES.or1k=		or1k
748MACHINES.powerpc=	amigappc bebox evbppc ibmnws macppc mvmeppc \
749			ofppc prep rs6000 sandpoint
750MACHINES.riscv=		riscv
751MACHINES.sh3=		dreamcast evbsh3 hpcsh landisk mmeye
752MACHINES.sparc=		sparc sparc64
753MACHINES.sparc64=	sparc64
754MACHINES.vax=		vax
755MACHINES.x86_64=	amd64
756
757# OBJCOPY flags to create a.out binaries for old firmware
758# shared among src/distrib and ${MACHINE}/conf/Makefile.${MACHINE}.inc
759.if ${MACHINE_CPU} == "arm"
760OBJCOPY_ELF2AOUT_FLAGS?=	\
761	-O a.out-arm-netbsd	\
762	-R .ident		\
763	-R .ARM.attributes	\
764	-R .ARM.exidx		\
765	-R .ARM.extab		\
766	-R .SUNW_ctf		\
767	-R .arm.atpcs		\
768	-R .comment		\
769	-R .debug_abbrev	\
770	-R .debug_aranges	\
771	-R .debug_info		\
772	-R .debug_line		\
773	-R .debug_frame		\
774	-R .debug_loc		\
775	-R .debug_pubnames	\
776	-R .debug_pubtypes	\
777	-R .debug_ranges	\
778	-R .debug_str		\
779	-R .debug_macinfo	\
780	-R .eh_frame		\
781	-R .note.netbsd.ident
782.endif
783
784#
785# Targets to check if DESTDIR or RELEASEDIR is provided
786#
787.if !target(check_DESTDIR)
788check_DESTDIR: .PHONY .NOTMAIN
789.if !defined(DESTDIR)
790	@echo "setenv DESTDIR before doing that!"
791	@false
792.else
793	@true
794.endif
795.endif
796
797.if !target(check_RELEASEDIR)
798check_RELEASEDIR: .PHONY .NOTMAIN
799.if !defined(RELEASEDIR)
800	@echo "setenv RELEASEDIR before doing that!"
801	@false
802.else
803	@true
804.endif
805.endif
806
807#
808# Where the system object and source trees are kept; can be configurable
809# by the user in case they want them in ~/foosrc and ~/fooobj (for example).
810#
811BSDSRCDIR?=	/usr/src
812BSDOBJDIR?=	/usr/obj
813NETBSDSRCDIR?=	${BSDSRCDIR}
814
815BINGRP?=	wheel
816BINOWN?=	root
817BINMODE?=	555
818NONBINMODE?=	444
819
820# These are here mainly because we don't want suid root in case
821# a Makefile defines BINMODE.
822RUMPBINGRP?=	wheel
823RUMPBINOWN?=	root
824RUMPBINMODE?=	555
825RUMPNONBINMODE?=444
826
827MANDIR?=	/usr/share/man
828MANGRP?=	wheel
829MANOWN?=	root
830MANMODE?=	${NONBINMODE}
831MANINSTALL?=	${_MANINSTALL}
832
833INFODIR?=	/usr/share/info
834INFOGRP?=	wheel
835INFOOWN?=	root
836INFOMODE?=	${NONBINMODE}
837
838LIBDIR?=	/usr/lib
839
840LINTLIBDIR?=	/usr/libdata/lint
841LIBGRP?=	${BINGRP}
842LIBOWN?=	${BINOWN}
843LIBMODE?=	${NONBINMODE}
844
845DOCDIR?=	/usr/share/doc
846DOCGRP?=	wheel
847DOCOWN?=	root
848DOCMODE?=	${NONBINMODE}
849
850NLSDIR?=	/usr/share/nls
851NLSGRP?=	wheel
852NLSOWN?=	root
853NLSMODE?=	${NONBINMODE}
854
855KMODULEGRP?=	wheel
856KMODULEOWN?=	root
857KMODULEMODE?=	${NONBINMODE}
858
859LOCALEDIR?=	/usr/share/locale
860LOCALEGRP?=	wheel
861LOCALEOWN?=	root
862LOCALEMODE?=	${NONBINMODE}
863
864FIRMWAREDIR?=	/libdata/firmware
865FIRMWAREGRP?=	wheel
866FIRMWAREOWN?=	root
867FIRMWAREMODE?=	${NONBINMODE}
868
869DEBUGDIR?=	/usr/libdata/debug
870DEBUGGRP?=	wheel
871DEBUGOWN?=	root
872DEBUGMODE?=	${NONBINMODE}
873
874DTBDIR?=	/boot/dtb
875DTBGRP?=	wheel
876DTBOWN?=	root
877DTBMODE?=	${NONBINMODE}
878
879MKDIRMODE?=	0755
880MKDIRPERM?=	-m ${MKDIRMODE}
881
882#
883# Data-driven table using make variables to control how
884# toolchain-dependent targets and shared libraries are built
885# for different platforms and object formats.
886#
887# OBJECT_FMT:		currently either "ELF" or "a.out".
888#
889# All platforms are ELF.
890#
891OBJECT_FMT=	ELF
892
893#
894# If this platform's toolchain is missing, we obviously cannot build it.
895#
896.if ${TOOLCHAIN_MISSING} != "no"
897MKBINUTILS:= no
898MKGDB:= no
899MKGCC:= no
900.endif
901
902#
903# If we are using an external toolchain, we can still build the target's
904# binutils, but we cannot build GCC's support libraries, since those are
905# tightly-coupled to the version of GCC being used.
906#
907.if defined(EXTERNAL_TOOLCHAIN)
908MKGCC:= no
909.endif
910
911MKGDB.or1k=	no
912
913# No kernel modules for or1k or riscv (yet)
914MKKMOD.or1k=	no
915
916# No profiling for or1k (yet)
917MKPROFILE.or1k=	no
918MKPROFILE.riscv32=no
919MKPROFILE.riscv64=no
920
921#
922# The m68000 port is incomplete.
923#
924.if ${MACHINE_ARCH} == "m68000"
925NOPIC=		# defined
926MKISCSI=	no
927# XXX GCC 4 outputs mcount() calling sequences that try to load values
928# from over 64KB away and this fails to assemble.
929.if defined(HAVE_GCC)
930NOPROFILE=	# defined
931.endif
932.endif
933
934#
935# The ia64 port is incomplete.
936#
937MKGDB.ia64=	no
938
939#
940# On VAX using ELF, all objects are PIC, not just shared libraries,
941# so don't build the _pic version. VAX has no native TLS support either,
942# so differences between TLS models are not relevant.
943#
944MKPICLIB.vax=	no
945
946#
947# Location of the file that contains the major and minor numbers of the
948# version of a shared library.  If this file exists a shared library
949# will be built by <bsd.lib.mk>.
950#
951SHLIB_VERSION_FILE?= ${.CURDIR}/shlib_version
952
953#
954# GNU sources and packages sometimes see architecture names differently.
955#
956GNU_ARCH.aarch64eb=aarch64_be
957GNU_ARCH.coldfire=m5407
958GNU_ARCH.earm=arm
959GNU_ARCH.earmhf=arm
960GNU_ARCH.earmeb=armeb
961GNU_ARCH.earmhfeb=armeb
962GNU_ARCH.earmv4=armv4
963GNU_ARCH.earmv4eb=armv4eb
964GNU_ARCH.earmv5=arm
965GNU_ARCH.earmv5hf=arm
966GNU_ARCH.earmv5eb=armeb
967GNU_ARCH.earmv5hfeb=armeb
968GNU_ARCH.earmv6=armv6
969GNU_ARCH.earmv6hf=armv6
970GNU_ARCH.earmv6eb=armv6eb
971GNU_ARCH.earmv6hfeb=armv6eb
972GNU_ARCH.earmv7=armv7
973GNU_ARCH.earmv7hf=armv7
974GNU_ARCH.earmv7eb=armv7eb
975GNU_ARCH.earmv7hfeb=armv7eb
976GNU_ARCH.i386=i486
977GCC_CONFIG_ARCH.i386=i486
978GCC_CONFIG_TUNE.i386=nocona
979GCC_CONFIG_TUNE.x86_64=nocona
980GNU_ARCH.m68000=m68010
981GNU_ARCH.sh3eb=sh
982GNU_ARCH.sh3el=shle
983GNU_ARCH.mips64eb=mips64
984MACHINE_GNU_ARCH=${GNU_ARCH.${MACHINE_ARCH}:U${MACHINE_ARCH}}
985
986#
987# In order to identify NetBSD to GNU packages, we sometimes need
988# an "elf" tag for historically a.out platforms.
989#
990.if (${MACHINE_ARCH:Mearm*})
991MACHINE_GNU_PLATFORM?=${MACHINE_GNU_ARCH}--netbsdelf-${MACHINE_ARCH:C/eb//:C/v[4-7]//:S/earm/eabi/}
992.elif (${MACHINE_GNU_ARCH} == "arm" || \
993     ${MACHINE_GNU_ARCH} == "armeb" || \
994     ${MACHINE_ARCH} == "i386" || \
995     ${MACHINE_CPU} == "m68k" || \
996     ${MACHINE_GNU_ARCH} == "sh" || \
997     ${MACHINE_GNU_ARCH} == "shle" || \
998     ${MACHINE_ARCH} == "sparc" || \
999     ${MACHINE_ARCH} == "vax")
1000MACHINE_GNU_PLATFORM?=${MACHINE_GNU_ARCH}--netbsdelf
1001.else
1002MACHINE_GNU_PLATFORM?=${MACHINE_GNU_ARCH}--netbsd
1003.endif
1004
1005.if ${MACHINE_ARCH:M*arm*}
1006# Flags to pass to CC for using the old APCS ABI on ARM for compat or stand.
1007ARM_APCS_FLAGS=	-mabi=apcs-gnu -mfloat-abi=soft -marm
1008ARM_APCS_FLAGS+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8:? -mno-thumb-interwork :}
1009ARM_APCS_FLAGS+=${${ACTIVE_CC} == "clang":? -target ${MACHINE_GNU_ARCH}--netbsdelf -B ${TOOLDIR}/${MACHINE_GNU_PLATFORM}/bin :}
1010.endif
1011
1012GENASSYM_CPPFLAGS+=	${${ACTIVE_CC} == "clang":? -no-integrated-as :}
1013
1014TARGETS+=	all clean cleandir depend dependall includes \
1015		install lint obj regress tags html analyze describe \
1016		rumpdescribe
1017PHONY_NOTMAIN =	all clean cleandir depend dependall distclean includes \
1018		install lint obj regress beforedepend afterdepend \
1019		beforeinstall afterinstall realinstall realdepend realall \
1020		html subdir-all subdir-install subdir-depend analyze describe \
1021		rumpdescribe
1022.PHONY:		${PHONY_NOTMAIN}
1023.NOTMAIN:	${PHONY_NOTMAIN}
1024
1025.if ${NEED_OWN_INSTALL_TARGET} != "no"
1026.if !target(install)
1027install:	beforeinstall .WAIT subdir-install realinstall .WAIT afterinstall
1028beforeinstall:
1029subdir-install:
1030realinstall:
1031afterinstall:
1032.endif
1033all:		realall subdir-all
1034subdir-all:
1035realall:
1036depend:		realdepend subdir-depend
1037subdir-depend:
1038realdepend:
1039distclean:	cleandir
1040cleandir:	clean
1041
1042dependall:	.NOTMAIN realdepend .MAKE
1043	@cd "${.CURDIR}"; ${MAKE} realall
1044.endif
1045
1046#
1047# Define MKxxx variables (which are either yes or no) for users
1048# to set in /etc/mk.conf and override in the make environment.
1049# These should be tested with `== "no"' or `!= "no"'.
1050# The NOxxx variables should only be set by Makefiles.
1051#
1052# Please keep etc/Makefile and share/man/man5/mk.conf.5 in sync
1053# with changes to the MK* variables here.
1054#
1055
1056#
1057# Supported NO* options (if defined, MK* will be forced to "no",
1058# regardless of user's mk.conf setting).
1059#
1060# Source makefiles should set NO*, and not MK*, and must do so before
1061# including bsd.own.mk.
1062# Please keep alphabetically sorted with one entry per line.
1063#
1064_NOVARS= \
1065	NOCOMPAT \
1066	NODEBUGLIB \
1067	NODOC \
1068	NOHTML \
1069	NOINFO \
1070	NOLIBCSANITIZER \
1071	NOLINKLIB \
1072	NOLINT \
1073	NOMAN \
1074	NONLS \
1075	NOOBJ \
1076	NOPIC \
1077	NOPICINSTALL \
1078	NOPROFILE \
1079	NORELRO \
1080	NOSANITIZER \
1081	NOSHARE \
1082	NOSTATICLIB
1083
1084.for var in ${_NOVARS}
1085.if defined(${var})
1086MK${var:S/^NO//}:=	no
1087.endif
1088.endfor
1089
1090#
1091# MK* options which have variable defaults.
1092#
1093
1094#
1095# aarch64eb is not yet supported for MKCOMPAT.
1096#
1097.if ${MACHINE_ARCH} == "x86_64" || \
1098    ${MACHINE_ARCH} == "sparc64" || \
1099    ${MACHINE_MIPS64} || \
1100    ${MACHINE_ARCH} == "powerpc64" || \
1101    (${MACHINE_ARCH} == "aarch64" && ${HAVE_GCC:U0} == 0) || \
1102    ${MACHINE_ARCH} == "riscv64" || \
1103    ${MACHINE_ARCH:Mearm*}
1104MKCOMPAT?=	yes
1105.else
1106# Don't let this build where it really isn't supported.
1107MKCOMPAT:=	no
1108.endif
1109
1110.if ${MKCOMPAT} == "no"
1111MKCOMPATTESTS:=	no
1112MKCOMPATX11:=	no
1113.endif
1114
1115.if ${MACHINE_MIPS64} \
1116    || (${MACHINE} == "evbppc" && ${MACHINE_ARCH} == "powerpc")
1117MKCOMPATMODULES?=	yes
1118.else
1119MKCOMPATMODULES:=	no
1120.endif
1121
1122#
1123# These platforms use softfloat by default.
1124#
1125.if ${MACHINE_MIPS64}
1126MKSOFTFLOAT?=	yes
1127.endif
1128
1129#
1130# These platforms always use softfloat.
1131#
1132.if (${MACHINE_CPU} == "arm" && ${MACHINE_ARCH:M*hf*} == "") || \
1133    ${MACHINE_ARCH} == "coldfire" || ${MACHINE_CPU} == "or1k" || \
1134    ${MACHINE} == "emips" || ${MACHINE_CPU} == "sh3"
1135MKSOFTFLOAT=	yes
1136.endif
1137
1138.if ${MACHINE} == "emips"
1139SOFTFLOAT_BITS=	32
1140.endif
1141
1142#
1143# We want to build zfs only for amd64, aarch64 and sparc64 by default for now.
1144#
1145.if ${MACHINE} == "amd64" || \
1146    ${MACHINE} == "sparc64" || \
1147    ${MACHINE_ARCH:Maarch64*}
1148MKZFS?=		yes
1149.endif
1150
1151#
1152# DTrace works on amd64, i386, aarch64, and earm*
1153#
1154.if ${MACHINE_ARCH} == "i386" || \
1155    ${MACHINE_ARCH} == "x86_64" || \
1156    ${MACHINE_ARCH} == "aarch64" || \
1157    ${MACHINE_ARCH:Mearm*}
1158MKDTRACE?=	yes
1159MKCTF?=		yes
1160.endif
1161
1162#
1163# PIE is enabled on many platforms by default.
1164#
1165# Coverity does not like PIE
1166.if !defined(COVERITY_TOP_CONFIG) && \
1167    (${MACHINE_ARCH} == "i386" || \
1168    ${MACHINE_ARCH} == "x86_64" || \
1169    ${MACHINE_ARCH:Maarch64*} || \
1170    ${MACHINE_CPU} == "arm" || \
1171    ${MACHINE_CPU} == "m68k" || \
1172    ${MACHINE_CPU} == "mips" || \
1173    ${MACHINE_CPU} == "sh3" || \
1174    ${MACHINE} == "sparc64")
1175MKPIE?=		yes
1176.else
1177MKPIE?=		no
1178.endif
1179
1180#
1181# RELRO is enabled on i386, amd64, and aarch64 by default
1182#
1183# sync with NORELRO in compat/*/*/bsd.*.mk for the relro-enabled 64-bit
1184# platforms with relro-disabled 32-bit compat
1185#
1186.if ${MACHINE} == "i386" || \
1187    ${MACHINE} == "amd64" || \
1188    ${MACHINE_ARCH:Maarch64*}
1189MKRELRO?=	partial
1190.else
1191MKRELRO?=	no
1192.endif
1193
1194.if ${MACHINE_ARCH} == "x86_64" || ${MACHINE_ARCH} == "i386"
1195MKSTATICPIE?=	yes
1196.else
1197MKSTATICPIE?=	no
1198.endif
1199
1200#
1201# MK* options which default to "yes".
1202# Please keep alphabetically sorted with one entry per line.
1203#
1204_MKVARS.yes= \
1205	MKARGON2 \
1206	MKATF \
1207	MKBINUTILS \
1208	MKBSDTAR \
1209	MKCLEANSRC \
1210	MKCLEANVERIFY \
1211	MKCOMPLEX \
1212	MKCVS \
1213	MKCXX \
1214	MKDOC \
1215	MKDTC \
1216	MKDYNAMICROOT \
1217	MKGCC \
1218	MKGDB \
1219	MKGROFF \
1220	MKHESIOD \
1221	MKHTML \
1222	MKIEEEFP \
1223	MKINET6 \
1224	MKINFO \
1225	MKIPFILTER \
1226	MKISCSI \
1227	MKKERBEROS \
1228	MKKMOD \
1229	MKLDAP \
1230	MKLIBSTDCXX \
1231	MKLINKLIB \
1232	MKLVM \
1233	MKMAKEMANDB \
1234	MKMAN \
1235	MKMANDOC \
1236	MKMDNS \
1237	MKNLS \
1238	MKNPF \
1239	MKOBJ \
1240	MKPAM \
1241	MKPF \
1242	MKPIC \
1243	MKPICLIB \
1244	MKPOSTFIX \
1245	MKPROFILE \
1246	MKRUMP \
1247	MKSHARE \
1248	MKSKEY \
1249	MKSTATICLIB \
1250	MKSTRIPSYM \
1251	MKUNBOUND \
1252	MKX11FONTS \
1253	MKYP
1254
1255.for var in ${_MKVARS.yes}
1256${var}?=	${${var}.${MACHINE_ARCH}:U${${var}.${MACHINE}:Uyes}}
1257.endfor
1258
1259#
1260# MKGCCCMDS is only valid if we are building GCC so make it dependent on that.
1261#
1262_MKVARS.yes += MKGCCCMDS
1263MKGCCCMDS?=	${MKGCC}
1264
1265#
1266# Sanitizers, only "address" and "undefined" are supported by gcc
1267#
1268MKSANITIZER?=	no
1269USE_SANITIZER?=	address
1270
1271#
1272# Sanitizers implemented in libc, only "undefined" is supported
1273#
1274MKLIBCSANITIZER?=	no
1275USE_LIBCSANITIZER?=	undefined
1276
1277#
1278# Exceptions to the above:
1279#
1280
1281# RUMP uses -nostdinc which coverity does not like
1282# It also does not use many new files, so disable it
1283.if defined(COVERITY_TOP_CONFIG)
1284MKRUMP=		no
1285.endif
1286
1287#
1288# Build a dynamically linked /bin and /sbin, with the necessary shared
1289# libraries moved from /usr/lib to /lib and the shared linker moved
1290# from /usr/libexec to /lib
1291#
1292# Note that if the BINDIR is not /bin or /sbin, then we always use the
1293# non-DYNAMICROOT behavior (i.e. it is only enabled for programs in /bin
1294# and /sbin).  See <bsd.shlib.mk>.
1295#
1296# For ia64, ld.elf_so not yet implemented
1297.if ${MACHINE_ARCH} == "ia64"
1298MKDYNAMICROOT=	no
1299.endif
1300
1301.if defined(MKREPRO)
1302MKARZERO ?= ${MKREPRO}
1303GROFF_FLAGS ?= -dpaper=letter
1304ROFF_PAGESIZE ?= -P-pletter
1305.endif
1306
1307#
1308# Install the kernel as /netbsd/kernel and the modules in /netbsd/modules
1309#
1310KERNEL_DIR?=	no
1311
1312# Only install the general firmware on some systems
1313MKFIRMWARE.amd64=		yes
1314MKFIRMWARE.cobalt=		yes
1315MKFIRMWARE.evbarm=		yes
1316MKFIRMWARE.evbmips=		yes
1317MKFIRMWARE.evbppc=		yes
1318MKFIRMWARE.hpcarm=		yes
1319MKFIRMWARE.hppa=		yes
1320MKFIRMWARE.i386=		yes
1321MKFIRMWARE.mac68k=		yes
1322MKFIRMWARE.macppc=		yes
1323MKFIRMWARE.riscv=		yes
1324MKFIRMWARE.sandpoint=		yes
1325MKFIRMWARE.sparc64=		yes
1326
1327# Only install the GPU firmware on DRM-happy systems.
1328MKNOUVEAUFIRMWARE.x86_64=	yes
1329MKNOUVEAUFIRMWARE.i386=		yes
1330MKNOUVEAUFIRMWARE.aarch64=	yes
1331MKRADEONFIRMWARE.x86_64=	yes
1332MKRADEONFIRMWARE.i386=		yes
1333MKRADEONFIRMWARE.aarch64=	yes
1334MKAMDGPUFIRMWARE.x86_64=	yes
1335
1336# Only install the tegra firmware on evbarm.
1337MKTEGRAFIRMWARE.evbarm=		yes
1338
1339# Only build devicetree (dtb) files on armv6, armv7, and aarch64.
1340MKDTB.aarch64=			yes
1341MKDTB.aarch64eb=		yes
1342MKDTB.earmv6=			yes
1343MKDTB.earmv6hf=			yes
1344MKDTB.earmv6eb=			yes
1345MKDTB.earmv6hfeb=		yes
1346MKDTB.earmv7=			yes
1347MKDTB.earmv7hf=			yes
1348MKDTB.earmv7eb=			yes
1349MKDTB.earmv7hfeb=		yes
1350MKDTB.riscv32=			yes
1351MKDTB.riscv64=			yes
1352
1353# During transition from xorg-server 1.10 to 1.20
1354# XXX sgimips uses XAA which is removed in 1.20, and EXA is hard
1355# XXX to do the same with.
1356.if ${MACHINE} == "sgimips"
1357HAVE_XORG_SERVER_VER?=110
1358.else
1359HAVE_XORG_SERVER_VER?=120
1360.endif
1361
1362# Newer Mesa does not build with old X server
1363# VAX build triggers a gcc internal error
1364.if ${HAVE_XORG_SERVER_VER} != "120" || ${MACHINE} == "vax"
1365HAVE_MESA_VER=19
1366.endif
1367
1368HAVE_MESA_VER?=	21
1369.if ${HAVE_MESA_VER} == 19
1370EXTERNAL_MESALIB_DIR?=	MesaLib.old
1371.elif ${HAVE_MESA_VER} == 21
1372EXTERNAL_MESALIB_DIR?=	MesaLib
1373.endif
1374
1375# Default to LLVM run-time if x86 or aarch64 and X11 and Mesa 18 or newer
1376# XXX This knows that MKX11=no is default below, but would
1377# require splitting the below loop in two parts.
1378.if ${MKX11:Uno} != "no" && ${HAVE_MESA_VER} >= 19
1379MKLLVMRT.amd64=		yes
1380MKLLVMRT.i386=		yes
1381MKLLVMRT.aarch64=	yes
1382.endif
1383
1384# Just-in-time compiler for bpf, npf acceleration
1385MKSLJIT.aarch64=	yes
1386MKSLJIT.i386=		yes
1387MKSLJIT.sparc=		yes
1388#MKSLJIT.sparc64=	yes	# not suppored in sljit (yet?)
1389MKSLJIT.x86_64=		yes
1390#MKSLJIT.powerpc=	yes	# XXX
1391#MKSLJIT.powerpc64=	yes	# XXX
1392#MKSLJIT.mipsel=	yes	# XXX
1393#MKSLJIT.mipseb=	yes	# XXX
1394#MKSLJIT.mips64el=	yes	# XXX
1395#MKSLJIT.mips64eb=	yes	# XXX
1396#MKSLJIT.riscv32=	yes	# not until we update sljit
1397#MKSLJIT.riscv64=	yes	# not until we update sljit
1398
1399# compat with old names
1400MKDEBUGKERNEL?=${MKKDEBUG:Uno}
1401MKDEBUGTOOLS?=${MKTOOLSDEBUG:Uno}
1402
1403#
1404# MK* options which default to "no".
1405# Note that MKZFS has a different default for some platforms, see above.
1406# Please keep alphabetically sorted with one entry per line.
1407#
1408_MKVARS.no= \
1409	MKAMDGPUFIRMWARE \
1410	MKARZERO \
1411	MKBSDGREP \
1412	MKCATPAGES \
1413	MKCOMPATTESTS \
1414	MKCOMPATX11 \
1415	MKCTF \
1416	MKDEBUG \
1417	MKDEBUGLIB \
1418	MKDEPINCLUDES \
1419	MKDTB \
1420	MKDTRACE \
1421	MKFIRMWARE \
1422	MKGROFFHTMLDOC \
1423	MKHOSTOBJ \
1424	MKKYUA \
1425	MKLIBCXX \
1426	MKLINT \
1427	MKLLVM \
1428	MKLLVMRT \
1429	MKMANZ \
1430	MKNOUVEAUFIRMWARE \
1431	MKNSD \
1432	MKOBJDIRS \
1433	MKPCC \
1434	MKPICINSTALL \
1435	MKPIGZGZIP \
1436	MKRADEONFIRMWARE \
1437	MKREPRO \
1438	MKSLJIT \
1439	MKSOFTFLOAT \
1440	MKSTRIPIDENT \
1441	MKTEGRAFIRMWARE \
1442	MKTPM \
1443	MKUNPRIVED \
1444	MKUPDATE \
1445	MKX11 \
1446	MKX11MOTIF \
1447	MKXORG_SERVER \
1448	MKZFS
1449
1450.for var in ${_MKVARS.no}
1451${var}?=	${${var}.${MACHINE_ARCH}:U${${var}.${MACHINE}:Uno}}
1452.endfor
1453
1454#
1455# Which platforms build the xorg-server drivers (as opposed
1456# to just Xnest and Xvfb.)
1457#
1458.if ${MACHINE} == "alpha"	|| \
1459    ${MACHINE} == "amd64"	|| \
1460    ${MACHINE} == "amiga"	|| \
1461    ${MACHINE} == "bebox"	|| \
1462    ${MACHINE} == "cats"	|| \
1463    ${MACHINE} == "dreamcast"	|| \
1464    ${MACHINE} == "ews4800mips"	|| \
1465    ${MACHINE} == "evbarm"	|| \
1466    ${MACHINE} == "evbmips"	|| \
1467    ${MACHINE} == "evbppc"	|| \
1468    ${MACHINE} == "hp300"	|| \
1469    ${MACHINE} == "hpcarm"	|| \
1470    ${MACHINE} == "hpcmips"	|| \
1471    ${MACHINE} == "hpcsh"	|| \
1472    ${MACHINE} == "hppa"	|| \
1473    ${MACHINE} == "i386"	|| \
1474    ${MACHINE} == "ibmnws"	|| \
1475    ${MACHINE} == "iyonix"	|| \
1476    ${MACHINE} == "luna68k"	|| \
1477    ${MACHINE} == "mac68k"	|| \
1478    ${MACHINE} == "macppc"	|| \
1479    ${MACHINE} == "netwinder"	|| \
1480    ${MACHINE} == "newsmips"	|| \
1481    ${MACHINE} == "pmax"	|| \
1482    ${MACHINE} == "prep"	|| \
1483    ${MACHINE} == "ofppc"	|| \
1484    ${MACHINE} == "sgimips"	|| \
1485    ${MACHINE} == "shark"	|| \
1486    ${MACHINE} == "sparc"	|| \
1487    ${MACHINE} == "sparc64"	|| \
1488    ${MACHINE} == "vax"		|| \
1489    ${MACHINE} == "zaurus"
1490MKXORG_SERVER=yes
1491.endif
1492
1493#
1494# Force some options off if their dependencies are off.
1495#
1496
1497.if ${MKCXX} == "no"
1498MKATF:=		no
1499MKGCCCMDS:=	no
1500MKGDB:=		no
1501MKGROFF:=	no
1502MKKYUA:=	no
1503.endif
1504
1505.if ${MKMAN} == "no"
1506MKCATPAGES:=	no
1507MKHTML:=	no
1508.endif
1509
1510_MANINSTALL=	maninstall
1511.if ${MKCATPAGES} != "no"
1512_MANINSTALL+=	catinstall
1513.endif
1514.if ${MKHTML} != "no"
1515_MANINSTALL+=	htmlinstall
1516.endif
1517
1518.if ${MKLINKLIB} == "no"
1519MKLINT:=	no
1520MKPICINSTALL:=	no
1521MKPROFILE:=	no
1522.endif
1523
1524.if ${MKPIC} == "no"
1525MKPICLIB:=	no
1526.endif
1527
1528.if ${MKOBJ} == "no"
1529MKOBJDIRS:=	no
1530.endif
1531
1532.if ${MKSHARE} == "no"
1533MKCATPAGES:=	no
1534MKDOC:=		no
1535MKINFO:=	no
1536MKHTML:=	no
1537MKMAN:=		no
1538MKNLS:=		no
1539.endif
1540
1541.if ${MACHINE_ARCH:Mearm*}
1542_NEEDS_LIBCXX.${MACHINE_ARCH}=	yes
1543.endif
1544_NEEDS_LIBCXX.aarch64=		yes
1545_NEEDS_LIBCXX.aarch64eb=	yes
1546_NEEDS_LIBCXX.i386=		yes
1547_NEEDS_LIBCXX.powerpc=		yes
1548_NEEDS_LIBCXX.powerpc64=	yes
1549_NEEDS_LIBCXX.sparc=		yes
1550_NEEDS_LIBCXX.sparc64=		yes
1551_NEEDS_LIBCXX.x86_64=		yes
1552
1553.if ${MKLLVM} == "yes" && ${_NEEDS_LIBCXX.${MACHINE_ARCH}:Uno} == "yes"
1554MKLIBCXX:=	yes
1555.endif
1556
1557#
1558# Disable MKSTRIPSYM if MKDEBUG is enabled.
1559#
1560.if ${MKDEBUG} != "no"
1561MKSTRIPSYM:=	no
1562.endif
1563
1564#
1565# install(1) parameters.
1566#
1567COPY?=		-c
1568.if ${MKUPDATE} == "no"
1569PRESERVE?=
1570.else
1571PRESERVE?=	-p
1572.endif
1573RENAME?=	-r
1574HRDLINK?=	-l h
1575SYMLINK?=	-l s
1576
1577METALOG?=	${DESTDIR}/METALOG
1578METALOG.add?=	${TOOL_CAT} -l >> ${METALOG}
1579.if (${_SRC_TOP_} != "")	# only set INSTPRIV if inside ${NETBSDSRCDIR}
1580.if ${MKUNPRIVED} != "no"
1581INSTPRIV.unpriv=-U -M ${METALOG} -D ${DESTDIR} -h sha256
1582.else
1583INSTPRIV.unpriv=
1584.endif
1585INSTPRIV?=	${INSTPRIV.unpriv} -N ${NETBSDSRCDIR}/etc
1586.endif
1587STRIPFLAG?=
1588
1589INSTALL_DIR?=		${INSTALL} ${INSTPRIV} -d
1590INSTALL_FILE?=		${INSTALL} ${INSTPRIV} ${COPY} ${PRESERVE} ${RENAME}
1591INSTALL_LINK?=		${INSTALL} ${INSTPRIV} ${HRDLINK} ${RENAME}
1592INSTALL_SYMLINK?=	${INSTALL} ${INSTPRIV} ${SYMLINK} ${RENAME}
1593
1594# for crunchide & ldd, define the OBJECT_FMTS used by a MACHINE_ARCH
1595#
1596OBJECT_FMTS=
1597.if	${MACHINE_ARCH} != "alpha" && ${MACHINE_ARCH} != "ia64"
1598OBJECT_FMTS+=	elf32
1599.endif
1600.if	${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH:M*64*} != ""
1601. if !(${MKCOMPAT:Uyes} == "no" && ${MACHINE_ARCH:Mmips64*} != "")
1602OBJECT_FMTS+=	elf64
1603. endif
1604.endif
1605
1606#
1607# Set defaults for the USE_xxx variables.
1608#
1609
1610#
1611# USE_* options which default to "no" and will be forced to "no" if their
1612# corresponding MK* variable is set to "no".
1613#
1614.for var in USE_SKEY
1615.if (${${var:S/USE_/MK/}} == "no")
1616${var}:= no
1617.else
1618${var}?= no
1619.endif
1620.endfor
1621
1622#
1623# USE_* options which default to "yes" unless their corresponding MK*
1624# variable is set to "no".
1625#
1626.for var in USE_HESIOD USE_INET6 USE_KERBEROS USE_LDAP USE_PAM USE_YP
1627.if (${${var:S/USE_/MK/}} == "no")
1628${var}:= no
1629.else
1630${var}?= yes
1631.endif
1632.endfor
1633
1634#
1635# USE_* options which default to "yes".
1636#
1637.for var in USE_JEMALLOC
1638${var}?= yes
1639.endfor
1640
1641#
1642# USE_* options which default to "no".
1643#
1644# For now, disable pigz as compressor by default
1645.for var in USE_PIGZGZIP
1646${var}?= no
1647.endfor
1648
1649# Default to USE_XZ_SETS on some 64bit architectures where decompressor
1650# memory will likely not be in short supply.
1651# Since pigz can not create .xz format files currently, disable .xz
1652# format if USE_PIGZGZIP is enabled.
1653.if ${USE_PIGZGZIP} == "no" && \
1654    (${MACHINE} == "amd64" || \
1655     ${MACHINE_ARCH:Maarch64*})
1656USE_XZ_SETS?= yes
1657.else
1658USE_XZ_SETS?= no
1659.endif
1660
1661#
1662# TOOL_GZIP and friends.  These might refer to TOOL_PIGZ or to the host gzip.
1663#
1664.if ${USE_PIGZGZIP} != "no"
1665TOOL_GZIP=		${TOOL_PIGZ}
1666GZIP_N_FLAG?=		-nT
1667.else
1668.if ${USETOOLS} == "yes"
1669TOOL_GZIP=		${TOOLDIR}/bin/${_TOOL_PREFIX}gzip
1670.else
1671TOOL_GZIP=		gzip
1672.endif
1673GZIP_N_FLAG?=		-n
1674.endif
1675TOOL_GZIP_N=		${TOOL_GZIP} ${GZIP_N_FLAG}
1676
1677#
1678# Where X11 sources are and where it is installed to.
1679#
1680.if !defined(X11SRCDIR)
1681.if exists(${NETBSDSRCDIR}/../xsrc)
1682X11SRCDIR!=		cd "${NETBSDSRCDIR}/../xsrc" && pwd
1683.else
1684X11SRCDIR=		/usr/xsrc
1685.endif
1686.endif # !defined(X11SRCDIR)
1687
1688X11SRCDIR.local?=	${X11SRCDIR}/local
1689X11ROOTDIR?=		/usr/X11R7
1690X11BINDIR?=		${X11ROOTDIR}/bin
1691X11ETCDIR?=		/etc/X11
1692X11FONTDIR?=		${X11ROOTDIR}/lib/X11/fonts
1693X11INCDIR?=		${X11ROOTDIR}/include
1694X11LIBDIR?=		${X11ROOTDIR}/lib/X11
1695X11MANDIR?=		${X11ROOTDIR}/man
1696X11SHAREDIR?=		${X11ROOTDIR}/share
1697X11USRLIBDIR?=		${X11ROOTDIR}/lib${MLIBDIR:D/${MLIBDIR}}
1698
1699#
1700# New modular-xorg based builds
1701#
1702X11SRCDIRMIT?=		${X11SRCDIR}/external/mit
1703.for _lib in \
1704	FS ICE SM X11 XScrnSaver XTrap Xau Xcomposite Xcursor Xdamage \
1705	Xdmcp Xevie Xext Xfixes Xfont Xfont2 Xft Xi Xinerama Xmu Xpresent Xpm \
1706	Xrandr Xrender Xres Xt Xtst Xv XvMC Xxf86dga Xxf86misc Xxf86vm drm \
1707	epoxy fontenc vdpau xkbfile xkbui Xaw pciaccess xcb xshmfence \
1708	pthread-stubs xcvt
1709X11SRCDIR.${_lib}?=		${X11SRCDIRMIT}/lib${_lib}/dist
1710.endfor
1711
1712.for _proto in \
1713	xcb- xorg
1714X11SRCDIR.${_proto}proto?=		${X11SRCDIRMIT}/${_proto}proto/dist
1715.endfor
1716
1717.if ${HAVE_XORG_SERVER_VER} == "120"
1718XORG_SERVER_SUBDIR?=xorg-server
1719. if ${MACHINE} == "amd64" || ${MACHINE} == "i386" || ${MACHINE} == "evbarm"
1720HAVE_XORG_GLAMOR?=	yes
1721. endif
1722.else
1723XORG_SERVER_SUBDIR?=xorg-server.old
1724.endif
1725
1726X11SRCDIR.xorg-server?=		${X11SRCDIRMIT}/${XORG_SERVER_SUBDIR}/dist
1727HAVE_XORG_GLAMOR?=	no
1728
1729# Build glamor extension?
1730
1731.for _dir in \
1732	xtrans fontconfig freetype evieext mkfontscale bdftopcf \
1733	xorg-cf-files imake xbiff xkeyboard-config \
1734	xcompmgr xbitmaps appres xeyes xev xedit sessreg pixman \
1735	brotli \
1736	beforelight bitmap editres makedepend fonttosfnt fslsfonts fstobdf \
1737	glu glw mesa-demos MesaGLUT MesaLib MesaLib.old MesaLib7 \
1738	ico iceauth listres lndir \
1739	luit xproxymanagementprotocol mkfontdir oclock proxymngr rgb \
1740	rstart setxkbmap showfont smproxy transset twm viewres \
1741	util-macros \
1742	x11perf xauth xcalc xclipboard \
1743	xclock xcmsdb xconsole xditview xdpyinfo xdriinfo xdm \
1744	xfd xf86dga xfindproxy xfontsel xgamma xgc xhost xinit \
1745	xkill xload xlogo xlsatoms xlsclients xlsfonts xmag xmessage \
1746	xmh xmodmap xmore xman xprop xrandr xrdb xrefresh xset \
1747	xsetmode xsetpointer xsetroot xsm xstdcmap xvidtune xvinfo \
1748	xwininfo xwud xkbprint xkbevd \
1749	xterm xwd xfs xfsinfo xtrap xkbutils xkbcomp \
1750	xinput xcb-util xorg-docs \
1751	font-adobe-100dpi font-adobe-75dpi font-adobe-utopia-100dpi \
1752	font-adobe-utopia-75dpi font-adobe-utopia-type1 \
1753	font-alias \
1754	font-bh-100dpi font-bh-75dpi font-bh-lucidatypewriter-100dpi \
1755	font-bh-lucidatypewriter-75dpi font-bh-ttf font-bh-type1 \
1756	font-bitstream-100dpi font-bitstream-75dpi font-bitstream-type1 \
1757	font-cursor-misc font-daewoo-misc font-dec-misc font-ibm-type1 \
1758	font-isas-misc font-jis-misc font-misc-misc font-mutt-misc \
1759	font-sony-misc font-util ttf-bitstream-vera encodings
1760X11SRCDIR.${_dir}?=		${X11SRCDIRMIT}/${_dir}/dist
1761.endfor
1762
1763# X11SRCDIR.Mesa points to the currently used Mesa sources
1764X11SRCDIR.Mesa?=		${X11SRCDIRMIT}/${EXTERNAL_MESALIB_DIR}/dist
1765
1766.for _i in \
1767	elographics keyboard mouse synaptics vmmouse void ws
1768X11SRCDIR.xf86-input-${_i}?=	${X11SRCDIRMIT}/xf86-input-${_i}/dist
1769.endfor
1770
1771# xf86-video-modesetting move into the server build.
1772EXTRA_DRIVERS=
1773.if ${HAVE_XORG_SERVER_VER} == "120"
1774X11SRCDIR.xf86-video-modesetting=${X11SRCDIR.xorg-server}/hw/xfree86/drivers/modesetting
1775.else
1776EXTRA_DRIVERS=	modesetting
1777.endif
1778
1779.for _v in \
1780	ag10e amdgpu apm ark ast ati ati-kms chips cirrus crime \
1781	geode glint i128 i740 igs imstt intel intel-old intel-2014 \
1782	${EXTRA_DRIVERS} mach64 mga \
1783	neomagic newport nouveau nsc nv openchrome pnozz \
1784	r128 rendition \
1785	s3 s3virge savage siliconmotion sis suncg14 \
1786	suncg6 sunffb sunleo suntcx \
1787	tdfx tga trident tseng vboxvideo vesa vga vmware wsfb xgi
1788X11SRCDIR.xf86-video-${_v}?=	${X11SRCDIRMIT}/xf86-video-${_v}/dist
1789.endfor
1790
1791
1792X11DRI?=			yes
1793X11LOADABLE?=			yes
1794
1795
1796#
1797# MAKEDIRTARGET dir target [extra make(1) params]
1798#	run "cd $${dir} && ${MAKEDIRTARGETENV} ${MAKE} [params] $${target}", with a pretty message
1799#
1800MAKEDIRTARGETENV?=
1801MAKEDIRTARGET=\
1802	@_makedirtarget() { \
1803		dir="$$1"; shift; \
1804		target="$$1"; shift; \
1805		case "$${dir}" in \
1806		/*)	this="$${dir}/"; \
1807			real="$${dir}" ;; \
1808		.)	this="${_THISDIR_}"; \
1809			real="${.CURDIR}" ;; \
1810		*)	this="${_THISDIR_}$${dir}/"; \
1811			real="${.CURDIR}/$${dir}" ;; \
1812		esac; \
1813		show=$${this:-.}; \
1814		echo "$${target} ===> $${show%/}$${1:+	(with: $$@)}"; \
1815		cd "$${real}" \
1816		&& ${MAKEDIRTARGETENV} ${MAKE} _THISDIR_="$${this}" "$$@" $${target}; \
1817	}; \
1818	_makedirtarget
1819
1820#
1821# MAKEVERBOSE support.  Levels are:
1822#	0	Minimal output ("quiet")
1823#	1	Describe what is occurring
1824#	2	Describe what is occurring and echo the actual command
1825#	3	Ignore the effect of the "@" prefix in make commands
1826#	4	Trace shell commands using the shell's -x flag
1827#
1828MAKEVERBOSE?=		2
1829
1830.if ${MAKEVERBOSE} == 0
1831_MKMSG?=	@\#
1832_MKSHMSG?=	: echo
1833_MKSHECHO?=	: echo
1834.SILENT:
1835.elif ${MAKEVERBOSE} == 1
1836_MKMSG?=	@echo '   '
1837_MKSHMSG?=	echo '   '
1838_MKSHECHO?=	: echo
1839.SILENT:
1840.else	# MAKEVERBOSE >= 2
1841_MKMSG?=	@echo '\#  '
1842_MKSHMSG?=	echo '\#  '
1843_MKSHECHO?=	echo
1844.SILENT: __makeverbose_dummy_target__
1845.endif	# MAKEVERBOSE >= 2
1846.if ${MAKEVERBOSE} >= 3
1847.MAKEFLAGS:	-dl
1848.endif	# ${MAKEVERBOSE} >= 3
1849.if ${MAKEVERBOSE} >= 4
1850.MAKEFLAGS:	-dx
1851.endif	# ${MAKEVERBOSE} >= 4
1852
1853_MKMSG_BUILD?=		${_MKMSG} "  build "
1854_MKMSG_CREATE?=		${_MKMSG} " create "
1855_MKMSG_COMPILE?=	${_MKMSG} "compile "
1856_MKMSG_EXECUTE?=	${_MKMSG} "execute "
1857_MKMSG_FORMAT?=		${_MKMSG} " format "
1858_MKMSG_INSTALL?=	${_MKMSG} "install "
1859_MKMSG_LINK?=		${_MKMSG} "   link "
1860_MKMSG_LEX?=		${_MKMSG} "    lex "
1861_MKMSG_REMOVE?=		${_MKMSG} " remove "
1862_MKMSG_REGEN?=		${_MKMSG} "  regen "
1863_MKMSG_YACC?=		${_MKMSG} "   yacc "
1864
1865_MKSHMSG_CREATE?=	${_MKSHMSG} " create "
1866_MKSHMSG_FORMAT?=	${_MKSHMSG} " format "
1867_MKSHMSG_INSTALL?=	${_MKSHMSG} "install "
1868
1869_MKTARGET_BUILD?=	${_MKMSG_BUILD} ${.CURDIR:T}/${.TARGET}
1870_MKTARGET_CREATE?=	${_MKMSG_CREATE} ${.CURDIR:T}/${.TARGET}
1871_MKTARGET_COMPILE?=	${_MKMSG_COMPILE} ${.CURDIR:T}/${.TARGET}
1872_MKTARGET_FORMAT?=	${_MKMSG_FORMAT} ${.CURDIR:T}/${.TARGET}
1873_MKTARGET_INSTALL?=	${_MKMSG_INSTALL} ${.TARGET}
1874_MKTARGET_LINK?=	${_MKMSG_LINK} ${.CURDIR:T}/${.TARGET}
1875_MKTARGET_LEX?=		${_MKMSG_LEX} ${.CURDIR:T}/${.TARGET}
1876_MKTARGET_REMOVE?=	${_MKMSG_REMOVE} ${.TARGET}
1877_MKTARGET_YACC?=	${_MKMSG_YACC} ${.CURDIR:T}/${.TARGET}
1878
1879.if ${MKMANDOC} == "yes"
1880TARGETS+=	lintmanpages
1881.endif
1882
1883TESTSBASE=	/usr/tests${MLIBDIR:D/${MLIBDIR}}
1884
1885# Override with tools versions if needed
1886.if ${MKCTF:Uno} != "no" && !defined(NOCTF) && \
1887    (exists(${TOOL_CTFCONVERT}) || exists(/usr/bin/${TOOL_CTFCONVERT}))
1888CTFCONVERT=	${TOOL_CTFCONVERT}
1889CTFMERGE=	${TOOL_CTFMERGE}
1890.endif
1891
1892.endif	# !defined(_BSD_OWN_MK_)
1893