1 2.PATH: ${.CURDIR}/../../include 3 4LIB= egacy 5SRC= 6INCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS 7INCSGROUPS+= MACHINESYSINCS RPCINCS 8INCS= 9 10SYSINCSDIR= ${INCLUDEDIR}/sys 11CASPERINCDIR= ${INCLUDEDIR}/casper 12# Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool 13UFSINCSDIR= ${INCLUDEDIR}/ufs/ufs 14FFSINCSDIR= ${INCLUDEDIR}/ufs/ffs 15MSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs 16DISKINCSDIR= ${INCLUDEDIR}/sys/disk 17MACHINESYSINCSDIR= ${INCLUDEDIR}/machine 18RPCINCSDIR= ${INCLUDEDIR}/rpc 19 20BOOTSTRAPPING?= 0 21 22 23.if ${.MAKE.OS} == "Darwin" 24_XCODE_ROOT!=xcode-select -p 25# since macOS 10.14 C headers are no longer installed in /usr but only 26# provided via the SDK 27.if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools" 28# Only command line tools installed -> host headers are in the SDKs directory 29_MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/ 30.else 31# Full XCode installed -> host headers are below Platforms/MacOSX.platform 32_MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk 33.endif 34HOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include 35.if !exists(${HOST_INCLUDE_ROOT}/stdio.h) 36.error "You must install the macOS SDK (try xcode-select --install)" 37.endif 38.else 39HOST_INCLUDE_ROOT=/usr/include 40.endif 41 42# Allow building libc-internal files (also on non-FreeBSD hosts) 43CFLAGS+= -I${.CURDIR}/libc-bootstrap 44# Symbol versioning is not required for -legacy (and macOS bootstrap) 45MK_SYMVER= no 46 47_WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true 48.if ${_WITH_PWCACHEDB} == 0 49.PATH: ${.CURDIR}/../../contrib/libc-pwcache 50CFLAGS.pwcache.c+= -I${.CURDIR}/../../contrib/libc-pwcache 51SRCS+= pwcache.c 52.endif 53 54_WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true 55.if ${_WITH_STRSVIS} == 0 56.PATH: ${.CURDIR}/../../contrib/libc-vis 57INCS+= vis.h 58SRCS+= vis.c unvis.c 59CFLAGS.vis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 60CFLAGS.unvis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 61.endif 62 63_WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true 64.if ${_WITH_REALLOCARRAY} == 0 65.PATH: ${.CURDIR}/../../lib/libc/stdlib 66INCS+= stdlib.h 67SRCS+= reallocarray.c 68.endif 69 70.if exists(${HOST_INCLUDE_ROOT}/sys/stat.h) 71_WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true 72.else 73_WITH_UTIMENS= 0 74.endif 75.if ${_WITH_UTIMENS} == 0 76SYSINCS+= stat.h 77SRCS+= futimens.c utimensat.c 78.endif 79 80_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero ${HOST_INCLUDE_ROOT}/strings.h || true 81.if ${_WITH_EXPLICIT_BZERO} == 0 82# .PATH: ${SRCTOP}/sys/libkern 83# Adding sys/libkern to .PATH breaks building the cross-build compat library 84# since that attempts to build strlcpy.c from libc and adding libkern here will 85# cause it to pick the file from libkern instead (which won't compile). 86# Avoid modifying .PATH by creating a copy in the build directory instead. 87explicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c 88 cp ${.ALLSRC} ${.TARGET} 89CLEANFILES+= explicit_bzero.c 90INCS+= strings.h 91SRCS+= explicit_bzero.c 92.endif 93 94 95.if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h) 96_WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 97_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true 98.endif 99.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0 100.PATH: ${SRCTOP}/lib/libcapsicum 101INCS+= capsicum_helpers.h 102.PATH: ${SRCTOP}/lib/libcasper/libcasper 103INCS+= libcasper.h 104.endif 105 106# rpcgen should build against the source tree rpc/types.h and not the host. 107# This is especially important on non-FreeBSD systems where the types may 108# not match. 109RPCINCS+= ${SRCTOP}/sys/rpc/types.h 110 111INCS+= ${SRCTOP}/include/mpool.h 112INCS+= ${SRCTOP}/include/ndbm.h 113INCS+= ${SRCTOP}/include/err.h 114INCS+= ${SRCTOP}/include/stringlist.h 115 116# Needed to build arc4random.c 117INCSGROUPS+= CHACHA20INCS 118CHACHA20INCSDIR= ${INCLUDEDIR}/crypto/chacha20 119CHACHA20INCS+= ${SRCTOP}/sys/crypto/chacha20/_chacha.h \ 120 ${SRCTOP}/sys/crypto/chacha20/chacha.h 121 122_host_arch=${MACHINE} 123.if ${_host_arch} == "x86_64" 124# bmake on Linux/mac often prints that instead of amd64 125_host_arch=amd64 126.endif 127.if ${_host_arch} == "unknown" 128# HACK: If MACHINE is unknown, assume we are building on x86 129_host_arch=amd64 130.endif 131MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/elf.h 132.if ${_host_arch} == "amd64" || ${_host_arch} == "i386" 133INCSGROUPS+= X86INCS 134X86INCSDIR= ${INCLUDEDIR}/x86 135X86INCS+= ${SRCTOP}/sys/x86/include/elf.h 136.endif 137 138# needed for btxld: 139MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/exec.h 140MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/reloc.h 141INCS+= ${SRCTOP}/include/a.out.h 142INCS+= ${SRCTOP}/include/nlist.h 143SYSINCS+= ${SRCTOP}/sys/sys/imgact_aout.h 144SYSINCS+= ${SRCTOP}/sys/sys/nlist_aout.h 145 146 147.if ${.MAKE.OS} != "FreeBSD" 148.PATH: ${.CURDIR}/cross-build 149# dbopen() behaves differently on Linux and FreeBSD so we ensure that we 150# bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to 151# __freebsd_dbopen() so that we don't ever use the host version 152INCS+= ${SRCTOP}/include/db.h 153LIBC_SRCTOP= ${SRCTOP}/lib/libc/ 154.include "${LIBC_SRCTOP}/db/Makefile.inc" 155# Do the same as we did for dbopen() for getopt() on since it's not compatible 156# on Linux (and to avoid surprises also compile the FreeBSD code on macOS) 157.PATH: ${LIBC_SRCTOP}/stdlib 158SRCS+= getopt.c getopt_long.c 159INCS+= ${SRCTOP}/include/getopt.h 160 161# getcap.c is needed for cap_mkdb: 162.PATH: ${LIBC_SRCTOP}/gen 163SRCS+= getcap.c 164# Glibc does not provide all err*/warn* functions, and for macOS we need the 165# alias with the extra underscore. 166SRCS+= err.c 167# Add various libbc functions that are not available in glibc: 168SRCS+= stringlist.c setmode.c 169SRCS+= strtonum.c merge.c heapsort.c reallocf.c 170.PATH: ${LIBC_SRCTOP}/locale 171SRCS+= rpmatch.c 172 173.if ${.MAKE.OS} == "Linux" 174# On Linux, glibc does not provide strlcpy,strlcat or strmode. 175.PATH: ${LIBC_SRCTOP}/string 176SRCS+= strlcpy.c strlcat.c strmode.c 177# Compile the fgetln/fgetwln/closefrom fallback code from libbsd: 178SRCS+= fgetln_fallback.c fgetwln_fallback.c closefrom.c 179CFLAGS.closefrom.c+= -DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \ 180 -DHAVE_DIRFD -DHAVE_SYSCONF 181# Provide getprogname/setprograme 182SRCS+= progname.c 183# Stub implementations of fflagstostr/strtofflags 184SRCS+= fflags.c 185.endif 186# Provide the same arc4random implementation on Linux/macOS 187CFLAGS.arc4random.c+= -I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1 188SRCS+= arc4random.c arc4random_uniform.c 189 190# expand_number() is not provided by either Linux or MacOS libutil 191.PATH: ${SRCTOP}/lib/libutil 192SRCS+= expand_number.c 193# Linux libutil also doesn't have fparseln 194SRCS+= fparseln.c 195# A dummy sysctl for tzsetup: 196SRCS+= fake_sysctl.c 197 198# capsicum support 199SYSINCS+= ${SRCTOP}/sys/sys/capsicum.h 200SYSINCS+= ${SRCTOP}/sys/sys/caprights.h 201SRCS+= capsicum_stubs.c 202# XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes 203# conflicts with other files. Instead copy subr_capability to the build dir. 204subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c 205 cp ${.ALLSRC} ${.TARGET} 206SRCS+= subr_capability.c 207CLEANFILES+= subr_capability.c 208.endif 209 210CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h 211CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_net/cap_net.h 212 213.if empty(SRCS) 214SRCS= dummy.c 215.endif 216 217.if defined(CROSS_BUILD_TESTING) 218SUBDIR= cross-build 219.endif 220 221# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: 222UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h 223UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h 224FFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h 225 226MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h 227MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h 228MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h 229MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h 230MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h 231MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h 232DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h 233 234# Needed to build config (since it uses libnv) 235SYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ 236 ${SRCTOP}/sys/sys/dnv.h 237 238# Needed when bootstrapping ldd (since it uses DF_1_PIE) 239SYSINCS+= ${SRCTOP}/sys/sys/elf32.h 240SYSINCS+= ${SRCTOP}/sys/sys/elf64.h 241SYSINCS+= ${SRCTOP}/sys/sys/elf_common.h 242SYSINCS+= ${SRCTOP}/sys/sys/elf_generic.h 243SYSINCS+= ${SRCTOP}/sys/sys/queue.h 244SYSINCS+= ${SRCTOP}/sys/sys/md5.h 245SYSINCS+= ${SRCTOP}/sys/sys/sbuf.h 246SYSINCS+= ${SRCTOP}/sys/sys/tree.h 247 248# vtfontcvt is using sys/font.h 249SYSINCS+= ${SRCTOP}/sys/sys/font.h 250# For mkscrfil.c: 251SYSINCS+= ${SRCTOP}/sys/sys/consio.h 252# for gencat: 253INCS+= ${SRCTOP}/include/nl_types.h 254# for vtfontcvt: 255SYSINCS+= ${SRCTOP}/sys/sys/fnv_hash.h 256# opensolaris compatibility 257INCS+= ${SRCTOP}/include/elf.h 258SYSINCS+= ${SRCTOP}/sys/sys/elf.h 259SYSINCS+= ${SRCTOP}/sys/sys/ctf.h 260 261# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't 262# accidentally run tools that are incompatible but happen to be in $PATH. 263# This is especially important when building on Linux/MacOS where many of the 264# programs used during the build accept different flags or generate different 265# output. On those platforms we only symlink the tools known to be compatible 266# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others 267# from the FreeBSD sources during the bootstrap-tools stage. 268 269# basic commands: It is fine to use the host version for all of these even on 270# Linux/MacOS since we only use flags that are supported by all of them. 271_host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \ 272 dirname echo env false find fmt gzip gunzip head hostname id ln ls \ 273 mkdir mv nice patch rm sh sleep stat tee touch tr true uname uniq unxz \ 274 wc which xz 275 276# We also need a symlink to the absolute path to the make binary used for 277# the toplevel makefile. This is not necessarily the same as `which make` 278# since e.g. on Linux and MacOS that will be GNU make. 279_make_abs!= which "${MAKE}" 280_host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake 281 282.if ${.MAKE.OS} == "FreeBSD" 283# When building on FreeBSD we always copy the host tools instead of linking 284# into WORLDTMP to avoid issues with incompatible libraries (see r364030). 285# Note: we could create links if we don't intend to update the current machine. 286_COPY_HOST_TOOL=cp -pf 287.else 288# However, this is not necessary on Linux/macOS. Additionally, copying the host 289# tools to another directory with cp -p results in freezes on macOS Big Sur for 290# some unknown reason. It can also break building inside docker containers if 291# there are ACLs on shared volumes. 292_COPY_HOST_TOOL=ln -sfn 293_make_abs!= which "${MAKE}" 294_host_abs_tools_to_symlink+= ${_make_abs}:make ${_make_abs}:bmake 295.if ${.MAKE.OS} == "Darwin" 296# /usr/bin/cpp may invoke xcrun: 297_host_tools_to_symlink+=xcrun 298.endif # ${.MAKE.OS} == "Darwin" 299# On Ubuntu /bin/sh is dash which is totally useless. Let's just link bash 300# as the build sh since that will work fine. 301_host_abs_tools_to_symlink+= /bin/bash:sh 302_host_tools_to_symlink:=${_host_tools_to_symlink:Nsh} 303.endif 304 305host-symlinks: 306 @echo "Linking host tools into ${DESTDIR}/bin" 307.for _tool in ${_host_tools_to_symlink} 308 @export PATH=$${PATH}:/usr/local/bin; \ 309 source_path=`which ${_tool} || echo /dev/null/no/such`; \ 310 if [ ! -e "$${source_path}" ] ; then \ 311 echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; false; \ 312 fi; \ 313 rm -f "${DESTDIR}/bin/${_tool}"; \ 314 ${_COPY_HOST_TOOL} "$${source_path}" "${DESTDIR}/bin/${_tool}" 315.endfor 316.for _tool in ${_host_abs_tools_to_symlink} 317 @source_path="${_tool:S/:/ /:[1]}"; \ 318 target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \ 319 if [ ! -e "$${source_path}" ] ; then \ 320 echo "Host tool '$${source_path}' is missing"; false; \ 321 fi; \ 322 rm -f "$${target_path}"; \ 323 ${_COPY_HOST_TOOL} "$${source_path}" "$${target_path}" 324.endfor 325.if exists(/usr/libexec/flua) 326 rm -f ${DESTDIR}/usr/libexec/flua 327 ${_COPY_HOST_TOOL} /usr/libexec/flua ${DESTDIR}/usr/libexec/flua 328.endif 329 330# Create all the directories that are needed during the legacy, bootstrap-tools 331# and cross-tools stages. We do this here using mkdir since mtree may not exist 332# yet (this happens if we are crossbuilding from Linux/Mac). 333INSTALLDIR_LIST= \ 334 bin \ 335 lib/casper \ 336 lib/geom \ 337 usr/include/casper \ 338 usr/include/private/ucl \ 339 usr/include/private/zstd \ 340 usr/lib \ 341 usr/libdata/pkgconfig \ 342 usr/libexec 343 344installdirs: 345 mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,} 346 347# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a 348# bootstrap tool was added to WORLTMP with a symlink or by building it in the 349# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap 350# tools but adding the symlinks is easier and means all tools are also 351# in the directory that they are installed to normally. 352 353.for _dir in sbin usr/sbin usr/bin 354# delete existing directories from before r340157 355 @if [ -e ${DESTDIR}/${_dir} ] && [ ! -L ${DESTDIR}/${_dir} ]; then \ 356 echo "removing old non-symlink ${DESTDIR}/${_dir}"; \ 357 rm -rf "${DESTDIR}/${_dir}"; \ 358 fi 359.endfor 360 ln -sfn bin ${DESTDIR}/sbin 361 ln -sfn ../bin ${DESTDIR}/usr/bin 362 ln -sfn ../bin ${DESTDIR}/usr/sbin 363.for _group in ${INCSGROUPS:NINCS} 364 mkdir -p "${DESTDIR}/${${_group}DIR}" 365.endfor 366 367.include <bsd.lib.mk> 368