blob: 3a52e41fa655e40e148a13952e1a268835de712d [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#
Chandler Carruth2946cd72019-01-19 08:50:56 +00004# 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 Biryukovaf351da2017-06-30 09:46:45 +00007#
8#===-----------------------------------------------------------------------===//
9
10set -e
11
12function show_usage() {
Don Hinton1e4f6022017-07-31 15:18:57 +000013 cat << EOF
Ilya Biryukovaf351da2017-06-30 09:46:45 +000014Usage: build_install_llvm.sh [options] -- [cmake-args]
15
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000016Run cmake with the specified arguments. Used inside docker container.
Ilya Biryukovd9502012018-03-26 15:12:30 +000017Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000018the directory specified by --to option.
Ilya Biryukovaf351da2017-06-30 09:46:45 +000019
20Available options:
21 -h|--help show this help message
Ilya Biryukovaf351da2017-06-30 09:46:45 +000022 -i|--install-target name of a cmake install target to build and include in
23 the resulting archive. Can be specified multiple times.
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000024 --to destination directory where to install the targets.
25Required options: --to, at least one --install-target.
Ilya Biryukovaf351da2017-06-30 09:46:45 +000026
27All options after '--' are passed to CMake invocation.
28EOF
Ilya Biryukovaf351da2017-06-30 09:46:45 +000029}
30
Ilya Biryukovaf351da2017-06-30 09:46:45 +000031CMAKE_ARGS=""
32CMAKE_INSTALL_TARGETS=""
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000033CLANG_INSTALL_DIR=""
Ilya Biryukove421fc82017-07-20 08:30:44 +000034
Ilya Biryukovaf351da2017-06-30 09:46:45 +000035while [[ $# -gt 0 ]]; do
36 case "$1" in
Ilya Biryukovaf351da2017-06-30 09:46:45 +000037 -i|--install-target)
38 shift
39 CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"
40 shift
41 ;;
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000042 --to)
43 shift
44 CLANG_INSTALL_DIR="$1"
45 shift
46 ;;
Ilya Biryukovaf351da2017-06-30 09:46:45 +000047 --)
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
60done
61
62if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then
63 echo "No install targets. Please pass one or more --install-target."
64 exit 1
65fi
66
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000067if [ "$CLANG_INSTALL_DIR" == "" ]; then
68 echo "No install directory. Please specify the --to argument."
69 exit 1
Ilya Biryukove421fc82017-07-20 08:30:44 +000070fi
71
Ilya Biryukovaf351da2017-06-30 09:46:45 +000072CLANG_BUILD_DIR=/tmp/clang-build
Ilya Biryukovaf351da2017-06-30 09:46:45 +000073
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000074mkdir -p "$CLANG_INSTALL_DIR"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000075
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000076mkdir -p "$CLANG_BUILD_DIR/build"
Ilya Biryukov13cde862017-07-06 13:10:55 +000077pushd "$CLANG_BUILD_DIR/build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000078
79# Run the build as specified in the build arguments.
80echo "Running build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000081cmake -GNinja \
82 -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \
Ilya Biryukovaf351da2017-06-30 09:46:45 +000083 $CMAKE_ARGS \
84 "$CLANG_BUILD_DIR/src/llvm"
85ninja $CMAKE_INSTALL_TARGETS
86
87popd
88
Ilya Biryukovaf351da2017-06-30 09:46:45 +000089# Cleanup.
Ilya Biryukov2bf7c512018-04-20 10:19:38 +000090rm -rf "$CLANG_BUILD_DIR/build"
Ilya Biryukovaf351da2017-06-30 09:46:45 +000091
92echo "Done"