Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorJohan Lorensson <lateralusx.github@gmail.com>2018-08-29 09:51:19 +0300
committerGitHub <noreply@github.com>2018-08-29 09:51:19 +0300
commit2fc3c3a939b683f2e95ae0879eaf0cf99525e81e (patch)
tree241477354b31c0d9933d052831386b3212408ce4 /llvm
parent779ee790817aa5d5aa1ffa3e2f902218945e7ca6 (diff)
parent2f0a5a5526ea5744738426f01906ba2965a60107 (diff)
Merge pull request #10321 from lateralusX/lateralusX/fix-cross-windows-llvm-support
Fix Windows LLVM mono cross compiler build.
Diffstat (limited to 'llvm')
-rw-r--r--llvm/Makefile.am9
-rwxr-xr-xllvm/build_llvm_config.sh118
2 files changed, 97 insertions, 30 deletions
diff --git a/llvm/Makefile.am b/llvm/Makefile.am
index 8656bb3b96f..5932e921d0c 100644
--- a/llvm/Makefile.am
+++ b/llvm/Makefile.am
@@ -2,6 +2,13 @@
EXTRA_DIST=SUBMODULES.json build.mk build_llvm_config.sh
if ENABLE_LLVM
+
+if HOST_WIN32
+llvm_config=llvm-config.exe
+else
+llvm_config=llvm-config
+endif
+
if INTERNAL_LLVM
all-local: configure-llvm build-llvm install-llvm llvm_config.mk
@@ -9,7 +16,7 @@ all-local: configure-llvm build-llvm install-llvm llvm_config.mk
clean-local: clean-llvm clean-llvm-config
$(mono_build_root)/llvm/llvm_config.mk: install-llvm
- $(top_srcdir)/llvm/build_llvm_config.sh $(top_srcdir)/llvm/usr/bin/llvm-config $(LLVM_CODEGEN_LIBS) > $@
+ $(top_srcdir)/llvm/build_llvm_config.sh $(top_srcdir)/llvm/usr/bin/$(llvm_config) $(LLVM_CODEGEN_LIBS) > $@
else
all-local: llvm_config.mk
diff --git a/llvm/build_llvm_config.sh b/llvm/build_llvm_config.sh
index d6d06f269bd..8504ef0a7e2 100755
--- a/llvm/build_llvm_config.sh
+++ b/llvm/build_llvm_config.sh
@@ -3,45 +3,105 @@
llvm_config=$1
extra_libs="${@:2}"
-llvm_api_version=`$llvm_config --mono-api-version` || "0"
-with_llvm=`$llvm_config --prefix`
+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
-llvm_config_cflags=`$llvm_config --cflags`
+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`
+ llvm_old_jit=`$llvm_config --libs mcjit jit 2>>/dev/null`
+ llvm_new_jit=`$llvm_config --libs orcjit 2>>/dev/null`
+ llvm_extra=`$llvm_config --libs $extra_libs`
+
+ # 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_api_version=`awk '/MONO_API_VERSION/ { print $3 }' $llvm_config_path`
+ llvm_config_cflags=
+ llvm_system="-lshell32 -lpsapi -limagehlp"
+ llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport"
+ llvm_old_jit="-lLLVMJIT -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMMCJIT -lLLVMTarget -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMExecutionEngine -lLLVMMC -lLLVMCore -lLLVMSupport"
+ llvm_new_jit=
+ llvm_extra=
+fi
if [[ $llvm_config_cflags = *"stdlib=libc++"* ]]; then
-llvm_libc_c="-stdlib=libc++"
-llvm_libc_link="-lc++"
+ llvm_libc_c="-stdlib=libc++"
+ llvm_libc_link="-lc++"
else
-llvm_libc_c=""
-llvm_libc_link="-lstdc++"
+ llvm_libc_c=""
+ llvm_libc_link="-lstdc++"
fi
-# llvm-config --clfags adds warning and optimization flags we don't want
-shared_llvm_cflags="-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"
-cxxflag_additions="-std=c++11 -fno-rtti -fexceptions"
-
-ldflags="-L$with_llvm/lib"
+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
-llvm_system=`$llvm_config --system-libs`
+# 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_core_components=`$llvm_config --libs analysis core bitwriter`
-llvm_old_jit=`$llvm_config --libs mcjit jit 2>>/dev/null`
-llvm_new_jit=`$llvm_config --libs orcjit 2>>/dev/null`
-llvm_extra=`$llvm_config --libs $extra_libs`
llvm_lib_components="$llvm_core_components $llvm_old_jit $llvm_new_jit $llvm_extra"
-
-echo "LLVM_CFLAGS_INTERNAL=$shared_llvm_cflags"
-echo "LLVM_CXXFLAGS_INTERNAL=$shared_llvm_cflags $cxxflag_additions"
+
+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"
-
-
-
-
-
-
-
-
-