recipe 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # Build recipe for GCC.
  2. #
  3. # Copyright (c) 2015-2023 Matias Fonzo, <selk@dragora.org>.
  4. #
  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
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  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.
  16. # Exit immediately on any error
  17. set -e
  18. program=gcc
  19. version=11-20230310
  20. release=1
  21. # Define a category for the output of the package name
  22. pkgcategory=devel
  23. tarname=${program}-${version}.tar.xz
  24. # Remote source(s)
  25. fetch="
  26. https://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
  27. https://mirrors.concertpass.com/gcc/snapshots/${version}/$tarname
  28. https://mirror.marwan.ma/gcc/snapshots/${version}/$tarname
  29. "
  30. homepage=https://www.gnu.org/software/gcc
  31. license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
  32. description="
  33. The GNU C Compiler Collection.
  34. The GNU Compiler Collection (GCC) is a compiler system produced by the
  35. GNU Project supporting various programming languages. GCC is a key
  36. component of the GNU toolchain. The Free Software Foundation (FSF)
  37. distributes GCC under the GNU General Public License (GNU GPL).
  38. For more information about GCC, visit: $homepage
  39. "
  40. # Source documentation
  41. docs="COPYING* README"
  42. docsdir="${docdir}/${program}-${version}"
  43. build()
  44. {
  45. unpack "${tardir}/$tarname"
  46. cd "$srcdir"
  47. # Set sane permissions
  48. chmod -R u+w,go-w,a+rX-s .
  49. # Apply specific patches for the support in musl.
  50. # https://port70.net/~nsz/musl/gcc-11.1.0/
  51. patch -Np1 -i "${worktree}/patches/gcc/11/0002-posix_memalign.patch"
  52. patch -Np1 -i "${worktree}/patches/gcc/11/0003-j2.patch"
  53. patch -Np1 -i "${worktree}/patches/gcc/11/0004-static-pie.patch"
  54. patch -Np1 -i "${worktree}/patches/gcc/11/0005-m68k-sqrt.patch"
  55. patch -Np1 -i "${worktree}/patches/gcc/11/extra-musl_libssp.patch"
  56. patch -Np1 -i "${worktree}/patches/gcc/11/extra-relro-in-dragora.patch"
  57. # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
  58. patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
  59. patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
  60. patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
  61. patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
  62. patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
  63. patch -Np1 -i "${worktree}/patches/gcc/0014-nopie.patch"
  64. patch -Np1 -i "${worktree}/patches/gcc/0021-add-fortify-headers-paths.patch"
  65. # Create a separate build directory
  66. rm -rf BUILD
  67. mkdir BUILD
  68. cd BUILD
  69. # System-dependent
  70. MACHINE="$(gcc -dumpmachine)"
  71. ../configure SED=sed \
  72. CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
  73. $configure_args \
  74. --libdir=/usr/lib${libSuffix} \
  75. --mandir=$mandir \
  76. --infodir=$infodir \
  77. --enable-bootstrap \
  78. --enable-languages=c,c++,fortran,objc,obj-c++ \
  79. --enable-clocale=generic \
  80. --enable-threads=posix \
  81. --enable-cet=auto \
  82. --enable-initfini-array \
  83. --enable-tls \
  84. --enable-nls \
  85. --enable-lto \
  86. --enable-plugin \
  87. --enable-objc-gc \
  88. --enable-libstdcxx-time \
  89. --enable-checking=release \
  90. --enable-fully-dynamic-string \
  91. --enable-default-ssp \
  92. --enable-default-pie \
  93. --enable-libssp \
  94. --enable-initfini-array \
  95. --disable-symvers \
  96. --disable-libitm \
  97. --disable-gnu-indirect-function \
  98. --disable-libstdcxx-pch \
  99. --disable-libsanitizer \
  100. --disable-libcilkrts \
  101. --disable-install-libiberty \
  102. --with-system-zlib \
  103. --with-linker-hash-style=gnu \
  104. --build=$MACHINE \
  105. --host=$MACHINE \
  106. --target=$MACHINE \
  107. $multilib_options \
  108. $gcc_options
  109. make -j${jobs} V=1 \
  110. BOOT_CFLAGS="$QICFLAGS" \
  111. BOOT_CXXFLAGS="$QICXXFLAGS" \
  112. BOOT_LDFLAGS="$QILDFLAGS" \
  113. BOOT_CPPFLAGS="$QICPPFLAGS"
  114. make -j${jobs} V=1 DESTDIR="$destdir" install
  115. # Delete non-shared version of libssp (provided on the musl package)
  116. rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
  117. # Strip ELF executables only excluding shared objects
  118. find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
  119. cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  120. # Strip static libraries in order to reduce the package size
  121. find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
  122. cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
  123. cd ../
  124. # Move misplaced file(s) for GDB
  125. mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
  126. mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
  127. "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
  128. # Provide compatibility and make soft links for package size
  129. (
  130. cd "${destdir}/usr/bin" || exit 1
  131. mv gcc gcc-${version}
  132. ln -sf gcc-${version} gcc
  133. ln -sf gcc cc
  134. ln -sf gcc-${version} ${MACHINE}-gcc
  135. ln -sf gcc-${version} ${MACHINE}-gcc-${version}
  136. mv g++ g++-gcc-${version}
  137. ln -sf g++-gcc-${version} g++
  138. ln -sf g++ c++
  139. ln -sf g++-gcc-${version} ${MACHINE}-g++
  140. ln -sf g++-gcc-${version} ${MACHINE}-c++
  141. mv gfortran gfortran-${version}
  142. ln -sf gfortran-${version} gfortran
  143. ln -sf gfortran-${version} ${MACHINE}-gfortran
  144. # Extra symlinks for fortran
  145. ln -sf gfortran g77
  146. ln -sf g77 f77
  147. ln -sf gfortran g95
  148. ln -sf g95 f95
  149. mv gcc-ar gcc-ar-${version}
  150. ln -sf gcc-ar-${version} gcc-ar
  151. ln -sf gcc-ar-${version} ${MACHINE}-gcc-ar
  152. mv gcc-nm gcc-nm-${version}
  153. ln -sf gcc-nm-${version} gcc-nm
  154. ln -sf gcc-nm-${version} ${MACHINE}-gcc-nm
  155. mv gcc-ranlib gcc-ranlib-${version}
  156. ln -sf gcc-ranlib-${version} gcc-ranlib
  157. ln -sf gcc-ranlib-${version} ${MACHINE}-gcc-ranlib
  158. )
  159. (
  160. cd "${destdir}/usr/lib${libSuffix}" && ln -sf ../bin/cpp .
  161. )
  162. unset -v MACHINE
  163. # Insert wrapper scripts for handling C89 and C99 invocations
  164. cat "${worktree}/archive/gcc/c89" > "${destdir}/usr/bin/c89"
  165. cat "${worktree}/archive/gcc/c99" > "${destdir}/usr/bin/c99"
  166. chmod 755 "${destdir}"/usr/bin/c?9
  167. # Compress info documents deleting index file for the package
  168. if test -d "${destdir}/$infodir"
  169. then
  170. rm -f "${destdir}/${infodir}/dir"
  171. lzip -9 "${destdir}/${infodir}"/* || true
  172. fi
  173. # Compress and link man pages (if needed)
  174. if test -d "${destdir}/$mandir"
  175. then
  176. (
  177. cd "${destdir}/$mandir"
  178. find . -type f -exec lzip -9 {} +
  179. find . -type l | while read -r file
  180. do
  181. ln -sf "$(readlink -- "$file").lz" "${file}.lz"
  182. rm -- "$file"
  183. done
  184. )
  185. fi
  186. # Copy documentation
  187. mkdir -p "${destdir}/$docsdir"
  188. cp -p $docs "${destdir}/$docsdir"
  189. }