313 lines
8 KiB
Bash
Executable file
313 lines
8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#
|
|
# Singe 2
|
|
# Copyright (C) 2006-2024 Scott Duensing <scott@kangaroopunch.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public Licens
|
|
# as published by the Free Software Foundation; either version 3
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
# 02110-1301, USA.
|
|
#
|
|
|
|
|
|
G_BUILDROOT=${PWD}
|
|
G_BUILDDIR=.builddir
|
|
G_TARGET=
|
|
G_GENERATED=
|
|
|
|
|
|
function buildAll() {
|
|
local OS=$1
|
|
local ARCH=$2
|
|
local COMMON=
|
|
local OPT1=
|
|
|
|
# Activate toolchain for this platform.
|
|
source <(../toolchains/toolchains.sh use ${ARCH} ${OS})
|
|
|
|
G_TARGET=${G_BUILDROOT}/${G_BUILDDIR}/${OS}/${ARCH}
|
|
G_GENERATED=${G_TARGET}/generated
|
|
COMMON="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${G_TARGET} -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}"
|
|
|
|
export LDFLAGS="-L${G_TARGET}/lib ${LDFLAGS:-}"
|
|
export CFLAGS="-I${G_TARGET}/include ${CFLAGS:-}"
|
|
export CXXFLAGS="-I${G_TARGET}/include ${CXXFLAGS:-}"
|
|
export LD_LIBRARY_PATH="${G_TARGET}/lib"
|
|
# Our own libraries first, then the platform's (FFmpeg's hardware decoders need libva and libdrm).
|
|
export PKG_CONFIG_LIBDIR="${G_TARGET}/lib/pkgconfig"
|
|
if [[ "${OS}" == "linux" ]]; then
|
|
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:/usr/lib/${TRIPLE}/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig"
|
|
elif [[ "${OS}" == "pi" ]]; then
|
|
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:${SYSROOT}/usr/lib/${TRIPLE}/pkgconfig:${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
|
|
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
|
|
fi
|
|
|
|
mkdir -p ${G_GENERATED}
|
|
|
|
# Needed for Pi sysroot.
|
|
if [[ "${OS}" == "pi" ]]; then
|
|
export CFLAGS="--sysroot=${SYSROOT} ${CFLAGS}"
|
|
export CXXFLAGS="--sysroot=${SYSROOT} ${CXXFLAGS}"
|
|
sudo chroot ${SYSROOT} apt-get -y install libasound-dev libxi-dev libvdpau-dev libdrm-dev
|
|
fi
|
|
|
|
pushd thirdparty/zlib
|
|
clearAndEnterBuild
|
|
CFLAGS="-I${PWD}" ../configure \
|
|
--prefix=${G_TARGET} \
|
|
--static
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/zstd
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DZSTD_BUILD_SHARED=off \
|
|
-DZSTD_BUILD_STATIC=on \
|
|
-DZSTD_BUILD_PROGRAMS=off \
|
|
../build/cmake
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/SDL3
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DSDL_SHARED=off \
|
|
-DSDL_STATIC=on \
|
|
-DSDL_TESTS=off \
|
|
-DSDL_EXAMPLES=off \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/SDL3_image
|
|
clearAndEnterBuild
|
|
# The vendored libpng must see the vendored zlib, not the one under ${G_TARGET}/include.
|
|
CFLAGS="${CFLAGS#-I${G_TARGET}/include}" \
|
|
cmake ${COMMON} \
|
|
-DBUILD_SHARED_LIBS=off \
|
|
-DSDLIMAGE_DEPS_SHARED=off \
|
|
-DSDLIMAGE_SAMPLES=off \
|
|
-DSDLIMAGE_TESTS=off \
|
|
-DSDLIMAGE_VENDORED=on \
|
|
-DSDLIMAGE_BACKEND_STB=off \
|
|
-DSDLIMAGE_AVIF=off \
|
|
-DSDLIMAGE_JXL=off \
|
|
-DSDLIMAGE_TIF=off \
|
|
-DSDLIMAGE_WEBP=on \
|
|
-DSDL3_DIR=${G_TARGET}/lib/cmake/SDL3 \
|
|
-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 \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/SDL3_mixer
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DBUILD_SHARED_LIBS=off \
|
|
-DSDLMIXER_DEPS_SHARED=off \
|
|
-DSDLMIXER_VENDORED=on \
|
|
-DSDLMIXER_EXAMPLES=off \
|
|
-DSDLMIXER_TESTS=off \
|
|
-DSDLMIXER_FLAC_LIBFLAC=off \
|
|
-DSDLMIXER_MP3_MPG123=off \
|
|
-DSDLMIXER_VORBIS_STB=on \
|
|
-DSDLMIXER_VORBIS_VORBISFILE=off \
|
|
-DSDLMIXER_VORBIS_TREMOR=off \
|
|
-DSDLMIXER_GME=off \
|
|
-DSDLMIXER_MIDI_FLUIDSYNTH=off \
|
|
-DSDL3_DIR=${G_TARGET}/lib/cmake/SDL3 \
|
|
-DWAVPACK_ENABLE_ASM=no \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/SDL3_ttf
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DBUILD_SHARED_LIBS=off \
|
|
-DSDLTTF_VENDORED=on \
|
|
-DSDLTTF_HARFBUZZ=off \
|
|
-DSDLTTF_PLUTOSVG=off \
|
|
-DSDLTTF_SAMPLES=off \
|
|
-DSDL3_DIR=${G_TARGET}/lib/cmake/SDL3 \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/openssl
|
|
clearAndEnterBuild
|
|
if [[ "${OS}" == "windows" ]]; then
|
|
if [[ "${ARCH}" == "x86" ]]; then
|
|
OPT1="mingw"
|
|
else
|
|
OPT1="mingw64"
|
|
fi
|
|
else
|
|
OPT1=""
|
|
fi
|
|
if [[ "${OS}" == "pi" ]]; then
|
|
if [[ "${ARCH}" == "aarch64" ]]; then
|
|
OPT1="linux-aarch64"
|
|
else
|
|
OPT1="linux-arm4"
|
|
fi
|
|
fi
|
|
if [[ "${OS}" == "macos" ]]; then
|
|
if [[ "${ARCH}" == "aarch64" ]]; then
|
|
OPT1="darwin64-arm64"
|
|
else
|
|
OPT1="darwin64-x86_64"
|
|
fi
|
|
fi
|
|
../Configure ${OPT1} \
|
|
--prefix="${G_TARGET}" \
|
|
--libdir=lib \
|
|
--with-zlib-include="${G_TARGET}/include" \
|
|
--with-zlib-lib="${G_TARGET}/lib" \
|
|
--with-zstd-include="${G_TARGET}/include" \
|
|
--with-zstd-lib="${G_TARGET}/lib" \
|
|
no-apps \
|
|
no-docs \
|
|
no-dso \
|
|
no-dynamic-engine \
|
|
no-module \
|
|
no-shared \
|
|
no-tests \
|
|
zlib \
|
|
enable-zstd
|
|
make build_sw
|
|
make install_sw
|
|
popd
|
|
|
|
if [[ "${OS}" == "pi" ]]; then
|
|
# Hack to make ffmpeg compile.
|
|
mkdir -p "${G_TARGET}/include/sys"
|
|
echo "/* File no longer used */" > "${G_TARGET}/include/sys/sysctl.h"
|
|
fi
|
|
# Hardware decoding: each platform's native API. The libraries these pull in are read back
|
|
# from FFmpeg's pkg-config files by CMakeLists.txt, so the link follows this choice.
|
|
case "${OS}" in
|
|
linux) HWACCEL="--enable-vaapi --enable-vdpau --enable-libdrm" ;;
|
|
pi) HWACCEL="--enable-v4l2-m2m --enable-libdrm" ;;
|
|
macos) HWACCEL="--enable-videotoolbox" ;;
|
|
windows) HWACCEL="--enable-d3d11va --enable-dxva2" ;;
|
|
*) HWACCEL="" ;;
|
|
esac
|
|
pushd thirdparty/ffmpeg
|
|
clearAndEnterBuild
|
|
# https://trac.ffmpeg.org/wiki/CompilationGuide/CrossCompilingForWindows
|
|
../configure \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--disable-debug \
|
|
--disable-muxers \
|
|
${HWACCEL} \
|
|
--disable-encoders \
|
|
--disable-filters \
|
|
--disable-network \
|
|
--disable-devices \
|
|
--disable-bzlib \
|
|
--disable-lzma \
|
|
--disable-doc \
|
|
--disable-programs \
|
|
--enable-gpl \
|
|
--enable-version3 \
|
|
--extra-ldflags="-L${G_TARGET}/lib" \
|
|
--prefix=${G_TARGET} \
|
|
--arch=${ARCH} \
|
|
--target-os=${CROSS_OS} \
|
|
--cross-prefix=${TRIPLE}- \
|
|
--cc="${CC}" \
|
|
--cxx="${CXX}" \
|
|
--ranlib="${RANLIB}"
|
|
make install
|
|
popd
|
|
|
|
# Embedded resources, the version header, and the manual are generated by CMake.
|
|
|
|
pushd ${G_TARGET}
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} -DKANGAROO_OS=${OS} -DKANGAROO_ARCH=${ARCH} ${G_BUILDROOT}
|
|
make
|
|
# CMake names the binary Singe-v<version>-<Os>-<arch>.
|
|
mv -f Singe-v*${SUFFIX} ${G_BUILDROOT}/${G_BUILDDIR}/.
|
|
popd
|
|
}
|
|
|
|
|
|
function clearAndEnterBuild() {
|
|
[[ -d ${G_BUILDDIR} ]] && rm -rf ${G_BUILDDIR}
|
|
mkdir -p ${G_BUILDDIR}
|
|
cd ${G_BUILDDIR}
|
|
}
|
|
|
|
|
|
# -e = stop script on errors
|
|
# -u = stop script on undefined variable
|
|
# -o pipefail = stop pipeline if any step fails
|
|
set -euo pipefail
|
|
export MAKEFLAGS="${MAKEFLAGS:--j$(nproc)}"
|
|
|
|
if [[ ! -x ../toolchains/toolchains.sh ]]; then
|
|
echo "error: ../toolchains/toolchains.sh not found (see INSTALL)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
|
|
mkdir -p ${G_BUILDDIR}
|
|
|
|
|
|
# These are required for the build.
|
|
sudo apt-get install -y \
|
|
imagemagick \
|
|
lua5.4 \
|
|
ffmpeg \
|
|
asciidoctor \
|
|
ruby-asciidoctor-pdf \
|
|
autoconf \
|
|
automake \
|
|
libtool \
|
|
libasound-dev \
|
|
libxi-dev \
|
|
libvdpau-dev \
|
|
libva-dev \
|
|
libdrm-dev
|
|
|
|
|
|
# Usage: build-all.sh [os arch] (default: every supported platform)
|
|
if [[ $# -eq 2 ]]; then
|
|
buildAll "$1" "$2" 2>&1 | tee ${G_BUILDDIR}/$1-$2.log
|
|
else
|
|
buildAll linux x86_64 2>&1 | tee ${G_BUILDDIR}/linux-x86_64.log
|
|
buildAll macos aarch64 2>&1 | tee ${G_BUILDDIR}/macos-aarch64.log
|
|
buildAll pi aarch64 2>&1 | tee ${G_BUILDDIR}/pi-aarch64.log
|
|
buildAll windows x86_64 2>&1 | tee ${G_BUILDDIR}/windows-x86_64.log
|
|
fi
|
|
|
|
|
|
# === UNSUPPORTED ===
|
|
|
|
#buildAll macos x86_64 2>&1 | tee ${G_BUILDDIR}/macos-x86_64.log
|
|
#buildAll linux x86
|
|
#buildAll macos x86 #***TODO*** Needs older SDL2
|
|
#buildAll windows x86
|