FROM debian:buster-slim

LABEL maintainer="a.ellery@uq.edu.au"

WORKDIR /app
COPY . /app

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
	apt-get install -y gmsh git g++ python3 python3-dev python3-numpy python3-sympy \
	python3-matplotlib python3-scipy python3-pip python3-pyproj python3-gdal \
	libboost-python-dev libboost-random-dev libboost-iostreams-dev libmetis-dev \
	libmumps-dev libnetcdf-dev libnetcdf-cxx-legacy-dev libnetcdf-c++4-dev \
	libsuitesparse-dev libsilo-dev scons subversion lsb-release cmake make
RUN git clone https://github.com/trilinos/Trilinos /app/trilinos_source
RUN svn co https://svn.geocomp.uq.edu.au/svn/esys13/trunk /app/escript
RUN mkdir /app/trilinos_build
RUN cd /app/trilinos_build && \
	cmake \
        -D CMAKE_C_COMPILER=`which gcc` \
        -D CMAKE_CXX_COMPILER=`which g++` \
        -D CMAKE_Fortran_COMPILER=`which gfortran` \
        -D PYTHON_EXECUTABLE=/usr/bin/python \
        -D CMAKE_INSTALL_PREFIX=/usr/local/ \
        -D Trilinos_ENABLE_CXX11=ON \
        -D CMAKE_C_FLAGS=' -w -fopenmp' \
        -D CMAKE_CXX_FLAGS=' -w -fopenmp'\
        -D Trilinos_ENABLE_Fortran=ON \
        -D BUILD_SHARED_LIBS=ON \
        -D TPL_ENABLE_BLAS=ON \
        -D TPL_ENABLE_Boost=ON \
        -D TPL_ENABLE_Cholmod=ON \
        -D TPL_ENABLE_LAPACK=ON \
        -D TPL_ENABLE_METIS=ON \
        -D TPL_ENABLE_SuperLU=OFF \
        -D TPL_ENABLE_UMFPACK=ON \
        -D TPL_BLAS_INCLUDE_DIRS=/usr/include/suitesparse \
        -D TPL_Cholmod_INCLUDE_DIRS=/usr/include/suitesparse \
        -D TPL_Cholmod_LIBRARIES='libcholmod.so;libamd.so;libcolamd.so' \
        -D TPL_UMFPACK_INCLUDE_DIRS=/usr/include/suitesparse \
        -D TPL_Boost_INCLUDE_DIRS=/usr/local/boost/include \
        -D TPL_Boost_LIBRARY_DIRS=lib \
        -D Trilinos_ENABLE_Amesos=ON \
        -D Trilinos_ENABLE_Amesos2=ON \
        -D Trilinos_ENABLE_AztecOO=ON \
        -D Trilinos_ENABLE_Belos=ON \
        -D Trilinos_ENABLE_Ifpack=ON \
        -D Trilinos_ENABLE_Ifpack2=ON \
        -D Trilinos_ENABLE_Kokkos=ON \
        -D Trilinos_ENABLE_Komplex=ON \
        -D Trilinos_ENABLE_ML=ON \
        -D Trilinos_ENABLE_MueLu=ON \
        -D Trilinos_ENABLE_Teuchos=ON \
        -D Trilinos_ENABLE_Tpetra=ON \
        -D Trilinos_ENABLE_ALL_OPTIONAL_PACKAGES=ON \
        -D Kokkos_ENABLE_AGGRESSIVE_VECTORIZATION=ON \
        -D Tpetra_INST_COMPLEX_DOUBLE=ON \
        -D Trilinos_ENABLE_COMPLEX_DOUBLE=ON \
        -D Teuchos_ENABLE_COMPLEX=ON \
        -D Tpetra_INST_INT_INT=ON \
        -D Tpetra_ENABLE_DEPRECATED_CODE=ON \
        -D Trilinos_ENABLE_OpenMP=ON \
        -D Trilinos_ENABLE_MPI=OFF \
        -D Trilinos_ENABLE_EXPLICIT_INSTANTIATION=ON \
        -D Kokkos_ENABLE_COMPILER_WARNINGS=ON \
        -D Amesos2_ENABLE_Basker=ON \
        -D Tpetra_INST_SERIAL:BOOL=ON \
        -D Trilinos_ENABLE_TESTS=OFF \
		-D TPL_FIND_SHARED_LIBS=ON \
		-D Trilinos_LINK_SEARCH_START_STATIC=OFF /app/trilinos_source && \
	make -j`nproc` install
RUN rm -rf /app/trilinos_build /app/trilinos_source
RUN cd /app/escript && scons options_file=scons/templates/sid_py3_options.py \
		paso=1 umfpack=1 trilinos=1  werror=0 -j`nproc` prefix=/usr/local \
		trilinos_prefix=/usr/local mpi=none insane=True build_full
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
ENV PYTHONPATH=/usr/local/:$PYTHONPATH
ENV PATH=/usr/local/bin:$PATH
RUN useradd -ms /bin/bash appuser
RUN run-escript /app/escript/scripts/release_sanity.py
RUN rm -rf *

CMD ["/bin/bash"]
