Last active
August 11, 2023 13:51
-
-
Save badcf00d/1aa250e6ca591220e200fd8bc500f731 to your computer and use it in GitHub Desktop.
Dockerfile to build arm-none-eabi-gcc cross-compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:bullseye-20230725 | |
RUN apt-get -y update | |
RUN apt-get -y install build-essential python3 git | |
RUN apt-get -y install libgmp-dev libmpfr-dev libmpc-dev libexpat-dev liblzma-dev libsource-highlight-dev libpython3-dev libbabeltrace-dev libipt-dev libncurses5-dev libdebuginfod-dev meson ninja-build texinfo pkg-config python-is-python3 flex diffutils | |
RUN apt-get -y install --install-suggests gcc | |
# Setup build directory | |
RUN mkdir -p /root/gcc-cross-compiler/build | |
WORKDIR /root/gcc-cross-compiler/ | |
# Clone repositories (may be wise to checkout specific versions i.e. latest release tag) | |
RUN git clone --depth=1 -b releases/gcc-13.1.0 https://gcc.gnu.org/git/gcc.git | |
RUN git clone --depth=1 -b newlib-4.3.0 https://sourceware.org/git/newlib-cygwin.git | |
RUN git clone --depth=1 -b gdb-13.2-release https://sourceware.org/git/binutils-gdb.git | |
RUN git clone --depth=1 -b 1.8.2 https://github.com/picolibc/picolibc.git | |
# Build binutils | |
RUN mkdir -p binutils-build | |
WORKDIR /root/gcc-cross-compiler/binutils-build | |
RUN ../binutils-gdb/configure \ | |
--target=arm-none-eabi \ | |
--prefix=/root/gcc-cross-compiler/build \ | |
--with-pkgversion=my-custom-$(date -I) \ | |
--with-sysroot \ | |
--with-lzma \ | |
--with-expat \ | |
--with-python \ | |
--enable-ld=yes \ | |
--enable-gold=no \ | |
--enable-plugins \ | |
--enable-multilib \ | |
--enable-lto \ | |
--enable-source-highlight \ | |
--disable-werror \ | |
--disable-nls \ | |
--disable-warn-rwx-segments | |
RUN make -j$(nproc) | |
RUN make install | |
# Build gcc (state-1), this is so that our libc implementation below (newlib) | |
# gets compiled with the nice shiny new compiler version as well. This build | |
# will only build the gcc compiler itself, not all of the libraries like libgcc etc. | |
# because for that we need a libc implementation... which we haven't built yet. | |
# | |
# You could alternatively skip this step by installing a arm-none-eabi-gcc | |
# compiler from somewhere else (i.e. sudo apt install gcc-arm-none-eabi) | |
# and use that to compile newlib instead, which will probably work so long as | |
# it has been compiled with multilib support for at least rmprofile | |
# (because of the `--with-multilib-list=rmprofile` below) | |
RUN mkdir -p gcc-stage1-build | |
WORKDIR /root/gcc-cross-compiler/gcc-stage1-build | |
RUN ../gcc/configure \ | |
--prefix=/root/gcc-cross-compiler/build \ | |
--enable-languages=c \ | |
--target=arm-none-eabi \ | |
--with-pkgversion=stage1-my-custom-$(date -I) \ | |
--with-newlib \ | |
--with-sysroot=/root/gcc-cross-compiler/build/arm-none-eabi \ | |
--with-multilib-list=rmprofile \ | |
--without-headers \ | |
--enable-lto \ | |
--enable-multiarch \ | |
--disable-libssp \ | |
--disable-nls \ | |
--disable-tls \ | |
--disable-threads \ | |
--disable-shared | |
RUN make -j$(nproc) all-gcc | |
RUN make install-gcc | |
ENV PATH="/root/gcc-cross-compiler/build/bin:$PATH" | |
# Build newlib using our stage1 compiler (this is essentially newlib-nano) | |
RUN mkdir -p newlib-build | |
WORKDIR /root/gcc-cross-compiler/newlib-build | |
RUN echo "$PATH"; ../newlib-cygwin/configure \ | |
--target=arm-none-eabi \ | |
--prefix=/root/gcc-cross-compiler/build \ | |
--disable-newlib-supplied-syscalls \ | |
--disable-newlib-io-float \ | |
--disable-newlib-io-long-double \ | |
--disable-newlib-io-pos-args \ | |
--disable-newlib-io-c99-formats \ | |
--disable-newlib-io-long-long \ | |
--disable-newlib-multithread \ | |
--disable-newlib-retargetable-locking \ | |
--disable-newlib-wide-orient \ | |
--disable-newlib-fseek-optimization \ | |
--disable-newlib-fvwrite-in-streamio \ | |
--disable-newlib-unbuf-stream-opt \ | |
--disable-newlib-atexit-dynamic-alloc \ | |
--enable-newlib-nano-malloc \ | |
--enable-newlib-nano-formatted-io \ | |
--enable-newlib-global-atexit \ | |
--enable-lite-exit \ | |
--enable-newlib-reent-small \ | |
--enable-libssp \ | |
--enable-target-optspace | |
RUN make -j$(nproc) | |
RUN make install | |
# Build gcc (stage-2), this builds the whole gcc featureset, | |
# including the compiler, and all the gnu compiler libraries | |
RUN mkdir -p gcc-build | |
WORKDIR /root/gcc-cross-compiler/gcc-build | |
RUN ../gcc/configure \ | |
--prefix=/root/gcc-cross-compiler/build \ | |
--enable-languages=c,c++ \ | |
--target=arm-none-eabi \ | |
--with-pkgversion=my-custom-$(date -I) \ | |
--with-newlib \ | |
--with-sysroot=/root/gcc-cross-compiler/build/arm-none-eabi \ | |
--with-multilib-list=rmprofile \ | |
--without-headers \ | |
--enable-lto \ | |
--enable-target-optspace \ | |
--enable-multiarch \ | |
--disable-libssp \ | |
--disable-nls \ | |
--disable-tls \ | |
--disable-threads \ | |
--disable-shared | |
RUN make -j$(nproc) | |
RUN make install | |
# Build picolibc | |
RUN mkdir -p picolibc-build | |
WORKDIR /root/gcc-cross-compiler/picolibc-build | |
RUN ../picolibc/scripts/do-configure arm-none-eabi \ | |
-Dsysroot-install=true \ | |
-Dfast-strcmp=false \ | |
-Dio-c99-formats=false \ | |
-Dnewlib-global-atexit=true \ | |
-Dnewlib-multithread=false \ | |
-Dnewlib-retargetable-locking=false | |
RUN ninja | |
RUN ninja install | |
WORKDIR / | |
RUN cd /root/gcc-cross-compiler/ && rm -rf binutils* gcc* newlib* picolibc* | |
CMD bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment