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. 5# 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. 11 12set -ex 13 14ARCH=$1 15SECONDARY_ARCH=$2 16 17TOP=$(pwd) 18 19BUILDTOOLS=$TOP/buildtools 20HAIKU=$TOP/haiku 21OUTPUT=/tools 22SYSROOT=$OUTPUT/cross-tools-$ARCH/sysroot 23SYSROOT_SECONDARY=$OUTPUT/cross-tools-$SECONDARY_ARCH/sysroot 24PACKAGE_ROOT=/system 25 26# First up, build a cross-compiler 27git clone --depth=1 https://git.haiku-os.org/haiku 28git clone --depth=1 https://git.haiku-os.org/buildtools 29cd $BUILDTOOLS/jam 30make && ./jam0 install 31mkdir -p $OUTPUT 32cd $OUTPUT 33configureArgs="--build-cross-tools $ARCH $TOP/buildtools" 34if [ -n "$SECONDARY_ARCH" ]; then 35 configureArgs="$configureArgs --build-cross-tools $SECONDARY_ARCH" 36fi 37$HAIKU/configure $configureArgs 38 39# Set up sysroot to redirect to /system 40mkdir -p $SYSROOT/boot 41mkdir -p $PACKAGE_ROOT 42ln -s $PACKAGE_ROOT $SYSROOT/boot/system 43if [ -n "$SECONDARY_ARCH" ]; then 44 mkdir -p $SYSROOT_SECONDARY/boot 45 ln -s $PACKAGEROOT $SYSROOT_SECONDARY/boot/system 46fi 47 48# Build needed packages and tools for the cross-compiler 49jam -q haiku.hpkg haiku_devel.hpkg '<build>package' 50if [ -n "$SECONDARY_ARCH" ]; then 51 jam -q haiku_${SECONDARY_ARCH}.hpkg haiku_${SECONDARY_ARCH}_devel.hpkg 52fi 53 54# Set up our sysroot 55cp $OUTPUT/objects/linux/lib/*.so /lib/x86_64-linux-gnu 56cp $OUTPUT/objects/linux/x86_64/release/tools/package/package /bin/ 57for file in $SYSROOT/../bin/*; do 58 ln -s $file /bin/$(basename $file) 59done 60#find $SYSROOT/../bin/ -type f -exec ln -s {} /bin/ \; 61if [ -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 \; 66fi 67 68# Extract packages 69package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku.hpkg 70package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_devel.hpkg 71if [ -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 74fi 75find $OUTPUT/download/ -name '*.hpkg' -exec package extract -C $PACKAGE_ROOT {} \; 76cd $PACKAGE_ROOT/develop/lib 77ln -s ../../lib/libgcc_s.so libgcc_s.so 78if [ -n "$SECONDARY_ARCH" ]; then 79 cd $PACKAGE_ROOT/develop/lib/$SECONDARY_ARCH 80 ln -s ../../../lib/$SECONDARY_ARCH/libgcc_s.so libgcc_s.so 81fi 82 83# Clean up 84rm -rf $BUILDTOOLS 85rm -rf $HAIKU 86rm -rf $OUTPUT/Jamfile $OUTPUT/attributes $OUTPUT/build $OUTPUT/build_packages $OUTPUT/download $OUTPUT/objects 87 88if [ -n "$SECONDARY_ARCH" ]; then 89 echo "Cross compilers for $ARCH-unknown-haiku and $SECONDARY_ARCH-unknown-haiku built and configured" 90else 91 echo "Cross compiler for $ARCH-unknown-haiku built and configured" 92fi 93