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 sed 's/^deb /deb-src /' </etc/apt/sources.list >/etc/apt/sources.list.d/deb-src.list
14
15RUN apt update && \
16    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
17    DEBIAN_FRONTEND=noninteractive eatmydata \
18    apt install -y --no-install-recommends \
19        bison \
20        ca-certificates \
21        flex \
22        gawk \
23        libmpc-dev \
24        libmpfr-dev \
25        rsync \
26        wget && \
27    DEBIAN_FRONTEND=noninteractive eatmydata \
28    apt build-dep -yy --arch-only gcc glibc
29
30ADD build-toolchain.sh /root/build-toolchain.sh
31
32RUN cd /root && ./build-toolchain.sh
33
34# Throw away the extra toolchain build deps, the downloaded source,
35# and the build trees by restoring the original image,
36# then copying the built toolchain from stage 0.
37FROM docker.io/library/debian:11-slim
38RUN apt update && \
39    DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \
40    DEBIAN_FRONTEND=noninteractive eatmydata \
41    apt install -y --no-install-recommends \
42        libmpc3
43COPY --from=0 /usr/local /usr/local
44# As a final step configure the user (if env is defined)
45ARG USER
46ARG UID
47RUN if [ "${USER}" ]; then \
48  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
49