-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcommon-apps-functions-source.sh
3738 lines (2913 loc) · 123 KB
/
common-apps-functions-source.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
# -----------------------------------------------------------------------------
# This file is part of the xPack distribution.
# (https://xpack.github.io)
# Copyright (c) 2020 Liviu Ionescu.
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose is hereby granted, under the terms of the MIT license.
# -----------------------------------------------------------------------------
# Helper script used in xPack Developer Tools build scripts.
# As the name implies, it should contain only functions and
# should be included with 'source' by the build scripts (both native
# and container).
# -----------------------------------------------------------------------------
function build_patchelf()
{
# https://nixos.org/patchelf.html
# https://github.com/NixOS/patchelf
# https://github.com/NixOS/patchelf/releases/
# https://github.com/NixOS/patchelf/releases/download/0.12/patchelf-0.12.tar.bz2
# https://github.com/NixOS/patchelf/archive/0.12.tar.gz
# https://github.com/archlinux/svntogit-community/blob/packages/patchelf/trunk/PKGBUILD
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/patchelf.rb
# 2016-02-29, "0.9"
# 2019-03-28, "0.10"
# 2020-06-09, "0.11"
# 2020-08-27, "0.12"
# 05 Aug 2021, "0.13"
# 05 Dec 2021, "0.14.3"
local patchelf_version="$1"
local patchelf_src_folder_name="patchelf-${patchelf_version}"
local patchelf_archive="${patchelf_src_folder_name}.tar.bz2"
# GitHub release archive.
local patchelf_github_archive="${patchelf_version}.tar.gz"
local patchelf_url="https://github.com/NixOS/patchelf/archive/${patchelf_github_archive}"
local patchelf_folder_name="${patchelf_src_folder_name}"
mkdir -pv "${LOGS_FOLDER_PATH}/${patchelf_folder_name}"
local patchelf_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${patchelf_folder_name}-installed"
if [ ! -f "${patchelf_stamp_file_path}" ]
then
cd "${SOURCES_FOLDER_PATH}"
download_and_extract "${patchelf_url}" "${patchelf_archive}" \
"${patchelf_src_folder_name}"
(
if [ ! -x "${SOURCES_FOLDER_PATH}/${patchelf_src_folder_name}/configure" ]
then
cd "${SOURCES_FOLDER_PATH}/${patchelf_src_folder_name}"
xbb_activate_installed_dev
run_verbose bash ${DEBUG} "bootstrap.sh"
fi
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${patchelf_folder_name}/autogen-output-$(ndate).txt"
(
mkdir -pv "${BUILD_FOLDER_PATH}/${patchelf_folder_name}"
cd "${BUILD_FOLDER_PATH}/${patchelf_folder_name}"
xbb_activate_installed_dev
CPPFLAGS="${XBB_CPPFLAGS}"
CFLAGS="${XBB_CFLAGS_NO_W}"
CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
# Wihtout -static-libstdc++, it fails with
# /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found
LDFLAGS="${XBB_LDFLAGS_APP_STATIC_GCC}"
if [ "${TARGET_PLATFORM}" == "linux" ]
then
LDFLAGS+=" -Wl,-rpath,${LD_LIBRARY_PATH}"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running patchelf configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${patchelf_src_folder_name}/configure" --help
fi
config_options=()
config_options+=("--prefix=${BINS_INSTALL_FOLDER_PATH}")
config_options+=("--libdir=${LIBS_INSTALL_FOLDER_PATH}/lib")
config_options+=("--includedir=${LIBS_INSTALL_FOLDER_PATH}/include")
# config_options+=("--datarootdir=${LIBS_INSTALL_FOLDER_PATH}/share")
config_options+=("--mandir=${LIBS_INSTALL_FOLDER_PATH}/share/man")
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
config_options+=("--disable-debug") # HB
config_options+=("--disable-dependency-tracking") # HB
if [ "${IS_DEVELOP}" == "y" ]
then
config_options+=("--disable-silent-rules") # HB
fi
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${patchelf_src_folder_name}/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${patchelf_folder_name}/config-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${patchelf_folder_name}/configure-output-$(ndate).txt"
fi
(
echo
echo "Running patchelf make..."
# Build.
run_verbose make -j ${JOBS}
if [ "${WITH_STRIP}" == "y" ]
then
run_verbose make install-strip
else
run_verbose make install
fi
# Fails.
# x86_64: FAIL: set-rpath-library.sh (Segmentation fault (core dumped))
# x86_64: FAIL: set-interpreter-long.sh (Segmentation fault (core dumped))
# make -C tests -j1 check
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${patchelf_folder_name}/make-output-$(ndate).txt"
copy_license \
"${SOURCES_FOLDER_PATH}/${patchelf_src_folder_name}" \
"${patchelf_folder_name}"
)
(
test_patchelf "${BINS_INSTALL_FOLDER_PATH}/bin"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${patchelf_folder_name}/test-output-$(ndate).txt"
hash -r
touch "${patchelf_stamp_file_path}"
else
echo "Component patchelf already installed."
fi
tests_add "test_patchelf" "${BINS_INSTALL_FOLDER_PATH}/bin"
}
function test_patchelf()
{
local test_bin_folder_path="$1"
(
echo
echo "Checking the patchelf binaries shared libraries..."
show_libs "${test_bin_folder_path}/patchelf"
echo
echo "Testing if patchelf binaries start properly..."
run_app "${test_bin_folder_path}/patchelf" --version
run_app "${test_bin_folder_path}/patchelf" --help
)
}
# -----------------------------------------------------------------------------
function build_automake()
{
# https://www.gnu.org/software/automake/
# https://ftp.gnu.org/gnu/automake/
# https://github.com/archlinux/svntogit-packages/tree/packages/automake/trunk
# https://archlinuxarm.org/packages/any/automake/files/PKGBUILD
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=automake-git
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/automake.rb
# 2015-01-05, "1.15"
# 2018-02-25, "1.16"
# 2020-03-21, "1.16.2"
# 2020-11-18, "1.16.3"
# 2021-07-26, "1.16.4"
# 2021-10-03, "1.16.5"
local automake_version="$1"
local automake_src_folder_name="automake-${automake_version}"
local automake_archive="${automake_src_folder_name}.tar.xz"
local automake_url="https://ftp.gnu.org/gnu/automake/${automake_archive}"
local automake_folder_name="${automake_src_folder_name}"
# help2man: can't get `--help' info from automake-1.16
# Try `--no-discard-stderr' if option outputs to stderr
mkdir -pv "${LOGS_FOLDER_PATH}/${automake_folder_name}"
local automake_patch_file_name="${automake_folder_name}.patch"
local automake_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${automake_folder_name}-installed"
if [ ! -f "${automake_stamp_file_path}" ]
then
cd "${SOURCES_FOLDER_PATH}"
download_and_extract "${automake_url}" "${automake_archive}" \
"${automake_src_folder_name}" \
"${automake_patch_file_name}"
(
mkdir -pv "${BUILD_FOLDER_PATH}/${automake_folder_name}"
cd "${BUILD_FOLDER_PATH}/${automake_folder_name}"
xbb_activate_installed_dev
CPPFLAGS="${XBB_CPPFLAGS}"
CFLAGS="${XBB_CFLAGS_NO_W}"
CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
# LDFLAGS="${XBB_LDFLAGS_APP_STATIC_GCC}"
LDFLAGS="${XBB_LDFLAGS_APP}"
if [ "${TARGET_PLATFORM}" == "linux" ]
then
LDFLAGS+=" -Wl,-rpath,${LD_LIBRARY_PATH}"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running automake configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${automake_src_folder_name}/configure" --help
fi
config_options=()
config_options+=("--prefix=${BINS_INSTALL_FOLDER_PATH}")
config_options+=("--libdir=${LIBS_INSTALL_FOLDER_PATH}/lib")
config_options+=("--includedir=${LIBS_INSTALL_FOLDER_PATH}/include")
# config_options+=("--datarootdir=${LIBS_INSTALL_FOLDER_PATH}/share")
config_options+=("--mandir=${LIBS_INSTALL_FOLDER_PATH}/share/man")
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${automake_src_folder_name}/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${automake_folder_name}/config-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${automake_folder_name}/configure-output-$(ndate).txt"
fi
(
echo
echo "Running automake make..."
# Build.
run_verbose make -j ${JOBS}
if [ "${WITH_STRIP}" == "y" ]
then
run_verbose make install-strip
else
run_verbose make install
fi
# Takes too long and some tests fail.
# XFAIL: t/pm/Cond2.pl
# XFAIL: t/pm/Cond3.pl
# ...
if false # [ "${RUN_LONG_TESTS}" == "y" ]
then
run_verbose make -j1 check
fi
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${automake_folder_name}/make-output-$(ndate).txt"
copy_license \
"${SOURCES_FOLDER_PATH}/${automake_src_folder_name}" \
"${automake_folder_name}"
)
(
test_automake "${BINS_INSTALL_FOLDER_PATH}/bin"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${automake_folder_name}/test-output-$(ndate).txt"
hash -r
touch "${automake_stamp_file_path}"
else
echo "Component automake already installed."
fi
tests_add "test_automake" "${BINS_INSTALL_FOLDER_PATH}/bin"
}
function test_automake()
{
local test_bin_folder_path="$1"
(
echo
echo "Testing if automake scripts start properly..."
run_app "${test_bin_folder_path}/automake" --version
)
}
# -----------------------------------------------------------------------------
function build_findutils()
{
# https://www.gnu.org/software/findutils/
# https://ftp.gnu.org/gnu/findutils/
# https://ftp.gnu.org/gnu/findutils/findutils-4.8.0.tar.xz
# 2021-01-09, "4.8.0"
local findutils_version="$1"
local findutils_src_folder_name="findutils-${findutils_version}"
local findutils_archive="${findutils_src_folder_name}.tar.xz"
local findutils_url="https://ftp.gnu.org/gnu/findutils/${findutils_archive}"
local findutils_folder_name="${findutils_src_folder_name}"
mkdir -pv "${LOGS_FOLDER_PATH}/${findutils_folder_name}"
local findutils_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${findutils_folder_name}-installed"
if [ ! -f "${findutils_stamp_file_path}" ]
then
cd "${SOURCES_FOLDER_PATH}"
download_and_extract "${findutils_url}" "${findutils_archive}" \
"${findutils_src_folder_name}"
(
if [ ! -x "${SOURCES_FOLDER_PATH}/${findutils_src_folder_name}/configure" ]
then
cd "${SOURCES_FOLDER_PATH}/${findutils_src_folder_name}"
xbb_activate_installed_dev
run_verbose bash ${DEBUG} "bootstrap.sh"
fi
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${findutils_folder_name}/autogen-output-$(ndate).txt"
(
mkdir -pv "${LIBS_BUILD_FOLDER_PATH}/${findutils_folder_name}"
cd "${LIBS_BUILD_FOLDER_PATH}/${findutils_folder_name}"
xbb_activate_installed_dev
CPPFLAGS="${XBB_CPPFLAGS}"
CFLAGS="${XBB_CFLAGS_NO_W}"
CXXFLAGS="${XBB_CXXFLAGS_NO_W}"
LDFLAGS="${XBB_LDFLAGS_APP_STATIC_GCC}"
if [ "${TARGET_PLATFORM}" == "linux" ]
then
LDFLAGS+=" -Wl,-rpath,${LD_LIBRARY_PATH}"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running findutils configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${findutils_src_folder_name}/configure" --help
fi
config_options=()
config_options+=("--prefix=${LIBS_INSTALL_FOLDER_PATH}")
config_options+=("--build=${BUILD}")
# config_options+=("--host=${HOST}")
# config_options+=("--target=${TARGET}")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${findutils_src_folder_name}/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${findutils_folder_name}/config-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${findutils_folder_name}/configure-output-$(ndate).txt"
fi
(
echo
echo "Running findutils make..."
# Build.
run_verbose make -j ${JOBS}
if [ "${WITH_STRIP}" == "y" ]
then
run_verbose make install-strip
else
run_verbose make install
fi
show_libs "${LIBS_INSTALL_FOLDER_PATH}/bin/find"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${findutils_folder_name}/make-output-$(ndate).txt"
copy_license \
"${SOURCES_FOLDER_PATH}/${findutils_src_folder_name}" \
"${findutils_folder_name}"
)
(
test_findutils
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${findutils_folder_name}/test-output-$(ndate).txt"
touch "${findutils_stamp_file_path}"
else
echo "Component findutils already installed."
fi
}
function test_findutils()
{
(
xbb_activate
echo
echo "Checking the findutils shared libraries..."
show_libs "${LIBS_INSTALL_FOLDER_PATH}/bin/find"
echo
echo "Checking if findutils starts..."
"${LIBS_INSTALL_FOLDER_PATH}/bin/find" || true
)
}
# =============================================================================
# Used to initialise options in all mingw builds:
# `config_options=("${config_options_common[@]}")`
function prepare_mingw_config_options_common()
{
# ---------------------------------------------------------------------------
# Used in multiple configurations.
config_options_common=()
local prefix=${APP_PREFIX}
if [ $# -ge 1 ]
then
config_options_common+=("--prefix=$1")
else
echo "prepare_mingw_config_options_common requires a prefix path"
exit 1
fi
config_options_common+=("--disable-multilib")
# https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-160
# Windows 7
config_options_common+=("--with-default-win32-winnt=0x601")
# `ucrt` is the new Microsoft C runtime.
# https://support.microsoft.com/en-us/topic/update-for-universal-c-runtime-in-windows-c0514201-7fe6-95a3-b0a5-287930f3560c
config_options_common+=("--with-default-msvcrt=${MINGW_MSVCRT:-ucrt}")
# config_options_common+=("--with-default-msvcrt=${MINGW_MSVCRT:-msvcrt}")
config_options_common+=("--enable-wildcard")
config_options_common+=("--enable-warnings=0")
}
function prepare_mingw_env()
{
export MINGW_VERSION="$1"
export MINGW_NAME_SUFFIX=${2-''}
export MINGW_VERSION_MAJOR=$(echo ${MINGW_VERSION} | sed -e 's|\([0-9][0-9]*\)\..*|\1|')
# The original SourceForge location.
export MINGW_SRC_FOLDER_NAME="mingw-w64-v${MINGW_VERSION}"
export MINGW_FOLDER_NAME="${MINGW_SRC_FOLDER_NAME}${MINGW_NAME_SUFFIX}"
}
function build_mingw_headers()
{
# http://mingw-w64.org/doku.php/start
# https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mingw-w64-headers
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mingw-w64-crt
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mingw-w64-winpthreads
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mingw-w64-binutils
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mingw-w64-gcc
# https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-headers-git/PKGBUILD
# https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-crt-git/PKGBUILD
# https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-winpthreads-git/PKGBUILD
# https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-binutils/PKGBUILD
# https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/PKGBUILD
# https://github.com/msys2/MSYS2-packages/blob/master/gcc/PKGBUILD
# https://github.com/StephanTLavavej/mingw-distro
# 2018-06-03, "5.0.4"
# 2018-09-16, "6.0.0"
# 2019-11-11, "7.0.0"
# 2020-09-18, "8.0.0"
# 2021-05-09, "8.0.2"
# 2021-05-22, "9.0.0"
# 2022-04-04, "10.0.0"
local mingw_archive="${MINGW_SRC_FOLDER_NAME}.tar.bz2"
local mingw_url="https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/${mingw_archive}"
# If SourceForge is down, there is also a GitHub mirror.
# https://github.com/mirror/mingw-w64
# MINGW_FOLDER_NAME="mingw-w64-${MINGW_VERSION}"
# mingw_archive="v${MINGW_VERSION}.tar.gz"
# mingw_url="https://github.com/mirror/mingw-w64/archive/${mingw_archive}"
# https://sourceforge.net/p/mingw-w64/wiki2/Cross%20Win32%20and%20Win64%20compiler/
# https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/configure
# For binutils/GCC, the official method to build the mingw-w64 toolchain
# is to set --prefix and --with-sysroot to the same directory to allow
# the toolchain to be relocatable.
# Recommended GCC configuration:
# (to disable multilib, add `--enable-targets="${TARGET}"`)
#
# $ ../gcc-trunk/configure --{host,build}=<build triplet> \
# --target=x86_64-w64-mingw32 --enable-multilib --enable-64bit \
# --{prefix,with-sysroot}=<prefix> --enable-version-specific-runtime-libs \
# --enable-shared --with-dwarf --enable-fully-dynamic-string \
# --enable-languages=c,ada,c++,fortran,objc,obj-c++ --enable-libgomp \
# --enable-libssp --with-host-libstdcxx="-lstdc++ -lsupc++" \
# --with-{gmp,mpfr,mpc,cloog,ppl}=<host dir> --enable-lto
#
# $ make all-gcc && make install-gcc
#
# build mingw-w64-crt (headers, crt, tools)
#
# $ make all-target-libgcc && make install-target-libgcc
#
# build mingw-libraries (winpthreads)
#
# Continue the GCC build (C++)
# $ make && make install
# ---------------------------------------------------------------------------
# The 'headers' step creates the 'include' folder.
local mingw_headers_folder_name="mingw-${MINGW_VERSION}-headers${MINGW_NAME_SUFFIX}"
cd "${SOURCES_FOLDER_PATH}"
download_and_extract "${mingw_url}" "${mingw_archive}" \
"${MINGW_SRC_FOLDER_NAME}"
# The docs recommend to add several links, but for non-multilib
# configurations there are no target or lib32/lib64 specific folders.
mkdir -pv "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}"
# ---------------------------------------------------------------------------
# https://github.com/archlinux/svntogit-community/blob/packages/mingw-w64-headers/trunk/PKGBUILD
local mingw_headers_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${mingw_headers_folder_name}-installed"
if [ ! -f "${mingw_headers_stamp_file_path}" ]
then
(
mkdir -p "${BUILD_FOLDER_PATH}/${mingw_headers_folder_name}"
cd "${BUILD_FOLDER_PATH}/${mingw_headers_folder_name}"
if [ ! -f "config.status" ]
then
(
echo
echo "Running mingw-w64-headers${MINGW_NAME_SUFFIX} configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-headers/configure" --help
fi
if [ -n "${MINGW_NAME_SUFFIX}" ]
then
prepare_mingw_config_options_common "${APP_PREFIX}${MINGW_NAME_SUFFIX}"
config_options=("${config_options_common[@]}")
config_options+=("--build=${BUILD}")
# The bootstrap binaries will run on the build machine.
config_options+=("--host=${TARGET}")
config_options+=("--target=${TARGET}")
else
prepare_mingw_config_options_common "${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}"
config_options=("${config_options_common[@]}")
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
fi
config_options+=("--with-tune=generic")
config_options+=("--enable-sdk=all")
config_options+=("--enable-idl")
config_options+=("--without-widl")
# From Arch, but not recognised.
# config_options+=("--enable-secure-api")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-headers/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/config-headers-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/configure-headers-output-$(ndate).txt"
fi
(
echo
echo "Running mingw-w64-headers${MINGW_NAME_SUFFIX} make..."
# Build.
run_verbose make -j ${JOBS}
run_verbose make install-strip
if [ -n "${MINGW_NAME_SUFFIX}" ]
then
mkdir -pv "${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}"
(
cd "${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}"
run_verbose ln -sv ../include include
)
# This is this needed by the GCC bootstrap; otherwise:
# The directory that should contain system headers does not exist:
# /Host/home/ilg/Work/gcc-11.1.0-1/win32-x64/install/gcc-bootstrap/mingw/include
rm -rf "${APP_PREFIX}${MINGW_NAME_SUFFIX}/mingw"
(
cd "${APP_PREFIX}${MINGW_NAME_SUFFIX}"
run_verbose ln -sv "${CROSS_COMPILE_PREFIX}" "mingw"
)
fi
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/make-headers-output-$(ndate).txt"
# No need to do it again for each component.
if [ -z "${MINGW_NAME_SUFFIX}" ]
then
copy_license \
"${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}" \
"${MINGW_FOLDER_NAME}"
fi
)
touch "${mingw_headers_stamp_file_path}"
else
echo "Component mingw-w64-headers${MINGW_NAME_SUFFIX} already installed."
fi
}
function build_mingw_crt()
{
# ---------------------------------------------------------------------------
# The 'crt' step creates the C run-time in the 'lib' folder.
# https://github.com/archlinux/svntogit-community/blob/packages/mingw-w64-crt/trunk/PKGBUILD
local mingw_crt_folder_name="mingw-${MINGW_VERSION}-crt${MINGW_NAME_SUFFIX}"
local mingw_crt_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${mingw_crt_folder_name}-installed"
if [ ! -f "${mingw_crt_stamp_file_path}" ]
then
(
mkdir -p "${BUILD_FOLDER_PATH}/${mingw_crt_folder_name}"
cd "${BUILD_FOLDER_PATH}/${mingw_crt_folder_name}"
# -ffunction-sections -fdata-sections fail with:
# Error: .seh_endproc used in segment '.text' instead of expected '.text$WinMainCRTStartup'
CPPFLAGS=""
CFLAGS="-O2 -pipe -w"
CXXFLAGS="-O2 -pipe -w"
LDFLAGS=""
if [ "${IS_DEVELOP}" == "y" ]
then
LDFLAGS+=" -v"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
# Without it, apparently a bug in autoconf/c.m4, function AC_PROG_CC, results in:
# checking for _mingw_mac.h... no
# configure: error: Please check if the mingw-w64 header set and the build/host option are set properly.
# (https://github.com/henry0312/build_gcc/issues/1)
# export CC=""
# Alternately it is possible to define CC to the mingw-gcc.
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running mingw-w64-crt${MINGW_NAME_SUFFIX} configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-crt/configure" --help
fi
prepare_mingw_config_options_common "${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}"
config_options=("${config_options_common[@]}")
config_options+=("--with-sysroot=${APP_PREFIX}${MINGW_NAME_SUFFIX}")
if [ -n "${MINGW_NAME_SUFFIX}" ]
then
config_options+=("--build=${BUILD}")
# The bootstrap binaries will run on the build machine.
config_options+=("--host=${TARGET}")
config_options+=("--target=${TARGET}")
else
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
fi
if [ "${TARGET_ARCH}" == "x64" ]
then
config_options+=("--disable-lib32")
config_options+=("--enable-lib64")
elif [ "${TARGET_ARCH}" == "x32" -o "${TARGET_ARCH}" == "ia32" ]
then
config_options+=("--enable-lib32")
config_options+=("--disable-lib64")
else
echo "Oops! Unsupported TARGET_ARCH=${TARGET_ARCH}."
exit 1
fi
config_options+=("--enable-wildcard")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-crt/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/config-crt-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/configure-crt-output-$(ndate).txt"
fi
(
echo
echo "Running mingw-w64-crt${MINGW_NAME_SUFFIX} make..."
# Build.
# On Linux it fails with weird messages.
# run_verbose make -j ${JOBS}
run_verbose make -j1
run_verbose make install-strip
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/make-crt-output-$(ndate).txt"
)
touch "${mingw_crt_stamp_file_path}"
else
echo "Component mingw-w64-crt${MINGW_NAME_SUFFIX} already installed."
fi
}
function build_mingw_winpthreads()
{
# https://github.com/archlinux/svntogit-community/blob/packages/mingw-w64-winpthreads/trunk/PKGBUILD
local mingw_winpthreads_folder_name="mingw-${MINGW_VERSION}-winpthreads${MINGW_NAME_SUFFIX}"
local mingw_winpthreads_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${mingw_winpthreads_folder_name}-installed"
if [ ! -f "${mingw_winpthreads_stamp_file_path}" ]
then
(
mkdir -p "${BUILD_FOLDER_PATH}/${mingw_winpthreads_folder_name}"
cd "${BUILD_FOLDER_PATH}/${mingw_winpthreads_folder_name}"
# -ffunction-sections -fdata-sections fail with:
# Error: .seh_endproc used in segment '.text' instead of expected '.text$WinMainCRTStartup'
CPPFLAGS=""
CFLAGS="-O2 -pipe -w"
CXXFLAGS="-O2 -pipe -w"
LDFLAGS=""
if [ "${IS_DEVELOP}" == "y" ]
then
LDFLAGS+=" -v"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running mingw-w64-winpthreads${MINGW_NAME_SUFFIX} configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-libraries/winpthreads/configure" --help
fi
config_options=()
config_options+=("--prefix=${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}")
config_options+=("--with-sysroot=${APP_PREFIX}${MINGW_NAME_SUFFIX}")
config_options+=("--libdir=${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}/lib")
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
# This prevents references to libwinpthread-1.dll, which is
# particularly useful with -static-libstdc++, otherwise the
# result is not exactly static.
# This also requires disabling shared in the GCC configuration.
config_options+=("--disable-shared")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-libraries/winpthreads/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/config-winpthreads-log-$(ndate).txt"
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/configure-winpthreads-output-$(ndate).txt"
fi
(
echo
echo "Running mingw-w64-winpthreads${MINGW_NAME_SUFFIX} make..."
# Build.
run_verbose make -j ${JOBS}
run_verbose make install-strip
) 2>&1 | tee "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/make-winpthreads-output-$(ndate).txt"
)
touch "${mingw_winpthreads_stamp_file_path}"
else
echo "Component mingw-w64-winpthreads${MINGW_NAME_SUFFIX} already installed."
fi
}
function build_mingw_winstorecompat()
{
local mingw_winstorecompat_folder_name="mingw-${MINGW_VERSION}-winstorecompat${MINGW_NAME_SUFFIX}"
local mingw_winstorecompat_stamp_file_path="${STAMPS_FOLDER_PATH}/stamp-${mingw_winstorecompat_folder_name}-installed"
if [ ! -f "${mingw_winstorecompat_stamp_file_path}" ]
then
(
mkdir -p "${BUILD_FOLDER_PATH}/${mingw_winstorecompat_folder_name}"
cd "${BUILD_FOLDER_PATH}/${mingw_winstorecompat_folder_name}"
CPPFLAGS=""
CFLAGS="-O2 -pipe -w"
CXXFLAGS="-O2 -pipe -w"
LDFLAGS=""
if [ "${IS_DEVELOP}" == "y" ]
then
LDFLAGS+=" -v"
fi
export CPPFLAGS
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ ! -f "config.status" ]
then
(
if [ "${IS_DEVELOP}" == "y" ]
then
env | sort
fi
echo
echo "Running mingw-w64-winstorecompat${MINGW_NAME_SUFFIX} configure..."
if [ "${IS_DEVELOP}" == "y" ]
then
run_verbose bash "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-libraries/winstorecompat/configure" --help
fi
config_options=()
# Note: native library.
config_options+=("--prefix=${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}")
config_options+=("--libdir=${APP_PREFIX}${MINGW_NAME_SUFFIX}/${CROSS_COMPILE_PREFIX}/lib")
config_options+=("--build=${BUILD}")
config_options+=("--host=${HOST}")
config_options+=("--target=${TARGET}")
run_verbose bash ${DEBUG} "${SOURCES_FOLDER_PATH}/${MINGW_SRC_FOLDER_NAME}/mingw-w64-libraries/winstorecompat/configure" \
"${config_options[@]}"
cp "config.log" "${LOGS_FOLDER_PATH}/${MINGW_FOLDER_NAME}/config-winstorecompat-log-$(ndate).txt"