Start mass upgrade
[dragora.git] / stages / 0 / 05-gcc-final
blob3eecc153c5065b946940e7b3ce4ccf7cc4e365a8
1 # Build script for gcc.
3 # Copyright (c) 2016-2022 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=10-20220114
19 # Prerequisites
20 gmp_version=6.2.1
21 mpfr_version=4.1.0
22 mpc_version=1.2.1
23 isl_version=0.24
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 # Make symlinks for requisites
39 ln -s ../gmp-${gmp_version} gmp
40 ln -s ../mpfr-${mpfr_version} mpfr
41 ln -s ../mpc-${mpc_version} mpc
42 ln -s ../isl-${isl_version} isl
44 # Apply patches for MPFR
46     cd mpfr || exit 1
48     for file in "${worktree}"/patches/mpfr/*
49     do
50         if test -f "$file"
51         then
52             rm -f PATCHES
53             patch -p1 < "$file"
54         fi
55     done
58 # Update detection for hosts based on musl
60 cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
61 cp -f "${worktree}/archive/common/config.sub" gmp/config.sub
63 cp -f "${worktree}/archive/common/config.guess" isl/config.guess
64 cp -f "${worktree}/archive/common/config.sub" isl/config.sub
66 # Apply specific patches for the support in musl.
67 # https://port70.net/~nsz/musl/gcc-10.3.0/
69 patch -Np1 -i "${worktree}/patches/gcc/10/0002-posix_memalign.patch"
70 patch -Np1 -i "${worktree}/patches/gcc/10/0003-j2.patch"
71 patch -Np1 -i "${worktree}/patches/gcc/10/0004-static-pie.patch"
72 patch -Np1 -i "${worktree}/patches/gcc/10/0005-libstdc-futex-time64.patch"
73 patch -Np1 -i "${worktree}/patches/gcc/10/0006-m68k-sqrt.patch"
74 patch -Np1 -i "${worktree}/patches/gcc/10/extra-musl_libssp.patch"
76 patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
78 # Build in a separate directory
79 rm -rf ../gcc-build
80 mkdir ../gcc-build
81 cd ../gcc-build
83 option_list="
84  --prefix="$crossdir" \
85  --libdir="${crossdir}/lib${libSuffix}" \
86  --build=$host \
87  --host=$host \
88  --target=$target \
89  --enable-languages=c,c++ \
90  --enable-clocale=generic \
91  --enable-initfini-array \
92  --enable-tls \
93  --enable-libstdcxx-time \
94  --enable-checking=release \
95  --enable-fully-dynamic-string \
96  --enable-libssp \
97  --disable-symvers \
98  --disable-gnu-indirect-function \
99  --disable-libsanitizer \
100  --disable-libmpx \
101  --disable-nls \
102  --with-sysroot="${crossdir}/$target" \
103  $multilib_options \
104  $gcc_options
107 if test -n "$IS_DARKCRUSADE"
108 then
109     ../gcc-${version}/configure CC="$BTCC" CXX="$BTCXX" AR="ar" \
110     CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
111     $option_list
112 else
113     ../gcc-${version}/configure AR="ar" \
114     CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
115     $option_list
118 unset option_list IS_DARKCRUSADE
120 make -j${jobs} all \
121  AS_FOR_TARGET="${target}-as" \
122  LD_FOR_TARGET="${target}-ld"
124 make -j${jobs} install
126 # Insert again libssp_nonshared.a overwritten the recent library
127 ${target}-gcc \
128  -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
129  -o __stack_chk_fail_local.o
131 ${target}-ar rc libssp_nonshared.a __stack_chk_fail_local.o
132 ${target}-ranlib libssp_nonshared.a
133 cp -f libssp_nonshared.a "${crossdir}/${target}/lib/"
135 cd -- "$TMPDIR"
137 cleanup()
139     rm -rf gcc-${version} gcc-build \
140      gmp-${gmp_version} mpfr-${mpfr_version} \
141      mpc-${mpc_version} isl-${isl_version}