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