1#
2# Docker toolchain cross-compiler
3#
4# This dockerfile is used for building a cross-compiler toolchain.
5# The script for building the toolchain is supplied via extra-files.
6#
7FROM docker.io/library/debian:11-slim
8
9# Install build utilities for building gcc and glibc.
10# ??? The build-dep isn't working, missing a number of
11# minimal build dependiencies, e.g. libmpc.
12
13RUN apt update && \
14    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
15    DEBIAN_FRONTEND=noninteractive eatmydata \
16    apt install -y --no-install-recommends \
17        bison \
18        ca-certificates \
19        flex \
20        gawk \
21        libmpc-dev \
22        libmpfr-dev \
23        rsync \
24        wget && \
25    DEBIAN_FRONTEND=noninteractive eatmydata \
26    apt build-dep -yy --arch-only gcc glibc
27
28ADD build-toolchain.sh /root/build-toolchain.sh
29
30RUN cd /root && ./build-toolchain.sh
31
32# Throw away the extra toolchain build deps, the downloaded source,
33# and the build trees by restoring the original image,
34# then copying the built toolchain from stage 0.
35FROM docker.io/library/debian:11-slim
36COPY --from=0 /usr/local /usr/local
37# As a final step configure the user (if env is defined)
38ARG USER
39ARG UID
40RUN if [ "${USER}" ]; then \
41  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
42