vfs: check userland buffers before reading them.
[haiku.git] / 3rdparty / docker / cross-compiler / build-toolchain.sh
blob1032de00af819c6f1b73b45b8a9b4f4c01d332ee
1 #!/bin/bash
2 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
12 set -ex
14 ARCH=$1
15 SECONDARY_ARCH=$2
17 TOP=$(pwd)
19 BUILDTOOLS=$TOP/buildtools
20 HAIKU=$TOP/haiku
21 OUTPUT=/tools
22 SYSROOT=$OUTPUT/cross-tools-$ARCH/sysroot
23 SYSROOT_SECONDARY=$OUTPUT/cross-tools-$SECONDARY_ARCH/sysroot
24 PACKAGE_ROOT=/system
26 # First up, build a cross-compiler
27 git clone --depth=1 https://git.haiku-os.org/haiku
28 git clone --depth=1 https://git.haiku-os.org/buildtools
29 cd $BUILDTOOLS/jam
30 make && ./jam0 install
31 mkdir -p $OUTPUT
32 cd $OUTPUT
33 configureArgs="--build-cross-tools $ARCH $TOP/buildtools"
34 if [ -n "$SECONDARY_ARCH" ]; then
35 configureArgs="$configureArgs --build-cross-tools $SECONDARY_ARCH"
37 $HAIKU/configure $configureArgs
39 # Set up sysroot to redirect to /system
40 mkdir -p $SYSROOT/boot
41 mkdir -p $PACKAGE_ROOT
42 ln -s $PACKAGE_ROOT $SYSROOT/boot/system
43 if [ -n "$SECONDARY_ARCH" ]; then
44 mkdir -p $SYSROOT_SECONDARY/boot
45 ln -s $PACKAGEROOT $SYSROOT_SECONDARY/boot/system
48 # Build needed packages and tools for the cross-compiler
49 jam -q haiku.hpkg haiku_devel.hpkg '<build>package'
50 if [ -n "$SECONDARY_ARCH" ]; then
51 jam -q haiku_${SECONDARY_ARCH}.hpkg haiku_${SECONDARY_ARCH}_devel.hpkg
54 # Set up our sysroot
55 cp $OUTPUT/objects/linux/lib/*.so /lib/x86_64-linux-gnu
56 cp $OUTPUT/objects/linux/x86_64/release/tools/package/package /bin/
57 for file in $SYSROOT/../bin/*; do
58 ln -s $file /bin/$(basename $file)
59 done
60 #find $SYSROOT/../bin/ -type f -exec ln -s {} /bin/ \;
61 if [ -n "$SECONDARY_ARCH" ]; then
62 for file in $SYSROOT_SECONDARY/../bin/*; do
63 ln -s $file /bin/$(basename $file)-$SECONDARY_ARCH
64 done
65 #find $SYSROOT_SECONDARY/../bin/ -type f -exec ln -s {} /bin/{}-$SECONDARY_ARCH \;
68 # Extract packages
69 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku.hpkg
70 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_devel.hpkg
71 if [ -n "$SECONDARY_ARCH" ]; then
72 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_${SECONDARY_ARCH}.hpkg
73 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_${SECONDARY_ARCH}_devel.hpkg
75 find $OUTPUT/download/ -name '*.hpkg' -exec package extract -C $PACKAGE_ROOT {} \;
76 cd $PACKAGE_ROOT/develop/lib
77 ln -s ../../lib/libgcc_s.so libgcc_s.so
78 if [ -n "$SECONDARY_ARCH" ]; then
79 cd $PACKAGE_ROOT/develop/lib/$SECONDARY_ARCH
80 ln -s ../../../lib/$SECONDARY_ARCH/libgcc_s.so libgcc_s.so
83 # Clean up
84 rm -rf $BUILDTOOLS
85 rm -rf $HAIKU
86 rm -rf $OUTPUT/Jamfile $OUTPUT/attributes $OUTPUT/build $OUTPUT/build_packages $OUTPUT/download $OUTPUT/objects
88 if [ -n "$SECONDARY_ARCH" ]; then
89 echo "Cross compilers for $ARCH-unknown-haiku and $SECONDARY_ARCH-unknown-haiku built and configured"
90 else
91 echo "Cross compiler for $ARCH-unknown-haiku built and configured"