130aaff11SWarner Losh 230aaff11SWarner Losh.PATH: ${.CURDIR}/../../include 330aaff11SWarner Losh 41c62f923SWarner LoshLIB= egacy 5c2774610SDavid E. O'BrienSRC= 6162ae9c8SAlex RichardsonINCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS 77ec1ec4fSAlex RichardsonINCSGROUPS+= MACHINESYSINCS RPCINCS 830aaff11SWarner LoshINCS= 930aaff11SWarner Losh 10d80f1dd1SJilles TjoelkerSYSINCSDIR= ${INCLUDEDIR}/sys 11d5f4dd1bSMariusz ZaborskiCASPERINCDIR= ${INCLUDEDIR}/casper 12162ae9c8SAlex Richardson# Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool 13162ae9c8SAlex RichardsonUFSINCSDIR= ${INCLUDEDIR}/ufs/ufs 14162ae9c8SAlex RichardsonFFSINCSDIR= ${INCLUDEDIR}/ufs/ffs 15162ae9c8SAlex RichardsonMSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs 16162ae9c8SAlex RichardsonDISKINCSDIR= ${INCLUDEDIR}/sys/disk 177ec1ec4fSAlex RichardsonMACHINESYSINCSDIR= ${INCLUDEDIR}/machine 187ec1ec4fSAlex RichardsonRPCINCSDIR= ${INCLUDEDIR}/rpc 19d80f1dd1SJilles Tjoelker 2030aaff11SWarner LoshBOOTSTRAPPING?= 0 2130aaff11SWarner Losh 227ec1ec4fSAlex Richardson 237ec1ec4fSAlex Richardson.if ${.MAKE.OS} == "Darwin" 247ec1ec4fSAlex Richardson_XCODE_ROOT!=xcode-select -p 257ec1ec4fSAlex Richardson# since macOS 10.14 C headers are no longer installed in /usr but only 267ec1ec4fSAlex Richardson# provided via the SDK 277ec1ec4fSAlex Richardson.if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools" 287ec1ec4fSAlex Richardson# Only command line tools installed -> host headers are in the SDKs directory 297ec1ec4fSAlex Richardson_MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/ 307ec1ec4fSAlex Richardson.else 317ec1ec4fSAlex Richardson# Full XCode installed -> host headers are below Platforms/MacOSX.platform 327ec1ec4fSAlex Richardson_MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk 337ec1ec4fSAlex Richardson.endif 347ec1ec4fSAlex RichardsonHOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include 357ec1ec4fSAlex Richardson.if !exists(${HOST_INCLUDE_ROOT}/stdio.h) 366f6fbfa3SEd Maste.error You must install the macOS SDK (try xcode-select --install) 377ec1ec4fSAlex Richardson.endif 387ec1ec4fSAlex Richardson.else 397ec1ec4fSAlex RichardsonHOST_INCLUDE_ROOT=/usr/include 407ec1ec4fSAlex Richardson.endif 417ec1ec4fSAlex Richardson 427ec1ec4fSAlex Richardson# Allow building libc-internal files (also on non-FreeBSD hosts) 437ec1ec4fSAlex RichardsonCFLAGS+= -I${.CURDIR}/libc-bootstrap 447ec1ec4fSAlex Richardson# Symbol versioning is not required for -legacy (and macOS bootstrap) 457ec1ec4fSAlex RichardsonMK_SYMVER= no 467ec1ec4fSAlex Richardson 477ec1ec4fSAlex Richardson_WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true 4879626055SBrooks Davis.if ${_WITH_PWCACHEDB} == 0 4979626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-pwcache 507ec1ec4fSAlex RichardsonCFLAGS.pwcache.c+= -I${.CURDIR}/../../contrib/libc-pwcache 5179626055SBrooks DavisSRCS+= pwcache.c 5279626055SBrooks Davis.endif 5379626055SBrooks Davis 547ec1ec4fSAlex Richardson_WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true 5579626055SBrooks Davis.if ${_WITH_STRSVIS} == 0 5679626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-vis 577ec1ec4fSAlex RichardsonINCS+= vis.h 587ec1ec4fSAlex RichardsonSRCS+= vis.c unvis.c 59a5252831SAlex RichardsonCFLAGS.vis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 60a5252831SAlex RichardsonCFLAGS.unvis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 6179626055SBrooks Davis.endif 6279626055SBrooks Davis 637ec1ec4fSAlex Richardson_WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true 648e7e3163SDimitry Andric.if ${_WITH_REALLOCARRAY} == 0 658e7e3163SDimitry Andric.PATH: ${.CURDIR}/../../lib/libc/stdlib 668e7e3163SDimitry AndricINCS+= stdlib.h 678e7e3163SDimitry AndricSRCS+= reallocarray.c 688e7e3163SDimitry Andric.endif 698e7e3163SDimitry Andric 70c5e54e56SEd Maste.if exists(${HOST_INCLUDE_ROOT}/sys/stat.h) 717ec1ec4fSAlex Richardson_WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true 72c5e54e56SEd Maste.else 73c5e54e56SEd Maste_WITH_UTIMENS= 0 74c5e54e56SEd Maste.endif 75d80f1dd1SJilles Tjoelker.if ${_WITH_UTIMENS} == 0 76d80f1dd1SJilles TjoelkerSYSINCS+= stat.h 77d80f1dd1SJilles TjoelkerSRCS+= futimens.c utimensat.c 78d80f1dd1SJilles Tjoelker.endif 79d80f1dd1SJilles Tjoelker 80ac6b2b43SJohn Baldwin_WITH_EXPLICIT_BZERO!= cat ${HOST_INCLUDE_ROOT}/strings.h ${HOST_INCLUDE_ROOT}/string.h | grep -c explicit_bzero || true 818d14ced6SAlex Richardson.if ${_WITH_EXPLICIT_BZERO} == 0 827ec1ec4fSAlex Richardson# .PATH: ${SRCTOP}/sys/libkern 837ec1ec4fSAlex Richardson# Adding sys/libkern to .PATH breaks building the cross-build compat library 847ec1ec4fSAlex Richardson# since that attempts to build strlcpy.c from libc and adding libkern here will 857ec1ec4fSAlex Richardson# cause it to pick the file from libkern instead (which won't compile). 867ec1ec4fSAlex Richardson# Avoid modifying .PATH by creating a copy in the build directory instead. 877ec1ec4fSAlex Richardsonexplicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c 887ec1ec4fSAlex Richardson cp ${.ALLSRC} ${.TARGET} 897ec1ec4fSAlex RichardsonCLEANFILES+= explicit_bzero.c 908d14ced6SAlex RichardsonINCS+= strings.h 918d14ced6SAlex RichardsonSRCS+= explicit_bzero.c 928d14ced6SAlex Richardson.endif 938d14ced6SAlex Richardson 945425ba83SKa Ho Ng_WITH_FSPACECTL!= grep -c fspacectl ${HOST_INCLUDE_ROOT}/fcntl.h || true 955425ba83SKa Ho Ng.if ${_WITH_FSPACECTL} == 0 965425ba83SKa Ho NgINCS+= fcntl.h 975425ba83SKa Ho NgSRCS+= fspacectl.c 985425ba83SKa Ho Ng.endif 997ec1ec4fSAlex Richardson 1007ec1ec4fSAlex Richardson.if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h) 1017ec1ec4fSAlex Richardson_WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 1027ec1ec4fSAlex Richardson_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 1033b7e9bfeSAlex Richardson.endif 104fbe12f20SMark Johnston.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0 1053b7e9bfeSAlex Richardson.PATH: ${SRCTOP}/lib/libcapsicum 1063b7e9bfeSAlex RichardsonINCS+= capsicum_helpers.h 1073b7e9bfeSAlex Richardson.PATH: ${SRCTOP}/lib/libcasper/libcasper 1083b7e9bfeSAlex RichardsonINCS+= libcasper.h 1093b7e9bfeSAlex Richardson.endif 1103b7e9bfeSAlex Richardson 1117ec1ec4fSAlex Richardson# rpcgen should build against the source tree rpc/types.h and not the host. 1127ec1ec4fSAlex Richardson# This is especially important on non-FreeBSD systems where the types may 1137ec1ec4fSAlex Richardson# not match. 1147ec1ec4fSAlex RichardsonRPCINCS+= ${SRCTOP}/sys/rpc/types.h 1157ec1ec4fSAlex Richardson 1167ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/mpool.h 1177ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/ndbm.h 1187ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/err.h 1197ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/stringlist.h 1207ec1ec4fSAlex Richardson 1217ec1ec4fSAlex Richardson# Needed to build arc4random.c 1227ec1ec4fSAlex RichardsonINCSGROUPS+= CHACHA20INCS 1237ec1ec4fSAlex RichardsonCHACHA20INCSDIR= ${INCLUDEDIR}/crypto/chacha20 1247ec1ec4fSAlex RichardsonCHACHA20INCS+= ${SRCTOP}/sys/crypto/chacha20/_chacha.h \ 1257ec1ec4fSAlex Richardson ${SRCTOP}/sys/crypto/chacha20/chacha.h 1267ec1ec4fSAlex Richardson 127db98bc2cSSimon J. Gerraty.if ${MACHINE} == "host" 128db98bc2cSSimon J. Gerraty_host_arch= ${_HOST_ARCH} 129f9df6097SSimon J. Gerraty.elif ${MACHINE} == "host32" 130f9df6097SSimon J. Gerraty_host_arch= ${_HOST_ARCH32} 131db98bc2cSSimon J. Gerraty.else 1327ec1ec4fSAlex Richardson_host_arch=${MACHINE} 133db98bc2cSSimon J. Gerraty.endif 1347ec1ec4fSAlex Richardson.if ${_host_arch} == "x86_64" 1357ec1ec4fSAlex Richardson# bmake on Linux/mac often prints that instead of amd64 1367ec1ec4fSAlex Richardson_host_arch=amd64 1378c22b9f3SKyle Evans.elif ${_host_arch} == "aarch64" 1388c22b9f3SKyle Evans# Linux calls arm64, aarch64, across the board 1398c22b9f3SKyle Evans_host_arch=arm64 1407b81e6c7SJustin Hibbits.elif ${_host_arch:Mppc*} 1417b81e6c7SJustin Hibbits_host_arch=powerpc 1427ec1ec4fSAlex Richardson.endif 1437ec1ec4fSAlex Richardson.if ${_host_arch} == "unknown" 1447ec1ec4fSAlex Richardson# HACK: If MACHINE is unknown, assume we are building on x86 1457ec1ec4fSAlex Richardson_host_arch=amd64 1467ec1ec4fSAlex Richardson.endif 1477ec1ec4fSAlex RichardsonMACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/elf.h 1487ec1ec4fSAlex Richardson.if ${_host_arch} == "amd64" || ${_host_arch} == "i386" 1497ec1ec4fSAlex RichardsonINCSGROUPS+= X86INCS 1507ec1ec4fSAlex RichardsonX86INCSDIR= ${INCLUDEDIR}/x86 1517ec1ec4fSAlex RichardsonX86INCS+= ${SRCTOP}/sys/x86/include/elf.h 1527ec1ec4fSAlex Richardson.endif 1537ec1ec4fSAlex Richardson 1547ec1ec4fSAlex Richardson# needed for btxld: 1557ec1ec4fSAlex RichardsonMACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/exec.h 1567ec1ec4fSAlex RichardsonMACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/reloc.h 1577ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/a.out.h 1587ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/nlist.h 1597ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/imgact_aout.h 1607ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/nlist_aout.h 1617ec1ec4fSAlex Richardson 1623b073d2eSBrooks Davis# macOS's bitstring lacks FreeBSD-specific additions used by makefs's ZFS code 1633b073d2eSBrooks Davis# and Linux doesn't have it at all. Older FreeBSD versions lack recent 1643b073d2eSBrooks Davis# additions. 1653b073d2eSBrooks DavisINCS+= ${SRCTOP}/include/bitstring.h 1663b073d2eSBrooks DavisSYSINCS+= ${SRCTOP}/sys/sys/bitstring.h 167ed845580SAlex Richardson 168ed845580SAlex Richardson.if ${.MAKE.OS} != "FreeBSD" 169ed845580SAlex Richardson.PATH: ${.CURDIR}/cross-build 170e9ba1fd5SJessica Clarke 171e9ba1fd5SJessica Clarke# Needed by our sys/types.h wrapper 172e9ba1fd5SJessica ClarkeSYSINCS+= ${SRCTOP}/sys/sys/bitcount.h 173e9ba1fd5SJessica Clarke 1747ec1ec4fSAlex Richardson# dbopen() behaves differently on Linux and FreeBSD so we ensure that we 1757ec1ec4fSAlex Richardson# bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to 1767ec1ec4fSAlex Richardson# __freebsd_dbopen() so that we don't ever use the host version 1777ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/db.h 1787ec1ec4fSAlex RichardsonLIBC_SRCTOP= ${SRCTOP}/lib/libc/ 1797ec1ec4fSAlex Richardson.include "${LIBC_SRCTOP}/db/Makefile.inc" 1807ec1ec4fSAlex Richardson# Do the same as we did for dbopen() for getopt() on since it's not compatible 1817ec1ec4fSAlex Richardson# on Linux (and to avoid surprises also compile the FreeBSD code on macOS) 1827ec1ec4fSAlex Richardson.PATH: ${LIBC_SRCTOP}/stdlib 1837ec1ec4fSAlex RichardsonSRCS+= getopt.c getopt_long.c 1847ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/getopt.h 1857ec1ec4fSAlex Richardson 1867ec1ec4fSAlex Richardson# getcap.c is needed for cap_mkdb: 1877ec1ec4fSAlex Richardson.PATH: ${LIBC_SRCTOP}/gen 1887ec1ec4fSAlex RichardsonSRCS+= getcap.c 189962a3814SAlex Richardson# Glibc does not provide all err*/warn* functions, and for macOS we need the 190962a3814SAlex Richardson# alias with the extra underscore. 191962a3814SAlex RichardsonSRCS+= err.c 1927ec1ec4fSAlex Richardson# Add various libbc functions that are not available in glibc: 1937ec1ec4fSAlex RichardsonSRCS+= stringlist.c setmode.c 1947ec1ec4fSAlex RichardsonSRCS+= strtonum.c merge.c heapsort.c reallocf.c 1957ec1ec4fSAlex Richardson.PATH: ${LIBC_SRCTOP}/locale 1967ec1ec4fSAlex RichardsonSRCS+= rpmatch.c 1977ec1ec4fSAlex Richardson 1987ec1ec4fSAlex Richardson.if ${.MAKE.OS} == "Linux" 199ceefd491SAndrew Turner# On Linux, glibc does not provide strmode. It only provides strlcpy 200ceefd491SAndrew Turner# and strlcat from glibc 2.38. 2017ec1ec4fSAlex Richardson.PATH: ${LIBC_SRCTOP}/string 202ceefd491SAndrew TurnerSRCS+= strmode.c 203ceefd491SAndrew Turner# Assume if strlcpy exists so does strlcat 204ceefd491SAndrew Turner_WITH_EXPLICIT_STRLCPY!= cat ${HOST_INCLUDE_ROOT}/strings.h ${HOST_INCLUDE_ROOT}/string.h | grep -c strlcpy || true 205ceefd491SAndrew Turner.if ${_WITH_EXPLICIT_STRLCPY} == 0 206ceefd491SAndrew TurnerSRCS+= strlcpy.c strlcat.c 207ceefd491SAndrew Turner.endif 208548f8a65SJessica Clarke# On Linux, glibc provides ffs* but not fls* 209548f8a65SJessica ClarkeSRCS+= fls.c flsl.c flsll.c 2107ec1ec4fSAlex Richardson# Compile the fgetln/fgetwln/closefrom fallback code from libbsd: 2117ec1ec4fSAlex RichardsonSRCS+= fgetln_fallback.c fgetwln_fallback.c closefrom.c 2127ec1ec4fSAlex RichardsonCFLAGS.closefrom.c+= -DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \ 2137ec1ec4fSAlex Richardson -DHAVE_DIRFD -DHAVE_SYSCONF 214962a3814SAlex Richardson# Provide getprogname/setprograme 215962a3814SAlex RichardsonSRCS+= progname.c 2164e64fb9fSAlex Richardson# Stub implementations of fflagstostr/strtofflags 2174e64fb9fSAlex RichardsonSRCS+= fflags.c 218976ba7f0SSimon J. Gerraty 219881ec813SJessica Clarke# macOS has a standalone cross-build implementation, but Linux can use the same 220881ec813SJessica Clarke# ELF one as FreeBSD 221881ec813SJessica ClarkeSYSINCS+= ${SRCTOP}/sys/sys/linker_set.h 222881ec813SJessica Clarke 2230ec03c0bSMark Johnston.endif # ${MAKE.OS} == "Linux" 2240ec03c0bSMark Johnston 2250ec03c0bSMark Johnston.if ${.MAKE.OS} == "Darwin" 2260ec03c0bSMark Johnston# Standalone implementation of secure_getenv(), not available on MacOS. 2270ec03c0bSMark JohnstonSRCS+= secure_getenv.c 2280ec03c0bSMark Johnston.endif # ${MAKE.OS} == "Darwin" 2290ec03c0bSMark Johnston 2307ec1ec4fSAlex Richardson# Provide the same arc4random implementation on Linux/macOS 2317ec1ec4fSAlex RichardsonCFLAGS.arc4random.c+= -I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1 2327ec1ec4fSAlex RichardsonSRCS+= arc4random.c arc4random_uniform.c 2337ec1ec4fSAlex Richardson 2347ec1ec4fSAlex Richardson# expand_number() is not provided by either Linux or MacOS libutil 2357ec1ec4fSAlex Richardson.PATH: ${SRCTOP}/lib/libutil 2367ec1ec4fSAlex RichardsonSRCS+= expand_number.c 2377ec1ec4fSAlex Richardson# Linux libutil also doesn't have fparseln 2387ec1ec4fSAlex RichardsonSRCS+= fparseln.c 2397ec1ec4fSAlex Richardson# A dummy sysctl for tzsetup: 2407ec1ec4fSAlex RichardsonSRCS+= fake_sysctl.c 2417ec1ec4fSAlex Richardson 2427ec1ec4fSAlex Richardson# capsicum support 2437ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/capsicum.h 2447ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/caprights.h 2457ec1ec4fSAlex RichardsonSRCS+= capsicum_stubs.c 2467ec1ec4fSAlex Richardson# XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes 2477ec1ec4fSAlex Richardson# conflicts with other files. Instead copy subr_capability to the build dir. 2487ec1ec4fSAlex Richardsonsubr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c 2497ec1ec4fSAlex Richardson cp ${.ALLSRC} ${.TARGET} 2507ec1ec4fSAlex RichardsonSRCS+= subr_capability.c 2517ec1ec4fSAlex RichardsonCLEANFILES+= subr_capability.c 2520ec03c0bSMark Johnston.endif # ${MAKE.OS} != "FreeBSD" 2537ec1ec4fSAlex Richardson 254d5f4dd1bSMariusz ZaborskiCASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h 255aefe30c5SMariusz ZaborskiCASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_net/cap_net.h 256d5f4dd1bSMariusz Zaborski 25730aaff11SWarner Losh.if empty(SRCS) 25830aaff11SWarner LoshSRCS= dummy.c 25930aaff11SWarner Losh.endif 26030aaff11SWarner Losh 261f09a3cc4SRuslan Ermilov.if defined(CROSS_BUILD_TESTING) 262f09a3cc4SRuslan ErmilovSUBDIR= cross-build 263f09a3cc4SRuslan Ermilov.endif 264f09a3cc4SRuslan Ermilov 265162ae9c8SAlex Richardson# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: 266162ae9c8SAlex RichardsonUFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h 267162ae9c8SAlex RichardsonUFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h 268162ae9c8SAlex RichardsonFFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h 269162ae9c8SAlex Richardson 270162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h 271162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h 272162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h 273162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h 274162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h 275162ae9c8SAlex RichardsonMSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h 276162ae9c8SAlex RichardsonDISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h 277162ae9c8SAlex Richardson 27863889bbdSAlex Richardson# Needed to build config (since it uses libnv) 279c36f4276SMarius StroblSYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ 280000321baSReid Linnemann ${SRCTOP}/sys/sys/dnv.h ${SRCTOP}/sys/sys/nv_namespace.h 28163889bbdSAlex Richardson 282313232ddSAlex Richardson# Needed when bootstrapping ldd (since it uses DF_1_PIE) 283313232ddSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/elf32.h 284313232ddSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/elf64.h 285313232ddSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/elf_common.h 286313232ddSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/elf_generic.h 2877ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/queue.h 2887ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/md5.h 2897ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/sbuf.h 2907ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/tree.h 291313232ddSAlex Richardson 292e7fd9688SToomas Soome# vtfontcvt is using sys/font.h 293e7fd9688SToomas SoomeSYSINCS+= ${SRCTOP}/sys/sys/font.h 2947ec1ec4fSAlex Richardson# For mkscrfil.c: 2957ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/consio.h 2967ec1ec4fSAlex Richardson# for gencat: 2977ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/nl_types.h 2987ec1ec4fSAlex Richardson# for vtfontcvt: 2997ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/fnv_hash.h 3007ec1ec4fSAlex Richardson# opensolaris compatibility 3017ec1ec4fSAlex RichardsonINCS+= ${SRCTOP}/include/elf.h 3027ec1ec4fSAlex RichardsonSYSINCS+= ${SRCTOP}/sys/sys/elf.h 3032d5d2a98SMark JohnstonSYSINCS+= ${SRCTOP}/sys/sys/ctf.h 304968a3db7SJessica Clarke# for kbdcontrol: 305968a3db7SJessica ClarkeSYSINCS+= ${SRCTOP}/sys/sys/kbio.h 306ff7c12c1SJessica Clarke# for kldxref: 307ff7c12c1SJessica ClarkeSYSINCS+= ${SRCTOP}/sys/sys/module.h 308e7fd9688SToomas Soome 3098f62bca4SAlex Richardson# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't 3108f62bca4SAlex Richardson# accidentally run tools that are incompatible but happen to be in $PATH. 3118f62bca4SAlex Richardson# This is especially important when building on Linux/MacOS where many of the 3128f62bca4SAlex Richardson# programs used during the build accept different flags or generate different 3138f62bca4SAlex Richardson# output. On those platforms we only symlink the tools known to be compatible 3148f62bca4SAlex Richardson# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others 3158f62bca4SAlex Richardson# from the FreeBSD sources during the bootstrap-tools stage. 3168f62bca4SAlex Richardson 3178f62bca4SAlex Richardson# basic commands: It is fine to use the host version for all of these even on 3188f62bca4SAlex Richardson# Linux/MacOS since we only use flags that are supported by all of them. 319ea6c594cSAlex Richardson_host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \ 3208f62bca4SAlex Richardson dirname echo env false find fmt gzip gunzip head hostname id ln ls \ 3215c9cb96aSAlex Richardson mkdir mv nice patch rm sh sleep stat tee time touch tr true uname uniq \ 3225c9cb96aSAlex Richardson unxz wc which xz 3238f62bca4SAlex Richardson 3248f62bca4SAlex Richardson# We also need a symlink to the absolute path to the make binary used for 3258f62bca4SAlex Richardson# the toplevel makefile. This is not necessarily the same as `which make` 3268f62bca4SAlex Richardson# since e.g. on Linux and MacOS that will be GNU make. 3278f62bca4SAlex Richardson_make_abs!= which "${MAKE}" 3288f62bca4SAlex Richardson_host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake 3298f62bca4SAlex Richardson 33065f28f63SJessica Clarke_LINK_HOST_TOOL= ln -sfn 33165f28f63SJessica Clarke 332a8b20f4fSAlexander Richardson.if ${.MAKE.OS} == "FreeBSD" 333a8b20f4fSAlexander Richardson# When building on FreeBSD we always copy the host tools instead of linking 334a8b20f4fSAlexander Richardson# into WORLDTMP to avoid issues with incompatible libraries (see r364030). 335a8b20f4fSAlexander Richardson# Note: we could create links if we don't intend to update the current machine. 336a8b20f4fSAlexander Richardson_COPY_HOST_TOOL= cp -pf 337a8b20f4fSAlexander Richardson.else 338a8b20f4fSAlexander Richardson# However, this is not necessary on Linux/macOS. Additionally, copying the host 339a8b20f4fSAlexander Richardson# tools to another directory with cp -p results in freezes on macOS Big Sur for 340a8b20f4fSAlexander Richardson# some unknown reason. It can also break building inside docker containers if 341a8b20f4fSAlexander Richardson# there are ACLs on shared volumes. 34265f28f63SJessica Clarke_COPY_HOST_TOOL= ${_LINK_HOST_TOOL} 343dd3ad7c2SJessica Clarke 3447ec1ec4fSAlex Richardson.if ${.MAKE.OS} == "Darwin" 3457ec1ec4fSAlex Richardson# /usr/bin/cpp may invoke xcrun: 3467ec1ec4fSAlex Richardson_host_tools_to_symlink+= xcrun 3477ec1ec4fSAlex Richardson.endif # ${.MAKE.OS} == "Darwin" 348dd3ad7c2SJessica Clarke 349dd3ad7c2SJessica Clarke# On Ubuntu /bin/sh is dash which is totally useless, and the same for modern 350dd3ad7c2SJessica Clarke# macOS. Let's just link bash as the build sh since that will work fine. 3517ec1ec4fSAlex Richardson_host_abs_tools_to_symlink+= /bin/bash:sh 3527ec1ec4fSAlex Richardson_host_tools_to_symlink:= ${_host_tools_to_symlink:Nsh} 3537ec1ec4fSAlex Richardson.endif 3547ec1ec4fSAlex Richardson 35565f28f63SJessica Clarke# We also need to symlink any non-absolute toolchain commands. Clang finds its 35601718a2eSJessica Clarke# resource directory relative to itself, so CC/CXX/CPP cannot be copied, and 35701718a2eSJessica Clarke# there should be no concerns about installing over the current system since we 35801718a2eSJessica Clarke# don't use the toolchain during install, so that's not an issue. However, 35901718a2eSJessica Clarke# before Clang 13 there was no symlink detection for FreeBSD so that was broken 36001718a2eSJessica Clarke# in the same way as copying (https://reviews.llvm.org/D103346), thus create a 36101718a2eSJessica Clarke# wrapper script for each to work around this and behave like a symlink. 36201718a2eSJessica Clarke# Remove this hack and just use a symlink once Clang 13 can be assumed. 36301718a2eSJessica Clarke# For consistency, we use the same strategy for LD. 36401718a2eSJessica Clarke.include <bsd.compiler.mk> 36501718a2eSJessica Clarke.if ${.MAKE.OS} == "FreeBSD" && ${COMPILER_TYPE} == "clang" && \ 36601718a2eSJessica Clarke ${COMPILER_VERSION} < 130000 36701718a2eSJessica Clarke_WRAP_HOST_TOOL= sh -c "printf '\#!/bin/sh\nexec \"\%s\" \"\$$@\"\n' \"\$$0\" > \"\$$1\" && chmod +x \"\$$1\"" 36801718a2eSJessica Clarke.else 36901718a2eSJessica Clarke_WRAP_HOST_TOOL= ${_LINK_HOST_TOOL} 37001718a2eSJessica Clarke.endif 37165f28f63SJessica Clarke.for var in CC CXX CPP LD 37265f28f63SJessica Clarke.for X in $${_empty_var_} X 373*5d1ecf0bSKyle Evans.if !empty(${X}${var}) && !${${X}${var}:[1]:M/*} && \ 374*5d1ecf0bSKyle Evans !${_toolchain_tools_to_symlink:U:M${${X}${var}:[1]}} 375*5d1ecf0bSKyle Evans_toolchain_tools_to_symlink+= ${${X}${var}:[1]} 37665f28f63SJessica Clarke.endif 37765f28f63SJessica Clarke.endfor 37865f28f63SJessica Clarke.endfor 37965f28f63SJessica Clarke 3808f62bca4SAlex Richardsonhost-symlinks: 3818f62bca4SAlex Richardson @echo "Linking host tools into ${DESTDIR}/bin" 3828f62bca4SAlex Richardson.for _tool in ${_host_tools_to_symlink} 3838c9e4550SJessica Clarke @export PATH=$${PATH}:/usr/local/bin; \ 3848c9e4550SJessica Clarke source_path=`which ${_tool} || echo /dev/null/no/such`; \ 3858f62bca4SAlex Richardson if [ ! -e "$${source_path}" ] ; then \ 3865bb9250eSAlex Richardson echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \ 3878f62bca4SAlex Richardson fi; \ 38833176cdcSWarner Losh rm -f "${DESTDIR}/bin/${_tool}"; \ 389a8b20f4fSAlexander Richardson ${_COPY_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}" 3908f62bca4SAlex Richardson.endfor 3918f62bca4SAlex Richardson.for _tool in ${_host_abs_tools_to_symlink} 3928f62bca4SAlex Richardson @source_path="${_tool:S/:/ /:[1]}"; \ 3938f62bca4SAlex Richardson target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \ 3948f62bca4SAlex Richardson if [ ! -e "$${source_path}" ] ; then \ 395ddf312e8SMark Johnston echo "Host tool '$${source_path}' is missing"; false; \ 3968f62bca4SAlex Richardson fi; \ 39733176cdcSWarner Losh rm -f "$${target_path}"; \ 398a8b20f4fSAlexander Richardson ${_COPY_HOST_TOOL} "$${source_path}" "$${target_path}" 3998f62bca4SAlex Richardson.endfor 4004f47920eSKyle Evans.if exists(/usr/libexec/flua) 40133176cdcSWarner Losh rm -f ${DESTDIR}/usr/libexec/flua 402a8b20f4fSAlexander Richardson ${_COPY_HOST_TOOL} /usr/libexec/flua ${DESTDIR}/usr/libexec/flua 4034f47920eSKyle Evans.endif 40465f28f63SJessica Clarke.for _tool in ${_toolchain_tools_to_symlink} 40565f28f63SJessica Clarke @export PATH=$${PATH}:/usr/local/bin; \ 40665f28f63SJessica Clarke source_path=`which ${_tool} || echo /dev/null/no/such`; \ 40765f28f63SJessica Clarke if [ ! -e "$${source_path}" ] ; then \ 40865f28f63SJessica Clarke echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \ 40965f28f63SJessica Clarke fi; \ 41065f28f63SJessica Clarke rm -f "${DESTDIR}/bin/${_tool}"; \ 41101718a2eSJessica Clarke ${_WRAP_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}" 41265f28f63SJessica Clarke.endfor 4134acc8a67SAlex Richardson 4144acc8a67SAlex Richardson# Create all the directories that are needed during the legacy, bootstrap-tools 4154acc8a67SAlex Richardson# and cross-tools stages. We do this here using mkdir since mtree may not exist 4164acc8a67SAlex Richardson# yet (this happens if we are crossbuilding from Linux/Mac). 41717adf17bSSimon J. GerratyINSTALLDIR_LIST= \ 41817adf17bSSimon J. Gerraty bin \ 41917adf17bSSimon J. Gerraty lib/geom \ 42017adf17bSSimon J. Gerraty usr/include/casper \ 42194a82666SRyan Moeller usr/include/private/ucl \ 42217adf17bSSimon J. Gerraty usr/include/private/zstd \ 42317adf17bSSimon J. Gerraty usr/lib \ 4247ba31d58SJessica Clarke usr/libdata/pkgconfig \ 425f22a5921SKyle Evans usr/libexec 42617adf17bSSimon J. Gerraty 4274acc8a67SAlex Richardsoninstalldirs: 42817adf17bSSimon J. Gerraty mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,} 42917adf17bSSimon J. Gerraty 4308f62bca4SAlex Richardson# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a 4318f62bca4SAlex Richardson# bootstrap tool was added to WORLTMP with a symlink or by building it in the 4328f62bca4SAlex Richardson# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap 4338f62bca4SAlex Richardson# tools but adding the symlinks is easier and means all tools are also 4348f62bca4SAlex Richardson# in the directory that they are installed to normally. 435b25c7179SAlex Richardson 436b25c7179SAlex Richardson.for _dir in sbin usr/sbin usr/bin 437b25c7179SAlex Richardson# delete existing directories from before r340157 4385bb9250eSAlex Richardson @if [ -e ${DESTDIR}/${_dir} ] && [ ! -L ${DESTDIR}/${_dir} ]; then \ 439b25c7179SAlex Richardson echo "removing old non-symlink ${DESTDIR}/${_dir}"; \ 440b25c7179SAlex Richardson rm -rf "${DESTDIR}/${_dir}"; \ 441b25c7179SAlex Richardson fi 442b25c7179SAlex Richardson.endfor 443b25c7179SAlex Richardson ln -sfn bin ${DESTDIR}/sbin 444b25c7179SAlex Richardson ln -sfn ../bin ${DESTDIR}/usr/bin 445b25c7179SAlex Richardson ln -sfn ../bin ${DESTDIR}/usr/sbin 4464acc8a67SAlex Richardson.for _group in ${INCSGROUPS:NINCS} 4474acc8a67SAlex Richardson mkdir -p "${DESTDIR}/${${_group}DIR}" 4484acc8a67SAlex Richardson.endfor 4494acc8a67SAlex Richardson 45030aaff11SWarner Losh.include <bsd.lib.mk> 451