1 # Build recipe for GCC.
3 # Copyright (c) 2015-2021 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
30 fetch=https://mirror.marwan.ma/gcc/snapshots/${version}/$tarname
32 # https://www.netgull.com/gcc/snapshots/${version}/$tarname
33 # https://gnu.c3sl.ufpr.br/ftp/gcc/gcc-${version}/$tarname
34 # ftp://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
37 homepage=https://www.gnu.org/software/gcc
38 license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
41 The GNU C Compiler Collection.
43 The GNU Compiler Collection (GCC) is a compiler system produced by the
44 GNU Project supporting various programming languages. GCC is a key
45 component of the GNU toolchain. The Free Software Foundation (FSF)
46 distributes GCC under the GNU General Public License (GNU GPL).
48 For more information about GCC, visit: $homepage
51 # Source documentation
52 docs="COPYING* README"
53 docsdir="${docdir}/${program}-${version}"
57 unpack "${tardir}/$tarname"
61 # Set sane permissions
62 chmod -R u+w,go-w,a+rX-s .
64 # Apply specific patches for the support in musl.
65 # https://port70.net/~nsz/musl/gcc-10.1.0/
67 patch -Np1 -i "${worktree}/patches/gcc/10/0002-posix_memalign.patch"
68 patch -Np1 -i "${worktree}/patches/gcc/10/0003-j2.patch"
69 patch -Np1 -i "${worktree}/patches/gcc/10/0004-static-pie.patch"
71 # Apply extra patches to increment the security
72 patch -Np1 -i "${worktree}/patches/gcc/10/extra-relro-in-dragora.patch"
73 patch -Np1 -i "${worktree}/patches/gcc/10/extra-musl_libssp.patch"
75 # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
76 patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
77 patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
78 patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
79 patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
80 patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
81 patch -Np1 -i "${worktree}/patches/gcc/0020-add-fortify-headers-paths.patch"
82 patch -Np1 -i "${worktree}/patches/gcc/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch"
84 # Create a separate build directory
89 MACHINE="$(gcc -dumpmachine)"
91 ../configure SED=sed \
92 CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
94 --libdir=/usr/lib${libSuffix} \
98 --enable-languages=c,c++,fortran,objc,obj-c++ \
99 --enable-clocale=generic \
100 --enable-threads=posix \
102 --enable-initfini-array \
108 --enable-libstdcxx-time \
109 --enable-checking=release \
110 --enable-fully-dynamic-string \
111 --enable-default-ssp \
112 --enable-default-pie \
114 --enable-initfini-array \
117 --disable-gnu-indirect-function \
118 --disable-libstdcxx-pch \
119 --disable-libmudflap \
120 --disable-libsanitizer \
121 --disable-libcilkrts \
122 --disable-install-libiberty \
124 --with-linker-hash-style=gnu \
132 BOOT_CFLAGS="$QICFLAGS" \
133 BOOT_CXXFLAGS="$QICXXFLAGS" \
134 BOOT_LDFLAGS="$QILDFLAGS" \
135 BOOT_CPPFLAGS="$QICPPFLAGS"
137 make -j${jobs} V=1 DESTDIR="$destdir" install
139 # Delete non-shared version of libssp (provided on the musl package)
140 rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
142 # Strip ELF executables only excluding shared objects
143 find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
144 cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
146 # Strip static libraries in order to reduce the package size
147 find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
148 cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
152 # Move misplaced file(s) for GDB
153 mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
154 mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
155 "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
157 # Provide compatibility and make soft links for package size
159 cd "${destdir}/usr/bin" || exit 1
160 mv gcc gcc-${version}
161 ln -sf gcc-${version} gcc
163 ln -sf gcc-${version} ${MACHINE}-gcc
164 ln -sf gcc-${version} ${MACHINE}-gcc-${version}
166 mv g++ g++-gcc-${version}
167 ln -sf g++-gcc-${version} g++
169 ln -sf g++-gcc-${version} ${MACHINE}-g++
170 ln -sf g++-gcc-${version} ${MACHINE}-c++
172 mv gfortran gfortran-${version}
173 ln -sf gfortran-${version} gfortran
174 ln -sf gfortran-${version} ${MACHINE}-gfortran
175 # Extra symlinks for fortran
181 mv gcc-ar gcc-ar-${version}
182 ln -sf gcc-ar-${version} gcc-ar
183 ln -sf gcc-ar-${version} ${MACHINE}-gcc-ar
185 mv gcc-nm gcc-nm-${version}
186 ln -sf gcc-nm-${version} gcc-nm
187 ln -sf gcc-nm-${version} ${MACHINE}-gcc-nm
189 mv gcc-ranlib gcc-ranlib-${version}
190 ln -sf gcc-ranlib-${version} gcc-ranlib
191 ln -sf gcc-ranlib-${version} ${MACHINE}-gcc-ranlib
194 mkdir -p "${destdir}/lib" && \
195 cd "${destdir}/lib" && ln -sf ../usr/bin/cpp .
200 # Insert wrapper scripts for handling C89 and C99 invocations
201 cat "${worktree}/archive/gcc/c89" > "${destdir}/usr/bin/c89"
202 cat "${worktree}/archive/gcc/c99" > "${destdir}/usr/bin/c99"
203 chmod 755 "${destdir}"/usr/bin/c?9
205 # Compress info documents deleting index file for the package
206 if test -d "${destdir}/$infodir"
208 rm -f "${destdir}/${infodir}/dir"
209 lzip -9 "${destdir}/${infodir}"/* || true
212 # Compress and link man pages (if needed)
213 if test -d "${destdir}/$mandir"
216 cd "${destdir}/$mandir"
217 find . -type f -exec lzip -9 {} +
218 find . -type l | while read -r file
220 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
227 mkdir -p "${destdir}${docsdir}"
228 cp -p $docs "${destdir}${docsdir}/"