# Builder stage
FROM ubuntu:plucky AS builder

RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 python3-pip \
    libasound2-dev \
    libpulse-dev \
    libudev-dev \
    libwayland-dev \
    wayland-protocols \
    libxkbcommon-dev \
    libx11-dev \
    libxext-dev \
    libxrandr-dev \
    libxcursor-dev \
    libxi-dev \
    libxinerama-dev \
    libxss-dev \
    libegl1-mesa-dev \
    libgl1-mesa-dev \
    cmake \
    ninja-build \
    git \
    build-essential \
    binutils \
    pkg-config \
    meson \
    zip && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
RUN git clone https://gitea.pockle.world/john/prosperon.git
WORKDIR /app/prosperon
RUN git checkout jsffi_refactor
RUN meson setup build -Dbuildtype=release -Db_lto=true -Db_lto_mode=thin -Db_ndebug=true
RUN meson compile -C build

# Runtime stage
FROM ubuntu:latest

# Install minimal runtime dependencies (e.g., for dynamically linked libraries)
RUN apt-get update && apt-get install -y libstdc++6 && rm -rf /var/lib/apt/lists/*

# Copy the compiled prosperon binary from the build stage
COPY --from=builder /app/prosperon/build/prosperon /usr/local/bin/prosperon

# Create an entrypoint script
RUN echo '#!/bin/bash' > /entrypoint.sh && \
    echo '/usr/local/bin/prosperon "$@" &' >> /entrypoint.sh && \
    echo 'tail -f /dev/null' >> /entrypoint.sh && \
    chmod +x /entrypoint.sh

WORKDIR /workdir
ENTRYPOINT ["/entrypoint.sh"]