forked from koreader/koxtoolchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
x-compile.sh
executable file
·6365 lines (5994 loc) · 323 KB
/
x-compile.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 -ex
#
# Kindle cross toolchain & lib/bin/util build script
#
# $Id: x-compile.sh 19006 2022-12-25 17:45:39Z NiLuJe $
#
# kate: syntax bash;
#
##
## Using CrossTool-NG (http://crosstool-ng.org/)
SVN_ROOT="${HOME}/SVN"
## Remember where we are... (c.f., https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh)
SCRIPT_NAME="${BASH_SOURCE[0]-${(%):-%x}}"
SCRIPTS_BASE_DIR="$(readlink -f "${SCRIPT_NAME%/*}")"
# Setup xz multi-threading...
export XZ_DEFAULTS="-T 0"
# Speaking of multi-threading, we're using lbzip2 for tar.bz2 files.
# Note that we cannot use the -u flag (despite its potential advantages),
# because the Kindles bundle a truly abysmally old busybox version, one which
# doesn't handle multi-stream bz2 files, like the ones produces by pbzip2 or
# lbzip2 -u...
# FWIW, that's been supported since busybox 1.17.4, but the Kindles use 1.17.1...
# NOTE: That said, even without the -u switch, past a certain archive size (?!),
# it *still* upsets the Kindle's prehistoric busybox version... So avoid lbzip2
# when creating tarballs that will directly be processed on the device... :/
## Version comparison (req. coreutils 7) [cf. https://stackoverflow.com/questions/4023830]
is_ver_gte()
{
[ "${1}" = "$(echo -e "${1}\n${2}" | sort -V | tail -n1)" ]
}
## We never, ever want to be using libtool's .la files. They're terrible, and cause more trouble than they're worth...
# NOTE: c.f., https://flameeyes.blog/2008/04/14/what-about-those-la-files/ for more details.
# NOTE: In our particular context, see the FT build comments for the particular insanity they caused...
prune_la_files()
{
if [ -d "${TC_BUILD_DIR}/lib" ] ; then
find "${TC_BUILD_DIR}/lib" -name "*.la" -type l -delete
find "${TC_BUILD_DIR}/lib" -name "*.la" -type f -delete
fi
}
## Make the window title useful when running this through tmux...
pkgIndex="0"
update_title_info()
{
# Get package name from the current directory, because I'm lazy ;)
pkgName="${PWD##*/}"
# Increment package counter...
pkgIndex="$((pkgIndex + 1))"
# Get number of packages by counting the amount of calls to this very function in the script...
if [[ -z ${pkgCount} ]] ; then
# May not be 100% accurate because of the branching, although we try to manually correct that...
pkgCount="$(grep -c '^[[:blank:]]*update_title_info$' "${SCRIPTS_BASE_DIR}/x-compile.sh")"
# Try to correct the total count by hard-coding the amount of branches...
# There's zlib vs. zlib-ng...
pkgCount="$((pkgCount - 1))"
# There's the GCC 4.9 FT stack thingy...
if [[ "${KINDLE_TC}" == "K5" ]] ; then
pkgCount="$((pkgCount + 3))"
fi
# There's libtommath & libtomcrypt
if [[ "${BUILD_UPSTREAM_LIBTOM}" != "true" ]] ; then
pkgCount="$((pkgCount - 2))"
fi
# There's Gandalf which we only build for K5 & PW2...
if [[ "${KINDLE_TC}" != "K5" ]] && [[ "${KINDLE_TC}" != "PW2" ]] && [[ "${KINDLE_TC}" != "KHF" ]] ; then
pkgCount="$((pkgCount - 1))"
fi
# There's nettle vs. nettle-git
pkgCount="$((pkgCount - 1))"
# There's ICU which we don't always build...
if [[ "${KINDLE_TC}" != "K5" ]] && [[ "${KINDLE_TC}" != "PW2" ]] && [[ "${KINDLE_TC}" != "KHF" ]] && [[ "${KINDLE_TC}" != "KOBO" ]] ; then
pkgCount="$((pkgCount - 1))"
fi
# There's ltrace which we don't build on the K3...
if [[ "${KINDLE_TC}" == "K3" ]] ; then
pkgCount="$((pkgCount - 1))"
fi
# There's perf which we don't build on the K3 & K5...
if [[ "${KINDLE_TC}" == "K3" ]] || [[ "${KINDLE_TC}" == "K5" ]] ; then
pkgCount="$((pkgCount - 1))"
fi
# There's dosfstools which we only build on Kobo...
if [[ "${KINDLE_TC}" != "KOBO" ]] ; then
pkgCount="$((pkgCount - 1))"
fi
fi
# Set the panel name to something short & useful
myPanelTitle="X-TC ${KINDLE_TC}"
echo -e '\033k'${myPanelTitle}'\033\\'
# Set the window title to a longer description of what we're doing...
myWindowTitle="Building ${pkgName} for ${KINDLE_TC} (${pkgIndex} of ${pkgCount})"
echo -e '\033]2;'${myWindowTitle}'\007'
# Bye, Felicia!
prune_la_files
}
## Install/Setup CrossTool-NG
Build_CT-NG-Legacy() {
echo "* Building CrossTool-NG 1.23 . . ."
echo ""
cd ${HOME}/Kindle
mkdir -p CrossTool
cd CrossTool
# Remove previous CT-NG install...
rm -rf CT-NG
mkdir -p CT-NG
cd CT-NG
# Pull our own CT-NG branch, which includes a few tweaks needed to support truly old glibc & kernel versions...
git clone -b 1.23-kindle --single-branch https://github.com/NiLuJe/crosstool-ng.git .
git clean -fxdq
./bootstrap
./configure --enable-local
make -j$(nproc)
# We need a clean set of *FLAGS, or shit happens...
unset CFLAGS CXXFLAGS LDFLAGS
## And then build every TC one after the other...
for my_tc in kindle pocketbook ; do
echo ""
echo "* Building the ${my_tc} ToolChain . . ."
echo ""
# Start by removing the old TC...
[[ -d "${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi" ]] && chmod -R u+w ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi && rm -rf ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi
[[ -d "${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf" ]] && chmod -R u+w ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf && rm -rf ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf
# Then backup the current one...
[[ -d "${HOME}/x-tools/arm-${my_tc}-linux-gnueabi" ]] && mv ${HOME}/x-tools/{,_}arm-${my_tc}-linux-gnueabi
[[ -d "${HOME}/x-tools/arm-${my_tc}-linux-gnueabihf" ]] && mv ${HOME}/x-tools/{,_}arm-${my_tc}-linux-gnueabihf
# Clean the WD
./ct-ng clean
# Build the config from this TC's sample
./ct-ng $(find samples -type d -name "arm-${my_tc}-linux-gnueabi*" | cut -d'/' -f2)
# And fire away!
./ct-ng oldconfig
#./ct-ng menuconfig
./ct-ng updatetools
nice ./ct-ng build
done
}
## Install/Setup CrossTool-NG
Build_CT-NG() {
echo "* Building CrossTool-NG 1.24 . . ."
echo ""
cd ${HOME}/Kindle
mkdir -p CrossTool
cd CrossTool
# Remove previous CT-NG install...
rm -rf CT-NG
mkdir -p CT-NG
cd CT-NG
# Pull our own CT-NG branch, which includes a few tweaks needed to support truly old glibc & kernel versions...
git clone -b 1.24-kindle --single-branch https://github.com/NiLuJe/crosstool-ng.git .
# This also often includes the latest Linaro GCC versions...
# But, more generally,
# This includes the Make-3.82 patch to Glibc 2.9 too, because it fails to build in softfp with make 3.81... -_-" [Cf. http://lists.gnu.org/archive/html/help-make/2012-02/msg00025.html]
# Along with glibc patches to make the version checks more relaxed (i.e., imported from the most recent glibc release) and not die on newer make/gcc/binutils...
# Also backports https://sourceware.org/git/?p=glibc.git;a=commit;h=07037eeb43ca1e0ac2802e3a1492cecf869c63c6 to glibc 2.15, so that it actually builds...
# And https://sourceware.org/git/?p=glibc.git;a=commit;h=3857022a761ea7251f8e5c0e45d382ebc3e34cf9, too...
# NOTE: We *can* use glibc 2.16.0 instead of eglibc 2_15 for the KOBO TC, because eglibc is dead, it's not supported in ct-ng anymore, and glibc 2.15 is terrible (besides the aforementioned build fixes needed, there's the mostly unfixable rpc mess to contend with)
# NOTE: Or, we can use glibc 2.15, patched to the tip of the 2.15 branch (https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/release/2.15/master), which includes sunrpc support, plus the eventual needed fixes (https://sourceware.org/git/?p=glibc.git&a=search&h=HEAD&st=commit&s=sunrpc).
# Cherry-picked commits:
# * https://sourceware.org/git/?p=glibc.git;a=commit;h=3857022a761ea7251f8e5c0e45d382ebc3e34cf9
# * https://sourceware.org/git/?p=glibc.git;a=commit;h=07037eeb43ca1e0ac2802e3a1492cecf869c63c6
# * https://sourceware.org/git/?p=glibc.git;a=commit;h=07c58f8f3501329340bf3c69a347f7c8fdcbe528
# * https://sourceware.org/git/?p=glibc.git;a=commit;h=fb21f89b75d0152aa42efb6b620843799a4cd76b
# NOTE: Don't forget to backport https://sourceware.org/git/?p=glibc.git;a=commit;h=175cef4163dd60f95106cfd5f593b8a4e09d02c9 in glibc-ports to fix build w/ GCC 5
# NOTE: We also still currently need to backport https://git.linaro.org/toolchain/gcc.git/commitdiff/a26dad6a5955ed8574efc8d149faca3963a48d46 in Linaro GCC (ISL-0.15 handling for Graphite)...
# NOTE: The glibc 2.15 stuff currently doesn't apply to the 1.23-kindle branch, since upstream appears to have massaged glibc 2.15 into submission for the 1.23.0 release, which this branch is based on ;).
# XXX: Something is very, very wrong with my Linaro 2016.01 builds: everything segfaults on start (in __libc_csu_init).
# XXX: Progress! With the 2016.02 & 2016.03 snapshots, as well as the 2016.02 release, it SIGILLs (in _init/call_gmon_start)...
# XXX: Building the PW2 TC against glibc 2.19, on the other hand, results in working binaries... WTF?! (5.3 2016.03 snapshot)
# NOTE: Joy? The issue appears to be fixed in Linaro GCC 5.3 2016.04 snapshot! :)
# XXX: I'm seriously considering adding proper support for binutil's native handling of the LTO plugin, via lib/bfd-plugins, instead of relying on the GCC wrappers...
# cd ${HOME}/x-tools/arm-kobo-linux-gnueabihf
# mkdir -p lib/bfd-plugins
# cd lib/bfd-plugins
# ln -sf ../../libexec/gcc/arm-kobo-linux-gnueabihf/7.3.1/liblto_plugin.so.0.0.0 liblto_plugin.so
# NOTE: This *should* be automatically taken care of on ct-ng 1.24 ;).
# NOTE: Performance appears to have gone *noticeably* down between GCC Linaro 7.4 and ARM 8.3 (and even more sharply between ARM 8.3 & FSF 9.2)... :/
# Possibly related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91598
# TL;DR: We're not moving away from the final Linaro TC for now. Yay?
# The good news is all the work involved in moving to ct-ng 1.24 is done, and building Linaro 7.4 also works there, FWIW.
# NOTE: A quick test w/ GCC 10.1 shows slightly more encouraging results...
# PNG decoding w/ stb_image still takes a severe performance hit, but other things are faring better.
# NOTE: With the release of GCC 11.1, GCC 7 is now *very* EoL, so, just move to GCC 11.1 and call it a day.
# Things *are* admittedly a bit better than GCC 10 still, and, as far as stbi is concerned, switching away from Thumb mode does yield better performance (obviously at the expense of larger binaries).
# XXX: https://github.com/NiLuJe/crosstool-ng/commit/90c619fe156f997dfe8ec21bb316901ecd264efc
# was an ill-advised attempt to preserve the full set of computed *FLAGS during GCC's build, but it's problematic with -mcpu builds,
# because libatomic's build may set -march and this trips a warning when mixed w/ -mcpu on ARM, and that warning is fatal because -Werror...
git clean -fxdq
./bootstrap
./configure --enable-local
make -j$(nproc)
# We need a clean set of *FLAGS, or shit happens...
unset CFLAGS CXXFLAGS LDFLAGS
## And then build every TC one after the other...
## FIXME: kindle & pocketbook are broken in the 1.24 branch (The pass-2 core C gcc compiler fails to build libgcc with a multiple definition of `__libc_use_alloca' link failure), for some reason (they both use the same ridiculously old glibc version)...
for my_tc in kindle5 kindlepw2 kobo remarkable bookeen cervantes ; do
echo ""
echo "* Building the ${my_tc} ToolChain . . ."
echo ""
# Start by removing the old TC...
[[ -d "${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi" ]] && chmod -R u+w ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi && rm -rf ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabi
[[ -d "${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf" ]] && chmod -R u+w ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf && rm -rf ${HOME}/x-tools/_arm-${my_tc}-linux-gnueabihf
# Then backup the current one...
[[ -d "${HOME}/x-tools/arm-${my_tc}-linux-gnueabi" ]] && mv ${HOME}/x-tools/{,_}arm-${my_tc}-linux-gnueabi
[[ -d "${HOME}/x-tools/arm-${my_tc}-linux-gnueabihf" ]] && mv ${HOME}/x-tools/{,_}arm-${my_tc}-linux-gnueabihf
# Clean the WD
./ct-ng distclean
# Build the config from this TC's sample
./ct-ng $(find samples -type d -name "arm-${my_tc}-linux-gnueabi*" | cut -d'/' -f2)
# And fire away!
./ct-ng oldconfig
./ct-ng upgradeconfig
#./ct-ng menuconfig
./ct-ng updatetools
nice ./ct-ng build
done
## NOTE: Do that ourselves?
echo ""
echo "* You can now remove the source tarballs ct-ng downloaded in ${HOME}/src . . ."
echo ""
## Config Hints:
cat << EOF > /dev/null
CT-NG Config Overview:
* Paths >
EXPERIMENTAL: [*]
Parallel jobs: 3
* Target >
Arch: arm
Use the MMU
Endianness: Little endian
Bitness: 32-bit
Instruction set: arm
Arch level: armv6j | armv7-a
CPU: arm1136jf-s | cortex-a8 | cortex-a9 # NOTE: Prefer setting CPU instead of Arch & Tune (NOTE: In practice, we do the opposite in our CFLAGS, but using -mcpu when building GCC used to lead to a more accurate Tag_CPU_name aeabi attribute. That doesn't appear to be the case anymore with GCC8+, where -mcpu appears to simply autodetect what to set for -march & -mtune).
Tune: arm1136jf-s | cortex-a8 | cortex-a9
FPU: vfp | neon or vfpv3
Floating point: softfp # NOTE: Can't use hardf, it requires a linux-armhf loader (also, terrible idea to mix ABIs). Interwork is meaningless on ARMv6+. K5: I'm not sure Amazon defaults to Thumb2, but AFAICT we can use it safely.
CFLAGS: # Be very fucking conservative here, so, leave them empty to use the defaults (-O2 -pipe).... And, FWIW, don't use -ffast-math or -Ofast here, '#error "glibc must not be compiled with -ffast-math"' ;).
LDFLAGS:
Default instruction set mode: arm | thumb # NOTE: While Thumb produces noticeably smaller code, that may come at the cost of a veeeeeery small performance hit. Or the better code density might give it a veeeeeery small performance edge ;).
Use EABI: [*]
* TC >
Tuple's vendor: kindle | kindle5 | kindlepw2
* OS >
Target: linux
Kernel: 2.6.27.62 | 2.6.32.71 | 3.0.101 # [Or use the -lab126 tarball from Kindle Source Code packages, but you'll need to patch it. (sed -e 's/getline/get_line/g' -i scripts/unifdef.c)]
* Binary >
Format: ELF
Binutils: 2.26.1
Linkers to enable: ld, gold
Enable threaded gold: [*]
Add ld wrapper: [*]
Enable support for plugins: [*]
* C Compiler >
Type: gcc
Linaro: [*]
Version: linaro-snapshot-5.2-2015.11-2
Additional Lang: C++
Link lstdc++ statically
Disable GRAPHITE # NOTE: Linaro disables it, apparently lacks a proper maintener since ~2013... cf. https://git.linaro.org/toolchain/abe.git/blob/HEAD:/config/gcc.conf#l20
Enable LTO
Opt gcc libs for size [ ] # -Os is evil?
Use __cxa_atexit
<M> sjlj
<M> 128-bit long doubles
Linker hash-style: Default | gnu
* C library >
Type: glibc # NOTE: K5, PW2 & KOBO actually use eglibc, but that's been dropped from ct-ng, and it's ABI compatible, so we use mainline glibc instead
Version: 2.9 | 2.12.2 # NOTE: The ports addon for this glibc version has never been released. Gentoo used the one from 2.12.1. I rolled a tarball manually from https://sourceware.org/git/?p=glibc-ports.git;a=shortlog;h=refs/heads/release/2.12/master (except from the 2.12.2 tag, not the branch).
Threading: nptl
Minimum supported kernel version: 2.6.22 | 2.6.31 | 3.0.35
EOF
##
# NOTE: Be aware that FW 5.6.5 moved to eglibc 2_19 (still softfp, though...). But since we want to keep backwards compatibility, keep using 2.12.2...
# NOTE: Recap of my adventures in trying to use Linaro's ABE (https://wiki.linaro.org/ABE) to look into the GCC 5.3 issues w/ Linaro 5.3 2016.01/2016.02/2016.03...
# For some reason, trying to specify a linux & gmp version is b0rked, and prevents ABE from actually building & installing these components, which obviously breaks everything...
# NOTE: An URL pointing to a tarball is NOT supported, so, that at least explains the gmp failure... Using gmp=file:///usr/portage/distfiles/gmp-6.1.0.tar.xz instead should work, on the other hand... but suprise... it doesn't! :/
# In fact, file:// support doesn't seem to be implemented at all.. :?
# ../ABE/abe.sh --target arm-linux-gnueabi --set languages=c,c++,lto --set cpu=cortex-a9 --set libc=eglibc --set linker=ld gcc=gcc.git~linaro/gcc-5-branch eglibc=eglibc.git~eglibc-2_19 binutils=binutils-gdb.git~binutils-2_26-branch gdb=binutils-gdb.git~gdb-7.11-branch linux=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git~linux-3.0.y gmp=https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2 --build all
# ... And eglibc_2.19 is borked, too... (https://sourceware.org/ml/libc-alpha/2014-12/msg00105.html). YAY. Let's try w/ glibc instead...
# ../ABE/abe.sh --target arm-linux-gnueabi --set languages=c,c++,lto --set cpu=cortex-a9 --set libc=glibc --set linker=ld gcc=gcc.git~linaro/gcc-5-branch glibc=glibc.git~release/2.19/master binutils=binutils-gdb.git~binutils-2_26-branch gdb=binutils-gdb.git~gdb-7.11-branch --build all
# ... And it needs the nptl backports from 2.20 to build on ARM... >_<" (find_exidx.c:(.text+0x36c): undefined reference to `libgcc_s_resume')
# NOTE: On the other hand, a build against glibc 2.20 works... And the resulting binaries do, too... ARGH -_-".
# Although when using --tarbin, it uses a broken default sysroot, for some unfathomable reason... In which case you need to pass --sysroot to GCC, or symlink the sysroot, I guess? cf. https://git.linaro.org/toolchain/abe.git/blob/HEAD:/config/gcc.conf#l170
# NOTE: This relates to the various issues I encountered with these sets of Linaro snapshots, which were fixed in 2016.04 ;).
}
## Choose your TC!
case ${1} in
kindle | k2 | K2 | k3 | K3 )
KINDLE_TC="K3"
;;
kindle5 | k4 | K4 | k5 | K5 )
KINDLE_TC="K5"
;;
khf | kinldehf )
KINDLE_TC="KHF"
;;
kindlepw2 | pw2 | PW2 )
KINDLE_TC="PW2"
;;
kobo | Kobo | KOBO )
KINDLE_TC="KOBO"
;;
nickel | Nickel | NICKEL )
KINDLE_TC="NICKEL"
;;
kobomk7 | mk7 | Mk7 | MK7 )
KINDLE_TC="MK7"
;;
kobomk8 | mk8 | Mk8 | MK8 )
KINDLE_TC="MK8"
;;
remarkable | reMarkable | Remarkable )
KINDLE_TC="REMARKABLE"
;;
pocketbook | pb | PB )
KINDLE_TC="PB"
;;
bookeen | cy | CY )
KINDLE_TC="CY"
;;
# Or build them?
tc )
Build_CT-NG-Legacy
Build_CT-NG
# And exit happy now :)
exit 0
;;
* )
echo "You must choose a ToolChain! (k3, k5, pw2, kobo, mk7, nickel, remarkable, pocketbook or bookeen)"
echo "Or, alternatively, ask to build them (tc)"
exit 1
;;
esac
## NOTE: Reminder of the various stuff I had to install on a fresh Gentoo box...
#
# Don't forget the kernel sources for strace...
#
# For the packaging scripts:
# cave resolve -x lbzip2 pigz
# cave resolve dev-perl/File-MimeInfo -x
# cave resolve -x kindletool
# cave resolve -x svn2cl
# cave resolve -x rar
# cave resolve p7zip rar python-swiftclient python-keystoneclient
#
# emerge -a lbzip2 pigz dev-perl/File-MimeInfo kindletool svn2cl rar p7zip python-swiftclient python-keystoneclient app-text/dos2unix
#
# For harfbuzz:
# cave resolve -1 ragel gobject-introspection-common -x
#
# emerge -a gobject-introspection-common
#
# For OpenSSH & co:
# mkdir -p /mnt/onboard/.niluje/usbnet && mkdir -p /mnt/us/usbnet && chown -cvR niluje:users /mnt/us && chown -cvR niluje:users /mnt/onboard
#
# For Python:
#
# emerge -a dev-lang/python:2.7 dev-lang/python:3.9
#
# For Python 3rd party modules:
# cave resolve -x distutilscross
#
# emerge -a dev-python/distutilscross dev-python/distutilscross:2.7
#
# For FC:
# cave resolve -x dev-python/lxml (for fontconfig)
#
# emerge -a dev-python/lxml
#
# For SQLite:
# emerge -a dev-lang/tcl
#
# For lxml:
# emerge -a dev-python/cython dev-python/cython:2.7
#
# For BeautifulSoup:
# emerge -a dev-vcs/breezy
#
# For mosh:
# emerge -a protobuf
#
# For some stuff since Autoconf 2.70:
# emerge -a gtk-doc
#
# To fetch everything:
# cave resolve -1 -z -f -x sys-libs/zlib expat freetype harfbuzz util-linux fontconfig coreutils dropbear rsync busybox dev-libs/openssl:0 openssh ncurses htop lsof protobuf mosh libarchive gmp nettle libpng libjpeg-turbo '<=media-gfx/imagemagick-7' bzip2 dev-libs/libffi sys-libs/readline icu sqlite dev-lang/python:2.7 dev-lang/python dev-libs/glib sys-fs/fuse elfutils file nano libpcre zsh mit-krb5 libtirpc xz-utils libevent tmux gdb --uninstalls-may-break '*/*'
# OR
# emerge -1 -f sys-libs/zlib expat freetype harfbuzz util-linux fontconfig coreutils dropbear rsync busybox dev-libs/openssl:0 openssh ncurses htop lsof protobuf mosh libarchive gmp nettle libpng libjpeg-turbo '<=media-gfx/imagemagick-7' bzip2 dev-libs/libffi sys-libs/readline icu sqlite dev-lang/python:2.7 dev-lang/python:3.9 dev-libs/glib sys-fs/fuse elfutils file nano libpcre zsh mit-krb5 libtirpc xz-utils libevent tmux gdb libxml2 libxslt curl pax-utils libpcre2 less dev-vcs/git lftp app-text/tree
#
##
## Setup our env to use the right TC
echo "* Setting environment up . . ."
echo ""
## Setup parallellization... Shamelessly stolen from crosstool-ng ;).
AUTO_JOBS=$(($(getconf _NPROCESSORS_ONLN 2> /dev/null || echo 0) + 1))
JOBSFLAGS="-j${AUTO_JOBS}"
case ${KINDLE_TC} in
K3 )
ARCH_FLAGS="-march=armv6j -mtune=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp"
CROSS_TC="arm-kindle-linux-gnueabi"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
## NOTE: See http://gcc.gnu.org/gcc-4.7/changes.html & http://comments.gmane.org/gmane.linux.linaro.devel/12115 & http://comments.gmane.org/gmane.linux.ports.arm.kernel/117863
## But, basically, if you want to build a Kernel, backport https://github.com/mirrors/linux/commit/8428e84d42179c2a00f5f6450866e70d802d1d05 [it's not in FW 2.5.8/3.4/4.1.0/5.1.2],
## or build your Kernel with -mno-unaligned-access
## You might also want to backport https://github.com/mirrors/linux/commit/088c01f1e39dbe93a13e0b00f4532ed8b79d35f4 if you intend to roll your own Kernel.
## For those interested, basically, if your kernel has this: https://github.com/mirrors/linux/commit/baa745a3378046ca1c5477495df6ccbec7690428 then you're safe in userland.
## (That's the commit merged in 2.6.28 that the GCC docs refer to).
## It's in FW 3.x/4.x/5.x, so we're good on *some* Kindles. However, it's *NOT* in FW 2.x, and the trap handler defaults to ignoring unaligned access faults.
## I haven't seen any *actual* issues yet, but the counter does increment...
## So, to be on the safe side, let's use -mno-unaligned-access on the K3 TC, to avoid going kablooey in weird & interesting ways on FW 2.x... ;)
## And again, if you roll your own kernel with this TC, this may also be of interest to you: https://bugs.launchpad.net/linaro-toolchain-binaries/+bug/1186218/comments/7
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "4.7" ; then
ARM_NO_UNALIGNED_ACCESS="-mno-unaligned-access"
fi
## NOTE: The new libstdc++ ABI might cause some issues if not handled on GCC >= 5.1 (cf. https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html), so, disable it...
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "5.1" ; then
LEGACY_GLIBCXX_ABI="-D_GLIBCXX_USE_CXX11_ABI=0"
## NOTE: Like the FORTIFY stuff, this should *really* be in CPPFLAGS, but we have to contend with broken buildsystems that don't honor CPPFLAGS... So we go with the more ubiquitous CFLAGS instead ;/.
fi
## NOTE: When linking dynamically, disable GCC 4.3/Glibc 2.8 fortify & stack-smashing protection support to avoid pulling symbols requiring GLIBC_2.8 or GCC_4.3
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${ARM_NO_UNALIGNED_ACCESS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin -fno-stack-protector"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${ARM_NO_UNALIGNED_ACCESS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -fno-stack-protector"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} ${ARM_NO_UNALIGNED_ACCESS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin -fno-stack-protector"
## NOTE: And here comes another string of compatibility related tweaks...
# We don't have mkostemp on Glibc 2.5... ;) (fontconfig)
export ac_cv_func_mkostemp=no
# Avoid pulling __isoc99_sscanf@GLIBC_2.7 (dropbear, libjpeg-turbo, fuse, sshfs, zsh), and disable fortify to avoid the few _chk symbols that are from glibc 2.8
# NOTE: We do this here because, besides being the right place for them, some stuff (autotools?) might put CPPFLAGS *after* CFLAGS...
# And, yeah, the insane -U -> -D=0 dance appears to be necessary, or some things would stubbornly attempt to pull _chk symbols...
BASE_CPPFLAGS="-D_GNU_SOURCE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -U__USE_FORTIFY_LEVEL -D__USE_FORTIFY_LEVEL=0"
# utimensat's only available since Glibc 2.6, so we can't use it (rsync, libarchive)
export ac_cv_func_utimensat=no
# Avoid pulling stuff from glibc 2.6... (libarchive, xz-utils)
export ac_cv_func_futimens=no
# Avoid pulling stuff from GLIBC_2.7 & 2.9 (glib, gdb)
export glib_cv_eventfd=no
export ac_cv_func_pipe2=no
# Avoid pulling stuff from GLIBC_2.9, 2.8 & 2.7 (libevent)
export ac_cv_func_epoll_create1=no
export ac_cv_func_timerfd_create=no
export ac_cv_header_sys_timerfd_h=no
export ac_cv_func_eventfd=no
export ac_cv_header_sys_eventfd_h=no
## NOTE: The Glade guys built a tool to automate the symver approach to at worst detecting, at best handling the "build for an earlier glibc ABI" situation ;).
# It's called LibcWrapGenerator, and the libcwrap-kindle.h header in this repo was built with it.
# You basically pass it to every GCC call via -include (via a CC override instead of CPPFLAGS to deal with the largest amount of stupid buildsystems).
# It's not perfect: it won't help you automagically avoid *new* or *variant* symbols for instance, but it'll at least make it very explicit with a linker failure,
# instead of having to check everything later via readelf!
# c.f., https://gitlab.gnome.org/GNOME/glade/blob/master/build/linux/README for more info.
## NOTE: Shitty one-liner to check binaries: for file in $(find Configs/trunk/Kindle/Hacks -type f) ; do ; file "${file}" | grep -q "ELF 32-bit" && echo "${file}" && readelf -V "${file}" | grep "Name: GLIBC_" | awk '{print $3}' | sort -u ; done
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
#BASE_CFLAGS="${NOLTO_CFLAGS}"
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
BASE_CPPFLAGS="${BASE_CPPFLAGS} -isystem${TC_BUILD_DIR}/include"
export CPPFLAGS="${BASE_CPPFLAGS}"
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
## CMake is hell.
export CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_BASE_DIR}/CMakeCross.txt -DCMAKE_INSTALL_PREFIX=${TC_BUILD_DIR}"
DEVICE_USERSTORE="/mnt/us"
;;
K5 )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mthumb"
CROSS_TC="arm-kindle5-linux-gnueabi"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
## NOTE: The new libstdc++ ABI might cause some issues if not handled on GCC >= 5.1 (cf. https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html), so, disable it...
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "5.1" ; then
LEGACY_GLIBCXX_ABI="-D_GLIBCXX_USE_CXX11_ABI=0"
## NOTE: Like the FORTIFY stuff, this should *really* be in CPPFLAGS, but we have to contend with broken buildsystems that don't honor CPPFLAGS... So we go with the more ubiquitous CFLAGS instead ;/.
fi
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
#BASE_CFLAGS="${NOLTO_CFLAGS}"
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
export CPPFLAGS="${BASE_CPPFLAGS}"
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/Touch_Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
## CMake is hell.
export CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_BASE_DIR}/CMakeCross.txt -DCMAKE_INSTALL_PREFIX=${TC_BUILD_DIR}"
DEVICE_USERSTORE="/mnt/us"
;;
PW2 | KHF )
case ${KINDLE_TC} in
PW2 )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp -mthumb"
CROSS_TC="arm-kindlepw2-linux-gnueabi"
;;
KHF )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -mthumb"
CROSS_TC="arm-kindlehf-linux-gnueabihf"
;;
esac
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
## NOTE: The new libstdc++ ABI might cause some issues if not handled on GCC >= 5.1 (cf. https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html), so, disable it...
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "5.1" ; then
LEGACY_GLIBCXX_ABI="-D_GLIBCXX_USE_CXX11_ABI=0"
## NOTE: Like the FORTIFY stuff, this should *really* be in CPPFLAGS, but we have to contend with broken buildsystems that don't honor CPPFLAGS... So we go with the more ubiquitous CFLAGS instead ;/.
fi
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
## XXX: Crazy compat flags if the TC has been built against glibc 2.19...
## Why would we do that? Because since FW 5.6.5, that's actually the glibc version used, and, more importantly,
## it was part of an experiment: with the apparently broken Linaro 5.3 snapshots from 2016.01 to 2016.3, a TC built against glibc 2.19 would work, instead of silently generating broken code...
## NOTE: The root issue was fixed in Linaro 5.3 2016.04, which makes that whole experiment an archeological relic ;).
if [[ -f "${HOME}/x-tools/${CROSS_TC}/${CROSS_TC}/sysroot/lib/libc-2.19.so" ]] ; then
echo "!!"
echo "!! ENABLING GLIBC 2.19 -> GLIBC 2.12 COMPAT FLAGS! !!"
echo "!!"
# __<math>_finite@GLIBC_2.15 on ScreenSavers/src/linkss/lib/libpng16.so.16 & ScreenSavers/src/linkss/bin/convert & USBNetwork/src/usbnet/bin/htop
BASE_CFLAGS="${BASE_CFLAGS} -fno-finite-math-only"
NOLTO_CFLAGS="${NOLTO_CFLAGS} -fno-finite-math-only"
# getauxval@GLIBC_2.16 on USBNetwork/src/usbnet/lib/libcrypto.so.1.0.0
KINDLE_TC_IS_GLIBC_219="true"
# __fdelt_chk@GLIBC_2.15 on USBNetwork/src/usbnet/bin/mosh-* & OpenSSH
# __poll_chk@GLIBC_2.16 on OpenSSH
# NOTE: Requires killing FORTIFY_SOURCE... We do it on site w/ a KINDLE_TC_IS_GLIBC_219 check.
# XXX: Don't forget to kill those stray checks if I ever get rid of this monstrosity...
# clock_gettime@GLIBC_2.17 on USBNetwork/src/usbnet/bin/mosh-* & OpenSSH & USBNetwork/src/usbnet/bin/sshfs
# NOTE: This one is particular in that the function existed, it was just in librt instead of libc ;).
export ac_cv_search_clock_gettime="-lrt"
# setns@GLIBC_2.14 on GDB
export ac_cv_func_setns="no"
fi
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
#BASE_CFLAGS="${NOLTO_CFLAGS}"
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
export CPPFLAGS="${BASE_CPPFLAGS}"
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/PW2_Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
## CMake is hell.
export CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_BASE_DIR}/CMakeCross.txt -DCMAKE_INSTALL_PREFIX=${TC_BUILD_DIR}"
DEVICE_USERSTORE="/mnt/us"
;;
KOBO | NICKEL | MK7 | MK8 )
case ${KINDLE_TC} in
MK8 )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard -mthumb"
;;
MK7 )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -mthumb"
## NOTE: The only difference between FSF GCC (https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/releases/gcc-10) and Arm's branch (https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/vendors/ARM/heads/arm-10) is
## https://gcc.gnu.org/git?p=gcc.git;a=commit;h=3b91aab15443ee150b2ba314a4b26645ce8d713b (e.g., https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80155).
## If we wanted to mimic that, since we actually build against FSF GCC, we could disable code-hoisting here. Doesn't really seem to help us in practice though, so, eh.
#ARCH_FLAGS="${ARCH_FLAGS} -fno-code-hoisting"
## NOTE: As for defaulting to Thumb mode, that's consistent with Linaro's default armv7 configs.
;;
* )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard -mthumb"
;;
esac
case ${KINDLE_TC} in
KOBO )
CROSS_TC="arm-kobo-linux-gnueabihf"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
;;
NICKEL )
CROSS_TC="arm-nickel-linux-gnueabihf"
# NOTE: We use a directory tree slightly more in line w/ ct-ng here...
if [[ -n "${_XTC_WD}" ]] ; then
TC_BUILD_DIR="${_XTC_WD}/${CROSS_TC}/${CROSS_TC}/sysroot/usr"
else
TC_BUILD_DIR="${HOME}/Kobo/CrossTool/Build_${KINDLE_TC}/${CROSS_TC}/${CROSS_TC}/sysroot/usr"
fi
;;
MK7 )
CROSS_TC="arm-kobomk7-linux-gnueabihf"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
;;
MK8 )
CROSS_TC="arm-kobomk8-linux-gnueabihf"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
;;
esac
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
if [[ -n "${_XTC_DIR}" ]] ; then
export PATH="${_XTC_DIR}/${CROSS_TC}/bin:${PATH}"
else
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
fi
## NOTE: The new libstdc++ ABI might cause some issues if not handled on GCC >= 5.1 (cf. https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html), so, disable it...
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "5.1" ; then
LEGACY_GLIBCXX_ABI="-D_GLIBCXX_USE_CXX11_ABI=0"
## NOTE: Like the FORTIFY stuff, this should *really* be in CPPFLAGS, but we have to contend with broken buildsystems that don't honor CPPFLAGS... So we go with the more ubiquitous CFLAGS instead ;/.
fi
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
if [[ "${KINDLE_TC}" == "NICKEL" ]] ; then
# GCC 4.9 was terrible at LTO
BASE_CFLAGS="${NOLTO_CFLAGS}"
fi
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
if [[ "${KINDLE_TC}" == "NICKEL" ]] ; then
# That's a standard searchpath, no need to enforce it
BASE_CPPFLAGS=""
else
BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
fi
export CPPFLAGS="${BASE_CPPFLAGS}"
if [[ "${KINDLE_TC}" == "NICKEL" ]] ; then
# That's a standard searchpath, no need to enforce it
BASE_LDFLAGS="-Wl,-O1 -Wl,--as-needed"
else
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
fi
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/Kobo_Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
## NOTE: For Nickel, we want to pickup the sysroot, too, because this is where we chucked Qt...
if [[ "${KINDLE_TC}" == "NICKEL" ]] ; then
if [[ -n "${_XTC_DIR}" ]] ; then
BASE_SYSROOT="${_XTC_DIR}/${CROSS_TC}/${CROSS_TC}/sysroot"
else
BASE_SYSROOT="${HOME}/x-tools/${CROSS_TC}/${CROSS_TC}/sysroot"
fi
BASE_SYSROOT_PKG_CONFIG_LIBDIR="${BASE_SYSROOT}/usr/lib/pkgconfig"
BASE_PKG_CONFIG_LIBDIR="${BASE_SYSROOT_PKG_CONFIG_LIBDIR}:${TC_BUILD_DIR}/lib/pkgconfig"
# And since we'll have potentially two different sources of .pc files, and some of them may have been been baked with a no-longer viable build prefix, letting pkg-config compute the prefix based on the .pc's location sounds like a Great Idea!
# c.f., https://github.com/pgaskin/kobo-plugin-experiments/commit/7020977c611c9301c07ef1cb24656fd09acef77a
# NOTE: We bypass the TC's pkg-config wrapper because we want to use multiple searchpaths, no fixed sysroot, and --define-prefix ;).
BASE_PKG_CONFIG="pkg-config --define-prefix"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
# Let pkg-config strip the right redundant system paths
export PKG_CONFIG_SYSTEM_INCLUDE_PATH="${BASE_SYSROOT}/usr/include"
export PKG_CONFIG_SYSTEM_LIBRARY_PATH="${BASE_SYSROOT}/usr/lib:${BASE_SYSROOT}/lib"
else
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
fi
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
## CMake is hell.
export CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_BASE_DIR}/CMakeCross.txt -DCMAKE_INSTALL_PREFIX=${TC_BUILD_DIR}"
# Kobos are finnicky as hell, so take some more precautions...
# On the vfat partition, don't use the .kobo folder, since it might go poof with no warning in case of troubles...
# (It gets deleted by the Account sign out process, which is *possibly* what happens automatically in case of database corruption...)
# NOTE: One massive downside is that, since FW 4.17, Nickel will now scan *all* subdirectories, including hidden ones... >_<"
DEVICE_ONBOARD_USERSTORE="/mnt/onboard/.niluje"
# And we'll let dropbear live in the internal memory to avoid any potential interaction with USBMS...
DEVICE_INTERNAL_USERSTORE="/usr/local/niluje"
DEVICE_USERSTORE="${DEVICE_ONBOARD_USERSTORE}"
;;
REMARKABLE )
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard -mthumb"
CROSS_TC="arm-remarkable-linux-gnueabihf"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
## NOTE: Upstream is (currently) using GCC 7.3, so we have no potential C++ ABI issue to take care of :)
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} -pipe -fomit-frame-pointer -frename-registers -fweb"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
#BASE_CFLAGS="${NOLTO_CFLAGS}"
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
export CPPFLAGS="${BASE_CPPFLAGS}"
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/reMarkable_Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR="${BASE_PKG_CONFIG_LIBDIR}"
## CMake is hell.
export CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_BASE_DIR}/CMakeCross.txt -DCMAKE_INSTALL_PREFIX=${TC_BUILD_DIR}"
DEVICE_USERSTORE="/home/root"
;;
PB )
# NOTE: The TC itself is built in ARM mode, otherwise glibc 2.9 doesn't build (fails with a "r15 not allowed here" assembler error on csu/libc-start.o during the early multilib start-files step).
# AFAICT, the official SDK doesn't make a specific choice on that front (i.e., it passes neither -marm not -mthumb. That usually means ARM)...
ARCH_FLAGS="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mthumb"
CROSS_TC="arm-pocketbook-linux-gnueabi"
TC_BUILD_DIR="${HOME}/Kindle/CrossTool/Build_${KINDLE_TC}"
# Export it for our CMakeCross TC file
export CROSS_TC
export TC_BUILD_DIR
export CROSS_PREFIX="${CROSS_TC}-"
export PATH="${HOME}/x-tools/${CROSS_TC}/bin:${PATH}"
## NOTE: The new libstdc++ ABI might cause some issues if not handled on GCC >= 5.1 (c.f., https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html), so, disable it...
## NOTE: This is a bit annoying on PB, because older FW were based on GCC 4.8.1 (so, old ABI), but newer FW (5.19+) are based on GCC 6.3.0 + Clang 7 (so, new ABI, not libc++) :/.
if is_ver_gte "$(${CROSS_TC}-gcc -dumpversion)" "5.1" ; then
LEGACY_GLIBCXX_ABI="-D_GLIBCXX_USE_CXX11_ABI=0"
## NOTE: Like the FORTIFY stuff, this should *really* be in CPPFLAGS, but we have to contend with broken buildsystems that don't honor CPPFLAGS... So we go with the more ubiquitous CFLAGS instead ;/.
fi
BASE_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
NOLTO_CFLAGS="-O3 -ffast-math ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb"
## Here be dragons!
RICE_CFLAGS="-O3 -ffast-math -ftree-vectorize -funroll-loops ${ARCH_FLAGS} ${LEGACY_GLIBCXX_ABI} -pipe -fomit-frame-pointer -frename-registers -fweb -flto=${AUTO_JOBS} -fuse-linker-plugin"
## NOTE: Check if LTO still horribly breaks some stuff...
## NOTE: See https://gcc.gnu.org/gcc-4.9/changes.html for the notes about building LTO-enabled static libraries... (gcc-ar/gcc-ranlib)
## NOTE: And see https://gcc.gnu.org/gcc-5/changes.html to rejoice because we don't have to care about broken build-systems with mismatched compile/link time flags anymore :).
export AR="${CROSS_TC}-gcc-ar"
export RANLIB="${CROSS_TC}-gcc-ranlib"
export NM="${CROSS_TC}-gcc-nm"
## NOTE: Also, BOLO for packages thant link with $(CC) $(LDFLAGS) (ie. without CFLAGS). This is BAD. One (dirty) workaround if you can't fix the package is to append CFLAGS to the end of LDFLAGS... :/
## NOTE: ... although GCC 5 should handle this in a transparent & sane manner, so, yay :).
#BASE_CFLAGS="${NOLTO_CFLAGS}"
export CFLAGS="${BASE_CFLAGS}"
export CXXFLAGS="${BASE_CFLAGS}"
# NOTE: Use -isystem instead of -I to make sure GMP doesn't do crazy stuff... (FIXME: -idirafter sounds more correct for our use-case, though...)
BASE_CPPFLAGS="-isystem${TC_BUILD_DIR}/include"
export CPPFLAGS="${BASE_CPPFLAGS}"
BASE_LDFLAGS="-L${TC_BUILD_DIR}/lib -Wl,-O1 -Wl,--as-needed"
# NOTE: Dirty LTO workaround (cf. earlier). All hell might break loose if we tweak CFLAGS for some packages...
#BASE_LDFLAGS="${BASE_CFLAGS} ${BASE_LDFLAGS}"
export LDFLAGS="${BASE_LDFLAGS}"
# NOTE: We're no longer using the gold linker by default...
# FIXME: Because for some mysterious reason, gold + LTO leads to an unconditional dynamic link against libgcc_s (uless -static-libgcc is passed, of course).
export CTNG_LD_IS="bfd"
## NOTE: We jump through terrible hoops to counteract libtool's stripping of 'unknown' or 'harmful' FLAGS... (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html)
## That's a questionable behavior that is bound to screw up LTO in fun and interesting ways, at the very least on the performance aspect of things...
## Store those in the right format here, and apply patches or tricks to anything using libtool, because of course it's a syntax that gcc doesn't know about, so we can't simply put it in the global LDFLAGS.... -_-".
## And since autotools being autotools, it's used in various completely idiosyncratic ways, we can't always rely on simply overriding AM_LDFLAGS...
## NOTE: Hopefully, GCC 5's smarter LTO handling means we don't have to care about that anymore... :).
export XC_LINKTOOL_CFLAGS="-Wc,-ffast-math -Wc,-fomit-frame-pointer -Wc,-frename-registers -Wc,-fweb"
BASE_HACKDIR="${SVN_ROOT}/Configs/trunk/Kindle/PB_Hacks"
# We always rely on the native pkg-config, with custom search paths
BASE_PKG_CONFIG="pkg-config"
export PKG_CONFIG="${BASE_PKG_CONFIG}"
BASE_PKG_CONFIG_LIBDIR="${TC_BUILD_DIR}/lib/pkgconfig"
export PKG_CONFIG_PATH=""