Revert "gcc upgraded to version 8-20190222"
[dragora.git] / stages / 1 / 05-gcc
blobe68de837fea6188624258ccbb213616651a2ce6f
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=8-20190201
19 # Prerequisites
20 gmp_version=6.1.2
21 mpfr_version=4.0.2
22 mpc_version=1.1.0
23 isl_version=0.20
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-8.2.0
41 #patch -Np1 -i "${worktree}/patches/gcc/0001-ssp_nonshared.patch"
42 patch -Np1 -i "${worktree}/patches/gcc/musl-libssp.diff"
43 patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
44 patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
45 patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
46 patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
47 patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
48 patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
49 patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
50 patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
51 patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
52 patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
53 patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
55 # Hard code default paths to look in /tools
56 for file in \
57  gcc/config/linux.h gcc/config/i386/linux.h gcc/config/i386/linux64.h \
58  gcc/config/arm/linux-eabi.h gcc/config/arm/linux-elf.h \
59  gcc/config/mips/linux.h \
60  gcc/config/rs6000/linux64.h gcc/config/rs6000/sysv4.h \
61  gcc/config/aarch64/aarch64-linux.h \
62  gcc/config/microblaze/linux.h \
63  gcc/config/sh/linux.h ; \
65     if test ! -f "$file"
66     then
67         echo "WARNING: ${0}: Non-existent file: $file" 1>&2
68         continue;
69     fi
70     sed -i \
71      -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
72      -e 's@/usr@/tools@g' "$file"
73     echo '
74 #undef STANDARD_STARTFILE_PREFIX_1
75 #undef STANDARD_STARTFILE_PREFIX_2
76 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
77 #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
78 done
80 # Make symlinks for requisites
81 ln -s ../gmp-${gmp_version} gmp
82 ln -s ../mpfr-${mpfr_version} mpfr
83 ln -s ../mpc-${mpc_version} mpc
84 ln -s ../isl-${isl_version} isl
86 # Apply patches for MPFR
88     cd mpfr || exit 1
90     for file in "${worktree}"/patches/mpfr/*
91     do
92         if test -f "$file"
93         then
94             rm -f PATCHES
95             patch -p1 < "$file"
96         fi
97     done
100 # Build in a separate directory
101 rm -rf ../gcc-build
102 mkdir ../gcc-build
103 cd ../gcc-build
105 # Import and export toolchain variables
106 . "${worktree}/stages/env.d/cross-staticenv"
108 ../gcc-${version}/configure \
109 AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
110 CC="$BTCC" CXX="$BTCXX" \
111 CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
112  --prefix=/tools \
113  --libdir=/tools/lib${libSuffix} \
114  --build=$host \
115  --host=$target \
116  --target=$target \
117  --enable-languages=c,c++ \
118  --enable-clocale=generic \
119  --enable-tls \
120  --enable-libstdcxx-time \
121  --enable-install-libiberty \
122  --enable-fully-dynamic-string \
123  --enable-default-ssp \
124  --enable-default-pie \
125  --disable-libssp \
126  --disable-symvers \
127  --disable-bootstrap \
128  --disable-libstdcxx-pch \
129  --disable-gnu-indirect-function \
130  --disable-libmudflap \
131  --disable-libsanitizer \
132  --disable-libmpx \
133  --disable-nls \
134  --with-local-prefix=/tools \
135  --with-native-system-header-dir=/tools/include \
136  $multilib_options \
137  $gcc_options
139 make -j${jobs} all \
140  AS_FOR_TARGET="$AS" \
141  LD_FOR_TARGET="$LD"
143 make -j${jobs} install
145 # Provide minimal libssp_nonshared.a so we don't need libssp from GCC
147 $BTCC $BTCFLAGS -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
148                 -o __stack_chk_fail_local.o
149 $AR r libssp_nonshared.a __stack_chk_fail_local.o
151 cp -p libssp_nonshared.a /tools/lib${libSuffix}/
153 # Unset some imported variables from file
154 unset AR AS LD RANLIB READELF STRIP
156 cd -- "$TMPDIR"
158 cleanup()
160     rm -rf gcc-${version} gcc-build \
161      gmp-${gmp_version} mpfr-${mpfr_version} \
162      mpc-${mpc_version} isl-${isl_version}