Files
SimpleRemoter/linux/build_zstd_linux.sh

51 lines
1.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# build_zstd_linux.sh - 用官方源码编译 libzstd.a (x86_64 Linux)
# 产出linux/lib/libzstd.a (覆盖旧版本)
#
# 用法(在 WSL 或 Linux 下):
# cd linux && bash build_zstd_linux.sh
set -euo pipefail
cd "$(dirname "$0")"
ZSTD_VERSION="1.5.6"
ZSTD_TAR="zstd-${ZSTD_VERSION}.tar.gz"
ZSTD_URL="https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/${ZSTD_TAR}"
ZSTD_DIR="zstd-${ZSTD_VERSION}"
BUILD_DIR="zstd_build"
OUT_DIR="lib"
# --- 下载源码 ---
if [[ ! -d "$ZSTD_DIR" ]]; then
echo "Downloading zstd $ZSTD_VERSION..."
wget -q "$ZSTD_URL" -O "$ZSTD_TAR" || curl -sSL "$ZSTD_URL" -o "$ZSTD_TAR"
tar xf "$ZSTD_TAR"
rm "$ZSTD_TAR"
fi
# --- CMake 构建 ---
rm -rf "$BUILD_DIR"
cmake \
-B "$BUILD_DIR" -S "$ZSTD_DIR/build/cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-O2 -g0" \
-DZSTD_BUILD_STATIC=ON \
-DZSTD_BUILD_SHARED=OFF \
-DZSTD_BUILD_PROGRAMS=OFF \
-DZSTD_BUILD_TESTS=OFF \
-DZSTD_LEGACY_SUPPORT=0
cmake --build "$BUILD_DIR" --config Release -j"$(nproc)"
# --- 拷贝产物 ---
mkdir -p "$OUT_DIR"
cp "$BUILD_DIR/lib/libzstd.a" "$OUT_DIR/libzstd.a"
strip --strip-debug "$OUT_DIR/libzstd.a" 2>/dev/null || true
ls -lh "$OUT_DIR/libzstd.a"
rm -rf "$BUILD_DIR" "$ZSTD_DIR"
echo
echo "===== Done ====="
echo "libzstd.a 已写入 linux/lib/libzstd.a"