# docker.io/acmel/linux-perf-tools-build-debian:experimental-x-mips64
FROM docker.io/debian:experimental
MAINTAINER Arnaldo Carvalho de Melo <acme@kernel.org>
# Debian 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
# ARCH shouldn't be "mips64", the headers for 32-bit and 64-bit mips are shared, the TARGET is
# what will select the right binary time, MIPS64 in this case:
# [root@jouet x-mips64]# file /home/acme/git/tmp/perf 
# /home/acme/git/tmp/perf: ELF 64-bit MSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked, interpreter /lib64/ld.so.1, BuildID[sha1]=fdc0ae197bf2441fa1f47f3c2a363f59cfa4368e, for GNU/Linux 3.2.0, not stripped
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update && \
    apt-get -y install apt-utils make flex bison curl bc findutils build-essential && \
    apt-get -y clean && \
    rm -rf /usr/share/doc /usr/share/gtk-doc /usr/share/locale /usr/share/man
ENV ARCH mips
ENV TARGET mips64-linux-gnuabi64
RUN apt-get -y update && \
    apt-get -y install gcc-${TARGET} && \
    apt-get -y install wget bzip2 xz-utils && \
    export ELFUTILS_VER=0.173 && \
    export ZLIB_VER=1.2.11 && \
    export INSTALLDIR=/usr/${TARGET} && \
    export PATH=$INSTALLDIR/bin:$PATH && \
    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 && \
    cd zlib-${ZLIB_VER} && \
    ./configure --prefix=${INSTALLDIR} && \
    make && \
    make install && \
    cd .. && \
    rm -rf zlib-${ZLIB_VER} && \
    rm -f zlib-${ZLIB_VER}.tar.gz && \
    tar xf 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 && \
    unset TARGET INSTALLDIR TARGETMACH CROSS CC LD AS && \
    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 CROSS_COMPILE=${TARGET}-
ENTRYPOINT ["/rx_and_build.sh"]
