AC_ARG_WITH(cuda,
	[ --with-cuda           use minisat interface],
	if test "$withval" = yes; then
		yap_cv_cuda=/usr/local/cuda
	elif test "$withval" = no; then
		yap_cv_cuda=no
	else
		yap_cv_cuda="$withval"
	fi,
	[yap_cv_cuda=no])


CUDA_LDFLAGS=""
CUDA_CPPFLAGS=""
if test "$yap_cv_cuda" = no 
then
  PKG_CUDA=""
else
  AC_PATH_PROG(NVCC, [nvcc], [no], [$yap_cv_cuda/bin])
  if test "$yap_cv_cuda" = no
  then
    PKG_CUDA=""
  else
    PKG_CUDA="packages/cuda"
    case "$target_os" in
     *darwin*)
       CUDA_LDFLAGS="$LDFLAGS $LIBS"
    CUDA_CPPFLAGS="-arch=sm_20  -Xcompiler -fPIC -O3 "
    CUDA_SHLIB_LD="$NVCC  --shared -L../.. -lYap "
     ;;
     *linux*)
       CUDA_LDFLAGS="$LDFLAGS"
    CUDA_CPPFLAGS="-arch=sm_20  -Xcompiler -fPIC -O3 "
    CUDA_SHLIB_LD="$NVCC  --shared -L../.. -lYap "
     ;;
    **)
       CUDA_LDFLAGS="$LDFLAGS $LIBS"
    CUDA_CPPFLAGS=" -arch=sm_20  -Xcompiler -fPIC -O3 "
    CUDA_SHLIB_LD="$NVCC -Xcompiler -export-dynamic"
    ;;
    esac
 fi
fi

AC_SUBST(PKG_CUDA)
AC_SUBST(NVCC)
AC_SUBST(CUDA_SHLIB_LD)
AC_SUBST(CUDA_CPPFLAGS)
AC_SUBST(CUDA_LDFLAGS)

AC_CONFIG_FILES([packages/cuda/Makefile])

mkdir -p  packages/cuda