|
| 1 | +FROM buildpack-deps:buster |
| 2 | + |
| 3 | +RUN set -ex; \ |
| 4 | + if ! command -v gpg > /dev/null; then \ |
| 5 | + apt-get update; \ |
| 6 | + apt-get install -y --no-install-recommends \ |
| 7 | + gnupg \ |
| 8 | + dirmngr \ |
| 9 | + ; \ |
| 10 | + rm -rf /var/lib/apt/lists/*; \ |
| 11 | + fi |
| 12 | + |
| 13 | +# https://gcc.gnu.org/mirrors.html |
| 14 | +ENV GPG_KEYS \ |
| 15 | +# 1024D/745C015A 1999-11-09 Gerald Pfeifer <[email protected]> |
| 16 | + B215C1633BCA0477615F1B35A5B3A004745C015A \ |
| 17 | +# 1024D/B75C61B8 2003-04-10 Mark Mitchell <[email protected]> |
| 18 | + B3C42148A44E6983B3E4CC0793FA9B1AB75C61B8 \ |
| 19 | +# 1024D/902C9419 2004-12-06 Gabriel Dos Reis <[email protected]> |
| 20 | + 90AA470469D3965A87A5DCB494D03953902C9419 \ |
| 21 | +# 1024D/F71EDF1C 2000-02-13 Joseph Samuel Myers <[email protected]> |
| 22 | + 80F98B2E0DAB6C8281BDF541A7C8C3B2F71EDF1C \ |
| 23 | +# 2048R/FC26A641 2005-09-13 Richard Guenther <[email protected]> |
| 24 | + 7F74F97C103468EE5D750B583AB00996FC26A641 \ |
| 25 | +# 1024D/C3C45C06 2004-04-21 Jakub Jelinek <[email protected]> |
| 26 | + 33C235A34C46AA3FFB293709A328C3A2C3C45C06 |
| 27 | +RUN set -ex; \ |
| 28 | + for key in $GPG_KEYS; do \ |
| 29 | + gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ |
| 30 | + done |
| 31 | + |
| 32 | +# https://gcc.gnu.org/mirrors.html |
| 33 | +ENV GCC_MIRRORS \ |
| 34 | + https://ftpmirror.gnu.org/gcc \ |
| 35 | + https://mirrors.kernel.org/gnu/gcc \ |
| 36 | + https://bigsearcher.com/mirrors/gcc/releases \ |
| 37 | + http://www.netgull.com/gcc/releases \ |
| 38 | + https://ftpmirror.gnu.org/gcc \ |
| 39 | +# only attempt the origin FTP as a mirror of last resort |
| 40 | + ftp://ftp.gnu.org/gnu/gcc |
| 41 | + |
| 42 | +# Last Modified: 2020-05-07 |
| 43 | +ENV GCC_VERSION 10.1.0 |
| 44 | +# Docker EOL: 2021-11-07 |
| 45 | + |
| 46 | +RUN set -ex; \ |
| 47 | + \ |
| 48 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 49 | + apt-get update; \ |
| 50 | + apt-get install -y --no-install-recommends \ |
| 51 | + dpkg-dev \ |
| 52 | + flex \ |
| 53 | + ; \ |
| 54 | + rm -r /var/lib/apt/lists/*; \ |
| 55 | + \ |
| 56 | + _fetch() { \ |
| 57 | + local fetch="$1"; shift; \ |
| 58 | + local file="$1"; shift; \ |
| 59 | + for mirror in $GCC_MIRRORS; do \ |
| 60 | + if curl -fL "$mirror/$fetch" -o "$file"; then \ |
| 61 | + return 0; \ |
| 62 | + fi; \ |
| 63 | + done; \ |
| 64 | + echo >&2 "error: failed to download '$fetch' from several mirrors"; \ |
| 65 | + return 1; \ |
| 66 | + }; \ |
| 67 | + \ |
| 68 | + _fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz.sig" 'gcc.tar.xz.sig'; \ |
| 69 | + _fetch "gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.xz" 'gcc.tar.xz'; \ |
| 70 | + gpg --batch --verify gcc.tar.xz.sig gcc.tar.xz; \ |
| 71 | + mkdir -p /usr/src/gcc; \ |
| 72 | + tar -xf gcc.tar.xz -C /usr/src/gcc --strip-components=1; \ |
| 73 | + rm gcc.tar.xz*; \ |
| 74 | + \ |
| 75 | + cd /usr/src/gcc; \ |
| 76 | + \ |
| 77 | +# "download_prerequisites" pulls down a bunch of tarballs and extracts them, |
| 78 | +# but then leaves the tarballs themselves lying around |
| 79 | + ./contrib/download_prerequisites; \ |
| 80 | + { rm *.tar.* || true; }; \ |
| 81 | + \ |
| 82 | +# explicitly update autoconf config.guess and config.sub so they support more arches/libcs |
| 83 | + for f in config.guess config.sub; do \ |
| 84 | + wget -O "$f" "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb"; \ |
| 85 | +# find any more (shallow) copies of the file we grabbed and update them too |
| 86 | + find -mindepth 2 -name "$f" -exec cp -v "$f" '{}' ';'; \ |
| 87 | + done; \ |
| 88 | + \ |
| 89 | + dir="$(mktemp -d)"; \ |
| 90 | + cd "$dir"; \ |
| 91 | + \ |
| 92 | + extraConfigureArgs=''; \ |
| 93 | + dpkgArch="$(dpkg --print-architecture)"; \ |
| 94 | + case "$dpkgArch" in \ |
| 95 | +# with-arch: https://anonscm.debian.org/viewvc/gcccvs/branches/sid/gcc-6/debian/rules2?revision=9450&view=markup#l491 |
| 96 | +# with-float: https://anonscm.debian.org/viewvc/gcccvs/branches/sid/gcc-6/debian/rules.defs?revision=9487&view=markup#l416 |
| 97 | +# with-mode: https://anonscm.debian.org/viewvc/gcccvs/branches/sid/gcc-6/debian/rules.defs?revision=9487&view=markup#l376 |
| 98 | + armel) \ |
| 99 | + extraConfigureArgs="$extraConfigureArgs --with-arch=armv4t --with-float=soft" \ |
| 100 | + ;; \ |
| 101 | + armhf) \ |
| 102 | + extraConfigureArgs="$extraConfigureArgs --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-mode=thumb" \ |
| 103 | + ;; \ |
| 104 | + \ |
| 105 | +# with-arch-32: https://anonscm.debian.org/viewvc/gcccvs/branches/sid/gcc-6/debian/rules2?revision=9450&view=markup#l590 |
| 106 | + i386) \ |
| 107 | + osVersionID="$(set -e; . /etc/os-release; echo "$VERSION_ID")"; \ |
| 108 | + case "$osVersionID" in \ |
| 109 | + 8) extraConfigureArgs="$extraConfigureArgs --with-arch-32=i586" ;; \ |
| 110 | + *) extraConfigureArgs="$extraConfigureArgs --with-arch-32=i686" ;; \ |
| 111 | + esac; \ |
| 112 | +# TODO for some reason, libgo + i386 fails on https://github.com/gcc-mirror/gcc/blob/gcc-7_1_0-release/libgo/runtime/proc.c#L154 |
| 113 | +# "error unknown case for SETCONTEXT_CLOBBERS_TLS" |
| 114 | + ;; \ |
| 115 | + esac; \ |
| 116 | + \ |
| 117 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 118 | + /usr/src/gcc/configure \ |
| 119 | + --build="$gnuArch" \ |
| 120 | + --disable-multilib \ |
| 121 | + --enable-languages=c,c++,fortran,go \ |
| 122 | + $extraConfigureArgs \ |
| 123 | + ; \ |
| 124 | + make -j "$(nproc)"; \ |
| 125 | + make install-strip; \ |
| 126 | + \ |
| 127 | + cd ..; \ |
| 128 | + \ |
| 129 | + rm -rf "$dir" /usr/src/gcc; \ |
| 130 | + \ |
| 131 | + apt-mark auto '.*' > /dev/null; \ |
| 132 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ |
| 133 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false |
| 134 | + |
| 135 | +# gcc installs .so files in /usr/local/lib64... |
| 136 | +RUN set -ex; \ |
| 137 | + echo '/usr/local/lib64' > /etc/ld.so.conf.d/local-lib64.conf; \ |
| 138 | + ldconfig -v |
| 139 | + |
| 140 | +# ensure that alternatives are pointing to the new compiler and that old one is no longer used |
| 141 | +RUN set -ex; \ |
| 142 | + dpkg-divert --divert /usr/bin/gcc.orig --rename /usr/bin/gcc; \ |
| 143 | + dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++; \ |
| 144 | + dpkg-divert --divert /usr/bin/gfortran.orig --rename /usr/bin/gfortran; \ |
| 145 | + update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999 |
0 commit comments