-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-syscall-replayer.sh
executable file
·182 lines (166 loc) · 5.13 KB
/
build-syscall-replayer.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
#
# Build the program reanimator-replayer, installing any required dependencies if
# requested.
####################
# Script variables #
####################
readonly numberOfCores="$(nproc --all)"
install=false
installPackages=false
configArgs=""
replayerDir="$(pwd)"
installDir="${replayerDir}/reanimator_replayer_release"
buildDir="${replayerDir}/build"
repositoryDir="${buildDir}/repositories"
readonly programDependencies=("autoconf" "automake" "cmake" "gcc" "g++" "perl" "git")
missingPrograms=()
####################
# Script functions #
####################
function runcmd
{
echo "CMD: $*"
sleep 0.2
"$@"
ret=$?
if test $ret -ne 0 ; then
exit $ret
fi
}
function printUsage
{
(
cat << EOF
Usage: $0 [options...]
Options:
--build-dir DIR Download repositories and place build files in DIR
--config-args ARGS Append ARGS to every ./configure command
--install Install libraries and binaries under /usr/local
--install-dir DIR Install libraries and binaries under DIR
--install-packages Automatically use apt-get to install missing packages
-h, --help Print this help message
EOF
) >&2
exit 0
}
##################
# Script startup #
##################
# Parse script arguments
while [[ $# -gt 0 ]]; do
key="$1"
case "${key}" in
--build-dir)
shift # past argument
repositoryDir="$(realpath "$1" || exit $?)"
shift # past value
;;
--config-args)
shift # past argument
configArgs="$1"
shift # past value
;;
--install)
install=true
installDir="/usr/local"
shift # past argument
;;
--install-dir)
shift # past argument
installDir="$(realpath "$1" || exit $?)"
shift # past value
;;
--install-packages)
if command -v apt-get >/dev/null; then
installPackages=true
else
echo "Could not find apt-get. Missing packages must be \
installed manually." >&2
fi
shift # past argument
;;
-h|--help)
printUsage
shift # past argument
;;
*)
shift # past argument
;;
esac
done
# Check system for sudo command
if $install; then
if ! command -v sudo &>/dev/null; then
echo "Script could not find 'sudo' command. Cannot install." >&2
exit 1
fi
fi
# Check whether program dependencies are installed
for program in "${programDependencies[@]}"; do
programPath=$(command -v "${program}")
if [[ $? == 0 ]]; then
echo "${program}: Located at ${programPath}"
elif [[ "${installPackages}" == true ]]; then
echo "${program}: Not found. Queuing for installation..."
missingPrograms+=("${program}")
else
echo "${program}: Not found."
missingPrograms+=("${program}")
fi
done
# Check whether the user has all required programs for building
if [[ "${#missingPrograms[@]}" -gt 0 ]]; then
if [[ "${installPackages}" == true ]]; then
echo "Installing missing programs."
runcmd sudo apt-get install -y "${missingPrograms[*]}"
else
echo "Could not find all required programs. Not found:"
for program in "${missingPrograms[@]}"; do
echo " ${program}"
done
echo "To install on a Debian-based system, run the command"
echo " sudo apt-get install ${missingPrograms[*]}"
exit 1
fi
fi
#################
# Build process #
#################
# Cloning all repositories
runcmd mkdir -p "${repositoryDir}"
runcmd cd "${repositoryDir}"
[[ -d "oneTBB" ]] || runcmd git clone https://github.com/oneapi-src/oneTBB.git
[[ -d "reanimator-library" ]] || runcmd git clone https://github.com/SNIA/reanimator-library.git
# Build reanimator-library
# ------------------------
runcmd cd reanimator-library
runcmd chmod +x build-reanimator-library.sh
if $install; then
runcmd ./build-reanimator-library.sh --config-args "${configArgs}" --install
else
runcmd ./build-reanimator-library.sh --config-args "${configArgs}" --install-dir "${installDir}"
fi
runcmd cd "${repositoryDir}"
# Building tbb
# ------------
runcmd cd oneTBB
runcmd git fetch --all --tags --prune
runcmd git checkout tags/v2020.3
if $install; then
runcmd sudo cp -r ./include/. "${installDir}/include"
runcmd sudo make tbb_build_dir="${installDir}/lib" tbb_build_prefix=one_tbb -j"${numberOfCores}"
runcmd sudo cp "${installDir}/lib/one_tbb_release/"*".so"* "${installDir}/lib"
else
runcmd cp -r ./include/. "${installDir}/include"
runcmd make tbb_build_dir="${installDir}/lib" tbb_build_prefix=one_tbb -j"${numberOfCores}"
runcmd cp "${installDir}/lib/one_tbb_release/"*".so"* "${installDir}/lib"
fi
runcmd cd "${repositoryDir}"
# Building syscall-replayer
# -------------------------
runcmd cd "${replayerDir}"
runcmd cd build
runcmd cmake -DCMAKE_INSTALL_PREFIX="${installDir}" ..
runcmd make -j"${numberOfCores}"
runcmd make -j"${numberOfCores}" install