#!/usr/bin/env bash # Cross-build a MINIMAL static FreeType for the mingw-w64 (Windows) target. # # Why: the wallet's optional color-emoji rendering needs FreeType (to rasterize the COLR/CPAL Twemoji # font). Native Linux/macOS pick up the system FreeType via find_package; the Debian/Ubuntu mingw-w64 # cross toolchain ships no FreeType, so we build one here. The Twemoji font is COLRv0 (layered vector), # which FreeType renders WITHOUT libpng / harfbuzz / brotli / zlib — so this is a dependency-free static # build (no external libs to also cross-compile), producing a self-contained libfreetype.a. # # Output: /include/freetype2/... + /lib/libfreetype.a (default prefix: third_party/freetype-mingw) # build.sh --win-release runs this automatically and passes -DDRAGONX_MINGW_FREETYPE_PREFIX to CMake. set -euo pipefail FT_VERSION="2.13.3" FT_SHA256="5c3a8e78f7b24c20b25b54ee575d6daa40007a5f4eea2845861c3409b3021747" # freetype-2.13.3.tar.gz FT_URL="https://download.savannah.gnu.org/releases/freetype/freetype-${FT_VERSION}.tar.gz" FT_URL_MIRROR="https://downloads.sourceforge.net/project/freetype/freetype2/${FT_VERSION}/freetype-${FT_VERSION}.tar.gz" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" PREFIX="${1:-$SCRIPT_DIR/third_party/freetype-mingw}" WORK="$SCRIPT_DIR/third_party/.freetype-mingw-build" # Already built? (libfreetype.a present) → nothing to do. if [[ -f "$PREFIX/lib/libfreetype.a" && -d "$PREFIX/include/freetype2" ]]; then echo "FreeType (mingw) already built at: $PREFIX" exit 0 fi # Pick the mingw compilers (posix threads variant preferred, matching build.sh). if command -v x86_64-w64-mingw32-gcc-posix &>/dev/null; then MINGW_GCC=x86_64-w64-mingw32-gcc-posix; MINGW_GXX=x86_64-w64-mingw32-g++-posix elif command -v x86_64-w64-mingw32-gcc &>/dev/null; then MINGW_GCC=x86_64-w64-mingw32-gcc; MINGW_GXX=x86_64-w64-mingw32-g++ else echo "ERROR: x86_64-w64-mingw32-gcc not found (install mingw-w64)." >&2 exit 1 fi mkdir -p "$WORK" cd "$WORK" TARBALL="freetype-${FT_VERSION}.tar.gz" if [[ ! -f "$TARBALL" ]]; then echo "Downloading FreeType ${FT_VERSION} ..." curl -fsSL -o "$TARBALL" "$FT_URL" || curl -fsSL -o "$TARBALL" "$FT_URL_MIRROR" fi echo "Verifying SHA-256 ..." echo "${FT_SHA256} ${TARBALL}" | sha256sum -c - || { echo "ERROR: FreeType tarball checksum mismatch (expected ${FT_SHA256})." >&2 echo " got: $(sha256sum "$TARBALL" | cut -d' ' -f1)" >&2 exit 1 } rm -rf "freetype-${FT_VERSION}" tar xf "$TARBALL" SRC="$WORK/freetype-${FT_VERSION}" # Minimal mingw toolchain for FreeType's own CMake. cat > "$WORK/ft-mingw-toolchain.cmake" < $PREFIX/lib/libfreetype.a" else echo "ERROR: build did not produce libfreetype.a" >&2 exit 1 fi