93 lines · bash
1#!/usr/bin/env bash2#===- 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-exception7#8#===-----------------------------------------------------------------------===//9 10set -e11 12function show_usage() {13 cat << EOF14Usage: build_install_llvm.sh [options] -- [cmake-args]15 16Run cmake with the specified arguments. Used inside docker container.17Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into18the directory specified by --to option.19 20Available options:21 -h|--help show this help message22 -i|--install-target name of a cmake install target to build and include in23 the resulting archive. Can be specified multiple times.24 --to destination directory where to install the targets.25Required options: --to, at least one --install-target.26 27All options after '--' are passed to CMake invocation.28EOF29}30 31CMAKE_ARGS=""32CMAKE_INSTALL_TARGETS=""33CLANG_INSTALL_DIR=""34 35while [[ $# -gt 0 ]]; do36 case "$1" in37 -i|--install-target)38 shift39 CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1"40 shift41 ;;42 --to)43 shift44 CLANG_INSTALL_DIR="$1"45 shift46 ;;47 --)48 shift49 CMAKE_ARGS="$*"50 shift $#51 ;;52 -h|--help)53 show_usage54 exit 055 ;;56 *)57 echo "Unknown option: $1"58 exit 159 esac60done61 62if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then63 echo "No install targets. Please pass one or more --install-target."64 exit 165fi66 67if [ "$CLANG_INSTALL_DIR" == "" ]; then68 echo "No install directory. Please specify the --to argument."69 exit 170fi71 72CLANG_BUILD_DIR=/tmp/clang-build73 74mkdir -p "$CLANG_INSTALL_DIR"75 76mkdir -p "$CLANG_BUILD_DIR/build"77pushd "$CLANG_BUILD_DIR/build"78 79# Run the build as specified in the build arguments.80echo "Running build"81cmake -GNinja \82 -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \83 $CMAKE_ARGS \84 "$CLANG_BUILD_DIR/src/llvm"85ninja $CMAKE_INSTALL_TARGETS86 87popd88 89# Cleanup.90rm -rf "$CLANG_BUILD_DIR/build"91 92echo "Done"93