/
cross_compile_ffmpeg_shared.sh
executable file
·5984 lines (5322 loc) · 256 KB
/
cross_compile_ffmpeg_shared.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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# set -x
# ffmpeg windows cross compile helper/download script
# Copyright (C) 2014 Roger Pack, the script is under the GPLv3, but output FFmpeg's aren't necessarily
# with modifications by John Warburton john@johnwarburton.com
#Gnulib
# 1. Check it out separately
# 2.
#Gnu Coreutils
# 1. Remove configure test for mounted file system list
# 2. Set -Werror inactive
yes_no_sel () {
unset user_input
local question="$1"
shift
local default_answer="$1"
while [[ "$user_input" != [YyNn] ]]; do
echo -n "$question"
read user_input
if [[ -z "$user_input" ]]; then
echo "using default $default_answer"
user_input=$default_answer
fi
if [[ "$user_input" != [YyNn] ]]; then
clear; echo 'Your selection was not vaild, please try again.'; echo
fi
done
# downcase it
user_input=$(echo $user_input | tr '[A-Z]' '[a-z]')
}
check_missing_packages () {
local check_packages=('cmp' 'bzip2' 'rsync' 'sshpass' 'curl' 'pkg-config' 'make' 'gettext' 'git' 'svn' 'cmake' 'gcc' 'autoconf' 'libtool' 'automake' 'yasm' 'cvs' 'flex' 'bison' 'makeinfo' 'g++' 'ed' 'hg' 'patch' 'pax' 'bzr' 'gperf' 'ruby' 'doxygen' 'asciidoc' 'xsltproc' 'autogen' 'rake' 'autopoint' 'pxz' 'wget' 'zip' 'xmlto' 'gtkdocize' 'python-config' 'ant' 'sdl-config' 'sdl2-config' 'gyp' 'mm-common-prepare' 'sassc' 'nasm' 'ragel' 'gengetopt' 'asn1Parser' 'ronn' 'docbook2x-man' 'intltool-update' 'gtk-update-icon-cache' 'gdk-pixbuf-csource' 'interdiff' 'luac' 'makensis')
for package in "${check_packages[@]}"; do
type -P "$package" >/dev/null || missing_packages=("$package" "${missing_packages[@]}")
done
if [[ -n "${missing_packages[@]}" ]]; then
clear
echo "Could not find the following execs (svn is actually package subversion, autopoint is gettext or gettext-devel, sassc is libsass, makeinfo is actually package texinfo if you're missing them): ${missing_packages[@]}"
echo 'Install the missing packages before running this script.'
echo "for ubuntu: $ sudo apt-get install subversion curl texinfo g++ bison flex cvs yasm automake libtool autoconf gcc cmake git make pkg-config zlib1g-dev mercurial"
echo "for gentoo (a non ubuntu distro): same as above, but no g++, no gcc, git is dev-vcs/git, zlib1g-dev is zlib, pkg-config is dev-util/pkgconfig, add ed..."
exit 1
fi
local out=`cmake --version` # like cmake version 2.8.7
local version_have=`echo "$out" | cut -d " " -f 3`
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if [[ $(version $version_have) < $(version '2.8.10') ]]; then
echo "your cmake version is too old $version_have wanted 2.8.10"
exit 1
fi
if [[ ! -f /usr/include/zlib.h ]]; then
echo "warning: you may need to install zlib development headers first if you want to build mp4box [on ubuntu: $ apt-get install zlib1g-dev]" # XXX do like configure does and attempt to compile and include zlib.h instead?
sleep 1
fi
out=`yasm --version`
yasm_version=`echo "$out" | cut -d " " -f 2` # like 1.1.0.112
if [[ $(version $yasm_version) < $(version '1.2.0') ]]; then
echo "your yasm version is too old $yasm_version wanted 1.2.0"
exit 1
fi
}
intro() {
cat <<EOL
##################### Welcome ######################
Welcome to the ffmpeg cross-compile builder-helper script.
Downloads and builds will be installed to directories within $cur_dir
If this is not ok, then exit now, and cd to the directory where you'd
like them installed, then run this script again from there.
NB that once you build your compilers, you can no longer rename/move
the sandbox directory, since it will have some hard coded paths in there.
You can, of course, rebuild ffmpeg from within it, etc.
EOL
if [[ $sandbox_ok != 'y' && ! -d sandbox ]]; then
yes_no_sel "Is ./sandbox ok (requires ~ 5GB space) [Y/n]?" "y"
if [[ "$user_input" = "n" ]]; then
exit 1
fi
fi
mkdir -p "$cur_dir"
cd "$cur_dir"
if [[ $disable_nonfree = "y" ]]; then
non_free="n"
else
if [[ $disable_nonfree = "n" ]]; then
non_free="y"
else
yes_no_sel "Would you like to include non-free (non GPL compatible) libraries, like many high quality aac encoders [libfdk_aac]
The resultant binary may not be distributable, but can be useful for in-house use. Include these non-free-license libraries [y/N]?" "n"
non_free="$user_input" # save it away
fi
fi
}
pick_compiler_flavors() {
while [[ "$build_choice" != [1-4] ]]; do
if [[ -n "${unknown_opts[@]}" ]]; then
echo -n 'Unknown option(s)'
for unknown_opt in "${unknown_opts[@]}"; do
echo -n " '$unknown_opt'"
done
echo ', ignored.'; echo
fi
cat <<'EOF'
What version of MinGW-w64 would you like to build or update?
1. Both Win32 and Win64
2. Win32 (32-bit only)
3. Win64 (64-bit only)
4. Exit
EOF
echo -n 'Input your choice [1-5]: '
read build_choice
done
case "$build_choice" in
1 ) build_choice=multi ;;
2 ) build_choice=win32 ;;
3 ) build_choice=win64 ;;
4 ) echo "exiting"; exit 0 ;;
* ) clear; echo 'Your choice was not valid, please try again.'; echo ;;
esac
}
install_cross_compiler() {
if [[ -f "mingw-w64-i686/compiler.done" || -f "x86_64-w64-mingw32/compiler.done" ]]; then
echo "MinGW-w64 compiler of some type or other already installed, not re-installing..."
if [[ $rebuild_compilers != "y" ]]; then
return # early exit, they already have some type of cross compiler built.
fi
fi
if [[ -z $build_choice ]]; then
pick_compiler_flavors
fi
if [[ -f mingw-w64-build ]]; then
rm mingw-w64-build || exit 1
fi
curl https://raw.githubusercontent.com/Zeranoe/mingw-w64-build/master/mingw-w64-build -O || exit 1
chmod u+x mingw-w64-build
apply_patch file://${top_dir}/build-mingw-updates.patch
unset CFLAGS # don't want these for the compiler itself since it creates executables to run on the local box
# pthreads version to avoid having to use cvs for it
echo "building cross compile gcc [requires internet access]"
# Quick patch to update mingw to 4.0.4
# sed -i.bak "s/mingw_w64_release_ver='3.3.0'/mingw_w64_release_ver='4.0.4'/" mingw-w64-build-3.6.6
# sed -i.bak "s/gcc_release_ver='4.9.2'/gcc_release_ver='7.2.0'/" mingw-w64-build-3.6.6
# sed -i.bak "s/mpfr_release_ver='3.1.2'/mpfr_release_ver='3.1.5'/" mingw-w64-build-3.6.6
# sed -i.bak "s/binutils_release_ver='2.25'/binutils_release_ver='2.29'/" mingw-w64-build-3.6.6
# sed -i.bak "s/cloog_release_ver='0.18.1'/cloog_release_ver='0.18.1'/" mingw-w64-build-3.6.6
# sed -i.bak "s/isl_release_ver='0.12.2'/isl_release_ver='0.18'/" mingw-w64-build-3.6.6
# sed -i.bak "s/gmp_release_ver='6.0.0a'/gmp_release_ver='6.1.2'/" mingw-w64-build-3.6.6
# sed -i.bak "s/gmp-6\.0\.0/gmp-6.1.2/" mingw-w64-build-3.6.6
# sed -i.bak "s/--enable-lto/--enable-lto --enable-libgomp/" mingw-w64-build-3.6.6
# sed -i.bak "s!//gcc\.gnu\.org/svn/gcc/trunk!//gcc.gnu.org/svn/gcc/branches/gcc-7-branch!" mingw-w64-build-3.6.6
# apply_patch file://${top_dir}/mingw-w64-build-isl_fix.patch
# apply_patch file://${top_dir}/mingw-w64-build-gcc.patch
# sed -i.bak "s|ln -s '../include' './include'|mkdir include|" mingw-w64-build-3.6.6
# sed -i.bak "s|ln -s '../lib' './lib'|mkdir lib|" mingw-w64-build-3.6.6
# sed -i.bak "s/--enable-threads=win32/--enable-threads=posix/" mingw-w64-build-3.6.6
# Gendef compilation throws a char-as-array-index error when invoked with "--target=" : "--host" avoids this.
# sed -i.bak 's#gendef/configure" --build="$system_type" --prefix="$mingw_w64_prefix" --target#gendef/configure" --build="$system_type" --prefix="$mingw_w64_prefix" --host#' mingw-w64-build-3.6.6
# ./mingw-w64-build-3.6.6 --gcc-langs=c,c++,fortran --default-configure --mingw-w64-ver=git --gcc-ver=svn --pthreads-w32-ver=2-9-1 --cpu-count=$gcc_cpu_count --build-type=$build_choice --enable-gendef --enable-widl --binutils-ver=2.29 --verbose || exit 1 # --disable-shared allows c++ to be distributed at all...which seemed necessary for some random dependency...
./mingw-w64-build x86_64
export CFLAGS=$original_cflags # reset it
# We need to move the plain cross-compiling versions of bintools out of the way
# because exactly the same binaries exist with the host triplet prefix
# rm ${mingw_w64_x86_64_prefix}/bin/objdump ${mingw_w64_x86_64_prefix}/bin/ar ${mingw_w64_x86_64_prefix}/bin/ranlib ${mingw_w64_x86_64_prefix}/bin/objcopy ${mingw_w64_x86_64_prefix}/bin/dlltool ${mingw_w64_x86_64_prefix}/bin/nm ${mingw_w64_x86_64_prefix}/bin/strip ${mingw_w64_x86_64_prefix}/bin/as ${mingw_w64_x86_64_prefix}/bin/ld.bfd ${mingw_w64_x86_64_prefix}/bin/ld
# A couple of multimedia-related files need cases changing because of QT5 includes
cd x86_64-w64-mingw32/x86_64-w64-mingw32/include
ln -s evr9.h Evr9.h
ln -s mferror.h Mferror.h
# cp -v ${top_dir}/dxgi*.h .
apply_patch file://${top_dir}/d3d11.h.patch
apply_patch file://${top_dir}/cfgmgr32.h.patch
apply_patch file://${top_dir}/devpkey.h.patch
apply_patch file://${top_dir}/sal.h.patch
# apply_patch file://${top_dir}/dxgitype-missing.patch
# apply_patch file://${top_dir}/dxgi1_3.h.patch
cp -v ${top_dir}/dxgi1_6.h .
cd ../../..
if [ -d x86_64-w64-mingw32 ]; then
touch x86_64-w64-mingw32/compiler.done
fi
if [ -d mingw-w64-i686 ]; then
touch mingw-w64-i686/compiler.done
fi
# clear
echo "Ok, done building MinGW-w64 cross-compiler..."
}
# helper methods for downloading and building projects that can take generic input
do_svn_checkout() {
repo_url="$1"
to_dir="$2"
desired_revision="$3"
if [ ! -d $to_dir ]; then
echo "svn checking out to $to_dir"
if [[ -z "$desired_revision" ]]; then
svn checkout $repo_url $to_dir.tmp || exit 1
else
svn checkout -r $desired_revision $repo_url $to_dir.tmp || exit 1
fi
mv $to_dir.tmp $to_dir
else
cd $to_dir
echo "not svn Updating $to_dir since usually svn repo's aren't updated frequently enough..."
# XXX accomodate for desired revision here if I ever uncomment the next line...
# svn up
cd ..
fi
}
update_to_desired_git_branch_or_revision() {
local to_dir="$1"
local desired_branch="$2" # or tag or whatever...
if [ -n "$desired_branch" ]; then
pushd $to_dir
cd $to_dir
echo "git checkout $desired_branch"
git checkout "$desired_branch" || exit 1 # if this fails, nuke the directory first...
git merge "$desired_branch" || exit 1 # this would be if they want to checkout a revision number, not a branch...
popd # in case it's a cd to ., don't want to cd to .. here...since sometimes we call it with a '.'
fi
}
do_git_checkout() {
local repo_url="$1"
local to_dir="$2"
if [[ -z $to_dir ]]; then
echo "got empty to dir for git checkout?"
exit 1
fi
local desired_branch="$3"
if [ ! -d $to_dir ]; then
echo "Downloading (via git clone) $to_dir"
rm -rf $to_dir.tmp # just in case it was interrupted previously...
# prevent partial checkouts by renaming it only after success
git clone $repo_url $to_dir.tmp || exit 1
mv $to_dir.tmp $to_dir
echo "done downloading $to_dir"
update_to_desired_git_branch_or_revision $to_dir $desired_branch
else
cd $to_dir
old_git_version=`git rev-parse HEAD`
if [[ -z $desired_branch ]]; then
if [[ $git_get_latest = "y" ]]; then
echo "Updating to latest $to_dir version... $desired_branch"
git pull
else
echo "not doing git get latest pull for latest code $to_dir"
fi
else
if [[ $git_get_latest = "y" ]]; then
echo "Doing git fetch $to_dir in case it affects the desired branch [$desired_branch]"
git fetch
else
echo "not doing git fetch $to_dir to see if it affected desired branch [$desired_branch]"
fi
fi
update_to_desired_git_branch_or_revision "." $desired_branch
new_git_version=`git rev-parse HEAD`
if [[ "$old_git_version" != "$new_git_version" ]]; then
echo "got upstream changes, forcing re-configure."
rm -Rv already*
else
echo "this pull got no new upstream changes, not forcing re-configure..."
fi
cd ..
fi
}
download_config_files() {
curl -o config.guess "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
curl -o config.sub "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"
chmod +x config.guess config.sub
}
get_small_touchfile_name() { # have to call with assignment like a=$(get_small...)
local beginning="$1"
local extra_stuff="$2"
local touch_name="${beginning}_$(echo -- $extra_stuff $CFLAGS | /usr/bin/env md5sum | head --bytes 10)" # make it smaller
touch_name=$(echo $touch_name | sed "s/ //g") # md5sum introduces spaces, remove them
echo $touch_name # bash cruddy return system LOL
}
do_configure() {
local configure_options="$1"
local configure_name="$2"
local configure_env="$3"
local configure_noclean=""
if [[ "$configure_name" = "" ]]; then
configure_name="./configure"
fi
local cur_dir2=$(pwd)
local english_name=$(basename $cur_dir2)
local touch_name=$(get_small_touchfile_name already_configured "$configure_options $configure_name $LDFLAGS $CFLAGS")
if [ ! -f "$touch_name" ]; then
if [ "$configure_noclean" != "noclean" ]; then
make clean # just in case
fi
#make uninstall # does weird things when run under ffmpeg src
if [ ! -f ${configure_name} ]; then
if [ -f bootstrap.sh ]; then
./bootstrap.sh
elif [ -f bootstrap ]; then
./bootstrap
elif [ -f autogen.sh ]; then
./autogen.sh
elif [ -f autogen ]; then
./autogen
else
autoreconf -fvi
fi
fi
rm -f already_* # reset
echo "configuring $english_name ($PWD) as $ PATH=$PATH ${configure_env} $configure_name $configure_options"
"$configure_name" $configure_options || exit 1
touch -- "$touch_name"
make clean # just in case
else
echo "already configured $(basename $cur_dir2)"
fi
}
do_meson() {
local configure_options="$1"
local configure_name="$2"
local configure_env="$3"
local configure_noclean=""
if [[ "$configure_name" = "" ]]; then
configure_name="meson"
fi
local cur_dir2=$(pwd)
local english_name=$(basename $cur_dir2)
local touch_name=$(get_small_touchfile_name already_built "$configure_options $configure_name $LDFLAGS $CFLAGS")
if [ ! -f "$touch_name" ]; then
if [ "$configure_noclean" != "noclean" ]; then
make clean # just in case
fi
rm -f already_* # reset
echo "Using meson: $english_name ($PWD) as $ PATH=$PATH ${configure_env} $configure_name $configure_options"
env
"$configure_name" $configure_options || exit 1
touch -- "$touch_name"
make clean # just in case
else
echo "Already used meson $(basename $cur_dir2)"
fi
}
do_make() {
local extra_make_options="$1 -j $cpu_count"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_make "$extra_make_options")
if [ ! -f $touch_name ]; then
echo
echo "making $cur_dir2 as $ PATH=$PATH make $extra_make_options"
echo
make $extra_make_options || exit 1
touch $touch_name || exit 1 # only touch if the build was OK
else
echo "already did make $(basename "$cur_dir2")"
fi
}
do_make_clean() {
local extra_make_options="$1 -j $cpu_count"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_make_clean "$extra_make_options")
if [ ! -f $touch_name ]; then
echo
echo "making clean $cur_dir2 as $ PATH=$PATH make clean $extra_make_options"
echo
make $extra_make_options clean || exit 1
touch $touch_name || exit 1
else
echo "already did make clean $(basename "$cur_dir2")"
fi
}
do_rake() {
local extra_make_options="$1 -j $cpu_count"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_rake "$extra_make_options")
if [ ! -f $touch_name ]; then
echo
echo "raking $cur_dir2 as $ PATH=$PATH rake $extra_make_options"
echo
rake $extra_make_options || exit 1
touch $touch_name || exit 1 # only touch if the build was OK
else
echo "already did make $(basename "$cur_dir2")"
fi
}
do_drake() {
local extra_make_options="$1 -j $cpu_count"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_drake "$extra_make_options")
if [ ! -f $touch_name ]; then
echo
echo "draking $cur_dir2 as $ PATH=$PATH drake $extra_make_options"
echo
drake $extra_make_options || exit 1
touch $touch_name || exit 1 # only touch if the build was OK
else
echo "already did drake $(basename "$cur_dir2")"
fi
}
do_smake() {
local extra_make_options="$1"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_make "$extra_make_options")
if [ ! -f $touch_name ]; then
echo
echo "smaking $cur_dir2 as $ PATH=$PATH smake $extra_make_options"
echo
${mingw_w64_x86_64_prefix}/../bin/smake $extra_make_options || exit 1
touch $touch_name || exit 1 # only touch if the build was OK
else
echo "already did smake $(basename "$cur_dir2")"
fi
}
do_make_install() {
local extra_make_options="$1"
do_make "$extra_make_options"
local touch_name=$(get_small_touchfile_name already_ran_make_install "$extra_make_options")
if [ ! -f $touch_name ]; then
echo "make installing $cur_dir2 as $ PATH=$PATH make install $extra_make_options"
make install $extra_make_options || exit 1
touch $touch_name || exit 1
fi
}
do_smake_install() {
local extra_make_options="$1"
do_smake "$extra_make_options"
local touch_name=$(get_small_touchfile_name already_ran_make_install "$extra_make_options")
if [ ! -f $touch_name ]; then
echo "smake installing $cur_dir2 as $ PATH=$PATH smake install $extra_make_options"
${mingw_w64_x86_64_prefix}/../bin/smake install $extra_make_options || exit 1
touch $touch_name || exit 1
fi
}
do_cmake() {
extra_args=$1
source_dir=$2
local touch_name=$(get_small_touchfile_name already_ran_cmake "$extra_args")
if [ ! -f $touch_name ]; then
local cur_dir2=$(pwd)
export CMAKE_INCLUDE_PATH="$mingw_w64_x86_64_prefix/include"
export CMAKE_PREFIX_PATH="$mingw_w64_x86_64_prefix"
echo doing cmake in $cur_dir2 with PATH=$PATH with extra_args=$extra_args like this:
echo cmake $source_dir $extra_args -DBUILD_SHARED_LIB=1 -DBUILD_STATIC_LIBS=0 -DENABLE_STATIC_RUNTIME=0 -DENABLE_SHARED_RUNTIME=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_Fortran_COMPILER:FILEPATH=${cross_prefix}gfortran -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix || exit 1
cmake $source_dir $extra_args -DBUILD_SHARED_LIBS=1 -DBUILD_STATIC_LIBS=0 -DENABLE_STATIC_RUNTIME=0 -DENABLE_SHARED_RUNTIME=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix || exit 1
touch $touch_name || exit 1
unset CMAKE_INCLUDE_PATH
unset CMAKE_PREFIX_PATH
fi
}
do_cmake_static() {
extra_args=$1
source_dir=$2
local touch_name=$(get_small_touchfile_name already_ran_cmake "$extra_args")
if [ ! -f $touch_name ]; then
local cur_dir2=$(pwd)
export CMAKE_INCLUDE_PATH="$mingw_w64_x86_64_prefix/include"
export CMAKE_PREFIX_PATH="$mingw_w64_x86_64_prefix"
echo doing cmake in $cur_dir2 with PATH=$PATH with extra_args=$extra_args like this:
echo cmake $source_dir $extra_args -DBUILD_SHARED_LIB=0 -DBUILD_STATIC_LIBS=1 -DENABLE_STATIC_RUNTIME=0 -DENABLE_SHARED_RUNTIME=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_Fortran_COMPILER:FILEPATH=${cross_prefix}gfortran -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix || exit 1
cmake $source_dir $extra_args -DBUILD_SHARED_LIBS=0 -DBUILD_STATIC_LIBS=1 -DENABLE_STATIC_RUNTIME=1 -DENABLE_SHARED_RUNTIME=0 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix || exit 1
touch $touch_name || exit 1
fi
}
apply_patch() {
local url=$1
local patch_name=$(basename $url)
local patch_reverted_name="$patch_name.reverted"
local patch_done_name="$patch_name.done"
if [[ ! -e $patch_done_name ]]; then
if [[ -f $patch_name ]]; then
rm $patch_name || exit 1
fi
curl $url -O || exit 1
echo "applying patch $patch_name"
cat $patch_name
patch -p0 < "$patch_name" || exit 1
touch $patch_done_name || exit 1
rm -v $patch_reverted_name
rm already_ran* # if it's a new patch, reset everything too, in case it's really really really new
else
echo "patch $patch_name already applied"
fi
}
revert_patch() {
local url=$1
local patch_name=$(basename $url)
local patch_reverted_name="$patch_name.reverted"
local patch_done_name="$patch_name.done"
if [[ ! -e $patch_reverted_name ]]; then
if [[ -f $patch_name ]]; then
rm $patch_name || exit 1
fi
curl $url -O || exit 1
echo "reverting patch $patch_name"
cat $patch_name
patch -p0 -R < "$patch_name" || exit 1
touch $patch_reverted_name || exit 1
rm -v $patch_done_name || exit 1
rm already_ran* # if it's a new patch, reset everything too, in case it's really really really new
else
echo "patch $patch_name already reverted"
fi
}
apply_patch_p1() {
local url=$1
local patch_name=$(basename $url)
local patch_done_name="$patch_name.done"
if [[ ! -e $patch_done_name ]]; then
if [[ -f $patch_name ]]; then
rm $patch_name || exit 1
fi
curl $url -O || exit 1
echo "applying patch $patch_name"
patch -p1 < "$patch_name" || exit 1
touch $patch_done_name || exit 1
rm already_ran* # if it's a new patch, reset everything too, in case it's really really really new
else
echo "patch $patch_name already applied"
fi
}
download_and_unpack_file() {
url="$1"
output_name=$(basename $url)
output_dir="$2"
if [ ! -f "$output_dir/unpacked.successfully" ]; then
echo "downloading $url"
if [[ -f $output_name ]]; then
rm "$output_name" || exit 1
fi
# echo "About to call curl ${url} and output_name is ${output_name} and output_dir is ${output_dir}"
curl -k -O -L "${url}" || exit 1
tar --keep-directory-symlink -xvf "$output_name" || unzip "$output_name" || exit 1
touch "$output_dir/unpacked.successfully" || exit 1
rm "$output_name" || exit 1
fi
}
download_and_unpack_bz2file() {
url="$1"
output_name=$(basename $url)
output_dir="$2"
if [ ! -f "$output_dir/unpacked.successfully" ]; then
echo "downloading $url"
if [[ -f $output_name ]]; then
rm "$output_name" || exit 1
fi
curl "$url" -O -L || exit 1
mkdir $output_dir
tar ixvf "$output_name" -C $output_dir --strip-components=1 || exit 1
touch "$output_dir/unpacked.successfully" || exit 1
rm "$output_name" || exit 1
fi
}
generic_meson() {
local extra_configure_options="$1"
mkdir build
do_meson "--prefix=${mingw_w64_x86_64_prefix} --libdir=${mingw_w64_x86_64_prefix}/lib --buildtype release --strip --default-library shared --cross-file ${top_dir}/meson-cross.mingw.txt $extra_configure_options . build"
}
generic_configure() {
local extra_configure_options="$1"
# do_configure "--host=$host_target --prefix=$mingw_w64_x86_64_prefix --disable-shared --enable-static $extra_configure_options"
do_configure "--host=$host_target --prefix=$mingw_w64_x86_64_prefix --enable-shared --disable-static $extra_configure_options"
}
# needs 2 parameters currently [url, name it will be unpacked to]
generic_download_and_install() {
local url="$1"
local english_name="$2"
local extra_configure_options="$3"
download_and_unpack_file $url $english_name
cd $english_name || exit "needs 2 parameters"
generic_configure_make_install "$extra_configure_options"
cd ..
}
generic_configure_make_install() {
generic_configure "$1"
do_make_and_make_install
}
generic_configure_rake_install() {
generic_configure "$1"
do_rake_and_rake_install
}
generic_configure_drake_install() {
generic_configure "$1"
do_drake_and_drake_install
}
generic_meson_ninja_install() {
generic_meson "$1"
do_ninja_and_ninja_install
}
do_ninja_and_ninja_install() {
local extra_ninja_options="$1"
do_ninja "$extra_ninja_options"
local touch_name=$(get_small_touchfile_name already_ran_make_install "$extra_ninja_options")
if [ ! -f $touch_name ]; then
echo "ninja installing $(pwd) as $ PATH=$PATH ninja -C build install $extra_make_options"
ninja install || exit 1
touch $touch_name || exit 1
fi
}
do_ninja() {
local extra_make_options=" -j $cpu_count"
local cur_dir2=$(pwd)
local touch_name=$(get_small_touchfile_name already_ran_make "${extra_make_options}")
if [ ! -f $touch_name ]; then
echo
echo "ninja-ing $cur_dir2 as $ PATH=$PATH ninja "${extra_make_options}"
echo
ninja "${extra_make_options} || exit 1
touch $touch_name || exit 1 # only touch if the build was OK
else
echo "already did ninja $(basename "$cur_dir2")"
fi
}
do_make_and_make_install() {
local extra_make_options="$1"
do_make "$extra_make_options"
local touch_name=$(get_small_touchfile_name already_ran_make_install "$extra_make_options")
if [ ! -f $touch_name ]; then
echo "make installing $(pwd) as $ PATH=$PATH make install $extra_make_options"
make install $extra_make_options || exit 1
touch $touch_name || exit 1
fi
}
do_rake_and_rake_install() {
local extra_make_options="$1"
do_rake "$extra_make_options"
local touch_name=$(get_small_touchfile_name already_ran_make_install "$extra_make_options")
if [ ! -f $touch_name ]; then
echo "rake installing $(pwd) as $ PATH=$PATH rake install $extra_make_options"
rake install $extra_make_options || exit 1
touch $touch_name || exit 1
fi
}
do_drake_and_drake_install() {
local extra_make_options="$1"
do_drake "$extra_make_options"
local touch_name=$(get_small_touchfile_name already_ran_drake_install "$extra_make_options")
if [ ! -f $touch_name ]; then
echo "drake installing $(pwd) as $ PATH=$PATH drake install $extra_make_options"
drake install $extra_make_options || exit 1
touch $touch_name || exit 1
fi
}
do_cmake_and_install() {
extra_args="$1"
local touch_name=$(get_small_touchfile_name already_ran_cmake "$extra_args")
if [ ! -f $touch_name ]; then
rm -f already_* # reset so that make will run again if option just changed
local cur_dir2=$(pwd)
echo doing cmake in $cur_dir2 with PATH=$PATH with extra_args=$extra_args like this:
echo cmake –G”Unix Makefiles” . -DENABLE_STATIC_RUNTIME=0 -DENABLE_SHARED_RUNTIME=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix $extra_args
cmake –G”Unix Makefiles” . -DENABLE_STATIC_RUNTIME=0 -DENABLE_SHARED_RUNTIME=1 -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_RANLIB=${cross_prefix}ranlib -DCMAKE_C_COMPILER=${cross_prefix}gcc -DCMAKE_CXX_COMPILER=${cross_prefix}g++ -DCMAKE_RC_COMPILER=${cross_prefix}windres -DCMAKE_INSTALL_PREFIX=$mingw_w64_x86_64_prefix $extra_args || exit 1
touch $touch_name || exit 1
fi
do_make_and_make_install
}
do_cleanup() {
# Removes all files in, and under, directory except those which
# prevent re-making
echo "Running do_cleanup in $(pwd)..."
find . ! \( -name 'already_*' -o -name 'unpacked.successfully' -o -name '*patch.done' \) -type f -exec rm -rf {} +
}
build_libx265() {
do_git_checkout https://github.com/videolan/x265.git x265
cd x265
# apply_patch file://${top_dir}/x265-headers-revert.patch
cd ..
cd x265/source
local cmake_params="-DENABLE_SHARED=ON -DENABLE_STATIC=OFF -DENABLE_HDR10_PLUS=ON -DENABLE_ASSEMBLY=ON -DHIGH_BIT_DEPTH=1"
#if [[ $high_bitdepth == "y" ]]; then
# cmake_params="$cmake_params -DHIGH_BIT_DEPTH=ON -DMAIN12=ON" # Enable 10 bits (main10) and 12 bits (???) per pixels profiles.
# if grep "DHIGH_BIT_DEPTH=0" CMakeFiles/cli.dir/flags.make; then
# rm already_ran_cmake_* #Last build was not high bitdepth. Forcing rebuild.
# fi
#else
# if grep "DHIGH_BIT_DEPTH=1" CMakeFiles/cli.dir/flags.make; then
# rm already_ran_cmake_* #Last build was high bitdepth. Forcing rebuild.
# fi
#fi
# apply_patch_p1 file://${top_dir}/x265-missing-bool.patch
# Fixed by x265 developers now
do_cmake "$cmake_params"
# x265 seems to fail on parallel builds
# export cpu_count=1
do_make_install
# export cpu_count=$original_cpu_count
cd ../..
# We must remove the x265.exe executable because FFmpeg gets linked against it. I do not understand this.
# Furthermore, this makes x265.exe as an executable completely unuseable.
# cp -v ${mingw_w64_x86_64_prefix}/bin/libx265.dll ${mingw_w64_x86_64_prefix}/bin/x265.exe
}
#x264_profile_guided=y
build_libx264() {
do_git_checkout git://git.videolan.org/x264.git x264
cd x264
local configure_flags="--host=$host_target --disable-static --enable-shared --cross-prefix=$cross_prefix --prefix=$mingw_w64_x86_64_prefix --disable-avs --disable-swscale --disable-lavf --disable-ffms --disable-gpac --bit-depths=all --chroma-format=all" # --enable-win32thread --enable-debug shouldn't hurt us since ffmpeg strips it anyway I think
# if [[ $high_bitdepth == "y" ]]; then
# configure_flags="$configure_flags --bit-depth=10" # Enable 10 bits (main10) per pixels profile.
# if grep -q "HIGH_BIT_DEPTH 0" config.h; then
# rm already_configured_* #Last build was not high bitdepth. Forcing reconfigure.
# fi
# else
# if grep -q "HIGH_BIT_DEPTH 1" config.h; then
# rm already_configured_* #Last build was high bitdepth. Forcing reconfigure.
# fi
# fi
# if [[ $x264_profile_guided = y ]]; then
# TODO more march=native here?
# TODO profile guided here option, with wine?
# do_configure "$configure_flags"
# curl http://samples.mplayerhq.hu/yuv4mpeg2/example.y4m.bz2 -O || exit 1
# rm example.y4m # in case it exists already...
# bunzip2 example.y4m.bz2 || exit 1
# XXX does this kill git updates? maybe a more general fix, since vid.stab does also?
# sed -i.bak "s_\\, ./x264_, wine ./x264_" Makefile # in case they have wine auto-run disabled http://askubuntu.com/questions/344088/how-to-ensure-wine-does-not-auto-run-exe-files
# do_make_install "fprofiled VIDS=example.y4m" # guess it has its own make fprofiled, so we don't need to manually add -fprofile-generate here...
# else
do_configure "$configure_flags"
do_make_install
# fi
cd ..
}
build_librtmp() {
# download_and_unpack_file http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3.tgz rtmpdump-2.3 # has some odd configure failure
# cd rtmpdump-2.3/librtmp
do_git_checkout "http://repo.or.cz/r/rtmpdump.git" rtmpdump_git # 883c33489403ed360a01d1a47ec76d476525b49e # trunk didn't build once...this one i sstable
cd rtmpdump_git
sed -i.bak 's/SYS=posix/SYS=mingw/' Makefile
sed -i.bak 's/SYS=posix/SYS=mingw/' librtmp/Makefile
cd librtmp
do_make_install "CRYPTO=GNUTLS OPT=-O2 CROSS_COMPILE=$cross_prefix SHARED=yes prefix=$mingw_w64_x86_64_prefix SYS=mingw"
#make install CRYPTO=GNUTLS OPT='-O2 -g' "CROSS_COMPILE=$cross_prefix" SHARED=no "prefix=$mingw_w64_x86_64_prefix" || exit 1
sed -i.bak 's/-lrtmp -lz/-lrtmp -lwinmm -lz/' "$PKG_CONFIG_PATH/librtmp.pc"
cd ..
# TODO do_make here instead...
make SYS=mingw CRYPTO=GNUTLS OPT=-O2 CROSS_COMPILE=$cross_prefix SHARED=yes LIB_GNUTLS="`pkg-config --libs gnutls` -lz" || exit 1
# The makefile doesn't install
cp -fv rtmpdump.exe rtmpgw.exe rtmpsrv.exe rtmpsuck.exe "${mingw_w64_x86_64_prefix}/bin"
cd ..
}
build_qt() {
export QT_VERSION="5.10.1"
export QT_SOURCE="qt-source"
export QT_BUILD="qt-build"
# orig_cpu_count=$cpu_count
# export cpu_count=1
if [ ! -f qt.built ]; then
download_and_unpack_file http://download.qt.io/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz "qt-everywhere-src-${QT_VERSION}"
cd "qt-everywhere-src-${QT_VERSION}"
# apply_patch file://${top_dir}/qt-permissive.patch
apply_patch file://${top_dir}/qt5-skip-mapboxglnative.patch
# Change a type for updates in ANGLE project
grep -rl "EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE" ./ | xargs sed -i.bak 's/EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE/EGL_PLATFORM_ANGLE_DEVICE_TYPE_D3D_WARP_ANGLE/g'
cd ..
mkdir -p "${QT_BUILD}"
ln -vs "qt-everywhere-src-${QT_VERSION}" "${QT_SOURCE}"
cd "${QT_SOURCE}"
echo "QMAKE_LINK_OBJECT_MAX = 10" >> qtbase/mkspecs/win32-g++/qmake.conf
echo "QMAKE_LINK_OBJECT_SCRIPT = object_script" >> qtbase/mkspecs/win32-g++/qmake.conf
cd ..
cd "${QT_BUILD}"
do_configure "-xplatform win32-g++ -prefix ${mingw_w64_x86_64_prefix} -hostprefix ${mingw_w64_x86_64_prefix}/../ -opensource -qt-freetype -confirm-license -accessibility -nomake examples -nomake tests -skip qtwebglplugin -release -strip -openssl -opengl dynamic -device-option CROSS_COMPILE=$cross_prefix -device-option PKG_CONFIG=${mingw_w64_x86_64_prefix}/../bin/x86_64-w64-mingw32-pkg-config -no-static -shared -no-use-gold-linker -D MINGW_HAS_SECURE_API -D _WIN32_IE=0x0A00 -v -skip qtactiveqt" "../qt-everywhere-src-${QT_VERSION}/configure" # "noclean" # -skip qtactiveqt
# For sone reason, the compiler doesn't set the include path properly!
do_make || exit 1
do_make_install || exit 1
cd ..
# Qt, when building only the release libraries, retains pkgconfig files that refer to
# the debug libraries. We have not build the debug libraries. These references must
# therefore be changed to point to the release libraries.
/usr/bin/python3 ${top_dir}/fix-Qt-non-debug.py ${mingw_w64_x86_64_prefix}/lib/pkgconfig
touch "qt.built"
# rm -rf $QT_SOURCE $QT_BUILD
# QT's build tree takes up over 24GB of space. We don't need to see this again because
# we're not using a frequently-updated Git version
# echo "Removing QT-${QT_VERSION} build tree..."
# rm -rf ${QT_BUILD}
# echo "QT-${QT_VERSION} build tree now removed."
# The Qt libraries are sometimes searched for in the wrong place. So let's copythem
# to where they're sometimes expected
else
echo "Skipping QT build... already completed."
# Remove the debug versions of libQt5 libraries
rm -v ${mingw_w64_x86_64_prefix}/bin/Qt5*d.dll
fi
ln -sv ${mingw_w64_x86_64_prefix}/bin/Qt*.dll ${mingw_w64_x86_64_prefix}/../bin
ln -sv ${mingw_w64_x86_64_prefix}/plugins ${mingw_w64_x86_64_prefix}/../plugins
unset QT_VERSION
unset QT_SOURCE
unset QT_BUILD
# export cpu_count=$orig_cpu_count
}
#build_qt() {
## This is quite a minimal installation to try to shorten a VERY long compile.
## It's needed for OpenDCP and may well be extended to other programs later.
# unset CFLAGS
# download_and_unpack_file http://download.qt.io/archive/qt/4.8/4.8.6/qt-everywhere-opensource-src-4.8.6.tar.gz qt-everywhere-opensource-src-4.8.6
# cd qt-everywhere-opensource-src-4.8.6
# apply_patch_p1 file://${top_dir}/qplatformdefs.h.patch
# apply_patch_p1 file://${top_dir}/qfiledialog.cpp.patch
# # vlc's configure options...mostly
## do_configure "-static -release -fast -no-exceptions -no-stl -no-sql-sqlite -no-qt3support -no-gif -no-libmng -qt-libjpeg -no-libtiff -no-qdbus -no-openssl -no-webkit -sse -no-script -no-multimedia -no-phonon -opensource -no-scripttools -no-opengl -no-script -no-scripttools -no-declarative -no-declarative-debug -opensource -no-s60 -host-little-endian -confirm-license -xplatform win32-g++ -device-option CROSS_COMPILE=$cross_prefix -prefix $mingw_w64_x86_64_prefix -prefix-install -nomake examples"
# do_configure "-release -static -no-exceptions -no-sql-sqlite -no-scripttools -no-script -no-accessibility -no-qt3support -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-declarative -no-declarative-debug -no-s60 -host-little-endian -no-webkit -xplatform win32-g++ -no-cups -no-dbus -nomake tests -nomake docs -nomake tools -opensource -confirm-license -nomake demos -nomake examples -no-libmng -device-option CROSS_COMPILE=$cross_prefix -prefix $mingw_w64_x86_64_prefix -prefix-install"
# if [ ! -f 'already_qt_maked_k' ]; then
# do_make # sub-src might make the build faster? # complains on mng? huh?
# do_make_install
# touch 'already_qt_maked_k'
# fi
# # vlc needs an adjust .pc file? huh wuh?
## sed -i.bak 's/Libs: -L${libdir} -lQtGui/Libs: -L${libdir} -lcomctl32 -lqjpeg -lqtaccessiblewidgets -lQtGui/' "$PKG_CONFIG_PATH/QtGui.pc" # sniff
# cd ..
# export CFLAGS=$original_cflags
#}
build_libsoxr() {
#download_and_unpack_file http://sourceforge.net/projects/soxr/files/soxr-0.1.1-Source.tar.xz soxr-0.1.1-Source # not /download since apparently some tar's can't untar it without an extension?
do_git_checkout git://git.code.sf.net/p/soxr/code "soxr-code"
cd soxr-code
do_cmake "-DHAVE_WORDS_BIGENDIAN_EXITCODE=0 -DBUILD_SHARED_LIBS:bool=on -DBUILD_STATIC_LIBS:bool=off -DBUILD_TESTS:BOOL=OFF"
do_make_install
cd ..
}
build_googletest() {
do_git_checkout https://github.com/google/googletest.git googletest
cd googletest
do_cmake "-DBUILD_SHARED_LIBS=ON"
do_make_install
# Must leave this behind. movit needs to see the source.
# do_make_clean
cd ..
}
build_mlt() {
do_git_checkout http://github.com/mltframework/mlt.git mlt # 18b8609
cd mlt
# apply_patch file://${top_dir}/mlt-mingw-sandbox.patch
export CXX=x86_64-w64-mingw32-g++
export CROSS=x86_64-w64-mingw32-
export CC=x86_64-w64-mingw32-gcc
orig_cflags="${CFLAGS}"
export CFLAGS=-DUSE_MLT_POOL
# apply_patch file://${top_dir}/mlt-rtaudio.patch
# The --avformat-ldextra option must contain all the libraries that
# libavformat.dll is linked against. These we obtain by reading libavformat.pc
# from the pkgconfig directory
avformat_ldextra=`pkg-config --static --libs-only-l libavformat`
# do_configure "--prefix=${mingw_w64_x86_64_prefix} --enable-gpl --enable-gpl3 --disable-gtk2 --target-os=mingw --target-arch=x86_64 --libdir=${mingw_w64_x86_64_prefix}/bin/lib --datadir=${mingw_w64_x86_64_prefix}/bin/share --mandir=${mingw_w64_x86_64_prefix}/share/man --avformat-swscale --avformat-ldextra=${avformat_ldextra}"
generic_configure_make_install "--enable-gpl --enable-gpl3 --target-os=mingw --target-arch=x86_64 --prefix=${mingw_w64_x86_64_prefix} --libdir=${mingw_w64_x86_64_prefix}/bin/lib --datadir=${mingw_w64_x86_64_prefix}/bin/share --mandir=${mingw_w64_x86_64_prefix}/share/man"
# apply_patch file://${top_dir}/mlt-rtaudio.patch
# do_make
# do_make_install
# The Makefiles don't use Autotools, and put the binaries in the wrong places with
# no executable extension for 'melt.exe'
# Also, the paths are not correct for Windows execution. So we must move things
mv -v ${mingw_w64_x86_64_prefix}/melt ${mingw_w64_x86_64_prefix}/bin/melt.exe
mv -v ${mingw_w64_x86_64_prefix}/libmlt* ${mingw_w64_x86_64_prefix}/bin/
unset CXX
unset CROSS
unset CC
export CFLAGS=${orig_cflags}
cd ..
}
build_DJV() {
# download_and_unpack_file http://gallery.johnwarburton.net/djv-git-a7104da34d8a273de457b3225f77de35ccb4a63e.tar.xz djv-git-a7104da34d8a273de457b3225f77de35ccb4a63e
do_git_checkout https://github.com/sobotka/djv-view.git DJV ffmpeg-fixes
cd DJV
# cd djv-git-a7104da34d8a273de457b3225f77de35ccb4a63e
# Patch to get around Mingw-w64's difficult-to-follow handling of strerror_s()
apply_patch file://${top_dir}/djv-djvFileInfo.cpp.patch
# Patch to use g++ equivalents of possibly missing environment manipulation functions
apply_patch file://${top_dir}/djv-djvSystem.cpp.patch
# Non-portable patch to restore missing #define-s of these math constants
# that have lately disappeared in Mingw-w64
apply_patch file://${top_dir}/djv-FFmpeg.patch
# Use #define pulled from FFmpeg source code
sed -i.bak 's/FLT_EPSILON/1.19209290e-07F/' lib/djvCore/djvMath.cpp
sed -i.bak 's/DBL_EPSILON/2.2204460492503131e-16/' lib/djvCore/djvMath.cpp
# FFmpeg's headers have changed. DJV hasn't caught up yet
sed -i.bak 's/ PIX_FMT_RGBA/ AV_PIX_FMT_RGBA/' plugins/djvFFmpegPlugin/djvFFmpegLoad.cpp
# Replace a MSVC function that isn't yet in Mingw-w64
sed -i.bak 's/defined(DJV_WINDOWS)/defined(DJV_WINDOWS) \&\& defined(_MSC_VER)/' lib/djvCore/djvStringUtil.h
sed -i.bak 's/defined(DJV_WINDOWS)/defined(DJV_WINDOWS) \&\& defined(_MSC_VER)/' plugins/djvJpegPlugin/djvJpegLoad.cpp
sed -i.bak 's/defined(DJV_WINDOWS)/defined(DJV_WINDOWS) \&\& defined(_MSC_VER)/' plugins/djvJpegPlugin/djvJpegSave.cpp
sed -i.bak 's/defined(DJV_WINDOWS)/defined(DJV_WINDOWS) \&\& defined(_MSC_VER)/' plugins/djvPngPlugin/djvPngLoad.cpp
sed -i.bak 's/defined(DJV_WINDOWS)/defined(DJV_WINDOWS) \&\& defined(_MSC_VER)/' plugins/djvPngPlugin/djvPngSave.cpp
# Don't make dvjFileBrowserTest or, indeed, any tests
sed -i.bak 's/enable_testing()/#enable_testing()/' CMakeLists.txt
sed -i.bak 's/add_subdirectory(djvFileBrowserTest)/#add_subdirectory(djvFileBrowserTest)/' tests/CMakeLists.txt
# Change Windows' backslashes to forward slashes to allow MinGW compilation
# Remember that . and \ need escaping with \, which makes this hard to read
sed -i.bak 's!\.\.\\\\.\.\\\\etc\\\\Windows\\\\djv_view.ico!../../etc/Windows/djv_view.ico!' bin/djv_view/win.rc
do_cmake "-DBUILD_SHARED_LIBS=true -DCMAKE_VERBOSE_MAKEFILE=YES -DENABLE_STATIC_RUNTIME=0 -DCMAKE_PREFIX_PATH=${mingw_w64_x86_64_prefix} -DCMAKE_C_FLAGS=-D__STDC_CONSTANT_MACROS -DCMAKE_CXX_FLAGS=-D__STDC_CONSTANT_MACROS -DCMAKE_SUPPRESS_REGENERATION=TRUE"
${top_dir}/correct_headers.sh
orig_cpu_count=$cpu_count
export cpu_count=1
do_make "V=1"
export cpu_count=$orig_cpu_count
# The whole DJV suite is now in two directories: build/bin and build/lib.
# bin contains programs and their necessary DLLs, lib contains plugins and development libraries.
# We need to copy the executables and their companion DLLs to our bin distribution directory
# and the plugins (for now)
cp -v build/bin/* "${mingw_w64_x86_64_prefix}/bin/"
# The plugins are needed for the many file formats DJV can play
cp -v build/lib/*dll "${mingw_w64_x86_64_prefix}/bin/"
# We must rename these plugins to remove the initial "lib". The Cmake Windows packager
# normally does this, but we're not using it.
for library in ${mingw_w64_x86_64_prefix}/bin/libdjv*Plugin*dll; do
dllname=$(basename $library)
cut_dllname=${dllname:3}
mv -v ${library} ${mingw_w64_x86_64_prefix}/bin/${cut_dllname}