singe/build-all.sh

362 lines
8.7 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"
export PKG_CONFIG_LIBDIR="${G_TARGET}/lib/pkgconfig"
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
fi
pushd thirdparty/bzip2
clearAndEnterBuild
cmake ${COMMON} \
-DENABLE_SHARED_LIB=off \
-DENABLE_STATIC_LIB=on \
-DENABLE_LIB_ONLY=on \
..
make install
popd
pushd thirdparty/xz
clearAndEnterBuild
cmake ${COMMON} \
-DBUILD_SHARED_LIBS=off \
-DBUILD_TESTING=off \
..
make install
popd
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/SDL2
clearAndEnterBuild
cmake ${COMMON} \
-DSDL_SHARED=off \
-DSDL_STATIC=on \
..
make install
popd
pushd thirdparty/SDL2_image
clearAndEnterBuild
CFLAGS="-Iexternal/libpng ${CFLAGS}" \
cmake ${COMMON} \
-DBUILD_SHARED_LIBS=off \
-DSDL2IMAGE_DEPS_SHARED=off \
-DSDL2IMAGE_SAMPLES=off \
-DSDL2IMAGE_TESTS=off \
-DSDL2IMAGE_VENDORED=on \
-DSDL2IMAGE_BACKEND_STB=off \
-DSDL2IMAGE_AVIF=off \
-DSDL2IMAGE_JXL=off \
-DSDL2IMAGE_TIF=off \
-DSDL2IMAGE_WEBP=on \
-DSDL2_LIBRARY="${G_TARGET}/lib/libSDL2.a" \
-DSDL2_INCLUDE_DIR="${G_TARGET}/include/SDL2" \
-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' fails on zlib, which we don't want anyway.
make
cp -f ../include/SDL_image.h "${G_TARGET}/include/SDL2/."
cp -f libSDL2_image.a "${G_TARGET}/lib/."
cp -f external/libwebp/libwebp.a "${G_TARGET}/lib/."
cp -f external/libwebp/libwebpdemux.a "${G_TARGET}/lib/."
if [[ "${OS}" != "macos" ]]; then
cp -f external/jpeg/libjpeg.a "${G_TARGET}/lib/."
cp -f external/libpng/libpng.a "${G_TARGET}/lib/."
fi
popd
pushd thirdparty/SDL2_mixer
clearAndEnterBuild
cmake ${COMMON} \
-DBUILD_SHARED_LIBS=off \
-DSDL2MIXER_CMD=off \
-DSDL2MIXER_DEPS_SHARED=off \
-DSDL2MIXER_VENDORED=on \
-DSDL2MIXER_SAMPLES=off \
-DSDL2_DIR=${G_TARGET}/lib/cmake/SDL2 \
-DWAVPACK_ENABLE_ASM=no \
..
make install
popd
pushd thirdparty/SDL2_ttf
clearAndEnterBuild
cmake ${COMMON} \
-DBUILD_SHARED_LIBS=off \
-DSDL2TTF_VENDORED=on \
-DSDL2TTF_HARFBUZZ=off \
-DSDL2TTF_SAMPLES=off \
-DSDL2_DIR=${G_TARGET}/lib/cmake/SDL2 \
..
make install
popd
pushd thirdparty/libarchive
clearAndEnterBuild
cmake ${COMMON} \
-DBUILD_SHARED_LIBS=off \
-DBUILD_TESTING=off \
-DENABLE_CAT=off \
-DENABLE_CNG=off \
-DENABLE_CPIO=off \
-DENABLE_EXPAT=off \
-DENABLE_ICONV=off \
-DENABLE_LIBB2=off \
-DENABLE_LIBGCC=off \
-DENABLE_LIBXML2=off \
-DENABLE_LZ4=off \
-DENABLE_LZO=off \
-DENABLE_MBEDTLS=off \
-DENABLE_NETTLE=off \
-DENABLE_OPENSSL=off \
-DENABLE_PCREPOSIX=off \
-DENABLE_TAR=off \
-DENABLE_TEST=off \
-DENABLE_UNZIP=off \
-DPOSIX_REGEX_LIB=libc \
-DUSE_BZIP2_STATIC=on \
-DBZIP2_INCLUDE_DIR="${G_TARGET}/include" \
-DBZIP2_LIBRARIES="${G_TARGET}/lib/libbz2_static.a" \
-DZLIB_ROOT="${G_TARGET}" \
-DLIBLZMA_INCLUDE_DIR="${G_TARGET}/include" \
-DLIBLZMA_LIBRARY="${G_TARGET}/lib/liblzma.a" \
-DZSTD_INCLUDE_DIR="${G_TARGET}/include" \
-DZSTD_LIBRARY="${G_TARGET}/lib/libzstd.a" \
-DWINDOWS_VERSION=VISTA \
..
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
pushd thirdparty/ffmpeg
clearAndEnterBuild
# https://trac.ffmpeg.org/wiki/CompilationGuide/CrossCompilingForWindows
../configure \
--enable-static \
--disable-shared \
--disable-debug \
--disable-muxers \
--disable-hwaccels \
--disable-encoders \
--disable-filters \
--disable-network \
--disable-devices \
--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
pushd thirdparty/ffms2
# The configure script is not checked in; generate it once.
[[ -x configure ]] || NOCONFIGURE=1 ./autogen.sh
clearAndEnterBuild
../configure \
--prefix=${G_TARGET} \
--with-zlib=${G_TARGET} \
--enable-static \
--disable-shared \
--target=${TRIPLE} \
--host=${TRIPLE} \
--build=x86_64-linux
make install-libLTLIBRARIES # This weird target prevents building the command line tools.
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
# 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