Files
Hermit/scripts/build_third_party_mingw.sh
T
WHCandCursor 1f1fcba7ad Initial CST-Agent: portable Linux/Termux/Windows coding agent.
Vendored sashidown, OpenAI-compatible env (OPENAI_*), and bootstrap scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-07 22:42:32 +08:00

140 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build third-party deps for Windows MinGW cross + optional Unix busybox.
# Sources:
# busybox-w32: https://github.com/rmyorston/busybox-w32.git
# busybox: https://github.com/mirror/busybox.git
# curl: https://github.com/curl/curl.git (Windows via Schannel)
# PDCurses: https://github.com/wmcbrine/PDCurses.git
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TP="$ROOT/third_party"
HOST="${MINGW_HOST:-x86_64-w64-mingw32}"
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 4)}"
mkdir -p "$TP"
need_cmd() { command -v "$1" >/dev/null || { echo "missing: $1" >&2; exit 1; }; }
need_cmd git
need_cmd make
need_cmd "${HOST}-gcc"
clone_or_update() {
local url="$1" dir="$2"
if [[ -d "$dir/.git" ]]; then
git -C "$dir" fetch --depth 1 origin 2>/dev/null || true
git -C "$dir" pull --ff-only 2>/dev/null || true
else
git clone --depth 1 "$url" "$dir"
fi
}
# --- curl (static, Schannel) ---
build_curl_mingw() {
clone_or_update https://github.com/curl/curl.git "$TP/curl"
cd "$TP/curl"
if [[ ! -f configure ]]; then
autoreconf -fi 2>/dev/null || true
fi
# Prefer cmake for curl modern tree
rm -rf build-mingw
cmake -B build-mingw -G "Unix Makefiles" \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER="${HOST}-gcc" \
-DCMAKE_RC_COMPILER="${HOST}-windres" \
-DCMAKE_INSTALL_PREFIX="$TP/prefix-mingw" \
-DBUILD_SHARED_LIBS=OFF \
-DCURL_USE_SCHANNEL=ON \
-DCURL_USE_OPENSSL=OFF \
-DCURL_DISABLE_LDAP=ON \
-DCURL_USE_LIBPSL=OFF \
-DCURL_ZLIB=OFF \
-DCURL_BROTLI=OFF \
-DCURL_ZSTD=OFF \
-DUSE_NGHTTP2=OFF \
-DBUILD_CURL_EXE=OFF \
-DBUILD_TESTING=OFF \
-DHTTP_ONLY=OFF
cmake --build build-mingw -j"$JOBS"
cmake --install build-mingw
echo "curl installed -> $TP/prefix-mingw"
}
# --- PDCurses ---
build_pdcurses_mingw() {
clone_or_update https://github.com/wmcbrine/PDCurses.git "$TP/PDCurses"
cd "$TP/PDCurses/wincon"
make -f Makefile clean 2>/dev/null || true
make -f Makefile \
CC="${HOST}-gcc" \
LINK="${HOST}-gcc" \
CFLAGS="-O2 -I.. -DPDC_WIDE -DPDC_FORCE_UTF8" \
LIBEXE="${HOST}-ar" \
LIBFLAGS=rcv \
pdcurses.a
mkdir -p "$TP/prefix-mingw/include" "$TP/prefix-mingw/lib"
cp -f ../curses.h "$TP/prefix-mingw/include/"
[[ -f ../panel.h ]] && cp -f ../panel.h "$TP/prefix-mingw/include/" || true
cp -f pdcurses.a "$TP/prefix-mingw/lib/libpdcurses.a"
# Also install as curses for find_library
cp -f pdcurses.a "$TP/prefix-mingw/lib/libcurses.a"
echo "PDCurses -> $TP/prefix-mingw"
}
# --- busybox-w32 ---
build_busybox_w32() {
clone_or_update https://github.com/rmyorston/busybox-w32.git "$TP/busybox-w32"
cd "$TP/busybox-w32"
# configs: try mingw64 defconfig
if [[ -f configs/mingw64_defconfig ]]; then
make mingw64_defconfig
elif [[ -f configs/mingw_defconfig ]]; then
make mingw_defconfig
else
make defconfig
fi
# Cross compile
make -j"$JOBS" CROSS_COMPILE="${HOST}-" \
CONFIG_EXTRA_CFLAGS="-O2" \
busybox.exe 2>&1 || make -j"$JOBS" CROSS_COMPILE="${HOST}-"
mkdir -p "$TP/busybox"
if [[ -f busybox.exe ]]; then
cp -f busybox.exe "$TP/busybox/busybox.exe"
else
find . -name 'busybox.exe' | head -1 | xargs -I{} cp -f {} "$TP/busybox/busybox.exe"
fi
cat > "$TP/busybox/LICENSE.busybox" << 'EOF'
BusyBox is GPLv2. Source: https://github.com/rmyorston/busybox-w32
Upstream BusyBox: https://github.com/mirror/busybox
EOF
ls -la "$TP/busybox/busybox.exe"
}
# --- Unix busybox (optional, for Linux/Termux side-by-side bundle) ---
build_busybox_unix() {
clone_or_update https://github.com/mirror/busybox.git "$TP/busybox-src"
cd "$TP/busybox-src"
make defconfig
# Keep applets reasonable; enable ash + diff
make -j"$JOBS" busybox
mkdir -p "$TP/busybox"
cp -f busybox "$TP/busybox/busybox"
echo "unix busybox -> $TP/busybox/busybox"
}
TARGETS="${1:-all}"
case "$TARGETS" in
curl) build_curl_mingw ;;
pdcurses) build_pdcurses_mingw ;;
busybox-w32) build_busybox_w32 ;;
busybox-unix) build_busybox_unix ;;
all)
build_curl_mingw
build_pdcurses_mingw
build_busybox_w32
;;
*)
echo "usage: $0 [all|curl|pdcurses|busybox-w32|busybox-unix]"
exit 1
;;
esac
echo "DONE"