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