05-gcc 4.8 KB

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