FROM archlinux:latest

RUN pacman --noconfirm -Syu && pacman --noconfirm -Sy wget sudo arch-install-scripts git cmake make mbedtls ncurses rsync bison flex git gperf help2man lzip python unzip base-devel nodejs npm
RUN git clone https://github.com/crosstool-ng/crosstool-ng && cd ./crosstool-ng && ./bootstrap && ./configure && make install
RUN useradd -m build && \
    echo "build ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/build

USER build
WORKDIR /home/build
RUN mkdir ct-ppc && cd ct-ppc && ct-ng powerpc-unknown-linux-gnu && ct-ng build.`nproc` && cd .. && rm -rf ct-ppc

USER root

COPY cross /opt/cross
RUN mkdir -p /opt/cross/ppc/sysroot && cd /opt/cross/ppc/sysroot && wget https://wii-linux.org/files/wii_linux_rootfs_archpower-latest.tar.gz && tar xf wii_linux_rootfs_archpower-latest.tar.gz . && rm wii_linux_rootfs_archpower-latest.tar.gz
