05-gcc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # Build script for gcc.
  2. #
  3. # Copyright (c) 2016-2018 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=7.3.0
  17. # Prerequisites
  18. gmp_version=6.1.2
  19. mpfr_version=4.0.1
  20. mpc_version=1.1.0
  21. isl_version=0.19
  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.gz" \
  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-7.3.0
  34. patch -Np1 -i "${worktree}/patches/gcc/0001-ssp_nonshared.diff"
  35. patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.diff"
  36. patch -Np1 -i "${worktree}/patches/gcc/0003-cilkrts.diff"
  37. patch -Np1 -i "${worktree}/patches/gcc/0004-libatomic-test-fix.diff"
  38. patch -Np1 -i "${worktree}/patches/gcc/0005-libgomp-test-fix.diff"
  39. patch -Np1 -i "${worktree}/patches/gcc/0006-libitm-test-fix.diff"
  40. patch -Np1 -i "${worktree}/patches/gcc/0007-libvtv-test-fix.diff"
  41. patch -Np1 -i "${worktree}/patches/gcc/0008-static-pie-support.diff"
  42. patch -Np1 -i "${worktree}/patches/gcc/0009-j2.diff"
  43. patch -Np1 -i "${worktree}/patches/gcc/0010-s390x-muslldso.diff"
  44. patch -Np1 -i "${worktree}/patches/gcc/0011-microblaze-pr65649.diff"
  45. patch -Np1 -i "${worktree}/patches/gcc/0012-ldbl128-config.diff"
  46. # Hard code default paths to look in /tools
  47. for file in \
  48. gcc/config/linux.h gcc/config/i386/linux.h gcc/config/i386/linux64.h \
  49. gcc/config/arm/linux-eabi.h gcc/config/arm/linux-elf.h \
  50. gcc/config/mips/linux.h \
  51. gcc/config/rs6000/linux64.h gcc/config/rs6000/sysv4.h \
  52. gcc/config/aarch64/aarch64-linux.h \
  53. gcc/config/microblaze/linux.h \
  54. gcc/config/sh/linux.h ; \
  55. do
  56. if test ! -f "$file"
  57. then
  58. echo "WARNING: ${0}: Non-existent file: $file" 1>&2
  59. continue;
  60. fi
  61. sed -i \
  62. -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
  63. -e 's@/usr@/tools@g' "$file"
  64. echo '
  65. #undef STANDARD_STARTFILE_PREFIX_1
  66. #undef STANDARD_STARTFILE_PREFIX_2
  67. #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
  68. #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
  69. done
  70. # Make symlinks for requisites
  71. ln -s ../gmp-${gmp_version} gmp
  72. ln -s ../mpfr-${mpfr_version} mpfr
  73. ln -s ../mpc-${mpc_version} mpc
  74. ln -s ../isl-${isl_version} isl
  75. # Apply patches for MPFR
  76. (
  77. cd mpfr || exit 1
  78. for file in "${worktree}"/patches/mpfr/patch??*
  79. do
  80. if test -f "$file"
  81. then
  82. rm -f PATCHES
  83. patch -p1 < "$file"
  84. fi
  85. done
  86. )
  87. # Build in a separate directory
  88. rm -rf ../gcc-build
  89. mkdir ../gcc-build
  90. cd ../gcc-build
  91. # Import and export toolchain variables
  92. . "${worktree}/stages/env.d/cross-staticenv"
  93. ../gcc-${version}/configure \
  94. AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
  95. CC="$BTCC" CXX="$BTCXX" \
  96. CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
  97. --prefix=/tools \
  98. --libdir=/tools/lib${libSuffix} \
  99. --build=$host \
  100. --host=$target \
  101. --target=$target \
  102. --enable-languages=c,c++ \
  103. --enable-clocale=generic \
  104. --enable-tls \
  105. --enable-libstdcxx-time \
  106. --enable-install-libiberty \
  107. --enable-fully-dynamic-string \
  108. --enable-default-pie \
  109. --disable-symvers \
  110. --disable-bootstrap \
  111. --disable-libstdcxx-pch \
  112. --disable-gnu-indirect-function \
  113. --disable-libmudflap \
  114. --disable-libsanitizer \
  115. --disable-libmpx \
  116. --disable-nls \
  117. --with-local-prefix=/tools \
  118. --with-native-system-header-dir=/tools/include \
  119. $multilib_options \
  120. $gcc_options
  121. make -j${jobs} all \
  122. AS_FOR_TARGET="$AS" \
  123. LD_FOR_TARGET="$LD"
  124. make -j${jobs} install
  125. # Unset some imported variables from file
  126. unset AR AS LD RANLIB READELF STRIP
  127. cleanup()
  128. {
  129. cd -- "$TMPDIR" && rm -rf gcc-${version} \
  130. gmp-${gmp_version} mpfr-${mpfr_version} \
  131. mpc-${mpc_version} isl-${isl_version}
  132. }