-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdllstack.sh
executable file
·1601 lines (1441 loc) · 62.4 KB
/
dllstack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# dllstack.sh: Cross-compile set of libraries for Windows target.
#
# (c) 2008-2025 Marko Lindqvist
#
# This program is licensed under Gnu General Public License version 2.
#
#############################################################################################
#
# Preparations
#
CROSSER_MAINDIR="$(cd "$(dirname "$0")" || exit 1 ; pwd)"
if ! test -e "${CROSSER_MAINDIR}/CrosserVersion" && test -e "/usr/share/crosser/CrosserVersion"
then
CROSSER_MAINDIR="/usr/share/crosser"
fi
if test "$1" = "-h" || test "$1" = "--help"
then
echo "Usage: $(basename "$0") [[-h|--help]|[-v|--version]|[install prefix]] [versionset] [setup]"
exit 0
fi
# In order to give local setup opportunity to override versions,
# we have to load versionset before setup_reader.sh
# helpers.sh requires environment to be set up by setup_reader.sh.
if test "$2" != "" ; then
CROSSER_VERSIONSET="$2"
else
CROSSER_VERSIONSET="current"
fi
if test -e "${CROSSER_MAINDIR}/setups/${CROSSER_VERSIONSET}.versions"
then
. "${CROSSER_MAINDIR}/setups/${CROSSER_VERSIONSET}.versions"
else
# Versions being unset do not prevent loading of setup_reader.sh and helper.sh,
# resulting environment would just be unusable for building.
# We are not going to build anything, but just issuing error message - and for
# that we read log_error from helpers.sh
CROSSER_ERR_MSG="Cannot find versionset \"${CROSSER_VERSIONSET}.versions\""
fi
. "${CROSSER_MAINDIR}/scripts/setup_reader.sh"
. "${CROSSER_MAINDIR}/scripts/helpers.sh"
. "${CROSSER_MAINDIR}/scripts/packethandlers.sh"
# This must be after reading helpers.sh so that ${CROSSER_VERSION} is set
if test "$1" = "-v" || test "$1" = "--version"
then
echo "Windows library stack builder for Crosser ${CROSSER_VERSION}"
exit 0
fi
if test "$3" = ""
then
CROSSER_SETUP="${CROSSER_DEFAULT_SETUP}"
else
CROSSER_SETUP="$3"
fi
if ! log_init
then
echo "Cannot setup logging!" >&2
exit 1
fi
if test "${CROSSER_ERR_MSG}" != ""
then
log_error "${CROSSER_ERR_MSG}"
exit 1
fi
if test "$1" != ""
then
DLLSPREFIX="$1"
fi
################################################################################################
#
# Functions
#
# $1 - Component
# [$2] - Extra configure options
build_component()
{
build_component_full "$1" "$1" "$2"
}
# $1 - Component
# [$2] - Extra configure options
build_component_def_make()
{
build_component_full "$1" "$1" "$2" "" "" "" "" "yes"
}
# $1 - Component
# [$2] - Extra configure options
# [$3] - "native", "cross", or "pkg-config"
build_component_host()
{
if test "$3" = "pkg-config"
then
BTYPE="$3"
BDTYPE="cross"
else
if test "$3" != ""
then
BTYPE="$3"
else
BTYPE="native"
fi
BDTYPE="$BTYPE"
fi
if ! build_component_full "$BDTYPE-$1" "$1" "$2" "$BTYPE"
then
BERR=true
else
BERR=false
fi
# Reset command hash in case it already contained old version of the
# just built tool
hash -r
if test "$BERR" = "true"
then
return 1
fi
}
# $1 - Build dir or 'src'
# $2 - Component
# [$3] - Extra configure options
# [$4] - Build type ('native' | 'windres' | 'cross' |
# 'qt' | 'pkg-config' | 'custom' |
# 'icu' | 'unicode' | 'nounicode')
# Of these, either 'unicode' or 'nounicode' is also the default,
# but if you really want one of them, make it explicit.
# [$5] - Src subdir
# [$6] - Make options
# [$7] - Version
# [$8] - 'yes' - build default target before 'install'
build_component_full()
{
log_packet "$2"
if test "$7" != ""
then
BVER="$7"
else
BVER="$(component_version "$2")"
fi
if test "${BVER}" = ""
then
log_error "Version for $2 not defined"
return 1
fi
if test "${BVER}" = "0"
then
return 0
fi
BNAME=$(component_name_to_package_name "$2" "${BVER}")
if test "$5" != ""
then
SUBDIR="$5"
if ! test -d "${CROSSER_SRCDIR}/${SUBDIR}"
then
log_error "${BNAME} srcdir \"$5\" doesn't exist"
return 1
fi
else
SUBDIR="$(src_subdir "${BNAME}" "${BVER}")"
if test "${SUBDIR}" = ""
then
log_error "Cannot find srcdir for ${BNAME} version ${BVER}"
return 1
fi
fi
if test "$1" != "src"
then
DISPLAY_NAME="$1"
BUILDDIR="${CROSSER_BUILDDIR}/$1"
if ! mkdir -p "${BUILDDIR}"
then
log_error "Failed to create directory ${BUILDDIR}"
return 1
fi
SRCDIR="${CROSSER_SRCDIR}/${SUBDIR}"
else
DISPLAY_NAME="$2"
BUILDDIR="${CROSSER_SRCDIR}/${SUBDIR}"
SRCDIR="."
fi
(
cd "${BUILDDIR}"
if test "$4" = "native"
then
CONFOPTIONS="--prefix=${NATIVE_PREFIX} $3"
unset CPPFLAGS
unset LDFLAGS
export PKG_CONFIG_PATH="${NATIVE_PKG_CONFIG_PATH}"
elif test "$4" = "cross"
then
CONFOPTIONS="--prefix=${NATIVE_PREFIX} --build=${CROSSER_BUILD_ARCH} --host=${CROSSER_BUILD_ARCH} --target=${CROSSER_TARGET} $3"
unset CPPFLAGS
unset LDFLAGS
export PKG_CONFIG_PATH="${NATIVE_PKG_CONFIG_PATH}"
elif test "$4" = "pkg-config"
then
CONFOPTIONS="--prefix=${DIST_NATIVE_PREFIX} --program-prefix=${CROSSER_TARGET}- $3"
unset CPPFLAGS
unset LDFLAGS
export PKG_CONFIG_PATH="${NATIVE_PKG_CONFIG_PATH}"
elif test "$4" = "custom"
then
CONFOPTIONS="$3"
unset CPPFLAGS
unset LDFLAGS
elif test "$4" = "windres"
then
CONFOPTIONS="--prefix=${DLLSPREFIX} --build=${CROSSER_BUILD_ARCH} --host=${CROSSER_TARGET} --target=${CROSSER_TARGET} $3"
unset CPPFLAGS
export LDFLAGS="-L${DLLSPREFIX}/lib -static-libgcc ${CROSSER_STDCXX}"
export CC="${CROSSER_TARGET}-gcc${TARGET_SUFFIX} -static-libgcc"
export CXX="${CROSSER_TARGET}-g++${TARGET_SUFFIX} ${CROSSER_STDCXX} -static-libgcc"
elif test "$4" = "qt"
then
CONFOPTIONS="-prefix ${DLLSPREFIX} $3"
else
CONFOPTIONS="--prefix=${DLLSPREFIX} --build=${CROSSER_BUILD_ARCH} --host=${CROSSER_TARGET} --target=${CROSSER_TARGET} $3"
export CPPFLAGS="-I${DLLSPREFIX}/include -I${TGT_HEADERS} ${CROSSER_WINVER_FLAG}"
# Default is 'nounicode'. To change that, make this check
# ' "$4" != "nounicode" '
if test "$4" = "unicode" ; then
CPPFLAGS="${CPPFLAGS} -DUNICODE"
fi
if test "$4" = "icu" ; then
export LDFLAGS="-L${DLLSPREFIX}/lib -static-libgcc ${CROSSER_STDCXX} -Wl,-allow-multiple-definition"
else
export LDFLAGS="-L${DLLSPREFIX}/lib -static-libgcc ${CROSSER_STDCXX}"
fi
export CC="${CROSSER_TARGET}-gcc${TARGET_SUFFIX} -static-libgcc"
export CXX="${CROSSER_TARGET}-g++${TARGET_SUFFIX} ${CROSSER_STDCXX} -static-libgcc"
export PKG_CONFIG_PATH="${DLLSPREFIX}/lib/${CROSSER_PKG_ARCH}/pkgconfig"
fi
if test -x "${SRCDIR}/configure"
then
log_write 1 "Configuring ${DISPLAY_NAME}"
log_write 3 " Options: \"${CONFOPTIONS}\""
log_flags
if ! "${SRCDIR}/configure" ${CONFOPTIONS} \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Configure for ${DISPLAY_NAME} failed"
return 1
fi
elif test -f "${SRCDIR}/CMakeLists.txt"
then
CONFOPTIONS="-DCMAKE_TOOLCHAIN_FILE=${DLLSPREFIX}/etc/toolchain.cmake -DCMAKE_PREFIX_PATH=${DLLSPREFIX} -DCMAKE_SYSTEM_NAME=Windows -DHOST=${CROSSER_TARGET} -DCMAKE_INSTALL_PREFIX=${DLLSPREFIX} ${CONFOPTIONS}"
log_write 1 "Configuring ${DISPLAY_NAME}"
log_write 3 " Options: \"${CONFOPTIONS}\""
log_flags
if ! cmake $CONFOPTIONS "${SRCDIR}" \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "CMake configure for ${DISPLAY_NAME} failed"
return 1
fi
fi
log_write 1 "Building ${DISPLAY_NAME}"
if test -f Makefile
then
if test "$8" = "yes"
then
log_write 3 " Make targets: [default] install"
else
log_write 3 " Make targets: install"
fi
if test "$6" = "no"
then
MAKEOPTIONS=""
elif test "$6" != ""
then
MAKEOPTIONS="$6"
else
MAKEOPTIONS="${CROSSER_COREOPTIONS}"
fi
log_write 4 " Options: \"${MAKEOPTIONS}\""
if test "$8" = "yes"
then
if ! make ${MAKEOPTIONS} >> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Make for ${DISPLAY_NAME} failed"
return 1
fi
fi
if ! make ${MAKEOPTIONS} install >> "$CROSSER_LOGDIR/stdout.log" 2>> "$CROSSER_LOGDIR/stderr.log"
then
log_error "Install for ${DISPLAY_NAME} failed"
return 1
fi
else
log_error "Can't detect build method for ${DISPLAY_NAME}"
return 1
fi
)
RET=$?
if test $RET = 0 ; then
echo "${DISPLAY_NAME} : ${BVER}" >> "${DLLSPREFIX}/ComponentVersions.txt"
fi
return $RET
}
# $1 - Component
# $2 - Extra cmake options
build_with_cmake()
{
build_with_cmake_full "$1" "$1" "$2"
}
# $1 - Build dir
# $2 - Component
# $3 - Extra configure options
# [$4] - Build type ('native-qt6', 'qt', 'custom')
# [$5] - Src subdir
build_with_cmake_full()
{
log_packet "$2"
BVER="$(component_version "$2")"
if test "${BVER}" = ""
then
log_error "Version for $2 not defined"
return 1
fi
if test "${BVER}" = "0"
then
return 0
fi
BNAME=$(component_name_to_package_name "$2" "${BVER}")
if test "$5" != ""
then
SUBDIR="$5"
if ! test -d "${CROSSER_SRCDIR}/${SUBDIR}"
then
log_error "${BNAME} srcdir \"$5\" doesn't exist"
return 1
fi
else
SUBDIR="$(src_subdir "${BNAME}" "${BVER}")"
if test "${SUBDIR}" = ""
then
log_error "Cannot find srcdir for ${BNAME} version ${BVER}"
return 1
fi
fi
DISPLAY_NAME="$1"
BUILDDIR="${CROSSER_BUILDDIR}/$1"
if ! mkdir -p "${BUILDDIR}"
then
log_error "Failed to create directory ${BUILDDIR}"
return 1
fi
SRCDIR="${CROSSER_SRCDIR}/${SUBDIR}"
(
cd "${BUILDDIR}" || return 1
if test "$4" = "native-qt6"
then
CONFOPTIONS="--prefix=${DIST_NATIVE_PREFIX} $3"
unset CPPFLAGS
unset LDFLAGS
export PKG_CONFIG_PATH="${NATIVE_PKG_CONFIG_PATH}"
elif test "$4" = "qt"
then
CONFOPTIONS="-prefix ${DLLSPREFIX} $3"
elif test "$4" = "custom"
then
CONFOPTIONS="$3"
unset CPPFLAGS
unset LDFLAGS
else
CONFOPTIONS="$3"
export CPPFLAGS="-I${DLLSPREFIX}/include -I${TGT_HEADERS} ${CROSSER_WINVER_FLAG}"
export LDFLAGS="-L${DLLSPREFIX}/lib -static-libgcc ${CROSSER_STDCXX}"
export CC="${CROSSER_TARGET}-gcc${TARGET_SUFFIX} -static-libgcc"
export CXX="${CROSSER_TARGET}-g++${TARGET_SUFFIX} ${CROSSER_STDCXX} -static-libgcc"
export PKG_CONFIG_PATH="${DLLSPREFIX}/lib/${CROSSER_PKG_ARCH}/pkgconfig"
fi
log_write 1 "Configuring ${DISPLAY_NAME}"
log_write 3 " Options: \"${CONFOPTIONS}\""
log_flags
if test -x "${SRCDIR}/configure" &&
(test "$4" = "native-qt6" || test "$4" = "qt" )
then
if ! "${SRCDIR}/configure" ${CONFOPTIONS} \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Configure for ${DISPLAY_NAME} failed"
return 1
fi
else
CONFOPTIONS="-DCMAKE_TOOLCHAIN_FILE=${DLLSPREFIX}/etc/toolchain.cmake -DCMAKE_PREFIX_PATH=${DLLSPREFIX} -DCMAKE_SYSTEM_NAME=Windows -DHOST=${CROSSER_TARGET} -DCMAKE_INSTALL_PREFIX=${DLLSPREFIX} ${CONFOPTIONS}"
if ! cmake ${CONFOPTIONS} "${SRCDIR}" \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "CMake configure for ${DISPLAY_NAME} failed"
return 1
fi
fi
log_write 1 "Building ${DISPLAY_NAME}"
if test -f CMakeCache.txt
then
if ! cmake --build . --parallel \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "CMake build for ${DISPLAY_NAME} failed"
return 1
fi
if ! cmake --install . \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "CMake install for ${DISPLAY_NAME} failed"
return 1
fi
elif test -f Makefile
then
log_write 3 " Make targets: [default] install"
MAKEOPTIONS="${CROSSER_COREOPTIONS}"
log_write 4 " Options: \"${MAKEOPTIONS}\""
if ! make ${MAKEOPTIONS} \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Make for ${DISPLAY_NAME} failed"
return 1
fi
if ! make ${MAKEOPTIONS} install \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Install for ${DISPLAY_NAME} failed"
return 1
fi
else
log_error "Can't detect build method for ${DISPLAY_NAME}"
return 1
fi
)
RET=$?
if test $RET = 0 ; then
echo "${DISPLAY_NAME} : ${BVER}" >> "${DLLSPREFIX}/ComponentVersions.txt"
fi
return $RET
}
# $1 - Component
# $2 - Extra meson options
build_with_meson()
{
build_with_meson_full "$1" "$1" "$2"
}
# $1 - Component
# $2 - Extra meson options
build_with_meson_host()
{
build_with_meson_full "native-${1}" "$1" "$2" "native"
}
# $1 - Build dir
# $2 - Component
# $3 - Extra meson options
# [$4] - Build type ('native' | 'cross')
# [$5] - Source subdir
build_with_meson_full()
{
log_packet "$2"
BVER="$(component_version $2)"
if test "${BVER}" = ""
then
log_error "Version for $2 not defined"
return 1
fi
if test "${BVER}" = "0"
then
return 0
fi
BNAME="$(component_name_to_package_name $2 "${BVER}")"
SUBDIR="$(src_subdir $BNAME $BVER)"
if test "${SUBDIR}" = ""
then
log_error "Cannot find srcdir for ${BNAME} version ${BVER}"
return 1
fi
if test "$5" != "" ; then
SUBDIR="${SUBDIR}/$5"
if ! test -d "${CROSSER_SRCDIR}/${SUBDIR}" ; then
log_error "Cannot find source subdir \"${SUBDIR}\""
return 1
fi
fi
DISPLAY_NAME="$1"
BUILDDIR="${CROSSER_BUILDDIR}/$1"
if ! mkdir -p "${BUILDDIR}"
then
log_error "Failed to create directory ${BUILDDIR}"
return 1
fi
SRCDIR="${CROSSER_SRCDIR}/${SUBDIR}"
(
cd "${BUILDDIR}"
if test "$4" = "native" ; then
export PKG_CONFIG_PATH="${NATIVE_PKG_CONFIG_PATH}"
else
# The argument that can be given properly via the cross-file,
# are given that way. Here are the rest.
export CPPFLAGS="-I${DLLSPREFIX}/include -I${TGT_HEADERS} ${CROSSER_WINVER_FLAG}"
export LDFLAGS="-L${DLLSPREFIX}/lib"
export PKG_CONFIG_PATH="${DLLSPREFIX}/lib/${CROSSER_PKG_ARCH}/pkgconfig"
fi
log_write 1 "Running meson for ${DISPLAY_NAME}"
log_write 3 " PKG_CONFIG_PATH: \"${PKG_CONFIG_PATH}\""
log_write 3 " Options: $3"
if test "$4" = "native"
then
if ! meson.py setup "${SRCDIR}" . --prefix="${NATIVE_PREFIX}" $3 \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Meson for ${DISPLAY_NAME} failed"
return 1
fi
elif ! meson.py setup "${SRCDIR}" . --cross-file "${DLLSPREFIX}/etc/meson_cross_file.txt" \
"--prefix=${DLLSPREFIX}" $3 \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Meson for ${DISPLAY_NAME} failed"
return 1
fi
log_write 1 "Running ninja for ${DISPLAY_NAME}"
if ! ninja install \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Ninja for ${DISPLAY_NAME} failed"
return 1
fi
)
RET=$?
if test $RET = 0 ; then
echo "${DISPLAY_NAME} : ${BVER}" >> "${DLLSPREFIX}/ComponentVersions.txt"
fi
return $RET
}
# Build zlib
#
# $1 - Package name
# $2 - Version
# $3 - Configure options
#
build_zlib()
{
log_packet "$1"
SUBDIR="$(src_subdir $1 $2)"
if test "${SUBDIR}" = ""
then
log_error "Cannot find srcdir for $1 version $2"
return 1
fi
BUILDDIR="${CROSSER_BUILDDIR}/$1"
if ! mkdir -p "${BUILDDIR}"
then
log_error "Failed to create directory \"${BUILDDIR}\""
return 1
fi
SRCDIR="${CROSSER_SRCDIR}/${SUBDIR}"
(
export CC="${CROSSER_TARGET}-gcc${TARGET_SUFFIX} -static-libgcc"
export RANLIB="${CROSSER_TARGET}-ranlib"
export AR="${CROSSER_TARGET}-ar"
if ! cd "${BUILDDIR}"
then
log_error "Cannot change to directory \"${BUILDDIR}\""
return 1
fi
export CPPFLAGS="-isystem ${DLLSPREFIX}/include -isystem ${TGT_HEADERS} ${CROSSER_WINVER_FLAG}"
export LDFLAGS="-L${DLLSPREFIX}/lib"
CONFOPTIONS="--prefix=${DLLSPREFIX} --shared $3"
log_write 1 "Configuring $1"
log_write 3 " Options: \"${CONFOPTIONS}\""
log_flags
if ! "${SRCDIR}/configure" ${CONFOPTIONS} \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Configure for $1 failed"
return 1
fi
log_write 1 "Building $1"
log_write 3 " Make targets: [default] install"
log_write 4 " Options: \"${CROSSER_COREOPTIONS}\""
if ! make ${CROSSER_COREOPTIONS} \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Make for $1 failed"
return 1
fi
if ! make ${CROSSER_COREOPTIONS} install \
>> "${CROSSER_LOGDIR}/stdout.log" 2>> "${CROSSER_LOGDIR}/stderr.log"
then
log_error "Install for $1 failed"
return 1
fi
if ! cp "${DLLSPREFIX}/lib/libz.dll"* "${DLLSPREFIX}/bin/"
then
log_error "Failed to move libz dll:s to correct directory"
return 1
fi
)
RET=$?
if test "${RET}" = 0 ; then
echo "$1 : $2" >> "${DLLSPREFIX}/ComponentVersions.txt"
fi
return $RET
}
#######################################################################################################
#
# Main
#
cd "$(dirname "$0")" || exit 1
CROSSER_BUILD_ARCH="$("${CROSSER_MAINDIR}/scripts/aux/config.guess")"
CROSSER_PKG_ARCH="$(echo ${CROSSER_BUILD_ARCH} | sed 's/-pc//')"
if ! test -e "${CROSSER_MAINDIR}/setups/${CROSSER_SETUP}.conf" ; then
log_error "Can't find setup \"${CROSSER_SETUP}.conf\""
exit 1
fi
. "${CROSSER_MAINDIR}/setups/${CROSSER_SETUP}.conf"
if test "${TARGET_VENDOR}" = ""
then
export CROSSER_TARGET="${TARGET_ARCH}-${TARGET_OS}"
else
export CROSSER_TARGET="${TARGET_ARCH}-${TARGET_VENDOR}-${TARGET_OS}"
fi
if test -d "/usr/${CROSSER_TARGET}/include"
then
export TGT_HEADERS="/usr/${CROSSER_TARGET}/include"
fi
export DLLSPREFIX=$(setup_prefix_default "${HOME}/.crosser/<VERSION>/<VERSIONSET>/<SETUP>/winstack" "${DLLSPREFIX}")
export NATIVE_PREFIX=$(setup_prefix_default "${HOME}/.crosser/<VERSION>/<VERSIONSET>/dllshost" \
"${CROSSER_HOST_PREFIX}")
if test "${TARGET_SUFFIX_P}" = "" ; then
TARGET_SUFFIX_P="${TARGET_SUFFIX}"
fi
TARGET_GCC_VER=$(${CROSSER_TARGET}-gcc${TARGET_SUFFIX} -dumpversion 2>/dev/null | sed 's/-.*//')
TARGET_GXX_VER=$(${CROSSER_TARGET}-g++${TARGET_SUFFIX} -dumpversion 2>/dev/null | sed 's/-.*//')
if test "${TARGET_GCC_VER}" = "" ; then
log_error "Target compiler ${CROSSER_TARGET}-gcc${TARGET_SUFFIX} version not found!"
exit 1
fi
if test "${TARGET_GXX_VER}" = "" ; then
log_error "Target compiler ${CROSSER_TARGET}-g++${TARGET_SUFFIX} version not found!"
exit 1
fi
CROSSER_WINVER_FLAG="-D_WIN32_WINNT=${CROSSER_WINVER}"
log_write 2 "Install: \"${DLLSPREFIX}\""
log_write 2 "Src: \"${CROSSER_SRCDIR}\""
log_write 2 "Log: \"${CROSSER_LOGDIR}\""
log_write 2 "Build: \"${CROSSER_BUILDDIR}\""
log_write 2 "Setup: \"${CROSSER_SETUP}\""
log_write 2 "Versionset: \"${CROSSER_VERSIONSET}\""
log_write 2 "cross-gcc: ${TARGET_GCC_VER}"
log_write 2 "cross-g++: ${TARGET_GXX_VER}"
CROSSER_STDCXX="-static-libstdc++"
remove_dir "${CROSSER_SRCDIR}" &&
remove_dir "${CROSSER_BUILDDIR}" &&
remove_dir "${DLLSPREFIX}" &&
remove_dir "${NATIVE_PREFIX}"
RDRET=$?
if test "${RDRET}" = "1" ; then
log_error "Old directories not removed"
exit 1
elif test "${RDRET}" != "0" ; then
log_error "Failed to remove old directories"
exit 1
fi
if ! mkdir -p "${CROSSER_SRCDIR}"
then
log_error "Cannot create directory \"${CROSSER_SRCDIR}\""
exit 1
fi
if ! mkdir -p "${CROSSER_BUILDDIR}"
then
log_error "Cannot create directory \"${CROSSER_BUILDDIR}\""
exit 1
fi
if ! mkdir -p "${DLLSPREFIX}/man/man1" ||
! mkdir -p "${DLLSPREFIX}/etc"
then
log_error "Cannot create target directory hierarchy under \"${DLLSPREFIX}\""
exit 1
fi
if ! mkdir -p "${NATIVE_PREFIX}/bin"
then
log_error "Cannot create host directory hierarchy under \"${NATIVE_PREFIX}\""
exit 1
fi
export DIST_NATIVE_PREFIX="${DLLSPREFIX}/linux"
export PATH="${DIST_NATIVE_PREFIX}/bin:${NATIVE_PREFIX}/bin:${NATIVE_PREFIX}/meson-${VERSION_MESON}:${PATH}"
if ! packetdir_check
then
log_error "Packetdir missing"
exit 1
fi
log_write 1 "Creating meson cross file"
if ! (
TARGET_GCC=$(command -v ${CROSSER_TARGET}-gcc${TARGET_SUFFIX})
TARGET_GPP=$(command -v ${CROSSER_TARGET}-g++${TARGET_SUFFIX})
TARGET_AR=$(command -v ${CROSSER_TARGET}-ar)
TARGET_STRIP=$(command -v ${CROSSER_TARGET}-strip)
TARGET_PKGCONFIG="${DIST_NATIVE_PREFIX}/bin/${CROSSER_TARGET}-pkg-config"
TARGET_WINDRES=$(command -v ${CROSSER_TARGET}-windres)
if test "${TARGET_GCC}" = "" ||
test "${TARGET_GPP}" = "" ||
test "${TARGET_AR}" = "" ||
test "${TARGET_STRIP}" = "" ||
test "${TARGET_WINDRES}" = ""
then
log_error "Cross-tools missing"
exit 1
fi
if ! sed -e "s,<TARGET_GCC>,${TARGET_GCC},g" \
-e "s,<TARGET_GPP>,${TARGET_GPP},g" \
-e "s,<TARGET_AR>,${TARGET_AR},g" \
-e "s,<TARGET_STRIP>,${TARGET_STRIP},g" \
-e "s,<TARGET_PKGCONFIG>,${TARGET_PKGCONFIG},g" \
-e "s,<TARGET_WINDRES>,${TARGET_WINDRES},g" \
-e "s,<DLLSTACK>,${DLLSPREFIX},g" \
"${CROSSER_MAINDIR}/scripts/${MESON_CROSS_FILE}" \
> "${DLLSPREFIX}/etc/meson_cross_file.txt"
then
log_error "Meson cross-file creation failed"
exit 1
fi
)
then
exit 1
fi
log_write 1 "Creating cmake toolchain file"
if ! (
TARGET_GCC=$(command -v ${CROSSER_TARGET}-gcc${TARGET_SUFFIX})
TARGET_GPP=$(command -v ${CROSSER_TARGET}-g++${TARGET_SUFFIX})
if test "${TARGET_GCC}" = "" ||
test "${TARGET_GPP}" = ""
then
log_error "Cross-tools missing"
exit 1
fi
if ! sed -e "s,<TARGET_GCC>,${TARGET_GCC},g" \
-e "s,<TARGET_GPP>,${TARGET_GPP},g" \
-e "s,<DLLSPREFIX>,${DLLSPREFIX},g" \
"${CROSSER_MAINDIR}/scripts/${CMAKE_PLATFORM_FILE}" \
> "${DLLSPREFIX}/etc/toolchain.cmake"
then
log_error "CMake toolchain file creation failed"
exit 1
fi
)
then
exit 1
fi
log_write 1 "Setting up fixed environment"
if ! mkdir -p "${DLLSPREFIX}/lib/${CROSSER_PKG_ARCH}" ||
! ln -s ../pkgconfig "${DLLSPREFIX}/lib/${CROSSER_PKG_ARCH}/" ||
! mkdir -p "${NATIVE_PREFIX}/lib/${CROSSER_PKG_ARCH}" ||
! ln -s ../pkgconfig "${NATIVE_PREFIX}/lib/${CROSSER_PKG_ARCH}/"
then
log_error "Failed to set up fixed environment"
exit 1
fi
if test "${CROSSER_DOWNLOAD}" = "yes"
then
steplist="win"
if test "${CROSSER_SDL2}" = "yes" ; then
steplist="${steplist},sdl2"
fi
if test "${CROSSER_SFML}" = "yes" ; then
steplist="${steplist},sfml"
fi
if test "${CROSSER_FULL}" = "yes" ; then
steplist="${steplist},full"
fi
if ! (cd "${CROSSER_PACKETDIR}" &&
"${CROSSER_MAINDIR}/scripts/download_packets.sh" "$steplist" "${CROSSER_VERSIONSET}" "${CROSSER_SETUP}")
then
log_error "Downloading packets failed"
exit 1
fi
fi
GETTEXT_VARS="$(read_configure_vars gettext)"
CAIRO_VARS="$(read_configure_vars cairo)"
ICU_FILEVER="$(icu_filever "${VERSION_ICU}")"
export LD_LIBRARY_PATH="${DIST_NATIVE_PREFIX}/lib:${DIST_NATIVE_PREFIX}/lib64:${NATIVE_PREFIX}/lib:${NATIVE_PREFIX}/lib64:${NATIVE_PREFIX}/lib/${CROSSER_PKG_ARCH}"
export NATIVE_PKG_CONFIG_PATH="${DIST_NATIVE_PREFIX}/lib64/pkgconfig:${NATIVE_PREFIX}/lib/pkgconfig:${NATIVE_PREFIX}/lib64/pkgconfig"
GLIB_CONF_HOST="-Dlibmount=disabled -Dselinux=disabled"
if is_minimum_version "${VERSION_GLIB}" "2.80.0"
then
GLIB_CONF_HOST="${GLIB_CONF_HOST} -Dintrospection=disabled"
fi
if ! unpack_component meson "" "meson/${VERSION_MESON}" ||
! cp -R "${CROSSER_SRCDIR}/meson-${VERSION_MESON}" "${NATIVE_PREFIX}" ||
! unpack_component autoconf ||
! build_component_host autoconf ||
! deldir_component autoconf "${VERSION_AUTOCONF}" "native-autoconf" ||
! unpack_component automake ||
! build_component_host automake ||
! deldir_component automake "${VERSION_AUTOMAKE}" "native-automake" ||
! unpack_component libtool ||
! build_component_full native-libtool libtool \
"" "native" "" "" "${VERSION_LIBTOOL}" ||
! deldir_build "native-libtool" ||
! unpack_component libffi ||
! build_component_host libffi ||
! deldir_build "native-libffi" ||
! unpack_component pkgconf ||
! autogen_component pkgconf "${VERSION_PKGCONF}" ||
! build_component_host pkgconf \
"--with-pkg-config-dir=${NATIVE_PREFIX}/lib/pkgconfig --disable-shared" ||
! deldir_build "native-pkgconf" ||
! unpack_component pkg-config ||
! build_component_host pkg-config \
"--with-pc-path=${NATIVE_PREFIX}/lib/pkgconfig --with-internal-glib --disable-compile-warnings" ||
! deldir_build "native-pkg-config" ||
! unpack_component pcre2 ||
! build_component_host pcre2 \
"--enable-unicode-properties" ||
! deldir_build "native-pcre2" ||
! unpack_component glib ||
! build_with_meson_host glib "${GLIB_CONF_HOST}" ||
! deldir_build "native-glib" ||
! unpack_component gtk-doc ||
! patch_src gtk-doc "${VERSION_GTK_DOC}" "gtkdoc_pc" ||
! patch_src gtk-doc "${VERSION_GTK_DOC}" "gtkdoc_configheaders" ||
! ( is_minimum_version "${VERSION_GTK_DOC}" 1.33 ||
( autogen_component gtk-doc "${VERSION_GTK_DOC}" &&
build_component_host gtk-doc ) ) ||
! ( is_smaller_version "${VERSION_GTK_DOC}" 1.33 ||
build_with_meson_host gtk-doc ) ||
! deldir_component gtk-doc "${VERSION_GTK_DOC}" \
"native-gtk-doc" ||
! unpack_component gobject-introspection ||
! build_with_meson_host gobject-introspection ||
! deldir_component gobject-introspection "${VERSION_GOBJ_INTRO}" \
"native-gobject-introspection" ||
! build_component_host pkgconf \
"--with-pkg-config-dir=${DLLSPREFIX}/lib/pkgconfig --disable-shared" \
"pkg-config" ||
! deldir_component pkgconf "${VERSION_PKGCONF}" "cross-pkgconf" ||
! build_component_host pkg-config \
"--with-pc-path=${DLLSPREFIX}/lib/pkgconfig --disable-host-tool" "pkg-config" ||
! deldir_component pkg-config "${VERSION_PKG_CONFIG}" "cross-pkg-config" ||
! mv "${NATIVE_PREFIX}/bin/pkg-config" "${NATIVE_PREFIX}/bin/pkg-config.real" ||
! ln -s "${CROSSER_PKGCONF}" "${NATIVE_PREFIX}/bin/pkg-config" ||
! mv "${DIST_NATIVE_PREFIX}/bin/${CROSSER_TARGET}-pkg-config" \
"${DIST_NATIVE_PREFIX}/bin/${CROSSER_TARGET}-pkg-config.real" ||
! ln -s "${CROSSER_TARGET}-${CROSSER_PKGCONF}" \
"${DIST_NATIVE_PREFIX}/bin/${CROSSER_TARGET}-pkg-config" ||
! unpack_component icon-naming-utils ||
! patch_src icon-naming-utils "${VERSION_ICON_NUTILS}" "icon-nutils-pc" ||
! build_component_host icon-naming-utils ||
! deldir_component icon-naming-utils "${VERSION_ICON_NUTILS}" \
"native-icon-naming-utils" ||
! unpack_component icu4c "" "icu4c-${ICU_FILEVER}-src" ||
! patch_src icu "${VERSION_ICU}" icu_dbl_mant ||
! (is_smaller_version "${VERSION_ICU}" 59.1 ||
patch_src icu "${VERSION_ICU}" icu_filetools_inc ) ||
! CXX="g++" CFLAGS="-fPIC" build_component_full native-icu4c icu4c "" \
"native" "icu/source" "" "" "yes" ||
! unpack_component tiff ||
! build_component_host tiff ||
! deldir_build "native-tiff" ||
! unpack_component libxml2 ||
! build_component_host libxml2 "--without-python" ||
! deldir_build "native-libxml2" ||
! unpack_component shared-mime-info ||
! ln -s "../lib/pkgconfig" "${NATIVE_PREFIX}/share/pkgconfig" ||
! ( is_minimum_version "${VERSION_SHARED_MIME_INFO}" 2.2 ||
patch_src shared-mime-info "${VERSION_SHARED_MIME_INFO}" \
"smi-meson-0.60" ) ||
! ( is_smaller_version "${VERSION_SHARED_MIME_INFO}" 2.2 ||
patch_src shared-mime-info "${VERSION_SHARED_MIME_INFO}" "smi-html" ) ||
! (is_smaller_version "${VERSION_SHARED_MIME_INFO}" 2.0 ||
XML_CATALOG_FILES="/etc/xml/catalog" \
build_with_meson_host shared-mime-info ) ||
! (is_minimum_version "${VERSION_SHARED_MIME_INFO}" 2.0 ||
build_component_full native-shared-mime-info shared-mime-info \
"" "native" "" "no" ) ||