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 11set -e 12 13function show_usage() { 14 cat << EOF 15Usage: build_install_llvm.sh [options] -- [cmake-args] 16 17Run cmake with the specified arguments. Used inside docker container. 18Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into 19the directory specified by --to option. 20 21Available options: 22 -h|--help show this help message 23 -i|--install-target name of a cmake install target to build and include in 24 the resulting archive. Can be specified multiple times. 25 --install destination directory where to install the targets. 26 --source location of the source tree. 27 --build location to use as the build directory. 28Required options: --to, --source, --build, and at least one --install-target. 29 30All options after '--' are passed to CMake invocation. 31EOF 32} 33 34CMAKE_ARGS="" 35CMAKE_INSTALL_TARGETS="" 36CLANG_INSTALL_DIR="" 37CLANG_SOURCE_DIR="" 38CLANG_BUILD_DIR="" 39 40while [[ $# -gt 0 ]]; do 41 case "$1" in 42 -i|--install-target) 43 shift 44 CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1" 45 shift 46 ;; 47 --source) 48 shift 49 CLANG_SOURCE_DIR="$1" 50 shift 51 ;; 52 --build) 53 shift 54 CLANG_BUILD_DIR="$1" 55 shift 56 ;; 57 --install) 58 shift 59 CLANG_INSTALL_DIR="$1" 60 shift 61 ;; 62 --) 63 shift 64 CMAKE_ARGS="$*" 65 shift $# 66 ;; 67 -h|--help) 68 show_usage 69 exit 0 70 ;; 71 *) 72 echo "Unknown option: $1" 73 exit 1 74 esac 75done 76 77if [ "$CLANG_SOURCE_DIR" == "" ]; then 78 echo "No source directory. Please pass --source." 79 exit 1 80fi 81 82if [ "$CLANG_BUILD_DIR" == "" ]; then 83 echo "No build directory. Please pass --build" 84 exit 1 85fi 86 87if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then 88 echo "No install targets. Please pass one or more --install-target." 89 exit 1 90fi 91 92if [ "$CLANG_INSTALL_DIR" == "" ]; then 93 echo "No install directory. Please specify the --to argument." 94 exit 1 95fi 96 97echo "Building in $CLANG_BUILD_DIR" 98mkdir -p "$CLANG_BUILD_DIR" 99pushd "$CLANG_BUILD_DIR" 100 101# Run the build as specified in the build arguments. 102echo "Running build" 103cmake -GNinja \ 104 -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \ 105 $CMAKE_ARGS \ 106 "$CLANG_SOURCE_DIR" 107ninja $CMAKE_INSTALL_TARGETS 108 109popd 110 111# Cleanup. 112rm -rf "$CLANG_BUILD_DIR" 113 114echo "Done" 115