# cross passes the correct base via this ARG
ARG CROSS_BASE_IMAGE
FROM ${CROSS_BASE_IMAGE}

RUN dpkg --add-architecture mipsel \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
      build-essential gperf pkg-config \
      wget ca-certificates \
 && rm -rf /var/lib/apt/lists/*

RUN wget https://github.com/seccomp/libseccomp/releases/download/v2.6.0/libseccomp-2.6.0.tar.gz && \
 tar -xvpf libseccomp-2.6.0.tar.gz && \
 cd libseccomp-2.6.0 && \
 env CC=mipsel-linux-muslsf-gcc \
     LD=mipsel-linux-muslsf-gcc \
     AR=mipsel-linux-muslsf-ar \
     CFLAGS="-g -O2 -fPIE" \
 ./configure \
        --enable-static \
        --disable-shared \
        --host=mipsel-linux-muslsf \
        --prefix=/usr/local/mipsel-linux-muslsf && \
 make -j >&2 && \
 make install >&2

 RUN ln -s /usr/local/lib/gcc/mipsel-linux-muslsf/9.2.0/crtbegin.o /usr/local/mipsel-linux-muslsf/lib
 RUN ln -s /usr/local/lib/gcc/mipsel-linux-muslsf/9.2.0/crtend.o /usr/local/mipsel-linux-muslsf/lib
 RUN ln -sf /usr/local/lib/gcc/mipsel-linux-muslsf/9.2.0/libgcc_eh.a /usr/local/mipsel-linux-muslsf/lib/libunwind.a
