build_install_llvm.sh (2654B)
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 11 set -e 12 13 function show_usage() { 14 cat << EOF 15 Usage: build_install_llvm.sh [options] -- [cmake-args] 16 17 Run cmake with the specified arguments. Used inside docker container. 18 Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into 19 the directory specified by --to option. 20 21 Available 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. 28 Required options: --to, --source, --build, and at least one --install-target. 29 30 All options after '--' are passed to CMake invocation. 31 EOF 32 } 33 34 CMAKE_ARGS="" 35 CMAKE_INSTALL_TARGETS="" 36 CLANG_INSTALL_DIR="" 37 CLANG_SOURCE_DIR="" 38 CLANG_BUILD_DIR="" 39 40 while [[ $# -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 75 done 76 77 if [ "$CLANG_SOURCE_DIR" == "" ]; then 78 echo "No source directory. Please pass --source." 79 exit 1 80 fi 81 82 if [ "$CLANG_BUILD_DIR" == "" ]; then 83 echo "No build directory. Please pass --build" 84 exit 1 85 fi 86 87 if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then 88 echo "No install targets. Please pass one or more --install-target." 89 exit 1 90 fi 91 92 if [ "$CLANG_INSTALL_DIR" == "" ]; then 93 echo "No install directory. Please specify the --to argument." 94 exit 1 95 fi 96 97 echo "Building in $CLANG_BUILD_DIR" 98 mkdir -p "$CLANG_BUILD_DIR" 99 pushd "$CLANG_BUILD_DIR" 100 101 # Run the build as specified in the build arguments. 102 echo "Running build" 103 cmake -GNinja \ 104 -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \ 105 $CMAKE_ARGS \ 106 "$CLANG_SOURCE_DIR" 107 ninja $CMAKE_INSTALL_TARGETS 108 109 popd 110 111 # Cleanup. 112 rm -rf "$CLANG_BUILD_DIR" 113 114 echo "Done"