1 # Build recipe for GCC.
3 # Copyright (c) 2015-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 # Exit immediately on any error
24 # Define a category for the output of the package name
27 tarname=${program}-${version}.tar.xz
31 https://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
32 https://mirrors.concertpass.com/gcc/snapshots/${version}/$tarname
33 https://mirror.marwan.ma/gcc/snapshots/${version}/$tarname
36 homepage=https://www.gnu.org/software/gcc
37 license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
40 The GNU C Compiler Collection.
42 The GNU Compiler Collection (GCC) is a compiler system produced by the
43 GNU Project supporting various programming languages. GCC is a key
44 component of the GNU toolchain. The Free Software Foundation (FSF)
45 distributes GCC under the GNU General Public License (GNU GPL).
47 For more information about GCC, visit: $homepage
50 # Source documentation
51 docs="COPYING* README"
52 docsdir="${docdir}/${program}-${version}"
56 unpack "${tardir}/$tarname"
60 # Set sane permissions
61 chmod -R u+w,go-w,a+rX-s .
63 # Apply specific patches for the support in musl.
64 # https://port70.net/~nsz/musl/gcc-10.3.0/
66 patch -Np1 -i "${worktree}/patches/gcc/10/0002-posix_memalign.patch"
67 patch -Np1 -i "${worktree}/patches/gcc/10/0003-j2.patch"
68 patch -Np1 -i "${worktree}/patches/gcc/10/0004-static-pie.patch"
69 patch -Np1 -i "${worktree}/patches/gcc/10/0005-libstdc-futex-time64.patch"
70 patch -Np1 -i "${worktree}/patches/gcc/10/0006-m68k-sqrt.patch"
71 patch -Np1 -i "${worktree}/patches/gcc/10/extra-musl_libssp.patch"
72 patch -Np1 -i "${worktree}/patches/gcc/10/extra-relro-in-dragora.patch"
74 # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
75 patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
76 patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
77 patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
78 patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
79 patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
80 patch -Np1 -i "${worktree}/patches/gcc/0020-add-fortify-headers-paths.patch"
82 # Create a separate build directory
88 MACHINE="$(gcc -dumpmachine)"
90 ../configure SED=sed \
91 CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
93 --libdir=/usr/lib${libSuffix} \
97 --enable-languages=c,c++,fortran,objc,obj-c++ \
98 --enable-clocale=generic \
99 --enable-threads=posix \
101 --enable-initfini-array \
107 --enable-libstdcxx-time \
108 --enable-checking=release \
109 --enable-fully-dynamic-string \
110 --enable-default-ssp \
111 --enable-default-pie \
113 --enable-initfini-array \
116 --disable-gnu-indirect-function \
117 --disable-libstdcxx-pch \
118 --disable-libsanitizer \
119 --disable-libcilkrts \
120 --disable-install-libiberty \
122 --with-linker-hash-style=gnu \
130 BOOT_CFLAGS="$QICFLAGS" \
131 BOOT_CXXFLAGS="$QICXXFLAGS" \
132 BOOT_LDFLAGS="$QILDFLAGS" \
133 BOOT_CPPFLAGS="$QICPPFLAGS"
135 make -j${jobs} V=1 DESTDIR="$destdir" install
137 # Delete non-shared version of libssp (provided on the musl package)
138 rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
140 # Strip ELF executables only excluding shared objects
141 find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
142 cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
144 # Strip static libraries in order to reduce the package size
145 find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
146 cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
150 # Move misplaced file(s) for GDB
151 mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
152 mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
153 "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
155 # Provide compatibility and make soft links for package size
157 cd "${destdir}/usr/bin" || exit 1
159 mv gcc gcc-${version}
160 ln -sf gcc-${version} gcc
162 ln -sf gcc-${version} ${MACHINE}-gcc
163 ln -sf gcc-${version} ${MACHINE}-gcc-${version}
165 mv g++ g++-gcc-${version}
166 ln -sf g++-gcc-${version} g++
168 ln -sf g++-gcc-${version} ${MACHINE}-g++
169 ln -sf g++-gcc-${version} ${MACHINE}-c++
171 mv gfortran gfortran-${version}
172 ln -sf gfortran-${version} gfortran
173 ln -sf gfortran-${version} ${MACHINE}-gfortran
174 # Extra symlinks for fortran
180 mv gcc-ar gcc-ar-${version}
181 ln -sf gcc-ar-${version} gcc-ar
182 ln -sf gcc-ar-${version} ${MACHINE}-gcc-ar
184 mv gcc-nm gcc-nm-${version}
185 ln -sf gcc-nm-${version} gcc-nm
186 ln -sf gcc-nm-${version} ${MACHINE}-gcc-nm
188 mv gcc-ranlib gcc-ranlib-${version}
189 ln -sf gcc-ranlib-${version} gcc-ranlib
190 ln -sf gcc-ranlib-${version} ${MACHINE}-gcc-ranlib
193 cd "${destdir}/usr/lib${libSuffix}" && ln -sf ../bin/cpp .
198 # Insert wrapper scripts for handling C89 and C99 invocations
199 cat "${worktree}/archive/gcc/c89" > "${destdir}/usr/bin/c89"
200 cat "${worktree}/archive/gcc/c99" > "${destdir}/usr/bin/c99"
201 chmod 755 "${destdir}"/usr/bin/c?9
203 # Compress info documents deleting index file for the package
204 if test -d "${destdir}/$infodir"
206 rm -f "${destdir}/${infodir}/dir"
207 lzip -9 "${destdir}/${infodir}"/* || true
210 # Compress and link man pages (if needed)
211 if test -d "${destdir}/$mandir"
214 cd "${destdir}/$mandir"
215 find . -type f -exec lzip -9 {} +
216 find . -type l | while read -r file
218 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
225 mkdir -p "${destdir}${docsdir}"
226 cp -p $docs "${destdir}${docsdir}/"