dnl Process this file with autoconf to produce a configure script.
dnl configure.in for xpuzzles.
AC_INIT([xpanex], m4_esyscmd([cat version.h | cut -f2 -d\" | tr -d '\n']), [bagleyd@tux.org])
AC_SUBST([PACKAGE_NAME])dnl

dnl Checks for programs.
AC_ARG_WITH(gcc,
[  --with-gcc              use GCC to compile])
dnl AC_ARG_WITH(debug,
dnl [  --with-debug            compile with -g, if no optimize])

test -n "$CC" && cc_specified=yes
case ${with_gcc} in
  yes ) CC=gcc ;;
dnl yes ) CC=g++ ;;
  no  ) CC=cc ;;
  *   ) AC_PROG_CC;;
dnl  *   ) AC_PROG_CXX ;;
esac

dnl case ${with_debug} in
dnl   yes ) CFLAGS="${CFLAGS} -g" ;;
dnl   no ) CFLAGS="${CFLAGS} -O" ;;
dnl esac

if test "${CC}" = "gcc" ; then
  CFLAGS="${CFLAGS} -Wall"
fi

AC_PROG_LN_S
AC_PROG_CPP
AC_AIX
AC_PROG_INSTALL
dnl Optional features.
dnl add copious amounts of debugging with gcc

dnl Checks for header files.
dnl AC_HEADER_STDC /* If its not ansi, its not going to go */
dnl AC_CHECK_HEADERS(poll.h sys/poll.h)
AC_CHECK_HEADERS(fcntl.h sys/select.h sys/time.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

srand=no
dnl AC_CHECK_FUNC(srand48, AC_DEFINE(SRAND,srand48) AC_DEFINE(LRAND,lrand48)
dnl   AC_DEFINE(MAXRAND,2147483648.0),
dnl [AC_CHECK_FUNC(srandom, AC_DEFINE(SRAND,srandom) AC_DEFINE(LRAND,random)
dnl   AC_DEFINE(MAXRAND,2147483648.0),
dnl AC_CHECK_FUNC(srand, AC_DEFINE(SRAND,srand) AC_DEFINE(LRAND,rand) srand=yes))])
AC_CHECK_FUNC(srand48,
  [AC_DEFINE(HAVE_RAND48)
   AC_MSG_CHECKING([for srand48 declaration])
   AC_EGREP_HEADER(srand48, stdlib.h,
     AC_DEFINE(DECLARED_SRAND48) AC_MSG_RESULT(yes),
     AC_MSG_RESULT(no))])
  if test $ac_cv_func_srand48 = no; then
    AC_CHECK_FUNC(srandom, AC_DEFINE(HAVE_RANDOM))
    if test $ac_cv_func_srandom = no; then
      AC_CHECK_FUNC(srand, AC_DEFINE(HAVE_RAND) srand=yes)
    fi
  fi
dnl if test "$srand" = yes; then
dnl   case "${canonical}" in
dnl     *-*-aix* )
dnl       AC_DEFINE(MAXRAND,2147483648.0)
dnl       ;;
dnl     *-*-* )
dnl       AC_DEFINE(MAXRAND,32768.0)
dnl       ;;
dnl   esac
dnl else
dnl   AC_DEFINE(MAXRAND,2147483648.0)
dnl fi

dnl Rather have a usleep
AC_CHECK_FUNC(usleep, AC_DEFINE(HAVE_USLEEP))
if test $ac_cv_func_usleep = no; then
AC_CHECK_FUNC(nanosleep, AC_DEFINE(HAVE_NANOSLEEP))
fi

AC_ARG_ENABLE(constpixmaps, [  --enable-constpixmaps   g++ build with make constpixmaps; make],
  constpixmaps=$enableval,
  constpixmaps=no)
if test "$constpixmaps" = "yes"; then
  AC_MSG_RESULT([enabling constpixmaps])
  CFLAGS="${CFLAGS} -DCONSTPIXMAPS"
fi

dnl Checks for library functions.
dnl AC_CHECK_FUNCS(select)

dnl X Window System files.
AC_PATH_XTRA
if test "$no_x" = yes; then
  XLIBS=NONE
else
  if test -n "${x_includes}"; then
    XWIDGETINC="-I${x_includes} ${XWIDGETINC}"
dnl    if test "${CC}" = "gcc" ; then
   dnl   Do not warn me about anything here
dnl      XWIDGETINC="-isystem ${x_includes} ${XWIDGETINC}"
dnl    fi
  fi
  XLIBS="${x_libraries}"
  if test -n "${x_libraries}"; then
    XWIDGET_LDFLAGS="/usr/lib:${x_libraries}"
    XWIDGETLIBPATHS="-L${x_libraries} ${XWIDGETLIBPATHS}"
  fi
  LIBS="${X_PRE_LIBS} -lXt -lX11 ${X_EXTRA_LIBS} ${LIBS}"
dnl AC_DEFINE(X11) /* If there is no X, its not going to go */
fi

# Try and find the app-defaults directory.
AC_DEFUN(AC_PATH_X_APP_DEFAULTS_XMKMF,
  [
  rm -fr conftestdir
  if mkdir conftestdir; then
    cd conftestdir
    # Make sure to not put "make" in the Imakefile rules, since we grep it out.
    cat > Imakefile <<'EOF'
acfindx:
  @echo 'ac_x_app_defaults="${XAPPLOADDIR}"'
EOF
    if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
      # GNU make sometimes prints "make[1]: Entering...", which'd confuse us.
      eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
    fi
    cd ..
    rm -fr conftestdir
  fi])

AC_DEFUN(AC_PATH_X_APP_DEFAULTS_DIRECT,
[  # Look for the directory under a standard set of common directories.
  # Check X11 before X11Rn because it's often a symlink to the current release.
  for ac_dir in         \
    /lib/X11/app-defaults \
    /lib/app-defaults \
    /lib/X11R6/app-defaults \
    /lib/X11R6/X11/app-defaults \
    /lib/X11R5/app-defaults \
    /lib/X11R5/X11/app-defaults \
    /lib/X11R4/app-defaults \
    /lib/X11R4/X11/app-defaults \
    ; \
  do
    found=""
    if test -d "${prefix}$ac_dir"; then
      ac_x_app_defaults=\\\$\\\{prefix\\\}$ac_dir
    found="1"
      break
    fi
  done
  if test -z "$found"; then
  for ac_dir in         \
    /usr/X11/lib/app-defaults     \
    /usr/X11R6/lib/app-defaults     \
    /usr/X11R6/lib/X11/app-defaults   \
    /usr/X11R5/lib/app-defaults     \
    /usr/X11R5/lib/X11/app-defaults   \
    /usr/X11R4/lib/app-defaults     \
    /usr/X11R4/lib/X11/app-defaults   \
            \
    /usr/lib/X11/app-defaults     \
    /usr/lib/X11R6/app-defaults     \
    /usr/lib/X11R5/app-defaults     \
    /usr/lib/X11R4/app-defaults     \
            \
    /usr/local/X11/lib/app-defaults   \
    /usr/remote/X11/lib/app-defaults   \
    /usr/local/X11R6/lib/app-defaults   \
    /usr/local/X11R6/lib/X11/app-defaults   \
    /usr/local/X11R5/lib/app-defaults   \
    /usr/local/X11R5/lib/X11/app-defaults   \
    /usr/local/X11R4/lib/app-defaults   \
    /usr/local/X11R4/lib/X11/app-defaults   \
            \
    /usr/local/lib/X11/app-defaults   \
    /usr/remote/lib/X11/app-defaults   \
    /usr/local/lib/X11R6/app-defaults   \
    /usr/local/lib/X11R6/X11/app-defaults \
    /usr/local/lib/X11R5/app-defaults   \
    /usr/local/lib/X11R5/X11/app-defaults \
    /usr/local/lib/X11R4/app-defaults   \
    /usr/local/lib/X11R4/X11/app-defaults \
            \
    /usr/X386/lib/X11/app-defaults    \
    /usr/x386/lib/X11/app-defaults    \
    /usr/XFree86/lib/X11/app-defaults   \
            \
    /usr/lib/X11/app-defaults     \
    /usr/unsupported/lib/X11/app-defaults \
    /usr/athena/lib/X11/app-defaults    \
    /usr/local/x11r5/lib/X11/app-defaults \
    /usr/lpp/Xamples/lib/X11/app-defaults \
    /lib/usr/lib/X11/app-defaults   \
    /usr/local/lib/app-defaults   \
    /usr/remote/lib/app-defaults   \
            \
    /usr/openwin/lib/app-defaults   \
    /usr/openwin/lib/X11/app-defaults   \
    /usr/openwin/share/lib/app-defaults   \
    /usr/openwin/share/lib/X11/app-defaults \
            \
    /X11R6/lib/app-defaults     \
    /X11R5/lib/app-defaults     \
    /X11R4/lib/app-defaults     \
    ; \
  do
    if test -d "$ac_dir"; then
      ac_x_app_defaults=$ac_dir
      break
    fi
  done
    fi
])

AC_DEFUN(AC_PATH_X_APP_DEFAULTS,
  [AC_REQUIRE_CPP()
    AC_CACHE_CHECK([for X app-defaults directory], ac_cv_x_app_defaults,
     [AC_PATH_X_APP_DEFAULTS_XMKMF
      AC_PATH_X_APP_DEFAULTS_DIRECT
      if test x"$ac_x_app_defaults" = x; then
        ac_cv_x_app_defaults="/usr/lib/X11/app-defaults"
      else
        # Record where we found app-defaults for the cache.
        ac_cv_x_app_defaults="$ac_x_app_defaults"
      fi])
    eval ac_x_app_defaults="$ac_cv_x_app_defaults"])

AC_PATH_X_APP_DEFAULTS
APPDEFAULTS=$ac_x_app_defaults

AC_ARG_WITH(includes, [  --with-includes=DIR     search include DIR for optional packages below])
case "x$withval" in
x/*|x.*)
  extra_include=$withval
  AC_MSG_RESULT([adding $extra_include to include search path for following packages ])
  if test ! -d $extra_include; then
    AC_MSG_RESULT([Warning: Directory $extra_include does not exist])
  fi
  ;;
*)
  extra_include=""
  ;;
esac

AC_ARG_WITH(libraries, [  --with-libraries=DIR    search library DIR for optional packages below])
case "x$withval" in
x/*|x.*)
  extra_lib=$withval
  AC_MSG_RESULT([adding $extra_lib to library search path for following packages])
  if test ! -d $extra_lib; then
    AC_MSG_RESULT([Warning: Directory $extra_lib does not exist])
  fi
  ;;
*)
  extra_lib=""
  ;;
esac

dnl Xm MOTIF Motif motif

AC_DEFUN(AC_PATH_MOTIF_DIRECT,
[test -z "$motif_direct_test_library" && motif_direct_test_library=Xm
test -z "$motif_direct_test_function" && motif_direct_test_function=XmCreatePushButton
test -z "$motif_direct_test_include" && motif_direct_test_include=Xm/Xm.h
  for ac_dir in               \
    /usr/include/Motif1.2     \
    /usr/Motif1.2/include     \
                              \
    /usr/motif/include        \
                              \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11R4/include        \
                              \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
    /usr/include/X11R4        \
                              \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
    /usr/local/X11R4/include  \
                              \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
    /usr/local/include/X11R4  \
                              \
    /usr/X11/include          \
    /usr/include/X11          \
    /usr/local/X11/include    \
    /usr/local/include/X11    \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
                              \
    /usr/dt/include           \
                              \
    /usr/local/include        \
    /usr/remote/include       \
    /usr/include              \
    /usr/unsupported/include  \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
    $extra_include            \
    ; \
  do
    if test -r "$ac_dir/$motif_direct_test_include"; then
      no_motif= ac_motif_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Don't add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$motif_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_motif_includes" | sed s/include/lib/` \
    /usr/lib/Motif1.2     \
    /usr/Motif1.2/lib     \
                          \
    /usr/motif/lib        \
                          \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
    /usr/X11R4/lib        \
                          \
    /usr/lib/X11R6        \
    /usr/lib/X11R5        \
    /usr/lib/X11R4        \
                          \
    /usr/local/X11R6/lib  \
    /usr/local/X11R5/lib  \
    /usr/local/X11R4/lib  \
                          \
    /usr/local/lib/X11R6  \
    /usr/local/lib/X11R5  \
    /usr/local/lib/X11R4  \
                          \
    /usr/X11/lib          \
    /usr/lib/X11          \
    /usr/local/X11/lib    \
                          \
    /usr/X386/lib         \
    /usr/x386/lib         \
    /usr/XFree86/lib/X11  \
                          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/remote/lib       \
    /usr/unsupported/lib  \
    /usr/athena/lib       \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
    $extra_lib            \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${motif_direct_test_library}.$ac_extension; then
      no_motif= ac_motif_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"])
AC_DEFUN(AC_PATH_MOTIF,
[AC_REQUIRE_CPP()dnl

motif_includes=NONE
motif_libraries=NONE

AC_MSG_CHECKING(for Motif)
AC_ARG_WITH(motif, [  --without-motif         disable Motif])
if test "x$with_motif" = xno; then
  no_motif=yes
else
  if test "x$motif_includes" != xNONE && test "x$motif_libraries" != xNONE; then
    no_motif=
  else
AC_CACHE_VAL(ac_cv_path_motif,
[# One or both of these vars are not set, and there is no cached value.
no_motif=yes
AC_PATH_MOTIF_DIRECT

if test "$no_motif" = yes; then
  ac_cv_path_motif="no_motif=yes"
else
  ac_cv_path_motif="no_motif= ac_motif_includes=$ac_motif_includes ac_motif_libraries=$ac_motif_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_motif"
fi # with_motif != no

if test "$no_motif" = yes; then
  AC_MSG_RESULT(no)
else
  AC_DEFINE(HAVE_MOTIF)
  LIBS="-lXm ${LIBS}"
  test "x$motif_includes" = xNONE && motif_includes=$ac_motif_includes
  test "x$motif_libraries" = xNONE && motif_libraries=$ac_motif_libraries
  ac_cv_path_motif="no_motif= ac_motif_includes=$motif_includes ac_motif_libraries=$motif_libraries"
  AC_MSG_RESULT([libraries $motif_libraries, headers $motif_includes])
fi
])

AC_PATH_MOTIF

if test "x$motif_libraries" != x ; then
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$motif_libraries"
  XWIDGETLIBPATHS="-L$motif_libraries ${XWIDGETLIBPATHS}"
fi
if test "x$motif_includes" != x ; then
  XWIDGETINC="${XWIDGETINC} -I$motif_includes"
fi

XM_PREFIX=
AC_ARG_ENABLE(xm_prefix, [  --enable-xm-prefix      install binary with an xm prefix (instead of an x)],
  xm_prefix=$enableval,
  xm_prefix=no)
if test "$xm_prefix" = "yes"; then
  AC_MSG_RESULT([enabling xm-prefix])
  XM_PREFIX=m
fi

dnl Xmu EDITRES Editres editres

AC_DEFUN(AC_PATH_EDITRES_DIRECT,
[test -z "$editres_direct_test_library" && editres_direct_test_library=Xmu
test -z "$editres_direct_test_function" && editres_direct_test_function=_XEditResCheckMessages
test -z "$editres_direct_test_include" && editres_direct_test_include=X11/Xmu/Editres.h
  for ac_dir in               \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11R4/include        \
    /usr/X11/include          \
                              \
    /usr/include/X11          \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
    /usr/include/X11R4        \
                              \
    /usr/local/X11/include    \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
    /usr/local/X11R4/include  \
                              \
    /usr/local/include/X11    \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
    /usr/local/include/X11R4  \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include      \
                              \
    /usr/local/include        \
    /usr/remote/include       \
    /usr/include              \
    /usr/unsupported/include  \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
                              \
    /usr/openwin/include      \
    /usr/openwin/share/include \
    $extra_include            \
    ; \
  do
    if test -r "$ac_dir/$editres_direct_test_include"; then
      no_editres= ac_editres_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Don't add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$editres_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_editres_includes" | sed s/include/lib/` \
                          \
    /usr/X11/lib          \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
    /usr/X11R4/lib        \
                          \
    /usr/lib/X11          \
    /usr/lib/X11R6        \
    /usr/lib/X11R5        \
    /usr/lib/X11R4        \
                          \
    /usr/local/X11/lib    \
    /usr/local/X11R6/lib  \
    /usr/local/X11R5/lib  \
    /usr/local/X11R4/lib  \
                          \
    /usr/local/lib/X11    \
    /usr/local/lib/X11R6  \
    /usr/local/lib/X11R5  \
    /usr/local/lib/X11R4  \
                          \
    /usr/X386/lib         \
    /usr/x386/lib         \
    /usr/XFree86/lib/X11  \
                          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/remote/lib       \
    /usr/unsupported/lib  \
    /usr/athena/lib       \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
    /lib/usr/lib/X11      \
                          \
    /usr/openwin/lib      \
    /usr/openwin/share/lib \
    $extra_lib            \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${editres_direct_test_library}.$ac_extension; then
      no_editres= ac_editres_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"])
AC_DEFUN(AC_PATH_EDITRES,
[AC_REQUIRE_CPP()dnl

editres_includes=NONE
editres_libraries=NONE

AC_MSG_CHECKING(for Editres)
AC_ARG_WITH(editres, [  --with-editres          debugger for motif])
if test "x$with_editres" = xno; then
  no_editres=yes
else
  if test "x$editres_includes" != xNONE && test "x$editres_libraries" != xNONE; then
    no_editres=
  else
AC_CACHE_VAL(ac_cv_path_editres,
[# One or both of these vars are not set, and there is no cached value.
no_editres=yes
AC_PATH_EDITRES_DIRECT

if test "$no_editres" = yes; then
  ac_cv_path_editres="no_editres=yes"
else
  ac_cv_path_editres="no_editres= ac_editres_includes=$ac_editres_includes ac_editres_libraries=$ac_editres_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_editres"
fi # with_editres != no

if test "$no_editres" = yes; then
  AC_MSG_RESULT(no)
else
  AC_DEFINE(USE_XMU)
  LIBS="-lXmu ${LIBS}"
  test "x$editres_includes" = xNONE && editres_includes=$ac_editres_includes
  test "x$editres_libraries" = xNONE && editres_libraries=$ac_editres_libraries
  ac_cv_path_editres="no_editres= ac_editres_includes=$editres_includes ac_editres_libraries=$editres_libraries"
  AC_MSG_RESULT([libraries $editres_libraries, headers $editres_includes])
fi
])

dnl AC_PATH_EDITRES

if test "x$editres_libraries" != x ; then
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$editres_libraries"
  XWIDGETLIBPATHS="-L$editres_libraries ${XWIDGETLIBPATHS}"
fi
if test "x$editres_includes" != x ; then
  XWIDGETINC="${XWIDGETINC} -I$editres_includes"
fi

xpm=no
dnl Xpm XPM xpm

AC_DEFUN(AC_PATH_XPM_DIRECT,
[test -z "$xpm_direct_test_library" && xpm_direct_test_library=Xpm
test -z "$xpm_direct_test_function" && xpm_direct_test_function=XpmCreateImageFromData
test -z "$xpm_direct_test_include" && xpm_direct_test_include=X11/xpm.h
  for ac_dir in               \
    /usr/include              \
    /usr/openwin/include      \
    /usr/openwin/share/include \
    /usr/include/Vk           \
                              \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11R4/include        \
                              \
    /usr/include/X11R6        \
    /usr/include/X11R5        \
    /usr/include/X11R4        \
                              \
    /usr/local/X11R6/include  \
    /usr/local/X11R5/include  \
    /usr/local/X11R4/include  \
                              \
    /usr/local/include/X11    \
    /usr/local/include/X11R6  \
    /usr/local/include/X11R5  \
    /usr/local/include/X11R4  \
                              \
    /usr/X386/include         \
    /usr/x386/include         \
    /usr/XFree86/include/X11  \
                              \
    /usr/local/include        \
    /usr/remote/include       \
    /usr/include              \
    /usr/unsupported/include  \
    /usr/athena/include       \
    /usr/local/x11r5/include  \
    /usr/lpp/Xamples/include  \
    $extra_include            \
    ; \
  do
    if test -r "$ac_dir/$xpm_direct_test_include"; then
      no_xpm= ac_xpm_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Do not add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$xpm_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_xpm_includes" | sed s%/X11$%% | sed s/include/lib/` \
    /usr/include              \
    /usr/openwin/include      \
    /usr/openwin/share/include \
    /usr/include/Vk           \
                          \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
    /usr/X11R4/lib        \
                          \
    /usr/lib/X11R6        \
    /usr/lib/X11R5        \
    /usr/lib/X11R4        \
                          \
    /usr/local/X11/lib    \
    /usr/local/X11R6/lib  \
    /usr/local/X11R5/lib  \
    /usr/local/X11R4/lib  \
                          \
    /usr/local/lib/X11    \
    /usr/local/lib/X11R6  \
    /usr/local/lib/X11R5  \
    /usr/local/lib/X11R4  \
                          \
    /usr/X386/lib         \
    /usr/x386/lib         \
    /usr/XFree86/lib/X11  \
                          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/remote/lib       \
    /usr/unsupported/lib  \
    /usr/athena/lib       \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
    $extra_lib            \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${xpm_direct_test_library}.$ac_extension; then
      no_xpm= ac_xpm_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"])
AC_DEFUN(AC_PATH_XPM,
[AC_REQUIRE_CPP()dnl

xpm_includes=NONE
xpm_libraries=NONE

AC_MSG_CHECKING(for XPM)
AC_ARG_WITH(xpm, [  --without-xpm           disable color icon])
if test "x$with_xpm" = xno; then
  no_xpm=yes
else
  if test "x$xpm_includes" != xNONE && test "x$xpm_libraries" != xNONE; then
    no_xpm=
  else
AC_CACHE_VAL(ac_cv_path_xpm,
[# One or both of these vars are not set, and there is no cached value.
no_xpm=yes
AC_PATH_XPM_DIRECT

if test "$no_xpm" = yes; then
  ac_cv_path_xpm="no_xpm=yes"
else
  ac_cv_path_xpm="no_xpm= ac_xpm_includes=$ac_xpm_includes ac_xpm_libraries=$ac_xpm_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_xpm"
fi # with_xpm != no

if test "$no_xpm" = yes; then
  AC_MSG_RESULT(no)
else
  AC_DEFINE(HAVE_XPM)
  LIBS="${LIBS} -lXpm"
  test "x$xpm_includes" = xNONE && xpm_includes=$ac_xpm_includes
  test "x$xpm_libraries" = xNONE && xpm_libraries=$ac_xpm_libraries
  ac_cv_path_xpm="no_xpm= ac_xpm_includes=$xpm_includes ac_xpm_libraries=$xpm_libraries"
  AC_MSG_RESULT([libraries $xpm_libraries, headers $xpm_includes])
fi
])

AC_PATH_XPM

if test "x$xpm_libraries" != x && test "x$xpm_libraries" != xNONE ; then
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$xpm_libraries"
  XWIDGETLIBPATHS="${XWIDGETLIBPATHS} -L$xpm_libraries"
fi
if test "x$xpm_includes" != x && test "x$xpm_includes" != xNONE ; then
  XWIDGETINC="${XWIDGETINC} -I$xpm_includes"
fi

sound=none
dnl RPLAY RPlay rplay

AC_DEFUN(AC_PATH_RPLAY_DIRECT,
[test -z "$rplay_direct_test_library" && rplay_direct_test_library=rplay
test -z "$rplay_direct_test_function" && rplay_direct_test_function=rplay_open_default
test -z "$rplay_direct_test_include" && rplay_direct_test_include=rplay.h
  for ac_dir in               \
    /usr/X11R6.5.1/include    \
    /usr/X11R6.4/include      \
    /usr/X11R6.3/include      \
    /usr/X11R6.2/include      \
    /usr/X11R6.1/include      \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11/include          \
    /usr/local/include        \
    /usr/remote/include       \
    /usr/include              \
    $extra_include            \
    ; \
  do
    if test -r "$ac_dir/$rplay_direct_test_include"; then
      no_rplay= ac_rplay_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Do not add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$rplay_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_rplay_includes" | sed s/include/lib/` \
                          \
    /usr/X11R6.5.1/lib    \
    /usr/X11R6.4/lib      \
    /usr/X11R6.3/lib      \
    /usr/X11R6.2/lib      \
    /usr/X11R6.1/lib      \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
    /usr/X11/lib          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/remote/lib       \
    $extra_lib            \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${rplay_direct_test_library}.$ac_extension; then
      no_rplay= ac_rplay_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"])
AC_DEFUN(AC_PATH_RPLAY,
[AC_REQUIRE_CPP()dnl

rplay_includes=NONE
rplay_libraries=NONE

AC_MSG_CHECKING(for RPLAY)
AC_ARG_WITH(rplay, [  --without-rplay         disable RPLAY sounds])
if test "x$with_rplay" = xno; then
  no_rplay=yes
else
  if test "x$rplay_includes" != xNONE && test "x$rplay_libraries" != xNONE; then
    no_rplay=
  else
AC_CACHE_VAL(ac_cv_path_rplay,
[# One or both of these vars are not set, and there is no cached value.
no_rplay=yes
AC_PATH_RPLAY_DIRECT

if test "$no_rplay" = yes; then
  ac_cv_path_rplay="no_rplay=yes"
else
  ac_cv_path_rplay="no_rplay= ac_rplay_includes=$ac_rplay_includes ac_rplay_libraries=$ac_rplay_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_rplay"
fi # with_rplay != no

if test "$no_rplay" = yes; then
  AC_MSG_RESULT(no)
else
dnl  solaris26=no
dnl  case "${canonical}" in
dnl    *-*-solaris2.6 )
dnl    solaris26=yes
dnl    ;;
dnl  esac
dnl  if test "$CC" = gcc && test "$solaris26" = yes; then
dnl    AC_MSG_RESULT(ignored - problems here with gcc and solaris2.6)
dnl  else
    sound=rplay
    AC_DEFINE(USE_RPLAY)
    LIBS="${LIBS} -lrplay"
    test "x$rplay_includes" = xNONE && rplay_includes=$ac_rplay_includes
    test "x$rplay_libraries" = xNONE && rplay_libraries=$ac_rplay_libraries
    ac_cv_path_rplay="no_rplay= ac_rplay_includes=$rplay_includes ac_rplay_libraries=$rplay_libraries"
    AC_MSG_RESULT([libraries $rplay_libraries, headers $rplay_includes])
dnl  fi
fi
])

AC_PATH_RPLAY

if test "x$rplay_libraries" != x && test "x$rplay_libraries" != xNONE ; then
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$rplay_libraries"
  XWIDGETLIBPATHS="${XWIDGETLIBPATHS} -L$rplay_libraries"
fi
if test "x$rplay_includes" != x && test "x$rplay_includes" != xNONE ; then
  XWIDGETINC="${XWIDGETINC} -I$rplay_includes"
fi

dnl ESOUND Enlightenment sound daemon

AC_DEFUN(AC_PATH_ESOUND,
[AC_REQUIRE_CPP()dnl

esound_includes=NONE
esound_libraries=NONE

AC_MSG_CHECKING(for ESOUND)
AC_ARG_WITH(esound,            [  --with-esound           enable Enlightenment Sound Daemon sounds])
AC_ARG_WITH(esound_config,     [  --with-esound-config    use this configurator for Enlightenment Sound Daemon])
AC_ARG_WITH(esound_prefix,     [  --with-esound-prefix    use this prefix for Enlightenment Sound Daemon])
AC_ARG_WITH(esound_includes,   [  --with-esound-includes  use this dir for Enlightenment Sound Daemon headers])
AC_ARG_WITH(esound_libraries,  [  --with-esound-libraries use this dir for Enlightenment Sound Daemon libs])
if test "x$with_esound" = xno; then
  no_esound=yes
else
  if test "x$esound_includes" != xNONE && test "x$esound_libraries" != xNONE; then
    no_esound=
    if test "x$esound_config" = "x"; then
      if test "x$esound_prefix" != "x"; then
        esound_config="$esound_prefix/bin/esd-config"
      else
        esound_config="esd-config"
      fi
    else
      if test "x$esound_prefix" = "x"; then
        esound_prefix=`$esound_config --prefix 2> /dev/null`
      fi
    fi
  else
    if test "x$esound_config" = "x"; then
      if test "x$esound_prefix" != "x"; then
        esound_config="$esound_prefix/bin/esd-config"
      else
        esound_config="esd-config"
      fi
    else
      if test "x$esound_prefix" = "x"; then
        esound_prefix=`$esound_config --prefix 2> /dev/null`
      fi
    fi
AC_CACHE_VAL(ac_cv_path_esound,
[# One or both of these vars are not set, and there is no cached value.
no_esound=yes
no_esound_config=yes
if test "x$esound_prefix" != "x"; then
  ac_esound_prefix=$esound_prefix
  ac_esound_includes=$ac_esound_prefix/include
  ac_esound_libraries=$ac_esound_prefix/lib
  no_esound="ac_esound_config=$ac_esound_config ac_esound_prefix=$ac_esound_prefix ac_esound_includes=$ac_esound_includes ac_esound_libraries=$ac_esound_libraries"
else
  ac_esound_config="$esound_config"
  ac_esound_prefix=`$esound_config --prefix 2> /dev/null`
  if test $? != 0; then
    no_esound=yes
    no_esound_config=yes
    ac_esound_config=""
    ac_esound_prefix=""
  else
    no_esound=
    no_esound_config=
    ac_esound_includes=$ac_esound_prefix/include
    ac_esound_libraries=$ac_esound_prefix/lib
  fi
fi
if $esound_config --libs 2>&1 | grep "not found" > /dev/null; then
  no_esound=yes
fi
if $esound_config --cflags 2>&1 | grep "not found" > /dev/null; then
  no_esound=yes
fi
if test "$no_esound" = yes; then
  ac_cv_path_esound="no_esound=yes"
else
  ac_cv_path_esound="no_esound= ac_esound_config=\"$ac_esound_config\" ac_esound_prefix=\"$ac_esound_prefix\" ac_esound_includes=\"$ac_esound_includes\" ac_esound_libraries=\"$ac_esound_libraries\""
fi])dnl
  fi
  eval "$ac_cv_path_esound"
fi # with_esound != no

if test "$no_esound_config" = yes; then
  AC_MSG_RESULT(no esd-config)
else
  if test "$no_esound" = yes; then
    AC_MSG_RESULT(no)
  else
    if test "$sound" = none; then
      sound=yes
      AC_DEFINE(USE_ESOUND)
      AC_DEFINE(HAVE_LIBESD)
      #if test "x$prefix" = xNONE; then
      #  AC_DEFINE_UNQUOTED(SOUNDPATH, "/usr/local/share/games/xpuzzles")
      #else
      #  AC_DEFINE_UNQUOTED(SOUNDPATH, "${prefix}/share/games/xpuzzles")
      #fi
      test "x$esound_config" = xNONE && esound_config=$ac_esound_config
      test "x$esound_prefix" = xNONE && esound_prefix=$ac_esound_prefix
      test "x$esound_includes" = xNONE && esound_includes=$ac_esound_includes
      test "x$esound_libraries" = xNONE && esound_libraries=$ac_esound_libraries
      ac_cv_path_esound="no_esound= ac_esound_config=$esound_config ac_esound_prefix=$esound_prefix ac_esound_includes=$esound_includes ac_esound_libraries=$esound_libraries"
      AC_MSG_RESULT([libraries $esound_libraries, headers $esound_includes])
    else
      AC_MSG_RESULT(ignored - using previous definition for sound)
    fi
  fi
fi
])

AC_PATH_ESOUND

if test "x$esound_libraries" != x && test "x$esound_libraries" != xNONE ; then
  LIBS="${LIBS} `$esound_config --libs`"
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$esound_libraries"
  XWIDGETLIBPATHS="${XWIDGETLIBPATHS} -L$esound_libraries"
fi
if test "x$esound_includes" != x && test "x$esound_includes" != xNONE ; then
  XWIDGETINC="${XWIDGETINC} -I$esound_includes `$esound_config --cflags`"
fi

dnl NAS audio

AC_DEFUN(AC_PATH_NAS_DIRECT,
[test -z "$nas_direct_test_library" && nas_direct_test_library=audio
test -z "$nas_direct_test_function" && nas_direct_test_function=AuOpenServer
test -z "$nas_direct_test_include" && nas_direct_test_include=audio/audio.h
  for ac_dir in               \
    /usr/X11R6.5.1/include    \
    /usr/X11R6.4/include      \
    /usr/X11R6.3/include      \
    /usr/X11R6.2/include      \
    /usr/X11R6.1/include      \
    /usr/X11R6/include        \
    /usr/X11R5/include        \
    /usr/X11/include          \
    /usr/local/include        \
    /usr/remote/include       \
    /usr/include              \
    $extra_include            \
    ; \
  do
    if test -r "$ac_dir/$nas_direct_test_include"; then
      no_nas= ac_nas_includes=$ac_dir
      break
    fi
  done

# Check for the libraries.
# See if we find them without any special options.
# Do not add to $LIBS permanently.
ac_save_LIBS="$LIBS"
LIBS="-l$nas_direct_test_library $LIBS"
# First see if replacing the include by lib works.
for ac_dir in `echo "$ac_nas_includes" | sed s/include/lib/` \
                          \
    /usr/X11R6.5.1/lib    \
    /usr/X11R6.4/lib      \
    /usr/X11R6.3/lib      \
    /usr/X11R6.2/lib      \
    /usr/X11R6.1/lib      \
    /usr/X11R6/lib        \
    /usr/X11R5/lib        \
    /usr/X11/lib          \
    /usr/lib              \
    /usr/local/lib        \
    /usr/remote/lib       \
    $extra_lib            \
    ; \
do
  for ac_extension in a so sl; do
    if test -r $ac_dir/lib${nas_direct_test_library}.$ac_extension; then
      no_nas= ac_nas_libraries=$ac_dir
      break 2
    fi
  done
done
LIBS="$ac_save_LIBS"])
AC_DEFUN(AC_PATH_NAS,
[AC_REQUIRE_CPP()dnl

nas_includes=NONE
nas_libraries=NONE

AC_MSG_CHECKING(for NAS)
AC_ARG_WITH(nas, [  --without-nas           disable NAS sounds])
if test "x$with_nas" = xno; then
  no_nas=yes
else
  if test "x$nas_includes" != xNONE && test "x$nas_libraries" != xNONE; then
    no_nas=
  else
AC_CACHE_VAL(ac_cv_path_nas,
[# One or both of these vars are not set, and there is no cached value.
no_nas=yes
AC_PATH_NAS_DIRECT

if test "$no_nas" = yes; then
  ac_cv_path_nas="no_nas=yes"
else
  ac_cv_path_nas="no_nas= ac_nas_includes=$ac_nas_includes ac_nas_libraries=$ac_nas_libraries"
fi])dnl
  fi
  eval "$ac_cv_path_nas"
fi # with_nas != no

if test "$no_nas" = yes; then
  AC_MSG_RESULT(no)
else
  if test "$sound" = none; then
    sgi=no
    case "${canonical}" in
      *-*-irix5* | *-*-irix6* )
        sgi=yes
      ;;
    esac
    if test "$sgi" = yes; then
      AC_MSG_RESULT(ignored - problems here with audio and nas)
    else
      sound=nas
      AC_DEFINE(USE_NAS)
      LIBS="${LIBS} -laudio"
dnl    LIBS="${LIBS} -lnas"
      test "x$nas_includes" = xNONE && nas_includes=$ac_nas_includes
      test "x$nas_libraries" = xNONE && nas_libraries=$ac_nas_libraries
      ac_cv_path_nas="no_nas= ac_nas_includes=$nas_includes ac_nas_libraries=$nas_libraries"
      AC_MSG_RESULT([libraries $nas_libraries, headers $nas_includes])
    fi
  else
    AC_MSG_RESULT(ignored - using previous definition for sound)
  fi
fi
])

AC_PATH_NAS

if test "x$nas_libraries" != x && test "x$nas_libraries" != xNONE ; then
  XWIDGET_LDFLAGS="${XWIDGET_LDFLAGS}:$nas_libraries"
  XWIDGETLIBPATHS="${XWIDGETLIBPATHS} -L$nas_libraries"
fi
if test "x$nas_includes" != x && test "x$nas_includes" != xNONE ; then
  XWIDGETINC="${XWIDGETINC} -I$nas_includes"
fi

if test "$sound" = none; then
  AC_ARG_ENABLE(def_play, [  --enable-def-play=program
                          set def-play to program that plays sounds],def_play=$enableval,def_play=no)
  if test "$def_play" != no; then
    AC_MSG_RESULT([defining option DEF_PLAY = "$enableval"])
    AC_DEFINE_UNQUOTED(DEF_PLAY,"$enableval")
  fi
fi

dnl Now we handle the various system dependent problems
dnl that aren't addressed in the X header files, or things dealing
dnl with utility quirks on some systems.

AC_CANONICAL_HOST
canonical=$host
case "${canonical}" in

  *-*-aix2* | *-*-aix3.0* | *-*-aix3.1* )
    AC_DEFINE(LESS_THAN_AIX3_2)
  ;;

  *-*-cygwin* )
    LIBS="${LIBS} -lSM -lICE"
  ;;

  *-*-freebsd* | *-*-netbsd* | *-*-openbsd* )
    XWIDGETLDFLAGS="-R${XWIDGET_LDFLAGS}"
  ;;

  *-*-hpux* )
    if test "${CC}" = "cc" ; then
      CFLAGS="${CFLAGS} -Aa -z -D_HPUX_SOURCE"
      GPROF_CFLAGS="${GPROF_CFLAGS} -Aa -z -D_HPUX_SOURCE"
    fi
  ;;

  *-*-irix5* | *-*-irix6* )
    if test "${CC}" = "cc" ; then
      CFLAGS="${CFLAGS} -fullwarn"
    fi
  ;;

  *-*-linux* )
    CFLAGS="${CFLAGS} -std=c99 -pedantic"
    AC_DEFINE(linux)
    AC_DEFINE(_POSIX_SOURCE)
    AC_DEFINE(_BSD_SOURCE)
    AC_DEFINE(_GNU_SOURCE)
  ;;

  *-*-solaris2* )
    AC_DEFINE(SYSV)
    AC_DEFINE(SVR4)
    XWIDGETLDFLAGS="-R${XWIDGET_LDFLAGS}"
    LIBS="${LIBS} -lsocket -lnsl -lposix4"
  ;;

esac

XWIDGETLIBS="${XWIDGETLIBPATHS} ${LIBS}"
AC_SUBST(XWIDGETLDFLAGS)
AC_SUBST(XWIDGETINC)
AC_SUBST(XLIBS)
AC_SUBST(XWIDGETLIBS)
AC_SUBST(XM_PREFIX)
AC_SUBST(APPDEFAULTS)
AC_SUBST(LINT)

dnl AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
