forked from haiku/haiku
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·1211 lines (1108 loc) · 37.1 KB
/
configure
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/sh
#
# configure [ <options> ]
# usage
#
# Prints usage.
#
usage()
{
cat << EOF
Usage: $0 <options>
options:
--help Prints out this help.
--update Re-runs last configure invocation [must be given
as first option!]
--bootstrap <haikuporter> <HaikuPorts cross repo> <HaikuPorts repo>
Prepare for a bootstrap build. No pre-built
packages will be used, instead they will be built
from the sources (in several phases).
<haikuporter> is the path to the haikuporter tool
suitable for the host platform.
<HaikuPorts cross repo> is the path to a checked
out HaikuPorts cross-compilation repository.
<HaikuPorts repo> is the path to a checked out
HaikuPorts repository.
--build-cross-tools <arch>
Assume cross compilation.
Toolchain will be compiled and placed in the
output directory under "cross-tools". The
HAIKU_* tools variables will be set accordingly.
<arch> specifies the target architecture, either
"x86_gcc2", "x86", "x86_64", "ppc", "m68k",
"arm", "arm64", "riscv64", "sparc"
This option and --cross-tools-prefix can be
specified multiple times. The first cross tools
specify the primary tools, the subsequent ones the
secondary tools (for "hybrid" images).
--cross-tools-prefix <prefix>
Assume cross compilation. <prefix> should be a
path to the directory where the cross
compilation tools are located, plus the platform
prefix, e.g. "/path/to/tools/i586-pc-haiku-".
This overrides the HAIKU_* tool variables.
--cross-tools-source <buildtools dir>
Toolchain sources for cross compilation.
<buildtools dir> defines the location of the
buildtools sources.
--distro-compatibility <level>
The distribution's level of compatibility with
the official Haiku distribution. The generated
files will contain the respective trademarks
accordingly.
official -- the official Haiku distribution.
compatible -- a Haiku Compatible (tm) distro.
default -- any other distro (default value).
--host-only Configure for building tools for the build host
only. Haiku cannot be built when configured like
this.
--include-sources Includes the source code of projects that require
either an offer of source code or a copy of the
patched sources. This is preferable when
distributing on physical mediums.
--include-3rdparty Include 3rdparty/ in the build system.
-j<n> Only relevant for --build-cross-tools. Is passed
on to the make building the build tools.
--no-downloads Do not download anything. Useful when trying to
bootstrap and build Haiku from source only.
--sysroot The location of the cross-compiler sysroot,
primarily for CI environments or cross-compilers
used outside of the Haiku build system.
--target-arch <arch> Haiku only: Specify the target architecture to
build for. Must be one of the architectures of the
host system. The installed build tools for that
architecture will be used.
This option can be specified multiple times. The
first occurrence specifies the primary
architecture of the Haiku to build, subsequent
ones the secondary architectures.
--use-clang <arch> Build with host Clang instead of GCC cross
compiler, targeting <arch>
--use-gcc-pipe Build with GCC option -pipe. Speeds up the build
process, but uses more memory.
--use-gcc-graphite Build with GCC Graphite engine for loop
optimizations. (Only for GCC 4+.)
--use-32bit Use -m32 flag on 64bit host gcc compiler.
--no-full-xattr Do not use Linux/*BSD/Darwin's native extended file
attributes as Haiku attributes. If they are still
available, they will be used to store hashes for
the attribute emulation layer.
--no-xattr Do not use Linux/*BSD/Darwin's native extended file
attributes for Haiku extended attributes at all,
even if they are available.
--with-gdb <gdb sources dir>
specify the path to a GDB source dir, to build
GDB for each arch we build the cross-tools for.
--use-stack-protector Build with stack protection enabled
--efi-signing-key Private keyfile to sign any EFI bootloaders
environment variables:
CC The host compiler. Defaults to "gcc".
HAIKU_AR_<arch> The static library archiver for <arch>.
Defaults to "ar".
HAIKU_CC_<arch> The compiler for <arch>. Defaults to "gcc".
HAIKU_LD_<arch> The <arch> linker. Defaults to "ld".
HAIKU_OBJCOPY_<arch> The <arch> objcopy to be used. Defaults to
"objcopy".
HAIKU_RANLIB_<arch> The static library indexer for <arch>. Defaults
to "ranlib".
HAIKU_STRIP_<arch> The <arch> strip command. Defaults to "strip".
HAIKU_NASM The nasm assembler (x86 and x86_64 only).
HAIKU_CPPFLAGS_<arch> The preprocessor flags for target architecture
<arch>. Defaults to "".
HAIKU_CCFLAGS_<arch> The C flags for target architecture <arch>.
Defaults to "".
HAIKU_CXXFLAGS_<arch> The C++ flags for target architecture <arch>.
Defaults to "".
HAIKU_LINKFLAGS_<arch> The flags passed to the compiler when linking for
target architecture <arch>. Defaults to "".
HAIKU_LDFLAGS_<arch> The linker flags for target architecture <arch>.
Defaults to "".
HAIKU_ARFLAGS_<arch> The flags passed to HAIKU_AR for target
architecture <arch> for archiving. Defaults to
"cru".
HAIKU_UNARFLAGS_<arch> The flags passed to HAIKU_AR for target
architecture <arch> for unarchiving. Defaults to
"x".
Non-default output directories:
By default all objects, build configuration, and other related files are
stored in /path/to/haiku_source/generated. To store objects in a non-default
location, run "../../relative/path/to/haiku_source/configure <options>" from
within your non-default location. "jam [ options ] targets" can then be run
directly inside your non-default location. Another option is to invoke "jam
[ options ] targets" from within haiku_source. This can be accomplished by
either "export HAIKU_OUTPUT_DIR=your non-default location" before invoking
jam or by creating a symlink of haiku_source/generated pointing to your
non-default location and running jam.
EOF
}
# assertparam
#
# Checks whether at least one parameter is left.
#
assertparam()
{
if [ $2 -lt 2 ]; then
echo $0: \`$1\': Parameter expected.
exit 1
fi
}
# assertparams
#
# Checks whether at least a certain number of parameters is left.
#
assertparams()
{
if [ $3 -le $2 ]; then
echo $0: \`$1\': Not enough parameters.
exit 1
fi
}
# absolute_path
#
# returns the absolute path of a given path.
#
absolute_path()
{
if [ "x$1" != "x${1#/}" ]; then
echo "$1"
else
echo "`pwd`/$1"
fi
}
# check_dir_exists
#
# check if a directory exists or not
#
check_dir_exists()
{
if [ -d "$1" ]; then
return 0
else
return 1
fi
}
# check_file_exists
#
# check if a file exists or not
#
check_file_exists()
{
if [ -f "$1" ]; then
return 0
else
return 1
fi
}
# real_path
#
# returns the realpath of a symbolic link.
#
real_path()
{
perl -MCwd=realpath -e'print realpath($ARGV[0]), "\n"' "$1"
}
# relative_to
#
# returns $1 relative to $2
#
relative_to()
{
perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' \
"$1" "$2"
}
# valid_toolchain
#
# check if a toolchain is valid
#
valid_toolchain()
{
TRIPLET="$1"
BASE="$2"
SOURCE="$3"
if [ ! -d "$BASE" ]; then
return 1
fi
if [ -f "$BASE/bin/$TRIPLET-gcc" ]; then
[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/legacy/gcc/configure" ] && \
[ "$BASE/bin/$TRIPLET-gcc" -nt "$SOURCE/gcc/gcc/configure" ]
return $?
fi
return 1
}
# is_legacy_gcc
#
# Determines if the specified GCC version is a "legacy" (i.e. GCC < 4) one.
#
is_legacy_gcc()
{
if [ `echo $1 | cut -d'.' -f1` -lt 4 ]; then
echo 1
else
echo 0
fi
}
# standard_gcc_settings
#
# Sets the variables for a GCC platform.
#
standard_gcc_settings()
{
local gcc="$1"
if which greadlink > /dev/null 2>&1; then
readlink="greadlink -e"
elif which realpath > /dev/null 2>&1; then
readlink=realpath
elif readlink -e / > /dev/null 2>&1; then
readlink="readlink -e"
else
readlink=real_path
fi
# PLATFORM_LINKLIBS
local gcclib=`$gcc -print-libgcc-file-name`
local gccdir=`dirname ${gcclib}`
local gccRawVersion=`$gcc -dumpversion`
local gccMachine=`$gcc -dumpmachine`
# determine architecture from machine triple
case $gccMachine in
arm-*) targetCpu=arm;;
aarch64-*) targetCpu=arm64;;
i?86-*) targetCpu=x86;;
m68k-*) targetCpu=m68k;;
powerpc-*) targetCpu=ppc;;
riscv64-*) targetCpu=riscv64;;
sparc64-*) targetCpu=sparc;;
x86_64-*) targetCpu=x86_64;;
*)
echo "Unsupported gcc target machine: $gccMachine" >&2
exit 1
;;
esac
local targetArch=$targetCpu
case $gccRawVersion in
2.9*)
# check for correct (most up-to-date) legacy compiler and complain
# if an older one is installed
if [ $gccRawVersion != $haikuRequiredLegacyGCCVersion ]; then
echo "GCC version $haikuRequiredLegacyGCCVersion is required!";
echo "Please download it from www.haiku-os.org...";
exit 1;
fi
targetArch=x86_gcc2
;;
esac
local bootLibgcc
local bootLibSupCxx
local bootCxxHeaders
local boot32Libgcc
local boot32LibSupCxx
local boot32CxxHeaders
case $gccMachine in
x86_64-*)
# Boot loader is 32-bit, need the 32-bit libs and c++ config
boot32Libgcc=`$gcc -m32 -print-file-name=libgcc.a`
boot32LibSupCxx=`$gcc -m32 -print-file-name=libsupc++.a`
bootLibgcc=`$gcc -print-file-name=libgcc.a`
bootLibSupCxx=`$gcc -print-file-name=libsupc++.a`
local headersBase=$gccdir/../../../..
local headers=$headersBase/$gccMachine/include/c++/$gccRawVersion
if [ ! -d $headers ]; then
headers=$headersBase/include/c++/$gccRawVersion
fi
boot32CxxHeaders="$headers/$gccMachine/32"
bootCxxHeaders="$headers/$gccMachine"
;;
esac
# determine whether graphite loop optimization should/can be used
local useGraphite=`get_variable HAIKU_USE_GCC_GRAPHITE_$targetCpu`
if [ -z "$useGraphite" ]; then
useGraphite=$useGccGraphiteDefault
fi
if [ "$useGraphite" != 0 ]; then
UNUSED=`echo "int main() {}" | $gcc -xc -c -floop-block - 2>&1`
if [ $? != 0 ]; then
echo "GCC Graphite loop optimizations cannot be used on $targetArch"
useGraphite=0
fi
fi
set_variable HAIKU_CPU_$targetArch $targetCpu
get_build_tool_path CC_$targetArch "$gcc"
set_variable HAIKU_CC_IS_LEGACY_GCC_$targetArch \
`is_legacy_gcc $gccRawVersion`
set_variable HAIKU_CC_IS_CLANG_$targetArch $useClang
set_variable HAIKU_GCC_RAW_VERSION_$targetArch $gccRawVersion
set_variable HAIKU_GCC_MACHINE_$targetArch $gccMachine
set_variable HAIKU_GCC_LIB_DIR_$targetArch $gccdir
set_variable HAIKU_BOOT_CXX_HEADERS_DIR_$targetArch "$bootCxxHeaders"
set_variable HAIKU_BOOT_LIBSUPCXX_$targetArch "$bootLibSupCxx"
set_variable HAIKU_BOOT_LIBGCC_$targetArch $bootLibgcc
set_variable HAIKU_BOOT_32_CXX_HEADERS_DIR_$targetArch "$boot32CxxHeaders"
set_variable HAIKU_BOOT_32_LIBSUPCXX_$targetArch "$boot32LibSupCxx"
set_variable HAIKU_BOOT_32_LIBGCC_$targetArch $boot32Libgcc
set_variable HAIKU_USE_GCC_GRAPHITE_$targetArch $useGraphite
standard_gcc_settings_targetArch=$targetArch
}
# set_variable
#
# Set the value of a variable.
#
set_variable()
{
eval "$1=\"$2\""
}
# get_variable
#
# Echo the value of a variable.
#
get_variable()
{
eval "echo \${$1}"
}
# set_default_value
#
# Set the value for a variable, if no value is set yet.
#
set_default_value()
{
eval "$1=\${$1-$2}"
}
# get_build_tool_path
#
# Gets a usable absolute path of a build tool.
#
get_build_tool_path()
{
local var="HAIKU_$1"
local varval="`get_variable $var`"
local cmd="$2"
if [ ! -z "$varval" ]; then
# this variable is already set (probably by user) so grab its contents
cmd=$varval
fi
local path=${cmd%% *}
if [ -f "$path" ]; then
# get absolute path from relative path
local oldPwd="`pwd`"
cd "`dirname "$path"`"
path="`pwd`/`basename "$path"`"
cd $oldPwd
else
which "$path" > /dev/null 2>&1 || {
echo "Build tool \"$path\" not found (maybe specify it in $var?)" >&2
exit 1
}
fi
if test "${cmd#* }" != "$cmd"; then
# $cmd contains arguments, so preserve them (and only them)
cmd=${cmd#* }
else
# $cmd does not contain arguments, so unset it
cmd=
fi
eval "$var=\"$path $cmd\""
}
# check_native_xattrs
#
# Checks the host platform's support for extended attributes.
# 0: no support, 1: only enough for xattr-ref, 2: full support
#
check_native_xattrs()
{
local xattr_set=
local xattr_set_args=
local xattr_get=
local xattr_get_args=
case $HOST_PLATFORM in
haiku_host)
xattr_set="addattr"; xattr_set_args="\$NAME \"\$VALUE\""
xattr_get="catattr"; xattr_get_args="\$NAME"
;;
darwin)
xattr_set="xattr"; xattr_set_args="-w \$NAME \"\$VALUE\""
xattr_get="xattr"; xattr_get_args="-p \$NAME"
;;
freebsd)
xattr_set="setextattr"; xattr_set_args="user \$NAME \"\$VALUE\""
xattr_get="getextattr"; xattr_get_args="user \$NAME"
;;
linux)
xattr_set="setfattr"; xattr_set_args="-n user.\$NAME -v \"\$VALUE\""
xattr_get="getfattr"; xattr_get_args="-n user.\$NAME"
;;
*)
return 0
;;
esac
if ! type $xattr_set >/dev/null 2>&1; then
echo "$0: could not find $xattr_set, assuming host has no extended attributes"
return 0
elif ! type $xattr_get >/dev/null 2>&1; then
echo "$0: could not find $xattr_get, assuming host has no extended attributes"
return 0
fi
mkdir -p "$outputDir"
echo "xattr test file" >"$outputDir/xattrtest"
local i=0
# on round 0, we test if we can set 3 attrs of 1K each (enough for xattr-ref)
# on round 1, we test if we can set 3 attrs of 45K each (enough for full xattr)
while [ $i -lt 2 ]; do
local j=0
while [ $j -lt 3 ]; do
NAME=attr$j
VALUE=`printf '%*s' $((1024 + $i * 45056)) "" | tr ' ' x`
if [ `echo -n $VALUE | wc -c` -lt $((1024 + $i * 45056)) ]; then
echo "$0: warning: could not generate test data for extended attributes"
rm "$outputDir/xattrtest"
return $i
elif ! $xattr_set `eval echo \"$xattr_set_args\"` \
"$outputDir/xattrtest" >/dev/null 2>&1 ; then
rm "$outputDir/xattrtest"
return $i
fi
j=$((j+1))
done
i=$((i+1))
done
rm "$outputDir/xattrtest"
return 2
}
is_in_list()
{
local element
for element in $2; do
if [ "$1" = "$element" ]; then
return 0
fi
done
return 1
}
# check for --help or -h and show usage immediately
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
usage; exit 0;
fi
# get cwd and the source directory
currentDir=`pwd`
cd `dirname "$0"`
sourceDir=`pwd`
cd "$currentDir"
# determine output directory
if [ "$currentDir" = "$sourceDir" ]; then
outputDir=$currentDir/generated
else
outputDir=$currentDir
fi
buildOutputDir="$outputDir/build"
HAIKU_BUILD_ATTRIBUTES_DIR="$outputDir/attributes"
buildConfigFile="$buildOutputDir/BuildConfig"
# check for update request
if [ "$1" = "--update" ]; then
if ! [ -e "$buildConfigFile" ]; then
echo $0 --update: \'$buildConfigFile\' not found - updating not possible.
exit 1
fi
# get last configure invocation and flags from BuildConfig and call ourselves with it
lastPwd=`grep "#d " "$buildConfigFile" | cut -c 4-`
lastConfig=`grep "#c " "$buildConfigFile" | cut -c 4-`
lastEnv=`grep "#e " "$buildConfigFile" | cut -c 4-`
lastArgs=`grep "#a " "$buildConfigFile" | cut -c 4-`
if [ -z "$lastConfig" ]; then
echo "$0 --update: The previous configure invocation was not properly" \
"encoded into '$buildConfigFile' - updating not possible."
exit 1
fi
cd "$lastPwd"
if [ -n "$lastEnv" ]; then
export $lastEnv
fi
$lastConfig $lastArgs
exit $?
fi
# backup the passed arguments
configureArgs="$@"
configurePath=$0
configureDir=`dirname $configurePath`
# backup relevant environs
configureEnvirons=
for var in `env`; do
case "$var" in
CC\=*|HAIKU*\=*|JAMSHELL\=*)
configureEnvirons="$configureEnvirons $var"
;;
esac
done
# ensure umask is not too restrictive
if [ `umask` -gt 22 ]; then
echo Your umask is too restrictive "(should be <= 0022;" is actually `umask`")"
echo
echo Additionally, if the source tree was cloned with a too-restrictive umask,
echo you will need to run \"git checkout\" again to fix this.
exit 1
fi
# internal default parameter values
#
platform=`uname`
platformMachine=`uname -m`
targetArchs=
buildCrossTools=
buildCrossToolsScript="$sourceDir/build/scripts/build_cross_tools"
buildCrossToolsJobs=
useClang=0
useGccGraphiteDefault=0
unknownArchIndex=1
haikuTargetArchs=
gdbSources=
if [ -z "$CC" ]; then
CC=gcc
fi
# detect the build platform
case "${platform}" in
Darwin) HOST_PLATFORM=darwin ;;
FreeBSD) HOST_PLATFORM=freebsd
if [ "$HAIKU_HOST_USE_32BIT" = 1 ] ; then
echo Unsupported platform: FreeBSD ${platformMachine}
exit 1
fi ;;
Haiku) HOST_PLATFORM=haiku_host ;;
Linux) HOST_PLATFORM=linux ;;
OpenBSD) HOST_PLATFORM=openbsd ;;
*) echo Unsupported platform: ${platform}
exit 1 ;;
esac
case $HOST_PLATFORM in
darwin|freebsd|openbsd) statCmd='stat -f' ;;
*) statCmd='stat -c' ;;
esac
# ensure git checkout was not done with a restrictive umask
if [ `$statCmd '%a' "$sourceDir/data/system/boot/SetupEnvironment"` -lt 644 ]; then
echo "The source tree was cloned with a umask > 0022. It seems you"
echo have already corrected your umask, but not re-checked-out the
echo source tree. Try running:
echo " git checkout --force"
echo to fix this problem.
exit 1
fi
# exported (BuildSetup) default parameter values
#
GIT_DIR=`git -C "$configureDir" rev-parse --git-dir | sed 's/^gitdir: //'`
HOST_GCC_RAW_VERSION=`$CC -dumpversion`
HOST_CC_IS_LEGACY_GCC=`is_legacy_gcc $HOST_GCC_RAW_VERSION`
HOST_GCC_MACHINE=`$CC -dumpmachine`
HAIKU_INCLUDE_SOURCES=0
HAIKU_INCLUDE_3RDPARTY=0
HAIKU_DISTRO_COMPATIBILITY=default
TARGET_PLATFORM=haiku
HAIKU_USE_GCC_PIPE=0
HAIKU_HOST_USE_32BIT=0
HAIKU_HOST_USE_XATTR=
HAIKU_HOST_USE_XATTR_REF=
HAIKU_HOST_BUILD_ONLY=0
HOST_EXTENDED_REGEX_SED="sed -r"
HOST_GCC_LD=`$CC -print-prog-name=ld`
HOST_GCC_OBJCOPY=`$CC -print-prog-name=objcopy`
HOST_SHA256=
HOST_HAIKU_PORTER=
HAIKU_PORTS=
HAIKU_PORTS_CROSS=
HAIKU_IS_BOOTSTRAP=0
HAIKU_NO_DOWNLOADS=0
HAIKU_PACKAGING_ARCHS=
set_default_value HAIKU_NASM nasm
if sha256sum < /dev/null > /dev/null 2>&1; then
HOST_SHA256=sha256sum
elif sha256 < /dev/null > /dev/null 2>&1; then
HOST_SHA256="sha256 -q"
elif shasum < /dev/null > /dev/null 2>&1; then
HOST_SHA256="shasum -a 256"
else
echo "Error: Neither sha256sum nor sha256 seem to be available!" >&2
exit 1
fi
haikuRequiredLegacyGCCVersion="2.95.3-haiku-2017_07_20"
export haikuRequiredLegacyGCCVersion
# version of legacy gcc required to build haiku
supportedTargetArchs="
arm
arm64
m68k
ppc
riscv64
sparc
x86
x86_64
x86_gcc2
"
# parse parameters
#
while [ $# -gt 0 ] ; do
case "$1" in
--sysroot)
assertparam "$1" $#
crossToolsSysroot=$2
shift 2
;;
--bootstrap)
assertparams "$1" 3 $#
HOST_HAIKU_PORTER="`absolute_path $2`"
HAIKU_PORTS_CROSS="`absolute_path $3`"
HAIKU_PORTS="`absolute_path $4`"
HAIKU_IS_BOOTSTRAP=1
HAIKU_NO_DOWNLOADS=1
check_file_exists "$HOST_HAIKU_PORTER" || (
echo "Invalid path to haikuporter: $HOST_HAIKU_PORTER" >&2
exit 1
)
check_dir_exists "$HAIKU_PORTS" || (
echo "Non-existent directory $HAIKU_PORTS" >&2
exit 1
)
check_dir_exists "$HAIKU_PORTS_CROSS" || (
echo "Non-existent directory $HAIKU_PORTS_CROSS" >&2
exit 1
)
shift 4
;;
--cross-tools-source)
assertparam "$1" $#
buildCrossTools=$2
shift 2
;;
--build-cross-tools)
assertparam "$1" $#
targetArch=$2
shift 2
case "$targetArch" in
x86_gcc2) targetMachine=i586-pc-haiku;;
x86) targetMachine=i586-pc-haiku;;
x86_64) targetMachine=x86_64-unknown-haiku;;
ppc) targetMachine=powerpc-apple-haiku;;
m68k) targetMachine=m68k-unknown-haiku;;
arm) targetMachine=arm-unknown-haiku;;
arm64) targetMachine=aarch64-unknown-haiku;;
riscv64) targetMachine=riscv64-unknown-haiku;;
sparc) targetMachine=sparc64-unknown-haiku;;
*)
echo "Unsupported target architecture: $targetArch" >&2
exit 1
;;
esac
set_variable buildCrossToolsMachine_$targetArch $targetMachine
targetArchs="$targetArchs $targetArch"
;;
--cross-tools-prefix)
assertparam "$1" $#
targetArch=unknown${unknownArchIndex}
set_variable crossToolsPrefix_$targetArch "$2"
targetArchs="$targetArchs $targetArch"
unknownArchIndex=$(($unknownArchIndex + 1))
shift 2
;;
--distro-compatibility)
assertparam "$1" $#
HAIKU_DISTRO_COMPATIBILITY=$2
case "$HAIKU_DISTRO_COMPATIBILITY" in
official) ;;
compatible) ;;
default) ;;
*) echo "Invalid distro compatibility" \
"level: $HAIKU_DISTRO_COMPATIBILITY"
exit 1;;
esac
shift 2
;;
--host-only) HAIKU_HOST_BUILD_ONLY=1; shift 1;;
--include-sources) HAIKU_INCLUDE_SOURCES=1; shift 1;;
--include-3rdparty) HAIKU_INCLUDE_3RDPARTY=1; shift 1;;
-j*) buildCrossToolsJobs="$1"; shift 1;;
--no-downloads) HAIKU_NO_DOWNLOADS=1; shift 1;;
--target-arch)
assertparam "$1" $#
targetArch=$2
shift 2
if [ ! "$platform" = Haiku ]; then
echo "--target-arch can only be specified on Haiku." >&2
exit 1
fi
is_in_list "$targetArch" "$supportedTargetArchs" || (
echo "Unsupported target architecture: \"$targetArch\"" >&2
exit 1
)
haikuTargetArchs="$haikuTargetArchs $targetArch"
;;
--use-clang)
assertparam "$1" $#
targetArch=$2
useClang=1
case "$targetArch" in
x86) targetMachine=i586-pc-haiku;;
x86_64) targetMachine=x86_64-unknown-haiku;;
ppc) targetMachine=powerpc-apple-haiku;;
arm) targetMachine=arm-unknown-haiku;;
arm64) targetMachine=aarch64-unknown-haiku;;
riscv64) targetMachine=riscv64-unknown-haiku;;
sparc) targetMachine=sparc64-unknown-haiku;;
*)
echo "Unsupported target architecture: $2" >&2
exit 1
;;
esac
get_build_tool_path clang clang
if [ -z `get_variable "crossToolsPrefix_$targetArch"` ] \
&& [ -z `get_variable buildCrossToolsMachine_$targetArch` ]; then
set_variable crossToolsPrefix_$targetArch llvm-
fi
clangVersion=`$HAIKU_clang -v 2>&1 | head -1 | cut -d " " -f3`
if [ `echo $clangVersion | cut -d'.' -f1` -lt 7 ]; then
echo "Haiku requires Clang 7 or better to build, but you have $clangVersion."
echo "Please install a newer version."
exit 1
fi
targetArchs="$targetArchs $targetArch"
shift 2
;;
--use-gcc-pipe) HAIKU_USE_GCC_PIPE=1; shift 1;;
--use-gcc-graphite) useGccGraphiteDefault=1; shift 1;;
--use-32bit) HAIKU_HOST_USE_32BIT=1; shift 1;;
--no-full-xattr)HAIKU_HOST_USE_XATTR=0; shift 1;;
--no-xattr) HAIKU_HOST_USE_XATTR_REF=0; shift 1;;
--with-gdb) gdbSources=$2; shift 2;;
--use-stack-protector) HAIKU_USE_STACK_PROTECTOR=1; shift 1;;
--efi-signing-key)
assertparam "$1" $#
HAIKU_EFI_SIGNING_KEY="$2"
shift 2
;;
*) echo Invalid argument: \`$1\'; exit 1;;
esac
done
# check for case-sensitive filesystem
mkdir haikuCaseTest 2>/dev/null
mkdir haikucasetest 2>/dev/null
caseInsensitive=$?
rmdir haikuCaseTest haikucasetest 2>/dev/null
if [ $caseInsensitive != 0 ]; then
echo "You need a case-sensitive file-system to build Haiku."
if [ $HOST_PLATFORM = "darwin" ]; then
echo "You can create a case-sensitive disk image using Disk Utility."
fi
exit 1
fi
# check xattr support
if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then
check_native_xattrs
attrSupport=$?
if [ $attrSupport = 2 ] && [ -z $HAIKU_HOST_USE_XATTR ]; then
HAIKU_HOST_USE_XATTR=1
elif [ $attrSupport = 1 ]; then
HAIKU_HOST_USE_XATTR_REF=1
fi
fi
if [ -z $HAIKU_HOST_USE_XATTR ]; then HAIKU_HOST_USE_XATTR=0; fi
if [ -z $HAIKU_HOST_USE_XATTR_REF ]; then HAIKU_HOST_USE_XATTR_REF=0; fi
# determine how to invoke sed with extended regexp support for non-GNU sed
if [ $HOST_PLATFORM = "darwin" ]; then
HOST_EXTENDED_REGEX_SED="sed -E"
fi
# pick a JAMSHELL
if [ "$JAMSHELL" = "" ]; then
if check_file_exists /bin/dash; then
JAMSHELL=/bin/dash
else
JAMSHELL=/bin/sh
fi
fi
if ! $JAMSHELL -c true; then
echo "$JAMSHELL does not work! Please specify a working JAMSHELL."
exit 1
fi
# locate python
if python3 --version < /dev/null > /dev/null 2>&1; then
HOST_PYTHON="python3"
elif python --version < /dev/null > /dev/null 2>&1; then
HOST_PYTHON="python"
else
echo "a python interpreter is required"
exit 1
fi
# check if nasm can actually output ELF files
# (the stock version in OSX can't)
# XXX: should probably only test for x86* arch
if [ "$("$HAIKU_NASM" -hf | grep -c elf'[36][24] ')" -ne "2" ]; then
echo "$HAIKU_NASM cannot generate ELF files. Please install a working version."
if [ $HOST_PLATFORM = "darwin" ]; then
echo "You can install it from Mac Ports."
echo "Mac Ports is available at: http://www.macports.org/"
fi
exit 1
fi
# create output directory
mkdir -p "$buildOutputDir" || exit 1
if [ "$HAIKU_HOST_BUILD_ONLY" = 1 ]; then
invalidCommand=$sourceDir/build/scripts/host_build_only
HAIKU_AR=$invalidCommand
HAIKU_CC=$invalidCommand
HAIKU_LD=$invalidCommand
HAIKU_OBJCOPY=$invalidCommand
HAIKU_RANLIB=$invalidCommand
HAIKU_ELFEDIT=$invalidCommand
HAIKU_NASM=$invalidCommand
HAIKU_STRIP=$invalidCommand
else
# On Haiku determine target architectures and tools automatically.
if [ -z "$targetArchs" ]; then
if [ $HOST_PLATFORM != haiku_host ]; then
echo "Please specify the build tools to use or build (via" \
"--cross-tools-prefix or --build-cross-tools) or specify a" \
"host-only build (--host-only)." >&2
echo "For more info, invoke $0 --help"
exit 1
fi
# determine primary architecture
targetArch=`package list -i /system/packages/haiku-*.hpkg \
| sed '/^\s*architecture:/!d; s,^\s*architecture:\s*,,'`
is_in_list "$targetArch" "$supportedTargetArchs" || (
echo "Unsupported target architecture: \"$targetArch\"" >&2
exit 1
)
targetArchs=$targetArch
set_default_value HAIKU_AR_$targetArch ar
set_default_value HAIKU_CC_$targetArch gcc
set_default_value HAIKU_LD_$targetArch ld
set_default_value HAIKU_OBJCOPY_$targetArch objcopy
set_default_value HAIKU_RANLIB_$targetArch ranlib
set_default_value HAIKU_ELFEDIT_$targetArch elfedit
set_default_value HAIKU_STRIP_$targetArch strip
# determine secondary architectures
for targetArch in $supportedTargetArchs; do
if [ -e /system/packages/haiku_$targetArch-*.hpkg ]; then
targetArchs="$targetArchs $targetArch"
set_default_value HAIKU_AR_$targetArch ar-$targetArch
set_default_value HAIKU_CC_$targetArch gcc-$targetArch
set_default_value HAIKU_LD_$targetArch ld-$targetArch
set_default_value HAIKU_OBJCOPY_$targetArch objcopy-$targetArch
set_default_value HAIKU_RANLIB_$targetArch ranlib-$targetArch
set_default_value HAIKU_ELFEDIT_$targetArch elfedit-$targetArch
set_default_value HAIKU_STRIP_$targetArch strip-$targetArch
fi
done
# The target architectures might have been specified explicitly.
if [ -n "$haikuTargetArchs" ]; then
for targetArch in $haikuTargetArchs; do
is_in_list "$targetArch" "$targetArchs" || (
echo "Unsupported target architecture: \"$targetArch\"." \
"Only native architectures of the host platform can" \
"be specified." >&2
exit 1
)
done
targetArchs="$haikuTargetArchs"
fi
fi
if [ "$targetArchs" = " x86_gcc2" ]; then
echo "Building a GCC2-only Haiku is no longer supported."
echo "Please configure the secondary architecture."
exit 1
fi
isPrimaryArch=1
for targetArch in $targetArchs; do
# Note: targetArch is "unknown<n>" at this point if a cross-tools
# prefix was specified. The standard_gcc_settings call below will get
# the actual architecture.
if test "${HAIKU_PACKAGING_ARCHS#*$targetArch\b}" != "$HAIKU_PACKAGING_ARCHS"; then
# somehow we wound up with a duplicate arch; skip this one
continue
fi
crossToolsPrefix=`get_variable crossToolsPrefix_$targetArch`
# build cross tools from sources
if [ -n "$buildCrossTools" -a -z "$crossToolsPrefix" ]; then
crossToolsDir="$outputDir/cross-tools-$targetArch"
targetMachine=`get_variable buildCrossToolsMachine_$targetArch`
script="$buildCrossToolsScript"
scriptArgs=
if [ $targetArch != x86_gcc2 ]; then
script="${script}_gcc4"
scriptArgs="$targetMachine"
set_default_value HAIKU_USE_GCC_GRAPHITE_$targetArch \
$useGccGraphiteDefault