forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmt_build.sh
executable file
·88 lines (79 loc) · 2.49 KB
/
mt_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
#!/bin/bash
# Copyright (c) 2023-2024 Moore Threads Technology Co., Ltd("Moore Threads"). All rights reserved.
# Terms of the MIT License
workdir="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
BUILD_DIR=$(cd `dirname $0`; pwd)/build
op_type="install"
install_prefix=/usr/local/musa
usage() {
echo -e "musa toolkits install script"
echo -e "Usage:"
echo -e "$0 <options>"
echo -e " [-i | --install]"
echo -e " [-u | --uninstall]"
echo -e " [-d | --prefix=<install_prefix>]"
echo -e " [-h | --help]"
echo -e ""
}
die() {
echo "$*" >&2;
exit 2;
}
needs_arg() {
if [ -z "$OPTARG" ]; then
usage
die "No arg for --$OPT option";
fi;
}
install_func () {
mkdir -p ${BUILD_DIR}
pushd ${BUILD_DIR}
cmake \
-DCMAKE_INSTALL_PREFIX=${install_prefix} \
-DTHRUST_ENABLE_HEADER_TESTING=OFF \
-DTHRUST_ENABLE_TESTING=OFF \
-DTHRUST_ENABLE_EXAMPLES=OFF \
-DTHRUST_INSTALL_CUB_HEADERS=OFF \
.. 2>&1 | tee cmake.log
cmake --build . 2>&1 | tee build.log
if [ ! -w ${install_prefix} ]; then
sudo cmake --build . --target install 2>&1 | tee install.log
else
cmake --build . --target install 2>&1 | tee install.log
fi
popd
}
uninstall_func () {
if [ "$UID" -ne "0" ]; then
sudo \rm -vrf ${install_prefix}/include/thrust
sudo \rm -vrf ${install_prefix}/lib/cmake/thrust
sudo \rm -vf ${install_prefix}/bin/Thrust_version
else
\rm -vrf ${install_prefix}/include/thrust
\rm -vrf ${install_prefix}/lib/cmake/thrust
\rm -vf ${install_prefix}/bin/Thrust_version
fi
}
while getopts d:-:iuh OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
i | install ) op_type=install;;
u | uninstall ) op_type=uninstall;;
d | prefix ) needs_arg; install_prefix="$OPTARG";;
h | help ) usage; exit 2;;
??* ) die "Illegal option --$OPT" ;; # bad long option
? ) exit 2 ;; # bad short option (error reported via getopts)
esac
done
if [[ "$op_type" == "install" ]]; then
echo "install ..."
install_func
fi
if [[ "$op_type" == "uninstall" ]]; then
echo "uninstall ..."
uninstall_func
fi