# PHSA testing dockerfile
# 17.10 is the first Ubuntu release with gccbrig

FROM amd64/ubuntu:17.10

RUN apt update
RUN apt upgrade -y
RUN apt install -y build-essential ocl-icd-libopencl1 cmake git pkg-config libclang-dev clang llvm make ninja-build ocl-icd-libopencl1 ocl-icd-dev ocl-icd-opencl-dev libhwloc-dev zlib1g zlib1g-dev clinfo
RUN apt install -y gccbrig-7 nano libboost-all-dev libelf-dev

# TODO this should be fixed somewhere
RUN ln -s /usr/bin/gccbrig-7 /usr/bin/gccbrig

##################################

###### build clang 3.7 HSAIL branch

RUN mkdir -p /home/LLVM_37_HSA/build ; mkdir -p /home/LLVM_37_HSA/source
RUN cd /home/LLVM_37_HSA/source ; git clone -b hsail-stable-3.7 https://github.com/HSAFoundation/HLC-HSAIL-Development-LLVM/ llvm
RUN cd /home/LLVM_37_HSA/source/llvm/tools ; git clone https://github.com/llvm-mirror/clang.git -b release_37
COPY clang-3.7-hsail-branch.patch /home
RUN cd /home/LLVM_37_HSA/source/llvm/tools/clang ; patch -p0 < /home/clang-3.7-hsail-branch.patch
RUN cd /home/LLVM_37_HSA/build ; cmake -G Ninja -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=HSAIL -DCMAKE_INSTALL_PREFIX=/home/LLVM_37_HSA  -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DHSAIL_USE_LIBHSAIL=OFF /home/LLVM_37_HSA/source/llvm
RUN cd /home/LLVM_37_HSA/build ; ninja
RUN cd /home/LLVM_37_HSA/build ; ninja install

CMD /bin/bash
