-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·299 lines (254 loc) · 7.85 KB
/
configure
File metadata and controls
executable file
·299 lines (254 loc) · 7.85 KB
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
295
296
297
298
299
#!/usr/bin/env bash
declare GITHUB_BASE="https://github.com/cjungmann/lib"
#############################
### CUSTOMIZED TO PROJECT ###
#############################
# github.com/cjungmann libraries, cloned and built below if not installed
declare -a CJUNGMANN_LIBS_NEEDED=( argeater )
# System resource prerequisites:
declare -a LIBS_REQUIRED=()
declare -a HEADERS_REQUIRED=(
builtins.h bash-builtins
)
declare -a APPS_REQUIRED=(
gcc build-essential
soelim man-db
less less
)
#############################
### END OF PROJECT CUSTOM ###
#############################
app_test()
{
type "$1" >/dev/null 2>&1
local -i ecode="$?"
return "$ecode"
}
lib_test()
{
local -i count=$( /sbin/ldconfig -p | grep -c "$1" )
(( count == 1 ))
}
header_test()
{
printf $'#include <%s>\nint main(void)\n{ return 0; }\n' "$1" > bogus.c
local bi_pre=/usr/include/bash
local -a incs=( -I"$bi_pre" -I"$bi_pre"/include )
gcc -x c -fsyntax-only "${incs[@]}" bogus.c >/dev/null 2>&1
local -i ecode="$?"
rm bogus.c
[ "$ecode" -eq 0 ]
}
man_test()
{
local errmsg=$( groff -z <( echo ".mso gproto.tmac" ) 2>&1 )
if [ -n "$errmsg" ]; then
echo $'You must install \e[31;1mgrofflib\e[39;22m to access the man pages.'
echo "Copy and paste the following green lines to install grofflib:"
echo ""
printf $'\e[32;1m'
echo "git clone https://www.github.com/cjungmann/grofflib.git"
echo "cd grofflib"
echo "sudo make install"
echo "cd .."
printf $'\e[39;22m'
echo ""
return 1
fi
return 0
}
confirm_prereq()
{
local -n cp_list="$1"
local cp_test_function="$2"
local cp_prereq_type="$3"
# Nameref to update global variable
local -n cp_all=PACKAGES_REQUIRED
local fmt=$'Missing %s \e[31;1m%s\e[39;22m. Please install \e[31;1m%s\e[39;22m.\n'
local -i missing_count=0
local prereq package el
for el in "${cp_list[@]}"; do
if [ -z "$prereq" ]; then
prereq="$el"
else
package="$el"
if ! "$cp_test_function" "$prereq"; then
# Give warning
printf "$fmt" "$cp_prereq_type" "$prereq" "$package"
# track missing count for function exit code
(( ++missing_count ))
# Accumulate missing packages for final message
cp_all+=( $package )
fi
prereq=""
package=""
fi
done
[ "$missing_count" -eq 0 ]
}
confirm_prerequisites()
{
local -a PACKAGES_REQUIRED=()
local -i error_count=0
confirm_prereq "LIBS_REQUIRED" "lib_test" "library"
(( TOTAL_ERRORS += $? ))
confirm_prereq "APPS_REQUIRED" "app_test" "app"
(( TOTAL_ERRORS += $? ))
confirm_prereq "HEADERS_REQUIRED" "header_test" "header"
(( TOTAL_ERRORS += $? ))
if [ "$TOTAL_ERRORS" -gt 0 ]; then
echo
echo "Use your package manager to install the following packages:"
printf $' \e[32;1m%s\e[39;22m\n' "${PACKAGES_REQUIRED[*]}"
echo ""
echo "Hint: copy the green list to paste into your install command."
echo
return 1
fi
return 0
}
########################################################
### Checking for and installing my missing libraries ###
########################################################
update_arrays_for_static_library()
{
local ua_libname="$1"
local ua_dir="libs/lib${libname}"
local ua_libfile="${ua_dir}/lib${libname}.a"
if [ -d "$ua_dir" ]; then
if [ -f "$ua_libfile" ]; then
LIB_MODULES_ARRAY+=( "$ua_libfile" )
INCFLAGS_ARRAY+=( "-I$ua_dir" )
fi
fi
}
install_and_build_library()
{
local libname="$1"
if ! [ -d "libs" ]; then
mkdir libs
fi
cd libs
git clone "${GITHUB_BASE}${libname}.git"
cd "lib$libname"
local dir="libs/lib$libname"
make
local -i ecode="$?"
cd ../..
if [ "$ecode" -eq 0 ]; then
update_arrays_for_static_library "$libname"
fi
}
shared_library_installed()
{
local libname="lib${1}.so"
/usr/sbin/ldconfig -p | grep [[:space:]]"$libname"[[:space:]] 2>&1 >/dev/null
}
static_library_installed()
{
local libname="$1"
local libdir="libs/lib${libname}"
local libfile="$libdir/lib${libname}.a"
if [ -d "$libdir" ]; then
if [ -f "$libfile" ]; then
return 0
fi
fi
return 1
}
confirm_library()
{
local libname="$1"
if shared_library_installed "$libname"; then
LIB_FLAGS_ARRAY+=( "-l$libname" )
elif static_library_installed "$libname"; then
update_arrays_for_static_library "$libname"
else
install_and_build_library "$libname"
fi
}
setup_cjungmann_libs()
{
local -n scl_SED_ARGS="$1"
# Arrays to track Makefile updates:
local -a LIB_FLAGS_ARRAY=()
local -a LIB_MODULES_ARRAY=()
local -a INCFLAGS_ARRAY=()
for lib in "${CJUNGMANN_LIBS_NEEDED[@]}"; do
confirm_library "$lib"
done
if [ "${#LIB_FLAGS_ARRAY[*]}" -gt 0 ]; then
local flags_str="s|^LIB_FLAGS =.*|LIB_FLAGS = ${LIB_FLAGS_ARRAY[*]}|"
flags_str="${flags_str// /\\ }"
scl_SED_ARGS+=( -e "$flags_str" )
fi
if [ "${#LIB_MODULES_ARRAY[*]}" -gt 0 ]; then
local mods_str="s|^LIB_MODULES =.*|LIB_MODULES = ${LIB_MODULES_ARRAY[*]}|"
mods_str="${mods_str// /\\ }"
scl_SED_ARGS+=( -e "$mods_str" )
fi
if [ "${#INCFLAGS_ARRAY[*]}" -gt 0 ]; then
local incflags_str="s|^INCFLAGS =.*|INCFLAGS = ${INCFLAGS_ARRAY[*]}|"
incflags_str="${incflags_str// /\\ }"
scl_SED_ARGS+=( -e "$incflags_str" )
fi
}
update_makefile_prefix()
{
local -n ump_SED_ARGS="$1"
shift
local option value prefix="/usr/local"
for arg in "$@"; do
if [ -z "$option" ] && [[ "${arg:0:2}" == "--" ]]; then
option="${arg:2}"
else
value="$arg"
if [[ "$option" == "prefix" ]]; then
if [ -d "$value" ]; then
prefix="$value"
else
(( ++TOTAL_ERRORS ))
printf $'Prefix directory \e[31;1m%s\e[39;22m does not exist.\n' "$value"
return 1
fi
fi
# Ignoring, for now, additional arguments or unrecognized options
option=
value=
fi
done
local sedscr="s|PREFIX +\\?= +.*|PREFIX ?= $prefix|g"
sedscr="s|^PREFIX\ ?= .*$|PREFIX ?= $prefix|g"
ump_SED_ARGS+=( -e "$sedscr" )
}
############################
### EXECUTION BEGINS ###
############################
# Global variable for tracking total errors during calls to
# 'confirm_prerequisites' and 'update_makefile_prefix'.
# Makefile updates will not be performed unless TOTAL_ERRORS == 0"
declare -i TOTAL_ERRORS=0
# Global array variable that will be used as arguments to a
# 'sed' call for updating the Makefile with appropriate values.
# It will be set by 'setup_cjungmann_libs' for Makefile updates
# dictated by the global array CJUNGMANN_LIBS_NEEDED
declare -a MAKEFILE_SED_ARGS=()
# This will identify/warn about missing libraries, with advice
# on which package will remedy the omission:
if confirm_prerequisites && man_test; then
# Check for --prefix option, adding a sed script to update the
# Makefile PREFIX variable if specified
update_makefile_prefix MAKEFILE_SED_ARGS "$@"
# This checks only for github.com/cjungmann libraries, cloning and
# installing as static libraries under this project if the library
# is not installed globally:
setup_cjungmann_libs MAKEFILE_SED_ARGS
if [ "${#MAKEFILE_SED_ARGS[*]}" -gt 0 ]; then
echo "Updating the Makefile."
sed -i "${MAKEFILE_SED_ARGS[@]}" Makefile
else
echo "Nothing to do for Makefile."
fi
else
echo "Please correct the errors and rerun ./configure."
fi