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 14BUILDTOOLS_REV=$1 15HAIKU_REV=$2 16ARCH=$3 17SECONDARY_ARCH=$4 18 19TOP=$(pwd) 20 21BUILDTOOLS=$TOP/buildtools 22HAIKU=$TOP/haiku 23OUTPUT=/tools 24SYSROOT=$OUTPUT/cross-tools-$ARCH/sysroot 25SYSROOT_SECONDARY=$OUTPUT/cross-tools-$SECONDARY_ARCH/sysroot 26PACKAGE_ROOT=/system 27 28# Get the source trees 29git clone --depth=1 --branch $HAIKU_REV https://review.haiku-os.org/haiku 30git clone --depth=1 --branch $BUILDTOOLS_REV https://review.haiku-os.org/buildtools 31 32# The Haiku build requires the ability to find a hrev tag. In case a specific branch is selected 33# (like `r1beta4`)`, we will get the entire history just to be sure that the tag will exist. 34cd haiku 35if ! `git describe --dirty --tags --match=hrev* --abbrev=1`; then 36 git fetch --unshallow 37fi 38 39# Build a cross-compiler 40cd $BUILDTOOLS/jam 41make && ./jam0 install 42mkdir -p $OUTPUT 43cd $OUTPUT 44configureArgs="--build-cross-tools $ARCH --cross-tools-source $TOP/buildtools" 45if [ -n "$SECONDARY_ARCH" ]; then 46 configureArgs="$configureArgs --build-cross-tools $SECONDARY_ARCH" 47fi 48$HAIKU/configure $configureArgs 49 50# Set up sysroot to redirect to /system 51mkdir -p $SYSROOT/boot 52mkdir -p $PACKAGE_ROOT 53ln -s $PACKAGE_ROOT $SYSROOT/boot/system 54if [ -n "$SECONDARY_ARCH" ]; then 55 mkdir -p $SYSROOT_SECONDARY/boot 56 ln -s $PACKAGE_ROOT $SYSROOT_SECONDARY/boot/system 57fi 58 59# Build needed packages and tools for the cross-compiler 60jam -q haiku.hpkg haiku_devel.hpkg '<build>package' 61if [ -n "$SECONDARY_ARCH" ]; then 62 jam -q haiku_${SECONDARY_ARCH}.hpkg haiku_${SECONDARY_ARCH}_devel.hpkg 63fi 64 65# Set up our sysroot 66cp $OUTPUT/objects/linux/lib/*.so /lib/x86_64-linux-gnu 67cp $OUTPUT/objects/linux/x86_64/release/tools/package/package /bin/ 68for file in $SYSROOT/../bin/*; do 69 ln -s $file /bin/$(basename $file) 70done 71#find $SYSROOT/../bin/ -type f -exec ln -s {} /bin/ \; 72if [ -n "$SECONDARY_ARCH" ]; then 73 for file in $SYSROOT_SECONDARY/../bin/*; do 74 ln -s $file /bin/$(basename $file)-$SECONDARY_ARCH 75 done 76 #find $SYSROOT_SECONDARY/../bin/ -type f -exec ln -s {} /bin/{}-$SECONDARY_ARCH \; 77fi 78 79# Extract packages 80package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku.hpkg 81package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_devel.hpkg 82if [ -n "$SECONDARY_ARCH" ]; then 83 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_${SECONDARY_ARCH}.hpkg 84 package extract -C $PACKAGE_ROOT $OUTPUT/objects/haiku/$ARCH/packaging/packages/haiku_${SECONDARY_ARCH}_devel.hpkg 85fi 86find $OUTPUT/download/ -name '*.hpkg' -exec package extract -C $PACKAGE_ROOT {} \; 87 88# Clean up 89rm -rf $BUILDTOOLS 90rm -rf $HAIKU 91rm -rf $OUTPUT/Jamfile $OUTPUT/attributes $OUTPUT/build $OUTPUT/build_packages $OUTPUT/download $OUTPUT/objects 92 93if [ -n "$SECONDARY_ARCH" ]; then 94 echo "Cross compilers for $ARCH-unknown-haiku and $SECONDARY_ARCH-unknown-haiku built and configured" 95else 96 echo "Cross compiler for $ARCH-unknown-haiku built and configured" 97fi 98