File: synfigstudio-cygwin-mingw-build.sh

package info (click to toggle)
synfig 1.5.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 59,132 kB
  • sloc: cpp: 109,639; sh: 6,121; makefile: 1,458; csh: 243; perl: 238; python: 124; ruby: 73
file content (1249 lines) | stat: -rw-r--r-- 37,260 bytes parent folder | download | duplicates (5)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
#!/bin/bash
#
# SynfigStudio Windows package build script
# Copyright (c) 2013 Konstantin Dmitriev
#
# This package is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
#
# = Usage notes =
# 
# * Download and install Git (http://msysgit.github.io/).
# * Open Git Bash and execute following commands:
# ** mkdir C:\synfig-build
# ** cd C:\synfig-build
# ** git clone https://github.com/synfig/synfig.git
# ** mkdir cygwin-dist
# ** cd synfig
# ** git config --global core.autocrlf input
# ** exit
# * Download Cygwin setup binary (http://www.cygwin.com/) and save it into C:\synfig-build\cygwin-dist\ directory.
# * Run Cygwin setup and install with the default parameters.
# * Download and install NSIS >=3.0 (http://nsis.sourceforge.net/). Install into C:\synfig-build\NSIS\ directory.
# * (64-bit build only!) Download and install 7zip (http://downloads.sourceforge.net/sevenzip/7z920-x64.msi). Install into C:\synfig-build\7zip\ directory.
# * Open Cygwin console (with administrator previlegies) and run the build script:
# ** bash C:/synfig-build/synfig/autobuild/synfigstudio-cygwin-mingw-build.sh
# * Installation bundle will be written to C:\synfig-build\
#
#
# = Other notes =
# * Builds from current repository, current revision. So you should manually checkout the desired revision to build
# * Executing script without arguments makes a full clean build and produces installer package
# * You can pass arguments to the script to invoke particular stage. 
#	Available stages: mkprep, mketl, mksynfig, mksynfigstudio, mkpackage
#	Example: 
#		synfigstudio-cygwin-mingw-build.sh mkpackage
# * You can pass a custom command to be invoked in the build environment.
#	Example (executes make with respect to the build environment):
#		synfigstudio-cygwin-mingw-build.sh make -j2



#================= EDIT THOSE VARIABLES BEFORE FIRST RUN! ======================

export NSIS_BINARY="C:/synfig-build/NSIS/makensis.exe"
export WORKSPACE="/cygdrive/c/synfig-build"
if [ -z $ARCH ]; then
    export ARCH="32"
fi
if [ -z $DEBUG ]; then
	export DEBUG=1
fi
if [ -z $THREADS ]; then
	export THREADS=4
fi
#=========================== EDIT UNTIL HERE ===================================

export DISTPREFIX=$WORKSPACE/dist
export SRCPREFIX=`dirname "$0"`
SRCPREFIX=$(cd "$SRCPREFIX/.."; pwd)

if [[ $ARCH == "32" ]]; then
    export TOOLCHAIN_HOST="i686-w64-mingw32"
    export TOOLCHAIN="mingw64-i686" # mingw64-i686 | mingw64-x86_64 | mingw
    export EXT_ARCH=i386
    export EXT_ARCH2=i686
    export CYGWIN_SETUP="C:/synfig-build/cygwin-dist/setup-x86.exe"
    export SZIP_BINARY="7z"
elif [[ $ARCH == "64" ]]; then
    export TOOLCHAIN_HOST="x86_64-w64-mingw32"
    export TOOLCHAIN="mingw64-x86_64"
    export EXT_ARCH=x86_64
    export EXT_ARCH2=x86_64
    export CYGWIN_SETUP="C:/synfig-build/cygwin64-dist/setup-x86_64.exe"
    export SZIP_BINARY="C:/synfig-build/7zip/7z.exe"
fi
export MINGWPREFIX="/usr/${TOOLCHAIN_HOST}/sys-root/mingw"
set -e

if [[ $DEBUG == 1 ]]; then
	DEBUG='--enable-debug --enable-optimization=0'
else
	DEBUG=''
fi

export VERSION=`cat ${SRCPREFIX}/synfig-core/configure.ac |egrep "AC_INIT\(\[Synfig Core\],"| sed "s|.*Core\],\[||" | sed "s|\],\[.*||"`
pushd "${SRCPREFIX}" > /dev/null
export REVISION=`git show --pretty=format:%ci HEAD |  head -c 10 | tr -d '-'`
popd > /dev/null


if [ ! -e "$SZIP_BINARY" ]; then
    if [[ $ARCH == "64" ]]; then
        echo "7zip not found! Please download and install 7zip (http://downloads.sourceforge.net/sevenzip/7z920-x64.msi). Install into C:\synfig-build\7zip\ directory."
        exit 1
    fi
fi
if [ ! -e "$NSIS_BINARY" ]; then
    echo "NSIS not found! Please download and install NSIS >=3.0 (http://nsis.sourceforge.net/). Install into C:\synfig-build\NSIS\ directory."
    exit 1
fi

chmod a+x ${MINGWPREFIX}/bin/*.dll || true

prepare_mingw_env()
{
export CBUILD=i686-pc-cygwin
export CHOST=${TOOLCHAIN_HOST}
export CTARGET=${TOOLCHAIN_HOST}
export CC=${TOOLCHAIN_HOST}-gcc
export CXX=${TOOLCHAIN_HOST}-g++
export F77=${TOOLCHAIN_HOST}-gfortran
export FC=${TOOLCHAIN_HOST}-gfortran
export GCJ=${TOOLCHAIN_HOST}-gcj
export GOC=${TOOLCHAIN_HOST}-gccgo
export OBJC=${TOOLCHAIN_HOST}-gcc
export OBJCXX=${TOOLCHAIN_HOST}-g++
export AR=${TOOLCHAIN_HOST}-ar
export OBJDUMP=${TOOLCHAIN_HOST}-objdump
export RANLIB=${TOOLCHAIN_HOST}-ranlib
export STRIP=${TOOLCHAIN_HOST}-strip
export RC=${TOOLCHAIN_HOST}-windres
export CFLAGS=' -O2 -pipe -mms-bitfields'
export CXXFLAGS=" -O2 -pipe -mms-bitfields"
#export CXXFLAGS=" -O2 -pipe -mms-bitfields  -I${MINGWPREFIX}/include/c++ -I${MINGWPREFIX}/include/c++/${TOOLCHAIN_HOST}"
export F77FLAGS=' -mms-bitfields'
export FCFLAGS=' -O2 -pipe -mms-bitfields'
export GCJFLAGS=' -O2 -pipe -mms-bitfields'
export GOCFLAGS=' -mms-bitfields'
export OBJCFLAGS=' -O2 -pipe -mms-bitfields'
export OBJCXXFLAGS=' -O2 -pipe -mms-bitfields'
export PKG_CONFIG=/usr/bin/pkg-config
export PKG_CONFIG_PATH="${MINGWPREFIX}/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="${MINGWPREFIX}/lib/pkgconfig:${MINGWPREFIX}/share/pkgconfig:/usr/share/pkgconfig"
export PKG_CONFIG_SYSTEM_INCLUDE_PATH=${MINGWPREFIX}/include
export PKG_CONFIG_SYSTEM_LIBRARY_PATH=${MINGWPREFIX}/lib
export CPPFLAGS=" -I${MINGWPREFIX}/include "
export LDFLAGS=" -L${MINGWPREFIX}/lib "
export LIBS=""
export PATH="${MINGWPREFIX}/bin/:$PATH"
alias convert="${MINGWPREFIX}/bin/convert"
}

mknative()
{
export CBUILD=""
export CHOST=""
export CTARGET=""
export CC="gcc"
export CXX="g++"
export F77=""
export FC=""
export GCJ=""
export GOC=""
export OBJC=""
export OBJCXX=""
export AR=""
export OBJDUMP=""
export RANLIB=""
export STRIP=""
export RC=""
export CFLAGS=""
export CXXFLAGS=""
export F77FLAGS=""
export FCFLAGS=""
export GCJFLAGS=""
export GOCFLAGS=""
export OBJCFLAGS=""
export OBJCXXFLAGS=""
export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig"
export PKG_CONFIG_LIBDIR=""
export PKG_CONFIG_SYSTEM_INCLUDE_PATH=""
export PKG_CONFIG_SYSTEM_LIBRARY_PATH=""
export CPPFLAGS=""
export LDFLAGS=""
export PATH="/usr/local/bin:/usr/bin"

$@
}

mkpopt()
{
PKG_NAME=popt
PKG_VERSION=1.10.3

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.gz ] || wget http://rpm5.org/files/popt/${PKG_NAME}-${PKG_VERSION}.tar.gz
[ -d ${PKG_NAME}-${PKG_VERSION} ] || tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.gz
cd ${PKG_NAME}-${PKG_VERSION}
./autogen.sh --noconfigure
./configure --prefix=/usr/local --libdir=/usr/local/lib 
make -j$THREADS install
if [[ $ARCH == "64" ]]; then
	mv /usr/local/lib64/* /usr/local/lib
fi

# remove old version of popt
[ ! -e /usr/bin/cygpopt-0.dll ] || rm /usr/bin/cygpopt-0.dll
}

mkrpm()
{
PKG_NAME=rpm
#PKG_VERSION=4.11.1
PKG_VERSION=4.10.3.1
#PKG_VERSION=4.7.0
TAREXT=bz2

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://rpm.org/releases/rpm-4.10.x/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xjf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
    patch -p1 < $SRCPREFIX/autobuild/cygwin/${PKG_NAME}-${PKG_VERSION}.patch
    patch -p1 < $SRCPREFIX/autobuild/cygwin/${PKG_NAME}-${PKG_VERSION}-python-fixes.patch
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi
LDFLAGS=" -L/usr/local/lib" CPPFLAGS="-I/usr/include/nspr -I/usr/include/nss -I/usr/include/db4.8/ -I/usr/include/python2.7/" ./autogen.sh \
    --with-external-db \
    --without-lua \
    --enable-python
make -j$THREADS install

cd python
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
export LDFLAGS=" -L/usr/local/lib" 
python setup.py build
python setup.py install
}

mkpyliblzma()
{
PKG_NAME=pyliblzma
PKG_VERSION=0.5.3
TAREXT=bz2

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget https://pypi.python.org/packages/source/p/pyliblzma/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi

export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig"

python setup.py build
python setup.py install
}

mkpycurl()
{
PKG_NAME=pycurl
PKG_VERSION=7.19.0
TAREXT=gz

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://pycurl.sourceforge.net/download/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi

python setup.py build
python setup.py install
}

mkurlgrabber()
{
PKG_NAME=urlgrabber
PKG_VERSION=3.9.1
TAREXT=gz

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://urlgrabber.baseurl.org/download/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi

python setup.py build
python setup.py install
}

mkyum-metadata-parser()
{
PKG_NAME=yum-metadata-parser
PKG_VERSION=1.1.4
TAREXT=gz

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://yum.baseurl.org/download/yum-metadata-parser/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi

python setup.py build
python setup.py install
}

mkyum()
{
PKG_NAME=yum
PKG_VERSION=3.4.3
TAREXT=gz

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://yum.baseurl.org/download/3.4/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi
rm INSTALL || true
make install PREFIX="//" DESTDIR=""
}

mkyum-utils()
{
PKG_NAME=yum-utils
PKG_VERSION=1.1.31
TAREXT=gz

cd $WORKSPACE
[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://yum.baseurl.org/download/yum-utils/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    cd ${PKG_NAME}-${PKG_VERSION}
else
    cd ${PKG_NAME}-${PKG_VERSION}
fi
make install || true
if [ ! -e /usr/bin/yumdownloader ]; then
    exit 1
fi
}

mklibcroco()
{
PKG_NAME=libcroco
PKG_VERSION=0.6.8
TAREXT=xz
if ! pkg-config ${PKG_NAME}-0.6 --exact-version=${PKG_VERSION}  --print-errors; then
	cd ${WORKSPACE}
	wget -c --no-check-certificate http://ftp.gnome.org/pub/gnome/sources/${PKG_NAME}/${PKG_VERSION%.*}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	[ ! -d ${PKG_NAME}-${PKG_VERSION} ] && tar -xf ${WORKSPACE}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	cd ${PKG_NAME}-${PKG_VERSION}
	[ ! -e config.cache ] || rm config.cache
	./configure \
		--prefix=${MINGWPREFIX} \
		--exec-prefix=${MINGWPREFIX} \
		--bindir=${MINGWPREFIX}/bin \
		--sbindir=${MINGWPREFIX}/sbin \
		--libexecdir=${MINGWPREFIX}/lib \
		--datadir=${MINGWPREFIX}/share \
		--localstatedir=${MINGWPREFIX}/var \
		--sysconfdir=${MINGWPREFIX}/etc \
		--datarootdir=${MINGWPREFIX}/share \
		--docdir=/usr/share/doc/mingw-synfig -C \
		--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
		--disable-static --enable-shared
	make -j${THREADS}
	make install
fi
}

mkgobjectintrospection()
{

#mkflex

PKG_NAME=gobject-introspection
PKG_VERSION=1.42.0
TAREXT=xz
if ! pkg-config ${PKG_NAME}-1.0 --exact-version=${PKG_VERSION}  --print-errors; then
	cd ${WORKSPACE}
	wget -c --no-check-certificate http://ftp.gnome.org/pub/gnome/sources/${PKG_NAME}/${PKG_VERSION%.*}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	[ ! -d ${PKG_NAME}-${PKG_VERSION} ] && tar -xf ${WORKSPACE}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	cd ${PKG_NAME}-${PKG_VERSION}
	[ ! -e config.cache ] || rm config.cache
	CPPFLAGS="$CPPFLAGS -I/usr/include" ./configure \
		--prefix=${MINGWPREFIX} \
		--exec-prefix=${MINGWPREFIX} \
		--bindir=${MINGWPREFIX}/bin \
		--sbindir=${MINGWPREFIX}/sbin \
		--libexecdir=${MINGWPREFIX}/lib \
		--datadir=${MINGWPREFIX}/share \
		--localstatedir=${MINGWPREFIX}/var \
		--sysconfdir=${MINGWPREFIX}/etc \
		--datarootdir=${MINGWPREFIX}/share \
		--docdir=/usr/share/doc/mingw-synfig -C \
		--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
		--disable-static --enable-shared
	make -j${THREADS}
	make install
fi
}


mklibrsvg()
{
	
	mklibcroco
	mkgobjectintrospection
	
PKG_NAME=librsvg
PKG_VERSION=2.40.6
TAREXT=xz
if ! pkg-config ${PKG_NAME} --exact-version=${PKG_VERSION}  --print-errors; then
	cd ${WORKSPACE}
	wget -c --no-check-certificate http://ftp.gnome.org/pub/gnome/sources/${PKG_NAME}/${PKG_VERSION%.*}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	[ ! -d ${PKG_NAME}-${PKG_VERSION} ] && tar -xf ${WORKSPACE}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	cd ${PKG_NAME}-${PKG_VERSION}
	[ ! -e config.cache ] || rm config.cache
	./configure \
		--prefix=${MINGWPREFIX} \
		--exec-prefix=${MINGWPREFIX} \
		--bindir=${MINGWPREFIX}/bin \
		--sbindir=${MINGWPREFIX}/sbin \
		--libexecdir=${MINGWPREFIX}/lib \
		--datadir=${MINGWPREFIX}/share \
		--localstatedir=${MINGWPREFIX}/var \
		--sysconfdir=${MINGWPREFIX}/etc \
		--datarootdir=${MINGWPREFIX}/share \
		--docdir=/usr/share/doc/mingw-synfig -C \
		--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
		--disable-static --enable-shared
	make -j${THREADS}
	make install
	cd ..
	popd
fi
}

mkgnomethemes()
{
	
mklibrsvg

PKG_NAME=gnome-themes-standard
PKG_VERSION=3.15.2
TAREXT=xz
if ! pkg-config ${PKG_NAME} --exact-version=${PKG_VERSION}  --print-errors; then
	cd ${WORKSPACE}
	wget -c --no-check-certificate http://ftp.gnome.org/pub/gnome/sources/${PKG_NAME}/${PKG_VERSION%.*}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	[ ! -d ${PKG_NAME}-${PKG_VERSION} ] && tar -xf ${WORKSPACE}/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
	cd ${PKG_NAME}-${PKG_VERSION}
	[ ! -e config.cache ] || rm config.cache
	./configure \
		--prefix=${MINGWPREFIX} \
		--exec-prefix=${MINGWPREFIX} \
		--bindir=${MINGWPREFIX}/bin \
		--sbindir=${MINGWPREFIX}/sbin \
		--libexecdir=${MINGWPREFIX}/lib \
		--datadir=${MINGWPREFIX}/share \
		--localstatedir=${MINGWPREFIX}/var \
		--sysconfdir=${MINGWPREFIX}/etc \
		--datarootdir=${MINGWPREFIX}/share \
		--docdir=/usr/share/doc/mingw-synfig -C \
		--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
		--disable-static --enable-shared \
		--disable-gtk2-engine
	make -j${THREADS}
	make install
	cd ..
	popd
fi
}

mkimagemagick()
{
PKG_NAME=ImageMagick
#PKG_VERSION=6.8.6-10
PKG_VERSION=6.8.7-10
TAREXT=xz

if ! pkg-config ${PKG_NAME} --exact-version=${PKG_VERSION%-*}  --print-errors; then
    cd $WORKSPACE
    [ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://www.imagemagick.org/download/releases/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
        tar -xf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
        cd ${PKG_NAME}-${PKG_VERSION}
    else
        cd ${PKG_NAME}-${PKG_VERSION}
    fi
    [ ! -e config.cache ] || rm config.cache
    autoreconf -i --verbose  # does this really required?
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
        --disable-static --enable-shared \
        --without-modules \
        --without-perl \
        --without-x \
        --with-threads \
        --with-magick_plus_plus

    make -j${THREADS}
    make install
fi
}

mklibogg()
{

PKG_NAME=libogg
PKG_VERSION=1.3.1
TAREXT=gz

if ! pkg-config ogg --exact-version=${PKG_VERSION}  --print-errors; then
    cd $WORKSPACE
    [ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://downloads.xiph.org/releases/ogg/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
        tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    fi
    cd ${PKG_NAME}-${PKG_VERSION}
    [ ! -e config.cache ] || rm config.cache
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST}

    make all
    make install

fi
}

mklibvorbis()
{
mklibogg

PKG_NAME=libvorbis
PKG_VERSION=1.3.4
TAREXT=gz

if ! pkg-config vorbis --exact-version=${PKG_VERSION}  --print-errors; then
    cd $WORKSPACE
    [ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://downloads.xiph.org/releases/vorbis/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
        tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    fi
    cd ${PKG_NAME}-${PKG_VERSION}
    [ ! -e config.cache ] || rm config.cache
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST}

    make all
    make install

fi
}

mklibsamplerate()
{
PKG_NAME=libsamplerate
PKG_VERSION=0.1.8
TAREXT=gz

if ! pkg-config samplerate --exact-version=${PKG_VERSION}  --print-errors; then
    cd $WORKSPACE
    [ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://www.mega-nerd.com/SRC/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
        tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    fi
    cd ${PKG_NAME}-${PKG_VERSION}
    [ ! -e config.cache ] || rm config.cache
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST}

    make all
    make install

fi
}

mksox()
{
PKG_NAME=sox
PKG_VERSION=14.4.1
TAREXT=gz

if ! pkg-config ${PKG_NAME} --exact-version=${PKG_VERSION}  --print-errors; then
    cd $WORKSPACE
    [ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://download.tuxfamily.org/synfig/packages/sources/base/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
        tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    fi
    cd ${PKG_NAME}-${PKG_VERSION}
    [ ! -e config.cache ] || rm config.cache
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST}

    make all
    make install

fi
}

mkmlt()
{
PKG_NAME=mlt
PKG_VERSION=0.9.6
TAREXT=gz

if ! pkg-config ${PKG_NAME}\+\+ --exact-version=${PKG_VERSION}  --print-errors; then
    cd $WORKSPACE
    #[ -e ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT} ] || wget http://download.tuxfamily.org/synfig/packages/sources/base/${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    #if [ ! -d ${PKG_NAME}-${PKG_VERSION} ]; then
    #    tar -xzf ${PKG_NAME}-${PKG_VERSION}.tar.${TAREXT}
    #fi
    #cd ${PKG_NAME}-${PKG_VERSION}
    if [ ! -d ${PKG_NAME} ]; then
        git clone https://github.com/morevnaproject/mlt
    fi
    cd mlt
    git reset --hard
    git checkout master
    git reset --hard
    git pull
    git clean -f -d
    [ ! -e config.cache ] || rm config.cache
    #autoreconf -i --verbose  # does this really required?
    rm -rf ${MINGWPREFIX}/lib/libmlt* || true
    rm -rf ${MINGWPREFIX}/bin/libmlt* || true
    ./configure \
        --prefix=${MINGWPREFIX} \
        --exec-prefix=${MINGWPREFIX} \
        --bindir=${MINGWPREFIX}/bin \
        --sbindir=${MINGWPREFIX}/sbin \
        --libexecdir=${MINGWPREFIX}/lib \
        --datadir=${MINGWPREFIX}/share \
        --localstatedir=${MINGWPREFIX}/var \
        --sysconfdir=${MINGWPREFIX}/etc \
        --datarootdir=${MINGWPREFIX}/share \
        --docdir=/usr/share/doc/mingw-synfig -C \
        --build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
        --avformat-shared=${MINGWPREFIX}/ \
        --enable-gpl --disable-decklink \
        --target-os=MinGW --target-arch=$EXT_ARCH \
        #$DEBUG
        
    if [ $ARCH == "64" ]; then
        touch src/modules/disable-motion_est
        touch src/modules/disable-xine
    fi
    touch src/modules/disable-gtk2

    make all
    make install

    mv ${MINGWPREFIX}/melt.exe ${MINGWPREFIX}/bin
    mv ${MINGWPREFIX}/libmlt*.dll ${MINGWPREFIX}/bin

    mkdir -p ${MINGWPREFIX}/bin/lib || true
    mkdir -p ${MINGWPREFIX}/bin/share || true
    cp -rf ${MINGWPREFIX}/lib/mlt ${MINGWPREFIX}/bin/lib/
    cp -rf ${MINGWPREFIX}/share/mlt ${MINGWPREFIX}/bin/share/

fi
}

#mktoolchain()
#{
#	cd ${WORKSPACE}
#	if [ ! -e mingw${ARCH}/done ]; then
#		[ ! -e ${WORKSPACE}/mingw32 ] || rm -rf ${WORKSPACE}/mingw32
#		TOOLCHAIN_ARCHIVE=${EXT_ARCH2}-4.9.2-release-posix-sjlj-rt_v3-rev1.7z
#		[ -e ${TOOLCHAIN_ARCHIVE} ] || wget http://downloads.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.2/threads-posix/sjlj/${TOOLCHAIN_ARCHIVE}
#		$SZIP_BINARY x ${TOOLCHAIN_ARCHIVE}
#		mkdir -p ${MINGWPREFIX} | true
#		mv mingw32/${TOOLCHAIN_HOST}/*  ${MINGWPREFIX}
#		cp ${MINGWPREFIX}/lib/*.dll ${MINGWPREFIX}/bin
#		touch mingw${ARCH}/done
#	fi
#}
mkffmpeg()
{
    export FFMPEG_VERSION=2.5.2
    if ! pkg-config libswscale --exact-version=${FFMPEG_VERSION}  --print-errors; then
        pushd $WORKSPACE
        [ -e ffmpeg-${FFMPEG_VERSION}-win${ARCH}-dev.7z ] || wget http://ffmpeg.zeranoe.com/builds/win${ARCH}/dev/ffmpeg-${FFMPEG_VERSION}-win${ARCH}-dev.7z
        [ -e ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared.7z ] || wget http://ffmpeg.zeranoe.com/builds/win${ARCH}/shared/ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared.7z
        [ ! -d ffmpeg ] || rm -rf ffmpeg
        mkdir -p ffmpeg
        cd ffmpeg
        $SZIP_BINARY x ../ffmpeg-${FFMPEG_VERSION}-win${ARCH}-dev.7z
        cp -rf ffmpeg-${FFMPEG_VERSION}-win${ARCH}-dev/include/* ${MINGWPREFIX}/include/
        cp -rf ffmpeg-${FFMPEG_VERSION}-win${ARCH}-dev/lib/* ${MINGWPREFIX}/lib/
        $SZIP_BINARY x ../ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared.7z
        cp -rf ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared/bin/ffmpeg.exe ${MINGWPREFIX}/bin
        cp -rf ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared/bin/*.dll ${MINGWPREFIX}/bin
        mkdir -p ${MINGWPREFIX}/share/ffmpeg/presets/ || true
        cp -rf ffmpeg-${FFMPEG_VERSION}-win${ARCH}-shared/presets/* ${MINGWPREFIX}/share/ffmpeg/presets/

		mkdir -p ${MINGWPREFIX}/lib/pkgconfig/ || true
		for PKG in avcodec avutil avformat swscale avdevice; do
			cat > ${MINGWPREFIX}/lib/pkgconfig/lib${PKG}.pc <<EOF
prefix=${MINGWPREFIX}
exec_prefix=${MINGWPREFIX}
libdir=${MINGWPREFIX}/lib
includedir=${MINGWPREFIX}/include

Name: lib${PKG}
Description: FFMpeg
Version: ${FFMPEG_VERSION}

Libs: -l${PKG}

EOF
		done
        popd
    fi
}

fedora-mingw-install()
{
[ -d $WORKSPACE/mingw-rpms ] || mkdir $WORKSPACE/mingw-rpms

cd $WORKSPACE/mingw-rpms

# Prepare custom yum.conf
cat > $WORKSPACE/mingw-rpms/yum.conf <<EOF
[main]
cachedir=${WORKSPACE}mingw-rpms/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
plugins=1
installonly_limit=3

[fedora]
name=Fedora \$releasever - \$basearch
failovermethod=priority
#mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-\$releasever&arch=\$basearch
baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/21/Everything/i386/os/
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/21/Everything/i386/os/
enabled=1
metadata_expire=7d

[updates]
name=Fedora \$releasever - \$basearch - Updates
failovermethod=priority
#mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-f\$releasever&arch=\$basearch
baseurl=http://archives.fedoraproject.org/pub/archive/fedora/linux/updates/21/i386/
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/21/i386/
enabled=1
EOF

if [ -z $2 ]; then
RPMROOT=/
else
RPMROOT=$2
fi

URLS=`yumdownloader --urls --resolve -c $WORKSPACE/mingw-rpms/yum.conf --releasever=20 --installroot="$WORKSPACE/mingw-rpms" $1`
for URL in $URLS; do
if ( echo "$URL" | egrep "^http:" > /dev/null ); then
    PKG=`basename $URL`
    if ( echo "$PKG" | egrep "^mingw" > /dev/null ); then
        if [ -z $3 ]; then
            if ! ( echo $PKG | egrep "^mingw..-headers|^mingw..-gcc|^mingw-|^mingw..-filesystem|^mingw..-binutils|^mingw..-crt|^mingw..-cpp" > /dev/null); then
                echo $PKG
                wget -c "$URL"
                rpm -Uhv --ignoreos --nodeps --force --root "$RPMROOT" "$PKG"
            fi
        else
			if ( echo $PKG | egrep "$1" > /dev/null); then
				echo $PKG
                wget -c "$URL"
                rpm -Uhv --ignoreos --nodeps --force --root "$RPMROOT" "$PKG"
			fi
		fi
    fi
fi
done

# Ensure all dlls have executable flag, otherwise the compiled binaries won't run
chmod a+x ${MINGWPREFIX}/bin/*.dll
}

# Install dependencies
mkprep()
{

export PREP_VERSION=6

if [[ `cat /prep-done` != "${PREP_VERSION}" ]]; then

$CYGWIN_SETUP \
-s http://www.mirrorservice.org/sites/sourceware.org/pub/cygwin/ \
-P git \
-P make \
-P gcc-core \
-P gcc-g++ \
-P $TOOLCHAIN-gcc  \
-P $TOOLCHAIN-gcc-g++  \
-P gdb \
-P intltool \
-P autoconf \
-P automake \
-P libtool \
-P pkg-config \
-P p7zip \
-P ImageMagick \
-P cygport \
-P zlib-devel \
-P libnspr-devel \
-P liblzma-devel \
-P libnss-devel \
-P libiconv \
-P libdb4.8-devel \
-P libpcre-devel \
-P python \
-P file-devel \
-P zlib-devel \
-P libdb-devel \
-P flex \
-P bison \
-P python-setuptools \
-q

# yum dependencies
$CYGWIN_SETUP \
-s http://www.mirrorservice.org/sites/sourceware.org/pub/cygwin/ \
-P urlgrabber \
-P rpm-devel \
-P rpm-python \
-P libglib2.0-devel \
-P libxml2-devel \
-P libsqlite3-devel \
-q


#-P libglib2.0-devel \ # yum req
#-P libsqlite3-devel \ # yum req
#-P libxml2-devel \ # yum req
#-P libcurl-devel \ # pycurl req

#mktoolchain

#echo "Building popt..."
#mknative mkpopt
echo "Building pyliblzma..."
mknative mkpyliblzma
#echo "Building rpm..."
#mknative mkrpm
#mknative mkurlgrabber
echo "Building yum-metadata-parser..."
mknative mkyum-metadata-parser


#mknative mkyum
#mknative mkyum-utils

install_fedora_env

echo ${PREP_VERSION} > /prep-done

fi
}

install_fedora_env()
{
cd $WORKSPACE
wget -c http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Everything/i386/os/Packages/y/yum-3.4.3-106.fc20.noarch.rpm
rpm -Uhv --force --ignoreos --nodeps yum-3.4.3-106.fc20.noarch.rpm
wget -c http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Everything/i386/os/Packages/y/yum-utils-1.1.31-18.fc20.noarch.rpm
rpm -Uhv --force --ignoreos --nodeps yum-utils-1.1.31-18.fc20.noarch.rpm
#wget -c http://fedora.inode.at/fedora/linux/releases/21/Everything/i386/os/Packages/y/yum-3.4.3-153.fc21.noarch.rpm
#rpm -Uhv --force --ignoreos --nodeps yum-3.4.3-153.fc21.noarch.rpm
#wget -c http://fedora.inode.at/fedora/linux/releases/21/Everything/i386/os/Packages/y/yum-utils-1.1.31-24.fc21.noarch.rpm
#rpm -Uhv --force --ignoreos --nodeps yum-utils-1.1.31-24.fc21.noarch.rpm

#[ ! -e C:/synfig-build/mingw-rpms/tmp ] || rm -rf C:/synfig-build/mingw-rpms/tmp
#mkdir -p C:/synfig-build/mingw-rpms/tmp
#fedora-mingw-install mingw${ARCH}-gcc-c++ C:/synfig-build/mingw-rpms/tmp 1
#cp C:/synfig-build/mingw-rpms/tmp${MINGWPREFIX}/bin/libstdc++-6.dll  ${MINGWPREFIX}/bin/

#fedora-mingw-install mingw${ARCH}-adwaita-icon-theme
#fedora-mingw-install mingw${ARCH}-hicolor-icon-theme
fedora-mingw-install mingw${ARCH}-libxml++
fedora-mingw-install mingw${ARCH}-cairo
fedora-mingw-install mingw${ARCH}-pango
fedora-mingw-install mingw${ARCH}-boost
fedora-mingw-install mingw${ARCH}-libjpeg-turbo
fedora-mingw-install mingw${ARCH}-gtkmm30
fedora-mingw-install mingw${ARCH}-SDL
fedora-mingw-install mingw${ARCH}-fftw
cp ${MINGWPREFIX}/include/SDL/* ${MINGWPREFIX}/include/

# Somehow this is required too...
fedora-mingw-install mingw${ARCH}-pcre

# Dependencies for magick++
fedora-mingw-install mingw${ARCH}-libltdl
fedora-mingw-install mingw${ARCH}-libtiff
}

mketl()
{
cd $SRCPREFIX/ETL
[ ! -e config.cache ] || rm config.cache
autoreconf --install --force
./configure \
--prefix=${MINGWPREFIX} \
--exec-prefix=${MINGWPREFIX} \
--bindir=${MINGWPREFIX}/bin \
--sbindir=${MINGWPREFIX}/sbin \
--libexecdir=${MINGWPREFIX}/lib \
--datadir=${MINGWPREFIX}/share \
--localstatedir=${MINGWPREFIX}/var \
--sysconfdir=${MINGWPREFIX}/etc \
--datarootdir=${MINGWPREFIX}/share \
--docdir=/usr/share/doc/mingw-synfig -C \
--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
--enable-shared --disable-static \
--with-libiconv-prefix=no --with-libintl-prefix=no \
--enable-maintainer-mode $DEBUG
make install
}

mksynfig()
{
cd $SRCPREFIX/synfig-core
[ ! -e config.cache ] || rm config.cache
./bootstrap.sh
./configure \
--prefix=${MINGWPREFIX} \
--exec-prefix=${MINGWPREFIX} \
--bindir=${MINGWPREFIX}/bin \
--sbindir=${MINGWPREFIX}/sbin \
--libexecdir=${MINGWPREFIX}/lib \
--datadir=${MINGWPREFIX}/share \
--localstatedir=${MINGWPREFIX}/var \
--sysconfdir=${MINGWPREFIX}/etc \
--datarootdir=${MINGWPREFIX}/share \
--docdir=/usr/share/doc/mingw-synfig -C \
--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
--enable-shared --disable-static \
--with-libiconv-prefix=no --with-libintl-prefix=no \
--with-magickpp=yes --with-boost=${MINGWPREFIX} \
--enable-maintainer-mode $DEBUG
make -j$THREADS
make install
}

mksynfigstudio()
{
cd $SRCPREFIX/synfig-studio
[ ! -e config.cache ] || rm config.cache
./bootstrap.sh
./configure \
--prefix=${MINGWPREFIX} \
--exec-prefix=${MINGWPREFIX} \
--bindir=${MINGWPREFIX}/bin \
--sbindir=${MINGWPREFIX}/sbin \
--libexecdir=${MINGWPREFIX}/lib \
--datadir=${MINGWPREFIX}/share \
--localstatedir=${MINGWPREFIX}/var \
--sysconfdir=${MINGWPREFIX}/etc \
--datarootdir=${MINGWPREFIX}/share \
--docdir=/usr/share/doc/mingw-synfig -C \
--build=i686-pc-cygwin --host=${TOOLCHAIN_HOST} \
--enable-shared --disable-static \
--with-libiconv-prefix=no --with-libintl-prefix=no \
--enable-maintainer-mode $DEBUG
make -j$THREADS
make install 
cp -rf ${MINGWPREFIX}/share/pixmaps/synfigstudio/*  ${MINGWPREFIX}/share/pixmaps
rm -rf ${MINGWPREFIX}/share/pixmaps/synfigstudio
mkdir -p $MINGWPREFIX/licenses
cp -rf COPYING $MINGWPREFIX/licenses/synfigstudio.txt

cat > ${MINGWPREFIX}/etc/gtk-3.0/gtkrc <<EOF

# Enable native look
gtk-theme-name = "MS-Windows"

# Use small toolbar buttons
gtk-toolbar-style = 0

EOF
}

mkpackage()
{

cp -rf ${SRCPREFIX}/autobuild/gtk-3.0/settings.ini $MINGWPREFIX/share/gtk-3.0

[ ! -d $DISTPREFIX ] || rm -rf $DISTPREFIX
mkdir -p $DISTPREFIX
[ -d $DISTPREFIX/bin ] || mkdir -p $DISTPREFIX/bin
[ -d $DISTPREFIX/licenses ] || mkdir -p $DISTPREFIX/licenses
[ -d $DISTPREFIX/lib ] || mkdir -p $DISTPREFIX/lib
[ -d $DISTPREFIX/share ] || mkdir -p $DISTPREFIX/share

cd $WORKSPACE

[ -e portable-python-3.2.5.1.zip ] || wget http://download.tuxfamily.org/synfig/packages/sources/portable-python-3.2.5.1.zip
[ ! -d python ] || rm -rf python
unzip portable-python-3.2.5.1.zip
[ ! -d $DISTPREFIX/python ] || rm -rf $DISTPREFIX/python
mv python $DISTPREFIX

cp -rf $SRCPREFIX/synfig-core/examples $DISTPREFIX/
cp -rf $SRCPREFIX/synfig-studio/COPYING $DISTPREFIX/licenses/synfigstudio.txt

#copy compiled files
#cp -rf $MINGWPREFIX/bin/*.exe $DISTPREFIX/bin/
#TODO: strip binaries?
#cp -rf $MINGWPREFIX/bin/*.dll $DISTPREFIX/bin/
[ -d ${DISTPREFIX}/bin ] || mkdir -p ${DISTPREFIX}/bin
for file in \
   av*.dll \
   ffmpeg.exe \
   iconv.dll \
   libatk-\*.dll \
   libatkmm-1.6-1.dll \
   libboost_chrono\*.dll \
   libboost_filesystem\*.dll \
   libboost_program_options\*.dll \
   libboost_system\*.dll \
   libbz2\*.dll \
   libcairo\*.dll \
   libdl.dll \
   libexpat\*.dll \
   libffi\*.dll \
   libfftw\*.dll \
   libfontconfig\*.dll \
   libfreetype\*.dll \
   libgcc_s_\*.dll \
   libgdk\*.dll \
   libgettext\*.dll \
   libgio\*.dll \
   libglib\*.dll \
   libgmodule\*.dll \
   libgobject\*.dll \
   libgomp*.dll \
   libgthread\*.dll \
   libgtk\*.dll \
   libharfbuzz\*.dll \
   libiconv\*.dll \
   libintl\*.dll \
   libjasper\*.dll \
   libjpeg\*.dll \
   libltdl*.dll \
   liblzma\*.dll \
   libMagick*.dll \
   libmlt*.dll \
   libogg*.dll \
   libpango\*.dll \
   libpixman\*.dll \
   libpng\*.dll \
   libsamplerate*.dll \
   libsigc\*.dll \
   libsox*.dll \
   libstdc++\*.dll \
   libsynfig\*.dll \
   libtiff\*.dll \
   libturbojpeg.dll \
   libvorbis*.dll \
   libwinpthread*.dll \
   libxml2\*.dll \
   libxml++\*.dll \
   libz\*.dll \
   postproc*.dll \
   pthread\*.dll \
   SDL.dll \
   swscale*.dll \
   swresample*.dll \
   zlib\*.dll \
   convert.exe \
   pango-querymodules.exe \
   synfig.exe \
   synfigstudio.exe \
   lib \
   share \
# this extra line is required!
do
	cp -rf $MINGWPREFIX/bin/$file $DISTPREFIX/bin || true
done
cp -rf $MINGWPREFIX/etc $DISTPREFIX
cp -rf $MINGWPREFIX/lib/gdk-pixbuf-2.0 $DISTPREFIX/lib
cp -rf $MINGWPREFIX/lib/gtk-3.0 $DISTPREFIX/lib
cp -rf $MINGWPREFIX/lib/pango $DISTPREFIX/lib
cp -rf $MINGWPREFIX/lib/synfig $DISTPREFIX/lib
cp -rf $MINGWPREFIX/share/fontconfig $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/glib-2.0 $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/gtk-3.0 $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/icons $DISTPREFIX/share || true
cp -rf $MINGWPREFIX/share/locale $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/pixmaps $DISTPREFIX/share
if [ -d $DISTPREFIX/share/pixmaps/synfigstudio ]; then
	cp -rf $DISTPREFIX/share/pixmaps/synfigstudio/*  $DISTPREFIX/share/pixmaps
	rm -rf $DISTPREFIX/share/pixmaps/synfigstudio
fi
cp -rf $MINGWPREFIX/share/synfig $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/themes $DISTPREFIX/share
cp -rf $MINGWPREFIX/share/xml $DISTPREFIX/share

#cleanup


gen_list_nsh()
{
[ ! -e $2.nsh ] || rm $2.nsh
[ ! -e $2-uninst.nsh ] || rm $2-uninst.nsh
for line in `find $1 -print`; do
	directory=`dirname $line`
	line1=`echo $directory | sed "s|\./||g" | sed "s|/|\\\\\|g"`
	line2=`echo $line | sed "s|\./||g" | sed "s|/|\\\\\|g"`
	if [ -d $line ]; then
		echo "RMDir \"\$INSTDIR\\$line2\"" >> $2-uninst.nsh
	else
		echo "SetOutPath \"\$INSTDIR\\$line1\""  >> $2.nsh
		echo "File \"$line2\"" >> $2.nsh
		echo "Delete \"\$INSTDIR\\$line2\"" >> $2-uninst.nsh
	fi
done
# reverse order of uninstall commands
cp $2-uninst.nsh $2-uninst.nsh.tmp
tac $2-uninst.nsh.tmp > $2-uninst.nsh
rm $2-uninst.nsh.tmp
}

cd $DISTPREFIX

#generate file lists

gen_list_nsh bin bin
sed -i '/ffmpeg\.exe/d' bin.nsh		# exclude ffmpeg from the list of binaries - it will go into separate group
gen_list_nsh etc etc
gen_list_nsh examples examples
gen_list_nsh lib/gdk-pixbuf-2.0 lib-gdk-pixbuf
gen_list_nsh lib/gtk-3.0 lib-gtk
gen_list_nsh lib/pango lib-pango
gen_list_nsh lib/synfig lib-synfig
gen_list_nsh licenses licenses
#gen_list_nsh python python # -- takes too long
gen_list_nsh share share


#make installer
cp -f $SRCPREFIX/autobuild/synfigstudio.nsi ./
sed -i "s/@VERSION@/$VERSION/g" ./synfigstudio.nsi
cp -f $SRCPREFIX/autobuild/win${ARCH}-specific.nsh ./arch-specific.nsh
"$NSIS_BINARY" -nocd -- synfigstudio.nsi

mv synfigstudio-${VERSION}.exe ../synfigstudio-${VERSION}-${REVISION}-${ARCH}bit.exe

INSTALLER_PATH=`cygpath -w "$WORKSPACE"`
echo
echo
echo
echo "Installer package generated:"
echo "   ${INSTALLER_PATH}synfigstudio-${VERSION}-${REVISION}-${ARCH}bit.exe"
echo
}

mkall()
{
	mkprep
	mkffmpeg
	prepare_mingw_env
	mkimagemagick
	mklibsamplerate
	mksox
	mklibvorbis
	mkmlt
	mketl
	mksynfig
	mksynfigstudio
	mkpackage
}

if [ -z $1 ]; then
	mkall
else
	echo "Executing custom user command..."
	prepare_mingw_env
	$@
fi