-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathbootStrapCrossMingwQt5_mxe.sh
425 lines (395 loc) · 11.7 KB
/
bootStrapCrossMingwQt5_mxe.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
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
#!/bin/bash
# Default config
bits=64
default_mxerootdir="/opt/mxe"
mxerootdir="$default_mxerootdir"
rebuild=0
debug=0
do_core=1
do_qt=1
do_cli=1
do_plugins=1
external_liba52=0
external_libmad=0
do_release_pkg=1
author_setup=0
# Functions
authorSetup()
{
export SDLDIR=/mingw
export MINGW=/mingw
export MINGWDEV=/mingw_dev
export PATH=${MINGW}/bin:$PATH
export INSTALL_DIR=${MINGW}/Release
export QT_HOME=/mingw/Qt/current
export O_PARAL="-j 2"
export TOOLCHAIN_LOCATION=/mingw
export CFLAGS="-I/mingw/include -L/mingw/lib"
}
setupEnv()
{
export BUILDDATE=$(date +%y%m%d-%H%M%S)
if [ "x$external_liba52" = "x1" ]; then
export EXTRA_CMAKE_DEFS="-DUSE_EXTERNAL_LIBA52=true $EXTRA_CMAKE_DEFS"
fi
if [ "x$external_libmad" = "x1" ]; then
export EXTRA_CMAKE_DEFS="-DUSE_EXTERNAL_LIBMAD=true $EXTRA_CMAKE_DEFS"
fi
export BUILDTOP=$PWD
if [[ $BUILDTOP = *" "* ]]; then
echo "The build directory path \"${BUILDTOP}\" contains one or more spaces."
echo "This is unsupported by FFmpeg configure."
fail "build prerequisites"
fi
export SRCTOP=$(cd $(dirname "$0") && pwd)
export BITS=$bits
if [ "x$BITS" = "x64" ]; then
export ARCH="x86_64"
else
export ARCH="i686"
fi
export MXE_ROOT="$mxerootdir"
export MXE_TARGET=${ARCH}-w64-mingw32.shared
export QT_SELECT=5
if [ "x$author_setup" = "x1" ]; then
authorSetup
else
export MINGW="${MXE_ROOT}/usr/${MXE_TARGET}"
export QT_HOME="${MINGW}"/qt5
export PATH="$PATH":"${MXE_ROOT}"/usr/bin:"${QT_HOME}"/bin
export TOOLCHAIN_LOCATION="${MXE_ROOT}"/usr
export SDL2DIR="$MINGW"
PARAL="-j $(nproc)"
if [ "x$debug" != "x1" ]; then
export INSTALL_DIR="${MINGW}"/out/avidemux
else
export INSTALL_DIR="${MINGW}"/out_debug/avidemux
fi
fi
export CROSS_PREFIX=$MXE_TARGET
export PKG_CONFIG_PATH="${MINGW}"/lib/pkgconfig
export PKG_CONFIG_LIBDIR="${MINGW}"/lib/pkgconfig
export CXXFLAGS="-std=c++11"
export CROSS_C_COMPILER=gcc
export CROSS_CXX_COMPILER=g++
}
fail()
{
echo "** Failed at $1 **"
exit 1
}
Process()
{
BASE=$1
SOURCEDIR=$2
EXTRA=$3
GENERATOR="Unix Makefiles"
if [ "x$debug" = "x1" ]; then
DEBUG="-DVERBOSE=1 -DCMAKE_BUILD_TYPE=Debug"
BASE="${BASE}_debug"
GENERATOR="CodeBlocks - Unix Makefiles"
fi
BUILDDIR="${PWD}/${BASE}"
echo "Building in \"${BUILDDIR}\" from \"${SOURCEDIR}\" with EXTRA=<${EXTRA}>)"
if [ "x$rebuild" != "x1" ]; then
rm -Rf "$BUILDDIR"
fi
if [ ! -e "$BUILDDIR" ]; then
mkdir "$BUILDDIR" || fail "creating build directory"
fi
pushd "$BUILDDIR" > /dev/null
cmake -DCROSS="$MINGW" \
-DCMAKE_SYSTEM_NAME:STRING=Windows \
-DCMAKE_FIND_ROOT_PATH="$MINGW" \
-DTOOLCHAIN_LOCATION="$TOOLCHAIN_LOCATION" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER:STRING="${CROSS_PREFIX}-${CROSS_C_COMPILER}" \
-DCMAKE_CXX_COMPILER:STRING="${CROSS_PREFIX}-${CROSS_CXX_COMPILER}" \
-DCMAKE_LINKER:STRING="${CROSS_PREFIX}-ld" \
-DCMAKE_AR:STRING="${CROSS_PREFIX}-ar" \
-DCMAKE_RC_COMPILER:STRING="${CROSS_PREFIX}-windres" \
-DAVIDEMUX_TOP_SOURCE_DIR:STRING="$SRCTOP" \
${DEBUG} \
-G "${GENERATOR}" \
$EXTRA \
"$SOURCEDIR" || fail "cmake"
make $PARAL >& /tmp/log$BASE || fail "make, result in /tmp/log$BASE"
make install || fail "install"
# Only install component=dev for dev package
if [ "x$author_setup" = "x1" ]; then
DESTDIR=${MINGWDEV} cmake -DCOMPONENT=dev -P cmake_install.cmake || fail make_install_dev
fi
popd > /dev/null
}
usage()
{
echo "Usage: bash $0 [OPTION]"
echo " --help : Print usage"
echo " --32 : Build a 32 bit application"
echo " --64 : Build a 64 bit application (default)"
echo " --debug : Switch debugging on"
echo " --mxe-root=DIR : Use MXE installed in DIR (default: ${default_mxerootdir})"
echo " --rebuild : Preserve existing build directories"
echo " --with-core : Build core (default)"
echo " --without-core : Don't build core"
echo " --with-cli : Build cli (default)"
echo " --without-cli : Don't build cli application and plugins"
echo " --with-qt : Build Qt (default)"
echo " --without-qt : Don't build Qt application and plugins"
echo " --with-plugins : Build plugins (default)"
echo " --without-plugins : Don't build plugins"
echo " --with-system-liba52 : Use the system liba52 (a52dec) instead of the bundled one"
echo " --with-system-libmad : Use the system libmad instead of the bundled one"
echo " --nopkg : Don't create a ZIP archive with all required libraries"
echo " -a, --author : Match the env setup used by the Author, implies --nopkg"
}
option_value()
{
echo $(echo $* | cut -d '=' -f 2-)
}
option_name()
{
echo $(echo $* | cut -d '=' -f 1 | cut -b 3-)
}
dir_check()
{
op_name="$1"
dir_path="$2"
if [ "x$dir_path" != "x" ] ; then
if [[ "$dir_path" != /* ]] ; then
>&2 echo "Expected an absolute path for --$op_name=$dir_path, aborting."
exit 1
fi
else
>&2 echo "Empty path provided for --$op_name, aborting."
exit 1
fi
case "$dir_path" in
*/)
echo $(expr "x$dir_path" : 'x\(.*[^/]\)') # strip trailing slashes
;;
*)
echo "$dir_path"
;;
esac
}
create_release_package()
{
if [ ! -e "${INSTALL_DIR}"/avidemux.exe ]; then
echo "No avidemux.exe (${BITS} bit) found in ${INSTALL_DIR}, aborting"
exit 1
fi
echo "Preparing package..."
pushd "$BUILDTOP" > /dev/null
PACKAGE_DIR="packaged_mingw_build_${BUILDDATE}"
if [ "x$debug" = "x1" ]; then
PACKAGE_DIR="packaged_mingw_debug_build_${BUILDDATE}"
fi
PACKAGE_DIR="${BUILDTOP}/${PACKAGE_DIR}"
if [ ! -e "$PACKAGE_DIR" ]; then
mkdir "$PACKAGE_DIR" || fail "creating package directory"
fi
cp -a "$INSTALL_DIR" "$PACKAGE_DIR"
cd "$PACKAGE_DIR"
mv -v avidemux avidemux_$BITS
TARGETDIR="${PACKAGE_DIR}/avidemux_$BITS"
if [ ! -e "${TARGETDIR}"/platforms ]; then
mkdir "${TARGETDIR}"/platforms || fail "creating platforms directory"
fi
if [ ! -e "${TARGETDIR}"/styles ]; then
mkdir "${TARGETDIR}"/styles || fail "creating styles directory"
fi
cd "${MINGW}"/bin
if [ "x${external_liba52}" = "x1" ]; then
cp -v liba52-*.dll "$TARGETDIR"
fi
if [ "x${external_libmad}" = "x1" ]; then
cp -v libmad-*.dll "$TARGETDIR"
fi
cp -v \
libaom.dll \
libass-*.dll \
libbrotlicommon.dll \
libbrotlidec.dll \
libbz2.dll \
libcrypto-*.dll \
libexpat-*.dll \
libfaad-*.dll \
libfdk-aac-*.dll \
libffi-*.dll \
libfontconfig-*.dll \
libfreetype-*.dll \
libfribidi-*.dll \
libgcc_*.dll \
libglib-*.dll \
libgobject-*.dll \
libharfbuzz-0.dll \
libiconv-*.dll \
icudt*.dll \
icuin*.dll \
icuuc*.dll \
libintl-*.dll \
libmp3lame-*.dll \
libogg-*.dll \
libopus-*.dll \
libpcre2-16-*.dll \
libpcre2-8-*.dll \
libpng16-*.dll \
libsamplerate-*.dll \
libsqlite3-*.dll \
libssl-*.dll \
libssp-*.dll \
libstdc++-*.dll \
libvorbis-*.dll \
libvorbisenc-*.dll \
libvorbisfile-*.dll \
libwinpthread-*.dll \
libx264-*.dll \
libx265.dll \
libzstd.dll \
SDL2.dll \
xvidcore.dll \
zlib1.dll \
"$TARGETDIR";
cd "$QT_HOME"
cp -v \
bin/Qt5Core.dll \
bin/Qt5Gui.dll \
bin/Qt5Network.dll \
bin/Qt5Widgets.dll \
bin/Qt5WinExtras.dll \
"$TARGETDIR";
cp -v \
plugins/platforms/qminimal.dll \
plugins/platforms/qwindows.dll \
"${TARGETDIR}"/platforms/;
cp -v \
plugins/styles/qwindowsvistastyle.dll \
"${TARGETDIR}"/styles/;
mkdir "${TARGETDIR}"/etc || fail "creating etc directory"
cp -rvL "${MINGW}"/etc/fonts "${TARGETDIR}"/etc
cd "$TARGETDIR"
if [ ! "x$debug" = "x1" ]; then
find . -name "*.dll.a" -exec rm -v '{}' \;
rm -Rf include
fi
cd "$PACKAGE_DIR"
zip -r avidemux_r${BUILDDATE}_win${BITS}Qt5.zip avidemux_$BITS
rm -Rf avidemux_$BITS
popd > /dev/null
echo "Avidemux Windows package generated as \"${PACKAGE_DIR}/avidemux_r${BUILDDATE}_win${BITS}Qt5.zip\""
}
# Options handling
while [ $# != 0 ]; do
config_option="$1"
case "$config_option" in
-h|--help)
usage
exit 1
;;
--32)
bits=32
;;
--64)
bits=64
;;
-a|--author)
export author_setup=1
do_release_pkg=0
;;
--mxe-root=*)
mxerootdir=$(dir_check $(option_name "$config_option") $(option_value "$config_option")) || exit 1
;;
--debug)
debug=1
;;
--rebuild)
rebuild=1
;;
--without-qt)
do_qt=0
;;
--without-cli)
do_cli=0
;;
--without-plugins)
do_plugins=0
;;
--without-core)
do_core=0
;;
--with-qt)
do_qt=1
;;
--with-cli)
do_cli=1
;;
--with-plugins)
do_plugins=1
;;
--with-core)
do_core=1
;;
--with-system-liba52)
export external_liba52=1
;;
--with-system-libmad)
export external_libmad=1
;;
--nopkg)
do_release_pkg=0
;;
*)
echo "unknown parameter $config_option"
usage
exit 1
;;
esac
shift
done
# Set all the required paths and env variables
setupEnv
# Create destination directory
echo "** Bootstrapping Avidemux **"
if [ "x$author_setup" = "x1" ]; then
rm -Rf "${MINGWDEV}"/*
fi
if [ -e "$INSTALL_DIR" -a "x$do_core" = "x1" -a "x$do_qt" = "x1" ]; then
rm -Rf "$INSTALL_DIR";
fi
mkdir -p "$INSTALL_DIR"
echo "Build top dir : $BUILDTOP"
# Build and install Avidemux components to the destination dir
if [ "x$do_core" = "x1" ]; then
echo "** CORE **"
Process buildMingwCore-${ARCH} "${SRCTOP}"/avidemux_core "-DCMAKE_CROSS_PREFIX=${CROSS_PREFIX}"
fi
if [ "x$do_qt" = "x1" ]; then
echo "** QT **"
Process buildMingwQt5-${ARCH} "${SRCTOP}"/avidemux/qt4 "-DQT_HOME:STRING=${QT_HOME} -DENABLE_QT5=true"
fi
if [ "x$do_cli" = "x1" ]; then
echo "** CLI **"
Process buildMingwCli-${ARCH} "${SRCTOP}"/avidemux/cli
fi
if [ "x$do_plugins" = "x1" ]; then
echo "** Plugins **"
Process buildMingwPluginsCommon-${ARCH} "${SRCTOP}"/avidemux_plugins "-DPLUGIN_UI=COMMON $EXTRA_CMAKE_DEFS"
fi
if [ "x$do_plugins" = "x1" -a "x$do_qt" = "x1" ]; then
echo "** Plugins Qt **"
Process buildMingwPluginsQt5-${ARCH} "${SRCTOP}"/avidemux_plugins "-DPLUGIN_UI=QT4 -DQT_HOME:STRING=$QT_HOME -DENABLE_QT5=true $EXTRA_CMAKE_DEFS"
fi
if [ "x$do_plugins" = "x1" -a "x$do_cli" = "x1" ]; then
echo "** Plugins CLI **"
Process buildMingwPluginsCli-${ARCH} "${SRCTOP}"/avidemux_plugins "-DPLUGIN_UI=CLI $EXTRA_CMAKE_DEFS"
fi
if [ "x$do_plugins" = "x1" ]; then
echo "** Plugins Settings **"
Process buildMingwPluginsSettings-${ARCH} "${SRCTOP}"/avidemux_plugins "-DPLUGIN_UI=SETTINGS $EXTRA_CMAKE_DEFS"
fi
# Create a ZIP archive with avidemux and all the required libs
if [ "x$do_release_pkg" = "x1" ]; then
create_release_package
fi
echo "** All done **"