-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall
executable file
·141 lines (115 loc) · 2.69 KB
/
install
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
VERSION=1.5.5
FILE=zstd-$VERSION.tar.gz
DIR=zstd-$VERSION
URL=https://github.com/facebook/zstd/archive/v$VERSION.tar.gz
ORIG_DIR=$(pwd)
function error
{
>&2 echo "Error: $1"
}
function abort
{
error "$1"
exit 1
}
function set_tempdir
{
fix=$1
if TMPDIR=$(mktemp -d --suffix=$fix 2>/dev/null); then
return 0
fi
if TMPDIR=$(mktemp -d -t $fix); then
return 0
fi
abort "could not create a temporary directory"
}
set_tempdir zstd
function set_logfile
{
fix=$1
if LOGFILE=$(mktemp --suffix=$fix.log 2>/dev/null); then
return 0
fi
if LOGFILE=$(mktemp -t $fix.log); then
return 0
fi
abort "could not create a log file"
}
set_logfile zstd
exec 3> "$LOGFILE"
function cleanup
{
exec 3>&-
rm -rf "$TMPDIR" >/dev/null 2>&1 || true
cd "$ORIG_DIR"
}
trap cleanup EXIT
function silent_run
{
eval "$@" 2>&3 1>&3
}
function run_ldconfig
{
if type ldconfig; then
ldconfig
fi
}
function is_unix
{
case "$(uname -s)" in
Linux*) return 0;;
Darwin*) return 0;;
*) return 1
esac
}
if [ -z ${CMAKE_GENERATOR_PLATFORM+x} ]; then
GENERATOR_PLATFORM_ARG=
else
if is_unix; then
CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM:-}
else
ARCH=${ARCH:-x64}
CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM:-$ARCH}
fi
GENERATOR_PLATFORM_ARG="-DCMAKE_GENERATOR_PLATFORM:STRING=$CMAKE_GENERATOR_PLATFORM"
fi
function failed
{
exec 3>&-
echo "FAILED."
echo
echo "---------------------------------------- log begin ----------------------------------------"
cat "$LOGFILE"
echo "---------------------------------------- log end ----------------------------------------"
echo
echo "LOG: $LOGFILE"
exit 1
}
trap failed INT
function succeeded
{
cleanup
rm -rf "$LOGFILE" >/dev/null 2>&1 || true
}
echo "[0/6] Library(zstd==$VERSION)"
cd $TMPDIR
echo -n "[1/6] Downloading... "
silent_run curl -o $FILE -L $URL
[ $? == 0 ] && echo "done." || failed
echo -n "[2/6] Extracting... "
silent_run tar xzf $FILE && mkdir $DIR/build/cmake/build && silent_run cd $DIR/build/cmake/build
[ $? == 0 ] && echo "done." || failed
echo -n "[3/6] Configuring... "
silent_run cmake -DCMAKE_BUILD_TYPE=Release $GENERATOR_PLATFORM_ARG ..
[ $? == 0 ] && echo "done." || failed
echo -n "[4/6] Compiling... "
silent_run cmake --build . --config Release
[ $? == 0 ] && echo "done." || failed
echo "[5/6] Installing..."
cmake --build . --config Release --target install
[ $? == 0 ] && echo "done." || failed
echo -n "[6/6] Finalizing... "
silent_run run_ldconfig
[ $? == 0 ] && echo "done." || failed
succeeded