gen-buildsys-clang.sh 2.4 KB
Newer Older
1 2
#!/usr/bin/env bash
#
3
# This file invokes cmake and generates the build system for Clang.
4 5
#

6
if [ $# -lt 4 -o $# -gt 6 ]
7 8
then
  echo "Usage..."
9
  echo "gen-buildsys-clang.sh <path to top level CMakeLists.txt> <ClangMajorVersion> <ClangMinorVersion> <Architecture> [build flavor] [cmakeargs]"
10
  echo "Specify the path to the top level CMake file - <corefx>/src/Native/Unix"
11
  echo "Specify the clang version to use, split into major and minor version"
12
  echo "Specify the target architecture." 
13
  echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG." 
14
  echo "Optionally pass additional arguments to CMake call."
15 16 17
  exit 1
fi

18
#Set the root directory of the project
19
project_root="$1"/../../..
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# Set up the environment to be used for building with clang.
if which "clang-$2.$3" > /dev/null 2>&1
    then
        export CC="$(which clang-$2.$3)"
        export CXX="$(which clang++-$2.$3)"
elif which "clang$2$3" > /dev/null 2>&1
    then
        export CC="$(which clang$2$3)"
        export CXX="$(which clang++$2$3)"
elif which clang > /dev/null 2>&1
    then
        export CC="$(which clang)"
        export CXX="$(which clang++)"
else
    echo "Unable to find Clang Compiler"
    exit 1
fi

39
build_arch="$4"
40 41
# Possible build types are DEBUG, RELEASE, RELWITHDEBINFO, MINSIZEREL.
# Default to DEBUG
42
if [ -z "$5" ]
43 44 45 46
then
  echo "Defaulting to DEBUG build."
  buildtype="DEBUG"
else
47
  buildtype="$5"
48 49
fi

50
cmake_extra_defines="-DCMAKE_BUILD_TYPE=$buildtype"
51 52 53 54 55 56 57

if [[ -n "$LLDB_LIB_DIR" ]]; then
    cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_LIBS=$LLDB_LIB_DIR"
fi
if [[ -n "$LLDB_INCLUDE_DIR" ]]; then
    cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_INCLUDES=$LLDB_INCLUDE_DIR"
fi
58 59 60 61 62
if [[ -n "$CROSSCOMPILE" ]]; then
    if ! [[ -n "$ROOTFS_DIR" ]]; then
        echo "ROOTFS_DIR not set for crosscompile"
        exit 1
    fi
63 64 65 66 67
    if [[ -z "$CONFIG_DIR" ]]; then
      CONFIG_DIR="$project_root/cross/$build_arch"
    fi
    cmake_extra_defines="$cmake_extra_defines -C $CONFIG_DIR/tryrun.cmake"
    cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$CONFIG_DIR/toolchain.cmake"
68
fi
C
chunseoklee 已提交
69
if [ "$build_arch" == "armel" ]; then
70 71
    cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi
72

73 74 75 76 77 78 79 80 81 82
__UnprocessedCMakeArgs=""
if [ -z "$6" ]; then
    echo "No CMake extra Args specified"
else
    __UnprocessedCMakeArgs="$6"
fi

cmake $cmake_extra_defines \
    $__UnprocessedCMakeArgs \
    $1