1# $FreeBSD$ 2 3.PATH: ${.CURDIR}/../../include 4 5LIB= egacy 6SRC= 7INCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS 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 17 18BOOTSTRAPPING?= 0 19 20_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true 21.if ${_WITH_PWCACHEDB} == 0 22.PATH: ${.CURDIR}/../../contrib/libc-pwcache 23CFLAGS+= -I${.CURDIR}/../../contrib/libc-pwcache \ 24 -I${.CURDIR}/../../lib/libc/include 25SRCS+= pwcache.c 26.endif 27 28_WITH_STRSVIS!= grep -c strsvis /usr/include/vis.h || true 29.if ${_WITH_STRSVIS} == 0 30.PATH: ${.CURDIR}/../../contrib/libc-vis 31SRCS+= vis.c 32CFLAGS+= -I${.CURDIR}/../../contrib/libc-vis \ 33 -I${.CURDIR}/../../lib/libc/include 34.endif 35 36_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true 37.if ${_WITH_REALLOCARRAY} == 0 38.PATH: ${.CURDIR}/../../lib/libc/stdlib 39INCS+= stdlib.h 40SRCS+= reallocarray.c 41CFLAGS+= -I${.CURDIR}/../../lib/libc/include 42.endif 43 44_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true 45.if ${_WITH_UTIMENS} == 0 46SYSINCS+= stat.h 47SRCS+= futimens.c utimensat.c 48.endif 49 50_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true 51.if ${_WITH_EXPLICIT_BZERO} == 0 52.PATH: ${SRCTOP}/sys/libkern 53INCS+= strings.h 54SRCS+= explicit_bzero.c 55.endif 56 57.if exists(/usr/include/capsicum_helpers.h) 58_WITH_CAPH_ENTER!= grep -c caph_enter /usr/include/capsicum_helpers.h || true 59_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit /usr/include/capsicum_helpers.h || true 60.endif 61.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0 62.PATH: ${SRCTOP}/lib/libcapsicum 63INCS+= capsicum_helpers.h 64.PATH: ${SRCTOP}/lib/libcasper/libcasper 65INCS+= libcasper.h 66.endif 67 68CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h 69 70.if empty(SRCS) 71SRCS= dummy.c 72.endif 73 74.if defined(CROSS_BUILD_TESTING) 75SUBDIR= cross-build 76.endif 77 78# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: 79UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h 80UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h 81FFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h 82 83MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h 84MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h 85MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h 86MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h 87MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h 88MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h 89DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h 90 91# Needed to build config (since it uses libnv) 92SYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ 93 ${SRCTOP}/sys/sys/dnv.h 94 95# vtfontcvt is using sys/font.h 96SYSINCS+= ${SRCTOP}/sys/sys/font.h 97 98# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't 99# accidentally run tools that are incompatible but happen to be in $PATH. 100# This is especially important when building on Linux/MacOS where many of the 101# programs used during the build accept different flags or generate different 102# output. On those platforms we only symlink the tools known to be compatible 103# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others 104# from the FreeBSD sources during the bootstrap-tools stage. 105 106# basic commands: It is fine to use the host version for all of these even on 107# Linux/MacOS since we only use flags that are supported by all of them. 108_host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \ 109 dirname echo env false find fmt gzip gunzip head hostname id ln ls \ 110 mkdir mv nice patch rm realpath sh sleep stat tee touch tr true uname \ 111 uniq wc which 112 113# We also need a symlink to the absolute path to the make binary used for 114# the toplevel makefile. This is not necessarily the same as `which make` 115# since e.g. on Linux and MacOS that will be GNU make. 116_make_abs!= which "${MAKE}" 117_host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake 118 119host-symlinks: 120 @echo "Linking host tools into ${DESTDIR}/bin" 121.for _tool in ${_host_tools_to_symlink} 122 @if [ ! -e "${DESTDIR}/bin/${_tool}" ]; then \ 123 source_path=`which ${_tool}`; \ 124 if [ ! -e "$${source_path}" ] ; then \ 125 echo "Cannot find host tool '${_tool}'"; false; \ 126 fi; \ 127 ln -sfnv "$${source_path}" "${DESTDIR}/bin/${_tool}"; \ 128 fi 129.endfor 130.for _tool in ${_host_abs_tools_to_symlink} 131 @source_path="${_tool:S/:/ /:[1]}"; \ 132 target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \ 133 if [ ! -e "$${target_path}" ] ; then \ 134 if [ ! -e "$${source_path}" ] ; then \ 135 echo "Host tool '${src_path}' is missing"; false; \ 136 fi; \ 137 ln -sfnv "$${source_path}" "$${target_path}"; \ 138 fi 139.endfor 140.if exists(/usr/libexec/flua) 141 ln -sf /usr/libexec/flua ${DESTDIR}/usr/libexec/flua 142.endif 143 144# Create all the directories that are needed during the legacy, bootstrap-tools 145# and cross-tools stages. We do this here using mkdir since mtree may not exist 146# yet (this happens if we are crossbuilding from Linux/Mac). 147INSTALLDIR_LIST= \ 148 bin \ 149 lib/casper \ 150 lib/geom \ 151 usr/include/casper \ 152 usr/include/private/ucl \ 153 usr/include/private/zstd \ 154 usr/lib \ 155 usr/libexec 156 157installdirs: 158 mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,} 159 160# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a 161# bootstrap tool was added to WORLTMP with a symlink or by building it in the 162# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap 163# tools but adding the symlinks is easier and means all tools are also 164# in the directory that they are installed to normally. 165 166.for _dir in sbin usr/sbin usr/bin 167# delete existing directories from before r340157 168 @if [ ! -L ${DESTDIR}/${_dir} ]; then \ 169 echo "removing old non-symlink ${DESTDIR}/${_dir}"; \ 170 rm -rf "${DESTDIR}/${_dir}"; \ 171 fi 172.endfor 173 ln -sfn bin ${DESTDIR}/sbin 174 ln -sfn ../bin ${DESTDIR}/usr/bin 175 ln -sfn ../bin ${DESTDIR}/usr/sbin 176.for _group in ${INCSGROUPS:NINCS} 177 mkdir -p "${DESTDIR}/${${_group}DIR}" 178.endfor 179 180.include <bsd.lib.mk> 181