#!/usr/bin/env bash # SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin # SPDX-License-Identifier: CC-BY-NC-ND-4.0 set -e if [ "$#" -lt 4 ]; then echo "Syntax: $0 [-system-freetype] [-system-harfbuzz] [-system-libjpeg] [-system-libpng] [-system-libwebp] [-system-libzip] [-system-zstd] [-system-qt] [-skip-download] [-skip-cleanup] [-only-download] " exit 1 fi for arg in "$@"; do if [ "$arg" == "-system-freetype" ]; then echo "Skipping building FreeType." SKIP_FREETYPE=true shift elif [ "$arg" == "-system-harfbuzz" ]; then echo "Skipping building HarfBuzz." SKIP_HARFBUZZ=true shift elif [ "$arg" == "-system-libjpeg" ]; then echo "Skipping building libjpeg." SKIP_LIBJPEG=true shift elif [ "$arg" == "-system-libpng" ]; then echo "Skipping building libpng." SKIP_LIBPNG=true shift elif [ "$arg" == "-system-libwebp" ]; then echo "Skipping building libwebp." SKIP_LIBWEBP=true shift elif [ "$arg" == "-system-libzip" ]; then echo "Skipping building libzip." SKIP_LIBZIP=true shift elif [ "$arg" == "-system-zstd" ]; then echo "Skipping building zstd." SKIP_ZSTD=true shift elif [ "$arg" == "-system-qt" ]; then echo "Skipping building Qt." SKIP_QT=true shift elif [ "$arg" == "-skip-download" ]; then echo "Not downloading sources." SKIP_DOWNLOAD=true shift elif [ "$arg" == "-skip-cleanup" ]; then echo "Not removing build directory." SKIP_CLEANUP=true shift elif [ "$arg" == "-only-download" ]; then echo "Only downloading sources." ONLY_DOWNLOAD=true shift fi done SCRIPTDIR=$(realpath $(dirname "${BASH_SOURCE[0]}")) NPROCS="$(getconf _NPROCESSORS_ONLN)" HOSTDIR="$1" if [ "${HOSTDIR:0:1}" != "/" ]; then HOSTDIR="$PWD/$HOSTDIR" fi CROSSARCH="$2" SYSROOTDIR="$3" if [ "${SYSROOTDIR:0:1}" != "/" ]; then SYSROOTDIR="$PWD/$SYSROOTDIR" fi INSTALLDIR="$4" if [ "${INSTALLDIR:0:1}" != "/" ]; then INSTALLDIR="$PWD/$INSTALLDIR" fi TOOLCHAINFILE="$INSTALLDIR/toolchain.cmake" CMAKE_COMMON=( -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAINFILE" -DCMAKE_PREFIX_PATH="$INSTALLDIR" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" ) # TODO: Pull all of this from the main file. FREETYPE=2.13.3 HARFBUZZ=10.1.0 LIBBACKTRACE=86885d14049fab06ef8a33aac51664230ca09200 LIBJPEGTURBO=3.0.4 LIBPNG=1.6.44 LIBWEBP=1.4.0 LIBZIP=1.11.2 SDL3=3.2.0 QT=6.8.1 ZSTD=1.5.6 CPUINFO=7524ad504fdcfcf75a18a133da6abd75c5d48053 DISCORD_RPC=144f3a3f1209994d8d9e8a87964a989cb9911c1e LUNASVG=9af1ac7b90658a279b372add52d6f77a4ebb482c SHADERC=1c0d3d18819aa75ec74f1fbd9ff0461e1b69a4d6 SOUNDTOUCH=463ade388f3a51da078dc9ed062bf28e4ba29da7 SPIRV_CROSS=vulkan-sdk-1.3.290.0 mkdir -p "${INSTALLDIR}" mkdir -p deps-build cd deps-build if [ "$SKIP_DOWNLOAD" != true ]; then curl -C - -L \ -O "https://github.com/ianlancetaylor/libbacktrace/archive/$LIBBACKTRACE.tar.gz" \ -O "https://github.com/libsdl-org/SDL/releases/download/release-$SDL3/SDL3-$SDL3.tar.gz" \ -o "cpuinfo-$CPUINFO.tar.gz" "https://github.com/stenzek/cpuinfo/archive/$CPUINFO.tar.gz" \ -o "discord-rpc-$DISCORD_RPC.tar.gz" "https://github.com/stenzek/discord-rpc/archive/$DISCORD_RPC.tar.gz" \ -o "lunasvg-$LUNASVG.tar.gz" "https://github.com/stenzek/lunasvg/archive/$LUNASVG.tar.gz" \ -o "shaderc-$SHADERC.tar.gz" "https://github.com/stenzek/shaderc/archive/$SHADERC.tar.gz" \ -o "soundtouch-$SOUNDTOUCH.tar.gz" "https://github.com/stenzek/soundtouch/archive/$SOUNDTOUCH.tar.gz" fi cat > SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS <> SHASUMS < "$TOOLCHAINFILE" << EOF set(CMAKE_CROSSCOMPILING TRUE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR ${CROSSARCH}) set(CMAKE_C_COMPILER "/usr/bin/${CROSSARCH}-linux-gnu-gcc") set(CMAKE_C_COMPILER_TARGET "${CROSSARCH}-linux-gnu") set(CMAKE_C_COMPILER_AR "/usr/bin/${CROSSARCH}-linux-gnu-ar") set(CMAKE_C_COMPILER_RANLIB "/usr/bin/${CROSSARCH}-linux-gnu-ranlib") set(CMAKE_CXX_COMPILER "/usr/bin/${CROSSARCH}-linux-gnu-g++") set(CMAKE_CXX_COMPILER_TARGET "${CROSSARCH}-linux-gnu") set(CMAKE_CXX_COMPILER_AR "/usr/bin/${CROSSARCH}-linux-gnu-ar") set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/${CROSSARCH}-linux-gnu-ranlib") set(CMAKE_FIND_ROOT_PATH "${INSTALLDIR};${SYSROOTDIR}") set(CMAKE_SYSROOT "${SYSROOTDIR}") set(CMAKE_PKG_CONFIG_PC_PATH "${PKG_CONFIG_PATH}") set(CMAKE_PKG_CONFIG_SYSROOT_DIR "${PKG_CONFIG_SYSROOT_DIR}") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) EOF # NOTE: Must be a shared library because otherwise aarch64 libgcc symbols are missing when building with clang. echo "Building libbacktrace..." rm -fr "libbacktrace-$LIBBACKTRACE" tar xf "$LIBBACKTRACE.tar.gz" cd "libbacktrace-$LIBBACKTRACE" ./configure --prefix="$INSTALLDIR" --build=x86_64-linux-gnu --host="${CROSSARCH}-linux-gnu" --with-pic --enable-shared --disable-static make make install cd .. if [ "$SKIP_LIBPNG" != true ]; then echo "Building libpng..." rm -fr "libpng-$LIBPNG" tar xf "libpng-$LIBPNG.tar.xz" cd "libpng-$LIBPNG" cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DPNG_TESTS=OFF -DPNG_STATIC=OFF -DPNG_SHARED=ON -DPNG_TOOLS=OFF -B build -G Ninja cmake --build build --parallel ninja -C build install cd .. fi if [ "$SKIP_LIBJPEG" != true ]; then echo "Building libjpeg..." rm -fr "libjpeg-turbo-$LIBJPEGTURBO" tar xf "libjpeg-turbo-$LIBJPEGTURBO.tar.gz" cd "libjpeg-turbo-$LIBJPEGTURBO" cmake "${CMAKE_COMMON[@]}" -DENABLE_STATIC=OFF -DENABLE_SHARED=ON -B build -G Ninja cmake --build build --parallel ninja -C build install cd .. fi if [ "$SKIP_ZSTD" != true ]; then echo "Building Zstandard..." rm -fr "zstd-$ZSTD" tar xf "zstd-$ZSTD.tar.gz" cd "zstd-$ZSTD" cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DZSTD_BUILD_SHARED=ON -DZSTD_BUILD_STATIC=OFF -DZSTD_BUILD_PROGRAMS=OFF -B build -G Ninja build/cmake cmake --build build --parallel ninja -C build install cd .. fi if [ "$SKIP_LIBWEBP" != true ]; then echo "Building WebP..." rm -fr "libwebp-$LIBWEBP" tar xf "libwebp-$LIBWEBP.tar.gz" cd "libwebp-$LIBWEBP" cmake "${CMAKE_COMMON[@]}" -B build -G Ninja \ -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF -DWEBP_BUILD_GIF2WEBP=OFF -DWEBP_BUILD_IMG2WEBP=OFF \ -DWEBP_BUILD_VWEBP=OFF -DWEBP_BUILD_WEBPINFO=OFF -DWEBP_BUILD_WEBPMUX=OFF -DWEBP_BUILD_EXTRAS=OFF -DBUILD_SHARED_LIBS=ON cmake --build build --parallel ninja -C build install cd .. fi if [ "$SKIP_LIBZIP" != true ]; then echo "Building libzip..." rm -fr "libzip-$LIBZIP" tar xf "libzip-$LIBZIP.tar.xz" cd "libzip-$LIBZIP" cmake "${CMAKE_COMMON[@]}" -B build -G Ninja \ -DENABLE_COMMONCRYPTO=OFF -DENABLE_GNUTLS=OFF -DENABLE_MBEDTLS=OFF -DENABLE_OPENSSL=OFF -DENABLE_WINDOWS_CRYPTO=OFF \ -DENABLE_BZIP2=OFF -DENABLE_LZMA=OFF -DENABLE_ZSTD=ON -DBUILD_SHARED_LIBS=ON -DLIBZIP_DO_INSTALL=ON \ -DBUILD_TOOLS=OFF -DBUILD_REGRESS=OFF -DBUILD_OSSFUZZ=OFF -DBUILD_EXAMPLES=OFF -DBUILD_DOC=OFF cmake --build build --parallel ninja -C build install cd .. fi if [ "$SKIP_FREETYPE" != true ]; then if [ "$SKIP_HARFBUZZ" != true ]; then echo "Building FreeType without HarfBuzz..." rm -fr "freetype-$FREETYPE" tar xf "freetype-$FREETYPE.tar.xz" cd "freetype-$FREETYPE" cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DFT_REQUIRE_ZLIB=ON -DFT_REQUIRE_PNG=ON -DFT_DISABLE_BZIP2=TRUE -DFT_DISABLE_BROTLI=TRUE -DFT_DISABLE_HARFBUZZ=TRUE -B build -G Ninja cmake --build build --parallel ninja -C build install cd .. echo "Building HarfBuzz..." rm -fr "harfbuzz-$HARFBUZZ" tar xf "harfbuzz-$HARFBUZZ.tar.gz" cd "harfbuzz-$HARFBUZZ" cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DHB_BUILD_UTILS=OFF -B build -G Ninja cmake --build build --parallel ninja -C build install cd .. fi echo "Building FreeType with HarfBuzz..." rm -fr "freetype-$FREETYPE" tar xf "freetype-$FREETYPE.tar.xz" cd "freetype-$FREETYPE" cmake "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DFT_REQUIRE_ZLIB=ON -DFT_REQUIRE_PNG=ON -DFT_DISABLE_BZIP2=TRUE -DFT_DISABLE_BROTLI=TRUE -DFT_REQUIRE_HARFBUZZ=TRUE -B build -G Ninja cmake --build build --parallel ninja -C build install cd .. fi echo "Building SDL..." rm -fr "SDL3-$SDL3" tar xf "SDL3-$SDL3.tar.gz" cd "SDL3-$SDL3" # needed because -Isystem with chroot/usr/include breaks patch -p1 < "$SCRIPTDIR/sdl2-disable-isystem.patch" cmake -B build "${CMAKE_COMMON[@]}" -DBUILD_SHARED_LIBS=ON -DSDL_SHARED=ON -DSDL_STATIC=OFF -DSDL_TESTS=OFF -G Ninja cmake --build build --parallel ninja -C build install cd .. if [ "$SKIP_QT" != true ]; then # Couple notes: # -fontconfig is needed otherwise Qt Widgets render only boxes. # -qt-doubleconversion avoids a dependency on libdouble-conversion. # ICU avoids pulling in a bunch of large libraries, and hopefully we can get away without it. # OpenGL is needed to render window decorations in Wayland, apparently. # dbus-runtime and linked off to avoid a relocation error (different to host.. probably should change that). echo "Building Qt Base..." rm -fr "qtbase-everywhere-src-$QT" tar xf "qtbase-everywhere-src-$QT.tar.xz" cd "qtbase-everywhere-src-$QT" patch -p1 < "$SCRIPTDIR/qtbase-disable-pcre2-jit.patch" mkdir build cd build ../configure -prefix "$INSTALLDIR" -extprefix "$INSTALLDIR" -qt-host-path "$HOSTDIR" -release -dbus runtime -gui -widgets -fontconfig -qt-doubleconversion -ssl -openssl-runtime -opengl desktop -qpa xcb,wayland -xkbcommon -xcb -gtk -- -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAINFILE" -DFEATURE_cups=OFF -DFEATURE_dbus=ON -DFEATURE_dbus_linked=OFF -DFEATURE_icu=OFF -DFEATURE_sql=OFF -DFEATURE_system_png=ON -DFEATURE_system_jpeg=ON -DFEATURE_system_zlib=ON -DFEATURE_system_freetype=ON -DFEATURE_system_harfbuzz=ON cmake --build . --parallel ninja install cd ../../ echo "Building Qt SVG..." rm -fr "qtsvg-everywhere-src-$QT" tar xf "qtsvg-everywhere-src-$QT.tar.xz" cd "qtsvg-everywhere-src-$QT" mkdir build cd build "$INSTALLDIR/bin/qt-configure-module" .. -- -DCMAKE_PREFIX_PATH="$INSTALLDIR" cmake --build . --parallel ninja install cd ../../ echo "Building Qt Image Formats..." rm -fr "qtimageformats-everywhere-src-$QT" tar xf "qtimageformats-everywhere-src-$QT.tar.xz" cd "qtimageformats-everywhere-src-$QT" mkdir build cd build "$INSTALLDIR/bin/qt-configure-module" .. -- -DCMAKE_PREFIX_PATH="$INSTALLDIR" -DFEATURE_system_webp=ON cmake --build . --parallel ninja install cd ../../ echo "Building Qt Wayland..." rm -fr "qtwayland-everywhere-src-$QT" tar xf "qtwayland-everywhere-src-$QT.tar.xz" cd "qtwayland-everywhere-src-$QT" mkdir build cd build "$INSTALLDIR/bin/qt-configure-module" .. -- -DCMAKE_PREFIX_PATH="$INSTALLDIR" -DFEATURE_wayland_server=OFF cmake --build . --parallel ninja install cd ../../ echo "Installing Qt Tools..." rm -fr "qttools-everywhere-src-$QT" tar xf "qttools-everywhere-src-$QT.tar.xz" cd "qttools-everywhere-src-$QT" # Force disable clang scanning, it gets very confused. patch -u configure.cmake <