#!/bin/bash
#This recipe was adapted from the default and conda-forge recipes

if [[ ${target_platform} == osx-64 ]]; then
  rm -rf "${PREFIX}"/lib/libuuid.la "${PREFIX}"/lib/libuuid.a
  XWIN_ARGS="--with-x --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib"
  CONDA_BUILD_SYSROOT=/opt/MacOSX10.9.sdk
  export CXXFLAGS="`echo $CXXFLAGS | sed s/-stdlib=libc++//g`"
  export DEBUG_CXXFLAGS="`echo $DEBUG_CXXFLAGS | sed s/-stdlib=libc++//g`"
  #Issue with competing X11 libs (from tk)
  rm -rf $PREFIX/include/X11
  rm -rf $CONDA_PREFIX/include/X11
else
  XWIN_ARGS=--with-x
fi

#In case any of the GTK dependencies contain libtool files
# conda-build #3102 should fix this, but the dependency might have been built without this.
find $PREFIX -name '*.la' -delete 
find $CONDA_PREFIX -name '*.la' -delete

./configure \
    --prefix="${PREFIX}"  \
    --host=${HOST}        \
    --enable-ft           \
    --enable-ps           \
    --enable-pdf          \
    --enable-svg          \
    --enable-pthread      \
    --disable-gtk-doc     \
    $XWIN_ARGS

make -j${CPU_COUNT} ${VERBOSE_AT}
# FAIL: check-link on OS X
# Hangs for > 10 minutes on Linux
# make check
make install

#Clean up created libtool files
cd $PREFIX
find . -name '*.la' -delete

#Create a symlink for headerfiles in include/cairo
cd $PREFIX/include/cairo
cairo_headers="`ls *.h`"
cd $PREFIX/include/
for h in ${cairo_headers}; do
  ln -s cairo/${h} ${h}
done
