dnl autoconf script for new-clx
dnl Gilbert Baumann, 1999-10-11

dnl Tried with Autoconf version 2.13

dnl we abstract caching a bit
dnl GB_CHECK(varname, message, instructions) is similar to
dnl AC_CACHE_CHECK, but with no naming constraints on `varname'

define(GB_CHECK,
 AC_CACHE_CHECK($2,gb_cv_$1,$3 gb_cv_$1=$$1)
 $1=$gb_cv_$1)


AC_INIT(clx.f)

dnl find a path to X11
dnl this generates X_LIBS, X_CFLAGS and X_PRE_LIBS
  AC_PATH_XTRA()

dnl Look for Xpm
GB_CHECK(have_xpm, [for Xpm library],
  [ gb_LIBS_save=$LIBS
    gb_CFLAGS_save=$CFLAGS
    LIBS="$X_LIBS -lXpm $X_PRE_LIBS -lX11 $LIBS"
    CFLAGS="$CFLAGS $X_CFLAGS"
    AC_TRY_LINK([#include <X11/xpm.h>], 
		[XpmReadFileToPixmap(0,0,0,0,0,0);],
      have_xpm=yes, 
      have_xpm=no)
    LIBS=$gb_LIBS_save
    CFLAGS=$gb_CFLAGS_save])

dnl Same thing with XShape
GB_CHECK(have_xshape, [for X shape extension],
  [ gb_LIBS_save=$LIBS
    gb_CFLAGS_save=$CFLAGS
    LIBS="$X_LIBS -lXext $X_PRE_LIBS -lX11 $LIBS"
    CFLAGS="$CFLAGS $X_CFLAGS"
    AC_TRY_LINK([#include <X11/Xlib.h>
	         #include <X11/Xutil.h>
	         #include <X11/extensions/shape.h>],
	        [XShapeQueryExtension(0,0,0);],
      have_xshape=yes, 
      have_xshape=no)
    LIBS=$gb_LIBS_save
    CFLAGS=$gb_CFLAGS_save])

dnl Now define some output variables

AC_SUBST(WANTS)		dnl defines WANTS as output variable

dnl Setup X_LIBS as well as WANTS

if test $have_xpm = "yes"; then
    X_LIBS="$X_LIBS -lXpm";
    WANTS="$WANTS -DWANT_XPM=1"
else
    WANTS="$WANTS -DWANT_XPM=0"
fi

if test $have_xshape = "yes"; then
    X_LIBS="$X_LIBS -lXext";
    WANTS="$WANTS -DWANT_XSHAPE=1"
else
    WANTS="$WANTS -DWANT_XSHAPE=0"
fi

dnl And dump what we found:
AC_OUTPUT(Makefile link.sh)

