1ca987d46SWarner Losh# Originally from $NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $ 2ca987d46SWarner Losh# 3ca987d46SWarner Losh# Notes: 4ca987d46SWarner Losh# - We don't use the libc strerror/sys_errlist because the string table is 5ca987d46SWarner Losh# quite large. 6ca987d46SWarner Losh# 7ca987d46SWarner Losh 8ca987d46SWarner Losh.include <bsd.init.mk> 9ca987d46SWarner Losh 10ca987d46SWarner LoshLIBSA_CPUARCH?=${MACHINE_CPUARCH} 11ca987d46SWarner Losh 12ca987d46SWarner LoshLIB?= sa 13ca987d46SWarner Losh 14ca987d46SWarner Losh# standalone components and stuff we have modified locally 15ed19b7c5SSimon J. GerratySRCS+= gzguts.h zutil.h __main.c abort.c assert.c bcd.c environment.c \ 161631382cSKyle Evans features.c getopt.c gets.c globals.c \ 17d1ea5017SWarner Losh hexdump.c nvstore.c pager.c panic.c printf.c strdup.c strerror.c \ 18e193d3baSColin Percival random.c sbrk.c tslog.c twiddle.c zalloc.c zalloc_malloc.c 19ca987d46SWarner Losh 20ca987d46SWarner Losh# private (pruned) versions of libc string functions 21ca987d46SWarner LoshSRCS+= strcasecmp.c 22ca987d46SWarner Losh 2380335781SKyle Evans.PATH: ${LIBCSRC}/net 24ca987d46SWarner Losh 25ca987d46SWarner LoshSRCS+= ntoh.c 26ca987d46SWarner Losh 27ca987d46SWarner Losh# string functions from libc 2880335781SKyle Evans.PATH: ${LIBCSRC}/string 29ca987d46SWarner LoshSRCS+= bcmp.c bcopy.c bzero.c ffs.c fls.c \ 30ca987d46SWarner Losh memccpy.c memchr.c memcmp.c memcpy.c memmove.c memset.c \ 317f72497eSEd Maste strcat.c strchr.c strchrnul.c strcmp.c strcpy.c stpcpy.c stpncpy.c \ 32ca987d46SWarner Losh strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \ 3337cb59c8SKyle Evans strnlen.c strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c 3424dfa658SWarner Losh 3524dfa658SWarner Losh# stdlib functions from libc 3680335781SKyle Evans.PATH: ${LIBCSRC}/stdlib 37afa643baSWarner LoshSRCS+= abs.c strtol.c strtoll.c strtoul.c strtoull.c 3824dfa658SWarner Losh 3952379d36SWarner Losh# common boot code 4052379d36SWarner Losh.PATH: ${SYSDIR}/kern 4152379d36SWarner LoshSRCS+= subr_boot.c 4252379d36SWarner Losh 43ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "arm" 4480335781SKyle Evans.PATH: ${LIBCSRC}/arm/gen 45ca987d46SWarner Losh 46ca987d46SWarner Losh# Do not generate movt/movw, because the relocation fixup for them does not 47ca987d46SWarner Losh# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8). 48ca987d46SWarner Losh# Also, the fpu is not available in a standalone environment. 49ca987d46SWarner LoshCFLAGS.clang+= -mno-movt 50ca987d46SWarner LoshCFLAGS.clang+= -mfpu=none 51ca987d46SWarner Losh 520b57cec5SDimitry Andric.PATH: ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins/arm/ 53ca987d46SWarner LoshSRCS+= aeabi_idivmod.S aeabi_ldivmod.S aeabi_uidivmod.S aeabi_uldivmod.S 54ca987d46SWarner LoshSRCS+= aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S 55ca987d46SWarner Losh.endif 56ca987d46SWarner Losh 57ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv" 5880335781SKyle Evans.PATH: ${LIBCSRC}/${MACHINE_CPUARCH}/gen 59ca987d46SWarner Losh.endif 60ca987d46SWarner Losh 6180746f9fSKyle Evans# Compiler support functions 620b57cec5SDimitry Andric.PATH: ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins/ 6380746f9fSKyle Evans# __clzsi2 and ctzsi2 for various builtin functions 6480746f9fSKyle EvansSRCS+= clzsi2.c ctzsi2.c 6580746f9fSKyle Evans# Divide and modulus functions called by the compiler 6680746f9fSKyle EvansSRCS+= divmoddi4.c divmodsi4.c divdi3.c divsi3.c moddi3.c modsi3.c 6780746f9fSKyle EvansSRCS+= udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c 6863d8b6eaSKyle EvansSRCS+= ashldi3.c ashrdi3.c lshrdi3.c 69ca987d46SWarner Losh 70e9b148a3SSimon J. Gerraty.if ${MACHINE_CPUARCH:Namd64:Ni386} == "" 71e9b148a3SSimon J. Gerraty.PATH: ${SASRC}/x86 72e9b148a3SSimon J. GerratySRCS+= hypervisor.c 73e9b148a3SSimon J. Gerraty.endif 74e9b148a3SSimon J. Gerraty 7580746f9fSKyle Evans.if ${MACHINE_CPUARCH} == "powerpc" 7680746f9fSKyle EvansSRCS+= syncicache.c 77bd7c104aSWarner Losh.endif 78bd7c104aSWarner Losh 79ca987d46SWarner Losh# uuid functions from libc 8080335781SKyle Evans.PATH: ${LIBCSRC}/uuid 81ca987d46SWarner LoshSRCS+= uuid_create_nil.c uuid_equal.c uuid_from_string.c uuid_is_nil.c uuid_to_string.c 82ca987d46SWarner Losh 83ca987d46SWarner Losh# _setjmp/_longjmp 84ca987d46SWarner Losh.PATH: ${SASRC}/${LIBSA_CPUARCH} 85ca987d46SWarner LoshSRCS+= _setjmp.S 86ca987d46SWarner Losh 87ca987d46SWarner Losh# decompression functionality from libbz2 88ca987d46SWarner Losh# NOTE: to actually test this functionality after libbz2 upgrade compile 89ca987d46SWarner Losh# loader(8) with LOADER_BZIP2_SUPPORT defined 90ca987d46SWarner Losh.PATH: ${SRCTOP}/contrib/bzip2 9159a4cfe0SWarner Losh.for i in bzlib.c crctable.c decompress.c huffman.c randtable.c 9259a4cfe0SWarner LoshCFLAGS.${i}+= -DBZ_NO_STDIO -DBZ_NO_COMPRESS 9359a4cfe0SWarner LoshSRCS+=${i} 9459a4cfe0SWarner Losh.endfor 95ca987d46SWarner Losh 96ca987d46SWarner Losh# decompression functionality from zlib 976b574b3bSWarner Losh# https://github.com/madler/zlib/issues/633 documents why we suppress deprecated 986b574b3bSWarner Losh# prototype warnings. 99c9083b85SXin LI.PATH: ${SRCTOP}/sys/contrib/zlib 100983a1802SWarner LoshZLIB_CFLAGS=-DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib ${NO_WDEPRECATED_NON_PROTOTYPE} 10184bf2bbbSWarner Losh.for i in adler32.c crc32.c infback.c inffast.c inflate.c inftrees.c zutil.c 10284bf2bbbSWarner LoshCFLAGS.${i}+=${ZLIB_CFLAGS} 10384bf2bbbSWarner LoshSRCS+= ${i} 10484bf2bbbSWarner Losh.endfor 105ca987d46SWarner Losh 106e499793eSToomas Soome# lz4 decompression functionality 107e499793eSToomas Soome.PATH: ${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4 108e499793eSToomas SoomeSRCS+= lz4.c 109e499793eSToomas SoomeCFLAGS.lz4.c+= -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4 110e499793eSToomas Soome 111ca987d46SWarner Losh# io routines 112b4cb3fe0SToomas SoomeSRCS+= closeall.c dev.c ioctl.c nullfs.c stat.c mount.c \ 113c25d9affSEmmanuel Vadot fstat.c close.c lseek.c open.c read.c write.c readdir.c preload.c 114ca987d46SWarner Losh 115a64f0b83SWarner Losh# SMBios routines 116a64f0b83SWarner LoshSRCS+= smbios.c 117a64f0b83SWarner Losh.if !defined(BOOT_HIDE_SERIAL_NUMBERS) 118a64f0b83SWarner Losh# Export serial numbers, UUID, and asset tag from loader. 119a64f0b83SWarner LoshCFLAGS.smbios.c+= -DSMBIOS_SERIAL_NUMBERS 120a64f0b83SWarner Losh.if defined(BOOT_LITTLE_ENDIAN_UUID) 121a64f0b83SWarner Losh# Use little-endian UUID format as defined in SMBIOS 2.6. 122a64f0b83SWarner LoshCFLAGS.smbios.c+= -DSMBIOS_LITTLE_ENDIAN_UUID 123a64f0b83SWarner Losh.elif defined(BOOT_NETWORK_ENDIAN_UUID) 124a64f0b83SWarner Losh# Use network-endian UUID format for backward compatibility. 125a64f0b83SWarner LoshCFLAGS.smbios.c+= -DSMBIOS_NETWORK_ENDIAN_UUID 126a64f0b83SWarner Losh.endif 127a64f0b83SWarner Losh.endif 128a64f0b83SWarner Losh 129ca987d46SWarner Losh# network routines 130ca987d46SWarner LoshSRCS+= arp.c ether.c ip.c inet_ntoa.c in_cksum.c net.c udp.c netif.c rpc.c 131ca987d46SWarner Losh 132ca987d46SWarner Losh# network info services: 133ca987d46SWarner LoshSRCS+= bootp.c rarp.c bootparam.c 134ca987d46SWarner Losh 135ca987d46SWarner Losh# boot filesystems 136ca987d46SWarner LoshSRCS+= ufs.c nfs.c cd9660.c tftp.c gzipfs.c bzipfs.c 137ca987d46SWarner LoshSRCS+= dosfs.c ext2fs.c 138ca987d46SWarner LoshSRCS+= splitfs.c 139ca987d46SWarner LoshSRCS+= pkgfs.c 140ca987d46SWarner Losh 1416ab1ffcbSWarner Losh# Time support 1426ab1ffcbSWarner LoshSRCS+= time.c 1436ab1ffcbSWarner Losh 144dffce215SKirk McKusick# kernel ufs support 145dffce215SKirk McKusick.PATH: ${SRCTOP}/sys/ufs/ffs 146dffce215SKirk McKusickSRCS+=ffs_subr.c ffs_tables.c 147dffce215SKirk McKusick 14814821130SWarner Losh# 14914821130SWarner Losh# i386 has a constrained space for its /boot/loader, so compile out the 15014821130SWarner Losh# extensive messages diagnosing bad superblocks. i386 doesn't support UEFI 15114821130SWarner Losh# booting, so doing it always makes sense natively there. When we compile 15214821130SWarner Losh# for 32-bit on amd64, LIBSA_CPUARCH is also i386 and we use libsa32 only 15314821130SWarner Losh# for the BIOS /boot/loader which has the same constraints. 15414821130SWarner Losh# 15514821130SWarner Losh.if ${LIBSA_CPUARCH} == "i386" 15614821130SWarner LoshCFLAGS.ffs_subr.c+= -DSTANDALONE_SMALL 15714821130SWarner Losh.endif 15814821130SWarner Losh 15984bf2bbbSWarner LoshCFLAGS.gzipfs.c+= ${ZLIB_CFLAGS} 16084bf2bbbSWarner LoshCFLAGS.pkgfs.c+= ${ZLIB_CFLAGS} 16159a4cfe0SWarner LoshCFLAGS.bzipfs.c+= -I${SRCTOP}/contrib/bzip2 -DBZ_NO_STDIO -DBZ_NO_COMPRESS 16205f37f4dSWarner Losh 163ad6f5f9aSKonstantin Belousov# explicit_bzero and calculate_crc32c 164ca987d46SWarner Losh.PATH: ${SYSDIR}/libkern 165ad6f5f9aSKonstantin BelousovSRCS+= explicit_bzero.c crc32_libkern.c 166ca987d46SWarner Losh 16717cccb6fSWarner Losh# Bits from GELI reused for some random seeding cases 168925f1573SColin Percival.PATH: ${SYSDIR}/geom/eli 169925f1573SColin PercivalSRCS+= g_eli_hmac.c pkcs5v2.c 170925f1573SColin Percival 17162bd02ceSWarner Losh# Maybe GELI 17262bd02ceSWarner Losh.if ${MK_LOADER_GELI} == "yes" 17362bd02ceSWarner Losh.include "${SASRC}/geli/Makefile.inc" 17462bd02ceSWarner Losh.endif 17562bd02ceSWarner Losh 1768df8b2d3SSimon J. Gerraty.if ${MK_LOADER_VERIEXEC} == "yes" && ${MK_BEARSSL} == "yes" 17737dabb06SWarner Losh# XXX Note that these pollutes CFLAGS in a way that's not easy to fix 1788df8b2d3SSimon J. Gerraty.include "${SRCTOP}/lib/libbearssl/Makefile.libsa.inc" 1798df8b2d3SSimon J. Gerraty.include "${SRCTOP}/lib/libsecureboot/Makefile.libsa.inc" 1808df8b2d3SSimon J. Gerraty.endif 1818df8b2d3SSimon J. Gerraty 182b8902de1SWarner Losh# Maybe ZFS 183fbeb31a2SMatt Macy.if ${MK_LOADER_ZFS} == "yes" 184b8902de1SWarner Losh.include "${SASRC}/zfs/Makefile.inc" 185b8902de1SWarner Losh.endif 186b8902de1SWarner Losh 187fd577b59SWarner Losh# Crypto hashing functions 188fd577b59SWarner Losh# sha256 and sha512 from sys/crypto 189fd577b59SWarner Losh.PATH: ${SYSDIR}/crypto/sha2 190fd577b59SWarner LoshSRCS+= sha256c.c sha512c.c 191fd577b59SWarner Losh 192e7a629c8SKyle Evans# md5 from the kernel 193e7a629c8SKyle Evans.PATH: ${SYSDIR}/kern 194fd577b59SWarner LoshSRCS+= md5c.c 195fd577b59SWarner Losh 19670b5c4ffSWarner Losh.if ${DO32:U0} == 0 19770b5c4ffSWarner LoshMAN=libsa.3 19870b5c4ffSWarner Losh.endif 19970b5c4ffSWarner Losh 2007c8b126cSWarner Losh# Create a subset of includes that are safe, as well as adjusting those that aren't 2017c8b126cSWarner Losh# The lists may drive people nuts, but they are explicitly opt-in 20241c233deSKyle EvansFAKE_DIRS=xlocale arpa ssp 203*780f2892SWarner LoshSAFE_INCS=a.out.h assert.h elf.h limits.h nlist.h setjmp.h stddef.h stdbool.h string.h strings.h time.h uuid.h 20417be774eSWarner LoshSTAND_H_INC=ctype.h fcntl.h signal.h stdio.h stdlib.h unistd.h 2057c8b126cSWarner LoshOTHER_INC=stdarg.h errno.h stdint.h 2067c8b126cSWarner Losh 2077c8b126cSWarner Loshbeforedepend: 2087c8b126cSWarner Losh mkdir -p ${FAKE_DIRS}; \ 2097c8b126cSWarner Losh for i in ${SAFE_INCS}; do \ 2107c8b126cSWarner Losh ln -sf ${SRCTOP}/include/$$i $$i; \ 2117c8b126cSWarner Losh done; \ 2127c8b126cSWarner Losh ln -sf ${SYSDIR}/${MACHINE}/include/stdarg.h stdarg.h; \ 2137c8b126cSWarner Losh ln -sf ${SYSDIR}/sys/errno.h errno.h; \ 2147c8b126cSWarner Losh ln -sf ${SYSDIR}/sys/stdint.h stdint.h; \ 2157c8b126cSWarner Losh ln -sf ${SRCTOP}/include/arpa/inet.h arpa/inet.h; \ 2167c8b126cSWarner Losh ln -sf ${SRCTOP}/include/arpa/tftp.h arpa/tftp.h; \ 21741c233deSKyle Evans ln -sf ${SRCTOP}/include/ssp/ssp.h ssp/ssp.h; \ 2187c8b126cSWarner Losh for i in _time.h _strings.h _string.h; do \ 2197c8b126cSWarner Losh [ -f xlocale/$$i ] || :> xlocale/$$i; \ 2207c8b126cSWarner Losh done; \ 2217c8b126cSWarner Losh for i in ${STAND_H_INC}; do \ 2227c8b126cSWarner Losh ln -sf ${SASRC}/stand.h $$i; \ 2237c8b126cSWarner Losh done 2247c8b126cSWarner LoshCLEANDIRS+=${FAKE_DIRS} 2257c8b126cSWarner LoshCLEANFILES+= ${SAFE_INCS} ${STAND_H_INC} ${OTHER_INC} 2267c8b126cSWarner Losh 227ca987d46SWarner Losh.include <bsd.lib.mk> 228