# Build image for the RFGuard Linux release artifacts (.deb + AppImage).
#
# Base is Debian 13 "trixie" by default (ARG BASE_IMAGE). The binary links the
# build distro's glibc, and glibc is backward-compatible only, so a trixie-built
# artifact targets Debian 13 / Raspberry Pi OS trixie and newer. For older
# systems override the base:
#   BASE_IMAGE=debian:bookworm-slim make docker-build    # Debian 12
# For another architecture (Raspberry Pi), build under emulation (needs
# binfmt / qemu-user-static on the host):
#   PLATFORM=linux/arm64 make docker-build               # arm64 (Pi 3/4/5, 64-bit OS)
#   PLATFORM=linux/arm/v7 make docker-build              # armhf (32-bit Raspberry Pi OS)
#
# The image only carries the toolchain and build dependencies; the RFGuard
# and nilorea-library trees are bind-mounted at run time by
# packaging/docker-build.sh, which runs `make deb appimage` inside.
ARG BASE_IMAGE=debian:trixie-slim
FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive

# Toolchain, the Allegro 5 addons the Makefile links, libX11 (n_clipboard),
# libcurl (OSM tiles, Overpass), zlib, and the packaging helpers: dpkg-dev for
# the .deb, curl / ca-certificates to fetch appimagetool, file, appstream
# (metainfo check) and gnupg (signing support) for appimagetool.
# The X11 / XCB client libs on the last line are the ones the AppImage bundles
# because Allegro's GLX driver dlopen()s them (APPIMAGE_EXTRA_SONAMES).
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential pkg-config curl ca-certificates file dpkg-dev \
        appstream gnupg \
        liballegro5-dev liballegro-image5-dev liballegro-ttf5-dev \
        liballegro-dialog5-dev liballegro-acodec5-dev liballegro-audio5-dev \
        libx11-dev libcurl4-openssl-dev zlib1g-dev \
        libx11-xcb1 libxcb-glx0 libxcb-dri2-0 libxcb-dri3-0 libxcb-present0 \
        libxcb-sync1 libxcb-randr0 libxcb-xfixes0 libxshmfence1 \
    && rm -rf /var/lib/apt/lists/*

# appimagetool is itself an AppImage; without FUSE (unavailable in an
# unprivileged container) it must extract-and-run instead of mounting.
ENV APPIMAGE_EXTRACT_AND_RUN=1

WORKDIR /build/rfguard
