network-experiment/scripts/create-cross-compiler/build-cross-compiler.Docker...

90 lines
2.1 KiB
Docker

FROM alpine:3.22.2
# Install packages needed in both building and running.
RUN apk update && \
apk add --no-cache \
libstdc++
# Install tools required for building.
RUN mkdir -p /root/.local/bin
ENV PATH="${PATH}:/root/.local/bin"
RUN apk add --no-cache \
autoconf \
bash \
binutils \
build-base \
cmake \
clang \
clang-extra-tools \
gdb \
git \
libtool \
linux-headers \
ninja \
m4 \
perl \
python3 \
pipx
# Install tools we need for building the cross compiler.
RUN apk add --no-cache \
gpg \
gpg-agent \
automake \
flex \
make \
texinfo \
xz \
help2man \
gawk \
bison \
ncurses-dev \
rsync \
wget
RUN mkdir -p /workspace
WORKDIR /workspace
# Download crosstool-ng that we use to build the cross compiler.
RUN <<EOF
gpg --keyserver pgp.surfnet.nl --recv-keys 721B0FB1CDC8318AEBB888B809F6DD5F1F30EF2E
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.28.0.tar.bz2.sig
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.28.0.tar.bz2
gpg --verify crosstool-ng-1.28.0.tar.bz2.sig
tar -xjf crosstool-ng-1.28.0.tar.bz2
mv /workspace/crosstool-ng-1.28.0 /crosstool
EOF
# - Add a user that we need for building (crosstool-ng requires non-root user for that).
# - Add some directories we need in the future for building.
# - Build crosstool-ng, which in it's turn will be used to build the cross compiler.
ENV CROSS_DESTDIR=/x-tools
WORKDIR /crosstool
RUN <<EOF
adduser -D crosstoolng
mkdir -p /home/crosstoolng/src
mkdir -p $CROSS_DESTDIR
./bootstrap
./configure
make DESTDIR=$CROSS_DESTDIR
make install
chown -R crosstoolng:crosstoolng /crosstool
chown -R crosstoolng:crosstoolng $CROSS_DESTDIR
chown -R crosstoolng:crosstoolng /home/crosstoolng
EOF
# We now have crosstool-ng built and ready to be used for building the cross-compiler that we actually want. To
# do that we need to feed some configuration
WORKDIR /workspace
ADD --chmod=544 ./scripts/create-cross-compiler.py .
ADD --chmod=544 ./scripts/entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]