~dragora/dragora/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Build script for gcc.
#
# Copyright (c) 2016-2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=9-20191012

# Prerequisites
gmp_version=6.1.2
mpfr_version=4.0.2
mpc_version=1.1.0
isl_version=0.21

cd -- "$TMPDIR"

rm -rf gcc-${version} gmp-${gmp_version} \
       mpfr-${mpfr_version} mpc-${mpc_version} isl-${isl_version}
unpack "${worktree}/sources/gcc-${version}.tar.xz" \
       "${worktree}/sources/gmp-${gmp_version}.tar.lz" \
       "${worktree}/sources/mpfr-${mpfr_version}.tar.bz2" \
       "${worktree}/sources/mpc-${mpc_version}.tar.gz" \
       "${worktree}/sources/isl-${isl_version}.tar.bz2" 

# Build instructions
cd gcc-${version}

# Make symlinks for requisites
ln -s ../gmp-${gmp_version} gmp
ln -s ../mpfr-${mpfr_version} mpfr
ln -s ../mpc-${mpc_version} mpc
ln -s ../isl-${isl_version} isl

# Apply patches for MPFR
(
    cd mpfr || exit 1

    for file in "${worktree}"/patches/mpfr/*
    do
        if test -f "$file"
        then
            rm -f PATCHES
            patch -p1 < "$file"
        fi
    done
)

# Update detection for hosts based on musl

cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
cp -f "${worktree}/archive/common/config.sub" gmp/config.sub

for directory in mpfr mpc isl
do
    cp -f "${worktree}/archive/common/config.guess" ${directory}/config.guess
    cp -f "${worktree}/archive/common/config.sub" ${directory}/config.sub
done
unset directory

# Apply specific patches for the support in musl.
# http://port70.net/~nsz/musl/gcc-9.1.0/

patch -Np1 -i "${worktree}/patches/gcc/230-musl_libssp.patch"
patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
patch -Np1 -i "${worktree}/patches/gcc/0013-invalid-tls-model.patch"

# Build in a separate directory
rm -rf ../gcc-build
mkdir ../gcc-build
cd ../gcc-build

option_list="
 --prefix="$crossdir" \
 --libdir="${crossdir}/lib${libSuffix}" \
 --build=$host \
 --host=$host \
 --target=$target \
 --enable-languages=c,c++ \
 --enable-clocale=generic \
 --enable-tls \
 --enable-libstdcxx-time \
 --enable-checking=release \
 --enable-fully-dynamic-string \
 --enable-libssp \
 --disable-symvers \
 --disable-gnu-indirect-function \
 --disable-libmudflap \
 --disable-libsanitizer \
 --disable-libmpx \
 --disable-nls \
 --disable-lto-plugin \
 --with-sysroot="${crossdir}/$target" \
 $multilib_options \
 $gcc_options
"

if test -n "$IS_DARKCRUSADE"
then
    ../gcc-${version}/configure CC="$BTCC" CXX="$BTCXX" AR="ar" \
    CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
    $option_list
else
    ../gcc-${version}/configure AR="ar" \
    CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
    $option_list
fi

unset option_list IS_DARKCRUSADE

make -j${jobs} all \
 AS_FOR_TARGET="${target}-as" \
 LD_FOR_TARGET="${target}-ld"

make -j${jobs} install

# Inset again libssp_nonshared.a overwritten the recent library
${target}-gcc \
 -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
 -o __stack_chk_fail_local.o

${target}-ar rc libssp_nonshared.a __stack_chk_fail_local.o
${target}-ranlib libssp_nonshared.a
cp -f libssp_nonshared.a "${crossdir}/${target}/lib/"

cd -- "$TMPDIR"

cleanup()
{
    rm -rf gcc-${version} gcc-build \
     gmp-${gmp_version} mpfr-${mpfr_version} \
     mpc-${mpc_version} isl-${isl_version}
}