[runtime] Switch to GC Unsafe for all GC external API functions
[mono-project.git] / llvm / build_llvm_config.sh
blob7880d84e680b1a7d4960a25d4e1b2c4976d91b41
1 #!/bin/bash
3 llvm_config=$1
4 llvm_codegen_libs="$2"
5 llvm_extra_libs="${@:3}"
7 use_llvm_config=1
8 llvm_host_win32=0
9 llvm_host_win32_wsl=0
10 llvm_host_win32_cygwin=0
12 function win32_format_path {
13 local formatted_path=$1
14 if [[ $llvm_host_win32_wsl = 1 ]] && [[ $1 != "/mnt/"* ]]; then
15 # if path is not starting with /mnt under WSL it could be a windows path, convert using wslpath.
16 formatted_path="$(wslpath -a "$1")"
17 elif [[ $llvm_host_win32_cygwin = 1 ]] && [[ $1 != "/cygdrive/"* ]]; then
18 # if path is not starting with /cygdrive under CygWin it could be a windows path, convert using cygpath.
19 formatted_path="$(cygpath -a "$1")"
21 echo "$formatted_path"
24 if [[ $llvm_config = *".exe" ]]; then
25 llvm_host_win32=1
26 # llvm-config is a windows binary. Check if we are running CygWin or WSL since then we might still be able to run llvm-config.exe
27 host_uname="$(uname -a)"
28 case "$host_uname" in
29 *Microsoft*)
30 use_llvm_config=1
31 llvm_host_win32_wsl=1
33 CYGWIN*)
34 use_llvm_config=1
35 llvm_host_win32_cygwin=1
38 use_llvm_config=0
39 esac
42 if [[ $llvm_host_win32 = 1 ]]; then
43 llvm_config=$(win32_format_path "$llvm_config")
46 if [[ $use_llvm_config = 1 ]]; then
47 llvm_api_version=`$llvm_config --mono-api-version` || "0"
48 with_llvm=`$llvm_config --prefix`
49 llvm_config_cflags=`$llvm_config --cflags`
50 llvm_system=`$llvm_config --system-libs`
51 llvm_core_components=`$llvm_config --libs analysis core bitwriter`
52 if [[ $llvm_api_version -lt 600 ]]; then
53 llvm_old_jit=`$llvm_config --libs mcjit jit 2>>/dev/null`
54 else
55 llvm_old_jit=`$llvm_config --libs mcjit 2>>/dev/null`
57 llvm_new_jit=`$llvm_config --libs orcjit 2>>/dev/null`
59 if [[ ! -z $llvm_codegen_libs ]]; then
60 llvm_extra=`$llvm_config --libs $llvm_codegen_libs`
63 # When building for Windows subsystem using WSL or CygWin the path returned from llvm-config.exe
64 # could be a Windows style path, make sure to format it into a path usable for WSL/CygWin.
65 if [[ $llvm_host_win32 = 1 ]]; then
66 with_llvm=$(win32_format_path "$with_llvm")
70 # When cross compiling for Windows on system not capable of running Windows binaries, llvm-config.exe can't be used to query for
71 # LLVM parameters. In that scenario we will need to fallback to default values.
72 if [[ $llvm_host_win32 = 1 ]] && [[ $use_llvm_config = 0 ]]; then
73 # Assume we have llvm-config sitting in llvm-install-root/bin directory, get llvm-install-root directory.
74 with_llvm="$(dirname $llvm_config)"
75 with_llvm="$(dirname $with_llvm)"
76 llvm_config_path=$with_llvm/include/llvm/Config/llvm-config.h
78 # llvm-config.exe --mono-api-version
79 llvm_api_version=`awk '/MONO_API_VERSION/ { print $3 }' $llvm_config_path`
81 # llvm-config.exe --cflags, returned information currently not used.
82 llvm_config_cflags=
84 # llvm-config.exe --system-libs
85 if [[ $llvm_api_version -lt 600 ]]; then
86 llvm_system="-limagehlp -lpsapi -lshell32"
87 else
88 llvm_system="-lpsapi -lshell32 -lole32 -luuid -ladvapi32"
91 # llvm-config.exe --libs analysis core bitwriter
92 if [[ $llvm_api_version -lt 600 ]]; then
93 llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport"
94 else
95 llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
98 # llvm-config.exe --libs mcjit jit
99 if [[ $llvm_api_version -lt 600 ]]; then
100 llvm_old_jit="-lLLVMJIT -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMMCJIT -lLLVMTarget -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMExecutionEngine -lLLVMMC -lLLVMCore -lLLVMSupport"
101 else
102 # Current build of LLVM 60 for cross Windows builds doesn't support LLVM JIT.
103 llvm_old_jit=
106 # LLVM 36 doesn't support new JIT and LLVM 60 is build without LLVM JIT support for cross Windows builds.
107 llvm_new_jit=
109 # Check codegen libs and add needed libraries.
110 case "$llvm_codegen_libs" in
111 *x86codegen*)
112 # llvm-config.exe --libs x86codegen
113 if [[ $llvm_api_version -lt 600 ]]; then
114 llvm_extra="-lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMObject -lLLVMBitReader -lLLVMMCDisassembler -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport"
115 else
116 llvm_extra="-lLLVMX86CodeGen -lLLVMGlobalISel -lLLVMX86Desc -lLLVMX86Info -lLLVMMCDisassembler -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
119 *armcodegen*)
120 # llvm-config.exe --libs armcodegen
121 if [[ $llvm_api_version -lt 600 ]]; then
122 llvm_extra="-lLLVMARMCodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMARMDesc -lLLVMMCDisassembler -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMMC -lLLVMSupport"
123 else
124 llvm_extra="-lLLVMARMCodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMARMDesc -lLLVMMCDisassembler -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMARMUtils -lLLVMMC -lLLVMSupport -lLLVMDemangle"
127 *aarch64codegen*)
128 # llvm-config.exe --libs aarch64codegen
129 if [[ $llvm_api_version -lt 600 ]]; then
130 llvm_extra="-lLLVMAArch64CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMMC -lLLVMAArch64Utils -lLLVMSupport"
131 else
132 llvm_extra="-lLLVMAArch64CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMMC -lLLVMAArch64Utils -lLLVMSupport -lLLVMDemangle"
136 llvm_extra=$llvm_codegen_libs
137 esac
140 if [[ $llvm_config_cflags = *"stdlib=libc++"* ]]; then
141 llvm_libc_c="-stdlib=libc++"
142 # llvm_libc_link="-lc++"
143 else
144 llvm_libc_c=""
145 # llvm_libc_link="-lstdc++"
148 if [[ $llvm_host_win32 = 1 ]]; then
149 host_cxxflag_additions="-std=gnu++11"
150 host_cflag_additions="-DNDEBUG"
151 else
152 host_cxxflag_additions="-std=c++11"
153 host_cflag_additions=""
156 if [[ ! -z $llvm_extra_libs ]]; then
157 llvm_extra="$llvm_extra $llvm_extra_libs"
160 # llvm-config --clfags adds warning and optimization flags we don't want
161 cflags_additions="-I$with_llvm/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DLLVM_API_VERSION=$llvm_api_version $llvm_libc_c $host_cflag_additions"
163 cxxflag_additions="-fno-rtti -fexceptions $host_cxxflag_additions"
165 ldflags="-L$with_llvm/lib"
167 llvm_lib_components="$llvm_core_components $llvm_old_jit $llvm_new_jit $llvm_extra"
169 echo "LLVM_CFLAGS_INTERNAL=$cflags_additions"
170 echo "LLVM_CXXFLAGS_INTERNAL=$cflags_additions $cxxflag_additions"
171 echo "LLVM_LDFLAGS_INTERNAL=$ldflags"
172 echo "LLVM_LIBS_INTERNAL=$llvm_lib_components $ldflags $llvm_system $llvm_libc_link"