#!/bin/sh
# Copyright © 2013-2016 Valve Corporation
# Copyright © 2017-2026 Collabora Ltd.
# SPDX-License-Identifier: MIT
#
# Loosely based on:
# https://github.com/ValveSoftware/steam-runtime/blob/v0.20230720.0/scripts/bootstrap-runtime.sh

set -eux

# Workaround bug 714890 in 32-bit clang. Gcc 4.8 changed the include paths.
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=714890
#   /usr/include/c++/4.6/i686-linux-gnu/bits/c++config.h
#   /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h
echo "Before fixing include paths:"
ls -ld /usr/include/c++/*/*-linux-gnu
ls -ld /usr/include/*-linux-gnu/c++/*

if [ -d /usr/include/i386-linux-gnu/c++/4.8 ]; then
    ln -s /usr/include/i386-linux-gnu/c++/4.8 /usr/include/c++/4.8/i686-linux-gnu
fi

echo "After fixing include paths:"
ls -ld /usr/include/c++/*/*-linux-gnu
ls -ld /usr/include/*-linux-gnu/c++/*

# Setup compiler alternatives
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 50

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.8 100

update-alternatives --install /usr/bin/gcc gcc /usr/bin/clang-3.4 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/clang++-3.4 50

update-alternatives --install /usr/bin/gcc gcc /usr/bin/clang-3.6 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/clang++-3.6 50

# gcc-4.8 is the default
update-alternatives --set gcc /usr/bin/gcc-4.8
update-alternatives --set g++ /usr/bin/g++-4.8
update-alternatives --set cpp-bin /usr/bin/cpp-4.8
