3 # This file invokes cmake and generates the build system for Clang.
9 echo "gen-buildsys-clang.sh <path to top level CMakeLists.txt> <ClangMajorVersion> <ClangMinorVersion> <Architecture> [build flavor] [coverage] [ninja] [cmakeargs]"
10 echo "Specify the path to the top level CMake file - <ProjectK>/src/NDP"
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 specify 'coverage' to enable code coverage build."
15 echo "Target ninja instead of make. ninja must be on the PATH."
16 echo "Pass additional arguments to CMake call."
20 # Set up the environment to be used for building with clang.
21 if command -v "clang-$2.$3" > /dev/null
23 export CC="$(command -v clang-$2.$3)"
24 export CXX="$(command -v clang++-$2.$3)"
25 elif command -v "clang$2$3" > /dev/null
27 export CC="$(command -v clang$2$3)"
28 export CXX="$(command -v clang++$2$3)"
29 elif command -v clang > /dev/null
31 export CC="$(command -v clang)"
32 export CXX="$(command -v clang++)"
34 echo "Unable to find Clang Compiler"
42 generator="Unix Makefiles"
43 __UnprocessedCMakeArgs=""
46 upperI="$(echo $i | awk '{print toupper($0)}')"
48 # Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO, MINSIZEREL.
49 DEBUG | CHECKED | RELEASE | RELWITHDEBINFO | MINSIZEREL)
53 echo "Code coverage is turned on for this build."
57 echo "Including tests directory in build."
64 __UnprocessedCMakeArgs="${__UnprocessedCMakeArgs}${__UnprocessedCMakeArgs:+ }$i"
71 # This can be a little complicated, because the common use-case of Ubuntu with
72 # llvm-3.5 installed uses a rather unusual llvm installation with the version
73 # number postfixed (i.e. llvm-ar-3.5), so we check for that first.
74 # On FreeBSD the version number is appended without point and dash (i.e.
76 # Additionally, OSX doesn't use the llvm- prefix.
77 if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" -o $OS = "SunOS" ]; then
79 elif [ $OS = "Darwin" ]; then
82 echo "Unable to determine build platform"
86 desired_llvm_major_version=$2
87 desired_llvm_minor_version=$3
88 if [ $OS = "FreeBSD" ]; then
89 desired_llvm_version="$desired_llvm_major_version$desired_llvm_minor_version"
90 elif [ $OS = "OpenBSD" ]; then
91 desired_llvm_version=""
92 elif [ $OS = "NetBSD" ]; then
93 desired_llvm_version=""
94 elif [ $OS = "SunOS" ]; then
95 desired_llvm_version=""
97 desired_llvm_version="-$desired_llvm_major_version.$desired_llvm_minor_version"
100 if command -v "$llvm_prefix$1$desired_llvm_version" > /dev/null 2>&1
102 echo "$(command -v $llvm_prefix$1$desired_llvm_version)"
103 elif command -v "$llvm_prefix$1" > /dev/null 2>&1
105 echo "$(command -v $llvm_prefix$1)"
111 llvm_ar="$(locate_llvm_exec ar)"
112 [[ $? -eq 0 ]] || { echo "Unable to locate llvm-ar"; exit 1; }
113 llvm_link="$(locate_llvm_exec link)"
114 [[ $? -eq 0 ]] || { echo "Unable to locate llvm-link"; exit 1; }
115 llvm_nm="$(locate_llvm_exec nm)"
116 [[ $? -eq 0 ]] || { echo "Unable to locate llvm-nm"; exit 1; }
117 if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" -o $OS = "SunOS" ]; then
118 llvm_objdump="$(locate_llvm_exec objdump)"
119 [[ $? -eq 0 ]] || { echo "Unable to locate llvm-objdump"; exit 1; }
123 if [[ -n "$LLDB_LIB_DIR" ]]; then
124 cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_LIBS=$LLDB_LIB_DIR"
126 if [[ -n "$LLDB_INCLUDE_DIR" ]]; then
127 cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_INCLUDES=$LLDB_INCLUDE_DIR"
129 if [[ -n "$CROSSCOMPONENT" ]]; then
130 cmake_extra_defines="$cmake_extra_defines -DCLR_CROSS_COMPONENTS_BUILD=1"
132 if [[ -n "$CROSSCOMPILE" ]]; then
133 if ! [[ -n "$ROOTFS_DIR" ]]; then
134 echo "ROOTFS_DIR not set for crosscompile"
137 if [[ -z $CONFIG_DIR ]]; then
138 CONFIG_DIR="$1/cross/$build_arch"
140 cmake_extra_defines="$cmake_extra_defines -C $CONFIG_DIR/tryrun.cmake"
141 cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$CONFIG_DIR/toolchain.cmake"
142 cmake_extra_defines="$cmake_extra_defines -DCLR_UNIX_CROSS_BUILD=1"
144 if [ $OS == "Linux" ]; then
145 linux_id_file="/etc/os-release"
146 if [[ -n "$CROSSCOMPILE" ]]; then
147 linux_id_file="$ROOTFS_DIR/$linux_id_file"
149 if [[ -e $linux_id_file ]]; then
150 source $linux_id_file
151 cmake_extra_defines="$cmake_extra_defines -DCLR_CMAKE_LINUX_ID=$ID"
154 if [ "$build_arch" == "armel" ]; then
155 cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
158 clang_version=$( $CC --version | head -1 | sed 's/[^0-9]*\([0-9]*\.[0-9]*\).*/\1/' )
159 # Use O1 option when the clang version is smaller than 3.9
160 # Otherwise use O3 option in release build
161 if [[ ( ${clang_version%.*} -eq 3 && ${clang_version#*.} -lt 9 ) &&
162 ( "$build_arch" == "arm" || "$build_arch" == "armel" ) ]]; then
163 overridefile=clang-compiler-override-arm.txt
165 overridefile=clang-compiler-override.txt
170 "-DCMAKE_USER_MAKE_RULES_OVERRIDE=$1/src/pal/tools/$overridefile" \
171 "-DCMAKE_AR=$llvm_ar" \
172 "-DCMAKE_LINKER=$llvm_link" \
173 "-DCMAKE_NM=$llvm_nm" \
174 "-DCMAKE_OBJDUMP=$llvm_objdump" \
175 "-DCMAKE_BUILD_TYPE=$buildtype" \
176 "-DCMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
177 "-DCMAKE_EXPORT_COMPILE_COMMANDS=1 " \
178 "-DCLR_CMAKE_BUILD_TESTS=$build_tests" \
179 $cmake_extra_defines \
180 $__UnprocessedCMakeArgs \