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.
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"
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
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 ; \
67 echo "WARNING: ${0}: Non-existent file: $file" 1>&2
71 -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
72 -e 's@/usr@/tools@g' "$file"
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"
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
90 for file in "${worktree}"/patches/mpfr/*
100 # Build in a separate directory
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" \
113 --libdir=/tools/lib${libSuffix} \
117 --enable-languages=c,c++ \
118 --enable-clocale=generic \
120 --enable-libstdcxx-time \
121 --enable-install-libiberty \
122 --enable-fully-dynamic-string \
123 --enable-default-ssp \
124 --enable-default-pie \
127 --disable-bootstrap \
128 --disable-libstdcxx-pch \
129 --disable-gnu-indirect-function \
130 --disable-libmudflap \
131 --disable-libsanitizer \
134 --with-local-prefix=/tools \
135 --with-native-system-header-dir=/tools/include \
140 AS_FOR_TARGET="$AS" \
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
160 rm -rf gcc-${version} gcc-build \
161 gmp-${gmp_version} mpfr-${mpfr_version} \
162 mpc-${mpc_version} isl-${isl_version}