mirror of
https://github.com/RetroDECK/AppImages.git
synced 2025-04-11 02:55:09 +00:00
109 lines
3.2 KiB
Bash
Executable file
109 lines
3.2 KiB
Bash
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
# Function: build_appimage
|
|
# Parameters:
|
|
# $1: Repository URL
|
|
# $2: App name (used for clone directory, executable name, AppDir, desktop file, and icon)
|
|
# $3: Output AppImage file name
|
|
# $4: (Optional) Additional CMake arguments
|
|
# $5...: (Optional) One or more patch file paths to be applied before building
|
|
|
|
|
|
REPO_URL="$1"
|
|
APP_NAME="$2"
|
|
APPIMAGE_OUTPUT="$3"
|
|
CMAKE_ARGS="${4:-}"
|
|
shift 4
|
|
PATCH_FILES=("$@") # Remaining arguments are patch files
|
|
|
|
# Static/temporary names based on the app name:
|
|
CLONE_DIR="$APP_NAME"
|
|
BUILD_DIR="build"
|
|
APPDIR="${APP_NAME}.AppDir"
|
|
|
|
# Save current directory
|
|
CURRENT_DIR="$(pwd)"
|
|
|
|
echo "--- AppImage Maker initiated ---"
|
|
echo "Building AppImage for $APP_NAME"
|
|
echo "Repository: $REPO_URL"
|
|
echo "AppImage output: $APPIMAGE_OUTPUT"
|
|
echo "CMake arguments: $CMAKE_ARGS"
|
|
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
|
|
echo "Patch files: ${PATCH_FILES[*]}"
|
|
fi
|
|
|
|
# Clone the repository if not already cloned
|
|
if [ ! -d "$CLONE_DIR" ]; then
|
|
echo "Cloning repository: $REPO_URL in $CLONE_DIR"
|
|
git clone "$REPO_URL" "$CLONE_DIR"
|
|
git submodule update --init --recursive
|
|
fi
|
|
|
|
pushd "$CLONE_DIR" > /dev/null
|
|
|
|
# Optionally checkout a specific branch or commit if desired
|
|
# git checkout <branch-or-commit>
|
|
|
|
# Apply patch files, if provided
|
|
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
|
|
for patch in "${PATCH_FILES[@]}"; do
|
|
if [ -f "$patch" ]; then
|
|
echo "Applying patch: $patch"
|
|
patch -p1 < "$patch"
|
|
else
|
|
echo "Warning: Patch file $patch does not exist. Skipping."
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Create build directory and build the project
|
|
mkdir -p "$BUILD_DIR"
|
|
pushd "$BUILD_DIR" > /dev/null
|
|
echo "Building $APP_NAME in $BUILD_DIR"
|
|
cmake .. -DCMAKE_BUILD_TYPE=Release $CMAKE_ARGS
|
|
make -j"$(nproc)"
|
|
popd > /dev/null
|
|
|
|
# Prepare the AppDir structure
|
|
rm -rf "$APPDIR"
|
|
mkdir -p "$APPDIR/usr/bin"
|
|
# Assumes the built executable is named as the app name and is located in the build directory
|
|
cp "$BUILD_DIR/$APP_NAME" "$APPDIR/usr/bin/"
|
|
|
|
# Copy the desktop file and icon (assumed to be in the repository root with matching names)
|
|
cp "${APP_NAME}.desktop" "$APPDIR/"
|
|
cp "${APP_NAME}.png" "$APPDIR/"
|
|
|
|
# Download appimagetool if not already present (placed one level above the clone directory)
|
|
if [ ! -f "../appimagetool" ]; then
|
|
echo "Downloading appimagetool..."
|
|
wget -O ../appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
|
|
chmod +x ../appimagetool
|
|
else
|
|
echo "appimagetool already exists. Skipping download."
|
|
fi
|
|
|
|
# Create the AppImage using appimagetool
|
|
echo "Creating AppImage..."
|
|
../appimagetool "$APPDIR" "$APPIMAGE_OUTPUT"
|
|
|
|
echo "AppImage created: $APPIMAGE_OUTPUT"
|
|
|
|
popd > /dev/null
|
|
cd "$CURRENT_DIR"
|
|
|
|
# Example usage:
|
|
# This will clone the repository into a folder named "dolphin-emu",
|
|
# build it using a build directory named "build",
|
|
# assume the executable is "dolphin-emu" and the desktop/icon files are named
|
|
# "dolphin-emu.desktop" and "dolphin-emu.png", apply any provided patch files,
|
|
# and output "Dolphin-emu.AppImage".
|
|
# build_appimage \
|
|
# "https://github.com/dolphin-emu/dolphin.git" \
|
|
# "dolphin-emu" \
|
|
# "Dolphin-emu.AppImage" \
|
|
# "-DENABLE_SDL=ON" \
|
|
# "patches/fix_bug.patch" "patches/add_feature.patch"
|