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