#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" JOBS="${JOBS:-1}" HOST="${HOST:-x86_64-w64-mingw32}" BUILD_HOST="${BUILD_HOST:-$("$ROOT/depends/config.guess")}" PREFIX="$ROOT/depends/$HOST" NATIVE_BIN="$ROOT/depends/build/$BUILD_HOST/bin" require_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "Missing required command: $1" >&2 exit 1 fi } require_path() { if [[ ! -e "$1" ]]; then echo "Missing required path: $1" >&2 exit 1 fi } copy_first_match() { local name="$1" local match match="$(find "$ROOT/depends/$BUILD_HOST" \( -path "*/bin/$name" -o -path "*/libexec/$name" \) -type f | sort | tail -n 1 || true)" if [[ -z "$match" ]]; then echo "Could not find Qt host tool after depends build: $name" >&2 exit 1 fi cp "$match" "$NATIVE_BIN/$name" } ensure_posix_mingw() { require_cmd "$HOST-g++" if ! "$HOST-g++" --version | head -n 1 | grep -qi posix; then cat >&2 </dev/null 2>&1; then cp "$(command -v lupdate)" "$NATIVE_BIN/lupdate" fi } cd "$ROOT" require_cmd make require_cmd tar require_cmd find require_cmd sort require_cmd tail require_cmd grep require_cmd cp ensure_posix_mingw echo "Building Win64 depends for $HOST..." echo "Building native Qt6 host tools and metadata for $BUILD_HOST..." # Keep the top-level depends scheduler serial. Individual package build # systems still use parallelism, but parallel package configure steps race on # the shared depends prefix and can make Qt see missing zlib/OpenSSL paths. make -C depends HOST="$BUILD_HOST" NO_QT=0 qt -j1 qt_host_cache=( "$ROOT/depends/built/$BUILD_HOST/qt"/qt-*.tar.gz ) if [[ ${#qt_host_cache[@]} -ne 1 || ! -f "${qt_host_cache[0]}" ]]; then echo "Could not locate a single native Qt6 cache archive for $BUILD_HOST" >&2 exit 1 fi mkdir -p "$ROOT/depends/$BUILD_HOST" tar --no-same-owner -xf "${qt_host_cache[0]}" -C "$ROOT/depends/$BUILD_HOST" make -C depends HOST="$HOST" NO_QT=0 -j1 require_path "$PREFIX/share/config.site" ensure_native_tools if [[ ! -f configure || ! -f src/secp256k1/configure || ! -f src/secp256k1/Makefile.in ]]; then ./autogen.sh fi if [[ build-aux/m4/bitcoin_qt.m4 -nt configure || build-aux/m4/bitcoin_qt.m4 -nt aclocal.m4 ]]; then ./autogen.sh fi echo "Configuring Win64 Qt6 wallet build..." CONFIG_SITE="$PREFIX/share/config.site" ./configure \ --prefix=/ \ --disable-maintainer-mode \ --disable-tests \ --disable-bench \ --with-gui=qt6 \ --with-qt-incdir="$PREFIX/include" \ --with-qt-libdir="$PREFIX/lib" \ --with-qt-plugindir="$PREFIX/plugins" \ --with-qt-translationdir="$PREFIX/translations" \ --with-qt-bindir="$NATIVE_BIN" echo "Cleaning stale target objects before compiling..." make clean echo "Building Win64 Qt6 wallet with JOBS=$JOBS..." make -j"$JOBS" echo "Windows wallet build complete:" echo " $ROOT/src/qt/agrarian-qt.exe" echo " $ROOT/src/agrariand.exe" echo " $ROOT/src/agrarian-cli.exe" echo " $ROOT/src/agrarian-tx.exe"