forked from aki/docker-aseprite-linux
This commit introduces a major refactoring of the Aseprite build process. It replaces the previous fragile system (prone to dependency fetching failures) with an interim multi-distribution Docker approach, paving the way for a future transition to Flatpak.
**Problems Addressed:**
* **Build Fragility & Dependency Fetching:** The prior method, compiling dependencies from source within a generic container, frequently failed due to network issues and rate limiting during source/sub-dependency acquisition (e.g., Skia's `git-sync-deps`), often late in the process. Source state inconsistencies could also cause failures.
* **Complexity of Full Source Builds:** Managing the compilation of the entire dependency tree from source was complex.
**New Architecture & Rationale:**
* **Host-Side Source Preparation (`prepare_sources.sh`):** Isolates the problematic source fetching and state management to a host-side script run *before* the main build. Key features:
* Handles cloning/updating core sources (`depot_tools`, Skia, Aseprite).
* Runs Skia `git-sync-deps` with **robust retry logic** to specifically address rate limit errors.
* Includes an `--check-integrity` flag which performs **aggressive checks and resets** (fetching, checking out specific tags/commits, resetting state) to ensure the local source directories precisely match the required state for the build, potentially involving significant network activity.
* **Distribution-Specific Builds (Interim Step):** Introduced `Dockerfile.arch`, `Dockerfile.debian`, `Dockerfile.fedora`. These use native package managers to install pre-built *common* development libraries within the container, simplifying the Docker build stage itself. Requires OS detection or manual selection (`TARGET_DISTRO`).
* **Clear Build Stages (Makefile):** Orchestrates source preparation, image building, and final binary extraction (`docker cp` to `./output/bin`).
* **Cleaned Structure:** Removed obsolete scripts/files (`compile.sh`, generic `Dockerfile`, `docker-compose.yml`) and updated `.gitignore`.
**Limitations & Future Direction (Flatpak):**
* **Fetching Challenges Persist:** While reliability is improved by isolating source prep and adding retries/integrity checks in `prepare_sources.sh`, the core challenge of potential rate limits or network issues during this initial step remains.
* **Flatpak for Portability:** The current multi-distro Docker setup is an **intermediate solution**. The ultimate goal and **forward-maintained approach** is migrating to **Flatpak (`flatpak-builder`)**. Flatpak will provide a **unified, distribution-agnostic build environment** using standard runtimes and produce a **portable `.flatpak` bundle**, eliminating the need for OS detection/separate Dockerfiles and ensuring consistent builds *after* sources are successfully prepared.
95 lines
3.0 KiB
Makefile
95 lines
3.0 KiB
Makefile
# --- OS Detection ---
|
|
# Attempt to detect host OS family. Fallback to 'arch'.
|
|
# This logic checks /etc/os-release for ID or ID_LIKE fields.
|
|
# Use $(strip ...) to remove potential leading/trailing whitespace from shell output.
|
|
DETECTED_DISTRO := $(strip $(shell \
|
|
if [ -f /etc/os-release ]; then \
|
|
. /etc/os-release; \
|
|
if echo "$$ID$$ID_LIKE" | grep -q -e arch; then \
|
|
echo arch; \
|
|
elif echo "$$ID$$ID_LIKE" | grep -q -e debian -e ubuntu; then \
|
|
echo debian; \
|
|
elif echo "$$ID$$ID_LIKE" | grep -q -e fedora; then \
|
|
echo fedora; \
|
|
else \
|
|
echo arch; \
|
|
fi; \
|
|
else \
|
|
echo arch; \
|
|
fi \
|
|
))
|
|
|
|
# Set default TARGET_DISTRO based on detection, allowing user override
|
|
TARGET_DISTRO ?= $(DETECTED_DISTRO)
|
|
|
|
# --- Configuration ---
|
|
IMAGE_NAME := docker-aseprite-${TARGET_DISTRO}
|
|
DOCKERFILE := Dockerfile.${TARGET_DISTRO}
|
|
OUTPUT_DIR := ${PWD}/output
|
|
TARGET_DIR_IN_IMAGE := /target/aseprite/build/bin
|
|
|
|
# --- Main Targets ---
|
|
# Default target
|
|
all: build
|
|
|
|
# Prepare source files by running the script
|
|
# Use .PHONY to ensure it always runs if called directly
|
|
.PHONY: prepare-sources
|
|
prepare-sources:
|
|
@echo "--- Preparing sources ---"
|
|
@./prepare_sources.sh
|
|
|
|
# Build the Docker image for the target distribution
|
|
# Depends on sources being ready (though prepare-sources isn't a file dependency)
|
|
build-image:
|
|
# --- DEBUGGING ---
|
|
@echo "DEBUG: TARGET_DISTRO='${TARGET_DISTRO}'"
|
|
@echo "DEBUG: DOCKERFILE='${DOCKERFILE}'"
|
|
# --- END DEBUGGING ---
|
|
ifeq (,$(wildcard ${DOCKERFILE}))
|
|
$(error Dockerfile for target distribution '${TARGET_DISTRO}' (${DOCKERFILE}) not found)
|
|
endif
|
|
@echo "--- Building Docker image (${IMAGE_NAME}) using ${DOCKERFILE} ---"
|
|
@docker build -t ${IMAGE_NAME} -f ${DOCKERFILE} .
|
|
|
|
# Extract the compiled binary from the image
|
|
# Depends on the image being built
|
|
.PHONY: extract-binary
|
|
extract-binary: build-image
|
|
@echo "--- Extracting Aseprite binary from ${IMAGE_NAME} ---"
|
|
@mkdir -p ${OUTPUT_DIR}/bin
|
|
@CONTAINER_ID=$$(docker create ${IMAGE_NAME}) && \
|
|
docker cp "$${CONTAINER_ID}:${TARGET_DIR_IN_IMAGE}/." "${OUTPUT_DIR}/bin/" && \
|
|
docker rm "$${CONTAINER_ID}" > /dev/null
|
|
@echo "Aseprite binary extracted to ${OUTPUT_DIR}/bin"
|
|
|
|
# Main build target: Prepare sources, build image, extract binary for selected distro
|
|
.PHONY: build
|
|
build: prepare-sources build-image extract-binary
|
|
@echo "--- Build complete for ${TARGET_DISTRO} ---"
|
|
@echo "Aseprite binary is in ${OUTPUT_DIR}/bin"
|
|
|
|
# --- Specific Distribution Targets ---
|
|
.PHONY: build-arch build-debian build-fedora
|
|
|
|
# Build for Arch Linux (default if not detected otherwise)
|
|
build-arch:
|
|
$(MAKE) build TARGET_DISTRO=arch
|
|
|
|
# Build for Debian/Ubuntu based systems
|
|
build-debian:
|
|
$(MAKE) build TARGET_DISTRO=debian
|
|
|
|
# Build for Fedora based systems
|
|
build-fedora:
|
|
$(MAKE) build TARGET_DISTRO=fedora
|
|
|
|
# --- Utility Targets ---
|
|
# Clean up downloaded sources and output directory
|
|
.PHONY: clean
|
|
clean:
|
|
@echo "--- Cleaning up ---"
|
|
@rm -rf ./src
|
|
@rm -rf ${OUTPUT_DIR}
|
|
@echo "Cleanup complete."
|