# docker.io/acmel/linux-perf-tools-build-ubuntu:14.04.4-x-linaro-arm64
FROM docker.io/ubuntu:14.04.4
MAINTAINER Arnaldo Carvalho de Melo <acme@kernel.org>
#ENV DEBIAN_FRONTEND noninteractive
# ubuntu doesn't have the other devel packages for this target, so build just the basic tool
# libelf-dev is needed to build objtool, which is a host tool, not being cross compiled.
# It will check the cross compiled kernel objects
# It will not be used tho, as there is no support to check binaries for this arch yet
ENV ARCH arm64
ENV TARGET aarch64-linux-gnu
ENV LINARO_VER=5.5.0-2017.10
ENV LINARO_TOOLCHAIN=gcc-linaro-${LINARO_VER}-x86_64_aarch64-linux-gnu
RUN apt-get -y update && \
    apt-get -y install make flex bison curl wget bzip2 xz-utils
RUN export LINARO_TARBALL=${LINARO_TOOLCHAIN}.tar.xz && \
    wget -q https://releases.linaro.org/components/toolchain/binaries/latest-5/aarch64-linux-gnu/${LINARO_TARBALL} && \
    tar xf ${LINARO_TARBALL} && \
    rm ${LINARO_TARBALL}
RUN export PATH=$PATH:/${LINARO_TOOLCHAIN}/bin && \
    export ELFUTILS_VER=0.169 && \
    export ZLIB_VER=1.2.11 && \
    export INSTALLDIR=/${LINARO_TOOLCHAIN}/${TARGET}/libc/usr/ && \
    export TARGETMACH=${TARGET} && \
    export CROSS=${TARGET}- && \
    export CC=${CROSS}gcc && \
    export LD=${CROSS}ld && \
    export AS=${CROSS}as && \
    wget -q http://zlib.net/zlib-${ZLIB_VER}.tar.gz && \
    wget -q https://fedorahosted.org/releases/e/l/elfutils/${ELFUTILS_VER}/elfutils-${ELFUTILS_VER}.tar.bz2 && \
    tar xf zlib-${ZLIB_VER}.tar.gz && \
    rm -f zlib-${ZLIB_VER}.tar.gz && \
    cd zlib-${ZLIB_VER} && \
    ./configure --prefix=${INSTALLDIR} && \
    make && \
    make install && \
    cd .. && \
    rm -rf zlib-${ZLIB_VER} && \
    tar xf elfutils-${ELFUTILS_VER}.tar.bz2 && \
    rm -f elfutils-${ELFUTILS_VER}.tar.bz2 && \
    cd elfutils-${ELFUTILS_VER} && \
    ./configure --host=${TARGET} --prefix=${INSTALLDIR} && \
    make && \
    make install && \
    cd .. && \
    rm -rf elfutils-${ELFUTILS_VER} && \
    apt-get -y remove wget bzip2 && \
    apt-get -y clean && \
    rm -rf /${LINARO_TOOLCHAIN}/share/doc /${LINARO_TOOLCHAIN}/share/locale /${LINARO_TOOLCHAIN}/share/man /core* && \
    rm -rf /usr/share/doc /usr/share/gtk-doc /usr/share/locale /usr/share/man
RUN mkdir -m 777 -p /git /tmp/build/perf /tmp/build/objtool /tmp/build/linux && \
    groupadd -r perfbuilder && \
    useradd -m -r -g perfbuilder perfbuilder && \
    chown -R perfbuilder.perfbuilder /tmp/build/ /git/
USER perfbuilder
COPY rx_and_build.sh /
ENV EXTRA_PATH=/${LINARO_TOOLCHAIN}/bin/
ENV CROSS_COMPILE=${EXTRA_PATH}${TARGET}-
ENTRYPOINT ["/rx_and_build.sh"]
