#!/usr/bin/env bash

# source: https://crascit.com/2016/04/09/using-ccache-with-cmake/

# Xcode generator doesn't include the compiler as the
# first argument, Ninja and Makefiles do. Handle both cases.
if [[ "$1" = "/home/metal/.anki/vicos-sdk/dist/5.3.0-r07/prebuilt/bin/arm-oe-linux-gnueabi-clang++" ]] ; then
    shift
fi

# CCACHE_CPP2 is required for clang
# http://peter.eisentraut.org/blog/2014/12/01/ccache-and-clang-part-3/
export CCACHE_CPP2=true
export CCACHE_MAXSIZE=10G
export CCACHE_BASEDIR="/home/metal/girl-os/anki/victor"
export CCACHE_HARDLINK=true
# caching is conservative by default, for more agressive caching, uncomment the next line           
export CCACHE_SLOPPINESS=include_file_mtime
#EXTRA_ARGS="$LD_LIBRARY_PATH"
#if [[ "$(uname -a)" == *"Linux"* ]]; then
#        if [[ "$(uname -a)" == *"aarch64"* ]]; then
#                ARCH="arm64"
#        elif [[ "$(uname -a)" == *"x86_64"* ]]; then
#                ARCH="amd64"
#        else
#                echo "Unknown CPU architecture."
#                exit 1
#        fi
#        EXTRA_ARGS="/home/metal/girl-os/anki/victor/3rd/libtinfo5/:$LD_LIBRARY_PATH"
#fi

exec "/usr/bin/ccache" "/home/metal/.anki/vicos-sdk/dist/5.3.0-r07/prebuilt/bin/arm-oe-linux-gnueabi-clang++" "$@"
