FROM --platform=${BUILDPLATFORM} mani/source AS source

FROM manibase

ARG ADDITIONAL_PACKAGES=
RUN \
	useradd -p locked -m mani && \
	apt-get -qq update && \
	apt-get -qq upgrade && \
	apt-get -qqy install gcc make git doxygen ccache pkg-config meson \
		libpci-dev libftdi1-dev libusb-1.0-0-dev \
		${ADDITIONAL_PACKAGES} && \
	{ apt-get -qqy install libjaylink-dev libgpiod-dev || true; } && \
	apt-get clean

COPY --from=source /source /home/mani/flashprog
RUN chown -R mani:mani /home/mani/flashprog

RUN mkdir -p -m 1777 /ccache

ENV GIT_SSL_NO_VERIFY=1
USER mani

RUN cd && mkdir .ccache && chown mani:mani .ccache

ARG IDENT=mani
ARG CCACHE_MAX=32M
RUN \
	ccache --set-config cache_dir=/ccache/${IDENT} && \
	ccache --set-config max_size=${CCACHE_MAX}

ENV DEVSHELL /bin/bash
COPY mani-wrapper.sh /home/mani/
ENTRYPOINT ["/bin/sh", "/home/mani/mani-wrapper.sh"]
