417 lines
10 KiB
Bash
Executable file
417 lines
10 KiB
Bash
Executable file
#!/bin/bash -xe
|
|
|
|
#
|
|
# 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 2
|
|
# 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_TARGET=
|
|
G_GENERATED=
|
|
|
|
|
|
function buildAll() {
|
|
local OS=$1
|
|
local ARCH=$2
|
|
local TRIPLE=
|
|
local SUFFIX=
|
|
local TOOLCHAIN=
|
|
local COMMON=
|
|
local CROSS_OS=
|
|
local OSXCROSS_LOCATION=
|
|
|
|
|
|
case "${OS}" in
|
|
|
|
linux)
|
|
case "${ARCH}" in
|
|
x86)
|
|
TRIPLE="i686-linux-gnu"
|
|
;;
|
|
x86_64)
|
|
TRIPLE="x86_64-linux-gnu"
|
|
;;
|
|
esac
|
|
CROSS_OS="linux"
|
|
;;
|
|
|
|
macos)
|
|
case "${ARCH}" in
|
|
aarch64)
|
|
TRIPLE="aarch64-apple-darwin22.4"
|
|
OSXCROSS_LOCATION=${G_BUILDROOT}/../toolchains/x-tools/aarch64-macos-apple
|
|
;;
|
|
x86)
|
|
TRIPLE="i386-apple-darwin17"
|
|
OSXCROSS_LOCATION=${G_BUILDROOT}/../toolchains/x-tools/x86_64-macos-apple
|
|
;;
|
|
x86_64)
|
|
TRIPLE="x86_64-apple-darwin17"
|
|
OSXCROSS_LOCATION=${G_BUILDROOT}/../toolchains/x-tools/x86_64-macos-apple
|
|
;;
|
|
esac
|
|
CROSS_OS="darwin"
|
|
source <("${OSXCROSS_LOCATION}/bin/osxcross-conf" 2>/dev/null)
|
|
export OSXCROSS_LOCATION
|
|
;;
|
|
|
|
|
|
windows)
|
|
case "${ARCH}" in
|
|
x86)
|
|
TRIPLE="i686-w64-mingw32"
|
|
;;
|
|
x86_64)
|
|
TRIPLE="x86_64-w64-mingw32"
|
|
;;
|
|
esac
|
|
SUFFIX=".exe"
|
|
CROSS_OS="mingw32"
|
|
;;
|
|
|
|
esac
|
|
|
|
G_TARGET=${G_BUILDROOT}/build/${OS}/${ARCH}
|
|
G_GENERATED=${G_TARGET}/generated
|
|
TOOLCHAIN=${G_BUILDROOT}/../toolchains/cmake/${TRIPLE}.cmake
|
|
COMMON="-DCMAKE_INSTALL_PREFIX=${G_TARGET} -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN}"
|
|
# Add CMAKE_BUILD_TYPE to COMMON
|
|
|
|
mkdir -p ${G_GENERATED}
|
|
|
|
#export LD_FLAGS="-L ${G_TARGET}/lib"
|
|
#export C_FLAGS="-I ${G_TARGET}/include"
|
|
#export CXX_FLAGS=${C_FLAGS}
|
|
export LD_LIBRARY_PATH=${G_TARGET}
|
|
export PKG_CONFIG_LIBDIR=${G_TARGET}/lib/pkgconfig
|
|
|
|
#:<<SKIP
|
|
pushd thirdparty/SDL2
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DSDL_SHARED=off \
|
|
-DSDL_STATIC=on \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/SDL2_image
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} \
|
|
-DBUILD_SHARED_LIBS=off \
|
|
-DSDL2IMAGE_DEPS_SHARED=off \
|
|
-DSDL2IMAGE_SAMPLES=off \
|
|
-DSDL2IMAGE_TESTS=off \
|
|
-DSDL2IMAGE_VENDORED=on \
|
|
-DSDL2IMAGE_AVIF=on \
|
|
-DSDL2IMAGE_JXL=on \
|
|
-DSDL2IMAGE_TIF=on \
|
|
-DSDL2IMAGE_WEBP=on \
|
|
-DSDL2_DIR=${G_TARGET}/lib/cmake/SDL2 \
|
|
..
|
|
make install
|
|
popd
|
|
if [[ "${OS}" == "windows" ]]; then
|
|
mv ${G_TARGET}/lib/libjxl_dec-static.a ${G_TARGET}/lib/libjxl_dec.a
|
|
fi
|
|
|
|
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=on \
|
|
-DSDL2TTF_SAMPLES=off \
|
|
-DSDL2_DIR=${G_TARGET}/lib/cmake/SDL2 \
|
|
..
|
|
make install
|
|
popd
|
|
|
|
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
|
|
cmake ${COMMON} ..
|
|
make install
|
|
popd
|
|
if [[ "${OS}" == "windows" ]]; then
|
|
mv ${G_TARGET}/lib/libzlibstatic.a ${G_TARGET}/lib/libz.a
|
|
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 \
|
|
--enable-gpl \
|
|
--enable-version3 \
|
|
--extra-ldflags="-L${G_TARGET}/lib -l:libz.a -l:liblzma.a" \
|
|
--prefix=${G_TARGET} \
|
|
--arch=${ARCH} \
|
|
--target-os=${CROSS_OS} \
|
|
--cross-prefix=${TRIPLE}-
|
|
make install
|
|
popd
|
|
|
|
pushd thirdparty/ffms2
|
|
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
|
|
|
|
# === Known FFMPEG Types ===
|
|
createExtensionHeader "${G_TARGET}/bin/ffmpeg" > ${G_GENERATED}/extensions.h
|
|
|
|
# === Overlay Font ===
|
|
createEmbeddedImage font
|
|
|
|
# === Window Icon ===
|
|
createEmbeddedImage icon
|
|
|
|
# === Kangaroo Punch Logo ===
|
|
createEmbeddedImage kangarooPunchLogo
|
|
|
|
# === Singe Logo ===
|
|
createEmbeddedImage singeLogo
|
|
|
|
# === Laser Disc ===
|
|
createEmbeddedImage laserDisc
|
|
|
|
# === Magnifying Glass ===
|
|
createEmbeddedImage magnifyingGlass
|
|
|
|
# === "Indexing" Text ===
|
|
createEmbeddedImage indexing
|
|
|
|
# === Singe Framework ===
|
|
createEmbeddedBinary assets/Framework.singe ${G_GENERATED}/Framework_singe.h FRAMEWORK_SINGE_H
|
|
|
|
# === Default Config ===
|
|
createEmbeddedBinary assets/controls.cfg ${G_GENERATED}/controls_cfg.h CONTROLS_CFG_H
|
|
|
|
# === Singe Menu App ===
|
|
createEmbeddedBinary assets/Menu.singe ${G_GENERATED}/Menu_singe.h MENU_SINGE_H
|
|
|
|
# === Singe Menu Font ===
|
|
createEmbeddedBinary assets/FreeSansBold.ttf ${G_GENERATED}/FreeSansBold_ttf.h FREESANSBOLD_TTF_H
|
|
|
|
# === Singe Menu Background Video ===
|
|
ffmpeg -i "assets/Singe Engine Intro.mpg" -filter:v 'crop=ih/3*4:ih' -vf scale=720:480 -c:v libx264 -c:a aac ${G_TARGET}/temp1.mkv
|
|
ffmpeg -i assets/180503_01_PurpleGrid.mp4 -filter:v 'crop=ih/3*4:ih' -vf scale=720:480 -c:v libx264 -c:a aac ${G_TARGET}/temp2.mkv
|
|
ffmpeg -f concat -safe 0 -i <(echo -e "file ${G_TARGET}/temp1.mkv\nfile ${G_TARGET}/temp2.mkv\n") -c copy ${G_TARGET}/menuBackground.mkv
|
|
createEmbeddedBinary ${G_TARGET}/menuBackground.mkv ${G_GENERATED}/menuBackground_mkv.h MENUBACKGROUND_MKV_H
|
|
rm ${G_TARGET}/temp1.mkv ${G_TARGET}/temp2.mkv ${G_TARGET}/menuBackground.mkv
|
|
#SKIP
|
|
|
|
:<<UNUSED
|
|
# === Singe Manual ===
|
|
#libreoffice --headless "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" --convert-to pdf:writer_pdf_Export Manual.odt
|
|
documentbuilder makePDFs.docbuilder
|
|
mv /tmp/Manual.pdf ${G_TARGET}/.
|
|
createEmbeddedBinary ${G_TARGET}/Manual.pdf ${G_GENERATED}/Manual_pdf.h MANUAL_H
|
|
rm ${G_TARGET}/Manual.pdf
|
|
UNUSED
|
|
|
|
pushd ${G_TARGET}
|
|
clearAndEnterBuild
|
|
cmake ${COMMON} ${G_BUILDROOT}
|
|
make
|
|
upx -9 singe2${SUFFIX}
|
|
mv -f singe2${SUFFIX} ../Singe-v2.10-${OS}-${ARCH}${SUFFIX}
|
|
popd
|
|
}
|
|
|
|
|
|
function clearAndEnterBuild() {
|
|
[[ -d build ]] && rm -rf build
|
|
mkdir -p build
|
|
cd build
|
|
}
|
|
|
|
|
|
function createEmbeddedBinary() {
|
|
local BINFILE=$1
|
|
local SOURCEFILE=$2 # This is assumed to be an absolute path
|
|
local BLOCKER=$3
|
|
local FILENAME=$(basename ${BINFILE})
|
|
local DIRNAME=$(dirname ${BINFILE})
|
|
|
|
outputLicense > ${SOURCEFILE}
|
|
outputHeader ${BLOCKER} >> ${SOURCEFILE}
|
|
printf "\n#ifdef EMBED_HERE\n\n" >> ${SOURCEFILE}
|
|
pushd ${DIRNAME}
|
|
xxd -i ${FILENAME} >> ${SOURCEFILE}
|
|
popd
|
|
printf "\n#else // EMBED_HERE\n\n" >> ${SOURCEFILE}
|
|
printf "extern unsigned char ${FILENAME/\./_}[];\n" >> ${SOURCEFILE}
|
|
printf "extern unsigned int ${FILENAME/\./_}_len;\n" >> ${SOURCEFILE}
|
|
printf "\n#endif // EMBED_HERE\n\n" >> ${SOURCEFILE}
|
|
outputFooter ${BLOCKER} >> ${SOURCEFILE}
|
|
}
|
|
|
|
|
|
function createEmbeddedImage() {
|
|
local BASENAME=$1
|
|
|
|
pushd assets
|
|
convert -flatten ${BASENAME}.xcf ${G_GENERATED}/${BASENAME}.png
|
|
createEmbeddedBinary ${G_GENERATED}/${BASENAME}.png ${G_GENERATED}/${BASENAME}.h ${BASENAME^^}_H
|
|
rm ${G_GENERATED}/${BASENAME}.png
|
|
popd
|
|
}
|
|
|
|
|
|
function createExtensionHeader() {
|
|
local FFMPEG=$1
|
|
local a=
|
|
local c=0
|
|
|
|
outputLicense
|
|
outputHeader FFMPEG_EXTENSIONS_H
|
|
printf "static char *ffmpegExtensions[] = {\n"
|
|
printf "\t"
|
|
getExtensions "${FFMPEG}" | sort | uniq -u | while read a; do
|
|
printf "\"${a}\", "
|
|
c=$((c + 1))
|
|
if [[ ${c} -ge 10 ]]; then
|
|
printf "\n\t"
|
|
c=0
|
|
fi
|
|
done
|
|
printf "0\n};"
|
|
outputFooter FFMPEG_EXTENSIONS_H
|
|
}
|
|
|
|
|
|
function getExtensions() {
|
|
local FFMPEG=$1
|
|
local a=
|
|
local b=
|
|
local c=
|
|
local d=
|
|
local e=
|
|
local f=
|
|
local g=
|
|
|
|
"${FFMPEG}" -demuxers 2> /dev/null | while read a b c; do
|
|
if [[ "${a}x" == "Dx" ]]; then
|
|
"${FFMPEG}" -h demuxer=${b} 2> /dev/null | grep "Common extensions" | while read d e f; do
|
|
g=${f/./}
|
|
echo -e "${g//,/\\n}"
|
|
done
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
function outputFooter() {
|
|
local BLOCKER=$1
|
|
|
|
printf "\n#pragma GCC diagnostic pop\n\n\n#endif // ${BLOCKER}\n"
|
|
}
|
|
|
|
|
|
function outputHeader() {
|
|
local BLOCKER=$1
|
|
|
|
printf "\n\n#ifndef ${BLOCKER}\n#define ${BLOCKER}\n\n\n"
|
|
printf "// ===== THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT =====\n\n\n"
|
|
printf "#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wunused-variable\"\n"
|
|
}
|
|
|
|
|
|
function outputLicense() {
|
|
cat <<- LICENSE
|
|
/*
|
|
*
|
|
* 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 License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* 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.
|
|
*
|
|
*/
|
|
LICENSE
|
|
}
|
|
|
|
|
|
#buildAll linux x86
|
|
#buildAll linux x86_64
|
|
buildAll macos aarch64
|
|
#buildAll macos x86 #***TODO*** Needs older SDL2
|
|
#buildAll macos x86_64 #***TODO*** Needs older SDL2
|
|
#buildAll windows x86
|
|
#buildAll windows x86_64
|