-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile
170 lines (146 loc) · 4.8 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
ARG TARGET_ARCH="v850-elf"
ARG TOOLCHAIN_VERSION="master"
ARG TOOLCHAIN_NAME="gcc-${TARGET_ARCH}-${TOOLCHAIN_VERSION}"
ARG TOOLCHAIN_PATH="/opt/${TOOLCHAIN_NAME}"
ARG UBUNTU_VERSION=20.04
FROM ubuntu:$UBUNTU_VERSION AS build
ARG TARGET_ARCH
ARG TOOLCHAIN_VERSION
ARG TOOLCHAIN_NAME
ARG TOOLCHAIN_PATH
ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update && \
apt-get -y install --no-install-recommends \
build-essential \
texinfo \
wget \
&& rm -rf /var/lib/apt/lists/*
ENV DOWNLOAD_PATH="/tmp/${TOOLCHAIN_NAME}/download" \
SOURCES_PATH="/tmp/${TOOLCHAIN_NAME}/sources" \
BUILD_PATH="/tmp/${TOOLCHAIN_NAME}/build"
ENV BINUTILS_VERSION="2.36.1" \
GCC_VERSION="10.3.0" \
GMP_VERSION="6.2.1" \
MPC_VERSION="1.2.1" \
MPFR_VERSION="4.1.0" \
GDB_VERSION="10.2" \
NEWLIB_VERSION="4.1.0"
RUN wget --tries=10 --continue --no-check-certificate --no-verbose \
https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz \
https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz \
https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 \
https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz \
https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.gz \
https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.gz \
ftp://sourceware.org/pub/newlib/newlib-${NEWLIB_VERSION}.tar.gz \
-P ${DOWNLOAD_PATH}
RUN mkdir -p ${SOURCES_PATH} && \
for f in ${DOWNLOAD_PATH}/*.tar.gz; \
do \
tar xf "$f" -C ${SOURCES_PATH}; \
done; \
for f in ${DOWNLOAD_PATH}/*.tar.bz2; \
do \
tar xjf "$f" -C ${SOURCES_PATH}; \
done
RUN cd ${SOURCES_PATH}/gcc-${GCC_VERSION} && \
ln -s ../gmp-${GMP_VERSION} gmp && \
ln -s ../mpc-${MPC_VERSION} mpc && \
ln -s ../mpfr-${MPFR_VERSION} mpfr
# build binutils
RUN mkdir -p ${BUILD_PATH}/binutils && \
cd ${BUILD_PATH}/binutils && \
${SOURCES_PATH}/binutils-${BINUTILS_VERSION}/configure \
--target=${TARGET_ARCH} \
--prefix=${TOOLCHAIN_PATH} \
--disable-nls \
&& \
make -j$(nproc) all && \
make install
ENV GCC_OPTS=" \
--with-gnu-as \
--with-gnu-ld \
--disable-shared \
--disable-libssp \
--disable-threads \
--disable-nls \
--with-newlib \
"
# build gcc - 1st pass
RUN mkdir -p ${BUILD_PATH}/gcc && \
cd ${BUILD_PATH}/gcc && \
${SOURCES_PATH}/gcc-${GCC_VERSION}/configure \
--target=${TARGET_ARCH} \
--prefix=${TOOLCHAIN_PATH} \
--enable-languages=c \
--without-headers \
${GCC_OPTS} \
&& \
make -j$(nproc) all-gcc && \
make install-gcc
# build newlib
# -fcommon forced to mitigate newlib syscalls.c issue with
# 'multiple definition of `errno' due to -fno-common enabled
# by default since gcc-10
RUN mkdir -p ${BUILD_PATH}/newlib && \
cd ${BUILD_PATH}/newlib && \
export CFLAGS_FOR_TARGET="-Os -fcommon" && \
${SOURCES_PATH}/newlib-${NEWLIB_VERSION}/configure \
--target=${TARGET_ARCH} \
--prefix=${TOOLCHAIN_PATH} \
--enable-newlib-nano-formatted-io \
--disable-nls \
&& \
make -j$(nproc) all && \
make install
# build gcc - 2nd pass
RUN cd ${BUILD_PATH}/gcc && \
${SOURCES_PATH}/gcc-${GCC_VERSION}/configure \
--target=${TARGET_ARCH} \
--prefix=${TOOLCHAIN_PATH} \
--enable-languages=c,c++ \
${GCC_OPTS} \
&& \
make -j$(nproc) all && \
make install-strip
# build gdb
RUN mkdir -p ${BUILD_PATH}/gdb && \
cd ${BUILD_PATH}/gdb &&\
${SOURCES_PATH}/gdb-${GDB_VERSION}/configure \
--target=${TARGET_ARCH} \
--prefix=${TOOLCHAIN_PATH} \
--disable-nls \
&& \
make -j$(nproc) all && \
make install
# Toolchain only
FROM ubuntu:$UBUNTU_VERSION AS toolchain
ARG TOOLCHAIN_PATH
COPY --from=build ${TOOLCHAIN_PATH} ${TOOLCHAIN_PATH}
ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update && \
apt-get -y install --no-install-recommends \
apt-transport-https \
ca-certificates \
gnupg \
software-properties-common \
wget \
&& \
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add - && \
apt-add-repository -n 'https://apt.kitware.com/ubuntu/' && \
apt-get -y update && \
apt-get -y install --no-install-recommends \
build-essential \
cmake \
ninja-build \
python2 \
&& rm -rf /var/lib/apt/lists/*
# Protobuf support
RUN apt-get -y update && \
apt-get -y install --no-install-recommends python3-distutils protobuf-compiler && \
wget -q https://bootstrap.pypa.io/get-pip.py && \
python3 get-pip.py && \
pip3 install protobuf && \
rm -rf get-pip.py /var/lib/apt/lists/*