-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-reanimator-strace.sh
executable file
·176 lines (161 loc) · 4.76 KB
/
build-reanimator-strace.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
#!/bin/bash
#
# Build the program reanimator-strace, installing any required dependencies if
# requested.
####################
# Script variables #
####################
readonly numberOfCores="$(nproc --all)"
install=false
installPackages=false
configArgs=""
installDir="$(pwd)/dist/reanimator_strace_release"
repositoryDir="$(pwd)/BUILD/repositories"
straceDir="$(pwd)"
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}" == true ]]; 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 "reanimator-library" ]] || runcmd git clone https://github.com/SNIA/reanimator-library.git
# Building reanimator-library
# ---------------------------
runcmd cd reanimator-library
runcmd chmod +x build-reanimator-library.sh
if $install; then
runcmd ./build-reanimator-library.sh --install
else
runcmd mkdir -p "${installDir}"
runcmd ./build-reanimator-library.sh --install-dir "${installDir}"
fi
runcmd cd "${repositoryDir}"
# Building reanimator-strace
# --------------------------
runcmd cd "${straceDir}"
runcmd ./bootstrap
runcmd mkdir -p BUILD
runcmd cd BUILD
runcmd export CPPFLAGS="-I${installDir}/strace2ds/include"
runcmd export LDFLAGS="\
-Xlinker -rpath=${installDir}/lib:${installDir}/strace2ds/lib \
-L${installDir}/lib -L${installDir}/strace2ds/lib"
libs="-lstrace2ds -lLintel -lDataSeries"
runcmd ../configure --enable-mpers=check --enable-dataseries
runcmd make clean
runcmd make LIBS="${libs}" CCLD=g++
if [[ "${install}" == false ]]; then
runcmd cp ./strace "${installDir}/bin/"
fi
runcmd cd "${repositoryDir}"