#!//usr/bin/env bash

# Copyright (c) 2025 vandermeij.tech - All rights reserved.
# This work is licensed under the terms of the MIT license.  
# For a copy, see <https://vandermeij.tech/files/MIT.txt>.

set -e

BASE_DIR=$(pwd)
MAKE_THREADS=2

CROSSTOOL_NG_URL="crosstool-ng.org/download/crosstool-ng"
CROSSTOOL_NG_V="1.27.0"

ARM_TARGET="arm-unknown-linux-uclibcgnueabi"

##################################################################

# crosstool-ng init
wget http://$CROSSTOOL_NG_URL/crosstool-ng-$CROSSTOOL_NG_V.tar.bz2
tar -xvjf crosstool-ng-$CROSSTOOL_NG_V.tar.bz2

cd crosstool-ng-$CROSSTOOL_NG_V
./configure --prefix=$BASE_DIR/crosstool-ng-env

make -j$MAKE_THREADS
make install

# crosstool-ng configure
cd $BASE_DIR/crosstool-ng-env
./bin/ct-ng $ARM_TARGET

# crosstool-ng build
./bin/ct-ng build

export PATH="$PATH:$HOME/x-tools/$ARM_TARGET/bin/"

# strace build
cd $BASE_DIR/

wget https://strace.io/files/5.10/strace-5.10.tar.xz
tar -xvf strace-5.10.tar.xz

cd $BASE_DIR/strace-5.10

./configure --host=$ARM_TARGET CC=$ARM_TARGET-gcc
make -j$MAKE_THREADS

# strace strip
$ARM_TARGET-strip src/strace
