#!/bin/bash

set -x

# Get an updated config.sub and config.guess
cp $BUILD_PREFIX/share/libtool/build-aux/config.* .
cp $BUILD_PREFIX/share/libtool/build-aux/config.* ./ccache.ccache/.

if [[ ${target_platform} == osx-* ]]; then
  export SDKROOT=${CONDA_BUILD_SYSROOT}
fi

if [ "$target_platform" = "osx-arm64" ]; then
    # Workaround for wrong detection of vector extensions,
    # see https://github.com/ccache/ccache/issues/734
    CMAKE_ARGS="${CMAKE_ARGS} -DHAVE_AVX2=NO -DHAVE_C_AVX2=NO -DHAVE_C_AVX512=NO -DHAVE_C_SSE2=NO -DHAVE_C_SSE41=NO"
fi

./ccache.ccache/configure --prefix=$PREFIX
make -j${CPU_COUNT}
if [[ ${target_platform} != osx-* ]]; then
  # Disabling macOS due to:
  # Test suite:     debug_prefix_map
  # Test case:      Multiple -fdebug-prefix-map
  # Failure reason: Relocation (name) not found in test.o
  make check
fi
make install
