1.PATH: ${.CURDIR}/../../include 2 3# XXX We need to include this to avoid installing MIT KRB5 includes on 4# XXX Heimdal systems. Remove the following line when Heimdal is finally 5# XXX removed. 6.include <src.opts.mk> 7 8LIB= egacy 9SRC= 10INCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS 11INCSGROUPS+= MACHINESYSINCS RPCINCS 12.if ${MK_MITKRB5} != "no" 13INCSGROUPS+= EDITINC K5GSSRPCINC GSSAPIINC 14INCSGROUPS+= K5GSSAPIINC K52GSSAPIINC KRB5INC 15.endif 16INCS= 17 18SYSINCSDIR= ${INCLUDEDIR}/sys 19CASPERINCDIR= ${INCLUDEDIR}/casper 20# Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool 21UFSINCSDIR= ${INCLUDEDIR}/ufs/ufs 22FFSINCSDIR= ${INCLUDEDIR}/ufs/ffs 23MSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs 24DISKINCSDIR= ${INCLUDEDIR}/sys/disk 25MACHINESYSINCSDIR= ${INCLUDEDIR}/machine 26RPCINCSDIR= ${INCLUDEDIR}/rpc 27.if ${MK_MITKRB5} != "no" 28EDITINCDIR= ${INCLUDEDIR}/edit/readline 29K5GSSRPCINCDIR= ${INCLUDEDIR}/gssrpc 30GSSAPIINCDIR= ${INCLUDEDIR}/gssapi 31K5GSSAPIINCDIR= ${INCLUDEDIR}/gssapi_krb5 32K52GSSAPIINCDIR=${INCLUDEDIR}/gssapi_krb5/gssapi 33KRB5INCDIR= ${INCLUDEDIR}/krb5 34KDB5INCDIR= ${INCLUDEDIR}/kdb5 35KADM5INCDIR= ${INCLUDEDIR}/kadm5 36.endif 37 38BOOTSTRAPPING?= 0 39 40 41.if ${.MAKE.OS} == "Darwin" 42_XCODE_ROOT!=xcode-select -p 43# since macOS 10.14 C headers are no longer installed in /usr but only 44# provided via the SDK 45.if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools" 46# Only command line tools installed -> host headers are in the SDKs directory 47_MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/ 48.else 49# Full XCode installed -> host headers are below Platforms/MacOSX.platform 50_MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk 51.endif 52HOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include 53.if !exists(${HOST_INCLUDE_ROOT}/stdio.h) 54.error You must install the macOS SDK (try xcode-select --install) 55.endif 56.else 57HOST_INCLUDE_ROOT=/usr/include 58.endif 59 60# Allow building libc-internal files (also on non-FreeBSD hosts) 61CFLAGS+= -I${.CURDIR}/libc-bootstrap 62# Symbol versioning is not required for -legacy (and macOS bootstrap) 63MK_SYMVER= no 64 65_WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true 66.if ${_WITH_PWCACHEDB} == 0 67.PATH: ${.CURDIR}/../../contrib/libc-pwcache 68CFLAGS.pwcache.c+= -I${.CURDIR}/../../contrib/libc-pwcache 69SRCS+= pwcache.c 70.endif 71 72_WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true 73.if ${_WITH_STRSVIS} == 0 74.PATH: ${.CURDIR}/../../contrib/libc-vis 75INCS+= vis.h 76SRCS+= vis.c unvis.c 77CFLAGS.vis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 78CFLAGS.unvis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 79.endif 80 81_WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true 82.if ${_WITH_REALLOCARRAY} == 0 83.PATH: ${.CURDIR}/../../lib/libc/stdlib 84INCS+= stdlib.h 85SRCS+= reallocarray.c 86.endif 87 88.if !exists(${HOST_INCLUDE_ROOT}/stdckdint.h) 89INCS+= stdckdint.h 90.endif 91 92.if exists(${HOST_INCLUDE_ROOT}/sys/stat.h) 93_WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true 94.else 95_WITH_UTIMENS= 0 96.endif 97.if ${_WITH_UTIMENS} == 0 98SYSINCS+= stat.h 99SRCS+= futimens.c utimensat.c 100.endif 101 102_WITH_EXPLICIT_BZERO!= cat ${HOST_INCLUDE_ROOT}/strings.h ${HOST_INCLUDE_ROOT}/string.h | grep -c explicit_bzero || true 103.if ${_WITH_EXPLICIT_BZERO} == 0 104# .PATH: ${SRCTOP}/sys/libkern 105# Adding sys/libkern to .PATH breaks building the cross-build compat library 106# since that attempts to build strlcpy.c from libc and adding libkern here will 107# cause it to pick the file from libkern instead (which won't compile). 108# Avoid modifying .PATH by creating a copy in the build directory instead. 109explicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c 110 cp ${.ALLSRC} ${.TARGET} 111CLEANFILES+= explicit_bzero.c 112INCS+= strings.h 113SRCS+= explicit_bzero.c 114.endif 115 116_WITH_FSPACECTL!= grep -c fspacectl ${HOST_INCLUDE_ROOT}/fcntl.h || true 117.if ${_WITH_FSPACECTL} == 0 118INCS+= fcntl.h 119SRCS+= fspacectl.c 120.endif 121 122.if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h) 123_WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 124_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 125.endif 126.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0 127.PATH: ${SRCTOP}/lib/libcapsicum 128INCS+= capsicum_helpers.h 129.PATH: ${SRCTOP}/lib/libcasper/libcasper 130INCS+= libcasper.h 131.endif 132 133# rpcgen should build against the source tree rpc/types.h and not the host. 134# This is especially important on non-FreeBSD systems where the types may 135# not match. 136RPCINCS+= ${SRCTOP}/sys/rpc/types.h 137 138INCS+= ${SRCTOP}/include/mpool.h 139INCS+= ${SRCTOP}/include/ndbm.h 140INCS+= ${SRCTOP}/include/err.h 141INCS+= ${SRCTOP}/include/stringlist.h 142 143# Needed to build arc4random.c 144INCSGROUPS+= CHACHA20INCS 145CHACHA20INCSDIR= ${INCLUDEDIR}/crypto/chacha20 146CHACHA20INCS+= ${SRCTOP}/sys/crypto/chacha20/_chacha.h \ 147 ${SRCTOP}/sys/crypto/chacha20/chacha.h 148 149.if ${MACHINE} == "host" 150_host_arch= ${_HOST_ARCH} 151.elif ${MACHINE} == "host32" 152_host_arch= ${_HOST_ARCH32} 153.else 154_host_arch=${MACHINE} 155.endif 156.if ${_host_arch} == "x86_64" 157# bmake on Linux/mac often prints that instead of amd64 158_host_arch=amd64 159.elif ${_host_arch} == "aarch64" 160# Linux calls arm64, aarch64, across the board 161_host_arch=arm64 162.elif ${_host_arch:Mppc*} 163_host_arch=powerpc 164.endif 165.if ${_host_arch} == "unknown" 166# HACK: If MACHINE is unknown, assume we are building on x86 167_host_arch=amd64 168.endif 169MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/elf.h 170.if ${_host_arch} == "amd64" || ${_host_arch} == "i386" 171INCSGROUPS+= X86INCS 172X86INCSDIR= ${INCLUDEDIR}/x86 173X86INCS+= ${SRCTOP}/sys/x86/include/elf.h 174.endif 175 176# needed for btxld: 177MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/exec.h 178MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/reloc.h 179INCS+= ${SRCTOP}/include/a.out.h 180INCS+= ${SRCTOP}/include/nlist.h 181SYSINCS+= ${SRCTOP}/sys/sys/imgact_aout.h 182SYSINCS+= ${SRCTOP}/sys/sys/nlist_aout.h 183 184# macOS's bitstring lacks FreeBSD-specific additions used by makefs's ZFS code 185# and Linux doesn't have it at all. Older FreeBSD versions lack recent 186# additions. 187INCS+= ${SRCTOP}/include/bitstring.h 188SYSINCS+= ${SRCTOP}/sys/sys/bitstring.h 189 190.if ${.MAKE.OS} != "FreeBSD" 191.PATH: ${.CURDIR}/cross-build 192 193# Needed by our sys/types.h wrapper 194SYSINCS+= ${SRCTOP}/sys/sys/bitcount.h 195 196# dbopen() behaves differently on Linux and FreeBSD so we ensure that we 197# bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to 198# __freebsd_dbopen() so that we don't ever use the host version 199INCS+= ${SRCTOP}/include/db.h 200LIBC_SRCTOP= ${SRCTOP}/lib/libc/ 201.include "${LIBC_SRCTOP}/db/Makefile.inc" 202# Do the same as we did for dbopen() for getopt() on since it's not compatible 203# on Linux (and to avoid surprises also compile the FreeBSD code on macOS) 204.PATH: ${LIBC_SRCTOP}/stdlib 205SRCS+= getopt.c getopt_long.c 206INCS+= ${SRCTOP}/include/getopt.h 207 208# getcap.c is needed for cap_mkdb: 209.PATH: ${LIBC_SRCTOP}/gen 210SRCS+= getcap.c 211# Glibc does not provide all err*/warn* functions, and for macOS we need the 212# alias with the extra underscore. 213SRCS+= err.c 214# Add various libbc functions that are not available in glibc: 215SRCS+= stringlist.c setmode.c 216SRCS+= strtonum.c merge.c heapsort.c reallocf.c 217.PATH: ${LIBC_SRCTOP}/locale 218SRCS+= rpmatch.c 219 220.if ${.MAKE.OS} == "Linux" 221# On Linux, glibc does not provide strmode. It only provides strlcpy 222# and strlcat from glibc 2.38. 223.PATH: ${LIBC_SRCTOP}/string 224SRCS+= strmode.c 225# Assume if strlcpy exists so does strlcat 226_WITH_EXPLICIT_STRLCPY!= cat ${HOST_INCLUDE_ROOT}/strings.h ${HOST_INCLUDE_ROOT}/string.h | grep -c strlcpy || true 227.if ${_WITH_EXPLICIT_STRLCPY} == 0 228SRCS+= strlcpy.c strlcat.c 229.endif 230# On Linux, glibc provides ffs* but not fls* 231SRCS+= fls.c flsl.c flsll.c 232# Compile the fgetln/fgetwln/closefrom fallback code from libbsd: 233SRCS+= fgetln_fallback.c fgetwln_fallback.c closefrom.c 234CFLAGS.closefrom.c+= -DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \ 235 -DHAVE_DIRFD -DHAVE_SYSCONF 236# Provide getprogname/setprograme 237SRCS+= progname.c 238# Provide fflagstostr/strtofflags for mtree and makefs 239# On macOS we use the host's so conflate host and target flags, which ideally 240# we'd avoid, but in practice these align for many flags, including 241# SF_IMMUTABLE, the only flag we currently set during install. 242SRCS+= strtofflags.c 243 244# macOS has a standalone cross-build implementation, but Linux can use the same 245# ELF one as FreeBSD 246SYSINCS+= ${SRCTOP}/sys/sys/linker_set.h 247 248.endif # ${MAKE.OS} == "Linux" 249 250.if ${.MAKE.OS} == "Darwin" 251# Standalone implementation of secure_getenv(), not available on MacOS. 252SRCS+= secure_getenv.c 253.endif # ${MAKE.OS} == "Darwin" 254 255# Provide the same arc4random implementation on Linux/macOS 256CFLAGS.arc4random.c+= -I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1 257SRCS+= arc4random.c arc4random_uniform.c 258 259# expand_number() is not provided by either Linux or MacOS libutil 260.PATH: ${SRCTOP}/lib/libutil 261SRCS+= expand_number.c 262# Linux libutil also doesn't have fparseln 263SRCS+= fparseln.c 264# A dummy sysctl for tzsetup: 265SRCS+= fake_sysctl.c 266 267# capsicum support 268SYSINCS+= ${SRCTOP}/sys/sys/capsicum.h 269SYSINCS+= ${SRCTOP}/sys/sys/caprights.h 270SRCS+= capsicum_stubs.c 271# XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes 272# conflicts with other files. Instead copy subr_capability to the build dir. 273subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c 274 cp ${.ALLSRC} ${.TARGET} 275SRCS+= subr_capability.c 276CLEANFILES+= subr_capability.c 277 278# Headers needed for msdosfs use in makefs 279SYSINCS+= ${SRCTOP}/sys/sys/_callout.h 280SYSINCS+= ${SRCTOP}/sys/sys/_lock.h 281SYSINCS+= ${SRCTOP}/sys/sys/_lockmgr.h 282SYSINCS+= ${SRCTOP}/sys/sys/_task.h 283.endif # ${MAKE.OS} != "FreeBSD" 284 285CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h 286CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_net/cap_net.h 287 288.if ${MK_MITKRB5} != "no" 289EDITINC+= ${SRCTOP}/contrib/libedit/readline/readline.h 290K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/auth.h 291K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/auth_gss.h 292K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/auth_gssapi.h 293K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/auth_unix.h 294K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/clnt.h 295K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/netdb.h 296K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/pmap_clnt.h 297K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/pmap_prot.h 298K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/pmap_rmt.h 299K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/rpc_msg.h 300K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/rpc.h 301K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/svc_auth.h 302K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/svc.h 303K5GSSRPCINC+= ${SRCTOP}/krb5/include/gssrpc/types.h 304K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/xdr.h 305K5GSSRPCINC+= ${SRCTOP}/crypto/krb5/src/include/gssrpc/xdr.h 306GSSAPIINC+= ${SRCTOP}/crypto/krb5/src/lib/gssapi/krb5/gssapi_krb5.h 307GSSAPIINC+= ${SRCTOP}/crypto/krb5/src/lib/gssapi/generic/gssapi_alloc.h 308GSSAPIINC+= ${SRCTOP}/crypto/krb5/src/lib/gssapi/generic/gssapi_generic.h 309GSSAPIINC+= ${SRCTOP}/crypto/krb5/src/lib/gssapi/generic/gssapi_ext.h 310K5GSSAPIINC+= ${SRCTOP}/crypto/krb5/src/include/gssapi.h 311KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/ccselect_plugin.h 312KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/certauth_plugin.h 313KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/clpreauth_plugin.h 314KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/hostrealm_plugin.h 315KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/kadm5_auth_plugin.h 316KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/kadm5_hook_plugin.h 317KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/kdcpolicy_plugin.h 318KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/kdcpreauth_plugin.h 319KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/localauth_plugin.h 320KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/locate_plugin.h 321KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/plugin.h 322KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/preauth_plugin.h 323KRB5INC+= ${SRCTOP}/crypto/krb5/src/include/krb5/pwqual_plugin.h 324INCS+= ${SRCTOP}/crypto/krb5/src/include/gssapi.h 325INCS+= ${SRCTOP}/crypto/krb5/src/include/kdb.h 326INCS+= ${SRCTOP}/crypto/krb5/src/include/krb5.h 327INCS+= ${SRCTOP}/crypto/krb5/src/include/krad.h 328INCS+= ${SRCTOP}/crypto/krb5/src/util/et/com_err.h 329INCS+= ${SRCTOP}/crypto/krb5/src/util/verto/verto-module.h 330INCS+= ${SRCTOP}/crypto/krb5/src/util/verto/verto.h 331.endif 332 333.if empty(SRCS) 334SRCS= dummy.c 335.endif 336 337.if defined(CROSS_BUILD_TESTING) 338SUBDIR= cross-build 339.endif 340 341# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: 342UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h 343UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h 344FFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h 345 346MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h 347MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h 348MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h 349MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h 350MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h 351MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h 352DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h 353 354# Needed to build config (since it uses libnv) 355SYSINCS+= ${SRCTOP}/sys/sys/_nv.h 356SYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ 357 ${SRCTOP}/sys/sys/dnv.h ${SRCTOP}/sys/sys/nv_namespace.h 358 359# Needed when bootstrapping ldd (since it uses DF_1_PIE) 360SYSINCS+= ${SRCTOP}/sys/sys/elf32.h 361SYSINCS+= ${SRCTOP}/sys/sys/elf64.h 362SYSINCS+= ${SRCTOP}/sys/sys/elf_common.h 363SYSINCS+= ${SRCTOP}/sys/sys/elf_generic.h 364SYSINCS+= ${SRCTOP}/sys/sys/queue.h 365SYSINCS+= ${SRCTOP}/sys/sys/md5.h 366SYSINCS+= ${SRCTOP}/sys/sys/sbuf.h 367SYSINCS+= ${SRCTOP}/sys/sys/tree.h 368 369# vtfontcvt is using sys/font.h 370SYSINCS+= ${SRCTOP}/sys/sys/font.h 371# For mkscrfil.c: 372SYSINCS+= ${SRCTOP}/sys/sys/consio.h 373# for gencat: 374INCS+= ${SRCTOP}/include/nl_types.h 375# for vtfontcvt: 376SYSINCS+= ${SRCTOP}/sys/sys/fnv_hash.h 377# opensolaris compatibility 378INCS+= ${SRCTOP}/include/elf.h 379SYSINCS+= ${SRCTOP}/sys/sys/elf.h 380SYSINCS+= ${SRCTOP}/sys/sys/ctf.h 381# for kbdcontrol: 382SYSINCS+= ${SRCTOP}/sys/sys/kbio.h 383# for kldxref: 384SYSINCS+= ${SRCTOP}/sys/sys/module.h 385.if ${.MAKE.OS} != "FreeBSD" 386# for libmd: 387SYSINCS+= ${SRCTOP}/sys/sys/md4.h 388.endif 389 390# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't 391# accidentally run tools that are incompatible but happen to be in $PATH. 392# This is especially important when building on Linux/MacOS where many of the 393# programs used during the build accept different flags or generate different 394# output. On those platforms we only symlink the tools known to be compatible 395# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others 396# from the FreeBSD sources during the bootstrap-tools stage. 397 398# basic commands: It is fine to use the host version for all of these even on 399# Linux/MacOS since we only use flags that are supported by all of them. 400_host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \ 401 dirname echo env false find fmt gzip gunzip head hostname id ln ls \ 402 mkdir mv nice patch rm sh sleep stat tee time touch tr true uname uniq \ 403 unxz wc which xz 404 405# We also need a symlink to the absolute path to the make binary used for 406# the toplevel makefile. This is not necessarily the same as `which make` 407# since e.g. on Linux and MacOS that will be GNU make. 408_make_abs!= which "${MAKE}" 409_host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake 410 411_LINK_HOST_TOOL= ln -sfn 412 413.if ${.MAKE.OS} == "FreeBSD" 414# When building on FreeBSD we always copy the host tools instead of linking 415# into WORLDTMP to avoid issues with incompatible libraries (see r364030). 416# Note: we could create links if we don't intend to update the current machine. 417_COPY_HOST_TOOL= cp -pf 418.else 419# However, this is not necessary on Linux/macOS. Additionally, copying the host 420# tools to another directory with cp -p results in freezes on macOS Big Sur for 421# some unknown reason. It can also break building inside docker containers if 422# there are ACLs on shared volumes. 423_COPY_HOST_TOOL= ${_LINK_HOST_TOOL} 424 425.if ${.MAKE.OS} == "Darwin" 426# /usr/bin/cpp may invoke xcrun: 427_host_tools_to_symlink+= xcrun 428.endif # ${.MAKE.OS} == "Darwin" 429 430# On Ubuntu /bin/sh is dash which is totally useless, and the same for modern 431# macOS. Let's just link bash as the build sh since that will work fine. 432_host_abs_tools_to_symlink+= /bin/bash:sh 433_host_tools_to_symlink:= ${_host_tools_to_symlink:Nsh} 434.endif 435 436# We also need to symlink any non-absolute toolchain commands. Clang finds its 437# resource directory relative to itself, so CC/CXX/CPP cannot be copied, and 438# there should be no concerns about installing over the current system since we 439# don't use the toolchain during install, so that's not an issue. However, 440# before Clang 13 there was no symlink detection for FreeBSD so that was broken 441# in the same way as copying (https://reviews.llvm.org/D103346), thus create a 442# wrapper script for each to work around this and behave like a symlink. 443# Remove this hack and just use a symlink once Clang 13 can be assumed. 444# For consistency, we use the same strategy for LD. 445.include <bsd.compiler.mk> 446.if ${.MAKE.OS} == "FreeBSD" && ${COMPILER_TYPE} == "clang" && \ 447 ${COMPILER_VERSION} < 130000 448_WRAP_HOST_TOOL= sh -c "printf '\#!/bin/sh\nexec \"\%s\" \"\$$@\"\n' \"\$$0\" > \"\$$1\" && chmod +x \"\$$1\"" 449.else 450_WRAP_HOST_TOOL= ${_LINK_HOST_TOOL} 451.endif 452.for var in CC CXX CPP LD 453.for X in $${_empty_var_} X 454.if !empty(${X}${var}) && !${${X}${var}:[1]:M/*} && \ 455 !${_toolchain_tools_to_symlink:U:M${${X}${var}:[1]}} 456_toolchain_tools_to_symlink+= ${${X}${var}:[1]} 457.endif 458.endfor 459.endfor 460 461host-symlinks: 462 @echo "Linking host tools into ${DESTDIR}/bin" 463.for _tool in ${_host_tools_to_symlink} 464 @export PATH=$${PATH}:/usr/local/bin; \ 465 source_path=`which ${_tool} || echo /dev/null/no/such`; \ 466 if [ ! -e "$${source_path}" ] ; then \ 467 echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \ 468 fi; \ 469 rm -f "${DESTDIR}/bin/${_tool}"; \ 470 ${_COPY_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}" 471.endfor 472.for _tool in ${_host_abs_tools_to_symlink} 473 @source_path="${_tool:S/:/ /:[1]}"; \ 474 target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \ 475 if [ ! -e "$${source_path}" ] ; then \ 476 echo "Host tool '$${source_path}' is missing"; false; \ 477 fi; \ 478 rm -f "$${target_path}"; \ 479 ${_COPY_HOST_TOOL} "$${source_path}" "$${target_path}" 480.endfor 481.if exists(/usr/libexec/flua) 482 rm -f ${DESTDIR}/usr/libexec/flua 483 ${_COPY_HOST_TOOL} /usr/libexec/flua ${DESTDIR}/usr/libexec/flua 484.endif 485.for _tool in ${_toolchain_tools_to_symlink} 486 @export PATH=$${PATH}:/usr/local/bin; \ 487 source_path=`which ${_tool} || echo /dev/null/no/such`; \ 488 if [ ! -e "$${source_path}" ] ; then \ 489 echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \ 490 fi; \ 491 rm -f "${DESTDIR}/bin/${_tool}"; \ 492 ${_WRAP_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}" 493.endfor 494 495# Create all the directories that are needed during the legacy, bootstrap-tools 496# and cross-tools stages. We do this here using mkdir since mtree may not exist 497# yet (this happens if we are crossbuilding from Linux/Mac). 498INSTALLDIR_LIST= \ 499 bin \ 500 lib/geom \ 501 usr/include/casper \ 502 usr/include/openssl \ 503 usr/include/private/ucl \ 504 usr/include/private/yaml \ 505 usr/include/private/zstd \ 506 usr/lib \ 507 usr/libdata/pkgconfig \ 508 usr/libexec 509 510installdirs: 511 mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,} 512 513# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a 514# bootstrap tool was added to WORLTMP with a symlink or by building it in the 515# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap 516# tools but adding the symlinks is easier and means all tools are also 517# in the directory that they are installed to normally. 518 519.for _dir in sbin usr/sbin usr/bin 520# delete existing directories from before r340157 521 @if [ -e ${DESTDIR}/${_dir} ] && [ ! -L ${DESTDIR}/${_dir} ]; then \ 522 echo "removing old non-symlink ${DESTDIR}/${_dir}"; \ 523 rm -rf "${DESTDIR}/${_dir}"; \ 524 fi 525.endfor 526 ln -sfn bin ${DESTDIR}/sbin 527 ln -sfn ../bin ${DESTDIR}/usr/bin 528 ln -sfn ../bin ${DESTDIR}/usr/sbin 529.for _group in ${INCSGROUPS:NINCS} 530 mkdir -p "${DESTDIR}/${${_group}DIR}" 531.endfor 532 533.include <bsd.lib.mk> 534