#!/usr/bin/env bash expected_triplet=$TARGET if [ -z "$expected_triplet" ]; then echo "ERROR: target triplet not provided!" exit 1 fi ensure_tool() { command -v "$1" > /dev/null if [ $? -ne 0 ]; then echo "ERROR: Missing tool: $1" exit 1 fi } if [ "$(uname -s)" = "Linux" ]; then is_linux=yes fi echo ">> Checking tools..." ensure_tool gcc ensure_tool g++ ensure_tool clang ensure_tool clang++ mkdir -p host_tools echo ">> Updating package database..." [ -n "$is_linux" ] && sudo apt-get update echo ">> Installing meson..." if [ -n "$is_linux" ]; then sudo apt-get install ninja-build else ninja_version=1.10.2 cd host_tools wget "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-mac.zip" || exit 1 tar xf ninja-mac.zip || exit 1 rm ninja-mac.zip cd .. export PATH="$(pwd)/host_tools:$PATH" fi if [ -n "$(command -v pip3)" ]; then sudo pip3 install meson || exit 1 elif [ -n "$(command -v pip)" ]; then sudo pip install meson || exit 1 else echo "ERROR: pip not found" exit 1 fi ensure_tool meson ensure_tool ninja if [ "$(uname -s)" != "Linux" ]; then exit 0 fi if [ "${CC/gcc}" != "${CC}" ]; then sudo apt-get install ${CC} ${CC/gcc/g++} || exit 1 fi current_triplet=`gcc -dumpmachine` if [ "$expected_triplet" = "$current_triplet" ]; then exit 0 fi echo ">> Installing toolchain..." if [ "$expected_triplet" = "x86_64-w64-mingw32" ]; then gcc_suffix="mingw-w64" extra_packages="wine" need_span=yes else gcc_suffix="${expected_triplet}" extra_packages="qemu-user" fi sudo apt-get install ${CC}-${gcc_suffix} ${CC/gcc/g++}-${gcc_suffix} ${extra_packages} || exit 1 # gcc9 too old to provide its own span... if [ -n "$need_span" ]; then wget -O include/cubescript/span.hpp \ https://raw.githubusercontent.com/tcbrindle/span/master/include/tcb/span.hpp # custom config cat << EOF > include/cubescript/cubescript_conf_user.hh #include "span.hpp" namespace cubescript { template using span_type = tcb::span; } #define LIBCUBESCRIPT_CONF_USER_SPAN EOF fi exit $?