recipe 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Build recipe for GCC.
  2. #
  3. # Copyright (c) 2015-2022 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-20220429
  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/0021-add-fortify-headers-paths.patch"
  64. # Create a separate build directory
  65. rm -rf BUILD
  66. mkdir BUILD
  67. cd BUILD
  68. # System-dependent
  69. MACHINE="$(gcc -dumpmachine)"
  70. ../configure SED=sed \
  71. CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
  72. $configure_args \
  73. --libdir=/usr/lib${libSuffix} \
  74. --mandir=$mandir \
  75. --infodir=$infodir \
  76. --enable-bootstrap \
  77. --enable-languages=c,c++,fortran,objc,obj-c++ \
  78. --enable-clocale=generic \
  79. --enable-threads=posix \
  80. --enable-cet=auto \
  81. --enable-initfini-array \
  82. --enable-tls \
  83. --enable-nls \
  84. --enable-lto \
  85. --enable-plugin \
  86. --enable-objc-gc \
  87. --enable-libstdcxx-time \
  88. --enable-checking=release \
  89. --enable-fully-dynamic-string \
  90. --enable-default-ssp \
  91. --enable-default-pie \
  92. --enable-libssp \
  93. --enable-initfini-array \
  94. --disable-symvers \
  95. --disable-libitm \
  96. --disable-gnu-indirect-function \
  97. --disable-libstdcxx-pch \
  98. --disable-libsanitizer \
  99. --disable-libcilkrts \
  100. --disable-install-libiberty \
  101. --with-system-zlib \
  102. --with-linker-hash-style=gnu \
  103. --build=$MACHINE \
  104. --host=$MACHINE \
  105. --target=$MACHINE \
  106. $multilib_options \
  107. $gcc_options
  108. make -j${jobs} V=1 \
  109. BOOT_CFLAGS="$QICFLAGS" \
  110. BOOT_CXXFLAGS="$QICXXFLAGS" \
  111. BOOT_LDFLAGS="$QILDFLAGS" \
  112. BOOT_CPPFLAGS="$QICPPFLAGS"
  113. make -j${jobs} V=1 DESTDIR="$destdir" install
  114. # Delete non-shared version of libssp (provided on the musl package)
  115. rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
  116. # Strip ELF executables only excluding shared objects
  117. find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
  118. cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  119. # Strip static libraries in order to reduce the package size
  120. find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
  121. cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
  122. cd ../
  123. # Move misplaced file(s) for GDB
  124. mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
  125. mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
  126. "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
  127. # Provide compatibility and make soft links for package size
  128. (
  129. cd "${destdir}/usr/bin" || exit 1
  130. mv gcc gcc-${version}
  131. ln -sf gcc-${version} gcc
  132. ln -sf gcc cc
  133. ln -sf gcc-${version} ${MACHINE}-gcc
  134. ln -sf gcc-${version} ${MACHINE}-gcc-${version}
  135. mv g++ g++-gcc-${version}
  136. ln -sf g++-gcc-${version} g++
  137. ln -sf g++ c++
  138. ln -sf g++-gcc-${version} ${MACHINE}-g++
  139. ln -sf g++-gcc-${version} ${MACHINE}-c++
  140. mv gfortran gfortran-${version}
  141. ln -sf gfortran-${version} gfortran
  142. ln -sf gfortran-${version} ${MACHINE}-gfortran
  143. # Extra symlinks for fortran
  144. ln -sf gfortran g77
  145. ln -sf g77 f77
  146. ln -sf gfortran g95
  147. ln -sf g95 f95
  148. mv gcc-ar gcc-ar-${version}
  149. ln -sf gcc-ar-${version} gcc-ar
  150. ln -sf gcc-ar-${version} ${MACHINE}-gcc-ar
  151. mv gcc-nm gcc-nm-${version}
  152. ln -sf gcc-nm-${version} gcc-nm
  153. ln -sf gcc-nm-${version} ${MACHINE}-gcc-nm
  154. mv gcc-ranlib gcc-ranlib-${version}
  155. ln -sf gcc-ranlib-${version} gcc-ranlib
  156. ln -sf gcc-ranlib-${version} ${MACHINE}-gcc-ranlib
  157. )
  158. (
  159. cd "${destdir}/usr/lib${libSuffix}" && ln -sf ../bin/cpp .
  160. )
  161. unset -v MACHINE
  162. # Insert wrapper scripts for handling C89 and C99 invocations
  163. cat "${worktree}/archive/gcc/c89" > "${destdir}/usr/bin/c89"
  164. cat "${worktree}/archive/gcc/c99" > "${destdir}/usr/bin/c99"
  165. chmod 755 "${destdir}"/usr/bin/c?9
  166. # Compress info documents deleting index file for the package
  167. if test -d "${destdir}/$infodir"
  168. then
  169. rm -f "${destdir}/${infodir}/dir"
  170. lzip -9 "${destdir}/${infodir}"/* || true
  171. fi
  172. # Compress and link man pages (if needed)
  173. if test -d "${destdir}/$mandir"
  174. then
  175. (
  176. cd "${destdir}/$mandir"
  177. find . -type f -exec lzip -9 {} +
  178. find . -type l | while read -r file
  179. do
  180. ln -sf "$(readlink -- "$file").lz" "${file}.lz"
  181. rm -- "$file"
  182. done
  183. )
  184. fi
  185. # Copy documentation
  186. mkdir -p "${destdir}/$docsdir"
  187. cp -p $docs "${destdir}/$docsdir"
  188. }