5 # SPDX-FileCopyrightText: 2022 Jason Self <j@jxself.org>
6 # SPDX-License-Identifier: AGPL-3.0-or-later
8 # This program is used to set up compilers to use for building GNU
11 # You will need a GNU/Linux system with a working compiler; GCC is
14 # You'll also need Autoconf, including Autoconf Archive, Bison,
15 # Flex, GnuPG, Gzip, Libtool, Lzip, Make, Tar, Texinfo, Wget, and
18 # On Trisquel you can install these with:
20 # apt install autoconf autoconf-archive bison flex g++ gcc gnupg
21 # gcc-multilib gzip libtool lzip make tar texinfo wget xz-utils
23 # Note that the GNU C Library is not built so these compilers are only
24 # functional for kernel builds; they cannot be used to build userspace
27 # These are the architectures that compilers will be built for.
28 # Adjust as needed. Changes may also need to be made further down to
29 # account for architectures-specific differences.
47 # We'll be downloading the source code for various programs and
48 # will need to use GPG to verify that things haven't been tampered
49 # with. While it could be possible to download the gnu-keyring.gpg
50 # file, downloading the keys from the same place that you're
51 # getting the source code from could open up problems if both are
52 # replaced with malicious versions. For this reason the expected
53 # keys are stored independently here, in the 'keys' directory and
54 # used for verification. Each file is named with the key
55 # fingerprint. They're stored in ASCII-armored format.
56 if [ ! -f "gnu-keyring.gpg" ]; then
57 for keyfile in keys/*.asc
59 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --import $keyfile
67 # This handles the actual downloading the of the source code from
68 # the GNU FTP mirrors along with invoking GPG for verification.
69 if [ ! -f "binutils-$binutils_version.tar.lz" ]; then
70 wget http://ftpmirror.gnu.org/gnu/binutils/binutils-$binutils_version.tar.lz
71 wget http://ftpmirror.gnu.org/gnu/binutils/binutils-$binutils_version.tar.lz.sig
72 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --verify binutils-$binutils_version.tar.lz.sig
74 if [ ! -f "gcc-$gcc_version.tar.xz" ]; then
75 wget http://ftpmirror.gnu.org/gnu/gcc/gcc-$gcc_version/gcc-$gcc_version.tar.xz
76 wget http://ftpmirror.gnu.org/gnu/gcc/gcc-$gcc_version/gcc-$gcc_version.tar.xz.sig
77 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --verify gcc-$gcc_version.tar.xz.sig
79 if [ ! -f "gmp-$gmp_version.tar.lz" ]; then
80 wget http://ftpmirror.gnu.org/gnu/gmp/gmp-$gmp_version.tar.lz
81 wget http://ftpmirror.gnu.org/gnu/gmp/gmp-$gmp_version.tar.lz.sig
82 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --verify gmp-$gmp_version.tar.lz.sig
84 if [ ! -f "mpc-$mpc_version.tar.gz" ]; then
85 wget http://ftpmirror.gnu.org/gnu/mpc/mpc-$mpc_version.tar.gz
86 wget http://ftpmirror.gnu.org/gnu/mpc/mpc-$mpc_version.tar.gz.sig
87 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --verify mpc-$mpc_version.tar.gz.sig
89 if [ ! -f "mpfr-$mpfr_version.tar.xz" ]; then
90 wget http://ftpmirror.gnu.org/gnu/mpfr/mpfr-$mpfr_version.tar.xz
91 wget http://ftpmirror.gnu.org/gnu/mpfr/mpfr-$mpfr_version.tar.xz.sig
92 gpg --no-default-keyring --keyring ./gnu-keyring.gpg --verify mpfr-$mpfr_version.tar.xz.sig
97 # After the source code has been downloaded and verified, this
98 # function extracts the tarballs and places things into the
99 # appropriate locations as needed.
100 if [ ! -d "binutils-$binutils_version" ]; then
101 tar xf binutils-$binutils_version.tar.lz
103 if [ ! -d "gcc-$gcc_version" ]; then
104 tar xf gcc-$gcc_version.tar.xz
106 if [ ! -d "gcc-$gcc_version/gmp" ]; then
107 mkdir gcc-$gcc_version/gmp
108 tar xf gmp-$gmp_version.tar.lz -C gcc-$gcc_version/gmp --strip-components=1
110 if [ ! -d "gcc-$gcc_version/mpc" ]; then
111 mkdir gcc-$gcc_version/mpc
112 tar xf mpc-$mpc_version.tar.gz -C gcc-$gcc_version/mpc --strip-components=1
114 if [ ! -d "gcc-$gcc_version/mpfr" ]; then
115 mkdir gcc-$gcc_version/mpfr
116 tar xf mpfr-$mpfr_version.tar.xz -C gcc-$gcc_version/mpfr --strip-components=1
117 # Regenerate GNU build system files for MPFR due to version
118 # differences with MPFR wanting a newer version of Automake
120 cd gcc-$gcc_version/mpfr
127 # This function handles the actual compiling of the toolchain.
130 if [ "$1" = "binutils" ]; then
131 ../binutils-$binutils_version/configure --target=$target --prefix=$dir/$toolchain_directory --disable-gdb --disable-libdecnumber --disable-nls --disable-readline --disable-sim --disable-werror --enable-64-bit-bfd --enable-obsolete 2>&1 | tee ../logs-$toolchain_directory/$target.log
132 elif [ "$1" = "gcc" ]; then
133 ../gcc-$gcc_version/configure --target=$target --prefix=$dir/$toolchain_directory --disable-bootstrap --disable-decimal-float --disable-libatomic --disable-libcc1 --disable-libgomp --disable-libmpx --disable-libmudflap --disable-libquadmath --disable-libssp --disable-nls --disable-shared --disable-threads --enable-checking=release --enable-languages=c --enable-targets=all --without-headers `if [[ $architectures == powerpc64le-* ]]; then echo "--disable-multilib";fi` 2>&1 | tee -a ../logs-$toolchain_directory/$target.log
135 make -j`nproc` 2>&1 | tee -a ../logs-$toolchain_directory/$target.log
136 make install 2>&1 | tee -a ../logs-$toolchain_directory/$target.log
142 # This adjusts the path to point to the location where the
143 # programs are being installed in order to use them during this
147 # Save $PATH for later restoration
149 export PATH=$dir/$toolchain_directory/bin:$PATH
153 # This changes the $PATH back to what it was originally. This is
154 # to prevent the $PATH from continuing to grow between loops and
155 # make sure it always points to the correct place, as adjusted for
156 # each run through the loop for each architecture.
160 setup_directories () {
161 # This make sure that certain needed directories exist before
162 # starting and to also make sure that any intermediate build
163 # directory is removed before starting, in case there had been a
164 # build failure in a prior attempt.
165 if [ ! -d "logs-$toolchain_directory" ]; then
166 mkdir logs-$toolchain_directory
169 if [ ! -d "$toolchain_directory" ]; then
170 mkdir $toolchain_directory
173 if [ -d "build" ]; then
178 # This loop is responsible for setting up any architecture-specific
179 # adjustments. Anything not called out as being a special case will be
180 # built using the default settings.
181 for target in "${architectures[@]}"
184 # Note the generally desired software versions. In some cases
185 # some architectures may need different versions of these.
186 # Examples include older kernel series that don't build with new
187 # versions of GCC, or for other reasons. As a result any given
188 # architecture may need to set up more than one combination of
189 # these. These are just the defaults and are adjusted for specific
190 # architectures as needed as the program runs.
191 export gcc_version="12.2.0"
192 export binutils_version="2.39"
193 export gmp_version="6.2.1"
194 export mpc_version="1.2.1"
195 export mpfr_version="4.1.0"
196 # The $toolchain_directory variable is used to store each
197 # compiled toolchain, named after the associated GCC version when
198 # the above versions are being used. The intention is to change
199 # the directory name to something else when needing to assemble a
200 # different variant based on the need of some specific
201 # architecture, such as needing to build the latest GCC but with
202 # an older version of binutils or for any other situation where a
203 # different name would be desirable so as to distinguish them from
204 # other toolchain builds that use the defaults.
205 export toolchain_directory="toolchain-$gcc_version"
215 # Now build some additional toolchains beyond the default ones. This
216 # is because some older kernels needs older toolchain versions.
219 # The 4.9 kernel series needs to be built with GCC 11.3
220 export gcc_version="11.3.0"
221 export toolchain_directory="toolchain-$gcc_version"
234 # The 6.0 series needs to be build with binutils 2.38
235 export binutils_version="2.38"
236 export toolchain_directory="toolchain-$gcc_version-binutils-$binutils_version"
249 # The 5.10 needs to be build with GCC 11.3
250 export gcc_version="11.3.0"
251 export toolchain_directory="toolchain-$gcc_version"
264 # The 5.10 and 4.9 series needs to be build with GCC 11.3
265 export gcc_version="11.3.0"
266 export toolchain_directory="toolchain-$gcc_version"
279 # The 4.9, and 4.14 kernel series needs to be built with GCC 8.5
280 export gcc_version="8.5.0"
281 export toolchain_directory="toolchain-$gcc_version"