FROM amd64/ubuntu:18.04

ARG GIT_COMMIT=master
ARG TCE_COMMIT=master
ARG LLVM_VERSION=80
LABEL git-commit=$GIT_COMMIT tce-commit=$TCE_COMMIT vendor=pocl distro=Ubuntu version=1.0

ENV TERM dumb
RUN apt update
RUN apt upgrade -y
RUN apt install -y build-essential ocl-icd-libopencl1 autoconf automake cmake git pkg-config make ninja-build ocl-icd-libopencl1 ocl-icd-dev ocl-icd-opencl-dev libhwloc-dev zlib1g zlib1g-dev clinfo texinfo

ENV LD_LIBRARY_PATH=/home/LLVM_$LLVM_VERSION/lib:/home/TCE_$LLVM_VERSION/lib
ENV PATH=/home/TCE_$LLVM_VERSION/bin:/home/LLVM_$LLVM_VERSION/bin:${PATH}

########### build LLVM with suitable flags

RUN mkdir -p /home/LLVM_$LLVM_VERSION/build ; mkdir -p /home/LLVM_$LLVM_VERSION/source

RUN cd /home/LLVM_$LLVM_VERSION/source ; git clone -b release_$LLVM_VERSION https://github.com/llvm-mirror/llvm.git

RUN cd /home/LLVM_$LLVM_VERSION/source/llvm/tools ; git clone -b release_$LLVM_VERSION https://github.com/llvm-mirror/clang.git

RUN apt install -y python python-dev

RUN cd /home/LLVM_$LLVM_VERSION/build ; cmake -G Ninja -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_INSTALL_PREFIX=/home/LLVM_$LLVM_VERSION -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON -DLLVM_LINK_LLVM_DYLIB:BOOL=ON /home/LLVM_$LLVM_VERSION/source/llvm

RUN cd /home/LLVM_$LLVM_VERSION/build ; ninja

RUN cd /home/LLVM_$LLVM_VERSION/build ; ninja install

CMD /bin/bash
