forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·115 lines (101 loc) · 3.04 KB
/
build.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
107
108
109
110
111
112
113
114
115
#!/bin/bash
LLVM_HOME=`pwd`
INSTALL=~/opt/riscv
TYPE=Release
THREAD=8
BUILD_ONLY=0
LLVM_DYLIB=On
BUILD_DIR=build
LOG=$LLVM_HOME/build/build.log
PROJECTS="clang;compiler-rt;lld;clang-tools-extra"
TOOL="Unix Makefiles"
LINKER="gold"
SECURITY_OPTION="-fPIE -pie -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack"
help() {
cat<<HELP
Usage: ./build.sh param
-b Set build only, default is 0
-g Set build type to Debug, default is Release
-h --help Print parameter description
-j Set therad number, default is 8
-l Set path of log, default is ./build/build.log
-p --prefix Set CMAKE_INSTALL_PREFIX, default is ~/opt/riscv
-n use ninja to build
HELP
exit 0
}
build_install_llvm() {
if [ ! -d $BUILD_DIR ]; then
mkdir $BUILD_DIR
fi
MAKE="make"
if [ "${TOOL}" = "Ninja" ]; then
MAKE=ninja
fi
# Only use ld in centos.
if [[ `uname -a` =~ "centos" ]]; then
LINKER=""
fi
# More cmake option reference https://llvm.org/docs/CMake.html
cd $BUILD_DIR && cmake -G "$TOOL" \
-DCMAKE_INSTALL_PREFIX=$INSTALL \
-DCMAKE_BUILD_TYPE=$TYPE \
-DCMAKE_C_FLAGS="$SECURITY_OPTION" \
-DCMAKE_CXX_FLAGS="$SECURITY_OPTION" \
-DCOMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG=OFF \
-DLLVM_OPTIMIZED_TABLEGEN=On \
-DLLVM_USE_LINKER=$LINKER \
-DLLVM_ENABLE_PROJECTS=$PROJECTS \
-DLLVM_LINK_LLVM_DYLIB=$LLVM_DYLIB \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" ../llvm > $LOG 2>&1
if [ $? -ne 0 ] ; then
echo "llvm cmake failed, exit!"
cat $LOG
exit 1
fi
$MAKE -j $THREAD VERBOSE=9 >> $LOG 2>&1
if [ $? -ne 0 ] ; then
echo "llvm make failed, exit!"
cat $LOG
exit 1
fi
if [ $BUILD_ONLY -eq 1 ]; then
echo "llvm build successful"
exit 0
fi
$MAKE install >> $LOG 2>&1
if [ $? -ne 0 ] ; then
echo "llvm make install failed, exit!"
cat $LOG
exit 1
fi
}
while [ -n "$1" ]
do
case "$1" in
-h|--help) help ;;
-b) BUILD_ONLY="1" ;;
-n) TOOL="Ninja" ;;
-g) TYPE="Debug"
LLVM_DYLIB=OFF
BUILD_DIR=build_debug
PROJECTS="clang;lld"
LOG=$LLVM_HOME/$BUILD_DIR/build.log ;;
-p|--prefix) INSTALL="$2"
shift ;;
-l) LOG="$2"
shift ;;
-j) THREAD="$2"
shift ;;
*) echo "error: $1 is not an option"
exit 1;;
esac
shift
done
echo -e "build param:\n prefix = $INSTALL\n type = $TYPE\n log = $LOG\n thread = $THREAD\n tool = $TOOL"
echo -e " build_only = $BUILD_ONLY\n llvm_dylib=$LLVM_DYLIB\n build_dir=$BUILD_DIR"
echo -e " security_option = $SECURITY_OPTION"
echo "start to build llvm"
build_install_llvm