2022-07-21 07:27:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-09-01 12:08:31 +00:00
|
|
|
# SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
|
|
|
# SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
2022-07-21 07:27:32 +00:00
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")
|
|
|
|
|
|
|
|
function retry_command {
|
|
|
|
# Package servers tend to be unreliable at times..
|
|
|
|
# Retry a bunch of times.
|
|
|
|
local RETRIES=10
|
|
|
|
|
|
|
|
for i in $(seq 1 "$RETRIES"); do
|
|
|
|
"$@" && break
|
|
|
|
if [ "$i" == "$RETRIES" ]; then
|
|
|
|
echo "Command \"$@\" failed after ${RETRIES} retries."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-07-21 07:27:32 +00:00
|
|
|
if [ "$#" -ne 4 ]; then
|
2023-09-05 12:03:02 +00:00
|
|
|
echo "Syntax: $0 <path to duckstation directory> <path to build directory> <deps prefix> <output name>"
|
2022-07-21 07:27:32 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
ROOTDIR=$1
|
|
|
|
BUILDDIR=$2
|
2022-07-21 07:27:32 +00:00
|
|
|
DEPSDIR=$3
|
|
|
|
NAME=$4
|
|
|
|
|
|
|
|
BINARY=duckstation-qt
|
|
|
|
APPDIRNAME=DuckStation.AppDir
|
2023-09-05 12:03:02 +00:00
|
|
|
STRIP=strip
|
2022-07-21 07:27:32 +00:00
|
|
|
|
2024-05-12 12:56:58 +00:00
|
|
|
declare -a MANUAL_LIBS=(
|
2024-07-04 04:40:16 +00:00
|
|
|
"libdiscord-rpc.so"
|
2024-08-25 10:53:25 +00:00
|
|
|
"libfreetype.so.6"
|
2024-06-14 04:37:33 +00:00
|
|
|
"libshaderc_shared.so"
|
2024-08-04 15:12:17 +00:00
|
|
|
"libspirv-cross-c-shared.so.0"
|
2024-05-12 12:56:58 +00:00
|
|
|
)
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
declare -a MANUAL_QT_LIBS=(
|
2022-07-21 07:27:32 +00:00
|
|
|
"libQt6WaylandEglClientHwIntegration.so.6"
|
|
|
|
)
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
declare -a MANUAL_QT_PLUGINS=(
|
|
|
|
"wayland-decoration-client"
|
|
|
|
"wayland-graphics-integration-client"
|
|
|
|
"wayland-shell-integration"
|
2022-07-21 07:27:32 +00:00
|
|
|
)
|
|
|
|
|
2024-06-16 06:21:24 +00:00
|
|
|
declare -a REMOVE_LIBS=(
|
|
|
|
'libwayland-client.so*'
|
|
|
|
'libwayland-cursor.so*'
|
|
|
|
'libwayland-egl.so*'
|
|
|
|
)
|
|
|
|
|
2022-07-21 07:27:32 +00:00
|
|
|
set -e
|
|
|
|
|
2024-07-13 08:24:52 +00:00
|
|
|
LINUXDEPLOY=./linuxdeploy-x86_64
|
|
|
|
LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_64
|
|
|
|
APPIMAGETOOL=./appimagetool-x86_64
|
2024-08-09 08:19:17 +00:00
|
|
|
APPIMAGERUNTIME=./runtime-x86_64
|
2023-09-05 12:03:02 +00:00
|
|
|
PATCHELF=patchelf
|
|
|
|
|
|
|
|
if [ ! -f "$LINUXDEPLOY" ]; then
|
2024-08-04 13:13:57 +00:00
|
|
|
retry_command wget -O "$LINUXDEPLOY" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-x86_64.AppImage
|
2023-09-05 12:03:02 +00:00
|
|
|
chmod +x "$LINUXDEPLOY"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then
|
2024-08-04 13:13:57 +00:00
|
|
|
retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-plugin-qt-x86_64.AppImage
|
2023-09-05 12:03:02 +00:00
|
|
|
chmod +x "$LINUXDEPLOY_PLUGIN_QT"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$APPIMAGETOOL" ]; then
|
2024-08-09 08:19:17 +00:00
|
|
|
retry_command wget -O "$APPIMAGETOOL" https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
|
2023-09-05 12:03:02 +00:00
|
|
|
chmod +x "$APPIMAGETOOL"
|
2022-07-21 07:27:32 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-09 08:19:17 +00:00
|
|
|
if [ ! -f "$APPIMAGERUNTIME" ]; then
|
|
|
|
retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_64
|
|
|
|
fi
|
|
|
|
|
2022-07-21 07:27:32 +00:00
|
|
|
OUTDIR=$(realpath "./$APPDIRNAME")
|
|
|
|
rm -fr "$OUTDIR"
|
|
|
|
|
2024-05-12 12:56:58 +00:00
|
|
|
echo "Locating extra libraries..."
|
2024-06-14 04:37:33 +00:00
|
|
|
EXTRA_LIBS_ARGS=()
|
2024-05-12 12:56:58 +00:00
|
|
|
for lib in "${MANUAL_LIBS[@]}"; do
|
|
|
|
srcpath=$(find "$DEPSDIR" -name "$lib")
|
|
|
|
if [ ! -f "$srcpath" ]; then
|
|
|
|
echo "Missinge extra library $lib. Exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found $lib at $srcpath."
|
2024-06-14 04:37:33 +00:00
|
|
|
EXTRA_LIBS_ARGS+=("--library=$srcpath")
|
2024-05-12 12:56:58 +00:00
|
|
|
done
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.
|
|
|
|
# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because
|
|
|
|
# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash
|
|
|
|
# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds
|
|
|
|
# the libs to copy), then swap them back after we're done.
|
|
|
|
# Isn't Linux packaging amazing?
|
|
|
|
|
|
|
|
rm -fr "$DEPSDIR.bak"
|
|
|
|
cp -a "$DEPSDIR" "$DEPSDIR.bak"
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
for i in $(find "$DEPSDIR" -iname '*.so'); do
|
|
|
|
echo "Stripping deps library ${i}"
|
|
|
|
strip "$i"
|
2022-07-21 07:27:32 +00:00
|
|
|
done
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
echo "Running linuxdeploy to create AppDir..."
|
2024-05-30 12:25:41 +00:00
|
|
|
EXTRA_QT_PLUGINS="core;gui;svg;waylandclient;widgets;xcbqpa" \
|
2023-09-05 12:03:02 +00:00
|
|
|
EXTRA_PLATFORM_PLUGINS="libqwayland-egl.so;libqwayland-generic.so" \
|
2024-04-25 05:04:40 +00:00
|
|
|
DEPLOY_PLATFORM_THEMES="1" \
|
2023-09-05 12:03:02 +00:00
|
|
|
QMAKE="$DEPSDIR/bin/qmake" \
|
|
|
|
NO_STRIP="1" \
|
2024-06-14 04:37:33 +00:00
|
|
|
$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \
|
2023-09-30 02:38:21 +00:00
|
|
|
--desktop-file="$ROOTDIR/scripts/org.duckstation.DuckStation.desktop" \
|
2024-05-12 12:56:58 +00:00
|
|
|
--icon-file="$ROOTDIR/scripts/org.duckstation.DuckStation.png" \
|
2023-09-05 12:03:02 +00:00
|
|
|
|
|
|
|
echo "Copying resources into AppDir..."
|
|
|
|
cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"
|
|
|
|
|
|
|
|
# LinuxDeploy's Qt plugin doesn't include Wayland support. So manually copy in the additional Wayland libraries.
|
|
|
|
echo "Copying Qt Wayland libraries..."
|
|
|
|
for lib in "${MANUAL_QT_LIBS[@]}"; do
|
|
|
|
srcpath="$DEPSDIR/lib/$lib"
|
|
|
|
dstpath="$OUTDIR/usr/lib/$lib"
|
|
|
|
echo " $srcpath -> $dstpath"
|
|
|
|
cp "$srcpath" "$dstpath"
|
|
|
|
$PATCHELF --set-rpath '$ORIGIN' "$dstpath"
|
2022-07-21 07:27:32 +00:00
|
|
|
done
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
# .. and plugins.
|
|
|
|
echo "Copying Qt Wayland plugins..."
|
|
|
|
for GROUP in "${MANUAL_QT_PLUGINS[@]}"; do
|
|
|
|
srcpath="$DEPSDIR/plugins/$GROUP"
|
|
|
|
dstpath="$OUTDIR/usr/plugins/$GROUP"
|
|
|
|
echo " $srcpath -> $dstpath"
|
|
|
|
mkdir -p "$dstpath"
|
|
|
|
|
|
|
|
for srcsopath in $(find "$DEPSDIR/plugins/$GROUP" -iname '*.so'); do
|
|
|
|
# This is ../../ because it's usually plugins/group/name.so
|
|
|
|
soname=$(basename "$srcsopath")
|
|
|
|
dstsopath="$dstpath/$soname"
|
|
|
|
echo " $srcsopath -> $dstsopath"
|
|
|
|
cp "$srcsopath" "$dstsopath"
|
|
|
|
$PATCHELF --set-rpath '$ORIGIN/../../lib:$ORIGIN' "$dstsopath"
|
|
|
|
done
|
2022-07-21 07:27:32 +00:00
|
|
|
done
|
|
|
|
|
2024-06-16 06:21:24 +00:00
|
|
|
# Why do we have to manually remove these libs? Because the linuxdeploy Qt plugin
|
|
|
|
# copies them, not the "main" linuxdeploy binary, and plugins don't inherit the
|
|
|
|
# include list...
|
|
|
|
for lib in "${REMOVE_LIBS[@]}"; do
|
|
|
|
for libpath in $(find "$OUTDIR/usr/lib" -name "$lib"); do
|
|
|
|
echo " Removing problematic library ${libpath}."
|
|
|
|
rm -f "$libpath"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
# Restore unstripped deps (for cache).
|
|
|
|
rm -fr "$DEPSDIR"
|
|
|
|
mv "$DEPSDIR.bak" "$DEPSDIR"
|
2022-07-21 07:27:32 +00:00
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
# Fix up translations.
|
|
|
|
rm -fr "$OUTDIR/usr/bin/translations"
|
|
|
|
mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"
|
|
|
|
cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"
|
2022-07-21 07:27:32 +00:00
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
# Generate AppStream meta-info.
|
|
|
|
echo "Generating AppStream metainfo..."
|
|
|
|
mkdir -p "$OUTDIR/usr/share/metainfo"
|
2023-10-29 11:15:03 +00:00
|
|
|
"$SCRIPTDIR/../generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"
|
|
|
|
|
|
|
|
# Copy in AppRun hooks.
|
|
|
|
echo "Copying AppRun hooks..."
|
|
|
|
mkdir -p "$OUTDIR/apprun-hooks"
|
|
|
|
for hookpath in "$SCRIPTDIR/apprun-hooks"/*; do
|
|
|
|
hookname=$(basename "$hookpath")
|
|
|
|
cp -v "$hookpath" "$OUTDIR/apprun-hooks/$hookname"
|
|
|
|
sed -i -e 's/exec /source "$this_dir"\/apprun-hooks\/"'"$hookname"'"\nexec /' "$OUTDIR/AppRun"
|
|
|
|
done
|
2022-07-21 07:27:32 +00:00
|
|
|
|
2023-09-05 12:03:02 +00:00
|
|
|
echo "Generating AppImage..."
|
|
|
|
rm -f "$NAME.AppImage"
|
2024-08-09 08:19:17 +00:00
|
|
|
"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$NAME.AppImage"
|