-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsetup-environ.sh
executable file
·1120 lines (946 loc) · 38.1 KB
/
setup-environ.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
# Written and placed in public domain by Jeffrey Walton
# This script verifies most prerequisites and creates
# an environment for other scripts to execute in.
#
# Generally speaking, a variable with uppercase INSTX_ is used
# throughout the scripts, like INSTX_CFLAGS and INSTX_CXX11. The
# INSTX_ variables are usually exported. A variable with lowercase
# opt_ is used only in this file. The opt_variables stay local to
# this file.
#
# We use Bash arrays, but we avoid ARR+=("$foo"). The '+=' operator
# came after arrays in Bash history. Early machines will handle arrays
# but not the '+=' operator.
#
# The 'grep' command is Posix, and the options -i, -c, and -E are Posix.
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
#
# The 'command' command is Posix, and the option -v is Posix.
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
#
# The 'awk' command is Posix, and printing fields using NR is Posix.
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
###############################################################################
# SC2034: XXX appears unused. Verify use (or export if used externally).
# SC2086: Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2034,SC2086
###############################################################################
# `gcc ... -o /dev/null` does not work on Solaris.
# `mktemp` is not available on AIX or Git Windows shell...
infile="in.${RANDOM}${RANDOM}.c"
outfile="out.${RANDOM}${RANDOM}"
cp programs/test-stdc.c "${infile}"
###############################################################################
CURR_DIR=$(pwd); export CURR_DIR
function finish {
rm -f "${CURR_DIR}/${infile}" 2>/dev/null
rm -f "${CURR_DIR}/${outfile}" 2>/dev/null
rm -rf "${CURR_DIR}/${outfile}.dSYM" 2>/dev/null
}
trap finish EXIT INT
###############################################################################
# We need to stash the top level directory for some scripts
if [[ -z ${INSTX_TOPDIR} ]]; then
INSTX_TOPDIR=$(pwd)
fi
if [[ ! -d "${INSTX_TOPDIR}/programs" ]]; then
printf "INSTX_TOPDIR is not valid."
[[ "$0" == "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
export INSTX_TOPDIR
###############################################################################
# Prerequisites needed for nearly all packages. Set to 1 to skip check.
if [[ "${INSTX_DISABLE_PKGCONFIG_CHECK}" -ne 1 ]]; then
if [[ -z $(command -v pkg-config 2>/dev/null) ]]; then
printf "%s\n" "Some packages require Package-config. Please install pkg-config, pkgconfig or pkgconf."
[[ "$0" == "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
fi
if [[ "${INSTX_DISABLE_GZIP_CHECK}" -ne 1 ]]; then
if [[ -z $(command -v gzip 2>/dev/null) ]]; then
printf "%s\n" "Some packages require Gzip. Please install Gzip."
[[ "$0" == "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
fi
if [[ "${INSTX_DISABLE_TAR_CHECK}" -ne 1 ]]; then
if [[ -z $(command -v tar 2>/dev/null) ]]; then
printf "%s\n" "Some packages require Tar. Please install Tar."
[[ "$0" == "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
fi
###############################################################################
# Command line tools, like sed and awk, need this on OS X.
if [[ $(uname -s | grep -i -c 'darwin') -ne 0 ]]; then
if [[ -z "$LC_ALL" ]]; then
if locale -a 2>/dev/null | grep -q en_US.UTF-8; then
export LC_ALL="en_US.UTF-8"
elif locale -a 2>/dev/null | grep -q '^C'; then
export LC_ALL="C"
fi
fi
if [[ -z "$LANG" ]]; then
if locale -a 2>/dev/null | grep -q en_US.UTF-8; then
export LANG="en_US.UTF-8"
elif locale -a 2>/dev/null | grep -q '^C'; then
export LANG="C"
fi
fi
fi
###############################################################################
THIS_SYSTEM=$(uname -s 2>&1)
IS_HURD=$(grep -i -c 'gnu' <<< "$THIS_SYSTEM")
IS_LINUX=$(grep -i -c 'linux' <<< "$THIS_SYSTEM")
IS_SOLARIS=$(grep -i -c 'sunos' <<< "$THIS_SYSTEM")
IS_DARWIN=$(grep -i -c 'darwin' <<< "$THIS_SYSTEM")
IS_AIX=$(grep -i -c 'aix' <<< "$THIS_SYSTEM")
IS_CYGWIN=$(grep -i -c 'cygwin' <<< "$THIS_SYSTEM")
IS_OPENBSD=$(grep -i -c 'openbsd' <<< "$THIS_SYSTEM")
IS_FREEBSD=$(grep -i -c 'freebsd' <<< "$THIS_SYSTEM")
IS_NETBSD=$(grep -i -c 'netbsd' <<< "$THIS_SYSTEM")
IS_APPLE_M1=$(sysctl machdep.cpu.brand_string 2>/dev/null | grep -i -c 'Apple M1')
THIS_SYSTEM=$(uname -v 2>&1)
IS_ALPINE=$(grep -i -c 'alpine' <<< "$THIS_SYSTEM")
export IS_LINUX IS_SOLARIS IS_DARWIN
export IS_CYGWIN IS_OPENBSD IS_FREEBSD IS_NETBSD
export IS_AIX IS_HURD IS_ALPINE
###############################################################################
GREP="${GREP:-"$(command -v grep 2>/dev/null)"}"
EGREP="${EGREP:-"$(command -v grep 2>/dev/null) -E"}"
SED="${SED:-"$(command -v sed 2>/dev/null)"}"
AWK="${AWK:-"$(command -v awk 2>/dev/null)"}"
# Non-anemic tools on Solaris
if [[ -d /usr/gnu/bin ]]; then
GREP="/usr/gnu/bin/grep"
EGREP="/usr/gnu/bin/grep -E"
SED="/usr/gnu/bin/sed"
AWK="/usr/gnu/bin/awk"
elif [[ -d /usr/sfw/bin ]]; then
GREP="/usr/sfw/bin/grep"
EGREP="/usr/sfw/bin/grep -E"
SED="/usr/sfw/bin/sed"
AWK="/usr/sfw/bin/awk"
fi
# Wget is special. We have to be able to bootstrap it and
# use a modern version throughout these scripts. The Wget
# we provide in ${HOME} is modern but crippled. However, it
# is enough to download all the packages we need.
if [[ -z "${WGET}" ]]; then
if [[ -e "${HOME}/.build-scripts/wget/bin/wget" ]]; then
WGET="${HOME}/.build-scripts/wget/bin/wget"
elif [[ -n "$(command -v wget 2>/dev/null)" ]]; then
WGET="$(command -v wget 2>/dev/null)"
fi
fi
# Automatically update the user's cacerts now. On occasion we need
# to add or remove a certificate. Otherwise, there are unexplained
# download failures.
bash setup-cacerts.sh 1>/dev/null
# OS X may not have a Wget available. However, a few build scripts
# intelligently fallback to cURL on OS X to get a critical download.
if [[ "${INSTX_DISABLE_WGET_CHECK}" -ne 1 && -z "${WGET}" ]]; then
echo "Failed to find Wget. If you have one, set WGET=/path/to/wget."
echo "If you don't have one, you can run ./setup-wget.sh."
exit 1
fi
export WGET
###############################################################################
# Paths are awful on Solaris. An unmodified environment only
# has /usr/bin and /usr/sbin on-path with anemic tools. They
# manage to provide fewer options than Posix...
if [ "${IS_SOLARIS}" -ne 0 ]
then
for path in /usr/gnu/bin /usr/sfw/bin /usr/ucb/bin /usr/xpg4/bin /bin /usr/bin /sbin /usr/sbin
do
if [ -d "$path" ]; then
SOLARIS_PATH="$SOLARIS_PATH:$path"
fi
done
# Add user's path in case a binary is in a non-standard location,
# like /opt/local. Place the PATH after SOLARIS_PATH so the anemic
# tools are last in the list.
PATH="$SOLARIS_PATH:$PATH"
fi
# Ensure Command Line Tools is on-path, if present.
if [ "${IS_DARWIN}" -ne 0 ]
then
for path in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin \
/Library/Developer/CommandLineTools/usr/bin
do
if [ -d "$path" ]; then
DARWIN_PATH="$DARWIN_PATH:$path"
fi
done
# Add user's path in case a binary is in a non-standard location,
# like /opt/local. Place the PATH after SOLARIS_PATH so the anemic
# tools are last in the list.
PATH="$DARWIN_PATH:$PATH"
fi
# Strip duplicate, leading and trailing colons
PATH=$(echo "$PATH" | tr -s ':' | ${SED} -e 's/^:\(.*\)/\1/' | ${SED} -e 's/:$//g')
export PATH
# echo "New PATH: $PATH"
###############################################################################
# OS X flavors. We delete everything prior to the
# version number to normalize the stream for awk.
# Old OS X uses 'System Version: Mac OS X 10.5.8'.
# New OS X uses 'System Version: OS X 10.9.5'.
# OS X 10.5 was last to support PowerPC.
OSX_VERSION=$(system_profiler SPSoftwareDataType 2>&1 | ${GREP} 'System Version:' | ${SED} 's/^[^[:digit:]]*//' | ${AWK} '{print $1}')
OSX_10p10_OR_ABOVE=$(${EGREP} -i -c -E "10\.1[0-9]|1[1-9]\.|[2-9][0-9]" <<< "$OSX_VERSION")
OSX_10p8_OR_ABOVE=$(${EGREP} -i -c -E "10\.[8-9]|10\.1[0-9]|1[1-9]\.|[2-9][0-9]" <<< "$OSX_VERSION")
OSX_10p9_OR_BELOW=$(${EGREP} -i -c -E "10\.[0-9]\." <<< "$OSX_VERSION")
OSX_10p5_OR_BELOW=$(${EGREP} -i -c -E "10\.[0-5]\." <<< "$OSX_VERSION")
OSX_10p5_OR_10p6=$(${EGREP} -i -c -E "10\.5|10\.6" <<< "$OSX_VERSION")
export OSX_10p5_OR_BELOW OSX_10p5_OR_10p6 OSX_10p9_OR_BELOW
export OSX_10p8_OR_ABOVE OSX_10p10_OR_ABOVE
if [[ "${OSX_10p5_OR_10p6}" -eq 1 ]]; then
export MACOSX_DEPLOYMENT_TARGET="10.5"
elif [[ "${OSX_10p5_OR_BELOW}" -eq 1 ]]; then
export MACOSX_DEPLOYMENT_TARGET="10.3"
fi
# Check for the BSD family members
THIS_SYSTEM=$(uname -s 2>&1)
IS_BSD_FAMILY=$(${EGREP} -i -c 'dragonfly|freebsd|netbsd|openbsd' <<< "$THIS_SYSTEM")
# Red Hat and derivatives use /lib64, not /lib.
IS_REDHAT=$(${GREP} -i -c 'redhat' /etc/redhat-release 2>/dev/null)
IS_CENTOS=$(${GREP} -i -c 'centos' /etc/centos-release 2>/dev/null)
IS_FEDORA=$(${GREP} -i -c 'fedora' /etc/fedora-release 2>/dev/null)
IS_DRAGONFLY=$(uname -s | ${GREP} -i -c DragonFly 2>/dev/null)
if [[ "$IS_REDHAT" -ne 0 || "$IS_CENTOS" -ne 0 || "$IS_FEDORA" -ne 0 ]]
then
IS_RH_FAMILY=1
else
IS_RH_FAMILY=0
fi
THIS_MACHINE=$(uname -m 2>&1)
IS_IA32=$(${EGREP} -i -c 'i86pc|i.86|amd64|x86_64' <<< "$THIS_MACHINE")
IS_AMD64=$(${EGREP} -i -c 'amd64|x86_64' <<< "$THIS_MACHINE")
IS_MIPS=$(${EGREP} -i -c 'mips' <<< "$THIS_MACHINE")
export IS_IA32 IS_AMD64 IS_MIPS
# The BSDs and Solaris should have GMake installed if its needed
if [[ -z "${MAKE}" ]]; then
if [[ $(command -v gmake 2>/dev/null) ]]; then
MAKE="gmake"
else
MAKE="make"
fi
fi
# Fix "don't know how to make w" on the BSDs
if [[ "${MAKE}" == "make" ]]; then
MAKEOPTS=
fi
export MAKE MAKEOPTS
USER_CC=${CC}
USER_CXX=${CXX}
# If CC and CXX are not set, then use default or assume Clang or GCC
if [[ -z "${CC}" ]]; then
CC=$(make -p 2>/dev/null | ${EGREP} '^CC.*=' | head -n 1 | cut -f 2 -d '=' | ${AWK} '{$1=$1};1')
fi
if [[ -z "${CXX}" ]]; then
CXX=$(make -p 2>/dev/null | ${EGREP} '^CXX.*=' | head -n 1 | cut -f 2 -d '=' | ${AWK} '{$1=$1};1')
fi
# Fixup for Solaris
if [[ -z "$(command -v "${CC}" 2>/dev/null)" ]]; then CC= ; fi;
if [[ -z "$(command -v "${CXX}" 2>/dev/null)" ]]; then CXX= ; fi;
# Use Clang as default on Darwin
if [[ "${IS_DARWIN}" -ne 0 ]]; then
if [[ -n "$(command -v clang 2>/dev/null)" ]]; then CC='clang'; fi
if [[ -n "$(command -v clang++ 2>/dev/null)" ]]; then CXX='clang++'; fi
fi
# Use GCC as default elsewhere, or on Darwin if Clang fails
if [[ -z "${CC}" ]] && [[ -n "$(command -v gcc 2>/dev/null)" ]]; then CC='gcc'; fi
if [[ -z "${CXX}" ]] && [[ -n "$(command -v g++ 2>/dev/null)" ]]; then CXX='g++'; fi
# After all the gyrations, use the user's choice
if [[ -n "${USER_CC}" ]]; then CC=${USER_CC}; fi
if [[ -n "${USER_CXX}" ]]; then CXX=${USER_CXX}; fi
# Finally, use the full path
CC="$(command -v "${CC}" 2>/dev/null)"
CXX="$(command -v "${CXX}" 2>/dev/null)"
TEST_CC="${CC}"
TEST_CXX="${CXX}"
export CC CXX
IS_GCC=$(${CC} --version 2>&1 | ${EGREP} -i -c 'gnu|gcc')
IS_CLANG=$(${CC} --version 2>&1 | ${EGREP} -i -c 'clang|llvm')
IS_SUNC=$(${CC} -V 2>&1 | ${EGREP} -i -c 'sun|studio')
if [[ "${IS_GCC}" -eq 1 ]]; then
GCC_4_OR_BELOW=$(${CC} --version 2>&1 | ${EGREP} -i -c '(GCC) 3\.|(GCC) 4\.')
fi
###############################################################################
# Where the package will run. We need to override for 64-bit Solaris.
# On Solaris some Autotools packages use 32-bit instead of 64-bit build.
AUTOCONF_BUILD=$(bash programs/config.guess 2>/dev/null)
# Use 64-bit for Solaris if available
# https://docs.oracle.com/cd/E37838_01/html/E66175/features-1.html
if [[ "${IS_SOLARIS}" -ne 0 ]]
then
if [[ $(isainfo -b 2>/dev/null) = 64 ]]; then
CFLAGS64=-m64
CXXFLAGS64=-m64
TEST_CC="${TEST_CC} -m64"
TEST_CXX="${TEST_CXX} -m64"
fi
fi
IS_SUN_AMD64=$(isainfo -v 2>/dev/null | ${EGREP} -i -c 'amd64')
IS_SUN_SPARCv9=$(isainfo -v 2>/dev/null | ${EGREP} -i -c 'sparcv9')
# Solaris Fixup
if [[ "${IS_SUN_AMD64}" -eq 1 ]]; then
IS_AMD64=1
AUTOCONF_BUILD=$(${SED} 's/i386/x86_64/g' <<< "${AUTOCONF_BUILD}")
elif [[ "${IS_SUN_SPARCv9}" -eq 1 ]]; then
AUTOCONF_BUILD=$(${SED} 's/sparc/sparcv9/g' <<< "${AUTOCONF_BUILD}")
fi
# Apple M1 fixup
if [[ ${IS_APPLE_M1} -eq 1 ]]; then
AUTOCONF_BUILD="aarch64-apple-darwin"
fi
export AUTOCONF_BUILD
###############################################################################
# Try to determine 32 vs 64-bit, /usr/local/lib, /usr/local/lib32,
# /usr/local/lib64 and /usr/local/lib/64. We drive a test compile
# using the supplied compiler and flags.
if ${TEST_CC} ${CFLAGS} programs/test-64bit.c -o "${outfile}" 2>/dev/null
then
IS_64BIT=1
IS_32BIT=0
INSTX_BITNESS=64
else
IS_64BIT=0
IS_32BIT=1
INSTX_BITNESS=32
fi
# Some of the BSDs install user software into /usr/local.
# We don't want to overwrite the system installed software.
if [[ "${IS_BSD_FAMILY}" -ne 0 ]]; then
DEF_PREFIX="/opt/local"
else
DEF_PREFIX="/usr/local"
fi
# Don't override a user choice of INSTX_PREFIX
if [[ -z "${INSTX_PREFIX}" ]]; then
INSTX_PREFIX="$DEF_PREFIX"
fi
# RPATH's and their history at https://lekensteyn.nl/rpath.html.
# $ORIGIN on Linux should be available back to about 1998.
# We feature test for INSTX_OPATH and INSTX_RPATH below.
# AIX also needs -bsvr4; while HP-UX uses -Wl,+b.
if [[ "${IS_SOLARIS}" -ne 0 ]]; then
DEF_LIBDIR="${INSTX_PREFIX}/lib"
DEF_RPATH="${INSTX_PREFIX}/lib"
DEF_OPATH="'""\$ORIGIN/../lib""'"
elif [[ "${IS_DARWIN}" -ne 0 ]]; then
DEF_LIBDIR="${INSTX_PREFIX}/lib"
DEF_RPATH="${INSTX_PREFIX}/lib"
DEF_OPATH="@loader_path/../lib"
elif [[ "${IS_RH_FAMILY}" -ne 0 ]] && [[ "$IS_64BIT" -ne 0 ]]; then
DEF_LIBDIR="${INSTX_PREFIX}/lib64"
DEF_RPATH="${INSTX_PREFIX}/lib64"
DEF_OPATH="'""\$ORIGIN/../lib64""'"
else
DEF_LIBDIR="${INSTX_PREFIX}/lib"
DEF_RPATH="${INSTX_PREFIX}/lib"
DEF_OPATH="'""\$ORIGIN/../lib""'"
fi
# Don't override a user choice of INSTX_LIBDIR. Also see
# https://blogs.oracle.com/dipol/dynamic-libraries,-rpath,-and-mac-os
if [[ -z "${INSTX_LIBDIR}" ]]; then
INSTX_LIBDIR="$DEF_LIBDIR"
fi
if [[ -z "${INSTX_SRCDIR}" ]]; then
INSTX_SRCDIR="$INSTX_PREFIX/src"
fi
if [[ -z "${INSTX_RPATH}" ]]; then
INSTX_RPATH="${DEF_RPATH}"
fi
if [[ -z "${INSTX_OPATH}" ]]; then
INSTX_OPATH="${DEF_OPATH}"
fi
# Remove duplicate and trailing slashes.
INSTX_PREFIX="$(echo ${INSTX_PREFIX} | tr -s '/' | ${SED} -e 's/\/$//g')"
INSTX_LIBDIR="$(echo ${INSTX_LIBDIR} | tr -s '/' | ${SED} -e 's/\/$//g')"
INSTX_SRCDIR="$(echo ${INSTX_SRCDIR} | tr -s '/' | ${SED} -e 's/\/$//g')"
INSTX_RPATH="$(echo ${INSTX_RPATH} | tr -s '/' | ${SED} -e 's/\/$//g')"
INSTX_OPATH="$(echo ${INSTX_OPATH} | tr -s '/' | ${SED} -e 's/\/$//g')"
export INSTX_BITNESS
export INSTX_PREFIX INSTX_LIBDIR INSTX_SRCDIR
export INSTX_RPATH INSTX_OPATH
###############################################################################
# Add our path since we know we are using the latest binaries.
# Strip duplicate, leading and trailing colons. This will bite
# us for the Wget we build for PREFIX. It is having problems
# with some multibyte names on Ubuntu.
PATH=$(echo "${INSTX_PREFIX}/bin:$PATH" | tr -s ':' | ${SED} -e 's/^:\(.*\)/\1/' | ${SED} -e 's/:$//g')
export PATH
###############################################################################
cc_result=$(${TEST_CC} -fPIC -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_pic="-fPIC"
else
cc_result=$(${TEST_CC} -qpic -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_pic="-qpic"
else
cc_result=$(${TEST_CC} -KPIC -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_pic="-KPIC"
fi
fi
fi
# Ugh... C++11 support as required. Things may still break.
cc_result=$(${TEST_CXX} -o "${outfile}" programs/test-cxx11.cpp 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
INSTX_CXX11=1
fi
cc_result=$(${TEST_CXX} -o "${outfile}" programs/test-cxx11-atomic.cpp 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
INSTX_CXX11_ATOMIC=1
fi
# Ugh... C++14 support as required. Things may still break.
cc_result=$(${TEST_CXX} -o "${outfile}" programs/test-cxx14.cpp 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
INSTX_CXX14=1
fi
# patchelf needs C++11 support. BerkeleyDB needs atomics.
INSTX_CXX11="${INSTX_CXX11:-0}"
INSTX_CXX11_ATOMIC="${INSTX_CXX11_ATOMIC:-0}"
INSTX_CXX14="${INSTX_CXX14:-0}"
export INSTX_CXX11 INSTX_CXX11_ATOMIC INSTX_CXX14
# For the benefit of the programs and libraries. Make them run faster.
cc_result=$(${TEST_CC} -march=native -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_native="-march=native"
fi
# PowerMac's with 128-bit long double. Gnulib and GetText expect 64-bit long double.
cc_result=$(${TEST_CC} -o "${outfile}" programs/test-128bit-double.c 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
if [[ $("./${outfile}") == "106" ]]; then
opt_64bit_dbl="-mlong-double-64"
fi
fi
cc_result=$(${TEST_CC} -pthread -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_pthread="-pthread"
fi
# Switch from -march=native to something more appropriate
if [[ $(${EGREP} -i -c 'armv7' /proc/cpuinfo 2>/dev/null) -ne 0 ]]; then
cc_result=$(${TEST_CC} -march=armv7-a -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_armv7="-march=armv7-a"
fi
fi
# See if we can upgrade to ARMv7+NEON
if [[ $(${EGREP} -i -c 'neon' /proc/cpuinfo 2>/dev/null) -ne 0 ]]; then
cc_result=$(${TEST_CC} -march=armv7-a -mfpu=neon -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_ARM_NEON=1
opt_armv7="-march=armv7-a -mfpu=neon"
fi
fi
# See if we can upgrade to ARMv8
if [[ $(${EGREP} -i -c 'asimd' /proc/cpuinfo 2>/dev/null) -ne 0 ]]; then
cc_result=$(${TEST_CC} -march=armv8-a -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_ARMV8=1
opt_armv8="-march=armv8-a"
fi
fi
if [[ $(sysctl -a 2>/dev/null | ${EGREP} -i -c 'hw.optional.arm64: 1') -ne 0 ]]; then
cc_result=$(${TEST_CC} -arch arm64 -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_ARMV8=1
opt_armv8="-arch arm64"
fi
fi
# See if we can upgrade to Altivec
if [[ $(${EGREP} -i -c 'altivec' /proc/cpuinfo 2>/dev/null) -ne 0 ]]; then
cc_result=$(${TEST_CC} -maltivec -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_ALTIVEC=1
opt_altivec="-maltivec"
fi
fi
# See if we can upgrade to Altivec
if [[ $(sysctl -a 2>/dev/null | ${EGREP} -i -c 'hw.optional.altivec: 1') -ne 0 ]]; then
cc_result=$(${TEST_CC} -maltivec -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_ALTIVEC=1
opt_altivec="-maltivec"
fi
fi
# See if we can upgrade to Power8
if [[ $(${EGREP} -i -c 'crypto' /proc/cpuinfo 2>/dev/null) -ne 0 ]]; then
cc_result=$(${TEST_CC} -mcpu=power8 -maltivec -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
IS_POWER8=1
opt_power8="-mcpu=power8 -maltivec"
fi
fi
# See if -Wl,-rpath,$ORIGIN/../lib works
cc_result=$(${TEST_CC} -Wl,-rpath,${INSTX_OPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_opath="-Wl,-rpath,${INSTX_OPATH}"
fi
cc_result=$(${TEST_CC} -Wl,-R,${INSTX_OPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_opath="-Wl,-R,${INSTX_OPATH}"
fi
cc_result=$(${TEST_CC} -Wl,-R,${INSTX_OPATH} -bsvr4 -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_opath="-Wl,-R,${INSTX_OPATH} -bsvr4"
fi
cc_result=$(${TEST_CC} -Wl,+b,${INSTX_OPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_opath="-Wl,+b,${INSTX_OPATH}"
fi
# See if -Wl,-rpath,${libdir} works.
cc_result=$(${TEST_CC} -Wl,-rpath,${INSTX_RPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_rpath="-Wl,-rpath,${INSTX_RPATH}"
fi
cc_result=$(${TEST_CC} -Wl,-R,${INSTX_RPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_rpath="-Wl,-R,${INSTX_RPATH}"
fi
cc_result=$(${TEST_CC} -Wl,-R,${INSTX_RPATH} -bsvr4 -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_rpath="-Wl,-R,${INSTX_RPATH} -bsvr4"
fi
cc_result=$(${TEST_CC} -Wl,+b,${INSTX_RPATH} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_rpath="-Wl,+b,${INSTX_RPATH}"
fi
# See if RUNPATHs are available. new-dtags convert a RPATH to a RUNPATH.
cc_result=$(${TEST_CC} -Wl,--enable-new-dtags -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_new_dtags="-Wl,--enable-new-dtags"
fi
# http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#shobj_dependencies
cc_result=$(${TEST_CC} ${opt_opath} -Wl,-z,origin -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_origin="-Wl,-z,origin"
fi
cc_result=$(${TEST_CC} -Wl,--no-as-needed -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_no_as_needed="-Wl,--no-as-needed"
fi
# OS X linker and install names
cc_result=$(${TEST_CC} -headerpad_max_install_names -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_max_header_pad="-headerpad_max_install_names"
fi
# Debug versus release builds
if [[ -n "${INSTX_DEBUG}" ]]; then
opt_cppflags_build="-DDEBUG"
else
opt_cppflags_build="-DNDEBUG"
fi
# Debug symbols
if [[ -z "$opt_sym" ]]; then
cc_result=$(${TEST_CC} -g2 -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_sym="-g2"
else
cc_result=$(${TEST_CC} -g -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_sym="-g"
fi
fi
# If we are building under the sanitizers with GCC or Clang, just use -g3
if [[ -n "${INSTX_UBSAN}" || -n "${INSTX_ASAN}" || -n "$INSTX_MSAN" ]]; then
opt_sym="-g3"
fi
# If we are building a debug build with GCC or Clang, just use -g3
if [[ -n "${INSTX_DEBUG}" ]]; then
opt_sym="-g3"
fi
fi
# Optimizations
if [[ -z "$opt_optimize" ]]; then
cc_result=$(${TEST_CC} -O2 -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_optimize="-O2"
else
cc_result=$(${TEST_CC} -O -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_optimize="-O"
fi
fi
# If we are building under the sanitizers with GCC or Clang, just use -O1
if [[ -n "${INSTX_UBSAN}" || -n "${INSTX_ASAN}" || -n "$INSTX_MSAN" ]]; then
opt_optimize="-O1"
fi
# If we are building a debug build with GCC or Clang, just use -O0
if [[ -n "${INSTX_DEBUG}" ]]; then
opt_optimize="-O0"
fi
fi
# Location to install the sources. Limit to Linux for the moment.
# https://alex.dzyoba.com/blog/gdb-source-path/
if [[ "${IS_LINUX}" -ne 0 ]]; then
# No need to install sources for Sanitizer testing.
if [[ "${INSTX_ASAN}" -eq 0 && "${INSTX_MSAN}" -eq 0 && "${INSTX_UBSAN}" -eq 0 ]]; then
cc_result=$(${TEST_CC} -g -fdebug-prefix-map=${PWD}=${PWD} -o "${outfile}" "${infile}" 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
INSTX_DEBUG_MAP=1
export INSTX_DEBUG_MAP
fi
fi
fi
# Perl does not add -lm when needed
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -lm 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
INSTX_LIBM=1
export INSTX_LIBM
fi
# OpenBSD does not have -ldl
if [[ -z "${opt_dl}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -ldl 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_dl="-ldl"
fi
fi
if [[ -z "${opt_libpthread}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -lpthread 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_libpthread="-lpthread"
fi
fi
# -fno-sanitize-recover causes an abort(). Useful for test
# programs that swallow UBsan output and pretty print "OK"
if [[ -z "${opt_san_no_recover}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fsanitize=undefined -fno-sanitize-recover=all 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_san_no_recover="-fno-sanitize-recover=all"
else
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fsanitize=undefined -fno-sanitize-recover 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_san_no_recover="-fno-sanitize-recover"
fi
fi
fi
# IEEE-754 allows divide by 0
if [[ -z "${opt_san_no_int_div_0}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fno-sanitize=integer-divide-by-zero 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_san_no_int_div_0="-fno-sanitize=integer-divide-by-zero"
fi
fi
# IEEE-754 allows divide by 0
if [[ -z "${opt_san_no_flt_div_0}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fno-sanitize=float-divide-by-zero 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_san_no_flt_div_0="-fno-sanitize=float-divide-by-zero"
fi
fi
# Disable LTO, sometimes
if [[ -z "$opt_no_lto" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fno-lto 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_no_lto="-fno-lto"
fi
fi
# Msan option
if [[ -z "$opt_msan_origin" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -fsanitize-memory-track-origins 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_msan_origin=1
fi
fi
# GOT and PLT hardening
if [[ -z "${opt_relro}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -Wl,-z,relro 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_relro="-Wl,-z,relro"
fi
fi
if [[ -z "${opt_now}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -Wl,-z,now 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_now="-Wl,-z,now"
fi
fi
# NX stacks
if [[ -z "${opt_as_nxstack}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -Wa,--noexecstack 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_as_nxstack="-Wa,--noexecstack"
fi
fi
if [[ -z "${opt_ld_nxstack}" ]]; then
cc_result=$(${TEST_CC} -o "${outfile}" "${infile}" -Wl,-z,noexecstack 2>&1 | wc -w)
if [[ "$cc_result" -eq 0 ]]; then
opt_ld_nxstack="-Wl,-z,noexecstack"
fi
fi
###############################################################################
# CA cert path? Also see http://gagravarr.org/writing/openssl-certs/others.shtml
# For simplicity use ${INSTX_PREFIX}/etc/pki. Avoid about 10 different places.
INSTX_CACERT_PATH="${INSTX_PREFIX}/etc/pki"
INSTX_CACERT_FILE="${INSTX_PREFIX}/etc/pki/cacert.pem"
INSTX_ROOTKEY_PATH="${INSTX_PREFIX}/etc/unbound"
INSTX_ROOTKEY_FILE="${INSTX_PREFIX}/etc/unbound/dnsrootkey.pem"
INSTX_ICANN_PATH="${INSTX_PREFIX}/etc/unbound"
INSTX_ICANN_FILE="${INSTX_PREFIX}/etc/unbound/icannbundle.pem"
export INSTX_CACERT_PATH INSTX_CACERT_FILE
export INSTX_ROOTKEY_PATH INSTX_ROOTKEY_FILE
export INSTX_ICANN_PATH INSTX_ICANN_FILE
###############################################################################
opt_pkgconfig=("${INSTX_LIBDIR}/pkgconfig")
opt_cppflags=("-I${INSTX_PREFIX}/include" "${opt_cppflags_build}")
opt_cflags=("$opt_sym" "$opt_optimize")
opt_cxxflags=("$opt_sym" "$opt_optimize")
opt_asflags=()
opt_ldflags=("-L${INSTX_LIBDIR}")
opt_ldlibs=()
if [[ -n "${CFLAGS64}" ]]
then
opt_cflags[${#opt_cflags[@]}]="${CFLAGS64}"
opt_cxxflags[${#opt_cxxflags[@]}]="${CFLAGS64}"
opt_asflags[${#opt_asflags[@]}]="${CFLAGS64}"
opt_ldflags[${#opt_ldflags[@]}]="${CFLAGS64}"
fi
if [[ -n "${opt_64bit_dbl}" ]]
then
opt_cflags[${#opt_cflags[@]}]="${opt_64bit_dbl}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_64bit_dbl}"
fi
# No common symbols on Darwin
if [[ "${IS_DARWIN}" -ne 0 ]]; then
opt_cflags[${#opt_cflags[@]}]="-fno-common"
opt_cxxflags[${#opt_cxxflags[@]}]="-fno-common"
fi
# Debug, UBsan, Asan, Msan and Analyzer builds
if [[ -n "${INSTX_DEBUG}" ]]; then
opt_cppflags[${#opt_cppflags[@]}]="-DTEST_DEBUG=1"
opt_cflags[${#opt_cflags[@]}]="-fno-omit-frame-pointer"
opt_cxxflags[${#opt_cxxflags[@]}]="-fno-omit-frame-pointer"
elif [[ -n "${INSTX_UBSAN}" ]]; then
opt_cppflags[${#opt_cppflags[@]}]="-DTEST_UBSAN=1"
opt_cflags[${#opt_cflags[@]}]="-fsanitize=undefined"
opt_cxxflags[${#opt_cxxflags[@]}]="-fsanitize=undefined"
opt_ldflags[${#opt_ldflags[@]}]="-fsanitize=undefined"
if [[ -n "${opt_san_no_int_div_0}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_san_no_int_div_0}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_san_no_int_div_0}"
opt_ldflags[${#opt_ldflags[@]}]="${opt_san_no_int_div_0}"
fi
if [[ -n "${opt_san_no_flt_div_0}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_san_no_flt_div_0}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_san_no_flt_div_0}"
opt_ldflags[${#opt_ldflags[@]}]="${opt_san_no_flt_div_0}"
fi
if [[ -n "${opt_san_no_recover}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_san_no_recover}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_san_no_recover}"
opt_ldflags[${#opt_ldflags[@]}]="${opt_san_no_recover}"
fi
elif [[ -n "${INSTX_ASAN}" ]]; then
opt_cppflags[${#opt_cppflags[@]}]="-DTEST_ASAN=1"
opt_cflags[${#opt_cflags[@]}]="-fsanitize=address"
opt_cflags[${#opt_cflags[@]}]="-fno-omit-frame-pointer"
opt_cxxflags[${#opt_cxxflags[@]}]="-fsanitize=address"
opt_cxxflags[${#opt_cxxflags[@]}]="-fno-omit-frame-pointer"
opt_ldflags[${#opt_ldflags[@]}]="-fsanitize=address $opt_no_lto"
# Requires GCC 10, like on Fedora 32
elif [[ -n "$INSTX_ANALYZE" ]]; then
opt_cppflags[${#opt_cppflags[@]}]="-DTEST_ANALYZE=1"
opt_cflags[${#opt_cflags[@]}]="-fanalyzer"
opt_cflags[${#opt_cflags[@]}]="-fno-omit-frame-pointer"
opt_cxxflags[${#opt_cxxflags[@]}]="-fanalyzer"
opt_cxxflags[${#opt_cxxflags[@]}]="-fno-omit-frame-pointer"
opt_ldflags[${#opt_ldflags[@]}]="-fanalyzer"
elif [[ -n "$INSTX_MSAN" ]]; then
opt_cppflags[${#opt_cppflags[@]}]="-DTEST_MSAN=1"
opt_cflags[${#opt_cflags[@]}]="-fsanitize=memory"
opt_cflags[${#opt_cflags[@]}]="-fno-omit-frame-pointer"
opt_cxxflags[${#opt_cxxflags[@]}]="-fsanitize=memory"
opt_cxxflags[${#opt_cxxflags[@]}]="-fno-omit-frame-pointer"
opt_ldflags[${#opt_ldflags[@]}]="-fsanitize=memory"
opt_ldflags[${#opt_ldflags[@]}]="-fno-omit-frame-pointer"
if [[ -n "$opt_msan_origin" ]]; then
opt_cflags[${#opt_cflags[@]}]="-fsanitize-memory-track-origins"
opt_cxxflags[${#opt_cxxflags[@]}]="-fsanitize-memory-track-origins"
opt_ldflags[${#opt_ldflags[@]}]="-fsanitize-memory-track-origins"
fi
fi
if [[ -n "${opt_armv8}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_armv8}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_armv8}"
elif [[ -n "${opt_armv7}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_armv7}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_armv7}"
elif [[ -n "${opt_native}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_native}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_native}"
fi
if [[ -n "${opt_power8}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_power8}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_power8}"
elif [[ -n "${opt_altivec}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_altivec}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_altivec}"
fi
if [[ -n "${opt_pic}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_pic}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_pic}"
fi
if [[ -n "${opt_pthread}" ]]; then
opt_cflags[${#opt_cflags[@]}]="${opt_pthread}"
opt_cxxflags[${#opt_cxxflags[@]}]="${opt_pthread}"
fi
if [[ -n "${opt_as_nxstack}" ]]; then
opt_asflags[${#opt_asflags[@]}]="${opt_as_nxstack}"
fi
if [[ -n "${opt_opath}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_opath}"
fi
if [[ -n "${opt_rpath}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_rpath}"
fi
if [[ -n "${opt_new_dtags}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_new_dtags}"
fi
if [[ -n "${opt_relro}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_relro}"
fi
if [[ -n "${opt_now}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_now}"
fi
if [[ -n "${opt_ld_nxstack}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_ld_nxstack}"
fi
if [[ -n "${opt_origin}" ]]; then
opt_ldflags[${#opt_ldflags[@]}]="${opt_origin}"
fi
if [[ -n "${opt_dl}" ]]; then
opt_ldlibs[${#opt_ldlibs[@]}]="${opt_dl}"
fi
if [[ -n "${opt_libpthread}" ]]; then
opt_ldlibs[${#opt_ldlibs[@]}]="${opt_libpthread}"
fi
#if [[ "${IS_DARWIN}" -ne 0 ]] && [[ -n "${opt_max_header_pad}" ]]; then
# opt_ldflags[${#opt_ldflags[@]}]="${opt_max_header_pad}"
#fi
###############################################################################
# Used to track packages that have been built by these scripts.
# The accounting is local to a user account. There is no harm
# in rebuilding a package under another account.
if [[ -z "${INSTX_PKG_CACHE}" ]]; then
# Change / to - for CACHE_DIR
CACHE_DIR=$(cut -c 2- <<< "${INSTX_PREFIX}" | ${SED} 's/\//-/g')
INSTX_PKG_CACHE="${HOME}/.build-scripts/${CACHE_DIR}"
mkdir -p "${INSTX_PKG_CACHE}"
fi
export INSTX_PKG_CACHE
# If the package is older than 7 days, then rebuild it. This sidesteps the
# problem of continually rebuilding the same package when installing a
# program like Git and SSH. It also avoids version tracking by automatically
# building a package after 7 days (even if it is the same version).
IFS= find "${INSTX_PKG_CACHE}" -type f -mtime +7 -print | while read -r pkg
do
# printf "Setting %s for rebuild\n" "$pkg"
rm -f "$pkg" 2>/dev/null
done
###############################################################################
# Solaris and OS X may have the GNU tools.
if [[ -n "$(command -v glibtool 2>/dev/null)" ]];
then