File: build_llvm_config.sh

package info (click to toggle)
mono 5.18.0.240+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,253,216 kB
  • sloc: cs: 10,925,936; xml: 2,804,987; ansic: 643,970; cpp: 120,384; perl: 59,272; asm: 21,383; sh: 20,162; makefile: 18,157; python: 4,715; pascal: 924; sql: 859; sed: 16; php: 1
file content (172 lines) | stat: -rwxr-xr-x 7,841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash

llvm_config=$1
llvm_codegen_libs="$2"
llvm_extra_libs="${@:3}"

use_llvm_config=1
llvm_host_win32=0
llvm_host_win32_wsl=0
llvm_host_win32_cygwin=0

function win32_format_path {
	local formatted_path=$1
	if  [[ $llvm_host_win32_wsl = 1 ]] && [[ $1 != "/mnt/"* ]]; then
		# if path is not starting with /mnt under WSL it could be a windows path, convert using wslpath.
		formatted_path="$(wslpath -a "$1")"
	elif [[ $llvm_host_win32_cygwin = 1 ]] && [[ $1 != "/cygdrive/"* ]]; then
		# if path is not starting with /cygdrive under CygWin it could be a windows path, convert using cygpath.
		formatted_path="$(cygpath -a "$1")"
	fi
	echo "$formatted_path"
}

if [[ $llvm_config = *".exe" ]]; then
	llvm_host_win32=1
	# 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
	host_uname="$(uname -a)"
	case "$host_uname" in
		*Microsoft*)
			use_llvm_config=1
			llvm_host_win32_wsl=1
			;;
		CYGWIN*)
			use_llvm_config=1
			llvm_host_win32_cygwin=1
			;;
		*)
			use_llvm_config=0
	esac
fi

if [[ $llvm_host_win32 = 1 ]]; then
	llvm_config=$(win32_format_path "$llvm_config")
fi

if [[ $use_llvm_config = 1 ]]; then
	llvm_api_version=`$llvm_config --mono-api-version` || "0"
	with_llvm=`$llvm_config --prefix`
	llvm_config_cflags=`$llvm_config --cflags`
	llvm_system=`$llvm_config --system-libs`
	llvm_core_components=`$llvm_config --libs analysis core bitwriter`
	if [[ $llvm_api_version -lt 600 ]]; then
		llvm_old_jit=`$llvm_config --libs mcjit jit 2>>/dev/null`
	else
		llvm_old_jit=`$llvm_config --libs mcjit 2>>/dev/null`
	fi
	llvm_new_jit=`$llvm_config --libs orcjit 2>>/dev/null`

	if [[ ! -z $llvm_codegen_libs ]]; then
		llvm_extra=`$llvm_config --libs $llvm_codegen_libs`
	fi

	# When building for Windows subsystem using WSL or CygWin the path returned from llvm-config.exe
	# could be a Windows style path, make sure to format it into a path usable for WSL/CygWin.
	if [[ $llvm_host_win32 = 1 ]]; then
		with_llvm=$(win32_format_path "$with_llvm")
	fi
fi

# When cross compiling for Windows on system not capable of running Windows binaries, llvm-config.exe can't be used to query for
# LLVM parameters. In that scenario we will need to fallback to default values.
if [[ $llvm_host_win32 = 1 ]] && [[ $use_llvm_config = 0 ]]; then
	# Assume we have llvm-config sitting in llvm-install-root/bin directory, get llvm-install-root directory.
	with_llvm="$(dirname $llvm_config)"
	with_llvm="$(dirname $with_llvm)"
	llvm_config_path=$with_llvm/include/llvm/Config/llvm-config.h

	# llvm-config.exe --mono-api-version
	llvm_api_version=`awk '/MONO_API_VERSION/ { print $3 }' $llvm_config_path`

	# llvm-config.exe --cflags, returned information currently not used.
	llvm_config_cflags=

	# llvm-config.exe --system-libs
	if [[ $llvm_api_version -lt 600 ]]; then
		llvm_system="-limagehlp -lpsapi -lshell32"
	else
		llvm_system="-lpsapi -lshell32 -lole32 -luuid -ladvapi32"
	fi

	# llvm-config.exe --libs analysis core bitwriter
	if [[ $llvm_api_version -lt 600 ]]; then
		llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport"
	else
		llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
	fi

	# llvm-config.exe --libs mcjit jit
	if [[ $llvm_api_version -lt 600 ]]; then
		llvm_old_jit="-lLLVMJIT -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMMCJIT -lLLVMTarget -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMExecutionEngine -lLLVMMC -lLLVMCore -lLLVMSupport"
	else
		# Current build of LLVM 60 for cross Windows builds doesn't support LLVM JIT.
		llvm_old_jit=
	fi

	# LLVM 36 doesn't support new JIT and LLVM 60 is build without LLVM JIT support for cross Windows builds.
	llvm_new_jit=

	# Check codegen libs and add needed libraries.
	case "$llvm_codegen_libs" in
		*x86codegen*)
			# llvm-config.exe --libs x86codegen
			if [[ $llvm_api_version -lt 600 ]]; then
				llvm_extra="-lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMObject -lLLVMBitReader -lLLVMMCDisassembler -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport"
			else
				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"
			fi
			;;
		*armcodegen*)
			# llvm-config.exe --libs armcodegen
			if [[ $llvm_api_version -lt 600 ]]; then
				llvm_extra="-lLLVMARMCodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMARMDesc -lLLVMMCDisassembler -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMMC -lLLVMSupport"
			else
				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"
			fi
			;;
		*aarch64codegen*)
			# llvm-config.exe --libs aarch64codegen
			if [[ $llvm_api_version -lt 600 ]]; then
				llvm_extra="-lLLVMAArch64CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMMC -lLLVMAArch64Utils -lLLVMSupport"
			else
				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"
			fi
			;;
		*)
			llvm_extra=$llvm_codegen_libs
	esac
fi

if [[ $llvm_config_cflags = *"stdlib=libc++"* ]]; then
	llvm_libc_c="-stdlib=libc++"
	llvm_libc_link="-lc++"
else
	llvm_libc_c=""
	llvm_libc_link="-lstdc++"
fi

if [[ $llvm_host_win32 = 1 ]]; then
	host_cxxflag_additions="-std=gnu++11"
	host_cflag_additions="-DNDEBUG"
else
	host_cxxflag_additions="-std=c++11"
	host_cflag_additions=""
fi

if [[ ! -z $llvm_extra_libs ]]; then
	llvm_extra="$llvm_extra $llvm_extra_libs"
fi

# llvm-config --clfags adds warning and optimization flags we don't want
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"

cxxflag_additions="-fno-rtti -fexceptions $host_cxxflag_additions"

ldflags="-L$with_llvm/lib"

llvm_lib_components="$llvm_core_components $llvm_old_jit $llvm_new_jit $llvm_extra"

echo "LLVM_CFLAGS_INTERNAL=$cflags_additions"
echo "LLVM_CXXFLAGS_INTERNAL=$cflags_additions $cxxflag_additions"
echo "LLVM_LDFLAGS_INTERNAL=$ldflags"
echo "LLVM_LIBS_INTERNAL=$llvm_lib_components $ldflags $llvm_system $llvm_libc_link"