-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure
executable file
·420 lines (366 loc) · 11.9 KB
/
configure
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/bin/bash
#########################################################
# #
# This is BashStyle-NG #
# #
# Licensed under GNU GENERAL PUBLIC LICENSE v3 #
# #
# Copyright Christopher Roy Bratušek #
# #
#########################################################
##############################
# Setup
##############################
shopt -s extglob
TOP_PID=$$
CWD=$(dirname "$(readlink -m "${BASH_SOURCE[0]}")")
source "${CWD}/.settings"
CFG_VERSION="4.5.1"
CFG_RESULTS="${CWD}/.configure_results"
if [[ -d "/usr/lib/girepository-1.0/" ]]; then
GIRPATH="/usr/lib/girepository-1.0"
elif [[ -d "/usr/lib64/girepository-1.0/" ]]; then
GIRPATH="/usr/lib64/girepository-1.0"
elif [[ -d "/usr/share/gir-1.0/" ]]; then
GIRPATH="/usr/share/gir-1.0"
else
missing_girpath_message
fi
PREFIX="/usr"
BINDIR="${PREFIX}/bin"
PCDIR="${PREFIX}/share/pkgconfig"
DATADIR="${PREFIX}/share"
DOCDIR="${DATADIR}/doc"
MANDIR="${DATADIR}/man"
PYTHON=$(command -v python3 || command -v python)
PYMINVER_P=">=3.x"
PYMAXVER_P="<=4.x"
PYMINVER=3
PYMAXVER=4
DISABLE_POSTINSTALL=0
for lang in "${APP_LANGUAGES[@]}"; do
LC_MESSAGES_DIRS+="${lang}/LC_MESSAGES"
done
PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
rm -f "${CWD}/.configure_results"
##############################
# Color Settings
##############################
set_colors () {
RED="\033[01;31m"
GREEN="\033[01;32m"
YELLOW="\033[01;33m"
BLUE="\033[01;34m"
MAGENTA="\033[01;35m"
CYAN="\033[01;36m"
WHITE="\033[01;37m"
case ${TERM} in
*xterm*color )
ORANGE="\033[01;38;5;202m"
SILVER="\033[01;38;5;246m"
;;
* )
ORANGE=${YELLOW}
SILVER=${WHITE}
;;
esac
}
##############################
# Screen messages
##############################
section_message () {
case ${1} in
APP ) echo -e "\n${RED}< Required ${WHITE}Applications" ;;
OPT_APP ) echo -e "\n${MAGENTA}< Optional ${WHITE}Applications" ;;
SBINAPP ) echo -e "\n${RED}< Required ${WHITE}SuperUser Applications" ;;
OPT_SBINAPP ) echo -e "\n${MAGENTA}< Optional ${WHITE}SuperUser Applications" ;;
BUILD ) echo -e "\n${RED}< Required ${WHITE}Build Tools" ;;
OPT_BUILD ) echo -e "\n${MAGENTA}< Optional ${WHITE}Build Tools" ;;
PY ) echo -e "\n${RED}< Python Interpreter${WHITE} ${PYMINVER_P} && ${PYMAXVER_P}" ;;
PYMOD ) echo -e "\n${RED}< Required ${WHITE}Python Modules" ;;
OPT_PYMOD ) echo -e "\n${MAGENTA}< Optional ${WHITE}Python Modules" ;;
LIB ) echo -e "\n${RED}< Required ${WHITE}Libraries" ;;
OPT_LIB ) echo -e "\n${MAGENTA}< Optional ${WHITE}Libraries" ;;
GIR ) echo -e "\n${RED}< Required ${WHITE}GIR Repositories" ;;
OPT_GIR ) echo -e "\n${MAGENTA}< Optional ${WHITE}GIR Repositories" ;;
esac
tput sgr0
}
start_message () {
echo -e "\n${WHITE}Configuring ${GREEN}${APP_NAME}${YELLOW} v${APP_VERSION} ${CYAN}(${APP_CODENAME})"
tput sgr0
}
ok_message () {
if [[ -n ${2} ]]; then
echo -e "${WHITE}\t+ ${CYAN}${1}${MAGENTA} >${GREEN} OK${SILVER} ( ${2} )"
else echo -e "${WHITE}\t+ ${CYAN}${1}${MAGENTA} >${GREEN} OK"
fi
tput sgr0
}
fail_message () {
case ${1} in
m ) echo -e "${WHITE}\t+ ${CYAN}${2}${MAGENTA} >${RED} !MISSING!" ;;
o ) echo -e "${WHITE}\t+ ${CYAN}${2}${MAGENTA} >${RED} !OLDER THAN ${3}!" ;;
p ) echo -e "${WHITE}\t+ ${CYAN}Python ($PYTHON)${MAGENTA} >${RED} !MISSING!" ;;
p- ) echo -e "${WHITE}\t+ ${CYAN}Python ($PYTHON)${MAGENTA} >${RED} !OLDER THAN ${PYMINVER_P}!" ;;
p+ ) echo -e "${WHITE}\t+ ${CYAN}Python ($PYTHON)${MAGENTA} >${RED} !IS ${PYMAXVER_P} OR ABOVE!" ;;
esac
tput sgr0
}
warn_message () {
echo -e "${WHITE}\t+ ${CYAN}${1}${MAGENTA} >${YELLOW} Not Available\
\n\t > ${WHITE}${2}"
tput sgr0
}
end_message () {
echo -e "\n${BLUE}Notes from configure:\
\n${YELLOW}Prefix\t\t\t${WHITE}>${MAGENTA} ${PREFIX}\
\n${YELLOW}Python\t\t\t${WHITE}>${MAGENTA} ${PYTHON}"
if [ "${DISABLE_POSTINSTALL}" -eq 1 ]; then
echo -e "${YELLOW}Post-Install Tasks\t${WHITE}>${RED} Disabled"
else echo -e "${YELLOW}Post-Install Tasks\t${WHITE}>${GREEN} Enabled"
fi
echo -e "\n\t${SILVER}You may want to continue with './make build'.\n"
tput sgr0
}
help_message () {
set_colors
echo -e "\n${GREEN}${APP_NAME} ${MAGENTA}v${APP_VERSION}${WHITE} / ${YELLOW}Configure v${CFG_VERSION} ${CYAN}help
\n${WHITE}Options:"
echo -e " ${ORANGE}--help${WHITE} *|${GREEN} Display this help message
${ORANGE}--prefix=<prefix>${WHITE} *|${GREEN} Change installation prefix${WHITE} *|${BLUE} default: /usr
${ORANGE}--bindir=<bindir>${WHITE} *|${GREEN} Change binary path${WHITE} *|${BLUE} default: /usr/bin
${ORANGE}--docdir=<docdir>${WHITE} *|${GREEN} Change doc path${WHITE} *|${BLUE} default: /usr/share/doc
${ORANGE}--mandir=<mandir>${WHITE} *|${GREEN} Change man path${WHITE} *|${BLUE} default: /usr/share/man
${ORANGE}--datadir=<datadir>${WHITE} *|${GREEN} Change data path${WHITE} *|${BLUE} default: /usr/share
${ORANGE}--pcdir=<pcdir>${WHITE} *|${GREEN} Change pkg-config path${WHITE} *|${BLUE} default: /usr/share/pkgconfig
${ORANGE}--girpath=<girpath>${WHITE} *|${GREEN} Where to look for G-I typelibs${WHITE} *|${BLUE} default: /usr/lib/girepository-1.0
${ORANGE}--python=<python>${WHITE} *|${GREEN} Use specific Python interpreter${WHITE} *|${BLUE} default: /usr/bin/python3
${ORANGE}--no-postinstall${WHITE} *|${GREEN} Disable post-installation tasks${WHITE} *|${BLUE} for package-maintainers" | column -t -s \*
echo
tput sgr0
exit 0
}
missing_girpath_message () {
echo -e "${RED}*** GIRPATH not detected ***${WHITE}
configure --girpath=<girpath> to specify where to look for gobject-introspection files\n"
tput sgr0
exit 1
}
##############################
# Dependency checks
##############################
check () {
for dir in ${PATH//:/ }; do
if [ -x "${dir}/${1}" ]; then
echo found
continue 2
fi
done
}
check_helper () {
[[ "${BUILD[*]}" ]] && (section_message BUILD && check_apps "false" "${BUILD[@]}")
[[ "${OPT_BUILD[*]}" ]] && (section_message OPT_BUILD && check_apps "true" "${OPT_BUILD[@]}")
[[ "${APPS[*]}" ]] && (section_message APP && check_apps "false" "${APPS[@]}")
[[ "${OPT_APPS[*]}" ]] && (section_message OPT_APP && check_apps "true" "${OPT_APPS[@]}")
[[ "${SAPPS[*]}" ]] && (section_message SBINAPP && check_apps "false" "${SAPPS[@]}")
[[ "${OPT_SAPPS[*]}" ]] && (section_message OPT_SBINAPP && check_apps "true" "${OPT_SAPPS[@]}")
[[ "${PYMODS[*]}" ]] && check_python
[[ "${PYMODS[*]}" ]] && (section_message PYMOD && check_pymods "false" "${PYMODS[@]}")
[[ "${OPT_PYMODS[*]}" ]] && (section_message OPT_PYMOD && check_pymods "true" "${OPT_PYMODS[@]}")
[[ "${LIBS[*]}" ]] && (section_message LIB && check_libs "false" "${LIBS[@]}")
[[ "${OPT_LIBS[*]}" ]] && (section_message OPT_LIB && check_libs "false" "${OPT_LIBS[@]}")
[[ "${GIR[*]}" ]] && (section_message GIR && check_gir "false" "${GIR[@]}")
[[ "${OPT_GIR[*]}" ]] && (section_message OPT_GIR && check_gir "false" "${OPT_GIR[@]}")
}
check_apps () {
OPT=${1}
shift
for ARG in "${@}"; do
APP=$(gawk -F : '{print $1}' <(echo "${ARG}"))
DESC=$(gawk -F : '{print $2}' <(echo "${ARG}"))
APP2=$(gawk -F : '{print $3}' <(echo "${ARG}"))
[[ ${APP2} ]] && APP2_P="(${APP2})" || APP2_P=""
DEP_RETURN=$(check "${APP}")
DEP_RETURN2=$(check "${APP2}")
if [[ ${DEP_RETURN} == *found* || ${DEP_RETURN2} == *found* ]]; then
ok_message "${APP} ${APP2_P}"
elif [[ (${DEP_RETURN} != *found* && ${DEP_RETURN2} != *found*) && ${OPT} == true ]]; then
warn_message "${APP} ${APP2_P}" "${DESC}"
MISSING+=" ${APP}"
else
fail_message m "${APP} ${APP2_P}"
kill -s TERM "${TOP_PID}"
fi
done
}
check_libs () {
OPT=${1}
shift
for ARG in "${@}"; do
LIB=$(gawk -F : '{print $1}' <(echo "${ARG}"))
VERSION=$(gawk -F : '{print $2}' <(echo "${ARG}"))
PC_FILE=$(gawk -F : '{print $3}' <(echo "${ARG}"))
DESC=$(gawk -F : '{print $4}' <(echo "${ARG}"))
pkg-config --exists "${PC_FILE}"
EXIST_RETURN=$?
pkg-config --atleast-version="${VERSION}" "${PC_FILE}"
DEP_RETURN=$?
if [[ ${EXIST_RETURN} != 0 && ! ${OPT} == true ]]; then
fail_message m "${LIB}"
kill -s TERM "${TOP_PID}"
elif [[ ${DEP_RETURN} == 0 ]]; then
ok_message "${LIB}" "${VERSION}"+
elif [[ ${EXIST_RETURN} != 0 && ${OPT} == true ]]; then
warn_message "${LIB}" "${DESC}"
MISSING+=" ${LIB}"
else
fail_message o "${LIB}" "${VERSION}"
kill -s TERM "${TOP_PID}"
fi
done
}
check_gir () {
OPT=${1}
shift
for ARG in "${@}"; do
GIR_NAME=$(gawk -F : '{print $1}' <(echo "${ARG}"))
VERSION=$(gawk -F : '{print $2}' <(echo "${ARG}"))
TYPE_LIB=$(gawk -F : '{print $3}' <(echo "${ARG}"))
DESC=$(gawk -F : '{print $4}' <(echo "${ARG}"))
FILE=$(basename "${GIRPATH}"/"${TYPE_LIB}"* .typelib 2>/dev/null)
if [[ ${FILE} != ".typelib" ]]; then
EXIST_RETURN=0
XVER=$(gawk -F - '{print $2}' <(echo "${FILE}"))
DEP_RETURN=$(echo "$XVER >= ${VERSION}" | bc)
fi
if [[ ${EXIST_RETURN} != 0 && ! ${OPT} == true ]]; then
fail_message m "${GIR_NAME}"
kill -s TERM "${TOP_PID}"
elif [[ ${DEP_RETURN} == 1 ]]; then
ok_message "${GIR_NAME}" "${VERSION}"+
elif [[ ${EXIST_RETURN} != 0 && ${OPT} == true ]]; then
warn_message "${GIR_NAME}" "${DESC}"
MISSING+=" ${GIR_NAME}"
else
fail_message o "${GIR_NAME}" "${VERSION}"
kill -s TERM "${TOP_PID}"
fi
done
}
check_python () {
section_message PY
if [[ ! -x ${PYTHON} ]]; then
fail_message p
kill -s TERM "${TOP_PID}"
else
PYVER=$(${PYTHON} --version 2>&1)
PYVER_C="${PYVER//@(*\ |\.|\+)}"
if [[ ${PYVER_C:0:1} -lt ${PYMINVER} ]]; then
fail_message p-
kill -s TERM "${TOP_PID}"
elif [[ ${PYVER_C:0:1} -ge ${PYMAXVER} ]]; then
fail_message p+
kill -s TERM "${TOP_PID}"
else
ok_message Python "${PYVER}"
fi
fi
}
check_pymods () {
OPT=${1}
shift
for ARG in "${@}"; do
MOD=$(gawk -F : '{print $1}' <(echo "${ARG}"))
SMOD=$(gawk -F : '{print $2}' <(echo "${ARG}"))
DESC=$(gawk -F : '{print $3}' <(echo "${ARG}"))
case ${MOD} in
gi.repository.Gtk )
${PYTHON} -c "import gi
gi.require_version('Gtk', '${SMOD}')
import ${MOD}"
;;
* )
${PYTHON} -c "import ${MOD}" 2>/dev/null
;;
esac
[[ ${SMOD} ]] && DEP="${MOD} (${SMOD})" || DEP="${MOD}"
DEP_RETURN=$?
if [[ ${DEP_RETURN} == 0 ]]; then
ok_message "${DEP}"
elif [[ ${DEP_RETURN} != 0 && ${OPT} == true ]]; then
warn_message "${DEP}" "${DESC}"
MISSING+=" ${DEP}"
else fail_message m "${DEP}"
kill -s TERM "${TOP_PID}"
fi
done
}
##############################
# Variable substitution
##############################
copy_in_files () {
for in_file in "${IN_FILES[@]}"; do
cp "${in_file}".in "${in_file}"
done
}
substitute_values () {
sed -e "s>@VERSION@>${APP_VERSION}>g" \
-e "s>@PREFIX@>${PREFIX}>g" \
-e "s>@CODENAME@>${APP_CODENAME}>g" \
-e "s>@DATADIR@>${DATADIR}>g" \
-e "s>@PYTHON@>${PYTHON}>g" \
-e "s>@BSNG_YEAR@>${APP_YEAR}>g" \
-i "${IN_FILES[@]}"
}
##############################
# Export results
##############################
export_result ()
{
echo -e "PREFIX=\"${PREFIX}\"
prefix=\"${PREFIX}\"
EXECDIR=\"${EXECDIR}\"
DATADIR=\"${DATADIR}/bashstyle-ng\"
DATADIR_LIST=(ui rc)
DOCDIR=\"${DOCDIR}/bashstyle-ng\"
MANDIR=\"${MANDIR}/man1\"
BINDIR=\"${BINDIR}\"
LOCALEDIR=\"${DATADIR}/locale\"
LOCALEDIR_LIST=(${LC_MESSAGES_DIRS})
ICONDIR=\"${DATADIR}/icons/hicolor/32x32/apps\"
DESKTOPDIR=\"${DATADIR}/applications\"
PCDIR=\"${PCDIR}\"
APP_LANGUAGES=\"${APP_LANGUAGES}\"
DISABLE_POSTINSTALL=${DISABLE_POSTINSTALL}" \
> "${CFG_RESULTS}"
}
##############################
# Main Loop
##############################
for opt in "${@}"; do
case ${opt} in
--prefix=* ) PREFIX="${opt/*=}" ;;
--pcdir=* ) PCDIR="${opt/*=}" ;;
--bindir=* ) BINDIR="${opt/*=}" ;;
--docdir=* ) DOCDIR="${opt/*=}" ;;
--mandir=* ) MANDIR="${opt/*=}" ;;
--girpath=* ) GIRPATH="${opt/*=}" ;;
--datadir=* ) DATADIR="${opt/*=}" ;;
--python=* ) PYTHON="${opt/*=}" ;;
--help | -h ) help_message ;;
--no-postinstall ) DISABLE_POSTINSTALL=1 ;;
* ) echo "unknown option: ${opt}" ;;
esac
shift
done
##############################
# Do stuff
##############################
set_colors
start_message
check_helper
copy_in_files
substitute_values
end_message
export_result