Bootstrap: docker
From: ubuntu:18.04

%help
    El script de bashrc de foam-extend no puede integrarse al contenedor.
    Ejecutar como:
        apptainer exec foamextend-4.0_openmpi-3.1.6.sif bash -c "source /opt/foam/foam-extend-4.0/etc/bashrc ; comando"

%environment
    export OMPI_DIR=/opt/ompi
    export PATH="$OMPI_DIR/bin:$PATH"
    export LD_LIBRARY_PATH="$OMPI_DIR/lib:$LD_LIBRARY_PATH"
    export MANPATH="$OMPI_DIR/share/man:$MANPATH"
    export WM_PROJECT_DIR=/opt/foam/foam-extend-4.0
    # . /opt/foam/foam-extend-4.0/etc/bashrc

%post -c /bin/bash
    export OMPI_VERSION=3.1.6
    export WM_NCOMPPROCS=32

    echo America/Buenos_Aires > /etc/localtime
    echo "Installing required packages..."
    apt-get update
    apt-get install -y
    apt-get install -y git-core build-essential binutils-dev cmake flex zlib1g-dev qt4-dev-tools libqt4-dev libncurses5-dev libxt-dev rpm mercurial graphviz python python-dev gcc-5 g++-5 wget
    apt-get clean
    rm -rf /var/lib/apt/lists/*

    export OMPI_DIR=/opt/ompi
    export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v${OMPI_VERSION:0:-2}/openmpi-$OMPI_VERSION.tar.bz2"
    mkdir -p /tmp/ompi
    mkdir -p /opt
    # Download
    cd /tmp/ompi && wget -O openmpi-$OMPI_VERSION.tar.bz2 $OMPI_URL && tar -xjf openmpi-$OMPI_VERSION.tar.bz2
    # Compile and install
    cd /tmp/ompi/openmpi-$OMPI_VERSION && ./configure --prefix=$OMPI_DIR && make -j$WM_NCOMPPROCS install

    # Set env variables so we can compile our application
    export PATH=$OMPI_DIR/bin:$PATH
    export LD_LIBRARY_PATH=$OMPI_DIR/lib:$LD_LIBRARY_PATH

    mkdir /opt/foam
    cd /opt/foam
    git clone git://git.code.sf.net/p/foam-extend/foam-extend-4.0 ./foam-extend-4.0

    cd foam-extend-4.0
    echo export WM_THIRD_PARTY_USE_BISON_27=1  >> etc/prefs.sh
    echo export QT_SELECT=qt4  >> etc/prefs.sh
    echo "export WM_CC='gcc-5'"  >> etc/prefs.sh
    echo "export WM_CXX='g++-5'"  >> etc/prefs.sh
    echo "export QT_BIN_DIR=/usr/bin/" >> etc/prefs.sh
    echo "export WM_MPLIB=SYSTEMOPENMPI" >> etc/prefs.sh
    echo "export OPENMPI_DIR=/opt/ompi/" >> etc/prefs.sh
    echo "export OPENMPI_BIN_DIR=\$OPENMPI_DIR/bin" >> etc/prefs.sh

    sed -i -e 's/foamInstall=$HOME\/$WM_PROJECT/#/' ./etc/bashrc
    sed -i -e 's/# foamInstall=\/opt/foamInstall=\/opt/' ./etc/bashrc

    source ./etc/bashrc
    sed -i -e 's=rpmbuild --define=rpmbuild --define "_build_id_links none" --define=' ThirdParty/tools/makeThirdPartyFunctionsForRPM
    sed -i -e 's/gcc/\$(WM_CC)/' wmake/rules/linux64Gcc/c
    sed -i -e 's/g++/\$(WM_CXX)/' wmake/rules/linux64Gcc/c++

    ./Allwmake.firstInstall
