63 lines
2.2 KiB
Bash
63 lines
2.2 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
dut=${1:?DUT path is required}
|
|
freebsd_src=${2:?FreeBSD source path is required}
|
|
output=${3:?output module path is required}
|
|
work=${4:?work directory is required}
|
|
src=$dut/src
|
|
sys=$freebsd_src/sys
|
|
target=x86_64-unknown-freebsd15.0
|
|
|
|
test -d "$sys" || { printf '%s\n' "FreeBSD sys tree is absent: $sys" >&2; exit 21; }
|
|
for tool in awk clang grep nm; do
|
|
command -v "$tool" >/dev/null 2>&1 || {
|
|
printf '%s\n' "missing B23 KLD tool: $tool" >&2
|
|
exit 21
|
|
}
|
|
done
|
|
test ! -e "$work" || { printf '%s\n' "B23 KLD work path exists: $work" >&2; exit 20; }
|
|
mkdir "$work"
|
|
cd "$work"
|
|
ln -s "$sys/amd64/include" machine
|
|
ln -s "$sys/x86/include" x86
|
|
ln -s "$sys/i386/include" i386
|
|
awk -f "$sys/tools/vnode_if.awk" "$sys/kern/vnode_if.src" -p
|
|
awk -f "$sys/tools/vnode_if.awk" "$sys/kern/vnode_if.src" -q
|
|
awk -f "$sys/tools/vnode_if.awk" "$sys/kern/vnode_if.src" -h
|
|
: > opt_global.h
|
|
|
|
cflags="-O2 -pipe -fno-common -fno-strict-aliasing \
|
|
-D_KERNEL -DKLD_MODULE -nostdinc -include $work/opt_global.h \
|
|
-I$work -I$sys -I$sys/contrib/ck/include -mcmodel=kernel \
|
|
-mno-red-zone -mno-mmx -mno-sse -msoft-float \
|
|
-fno-asynchronous-unwind-tables -ffreestanding -fwrapv \
|
|
-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fstack-protector \
|
|
-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
|
|
-Wcast-qual -Wundef -Wno-pointer-sign -Wmissing-include-dirs \
|
|
-Wno-unknown-pragmas -Wno-address-of-packed-member \
|
|
-Wno-format-zero-length -mno-aes -mno-avx -std=gnu17 \
|
|
-D__printf__=__freebsd_kprintf__ --target=$target"
|
|
|
|
for file in super.c inode.c data.c namei.c dir.c xattr.c erofs_vnops.c \
|
|
decompressor.c zmap.c zdata.c decompressor_lz4.c \
|
|
decompressor_lzma.c decompressor_deflate.c decompressor_zstd.c; do
|
|
extra=
|
|
if test "$file" = decompressor_zstd.c; then
|
|
extra="-I$sys/contrib/zstd/lib/freebsd"
|
|
fi
|
|
clang $cflags $extra -c "$src/$file" -o "${file%.c}.o"
|
|
done
|
|
|
|
clang --target="$target" -r -nostdlib ./*.o -o "$output"
|
|
if nm -u "$output" | awk '$NF == "bcmp" { found = 1 } END { exit found }'; then
|
|
:
|
|
else
|
|
printf '%s\n' 'B23 KLD contains an unresolved bcmp reference' >&2
|
|
exit 1
|
|
fi
|
|
if nm -u "$output" | grep -q ' ZSTD_'; then
|
|
printf '%s\n' 'B23 zstdio0 KLD contains an unexpected Zstd symbol' >&2
|
|
exit 1
|
|
fi
|