cd src

# Allow downloading dependencies
unset https_proxy

mkdir build
cd build
sdh_cmake -GNinja \
          -DCMAKE_BUILD_TYPE=Release \
          -DENABLE_TESTING=OFF \
		  ..
cmake --build .
DESTDIR=$SAGE_DESTDIR cmake --install .

set -e

mkdir -p "$SAGE_LOCAL/libexec/ccache"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/cc"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/c++"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/gcc"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/g++"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/clang"
ln -sf ../../bin/ccache "$SAGE_LOCAL/libexec/ccache/clang++"

# Copy a reasonable default configuration for Sage
# (cache size of 4G and compression enabled)
cp -p ../../ccache.conf "$SAGE_LOCAL/etc"
