dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.13)
AC_INIT(include/GL/gl.h)

dnl ------------------------------------------
AM_INIT_AUTOMAKE(Mesa, 3.1b3)
# CURRENT:REVISION:AGE
LIBGL_VERSION=3:0:2
LIBGLU_VERSION=3:0:2
LIBGLUT_VERSION=10:0:7
AC_SUBST(LIBGL_VERSION)
AC_SUBST(LIBGLU_VERSION)
AC_SUBST(LIBGLUT_VERSION)

AM_CONFIG_HEADER(conf.h)
AC_CANONICAL_HOST
AC_DISABLE_STATIC
AC_DISABLE_FAST_INSTALL
dnl AM_MAINTAINER_MODE

dnl ------------------------------------------
dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AM_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl ------------------------------------------
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(math.h malloc.h)

dnl ------------------------------------------
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_CHECK_FUNCS(strchr memcpy memmove)

if test "x$GCC" = xyes; then
   CFLAGS="$CFLAGS -Wall"
fi

AC_ARG_ENABLE(debug,
[  --enable-debug          enable full debugging [default=off]],
  enable_debug=$enableval, enable_debug=no)
if test "x$enable_debug" = xyes; then
  AC_DEFINE(MESA_DEBUG)
  if test "x$GCC" = xyes; then
    CFLAGS="$CFLAGS -O0"
  fi
fi

AC_ARG_ENABLE(profile,
[  --enable-profile        enable profiling [default=off]],
  enable_prof=$enableval, enable_prof=no)
if test "x$enable_prof" = xyes; then
  CFLAGS="$CFLAGS -DPROFILE"
  if test "x$GCC" = xyes; then
    CFLAGS="$CFLAGS -pg"
  fi
fi

AC_ARG_ENABLE(optimize,
[  --enable-optimize       enable extra optimization [default=on]],
  enable_optim=$enableval, enable_optim=yes)
if test "x$enable_optim" = xyes; then
  dnl Optimization flags
  if test "x$enable_debug" = xno && test "x$enable_prof" = xno; then
    if test "x$GCC" = xyes; then
      CFLAGS="$CFLAGS -fomit-frame-pointer -ffast-math -fexpensive-optimizations"
      case "$host" in
      i*86-*-*) CFLAGS="$CFLAGS -malign-loops=2 -malign-jumps=2 -malign-functions=2";;
      esac     
    fi
  fi
fi

AC_ARG_ENABLE(warn,
[  --enable-warn           enable extended compiler warnings [default=off]],
  enable_warn=$enableval, enable_warn=no)
if test "x$enable_warn" = xyes; then
  if test "x$GCC" = xyes; then
    CFLAGS="$CFLAGS -ansi -pedantic"
  fi
fi

dnl Checks for library functions.

dnl Check for drivers
dnl ------------------------------------------

dnl Necessary for assembler sources
save_ac_ext="$ac_ext"
save_CPPFLAGS="$CPPFLAGS"
ac_ext=S
CPPFLAGS="$CPPFLAGS -I$srcdir/src/X86"

dnl x86 assembler
case "$host" in
i*86-*-*) have_x86=on ;;
*) have_x86=off ;;
esac

AC_ARG_ENABLE(x86,
[  --enable-x86            enable x86 assembler [default=autodetect]],
  have_x86=$enableval)
if test "x$have_x86" = xon; then
  AC_MSG_CHECKING(whether the binutils support cpuid)
  cp "$srcdir/src/X86/common_x86asm.S" conftest.S
  if AC_TRY_EVAL(ac_compile); then
    AC_DEFINE(USE_X86_ASM)
    AC_MSG_RESULT(yes)
  else 
    AC_MSG_RESULT(no)
    have_x86=off
  fi
  rm conftest*
fi

dnl ------------------------------------------
dnl MMX support
have_mmx=$have_x86
AC_ARG_ENABLE(mmx,
[  --enable-mmx            enable MMX support [default=autodetect]],
  have_mmx=$enableval)
if test "x$have_mmx" = xon; then
  AC_MSG_CHECKING(whether the binutils support MMX)
  cp "$srcdir/src/X86/mmx_blend.S" conftest.S
  if AC_TRY_EVAL(ac_compile); then
    AC_DEFINE(USE_MMX_ASM)
    AC_MSG_RESULT(yes)
  else 
    AC_MSG_RESULT(no)
    echo 2>&1 "*******************************************************************************"
    echo 2>&1 " The installed assembler does not supports the MMX command set."
    echo 2>&1 " Update your binutils package, if you want to compile MMX support into Mesa."
    echo 2>&1 "*******************************************************************************"
    have_mmx=off
  fi
  rm conftest*
fi

dnl ------------------------------------------
dnl 3Dnow support
have_3dnow=$have_x86
AC_ARG_ENABLE(3dnow,
[  --enable-3dnow          enable 3Dnow support [default=autodetect]],
  have_3dnow=$enableval)
if test "x$have_3dnow" = xon; then
  AC_MSG_CHECKING(whether the binutils support 3Dnow)
  cp "$srcdir/src/X86/3dnow_norm_raw.S" conftest.S
  if AC_TRY_EVAL(ac_compile); then
    AC_DEFINE(USE_3DNOW_ASM)
    AC_MSG_RESULT(yes)
  else 
    AC_MSG_RESULT(no)
    echo 2>&1 "*******************************************************************************"
    echo 2>&1 " The installed assembler does not supports the 3Dnow! command set."
    echo 2>&1 " Update your binutils package, if you want to compile 3Dnow! support into Mesa."
    echo 2>&1 "*******************************************************************************"
    have_3dnow=off
  fi
  rm conftest*
fi
 
ac_ext="$save_ac_ext"
CPPFLAGS="$save_CPPFLAGS"
 
dnl ------------------------------------------
dnl OSmesa driver
have_osmesa=on
AC_ARG_ENABLE(osmesa,
  [  --enable-osmesa         enable OSmesa [default=on]],
  	have_osmesa=$enableval)

dnl ------------------------------------------
dnl Glide driver
have_fx=auto
FX_CFLAGS=""
FX_LIBS=""
AC_ARG_WITH(glide,
[  --with-glide=DIR        Glide is installed in DIR], have_fx="$withval")
if test "x$have_fx" != xno; then
  if test "x$have_fx" != xauto; then
    FX_CFLAGS="-I$withval/include"
    FX_LIBS="-L$withval/lib"
  fi
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $FX_CFLAGS"
  AC_CHECK_HEADER(glide.h, have_fx=yes, have_fx=no)
  if test "x$have_fx" != xyes; then
    CPPFLAGS="$save_CPPFLAGS -I/usr/include/glide2 -I/usr/local/include/glide2"
    AC_CHECK_HEADER(glide2/glide.h,
	FX_CFLAGS="-I/usr/include/glide2 -I/usr/local/include/glide2" have_fx=yes)
  fi
  if test "x$have_fx" != xyes; then
    CPPFLAGS="$save_CPPFLAGS -I/usr/include/glide -I/usr/local/include/glide"
    AC_CHECK_HEADER(glide/glide.h,
	FX_CFLAGS="-I/usr/include/glide -I/usr/local/include/glide" have_fx=yes)
  fi
  CPPFLAGS="$save_CPPFLAGS"
  if test "x$have_fx" = xyes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $FX_LIBS"
    AC_CHECK_LIB(glide2x, main, FX_LIBS="$FX_LIBS -lglide2x"
	AC_DEFINE(FX) have_fx=yes, have_fx=no, -lm)
    LIBS="$save_LIBS"
  fi
  if test "x$have_fx" != xyes; then
    FX_CFLAGS="" FX_LIBS=""
  fi
fi
AC_SUBST(FX_CFLAGS)
AC_SUBST(FX_LIBS)

dnl ------------------------------------------
dnl GGI driver
have_ggi=auto
GGI_CFLAGS=""
GGI_LIBS=""
AC_ARG_WITH(ggi,
[  --with-ggi=DIR          GGI is installed in DIR], have_ggi="$withval")
if test "x$have_ggi" != xno; then
  if test "x$have_ggi" != xauto; then
    GGI_CFLAGS="-I$withval/include"
    GGI_LIBS="-L$withval/lib"
  fi
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $GGI_CFLAGS"
  AC_CHECK_HEADER(ggi/ggi.h, have_ggi=yes, have_ggi=no)
  CPPFLAGS="$save_CPPFLAGS"
  if test "x$have_ggi" = xyes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $GGI_LIBS"
    AC_CHECK_LIB(ggi, main, GGI_LIBS="$GGI_LIBS -lggi" 
	AC_DEFINE(GGI) have_ggi=yes, have_ggi=no, -lgii -lgg)
    LIBS="$save_LIBS"
  fi
  if test "x$have_ggi" != xyes; then
    GGI_CFLAGS="" GGI_LIBS=""
  else
    build_ggi_fbdev_target=auto
    build_ggi_genkgi_driver=auto
    AC_ARG_ENABLE(ggi_fbdev,
    [  --disable-ggi-fbdev     Don't build the GGI fbdev target],
    build_ggi_fbdev_target=$enableval)
    AC_ARG_ENABLE(ggi_genkgi,
    [  --disable-ggi-genkgi    Don't build the GGI generic KGI driver (used by fbdev],
    build_ggi_genkgi_driver=$enableval)

    if test "x$build_ggi_fbdev_target" != "xno"; then
      AC_CHECK_HEADER(linux/fb.h, , build_ggi_fbdev_target=no)
    fi
    
    if test "x$build_ggi_genkgi_driver" != "xno"; then
      AC_CHECK_HEADER(kgi/kgi.h, , build_ggi_genkgi_driver=no)
    fi
    
    AC_MSG_CHECKING(if we should build GGI's fbdev target)
    if test "x$build_ggi_fbdev_target" = "xno"; then
      AC_MSG_RESULT(no)
    else
      GGI_DISPLAY_SUBDIRS="$GGI_DISPLAY_SUBDIRS fbdev"
      build_ggi_fbdev_target=yes
      AC_MSG_RESULT(yes)
    fi
      
    AC_MSG_CHECKING(if we should build GGIMesa's generic KGI driver)
    if test "x$build_ggi_genkgi_driver" = "xno"; then
      AC_MSG_RESULT(no)
    else
      GGI_DEFAULT_SUBDIRS="$GGI_DEFAULT_SUBDIRS kgi"
      build_ggi_genkgi_driver=yes
      AC_MSG_RESULT(yes)
    fi
    
    AM_CONDITIONAL(HAVE_GGI_FBDEV, test $build_ggi_fbdev_target = yes)
    AM_CONDITIONAL(HAVE_GGI_GENKGI, test $build_ggi_genkgi_driver = yes)
  fi
fi
ggi_confdir=/usr/local/etc
ggi_libdir=/usr/local/lib
AC_SUBST(ggi_confdir)
AC_SUBST(ggi_libdir)
AC_SUBST(GGI_CFLAGS)
AC_SUBST(GGI_LIBS)

dnl ------------------------------------------
dnl SVGALib driver
have_svga=auto
SVGA_CFLAGS=""
SVGA_LIBS=""
AC_ARG_WITH(svga,
[  --with-svga=DIR         SVGALib is installed in DIR], have_svga="$withval")
if test "x$have_svga" != xno; then
  if test "x$have_svga" != xauto; then
    SVGA_CFLAGS="-I$withval/include"
    SVGA_LIBS="-L$withval/lib"
  fi
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $SVGA_CFLAGS"
  AC_CHECK_HEADER(vga.h, have_svga=yes, have_svga=no)
  CPPFLAGS="$save_CPPFLAGS"
  if test "x$have_svga" = xyes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $SVGA_LIBS"
    AC_CHECK_LIB(vga, main, SVGA_LIBS="$SVGA_LIBS -lvga"
	AC_DEFINE(SVGA) have_svga=yes, have_svga=no)
    LIBS="$save_LIBS"
  fi
  if test "x$have_svga" != xyes; then
    SVGA_CFLAGS="" SVGA_LIBS=""
  fi
fi
AC_SUBST(SVGA_CFLAGS)
AC_SUBST(SVGA_LIBS)

dnl ------------------------------------------
dnl X11 driver
AC_PATH_XTRA
X_LIBADD=""
if test "x$have_x" = xyes; then
  save_LIBS="$LIBS"
  LIBS="$LIBS $X_LIBS $X_PRE_LIBS"
  AC_CHECK_LIB(Xmu, XmuRegisterExternalAgent, X_LIBADD="$X_LIBADD -lXmu")
  LIBS="$save_LIBS"
fi
X_LIBADD="$X_LIBADD -lXext -lXi -lX11"
AC_SUBST(X_LIBADD)

dnl Check for SHM
AC_CHECK_HEADER(sys/shm.h, AC_DEFINE(SHM))

dnl ------------------------------------------
dnl Check for GLUT
have_glut=auto
GLUT_CFLAGS=""
GLUT_LIBS=""
AC_ARG_WITH(glut,
[  --with-glut=DIR         GLUT is installed in DIR], have_glut="$withval")
if test "x$have_glut" != xno; then
  if test "x$have_glut" != xauto; then
    GLUT_CFLAGS="-I$withval/include"
    GLUT_LIBS="-L$withval/lib"
  fi
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $GLUT_CFLAGS"
  AC_CHECK_HEADER(GL/glut.h, have_glut=yes, have_glut=no)
  CPPFLAGS="$save_CPPFLAGS"
  if test "x$have_glut" = xyes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $GLUT_LIBS"
    AC_CHECK_LIB(glut, main, GLUT_LIBS="$GLUT_LIBS -lglut"
	have_glut=yes, have_glut=no)
    LIBS="$save_LIBS"
  fi
fi
need_glut=no
if test "x$have_glut" != xyes; then
  GLUT_CFLAGS="" GLUT_LIBS=""
  AC_MSG_CHECKING(for GLUT sources)
  if test -d src-glut; then
    AC_MSG_RESULT(yes)
    need_glut=yes
    GLUT_LIBS="\$(top_builddir)/src-glut/libglut.la"
  else 
    AC_MSG_RESULT(no)
    AC_MSG_WARN(Sorry, GLUT not found. Demos might not work.)
    AC_MSG_WARN(Please ignore the warnings about missing Makefiles)
    GLUT_LIBS="-lglut"
  fi
fi
AC_SUBST(GLUT_CFLAGS)
AC_SUBST(GLUT_LIBS)

dnl ------------------------------------------
dnl Check for demos
have_demos=no
AC_MSG_CHECKING(for Mesa demos sources)
if test -d book && test -d demos && test -d images && \
  test -d samples && test -d xdemos; then
  AC_MSG_RESULT(yes)
  have_demos=yes
else 
  AC_MSG_RESULT(no)
  AC_MSG_WARN(Please ignore the warnings about missing Makefiles)
fi

dnl ------------------------------------------
AM_CONDITIONAL(HAVE_3DNOW, test $have_3dnow = on)
AM_CONDITIONAL(HAVE_MMX, test $have_mmx = on)
AM_CONDITIONAL(HAVE_X86, test $have_x86 = on)
AM_CONDITIONAL(HAVE_FX, test $have_fx = yes)
AM_CONDITIONAL(HAVE_GGI, test $have_ggi = yes)
AM_CONDITIONAL(HAVE_OSMESA, test $have_osmesa = on)
AM_CONDITIONAL(HAVE_SVGA, test $have_svga = yes)
AM_CONDITIONAL(HAVE_X11, test $have_x = yes)
AM_CONDITIONAL(NEED_GLUT, test $need_glut = yes)
AM_CONDITIONAL(HAVE_DEMOS, test $have_demos = yes)

dnl ------------------------------------------
AC_OUTPUT(
Makefile
include/Makefile
include/GL/Makefile
src/Makefile
src/FX/Makefile
src/FX/X86/Makefile
src/GGI/Makefile
src/GGI/include/Makefile
src/GGI/include/ggi/Makefile
src/GGI/include/ggi/mesa/Makefile
src/GGI/ggimesa.conf
src/GGI/default/Makefile
src/GGI/default/genkgi.conf
src/GGI/display/Makefile
src/GGI/display/fbdev.conf
src/OSmesa/Makefile
src/SVGA/Makefile
src/X/Makefile
src/X86/Makefile
src-glu/Makefile
src-glut/Makefile
book/Makefile
demos/Makefile
samples/Makefile
xdemos/Makefile
util/Makefile
ggi/demos/Makefile
ggi/ggiglut/Makefile
)
