gcc upgraded to version 9-20191005
[dragora.git] / stages / 1 / 05-gcc
bloba57df2d9bdbebde5ada87702362470fd782d1567
1 # Build script for gcc.
3 # Copyright (c) 2016-2019 Matias Fonzo, <selk@dragora.org>.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 #    http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 version=9-20191005
19 # Prerequisites
20 gmp_version=6.1.2
21 mpfr_version=4.0.2
22 mpc_version=1.1.0
23 isl_version=0.21
25 cd -- "$TMPDIR"
27 rm -rf gcc-${version} gmp-${gmp_version} \
28        mpfr-${mpfr_version} mpc-${mpc_version} isl-${isl_version}
29 unpack "${worktree}/sources/gcc-${version}.tar.xz" \
30        "${worktree}/sources/gmp-${gmp_version}.tar.lz" \
31        "${worktree}/sources/mpfr-${mpfr_version}.tar.bz2" \
32        "${worktree}/sources/mpc-${mpc_version}.tar.gz" \
33        "${worktree}/sources/isl-${isl_version}.tar.bz2"
35 # Build instructions
36 cd gcc-${version}
38 # Apply specific patches for the support in musl.
39 # http://port70.net/~nsz/musl/gcc-9.1.0/
41 patch -Np1 -i "${worktree}/patches/gcc/230-musl_libssp.patch"
42 patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
43 patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
44 patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
45 patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
46 patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
47 patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
48 patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
49 patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
50 patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
51 patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
52 patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
53 patch -Np1 -i "${worktree}/patches/gcc/0013-invalid-tls-model.patch"
54 patch -Np1 -i "${worktree}/patches/gcc/turn-on-relro-bydefault.patch"
56 # Hard code default paths to look in /tools
57 for file in \
58  gcc/config/linux.h gcc/config/i386/linux.h gcc/config/i386/linux64.h \
59  gcc/config/arm/linux-eabi.h gcc/config/arm/linux-elf.h \
60  gcc/config/mips/linux.h \
61  gcc/config/rs6000/linux64.h gcc/config/rs6000/sysv4.h \
62  gcc/config/aarch64/aarch64-linux.h \
63  gcc/config/microblaze/linux.h \
64  gcc/config/sh/linux.h \
65  gcc/config/riscv/linux.h ; \
67     if test ! -f "$file"
68     then
69         echo "WARNING: ${0}: Non-existent file: $file" 1>&2
70         continue;
71     fi
72     sed -i \
73      -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
74      -e 's@/usr@/tools@g' "$file"
75     echo '
76 #undef STANDARD_STARTFILE_PREFIX_1
77 #undef STANDARD_STARTFILE_PREFIX_2
78 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
79 #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
80 done
82 # Make symlinks for requisites
83 ln -s ../gmp-${gmp_version} gmp
84 ln -s ../mpfr-${mpfr_version} mpfr
85 ln -s ../mpc-${mpc_version} mpc
86 ln -s ../isl-${isl_version} isl
88 # Apply patches for MPFR
90     cd mpfr || exit 1
92     for file in "${worktree}"/patches/mpfr/*
93     do
94         if test -f "$file"
95         then
96             rm -f PATCHES
97             patch -p1 < "$file"
98         fi
99     done
102 # Update detection for hosts based on musl
104 cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
105 cp -f "${worktree}/archive/common/config.sub" gmp/config.sub
107 for directory in mpfr mpc isl
109     cp -f "${worktree}/archive/common/config.guess" ${directory}/config.guess
110     cp -f "${worktree}/archive/common/config.sub" ${directory}/config.sub
111 done
112 unset directory
114 # Build in a separate directory
115 rm -rf ../gcc-build
116 mkdir ../gcc-build
117 cd ../gcc-build
119 # Import and export toolchain variables
120 . "${worktree}/stages/env.d/cross-staticenv"
122 ../gcc-${version}/configure \
123 AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
124 CC="$BTCC" CXX="$BTCXX" \
125 CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
126  --prefix=/tools \
127  --libdir=/tools/lib${libSuffix} \
128  --build=$host \
129  --host=$target \
130  --target=$target \
131  --enable-languages=c,c++ \
132  --enable-clocale=generic \
133  --enable-cet=auto \
134  --enable-tls \
135  --enable-libstdcxx-time \
136  --enable-install-libiberty \
137  --enable-fully-dynamic-string \
138  --enable-default-ssp \
139  --enable-default-pie \
140  --enable-libssp \
141  --disable-symvers \
142  --disable-bootstrap \
143  --disable-libstdcxx-pch \
144  --disable-gnu-indirect-function \
145  --disable-libmudflap \
146  --disable-libsanitizer \
147  --disable-nls \
148  --with-local-prefix=/tools \
149  --with-native-system-header-dir=/tools/include \
150  $multilib_options \
151  $gcc_options
153 make -j${jobs} all \
154  AS_FOR_TARGET="$AS" \
155  LD_FOR_TARGET="$LD"
157 make -j${jobs} install
159 # Provide minimal libssp_nonshared.a
161 $BTCC -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
162       -o __stack_chk_fail_local.o
163 $AR rc libssp_nonshared.a __stack_chk_fail_local.o
164 $RANLIB libssp_nonshared.a
165 cp -p libssp_nonshared.a /tools/lib${libSuffix}
167 # Unset some imported variables from file
168 unset AR AS LD RANLIB READELF STRIP
170 cd -- "$TMPDIR"
172 cleanup()
174     rm -rf gcc-${version} gcc-build \
175      gmp-${gmp_version} mpfr-${mpfr_version} \
176      mpc-${mpc_version} isl-${isl_version}