forked from dotnet/jitutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-coredistools.sh
executable file
·106 lines (89 loc) · 3.13 KB
/
build-coredistools.sh
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
#!/usr/bin/env bash
TargetOSArchitecture=$1
CrossRootfsDirectory=$2
case "$TargetOSArchitecture" in
linux-arm)
CrossCompiling=1
LLVMDefaultTargetTriple=thumbv7-linux-gnueabihf
LLVMHostTriple=arm-linux-gnueabihf
LLVMTargetsToBuild="AArch64;ARM"
;;
linux-arm64)
CrossCompiling=1
LLVMDefaultTargetTriple=aarch64-linux-gnu
LLVMHostTriple=aarch64-linux-gnu
LLVMTargetsToBuild="AArch64;ARM"
;;
linux-x64|osx-x64)
CrossCompiling=0
LLVMTargetsToBuild="AArch64;ARM;X86"
;;
*)
echo "Unknown target OS and architecture: $TargetOSArchitecture"
exit 1
esac
if [[ $CrossCompiling -eq 1 && ! -d $CrossRootfsDirectory ]]; then
echo "Invalid or unspecified CrossRootfsDirectory: $CrossRootfsDirectory"
exit 1
fi
RootDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SourcesDirectory=$RootDirectory/src
BinariesDirectory=$RootDirectory/obj/$TargetOSArchitecture
StagingDirectory=$RootDirectory/artifacts/$TargetOSArchitecture
which cmake >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo "ERROR: cmake is not found in the PATH"
exit 1
fi
if [ ! -d $BinariesDirectory ]; then
mkdir -p $BinariesDirectory
fi
pushd "$BinariesDirectory"
if [ "$CrossCompiling" -eq 1 ]; then
cmake \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=ON \
-DCMAKE_C_COMPILER=$(which clang) \
-DCMAKE_C_FLAGS="-target $LLVMHostTriple --sysroot=$CrossRootfsDirectory" \
-DCMAKE_CXX_COMPILER=$(which clang++) \
-DCMAKE_CXX_FLAGS="-target $LLVMHostTriple --sysroot=$CrossRootfsDirectory" \
-DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \
-DCMAKE_INSTALL_PREFIX=$StagingDirectory \
-DCMAKE_LIBRARY_PATH=$CrossRootfsDirectory/usr/lib/$LLVMHostTriple \
-DCMAKE_STRIP=/usr/$LLVMHostTriple/bin/strip \
-DLLVM_DEFAULT_TARGET_TRIPLE=$LLVMDefaultTargetTriple \
-DLLVM_EXTERNAL_PROJECTS=coredistools \
-DLLVM_EXTERNAL_COREDISTOOLS_SOURCE_DIR=$SourcesDirectory/coredistools \
-DLLVM_HOST_TRIPLE=$LLVMHostTriple \
-DLLVM_TABLEGEN=$(which llvm-tblgen) \
-DLLVM_TARGETS_TO_BUILD=$LLVMTargetsToBuild \
-DLLVM_TOOL_COREDISTOOLS_BUILD=ON \
$SourcesDirectory/llvm-project/llvm
else
cmake \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$(which clang) \
-DCMAKE_CXX_COMPILER=$(which clang++) \
-DCMAKE_INSTALL_PREFIX=$StagingDirectory \
-DLLVM_EXTERNAL_PROJECTS=coredistools \
-DLLVM_EXTERNAL_COREDISTOOLS_SOURCE_DIR=$SourcesDirectory/coredistools \
-DLLVM_TABLEGEN=$(which llvm-tblgen) \
-DLLVM_TARGETS_TO_BUILD=$LLVMTargetsToBuild \
-DLLVM_TOOL_COREDISTOOLS_BUILD=ON \
$SourcesDirectory/llvm-project/llvm
fi
popd
if [ "$?" -ne 0 ]; then
echo "ERROR: cmake exited with code $1"
exit 1
fi
cmake \
--build $BinariesDirectory \
--target install-coredistools-stripped
if [ "$?" -ne 0 ]; then
echo "ERROR: cmake exited with code $1"
exit 1
fi
exit 0