build_gcc_version.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env bash
  2. #===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
  3. #
  4. # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. # See https://llvm.org/LICENSE.txt for license information.
  6. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. #
  8. #===-----------------------------------------------------------------------===//
  9. set -e
  10. function show_usage() {
  11. cat << EOF
  12. Usage: build_gcc_version.sh [options]
  13. Run autoconf with the specified arguments. Used inside docker container.
  14. Available options:
  15. -h|--help show this help message
  16. --branch the branch of gcc you want to build.
  17. --cherry-pick a commit hash to apply to the GCC sources.
  18. --install destination directory where to install the targets.
  19. Required options: --install and --branch
  20. All options after '--' are passed to CMake invocation.
  21. EOF
  22. }
  23. GCC_INSTALL_DIR=""
  24. GCC_BRANCH=""
  25. CHERRY_PICK=""
  26. while [[ $# -gt 0 ]]; do
  27. case "$1" in
  28. --install)
  29. shift
  30. GCC_INSTALL_DIR="$1"
  31. shift
  32. ;;
  33. --branch)
  34. shift
  35. GCC_BRANCH="$1"
  36. shift
  37. ;;
  38. --cherry-pick)
  39. shift
  40. CHERRY_PICK="$1"
  41. shift
  42. ;;
  43. -h|--help)
  44. show_usage
  45. exit 0
  46. ;;
  47. *)
  48. echo "Unknown option: $1"
  49. exit 1
  50. esac
  51. done
  52. if [ "$GCC_INSTALL_DIR" == "" ]; then
  53. echo "No install directory. Please specify the --install argument."
  54. exit 1
  55. fi
  56. if [ "$GCC_BRANCH" == "" ]; then
  57. echo "No branch specified. Please specify the --branch argument."
  58. exit 1
  59. fi
  60. set -x
  61. NPROC=`nproc`
  62. TMP_ROOT="$(mktemp -d -p /tmp)"
  63. GCC_SOURCE_DIR="$TMP_ROOT/gcc"
  64. GCC_BUILD_DIR="$TMP_ROOT/build"
  65. echo "Cloning source directory for branch $GCC_BRANCH"
  66. git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR
  67. pushd "$GCC_SOURCE_DIR"
  68. if [ "$CHERRY_PICK" != "" ]; then
  69. git fetch origin trunk --unshallow # Urg, we have to get the entire history. This will take a while.
  70. git cherry-pick --no-commit -X theirs "$CHERRY_PICK"
  71. fi
  72. ./contrib/download_prerequisites
  73. popd
  74. mkdir "$GCC_BUILD_DIR"
  75. pushd "$GCC_BUILD_DIR"
  76. # Run the build as specified in the build arguments.
  77. echo "Running configuration"
  78. $GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
  79. --disable-bootstrap --disable-libgomp --disable-libitm \
  80. --disable-libvtv --disable-libcilkrts --disable-libmpx \
  81. --disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
  82. echo "Running build with $NPROC threads"
  83. make -j$NPROC
  84. echo "Installing to $GCC_INSTALL_DIR"
  85. make install -j$NPROC
  86. popd
  87. # Cleanup.
  88. rm -rf "$TMP_ROOT"
  89. echo "Done"