Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | #===- llvm/utils/docker/scripts/build_install_llvm.sh ---------------------===// |
| 3 | # |
| 4 | # The LLVM Compiler Infrastructure |
| 5 | # |
| 6 | # This file is distributed under the University of Illinois Open Source |
| 7 | # License. See LICENSE.TXT for details. |
| 8 | # |
| 9 | #===-----------------------------------------------------------------------===// |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | function show_usage() { |
Don Hinton | 1e4f602 | 2017-07-31 15:18:57 +0000 | [diff] [blame] | 14 | cat << EOF |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 15 | Usage: build_install_llvm.sh [options] -- [cmake-args] |
| 16 | |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 17 | Run cmake with the specified arguments. Used inside docker container. |
Ilya Biryukov | d950201 | 2018-03-26 15:12:30 +0000 | [diff] [blame] | 18 | Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 19 | the directory specified by --to option. |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 20 | |
| 21 | Available options: |
| 22 | -h|--help show this help message |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 23 | -i|--install-target name of a cmake install target to build and include in |
| 24 | the resulting archive. Can be specified multiple times. |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 25 | --to destination directory where to install the targets. |
| 26 | Required options: --to, at least one --install-target. |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 27 | |
| 28 | All options after '--' are passed to CMake invocation. |
| 29 | EOF |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 32 | CMAKE_ARGS="" |
| 33 | CMAKE_INSTALL_TARGETS="" |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 34 | CLANG_INSTALL_DIR="" |
Ilya Biryukov | e421fc8 | 2017-07-20 08:30:44 +0000 | [diff] [blame] | 35 | |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 36 | while [[ $# -gt 0 ]]; do |
| 37 | case "$1" in |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 38 | -i|--install-target) |
| 39 | shift |
| 40 | CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1" |
| 41 | shift |
| 42 | ;; |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 43 | --to) |
| 44 | shift |
| 45 | CLANG_INSTALL_DIR="$1" |
| 46 | shift |
| 47 | ;; |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 48 | --) |
| 49 | shift |
| 50 | CMAKE_ARGS="$*" |
| 51 | shift $# |
| 52 | ;; |
| 53 | -h|--help) |
| 54 | show_usage |
| 55 | exit 0 |
| 56 | ;; |
| 57 | *) |
| 58 | echo "Unknown option: $1" |
| 59 | exit 1 |
| 60 | esac |
| 61 | done |
| 62 | |
| 63 | if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then |
| 64 | echo "No install targets. Please pass one or more --install-target." |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 68 | if [ "$CLANG_INSTALL_DIR" == "" ]; then |
| 69 | echo "No install directory. Please specify the --to argument." |
| 70 | exit 1 |
Ilya Biryukov | e421fc8 | 2017-07-20 08:30:44 +0000 | [diff] [blame] | 71 | fi |
| 72 | |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 73 | CLANG_BUILD_DIR=/tmp/clang-build |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 74 | |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 75 | mkdir -p "$CLANG_INSTALL_DIR" |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 76 | |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 77 | mkdir -p "$CLANG_BUILD_DIR/build" |
Ilya Biryukov | 13cde86 | 2017-07-06 13:10:55 +0000 | [diff] [blame] | 78 | pushd "$CLANG_BUILD_DIR/build" |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 79 | |
| 80 | # Run the build as specified in the build arguments. |
| 81 | echo "Running build" |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 82 | cmake -GNinja \ |
| 83 | -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \ |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 84 | $CMAKE_ARGS \ |
| 85 | "$CLANG_BUILD_DIR/src/llvm" |
| 86 | ninja $CMAKE_INSTALL_TARGETS |
| 87 | |
| 88 | popd |
| 89 | |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 90 | # Cleanup. |
Ilya Biryukov | 2bf7c51 | 2018-04-20 10:19:38 +0000 | [diff] [blame^] | 91 | rm -rf "$CLANG_BUILD_DIR/build" |
Ilya Biryukov | af351da | 2017-06-30 09:46:45 +0000 | [diff] [blame] | 92 | |
| 93 | echo "Done" |