This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
configure
executable file
·431 lines (375 loc) · 12.4 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
421
422
423
424
425
426
427
428
429
430
431
#!/bin/bash
SED=sed
export PKG_CONFIG_PATH="./build/lib/pkgconfig:$PKG_CONFIG_PATH"
arguments="$@"
has_arg() {
[ -n "`echo $arguments | grep "$1"`" ]
}
kern=`uname -s`
njobs=
mpv_args=
os=
mkspec=
if [ "$kern" = "Darwin" ]; then
os="osx"
mpv_args="$mpv_args --enable-coreaudio --enable-vda-hwaccel" #
njobs=`sysctl hw.ncpu | awk '{print $2}'`
mkspec=macx-clang
elif [ "$kern" = "Linux" ]; then
os="linux"
mpv_args="$mpv_args --enable-alsa --enable-oss-audio" # --enable-vaapi-hwaccel --enable-vdpau-hwaccel
njobs=$(nproc)
else
echo "Not supported!"
exit
fi
argument_line=
option_line=
key_max_cols=22
parse_for_key() {
local key=`echo $1 | cut -d "=" -sf1`
if [ -z "$key" ]; then
echo $1
else
echo $key
fi
}
parse_for_value() {
echo `echo $1 | cut -d "=" -sf2`
}
get_option_field() {
echo `echo $option_line | cut -d "|" -sf $1`
}
get_option_name() {
echo $(parse_for_key $(get_option_field $f_key))
}
get_feature_name() {
local name=$1
if ! [ $name ]; then name=$(get_option_name); fi
echo `echo $name | cut -d '-' -sf 4`
}
loop_options() {
while read line; do
option_line=$line
"${@:2}"
done <<-heredoc
$1
heredoc
}
print_help_option_one() {
local key=$(get_option_field $f_key)
if [ -z "$key" ]; then continue; fi
local def=$(get_option_field $f_def)
if [ -z "$def" ]; then
printf " %-${key_max_cols}s %s\n" $key "$(get_option_field $f_help)"
else
printf " %-${key_max_cols}s %s [%s]\n" $key "$(get_option_field $f_help)" "$(get_option_field $f_def)"
fi
}
print_help_options() {
printf "$1:\n"
loop_options "$2" print_help_option_one
printf "\n"
}
set_option_key_max_cols_one() {
local key=$(get_option_field $f_key)
if [ -z "$key" ]; then continue; fi
if [ $key_max_cols -lt ${#key} ]; then key_max_cols=${#key}; fi
}
print_help() {
printf "Usage: $0 [OPTIONS]...\n\n"
loop_options "$options" set_option_key_max_cols_one
print_help_options "Configuration" "$config_opts"
print_help_options "Installation directories" "$install_opts"
print_help_options "Optional features" "$feature_opts"
exit 0
}
########################################################################################################
########################################################################################################
f_key=1
f_help=2
f_def=3
f_pkg=4
parallel=$njobs
release=
qmake=
qtsdk=
macdeployqt=
mo() {
local value=$(eval echo \$$1)
}
config_opts="""
--help|display this help and exit
--qtsdk=QTSDK|directory for Qt SDK|
--qmake=QMAKE|qmake executable|$qmake
--mkspec=MKSPEC|make spec for qmake|$mkspec
--macdeployqt=MACDEPLOYQT|macdeployqt executable|QTSDK/bin/macdeployqt
--parallel=JOBS|count of parallel jobs|autodetect:$njobs
--release|optimize for release
--developer|configure for developers
"""
config=
setup_build() {
if ! has_arg "release"; then config="$config release"; fi
if [ -n "$qtsdk" ]; then
if [ -z "$qmake" ]; then qmake=$qtsdk/bin/qmake; fi
if [ -z "$macdeployqt" ]; then macdeployqt=$qtsdk/bin/macdeployqt; fi
fi
if [ -z "$qmake" ]; then qmake=qmake-qt5; fi
if [ -n "$mkspec" ]; then qmake="$qmake -spec $mkspec"; fi
}
prefix=/usr/local
bindir=
datadir=
icondir=
appdir=
actiondir=
skindir=
importdir=
install_opts="""
--prefix=PREFIX|prefix directory for installation|$prefix
--bindir=BINDIR|directory for executables|PREFIX/bin
--datadir=DATADIR|directory for architecture-indepentent files|PREFIX/share
--icondir=ICONDIR|directory for application icons|DATADIR/icons/hicolor
--appdir=APPDIR|directory for application launchers|DATADIR/applications
--actiondir=ACTIONDIR|directory for action launchers|DATADIR/apps/solid/actions
--skindir=SKINDIR|directory for skin files|DATADIR/cmplayer/skins
--importdir=IMPORTDIR|directory for QML files|DATADIR/cmplayer/imports
"""
setup_dirs() {
if [ -z "$prefix" ]; then exit; fi
if [ -z "$bindir" ]; then bindir=$prefix/bin; fi
if [ -z "$datadir" ]; then datadir=$prefix/share; fi
if [ -z "$icondir" ]; then icondir=$datadir/icons/hicolor; fi
if [ -z "$appdir" ]; then appdir=$datadir/applications; fi
if [ -z "$actiondir" ]; then actiondir=$datadir/apps/solid/actions; fi
if [ -z "$skindir" ]; then skindir=$datadir/cmplayer/skins; fi
if [ -z "$importdir" ]; then importdir=$datadir/cmplayer/imports; fi
}
jack=disable
portaudio=disable
pulseaudio=disable
quvi4=disable
cdda=disable
mf() { # make_feature
local value=$(eval echo \$$1)
local opt="disable"
if [ $value = "disable" ]; then opt="enable"
elif [ $value = "enable" ]; then opt="disable"; fi
local pkg=$3
if [ -z "$pkg" ]; then pkg=$1; fi
echo "--$opt-$1|$2|$value|$pkg"
}
feature_opts="""
$(mf jack "enable JACK support")
$(mf portaudio "enable PortAudio support" "portaudio-2.0")
$(mf pulseaudio "enable PulseAudio support" "libpulse")
$(mf quvi4 "enable libquvi4 instead of libquvi9" "libquvi")
$(mf cdda "enable CDDA support" "libcdio_paranoia libcdio libcdio_cdda")
"""
add_mpv() {
mpv_args="$mpv_args --$1-$2"
}
setup_features() {
add_mpv $jack jack
add_mpv $portaudio portaudio
add_mpv $pulseaudio pulse
add_mpv $cdda cdda
if [ $quvi4 = enable ]; then
add_mpv enable libquvi4
add_mpv disable libquvi9
else
add_mpv enable libquvi9
add_mpv disable libquvi4
fi
}
options="""
$config_opts
$install_opts
$feature_opts
"""
check_valid_option() {
arg=$1
local ok
local value
local var
local key=$(parse_for_key $arg)
if [ $key = "--help" ]; then print_help; fi
if [ `echo "$key" | grep "^\-\-enable\|disable\-"` ]; then
while read line; do
option_line=$line
local name=$(get_option_name)
if [ -z "$name" ]; then continue; fi
if [ $(get_feature_name $key) = $(get_feature_name $name) ]; then
var=$(echo "$key" | grep "\-\-enable\|disable\-" | sed -E 's/^--(enable|disable)-([a-zA-Z0-9]+)$/\2/g')
value=$(echo "$key" | grep "\-\-enable\|disable\-" | sed -E 's/^--(enable|disable)-([a-zA-Z0-9]+)$/\1/g')
ok="ok"
break;
fi
done <<-heredoc
$feature_opts
heredoc
else
while read line; do
option_line=$line
local name=$(get_option_name)
if [ -z $name ]; then continue; fi
if [ $key = $name ]; then
var=$(echo "$key" | sed -E 's/^--(.+)$/\1/g')
value=$(parse_for_value $arg)
local ph=$(parse_for_value $(get_option_field $f_key))
if [ -n "$ph" ]; then
if [ -z "$value" ]; then break; fi
ok="ok"
else
if [ -n "$value" ]; then break; fi
value="yes"
ok="ok"
fi
fi
done <<-heredoc
$config_opts
$install_opts
heredoc
fi
if [ -n "$ok" ]; then
eval $var="$value"
true
else
echo "'$arg' is not a vaild option."
print_help
false
fi
}
for arg in $@; do
check_valid_option $arg
done
########################################################################################################
########################################################################################################
cflags=
libs=
defines=
has_pkg() {
if `pkg-config --exists $1`; then
true
else
false
fi
}
err_pkg=
check_pkg() {
err_pkg=""
printf "Checking for $1 ... "
local pkgs
if [ "$#" = 1 ]; then
if has_pkg "$1"; then
pkgs="$1"
else
err_pkg="$1"
fi
else
for pkg in "${@:2}"; do
if has_pkg "$pkg"; then
pkgs="$pkgs $pkg"
else
err_pkg="$pkg"
break
fi
done
fi
if [ -z "$err_pkg" ]; then
cflags="$cflags `pkg-config --cflags $pkgs`"
libs="$libs `pkg-config --libs $pkgs`"
printf "yes\n"
true
else
printf "no\n"
false
fi
}
check_pkg_or_exit() {
if ! check_pkg "$@"; then
printf "'$err_pkg' package was not found.\n"
exit
fi
true
}
if has_arg "developer"; then
if [ "$os" = "linux" ]; then
jack=enable
portaudio=enable
pulseaudio=enable
cdda=enable
elif [ "$os" = "osx" ]; then
qtsdk=/usr/local/opt/qt5
macdeployqt=macdeployqt
quvi4=enable
qmake=qmake
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/libass-ct/lib/pkgconfig:${PKG_CONFIG_PATH}"
fi
fi
check_pkg_or_exit ffmpeg "libavformat >= 55.12.0" "libavutil >= 52.48.101" "libavcodec >= 55.34.1" "libswresample" "libswscale" "libavfilter" "libpostproc"
check_pkg_or_exit "libmpg123"
check_pkg_or_exit "libass"
check_pkg_or_exit "dvdread"
check_pkg_or_exit "dvdnav"
check_pkg_or_exit "libbluray"
check_pkg_or_exit "icu-uc"
check_pkg_or_exit "chardet"
if [ $os = "linux" ]; then
check_pkg_or_exit glib "glib-2.0" "gobject-2.0"
check_pkg_or_exit "vaapi" "libva" "libva-glx" "libva-x11"
check_pkg_or_exit "vdpau"
check_pkg_or_exit xcb "xcb" "xcb-icccm" "x11"
check_pkg_or_exit "alsa"
fi
if ! [ "$quvi4" = "enable" ] ; then
check_pkg_or_exit "libquvi-0.9"
fi
add_defines() {
defines="$defines $1=$2"
}
check_feature_one() {
local var=$(get_feature_name)
local pkg=$(get_option_field $f_pkg)
local value=$(eval echo \$$var)
if [ -z $var ]; then continue; fi
if [ $value = enable ]; then
check_pkg_or_exit "$pkg"
elif [ $value = autodetect ]; then
if check_pkg "$pkg"; then
eval $var="enable"
else
eval $var="disable"
fi
fi
if [ $value = enable ]; then
add_defines HAVE_$var 1
else
add_defines HAVE_$var 0
fi
}
loop_options "$feature_opts" check_feature_one
defines=$(echo "$defines" | tr "[:lower:]" "[:upper:]")
setup_dirs
setup_features
setup_build
add_defines CMPLAYER_SKINS_PATH \\\\\\\\\\\\\\\"$skindir\\\\\\\\\\\\\\\"
add_defines CMPLAYER_IMPORTS_PATH \\\\\\\\\\\\\\\"$importdir\\\\\\\\\\\\\\\"
if has_arg release ; then defines="$defines CMPLAYER_RELEASE"; fi
parse_file() {
cp $1.in $1
local var
local sed="sed -i"
if [ "$os" = "osx" ]; then sed="sed -i .conf.bk -e"; fi
for token in "${@:2}"; do
var=$(eval echo \$$token)
$sed 's#@'"$token"'@#'"$var"'#g' $1
done
}
parse_file "src/cmplayer/configure.pro" defines config libs cflags
parse_file "Makefile" os qmake PKG_CONFIG_PATH prefix bindir datadir icondir appdir actiondir \
skindir importdir parallel qtsdk macdeployqt
parse_file "build-mpv" mpv_args parallel os njobs PKG_CONFIG_PATH
chmod +x build-mpv
printf "\nCMPlayer has been configured successfully!\n\n"