build_llvm_version.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env bash
  2. #===- libcxx/utils/docker/scripts/build_install_llvm_version_default.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_install_llvm.sh [options] -- [cmake-args]
  13. Run cmake with the specified arguments. Used inside docker container.
  14. Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
  15. the directory specified by --to option.
  16. Available options:
  17. -h|--help show this help message
  18. --install destination directory where to install the targets.
  19. --branch the branch or tag of LLVM to build
  20. Required options: --install, and --version.
  21. All options after '--' are passed to CMake invocation.
  22. EOF
  23. }
  24. LLVM_BRANCH=""
  25. CMAKE_ARGS=""
  26. LLVM_INSTALL_DIR=""
  27. while [[ $# -gt 0 ]]; do
  28. case "$1" in
  29. --install)
  30. shift
  31. LLVM_INSTALL_DIR="$1"
  32. shift
  33. ;;
  34. --branch)
  35. shift
  36. LLVM_BRANCH="$1"
  37. shift
  38. ;;
  39. --)
  40. shift
  41. CMAKE_ARGS="$*"
  42. shift $#
  43. ;;
  44. -h|--help)
  45. show_usage
  46. exit 0
  47. ;;
  48. *)
  49. echo "Unknown option: $1"
  50. exit 1
  51. esac
  52. done
  53. if [ "$LLVM_INSTALL_DIR" == "" ]; then
  54. echo "No install directory. Please specify the --install argument."
  55. exit 1
  56. fi
  57. if [ "$LLVM_BRANCH" == "" ]; then
  58. echo "No install directory. Please specify the --branch argument."
  59. exit 1
  60. fi
  61. if [ "$CMAKE_ARGS" == "" ]; then
  62. CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RELEASE '-DCMAKE_C_FLAGS=-gline-tables-only' '-DCMAKE_CXX_FLAGS=-gline-tables-only' -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
  63. fi
  64. set -x
  65. TMP_ROOT="$(mktemp -d -p /tmp)"
  66. LLVM_SOURCE_DIR="$TMP_ROOT/llvm-project"
  67. LLVM_BUILD_DIR="$TMP_ROOT/build"
  68. LLVM="$LLVM_SOURCE_DIR/llvm"
  69. git clone --branch $LLVM_BRANCH --single-branch --depth=1 https://github.com/llvm/llvm-project.git $LLVM_SOURCE_DIR
  70. pushd "$LLVM_SOURCE_DIR"
  71. # Setup the source-tree using the old style layout
  72. ln -s $LLVM_SOURCE_DIR/libcxx $LLVM/projects/libcxx
  73. ln -s $LLVM_SOURCE_DIR/libcxxabi $LLVM/projects/libcxxabi
  74. ln -s $LLVM_SOURCE_DIR/compiler-rt $LLVM/projects/compiler-rt
  75. ln -s $LLVM_SOURCE_DIR/clang $LLVM/tools/clang
  76. ln -s $LLVM_SOURCE_DIR/clang-tools-extra $LLVM/tools/clang/tools/extra
  77. popd
  78. # Configure and build
  79. mkdir "$LLVM_BUILD_DIR"
  80. pushd "$LLVM_BUILD_DIR"
  81. cmake -GNinja "-DCMAKE_INSTALL_PREFIX=$LLVM_INSTALL_DIR" $CMAKE_ARGS $LLVM
  82. ninja install
  83. popd
  84. # Cleanup
  85. rm -rf "$TMP_ROOT/"
  86. echo "Done"