05-gcc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # Build script for gcc.
  2. #
  3. # Copyright (c) 2016-2020 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. version=9.3.0
  17. # Prerequisites
  18. gmp_version=6.2.0
  19. mpfr_version=4.0.2
  20. mpc_version=1.1.0
  21. isl_version=0.22.1
  22. cd -- "$TMPDIR"
  23. rm -rf gcc-${version} gmp-${gmp_version} \
  24. mpfr-${mpfr_version} mpc-${mpc_version} isl-${isl_version}
  25. unpack "${worktree}/sources/gcc-${version}.tar.xz" \
  26. "${worktree}/sources/gmp-${gmp_version}.tar.lz" \
  27. "${worktree}/sources/mpfr-${mpfr_version}.tar.bz2" \
  28. "${worktree}/sources/mpc-${mpc_version}.tar.gz" \
  29. "${worktree}/sources/isl-${isl_version}.tar.bz2"
  30. # Build instructions
  31. cd gcc-${version}
  32. # Apply specific patches for the support in musl.
  33. # http://port70.net/~nsz/musl/gcc-9.1.0/
  34. patch -Np1 -i "${worktree}/patches/gcc/230-musl_libssp.patch"
  35. patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
  36. patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
  37. patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
  38. patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
  39. patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
  40. patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
  41. patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
  42. patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
  43. patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
  44. patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
  45. patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
  46. patch -Np1 -i "${worktree}/patches/gcc/0013-invalid-tls-model.patch"
  47. patch -Np1 -i "${worktree}/patches/gcc/turn-on-relro-bydefault.patch"
  48. # Hard code default paths to look in /tools
  49. for file in \
  50. gcc/config/linux.h gcc/config/i386/linux.h gcc/config/i386/linux64.h \
  51. gcc/config/arm/linux-eabi.h gcc/config/arm/linux-elf.h \
  52. gcc/config/mips/linux.h \
  53. gcc/config/rs6000/linux64.h gcc/config/rs6000/sysv4.h \
  54. gcc/config/aarch64/aarch64-linux.h \
  55. gcc/config/microblaze/linux.h \
  56. gcc/config/sh/linux.h \
  57. gcc/config/riscv/linux.h ; \
  58. do
  59. if test ! -f "$file"
  60. then
  61. echo "WARNING: ${0}: Non-existent file: $file" 1>&2
  62. continue;
  63. fi
  64. sed -i \
  65. -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
  66. -e 's@/usr@/tools@g' "$file"
  67. echo '
  68. #undef STANDARD_STARTFILE_PREFIX_1
  69. #undef STANDARD_STARTFILE_PREFIX_2
  70. #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
  71. #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
  72. done
  73. # Make symlinks for requisites
  74. ln -s ../gmp-${gmp_version} gmp
  75. ln -s ../mpfr-${mpfr_version} mpfr
  76. ln -s ../mpc-${mpc_version} mpc
  77. ln -s ../isl-${isl_version} isl
  78. # Apply patches for MPFR
  79. (
  80. cd mpfr || exit 1
  81. for file in "${worktree}"/patches/mpfr/*
  82. do
  83. if test -f "$file"
  84. then
  85. rm -f PATCHES
  86. patch -p1 < "$file"
  87. fi
  88. done
  89. )
  90. # Update detection for hosts based on musl
  91. cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
  92. cp -f "${worktree}/archive/common/config.sub" gmp/config.sub
  93. for directory in mpfr mpc isl
  94. do
  95. cp -f "${worktree}/archive/common/config.guess" ${directory}/config.guess
  96. cp -f "${worktree}/archive/common/config.sub" ${directory}/config.sub
  97. done
  98. unset directory
  99. # Build in a separate directory
  100. rm -rf ../gcc-build
  101. mkdir ../gcc-build
  102. cd ../gcc-build
  103. # Import and export toolchain variables
  104. . "${worktree}/stages/env.d/cross-staticenv"
  105. ../gcc-${version}/configure \
  106. AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
  107. CC="$BTCC" CXX="$BTCXX" \
  108. CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
  109. --prefix=/tools \
  110. --libdir=/tools/lib${libSuffix} \
  111. --build=$host \
  112. --host=$target \
  113. --target=$target \
  114. --enable-languages=c,c++ \
  115. --enable-clocale=generic \
  116. --enable-cet=auto \
  117. --enable-tls \
  118. --enable-libstdcxx-time \
  119. --enable-install-libiberty \
  120. --enable-fully-dynamic-string \
  121. --enable-default-ssp \
  122. --enable-default-pie \
  123. --enable-libssp \
  124. --disable-symvers \
  125. --disable-bootstrap \
  126. --disable-libstdcxx-pch \
  127. --disable-gnu-indirect-function \
  128. --disable-libmudflap \
  129. --disable-libsanitizer \
  130. --disable-nls \
  131. --with-local-prefix=/tools \
  132. --with-native-system-header-dir=/tools/include \
  133. $multilib_options \
  134. $gcc_options
  135. make -j${jobs} all \
  136. AS_FOR_TARGET="$AS" \
  137. LD_FOR_TARGET="$LD"
  138. make -j${jobs} install
  139. # Provide minimal libssp_nonshared.a
  140. $BTCC -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
  141. -o __stack_chk_fail_local.o
  142. $AR rc libssp_nonshared.a __stack_chk_fail_local.o
  143. $RANLIB libssp_nonshared.a
  144. cp -p libssp_nonshared.a /tools/lib${libSuffix}
  145. # Unset some imported variables from file
  146. unset AR AS LD RANLIB READELF STRIP
  147. cd -- "$TMPDIR"
  148. cleanup()
  149. {
  150. rm -rf gcc-${version} gcc-build \
  151. gmp-${gmp_version} mpfr-${mpfr_version} \
  152. mpc-${mpc_version} isl-${isl_version}
  153. }