blob: 0b9c0837203965eab1a6112079a081cf61b89a58 [file] [log] [blame]
Ilya Biryukovaf351da2017-06-30 09:46:45 +00001#!/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
11set -e
12
13function show_usage() {
Don Hinton1e4f6022017-07-31 15:18:57 +000014 cat << EOF
Ilya Biryukovaf351da2017-06-30 09:46:45 +000015Usage: build_install_llvm.sh [options] -- [cmake-args]
16
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000017Run cmake with the specified arguments. Used inside docker container.
Ilya Biryukovd9502012018-03-26 15:12:30 +000018Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000019the directory specified by --to option.
Ilya Biryukovaf351da2017-06-30 09:46:45 +000020
21Available options:
22 -h|--help show this help message
Ilya Biryukovaf351da2017-06-30 09:46:45 +000023 -i|--install-target name of a cmake install target to build and include in
24 the resulting archive. Can be specified multiple times.
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000025 --to destination directory where to install the targets.
26Required options: --to, at least one --install-target.
Ilya Biryukovaf351da2017-06-30 09:46:45 +000027
28All options after '--' are passed to CMake invocation.
29EOF
Ilya Biryukovaf351da2017-06-30 09:46:45 +000030}
31
Ilya Biryukovaf351da2017-06-30 09:46:45 +000032CMAKE_ARGS=""
33CMAKE_INSTALL_TARGETS=""
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000034CLANG_INSTALL_DIR=""
Ilya Biryukove421fc82017-07-20 08:30:44 +000035
Ilya Biryukovaf351da2017-06-30 09:46:45 +000036while [[ $# -gt 0 ]]; do
37 case "$1" in
Ilya Biryukovaf351da2017-06-30 09:46:45 +000038 -i|--install-target)
39 shift
40 CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"
41 shift
42 ;;
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000043 --to)
44 shift
45 CLANG_INSTALL_DIR="$1"
46 shift
47 ;;
Ilya Biryukovaf351da2017-06-30 09:46:45 +000048 --)
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
61done
62
63if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then
64 echo "No install targets. Please pass one or more --install-target."
65 exit 1
66fi
67
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000068if [ "$CLANG_INSTALL_DIR" == "" ]; then
69 echo "No install directory. Please specify the --to argument."
70 exit 1
Ilya Biryukove421fc82017-07-20 08:30:44 +000071fi
72
Ilya Biryukovaf351da2017-06-30 09:46:45 +000073CLANG_BUILD_DIR=/tmp/clang-build
Ilya Biryukovaf351da2017-06-30 09:46:45 +000074
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000075mkdir -p "$CLANG_INSTALL_DIR"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000076
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000077mkdir -p "$CLANG_BUILD_DIR/build"
Ilya Biryukov13cde862017-07-06 13:10:55 +000078pushd "$CLANG_BUILD_DIR/build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000079
80# Run the build as specified in the build arguments.
81echo "Running build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000082cmake -GNinja \
83 -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \
Ilya Biryukovaf351da2017-06-30 09:46:45 +000084 $CMAKE_ARGS \
85 "$CLANG_BUILD_DIR/src/llvm"
86ninja $CMAKE_INSTALL_TARGETS
87
88popd
89
Ilya Biryukovaf351da2017-06-30 09:46:45 +000090# Cleanup.
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000091rm -rf "$CLANG_BUILD_DIR/build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000092
93echo "Done"