build_install_llvm.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. #===- llvm/utils/docker/scripts/build_install_llvm.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. -i|--install-target name of a cmake install target to build and include in
  19. the resulting archive. Can be specified multiple times.
  20. --to destination directory where to install the targets.
  21. Required options: --to, at least one --install-target.
  22. All options after '--' are passed to CMake invocation.
  23. EOF
  24. }
  25. CMAKE_ARGS=""
  26. CMAKE_INSTALL_TARGETS=""
  27. CLANG_INSTALL_DIR=""
  28. while [[ $# -gt 0 ]]; do
  29. case "$1" in
  30. -i|--install-target)
  31. shift
  32. CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"
  33. shift
  34. ;;
  35. --to)
  36. shift
  37. CLANG_INSTALL_DIR="$1"
  38. shift
  39. ;;
  40. --)
  41. shift
  42. CMAKE_ARGS="$*"
  43. shift $#
  44. ;;
  45. -h|--help)
  46. show_usage
  47. exit 0
  48. ;;
  49. *)
  50. echo "Unknown option: $1"
  51. exit 1
  52. esac
  53. done
  54. if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then
  55. echo "No install targets. Please pass one or more --install-target."
  56. exit 1
  57. fi
  58. if [ "$CLANG_INSTALL_DIR" == "" ]; then
  59. echo "No install directory. Please specify the --to argument."
  60. exit 1
  61. fi
  62. CLANG_BUILD_DIR=/tmp/clang-build
  63. mkdir -p "$CLANG_INSTALL_DIR"
  64. mkdir -p "$CLANG_BUILD_DIR/build"
  65. pushd "$CLANG_BUILD_DIR/build"
  66. # Run the build as specified in the build arguments.
  67. echo "Running build"
  68. cmake -GNinja \
  69. -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \
  70. $CMAKE_ARGS \
  71. "$CLANG_BUILD_DIR/src/llvm"
  72. ninja $CMAKE_INSTALL_TARGETS
  73. popd
  74. # Cleanup.
  75. rm -rf "$CLANG_BUILD_DIR/build"
  76. echo "Done"