FROM  ubuntu:latest

SHELL ["/bin/bash", "-c"]
ENV CFPREFIX=/software/crystfel/devel
ENV PKG_CONFIG_PATH=$CFPREFIX/lib64/pkgconfig:$CFPREFIX/lib/pkgconfig
ENV LD_LIBRARY_PATH=$CFPREFIX/lib64:$CFPREFIX/lib
ENV LD_RUN_PATH=$CFPREFIX/lib64:$CFPREFIX/lib
ENV PATH=$CFPREFIX/bin:/venv/bin:$PATH

RUN    export DEBIAN_FRONTEND=noninteractive; \
       apt-get -y update ; \
       apt-get -q -y install build-essential flex bison cmake gfortran libgsl-dev libgtk-3-dev \
              libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libfftw3-dev libpng-dev libmsgpack-dev \
              libeigen3-dev libccp4-dev libhdf5-dev libzmq3-dev libpython3-dev python3-full python3-venv \
              liblz4-dev libbz2-dev libcurl4-openssl-dev  debianutils wget lz4 diffutils openssh-client \
              git curl unzip

RUN    python3 -m venv ./venv; /venv/bin/pip3  install meson ninja

# HDF5 filter plugins
RUN    git clone --depth 1 https://github.com/nexusformat/HDF5-External-Filter-Plugins.git ; \
       pushd HDF5-External-Filter-Plugins; \
       mkdir build; \
       pushd build; \
       cmake .. -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DENABLE_BITSHUFFLE_PLUGIN=yes \
                -DENABLE_LZ4_PLUGIN=yes \
                -DENABLE_BZIP2_PLUGIN=yes \
                -DCMAKE_BUILD_TYPE=Release ; \
       popd; \
       make -C build -j 32; \
       make -C build install; \
       popd # HDF5-External-Filter-Plugins

# MsgPack
RUN    wget -nv https://github.com/msgpack/msgpack-c/releases/download/cpp-3.3.0/msgpack-3.3.0.tar.gz ; \
       tar -xzf msgpack-3.3.0.tar.gz ;  \
       pushd msgpack-3.3.0; \
       mkdir build; \
       pushd build; \
       cmake .. -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DMSGPACK_BUILD_EXAMPLES=OFF \
                -DMSGPACK_ENABLE_CXX=OFF \
                -DCMAKE_BUILD_TYPE=Release ; \
       popd ; \
       make -C build -j 32 ; \
       make -C build install ; \
       popd # msgpack-3.3.0

# ASAP::O
RUN    git clone https://gitlab.desy.de/asapo/asapo.git ; \
       pushd asapo ; \
       git checkout 24.11.1 ; \
       mkdir build ; \
       pushd build ; \
       cmake .. -GNinja -DBUILD_CLIENTS_ONLY=ON -DBUILD_PYTHON=OFF \
                -DCMAKE_INSTALL_PREFIX=$CFPREFIX \
                -DCMAKE_BUILD_TYPE=RelWithDebInfo ; \
       popd ; \
       ninja -C build ; \
       ninja -C build install  ; \
       popd

# Seedee
RUN    git clone https://gitlab.desy.de/fs-sc/seedee.git ; \
       pushd seedee ; \
       mkdir build ; \
       cd build ; \
       cmake .. -GNinja -DCMAKE_INSTALL_PREFIX=$CFPREFIX -DCMAKE_BUILD_TYPE=RelWithDebInfo ; \
       cd .. ; \
       ninja -C build ; \
       ninja -C build install ; \
       popd
