/
configure-dmalloc
executable file
·294 lines (254 loc) · 5.45 KB
/
configure-dmalloc
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/bin/sh -eu
# configure-dmalloc: download and configure Dmalloc
# Copyright (C) 2021 "Michael G. Morey" <mgmorey@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
DMALLOC_ARCHIVE_DIR="$HOME/Downloads/Dmalloc"
DMALLOC_ARCHIVE_SUFFIX=.tgz
DMALLOC_MIRROR_BASE_URL=https://dmalloc.com
DMALLOC_OPT_PREFIX=/opt/%s
DMALLOC_PROJECT_NAME=dmalloc
DMALLOC_PROJECT_VERSION=5.6.5
abort() {
printf "$@" >&2
exit 1
}
abort_invalid_prefix() {
usage_error '%s: invalid prefix -- %s\n' "$script" "$*"
}
abort_invalid_version() {
usage_error '%s: invalid version -- %s\n' "$script" "$*"
}
abort_not_supported() {
abort '%s: %s: %s not supported\n' "$script" "$PRETTY_NAME" "$*"
}
assert() {
"$@" || abort '%s: Assertion failed: %s\n' "$script" "$*"
}
configure_dmalloc() {
umask 0022
if [ "$force" = true ]; then
rm -rf "$src_dirname" "$archive_pathname"
fi
mkdir -p "$src_dirname" "$archive_dirname"
download_archive "$archive_pathname" "$archive_url"
extract_archive "$archive_pathname" "$src_dirname"
cd "$src_dirname"
CFLAGS="${CFLAGS+$CFLAGS }-fPIC"
CXXFLAGS="${CXXFLAGS+$CXXFLAGS }-fPIC"
command=$(get_configure_command "$src_dirname")
printf '%s\n' "$command"
eval $command
if [ "$build" = true ]; then
make_build all cxx cxxsl shlib threads threadscxx threadscxxsl utils
fi
if [ "$check" = true ]; then
make_check "check"
fi
}
configure_paths() {
archive_dirname="$DMALLOC_ARCHIVE_DIR"
archive_basename=$DMALLOC_PROJECT_NAME-$version
src_dirname="$HOME/Documents/src/Dmalloc/$archive_basename"
archive_filename=$archive_basename$DMALLOC_ARCHIVE_SUFFIX
archive_pathname="$DMALLOC_ARCHIVE_DIR/$archive_filename"
archive_url=$DMALLOC_MIRROR_BASE_URL/releases/$archive_filename
}
get_configure_options() (
if [ -n "${prefix-}" ]; then
options="${options:+$options }--prefix=$(get_prefix)"
fi
if [ -n "${options:-}" ]; then
printf '%s\n' "$options"
fi
)
get_dependencies() {
get-packages $DMALLOC_PROJECT_NAME-build $DMALLOC_PROJECT_NAME-install
}
get_prefix() {
printf "$prefix" "$DMALLOC_PROJECT_NAME-$version"
}
install_dmalloc() {
if [ "$install" != true ]; then
return 0
elif [ "$ID" != windows -a "$(id -u)" -gt 0 ]; then
return 0
fi
umask 0022
cd "$src_dirname"
install_prefix=$(get_prefix)
targets="install installcxx installcxxsl installdocs installsl \
installth installthcxx installthcxxsl installthsl"
make_install prefix="$install_prefix" $targets
install_project_link "$install_prefix"
}
parse_arguments() {
build=true
check=true
force=false
install=false
prefix=$DMALLOC_OPT_PREFIX
version=$DMALLOC_PROJECT_VERSION
while getopts bcfinp:v:h opt; do
case $opt in
(b)
build=true
;;
(c)
check=true
;;
(f)
build=true
force=true
;;
(i)
install=true
;;
(n)
build=false
force=false
;;
(p)
case $OPTARG in
($HOME/.local|$LOCAL_PREFIX|$DMALLOC_OPT_PREFIX)
prefix=$OPTARG
;;
(*)
abort_invalid_prefix $OPTARG
;;
esac
;;
(v)
case $OPTARG in
(5.[0-9].[0-9]|5.[1-9][0-9]|5.[1-9][0-9].[0-9])
version=$OPTARG
;;
(*)
abort_invalid_version $OPTARG
;;
esac
;;
(h)
usage
exit 0
;;
(\?)
exit 2
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -gt 0 ]; then
usage_error '%s: Too many arguments\n' "$script"
fi
}
usage() {
cat <<EOF >&2
Usage: $script [-b] [-c] [-f] [-i] [-n] [-p PREFIX] [-v VERSION]
$script -h
EOF
}
usage_error() {
if [ $# -gt 0 ]; then
printf "$@" >&2
fi
printf '%s\n' '' >&2
usage
exit 2
}
validate_platform() {
case "$ID" in
(centos)
case "$VERSION_ID" in
(7)
return
;;
(8)
return
;;
(*)
abort_not_supported Release
;;
esac
;;
(debian|raspbian)
return
;;
(fedora)
return
;;
(opensuse-*)
return
;;
(rhel|ol)
case "$VERSION_ID" in
(7.*)
return
;;
(8.*)
return
;;
(*)
abort_not_supported Release
;;
esac
;;
(ubuntu)
return
;;
(freebsd)
return
;;
(illumos)
return
;;
(macos)
return
;;
(netbsd)
return
;;
(solaris)
return
;;
(windows)
return
;;
(*)
abort_not_supported "Operating system"
;;
esac
}
script=$(basename "$0")
case "$0" in
(*/*)
script_dir=$(cd "$(dirname "$0")" && pwd)
;;
(*)
script_dir=
;;
esac
script_prefix=${script_dir:+$script_dir/}
. "${script_prefix}common-functions.sh"
. "${script_prefix}config-functions.sh"
set_user_profile "$script_dir"
eval $(get-os-release -x)
validate_platform
configure_platform
parse_arguments "$@"
configure_paths
install_dependencies
if [ "$(id -u)" -eq 0 ]; then
run_unpriv /bin/sh -c "$0 $*"
else
configure_dmalloc
fi
install_dmalloc