forked from conda-archive/conda-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mingw-w64-build-3.6.0.sh
1835 lines (1696 loc) · 73.9 KB
/
mingw-w64-build-3.6.0.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
#!/bin/bash
script_ver='3.6.0'
################################################################################
# MingGW-w64 Build Script
################################################################################
# Copyright (C) 2011-2014 Kyle Schwarz
#
# This program 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 3 of the License, or (at your option) any later
# version.
#
# This program 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.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
# The GNU General Public License can be found at the end of this file.
#
# Written by Kyle Schwarz, report any bugs to <kyle.r.schwarz@gmail.com>
#
# This script will build MinGW-w64 for Win32 and Win64.
#
# This version will build the following packages into the toolchain:
# mingw-w64
# gmp
# mpfr
# mpc
# isl
# cloog
# binutils
# gcc
################################################################################
about () {
clear
read -p \
"################################################################################
# #
# MingGW-w64 Build Script $script_ver #
# #
# #
# This script will build MinGW-w64 for Win32 and Win64. #
# #
# This version will build the following packages into the toolchain #
# #
# mingw-w64 gmp #
# #
# mpfr mpc #
# #
# isl cloog #
# #
# binutils gcc #
# #
# #
# Press Enter to continue #
# #
# Copyright (C) 2011-1013 Kyle Schwarz #
# This program comes with ABSOLUTELY NO WARRANTY #
# #
################################################################################"
}
# Variables
working_dir="$(pwd)"
detected_cpu_count="$(grep -c processor /proc/cpuinfo)"
uname_m="$(uname -m)"
target_i686='i686-w64-mingw32'
target_x86_64='x86_64-w64-mingw32'
## Versions
mingw_w64_release_ver='3.1.0'
gcc_release_ver='4.9.0'
gcc_old_release_ver='4.8.3'
mpfr_release_ver='3.1.2'
mpc_release_ver='1.0.2'
binutils_release_ver='2.24'
gmp_release_ver='6.0.0a'
isl_release_ver='0.11.1'
cloog_release_ver='0.18.0'
pthreads_w32_release_ver='2-9-1'
## Locations
mingw_w64_source_dir="$working_dir/source"
mingw_w64_build_dir="$working_dir/build"
pkgs_dir="$working_dir/pkgs"
## Prefixes
mingw_w64_i686_prefix="$working_dir/mingw-w64-i686"
mingw_w64_x86_64_prefix="$working_dir/mingw-w64-x86_64"
display_help () {
cat <<EOF
Compile MinGW-w64 as a cross-toolchain for Win32 or Win64
Run options other than compiling (./mingw-w64-build-$script_ver OPTION):
wipe removes all MinGW-w64 files in the directory (build build.log
mingw-w64-i686 mingw-w64-x86_64 pkgs source)
Available options are specified in parentheses.
Defaults for the options are specified in brackets.
General:
-h, --help display this help and exit
-a, --about display the "About" page
-V, --version display version information and exit
Compile Options:
--build-type=TYPE compile for TYPE (win32, win64, multi)
--default-configure compile with default options for all unset options
--allow-overwrite allow overwrite if no updates are found
--rebuild-all rebuild all packages
--mingw-w64-ver=NUMBER compile with MinGW-w64 VERSION ($mingw_w64_release_ver, svn)
[$mingw_w64_release_ver]
--cpu-count=NUMBER use NUMBER of cores/threads to compile with (1-$detected_cpu_count,
max) [max]
--binutils-ver=VERSION compile with binutils VERSION (snapshot, $binutils_release_ver,
cvs) [$binutils_release_ver]
--gcc-ver=VERSION compile with GCC VERSION ($gcc_release_ver, $gcc_old_release_ver, svn)
[$gcc_old_release_ver]
--pthreads-w32-ver=VERSION compile with Pthreads-w32 VERSION ($pthreads_w32_release_ver, cvs)
[cvs]
--gcc-langs=LANG1,LANG2 compile GCC with support for LANG (ada, c, c++,
fortran, go, java, objc, obj-c++, all) [c,c++,lto]
--enable-nls enable "Native Language Support"
--disable-shared compile a static only toolchain
--threads=LIB compile with support for thread LIB (winpthreads,
pthreads-w32, disable) [pthreads-w32]
--clean-build remove the unneeded directories after a successful
compile, leaving only the built toolchain. The
'build', 'source', and 'packages' directories will
be removed.
--enable-gendef compile the MinGW-w64 tools gendef.
--verbose show raw build output
Report bugs to <kyle.r.schwarz@gmail.com>.
EOF
}
print_error ()
{
printf '\n\nError. See build.log for more details\n\n'
exit 1
}
yes_no_sel () {
local usr_input
local question="$1"
shift
while [[ "$usr_input" != [YyNn] ]]; do
printf '%s [y/n]: ' "$question"
read usr_input
if [[ "$usr_input" != [YyNn] ]]; then
printf '\nYour selection was not vaild, please try again.\n\n'
fi
done
case "$usr_input" in
[Yy] ) return 0 ;;
[Nn] ) return 1 ;;
esac
}
var_in_array() {
local var=$1
local array
shift
for array; do
[[ $var = "$array" ]] && return
done
return 1
}
create_pkg_dirs () {
local pkg_name="$1"
mkdir -p "$pkg_name"
cd "$pkg_name" || exit 1
mkdir -p 'build' 'source'
cd 'source' || exit 1
}
use_cpu_count () {
if [[ "$cpu_count" -ge '2' ]]; then
while [[ "$select_cpu_count" != [1-$cpu_count] ]]; do
printf '\nA total of %d cores/threads were found. How many would you like to use to compile MinGW-w64? You can set this option with: "--cpu-count=NUMBER", see --help for more information. [1-%d]: ' "$detected_cpu_count" "$detected_cpu_count"
read select_cpu_count
done
cpu_count="$select_cpu_count"
fi
if [[ "$cpu_count" -lt '1' ]]; then
if yes_no_sel 'The number of cores/threads could not be found, would you like to manually enter the number of cores/threads your CPU has? (If "n" is selected, one core/thread will be used).'; then
printf '\nPlease enter the number of cores/threads your CPU has. (Make sure the number you enter is correct, trying to use more cores/threads than your CPU has can cause your system to crash).: '
read cpu_count
else
cpu_count='1'
fi
fi
}
pkg_touch_success () {
local pkg_name="$1"
local pkg_ver="$2"
local pkg_state="$3"
local pkg_arch="$4"
shift 4
mkdir -p "$pkgs_dir/touch-files/$pkg_name"
touch "$pkgs_dir/touch-files/$pkg_name/$pkg_name-$pkg_ver-$pkg_arch.$pkg_state"
}
check_pkg_touch_success () {
local pkg_name="$1"
local pkg_ver="$2"
local pkg_state="$3"
local pkg_arch="$4"
shift 4
if [[ -f "$pkgs_dir/touch-files/$pkg_name/$pkg_name-$pkg_ver-$pkg_arch.$pkg_state" ]]; then
return 0
fi
return 1
}
build_progress ()
{
if [[ "$verbose" != 'yes' ]]; then
if [[ "$1" = 'Done' ]]; then
printf '%s\n' "$1"
return 0
fi
local step_function="$1"
local step_name="$2"
shift 2
printf '[%d/%d]: %s %s... ' "$current_step" "$total_steps" "$step_name" "$step_function"
((current_step++))
fi
}
build_log ()
{
if [[ "$verbose" = 'yes' ]]; then
tee -a "$working_dir/build.log"
else
cat >>"$working_dir/build.log"
fi
}
choose_mingw_w64_ver () {
while [[ "$mingw_w64_ver_select" != [1-2] ]]; do
cat <<EOF
Which MinGW-w64 version would you like to build? You can set this option with: '--mingw-w64-ver=NUMBER', see --help for more information.
1. MinGW-w64 $mingw_w64_release_ver
2. MinGW-w64 SVN (default)
EOF
printf 'Choose which MinGW-w64 version would would like to build. [1-2]: '
read mingw_w64_ver_select
case "$mingw_w64_ver_select" in
1 ) mingw_w64_ver="$mingw_w64_release_ver" ;;
2 ) mingw_w64_ver='svn' ;;
* ) printf '\nYour selection was not valid, please try again.\n\n' ;;
esac
done
}
choose_binutils_ver () {
while [[ "$binutils_ver_select" != [1-3] ]]; do
cat <<EOF
Which Binutils version would you like to build? You can set this option with: '--binutils-ver=VERSION', see --help for more information.
1. Binutils snapshot
2. Binutils $binutils_release_ver (default)
3. Binutils cvs
EOF
printf 'Choose which Binutils version would would like to build. [1-2]: '
read binutils_ver_select
case "$binutils_ver_select" in
1 ) binutils_ver="snapshot" ;;
2 ) binutils_ver="$binutils_release_ver" ;;
3 ) binutils_ver='cvs' ;;
* ) printf '\nYour selection was not valid, please try again.\n\n' ;;
esac
done
}
choose_gcc_ver () {
while [[ "$gcc_ver_select" != [1-4] ]]; do
cat <<EOF
Which GCC version would you like to build? You can set this option with: '--gcc-ver=VERSION', see --help for more information.
1. GCC $gcc_release_ver
2. GCC $gcc_old_release_ver (default)
3. GCC $svn
EOF
printf 'Choose which GCC version would would like to build. [1-3]: '
read gcc_ver_select
case "$gcc_ver_select" in
1 ) gcc_ver="$gcc_release_ver" ;;
2 ) gcc_ver="$gcc_old_release_ver" ;;
3 ) gcc_ver='svn' ;;
* ) printf '\nYour selection was not valid, please try again.\n\n' ;;
esac
done
}
configure_gcc () {
if [[ "$enabled_langs" != *,* ]]; then
printf -v enabled_langs '%s,' "${enabled_langs[@]}"
enabled_langs="${enabled_langs%,}"
fi
case "$gcc_ver" in
* ) "../source/gcc-$gcc_ver/configure" --build="$system_type" --target="$mingw_w64_target" "${static_build[@]}" "${disable_nls[@]}" --disable-multilib --prefix="$mingw_w64_prefix" --with-sysroot="$mingw_w64_prefix" --with-mpc="$mpc_prefix" --with-mpfr="$mpfr_prefix" --with-gmp="$gmp_prefix" --with-host-libstdcxx="-lstdc++ ${gcc_stdcxx_flags[*]}" --with-cloog="$cloog_prefix" --with-isl="$isl_prefix" --enable-languages="$enabled_langs" --enable-threads=win32 --enable-fully-dynamic-string --enable-lto > >(build_log) 2>&1 || exit 1 ;;
esac
}
choose_static_build () {
if yes_no_sel "Would you like to build a fully static build? You can set this option with: '--disable-shared', see --help for more information. (Select \"n\" if you are not sure, \"n\" is the default)."; then
static_build=('--disable-shared' '--enable-static')
else
static_build=('--enable-shared' '--disable-static')
fi
}
choose_disable_nls () {
if yes_no_sel "Would you like to disable NLS support? Native Language Support (NLS), which lets GCC/Binutils output diagnostics in languages other than American English. You can set this option with: '--disable-nls', see --help for more information. (Select \"y\" if you are not sure, \"y\" is the default)."; then
disable_nls=('--disable-nls')
else
disable_nls=('--enable-nls')
fi
}
choose_lang_sel () {
if yes_no_sel "Would you like to manualy configure which languages GCC will support? You can set this option with: '--gcc-langs=LANG1,LANG2', see --help for more information. (if \"n\" is input only C and C++ will be enabled)."; then
set_langs
else
enabled_langs=('c' 'c++')
fi
}
set_langs () {
all_langs=('ada' 'c' 'c++' 'fortran' 'go' 'java' 'objc' 'obj-c++')
formated_langs=('Ada' 'C' 'C++' 'Fortran' 'Go' 'Java' 'Objective-C' 'Objective-C++')
cat <<'EOF'
Choose which languages you would like GCC to support.
1. C and C++ (default)
2. All detected
3. Manually choose for each language.
EOF
printf 'Input your choice [1-3]: '
read sel_set_langs
case "$sel_set_langs" in
1 ) enabled_langs=('c' 'c++')
clear
confirm_langs ;;
2 ) enabled_langs=('all')
clear
confirm_langs ;;
3 ) custom_langs ;;
* ) printf '\nYour selection was not vaild, please try again.\n\n'
set_langs
esac
}
custom_langs () {
unset enabled_langs
local num='0'
for lang in "${formated_langs[@]}"; do
if yes_no_sel "Would you like to build GCC with $lang support?"; then
enabled_langs=("${enabled_langs[@]}" "${all_langs[$num]}")
fi
((num++))
done
confirm_langs
}
confirm_langs () {
if [[ "$enabled_langs" = 'all' ]]; then
printf 'GCC will attempt to detect and build all of the following languages. It will silently disable the languages it can not find. (A "*" indicates that GCC will attempt to support the language).\n'
else
printf 'The following languages will be supported in GCC. If one of the selected languages can not be found on your system when GCC is built it will fail and you will need to rerun this script after you have installed the failed language. (A "*" indicates that GCC will support the language).\n'
fi
local num='0'
for lang in "${all_langs[@]}"; do
if var_in_array "$lang" "${enabled_langs[@]}" || [[ "${enabled_langs}" = 'all' ]]; then
printf ' [*] %s\n' "${formated_langs[$num]}"
else
printf ' [ ] %s\n' "${formated_langs[$num]}"
fi
((num++))
done
printf 'Are the languages selected correct? (if "n" is selected, you will be allowed to reconfigure you language selection). [y/n]: '
read user_input
case "$user_input" in
[Nn] ) clear
unset enabled_langs
set_langs ;;
[Yy] ) ;;
* ) printf '\nYour selection was not valid, please try again.\n\n'
confirm_langs ;;
esac
}
configure_build_fn () {
if yes_no_sel 'Would you like to manually choose which package versions to build into MinGW-w64 yourself, and configure the build?'; then
if [[ -z "$mingw_w64_ver" ]]; then
choose_mingw_w64_ver
fi
if [[ -z "$binutils_ver" ]]; then
choose_binutils_ver
fi
if [[ -z "$gcc_ver" ]]; then
choose_gcc_ver
fi
if [[ -z "$static_build" ]]; then
choose_static_build
fi
if [[ -z "$disable_nls" ]]; then
choose_disable_nls
fi
if [[ -z "$enabled_langs" ]]; then
choose_lang_sel
fi
default_configure
else
default_configure
fi
}
default_configure () {
default_config='yes'
if [[ -z "$mingw_w64_ver" ]]; then
mingw_w64_ver="$mingw_w64_release_ver"
fi
if [[ -z "$binutils_ver" ]]; then
binutils_ver="$binutils_release_ver"
fi
if [[ -z "$gcc_ver" ]]; then
gcc_ver="$gcc_old_release_ver"
fi
if [[ -z "$disable_nls" ]]; then
disable_nls=('--disable-nls')
fi
if [[ -z "$enabled_langs" ]]; then
enabled_langs=('c' 'c++')
fi
if [[ -z "$thread_lib" ]]; then
thread_lib='pthreads-w32'
fi
if [[ -z "$cpu_count" ]]; then
cpu_count="$detected_cpu_count"
fi
}
download_extract () {
local download_urls=("$1" "$2")
shift 2
for download_url in "${download_urls[@]}"; do
archive="${download_url##*/}"
package_name="${archive%.tar*}"
if [[ -d "$package_name" ]]; then
return 0
fi
case "$archive" in
*.tar.gz ) archive_type='gzip' ;;
*.tar.bz2 ) archive_type='bzip2' ;;
*.tar.xz ) archive_type='xz' ;;
esac
if [[ ! -f "$archive" ]]; then
build_progress "$archive" 'Downloading'
wget -nv -t 5 "$download_url" > >(build_log) 2>&1
build_progress 'Done'
fi
if [[ ! -d "$package_name" ]]; then
build_progress "$archive" 'Extracting'
if "$archive_type" -d <"$archive" | pax -r ; then
build_progress 'Done'
return 0
else
rm -rf "$archive" "$package_name"
build_progress "$archive" 'Downloading'
wget -nv "$download_url" > >(build_log) 2>&1
build_progress 'Done'
build_progress "$archive" 'Extracting'
"$archive_type" -d <"$archive" | pax -r
build_progress 'Done'
fi
fi
done
if [[ ! -d "$package_name" ]]; then
exit 1
fi
}
clean_build () {
cd '..'
rm -fr 'build' || exit 1
mkdir -p 'build'
cd 'build' || exit 1
}
build_winpthreads () {
cd "$mingw_w64_build_dir" || exit 1
rm -fr 'winpthreads '
mkdir -p 'winpthreads'
cd 'winpthreads' || exit 1
local mingw_w64_target="$1"
local mingw_w64_prefix="$2"
shift 3
build_progress 'winpthreads' 'Configuring'
"../../source/mingw-w64-$mingw_w64_ver/mingw-w64-libraries/winpthreads/configure" --build="$system_type" --host="$mingw_w64_target" "${static_build[@]}" --prefix="$mingw_w64_prefix" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'winpthreads' 'Building'
make > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'winpthreads' 'Installing'
make install > >(build_log) 2>&1 || exit 1
build_progress 'Done'
}
build_binutils () {
cd "$pkgs_dir" || exit 1
create_pkg_dirs 'binutils' || exit 1
if [[ "$binutils_ver" != 'cvs' ]]; then
if [[ "$binutils_ver" = "snapshot" ]]; then
download_extract "ftp://sourceware.org/pub/binutils/snapshots/binutils.tar.bz2"
binutils_ver="$(find . -name binutils -type d)"; binutils_ver="${binutils_ver##*-}"; binutils_ver="${binutils_ver%%/*}"
else
download_extract "http://ftp.gnu.org/gnu/binutils/binutils-$binutils_ver.tar.bz2" "ftp://ftp.gnu.org/gnu/binutils/binutils-$binutils_ver.tar.bz2"
fi
else
if [[ -d 'binutils-cvs' ]]; then
cd 'binutils-cvs' || exit 1
read -r oldmd5 _ < <(md5sum './CVS/Entries')
build_progress 'binutils-cvs' 'Updating'
cvs update || exit 1
build_progress 'Done'
read -r newmd5 _ < <(md5sum './CVS/Entries')
if [[ "$oldmd5" != "$newmd5" ]]; then
rm -rf "$pkgs_dir/touch-files/binutils/binutils-cvs-$uname_m."*
fi
cd '..'
else
build_progress 'binutils-cvs' 'Downloading'
cvs -d :pserver:anoncvs@sourceware.org:/cvs/src checkout binutils > >(build_log) 2>&1 || exit 1
build_progress 'Done'
mv 'src' 'binutils-cvs'
fi
fi
cd '../build' || exit 1
mkdir -p "$mingw_w64_target"
cd "$mingw_w64_target" || exit 1
if ! check_pkg_touch_success 'binutils' "$binutils_ver" 'configure' "$mingw_w64_target"; then
cd '..'
rm -rf "$mingw_w64_target" || exit 1
mkdir "$mingw_w64_target"
cd "$mingw_w64_target" || exit 1
build_progress 'binutils' 'Configuring'
CC=gcc "../../source/binutils-$binutils_ver/configure" --build="$system_type" --target="$mingw_w64_target" "${static_build[@]}" "${disable_nls[@]}" --disable-multilib --with-sysroot="$mingw_w64_prefix" --prefix="$mingw_w64_prefix" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
fi
pkg_touch_success 'binutils' "$binutils_ver" 'configure' "$mingw_w64_target"
if ! check_pkg_touch_success 'binutils' "$binutils_ver" 'compile' "$mingw_w64_target"; then
build_progress 'binutils' 'Building'
make -j "$cpu_count" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
fi
pkg_touch_success 'binutils' "$binutils_ver" 'compile' "$mingw_w64_target"
build_progress 'binutils' 'Installing'
make install > >(build_log) 2>&1 || exit 1
build_progress 'Done'
}
std_compile ()
{
local pkg="$1"
local ver="$2"
local url="$3"
shift 3
if check_pkg_touch_success "$pkg" "$ver" 'install' "$uname_m"; then
return
fi
cd "$pkgs_dir" || exit 1
create_pkg_dirs "$pkg" || exit 1
download_extract "$url"
if ! check_pkg_touch_success "$pkg" "$ver" 'configure' "$uname_m"; then
clean_build
build_progress "$pkg" 'Configuring'
$@ > >(build_log) 2>&1 || print_error
build_progress 'Done'
fi
pkg_touch_success "$pkg" "$ver" 'configure' "$uname_m"
if ! check_pkg_touch_success "$pkg" "$ver" 'compile' "$uname_m"; then
build_progress "$pkg" 'Building'
make -j "$cpu_count" > >(build_log) 2>&1 || print_error
build_progress 'Done'
fi
pkg_touch_success "$pkg" "$ver" 'compile' "$uname_m"
if ! check_pkg_touch_success "$pkg" "$ver" 'install' "$uname_m"; then
build_progress "$pkg" 'Installing'
make install > >(build_log) 2>&1 || print_error
build_progress 'Done'
fi
pkg_touch_success "$pkg" "$ver" 'install' "$uname_m"
}
build_mingw_w64 () {
local mingw_w64_target="$1"
local mingw_w64_prefix="$2"
shift 2
if [[ "$rebuild" = 'yes' ]]; then
rm -rf "$pkgs_dir/touch-files"
fi
cd "$working_dir" || exit 1
rm -fr "$mingw_w64_prefix"
cd 'pkgs' || exit 1
mkdir -p 'touch-files'
build_binutils
export PATH="$mingw_w64_prefix/bin:$PATH"
cd "$mingw_w64_build_dir" || exit 1
clean_build
mkdir -p 'headers' 'crt'
cd 'headers' || exit 1
build_progress 'mingw-w64 headers' 'Configuring'
"$mingw_w64_source_dir/mingw-w64-$mingw_w64_ver/mingw-w64-headers/configure" --enable-sdk=all --build="$system_type" --host="$mingw_w64_target" --prefix="$mingw_w64_prefix" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'mingw-w64 headers' 'Installing'
make install > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cd "$mingw_w64_prefix" || exit 1
ln -s "./$mingw_w64_target" './mingw'
if [[ ! -d "./$mingw_w64_target/include" ]]; then
cd "./$mingw_w64_target" || exit 1
ln -s '../include' './include'
cd "$mingw_w64_prefix" || exit 1
fi
case "$gcc_ver" in
$gcc_release_ver ) cloog_ver='0.18.1'; isl_ver='0.12.2' ;;
$gcc_old_release_ver ) cloog_ver='0.18.0'; isl_ver='0.11.1' ;;
esac
mpfr_prefix="$pkgs_dir/mpfr/mpfr-$mpfr_release_ver-$uname_m"
mpc_prefix="$pkgs_dir/mpc/mpc-$mpc_release_ver-$uname_m"
cloog_prefix="$pkgs_dir/cloog/cloog-$cloog_ver-$uname_m"
isl_prefix="$pkgs_dir/isl/isl-$isl_ver-$uname_m"
gmp_prefix="$pkgs_dir/gmp/gmp-$gmp_release_ver-$uname_m"
if [[ -n $CC ]]; then
old_cc="$CC"
export CC=gcc
fi
# Build gmp
std_compile 'gmp' "$gmp_release_ver" "http://ftp.gnu.org/gnu/gmp/gmp-$gmp_release_ver.tar.xz" "../source/gmp-6.0.0/configure" --build="$system_type" --prefix="$gmp_prefix" --enable-fat --disable-shared --enable-static --enable-cxx CPPFLAGS='-fexceptions'
#build mpfr
std_compile 'mpfr' "$mpfr_release_ver" "http://ftp.gnu.org/gnu/mpfr/mpfr-$mpfr_release_ver.tar.xz" "../source/mpfr-$mpfr_release_ver/configure" --build="$system_type" --prefix="$mpfr_prefix" --disable-shared --enable-static --with-gmp="$gmp_prefix"
#build mpc
std_compile 'mpc' "$mpc_release_ver" "http://ftp.gnu.org/gnu/mpc/mpc-$mpc_release_ver.tar.gz" "../source/mpc-$mpc_release_ver/configure" --build="$system_type" --prefix="$mpc_prefix" --with-gmp="$gmp_prefix" --with-mpfr="$mpfr_prefix" --disable-shared --enable-static
#build isl
std_compile 'isl' "$isl_ver" "ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-$isl_ver.tar.bz2" "../source/isl-$isl_ver/configure" --prefix="$isl_prefix" --build="$system_type" --enable-static --disable-shared --with-gmp-prefix="$gmp_prefix" --with-piplib=no --with-clang=no
#build cloog
std_compile 'cloog' "$cloog_ver" "ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-$cloog_ver.tar.gz" "../source/cloog-$cloog_ver/configure" --prefix="$cloog_prefix" --build="$system_type" --enable-static --disable-shared --with-bits=gmp --with-isl=bundled --with-gmp-prefix="$gmp_prefix"
export CC="$old_cc"
# Build GCC (GCC only)
cd "$pkgs_dir" || exit 1
create_pkg_dirs 'gcc'
cd "$pkgs_dir/gcc/source" || exit 1
if [[ "$gcc_ver" != 'svn' ]]; then
download_extract "http://ftp.gnu.org/gnu/gcc/gcc-$gcc_ver/gcc-$gcc_ver.tar.bz2" "ftp://ftp.gnu.org/gnu/gcc/gcc-$gcc_ver/gcc-$gcc_ver.tar.bz2"
else
if [[ -d 'gcc-svn' ]]; then
cd 'gcc-svn' || exit 1
build_progress 'gcc-svn' 'Updating'
svn update > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cd '..'
else
build_progress 'gcc-svn' 'Downloading'
svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc-svn > >(build_log) 2>&1 || exit 1
build_progress 'Done'
fi
fi
clean_build
build_progress 'gcc' 'Configuring'
configure_gcc "$gcc_ver" || exit 1
build_progress 'Done'
build_progress 'all-gcc' 'Building'
make -j "$cpu_count" all-gcc > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gcc' 'Installing'
make install-gcc > >(build_log) 2>&1 || exit 1
build_progress 'Done'
# Build mingw-w64 CRT
cd "$mingw_w64_build_dir/crt" || exit 1
build_progress 'mingw-w64 crt' 'Configuring'
"$mingw_w64_source_dir/mingw-w64-$mingw_w64_ver/mingw-w64-crt/configure" --build="$system_type" --host="$mingw_w64_target" --prefix="$mingw_w64_prefix" --with-sysroot="$mingw_w64_prefix" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'mingw-w64 crt' 'Building'
make -j "$cpu_count" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'mingw-w64 crt' 'Installing'
make install > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cd "$mingw_w64_prefix" || exit 1
mv "./$mingw_w64_target/lib/"* './lib/'
rm -fr "./$mingw_w64_target/lib"
cd "./$mingw_w64_target"
ln -s '../lib' './lib'
# Build GCC
cd "$pkgs_dir/gcc/build" || exit 1
build_progress 'gcc target-libgcc' 'Building'
make -j "$cpu_count" all-target-libgcc > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gcc target-libgcc' 'Installing'
make -j "$cpu_count" install-target-libgcc > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gcc' 'Building'
make -j "$cpu_count" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gcc' 'Installing'
make install-strip > >(build_log) 2>&1 || exit 1
build_progress 'Done'
if [[ "$thread_lib" != 'disable' ]]; then
build_thread_lib "$mingw_w64_target" "$mingw_w64_prefix" || exit 1
fi
if [[ "$enable_gendef" = 'yes' ]]; then
cd "$mingw_w64_build_dir" || exit 1
rm -fr 'gendef'
mkdir 'gendef'
cd 'gendef' || exit 1
build_progress 'gendef' 'Configuring'
"$mingw_w64_source_dir/mingw-w64-$mingw_w64_ver/mingw-w64-tools/gendef/configure" --build="$system_type" --prefix="$mingw_w64_prefix" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gendef' 'Building'
make > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress 'gendef' 'Installing'
make install > >(build_log) 2>&1 || exit 1
build_progress 'Done'
fi
return 0
}
clean_build_fn () {
if [[ "$clean_build" = 'yes' ]]; then
cd "$working_dir" && rm -fr 'build' 'pkgs' 'source'
return
fi
if [[ "$default_config" = 'yes' ]]; then
return
fi
unset user_input
printf '\n'
while [[ "$user_input" != [YyNn] ]]; do
printf 'Would you like to clean the build, leaving only the built toolchain? You can set this option with: "--clean-build", see --help for more information. The "build", "pkgs", and "source" directories along with all files within them will be removed if "y" is selected. [y/n]: '
read user_input
if [[ "$user_input" = [Yy] ]]; then
cd "$working_dir" && rm -fr 'build' 'pkgs' 'source' 'build.log'
fi
if [[ "$user_input" != [YyNn] ]]; then
printf '\n\nYour selection was not vaild, please try again.\n\n'
fi
done
}
download_source () {
case "$1" in
'multi' ) if [[ -d "$mingw_w64_i686_prefix" && -d "$mingw_w64_x86_64_prefix" ]]; then prefix_present='yes'; fi ;;
'win32' ) if [[ -d "$mingw_w64_i686_prefix" ]]; then prefix_present='yes'; fi ;;
'win64' ) if [[ -d "$mingw_w64_x86_64_prefix" ]]; then prefix_present='yes'; fi ;;
esac
shift
mkdir -p 'pkgs' 'source' 'build'
cd 'pkgs' || exit 1
rm -fr 'config.guess'
build_progress 'config.guess' 'Downloading'
wget -nv -O config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' > >(build_log) 2>&1 || { ping -c 1 git.savannah.gnu.org >/dev/null 2>&1 || printf '\nsavannah.gnu.org seems to be offline right now and is needed to download the file "config.guess", please try again later.\n\n'; rm -f 'config.guess' && exit 1; }
build_progress 'Done'
system_type="$(sh config.guess)"
cd "$mingw_w64_source_dir" || exit 1
if [[ "$mingw_w64_ver" = 'svn' ]]; then
if [[ -d 'mingw-w64-svn' ]]; then
cd 'mingw-w64-svn' || exit 1
svn_ver_before=$(sed -n 4p '.svn/entries')
svn update || exit 1
svn_ver_after=$(sed -n 4p '.svn/entries')
if [[ "$allow_overwrite" != 'yes' && "$svn_ver_before" = "$svn_ver_after" && "$prefix_present" = 'yes' ]]; then
if ! yes_no_sel "MinGW-w64 is already the latest version, continue with the build anyway? You can set this option with: '--allow-overwrite', see '--help' for more information."; then
exit 0
fi
fi
else
svn checkout svn://svn.code.sf.net/p/mingw-w64/code/trunk mingw-w64-svn || exit 1
fi
else
if [[ -d "mingw-w64-$mingw_w64_release_ver" && "$allow_overwrite" != 'yes' && "$prefix_present" = 'yes' ]]; then
if ! yes_no_sel "MinGW-w64 is already the latest version, continue with the build anyway? You can set this option with: '--allow-overwrite', see '--help' for more information."; then
exit 0
fi
fi
if [[ ! -d "mingw-w64-$mingw_w64_release_ver" || ! -f "mingw-w64-$mingw_w64_release_ver.tar.bz2" ]]; then
rm -f "mingw-w64-$mingw_w64_release_ver.tar.bz2" "mingw-w64-$mingw_w64_release_ver"
build_progress "mingw-w64-$mingw_w64_release_ver.tar.bz2" 'Downloading'
wget -nv -O "mingw-w64-$mingw_w64_release_ver.tar.bz2" http://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v${mingw_w64_release_ver}.tar.bz2 > >(build_log) 2>&1 || exit 1
build_progress 'Done'
build_progress "mingw-w64-$mingw_w64_release_ver.tar.bz2" 'Extracting'
bzip2 -d <"mingw-w64-$mingw_w64_release_ver.tar.bz2" | pax -r
build_progress 'Done'
mv "mingw-w64-v$mingw_w64_release_ver" "mingw-w64-$mingw_w64_release_ver"
fi
fi
}
check_missing_packages () {
local check_packages=('bison' 'm4' 'flex' 'git' 'svn' 'gcc' 'yasm' 'cvs' 'g++' 'make' 'xz' 'bzip2' 'pax' 'gunzip')
for package in "${check_packages[@]}"; do
command -v "$package" >/dev/null || missing_packages=("$package" "${missing_packages[@]}")
done
if [[ -n "${missing_packages[@]}" ]]; then
printf '\nCould not find the following packages: %s\n' "${missing_packages[*]}"
printf 'Install the missing packages before running this script.\n\n'
exit 1
fi
}
build_pthreads_w32 () {
if [[ -z "$pthreads_w32_ver" ]]; then
pthreads_w32_ver='cvs'
fi
local target prefix
target="$1"
prefix="$2"
shift 2
cd "$pkgs_dir" || exit 1
create_pkg_dirs 'pthread-w32' || exit 1
if [[ "$pthreads_w32_ver" = "$pthreads_w32_release_ver" ]]; then
download_extract "ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-$pthreads_w32_release_ver-release.tar.gz"
if [[ ! -d "pthreads-w32-$pthreads_w32_release_ver" ]]; then
mv "pthreads-w32-$pthreads_w32_release_ver-release" "pthreads-w32-$pthreads_w32_release_ver" || exit 1
fi
else
unset oldmd5 newmd5
if [[ -d 'pthreads-w32-cvs' ]]; then
cd 'pthreads-w32-cvs' || exit 1
build_progress 'pthreads-w32 cvs' 'Updating'
cvs update > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cd '..'
else
build_progress 'pthreads-w32 cvs' 'Downloading'
cvs -d :pserver:anonymous@sourceware.org:/cvs/pthreads-win32 checkout pthreads > >(build_log) 2>&1 || exit 1
build_progress 'Done'
mv 'pthreads' 'pthreads-w32-cvs'
fi
fi
cd "pthreads-w32-$pthreads_w32_ver" || exit 1
make realclean > >(build_log) 2>&1 || exit 1
if [[ "${static_build[@]}" != *"disable-shared"* ]]; then
build_progress 'pthreads-w32 shared' 'Building'
make CROSS="$target-" realclean GC ARCH="$pthread_arch" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cp 'pthreadGC2.dll' "$prefix/lib/" || exit 1
cd "$prefix/lib" || exit 1
ln -s "./pthreadGC2.dll" "./libpthread.dll"
cd "$pkgs_dir/pthread-w32/source/pthreads-w32-$pthreads_w32_ver" || exit 1
fi
build_progress 'pthreads-w32 static' 'Building'
make CROSS="$target-" realclean GC-static ARCH="$pthread_arch" > >(build_log) 2>&1 || exit 1
build_progress 'Done'
cp 'libpthreadGC2.a' "$prefix/lib/" || exit 1
cp 'pthread.h' 'sched.h' 'semaphore.h' "$prefix/include/" || exit 1
cd "$prefix/lib" || exit 1
ln -s "./libpthreadGC2.a" "./libpthread.a"
cd '../include' || exit 1
for file in 'pthread.h' 'sched.h' 'semaphore.h'; do
if ! ed -s "$prefix/include/$file" <<< $',s/ __declspec (dllexport)//g\n,s/ __declspec (dllimport)//g\nw\nq' > >(build_log) 2>&1; then
mv "$file" "$file".orig
sed 's/ __declspec (dllexport)//g;s/ __declspec (dllimport)//g' "$file".orig > "$file"
rm -f "$file".orig
fi
done
}
build_thread_lib () {
local target prefix
target="$1"
prefix="$2"
shift 2
case "$thread_lib" in
'winpthreads' ) build_winpthreads "$target" "$prefix" ;;
'pthreads-w32' ) build_pthreads_w32 "$target" "$prefix" ;;
* ) build_pthreads_w32 "$target" "$prefix" ;;
esac
}
completed_build () {
local arch="$1"
case "$arch" in
'win32' ) mingw_w64_path_prefix="$mingw_w64_i686_prefix" ;;
'win64' ) mingw_w64_path_prefix="$mingw_w64_x86_64_prefix" ;;
esac
printf 'The MinGW-w64 bin directory needs to be added to the PATH variable so the system can find it, for %s this can be done with: export PATH="%s/bin:$PATH"\n' "${arch^}" "$mingw_w64_path_prefix"
}
no_errors='MinGW-w64 has been built without errors.'
calculate_steps ()
{
case "$arch" in
'multi' ) total_steps='68';;
'win32' ) total_steps='50';;
'win64' ) total_steps='50';;
esac
if [[ "$arch" = 'multi' ]]; then
if [[ "${static_build[@]}" = *"disable-shared"* ]]; then
total_steps=$((total_steps-2))
fi
if [[ "$enable_gendef" = 'yes' ]]; then
total_steps=$((total_steps+6))
fi
else
if [[ "${static_build[@]}" = *"disable-shared"* ]]; then
total_steps=$((total_steps-1))
fi
if [[ "$enable_gendef" = 'yes' ]]; then
total_steps=$((total_steps+3))
fi
fi
}
build_mingw_w64_toolchain () {