-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
122 lines (110 loc) · 3.39 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
116
117
118
119
120
121
#!/bin/bash
# Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
# libkperf licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Author: Mr.Dai
# Create: 2024-04-03
# Description: Building mainstream processes.
set -e
set -x
CURRENT_DIR=$(cd $(dirname "$0"); pwd)
PROJECT_DIR=$(realpath "${CURRENT_DIR}")
BUILD_DIR=${PROJECT_DIR}/_build
THIRD_PARTY=${PROJECT_DIR}/third_party/
INSTALL_PATH=${PROJECT_DIR}/output/
BUILD_TYPE=Release
# Python module are not compiled by default.
PYTHON=false
# Test cases are not compiled by default.
INCLUDE_TEST=false
source ${PROJECT_DIR}/build/common.sh
creat_dir "${BUILD_DIR}"
# Specifies the gcc used by all dependencies.
export CC=gcc
export CXX=g++
PYTHON_EXE=""
if [ -d "${THIRD_PARTY}/local" ];then
echo ${THIRD_PARTY}/local "is exist"
else
echo ${THIRD_PARTY}local "is not exist"
creat_dir ${THIRD_PARTY}/local
fi
for arg in "$@"; do
case "$arg" in
test=*)
INCLUDE_TEST="${arg#*=}"
;;
python=*)
PYTHON="${arg#*=}"
;;
install_path=*)
INSTALL_PATH="${arg#*=}"
;;
build_type=*)
BUILD_TYPE="${arg#*=}"
;;
python_exe=*)
PYTHON_EXE="${arg#*=}"
;;
esac
done
if [[ "$INCLUDE_TEST" == "true" ]]; then
build_googletest $THIRD_PARTY
fi
function build_elfin() {
local cmake_target_dir=$THIRD_PARTY/local/elfin-parser
rm -rf ${cmake_target_dir}
if [ -d "${cmake_target_dir}" ];then
echo ${cmake_target_dir} "is exist"
return
else
echo ${cmake_target_dir} "is not exist"
mkdir ${cmake_target_dir}
fi
cd "$THIRD_PARTY/elfin-parser"
rm -rf build
sed -i 's/-mcpu=tsv110//g' Common.cmake
sed -i 's/-mno-outline-atomics//g' Common.cmake
sed -i 's/-march=armv8.2-a//g' Common.cmake
if ! grep -q "^add_compile_options(-Wno-error=switch-enum)" CMakeLists.txt; then
sed -i '1i\add_compile_options(-Wno-error=switch-enum)' CMakeLists.txt
fi
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${cmake_target_dir} -DCMAKE_CXX_FLAGS="-fPIC" ..
make --silent -j ${cpu_core_num}
cp ./lib64/libdwarf++.a ./lib64/libelf++.a ${cmake_target_dir}
echo "install log path: $cmake_target_dir"
}
build_libkperf()
{
cd $BUILD_DIR
# Remove the PYTHON_KPERF warning
if [ -z ${PYTHON_EXE} ];then
cmake -DINCLUDE_TEST=${INCLUDE_TEST} -DPYTHON=${PYTHON} -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
else
cmake -DINCLUDE_TEST=${INCLUDE_TEST} -DPYTHON=${PYTHON} -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DPYTHON_KPERF=${PYTHON_EXE} ..
fi
make -j ${cpu_core_num}
make install
echo "build libkperf success"
}
function build_test()
{
if [ "$INCLUDE_TEST" = "true" ]; then
execute_binary "$PROJECT_DIR"
fi
}
main() {
build_elfin
build_libkperf
build_test
}
# bash build.sh test=true installPath=/home/ build_type=Release .The last three settings are optional.
main $@