FROM debian:testing-slim

# We assume the git repo's cloned outside and copied in, instead of
# cloning it in here. But that works, too.
WORKDIR /src
COPY . /src

LABEL MAINTAINER "jman <jman@city17.xyz>"
# reference and inspiration: https://www.masteringemacs.org/article/speed-up-emacs-libjansson-native-elisp-compilation

# Needed for add-apt-repository, et al.
#
# If you're installing this outside Docker you may not need this.
RUN apt update && apt upgrade -y \
        && apt install -y \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg-agent \
        software-properties-common \
        git

# Install generic dependencies
# with GUI
# RUN apt install -y --no-install-suggests clang autoconf make texinfo libxpm-dev libjpeg-dev libgtk-3-dev libgif-dev libtiff-dev libpng-dev libgnutls28-dev libncurses5-dev libsystemd-dev libharfbuzz-dev libgccjit-10-dev gcc-10 g++-10 libxt-dev
# without GUI
RUN apt install -y build-essential clang autoconf make texinfo libgnutls28-dev libncurses5-dev libsystemd-dev libharfbuzz-dev libgccjit-10-dev gcc-10 g++-10 libxt-dev

# Needed for fast JSON and the configure step
RUN apt install -y libjansson4 libjansson-dev

# Shut up debconf as it'll fuss over postfix for no good reason
# otherwise. If you're doing this outside Docker, you do not need to
# do this.
ENV DEBIAN_FRONTEND=noninteractive

# Configure and run
# with GUI
# RUN ./autogen.sh && ./configure --prefix=/home/$USER/.local --bindir=/home/$USER/.local/bin --with-native-compilation --with-xml2=yes --with-mailutils --with-gnutls=yes
# without GUI
RUN ./autogen.sh && ./configure --prefix=/home/jman/.local --bindir=/home/jman/.local/bin --with-native-compilation --with-mailutils --with-xml2=yes --without-gpm --with-x=no --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no --with-gnutls=yes

RUN make -j $(nproc)
RUN make install-strip

# make .deb
RUN apt install -y checkinstall
RUN checkinstall -y -D --pkgname=emacs-nc --pkgversion="0.1" --requires="libjansson-dev,libharfbuzz-dev,libncurses5-dev,libgccjit-10-dev" --pkggroup=emacs --gzman=yes --install=no

# NOTE: the resulting package will require ~267 mb dependencies

CMD ["/bin/bash"]