FROM ubuntu:24.04 AS builder

# Pilot build against the xrdp/xorgxrdp "devel" branches (pre-0.11).
# This is NOT the same codebase as Dockerfile (v0.10.x) - devel is ~787
# commits / ~300 files ahead of v0.10.6.1, and xorgxrdp's devel branch has
# moved together with it (137 commits / 81 files ahead of v0.10.5). Track
# them as a pair; don't mix a devel xrdp with a tagged xorgxrdp or vice versa.
#
# Known deltas from the v0.10.x build baked into this file:
#   - New hard dep: libxkbfile-dev (unconditional XKB header check)
#   - --enable-ibus now also needs libibus-1.0-dev + libglib2.0-dev
#   - NVENC support moved into a new helper binary (xrdp-accel-assist) that
#     vendors its own NVENC API headers, so the nv-codec-headers clone/symlink
#     step from the stable Dockerfile is gone - it's dead weight on devel.
#   - --enable-accel is auto-derived from --enable-nvenc in configure.ac, so
#     no new configure flag is needed to get xrdp-accel-assist built.
#
# devel is a floating branch, not a tag: Docker layer caching means a
# `docker build` with no cache change will keep reusing an old clone.
# Always pass --no-cache (or otherwise bust the git-clone layers) to actually
# pick up new commits on each pilot run.
#
# Usage:
#   docker build --no-cache -f Dockerfile.devel -t xrdp-builder:devel .
#   docker run --rm -v $(pwd)/packages:/output xrdp-builder:devel

# Get build and target platform info
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETARCH
ARG TARGETVARIANT

# Build arguments for versions - devel branches by default for this pilot
ARG XRDP_VERSION=devel
ARG XORGXRDP_VERSION=devel
ARG PW_MODULE_XRDP_VERSION=devel

# Prevent interactive prompts during build
ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies
RUN apt-get update && apt-get install -y \
    git \
    autoconf \
    automake \
    libtool \
    pkg-config \
    gcc \
    g++ \
    make \
    libssl-dev \
    libpam0g-dev \
    libx11-dev \
    libxfixes-dev \
    libxrandr-dev \
    libxkbfile-dev \
    nasm \
    xsltproc \
    flex \
    bison \
    libxml2-dev \
    dpkg-dev \
    libcap-dev \
    libfuse3-dev \
    libpixman-1-dev \
    intltool \
    xserver-xorg-dev \
    xserver-xorg-core \
    libconfig-dev \
    libjpeg-dev \
    wget \
    libturbojpeg-dev \
    libx264-dev \
    libpulse-dev \
    libopus-dev \
    libibus-1.0-dev \
    libglib2.0-dev \
    ca-certificates \
    libepoxy-dev \
    libasound2-dev \
    libdrm-dev \
    libglvnd-dev \
    libgbm-dev \
    pipewire \
    libpipewire-0.3-dev \
    libspa-0.2-dev \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y \
    nano \
    xvfb \
    xdotool \
    ibus \
    dbus-x11 \
    openbox \
    && rm -rf /var/lib/apt/lists/*

# Match the workspaceFolder set in devcontainer.json
WORKDIR /workspace
CMD [ "tail", "-f", "/dev/null" ]