dnl $Id: configure.in,v 1.3 2000/05/01 16:31:43 grumbel Exp $
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_INIT(ascii-logo)

cat ascii-logo

AC_PREFIX_DEFAULT(/usr/local)

dnl --------------------------------------------
dnl Verify the following programs are available:
dnl --------------------------------------------

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_RANLIB

dnl ----------------------------------------
dnl Search for libraries useful for ClanLib:
dnl ----------------------------------------

AC_CHECK_LIB(z,main,, echo "ClanLib requires zlib to run."; exit 1)
AC_CHECK_LIB(Hermes,main,, echo "ClanLib requires Hermes to run."; exit 1)
AC_CHECK_LIB(ggi,main, GGI=enabled, GGI=disabled)
AC_CHECK_LIB(vga,main, SVGALIB=enabled, SVGALIB=disabled)
AC_CHECK_LIB(ptc,main, PTC=enabled, PTC=disabled)

AC_MSG_CHECKING(for recent linux/fb.h)
AC_EGREP_HEADER(mmio_len, linux/fb.h, echo yes; FBDEV=enabled, echo no; FBDEV=disabled)

AC_CHECK_HEADERS(unistd.h fcntl.h sys/kd.h sys/vt.h)

AC_PATH_X
if test "$no_x" != "yes"; then
	x_includes="-I $x_includes -I $x_includes/X11"
	x_libraries="-L $x_libraries -lX11 -lXext"

	X11=enabled
else
	x_includes=""
	x_libraries=""
    X11=disabled
fi

AC_CHECK_LIB(GL,main, OPENGL=enabled, OPENGL=disabled,-L /usr/X11R6/lib -lX11 -lXext -lm)
AC_CHECK_LIB(Magick,main, Magick=enabled, Magick=disabled,-L /usr/X11R6/lib -lbz2)
AC_CHECK_LIB(Xxf86vm,main, VIDMODE=enabled, VIDMODE=disabled,-L /usr/X11R6/lib -lXxf86vm)

dnl -----------------------------------------------------------------------
dnl Check system endianess: (note: ClanLib is _not_ endian clean right now)
dnl -----------------------------------------------------------------------

AC_C_BIGENDIAN
AC_CHECK_SIZEOF(int, 4)

if test $ac_cv_sizeof_int -eq 8; then
	AC_DEFINE(USE_64BIT)
fi

if test "$ac_cv_c_bigendian" = "yes"; then
	AC_DEFINE(USE_BIG_ENDIAN)
fi

dnl ------------------------------------------------
dnl CL_EXPAND_DIR(VARNAME, DIR)
dnl ------------------------------------------------

dnl expands occurrences of ${prefix} and ${exec_prefix} in the given DIR,
dnl and assigns the resulting string to VARNAME
dnl example: CL_EXPAND_DIR(LOCALEDIR, "$datadir/locale")
dnl eg, then: AC_DEFINE_UNQUOTED(LOCALEDIR, "$LOCALEDIR")
dnl by Alexandre Oliva 
dnl from http://www.cygnus.com/ml/automake/1998-Aug/0040.html

define([CL_EXPAND_DIR],
[
	$1=$2
	$1=`(
		test "x$prefix" = xNONE && prefix="$ac_default_prefix"
		test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
		eval echo \""[$]$1"\"
	)`
])

CL_EXPAND_DIR(cl_scandir, "$libdir/ClanLib")
AC_DEFINE_UNQUOTED(CL_SCANDIR, "$cl_scandir")

dnl ------------------------------------------------
dnl BBN's macro for checking commandline parameters:
dnl ------------------------------------------------

dnl CHECK_ENABLED(feature,help,define,default)
define([CHECK_ENABLED],
[
  AC_ARG_ENABLE($1,[  $2],
  [
    if test "$enableval" != "no"; then
      $3="enabled"
      AC_DEFINE($3)
      AC_MSG_RESULT([enabled])
    else
      AC_MSG_RESULT([disabled])
    fi
  ],
  [
    if test "$4" = "enabled"; then
      $3="enabled"
      AC_DEFINE($3)
      AC_MSG_RESULT([enabled])
    else
      AC_MSG_RESULT([disabled])
    fi
  ])
])

dnl -----------------------------------------------------
dnl Check commandline parameters to the configure script:
dnl -----------------------------------------------------

AC_MSG_CHECKING(for X11 support)
CHECK_ENABLED(x11,
  [--enable-x11            Enable X11 support],
  USE_X11, $X11)

AC_MSG_CHECKING(for FBDev support)
CHECK_ENABLED(fbdev,
  [--enable-fbdev          Enable FBDev support],
  USE_FBDEV, $FBDEV)

AC_MSG_CHECKING(for GGI support)
CHECK_ENABLED(ggi,
  [--enable-ggi            Enable GGI support],
  USE_GGI, $GGI)

AC_MSG_CHECKING(for OpenGL support)
CHECK_ENABLED(opengl,
  [--enable-opengl            Enable OpenGL support],
  USE_OPENGL, $OPENGL)

AC_MSG_CHECKING(for svgalib support)
CHECK_ENABLED(svgalib,
  [--enable-svgalib        Enable svgalib support],
  USE_SVGALIB, $SVGALIB)

AC_MSG_CHECKING(for OpenPTC support)
CHECK_ENABLED(ptc,
  [--enable-ptc            Enable OpenPTC support],
  USE_PTC, $PTC)

AC_MSG_CHECKING(for VidMode support)
CHECK_ENABLED(vidmode,
  [--enable-vidmode           Enable VidMode support],
  USE_VIDMODE, $VIDMODE)

AC_MSG_CHECKING(for ClanSound support)
CHECK_ENABLED(clansound,
  [--enable-clansound      Enable ClanSound support],
  USE_CLANSOUND, enabled)

AC_MSG_CHECKING(for network support)
CHECK_ENABLED(network,
  [--enable-network        Enable network support],
  USE_NETWORK, enabled)

AC_MSG_CHECKING(for i386 assembly support)
CHECK_ENABLED(asm386,
  [--enable-asm386         Enable i386 assembly support],
  USE_I386, enabled)

AC_MSG_CHECKING(for dynamic loading support)
CHECK_ENABLED(dyn,
  [--enable-dyn            Enable dynamic loading],
  USE_DYN, enabled)

dnl ----------------------------------------------------
dnl Setup libs to be linked with the core library files.
dnl ----------------------------------------------------

libs="-ldl -lz -lHermes -lpthread"

objf_nondyn=""
flag_tty=""

if test "$USE_DYN" != "enabled"; then
	if test "$USE_VIDMODE" = "enabled"; then x_libraries="$x_libraries -lXxf86vm"; fi
	if test "$USE_X11" = "enabled"; then objf_nondyn="\$(OBJF_DISP_X11) $objf_nondyn"; libs="$x_libraries $libs"; fi
	if test "$USE_SVGALIB" = "enabled"; then flag_tty="yes"; objf_nondyn="\$(OBJF_DISP_SVGALIB) $objf_nondyn"; libs="-lvga $libs"; fi
	if test "$USE_OPENGL" = "enabled"; then objf_nondyn="\$(OBJF_DISP_GLX) $objf_nondyn"; libs="$x_libraries $libs -lGL -lGLU"; fi
	if test "$USE_FBDEV" = "enabled"; then flag_tty="yes"; objf_nondyn="\$(OBJF_DISP_FBDEV) $objf_nondyn"; fi
	if test "$USE_GGI" = "enabled"; then objf_nondyn="\$(OBJF_DISP_GGI) $objf_nondyn"; libs="-lggi $libs"; fi
	if test "$USE_PTC" = "enabled"; then objf_nondyn="\$(OBJF_DISP_PTC) $objf_nondyn"; libs="-lptc $libs"; fi
	if test "$USE_CLANSOUND" = "enabled"; then objf_nondyn="\$(OBJF_SOUND_CLANSOUND) $objf_nondyn"; fi
	if test "$USE_NETWORK" = "enabled"; then objf_nondyn="\$(OBJF_NETWORK_UNIX) $objf_nondyn"; fi
	if test "$flag_tty" = "yes"; then objf_nondyn="\$(OBJF_INPUT_TTY) $objf_nondyn"; fi
fi

x_libraries="$x_libraries -lXxf86vm"

AC_SUBST(x_includes)
AC_SUBST(x_libraries)
AC_SUBST(libs)
AC_SUBST(objf_nondyn)

dnl ---------------------------------------------------------------------
dnl Set which extra object files that should be used in case of assembly:
dnl ---------------------------------------------------------------------

generic_assembly=""

if test "$USE_I386" = "enabled"; then
  generic_assembly="$generic_assembly \$(OBJF_INTEL_ASM)"
fi
AC_SUBST(generic_assembly)

dnl --------------------
dnl Check for debug mode
dnl --------------------

AC_MSG_CHECKING(for debug mode)
AC_ARG_ENABLE(debug,[--enable-debug          Enable debugging support],
[

  if test "$enableval" != "no"; then
    comp_mode="-DDEBUG=1 -g"
    AC_MSG_RESULT([enabled])
  else
    comp_mode="-O3"
    AC_MSG_RESULT([*********** <-- DISABLED --> ***********])
  fi
],
[
  comp_mode="-O3"
  AC_MSG_RESULT([********** DISABLED FOR STABLE RELEASE VERSION **********])
])

AC_SUBST(comp_mode)

dnl ------------------------------------------
dnl Figure out which display targets to build:
dnl ------------------------------------------

display_targets=""
input_targets=""
flag_tty=""

if test "$USE_DYN" = "enabled"; then
  if test "$USE_X11" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-x11.so.\$(D_VERSION_MINOR)"
  fi

  if test "$USE_FBDEV" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-fbdev.so.\$(D_VERSION_MINOR)";
    flag_tty="yes";
  fi

  if test "$USE_GGI" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-ggi.so.\$(D_VERSION_MINOR)"
  fi

  if test "$USE_OPENGL" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-glx.so.\$(D_VERSION_MINOR)"
  fi

  if test "$USE_SVGALIB" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-svgalib.so.\$(D_VERSION_MINOR)";
    flag_tty="yes";
  fi

  if test "$USE_PTC" = "enabled"; then
    display_targets="$display_targets Libs/libclan-display-ptc.so.\$(D_VERSION_MINOR)"
  fi
  
  if test "$flag_tty"="yes"; then
    input_targets="Libs/libclan-input-tty.so.\$(D_VERSION_MINOR)"
  fi
fi

AC_SUBST(display_targets)
AC_SUBST(input_targets)

dnl ------------------------------------
dnl Check if the sound target is wanted:
dnl ------------------------------------

sound_targets=""

if test "$USE_DYN" = "enabled"; then
  if test "$USE_CLANSOUND" = "enabled"; then
    sound_targets="Libs/libclan-sound.so.\$(D_VERSION_MINOR)"
  fi
fi

AC_SUBST(sound_targets)

dnl --------------------------------------
dnl Check if the network target is wanted:
dnl --------------------------------------

network_targets=""

if test "$USE_DYN" = "enabled"; then
  if test "$USE_NETWORK" = "enabled"; then
    network_targets="Libs/libclan-network.so.\$(D_VERSION_MINOR)"
  fi
fi

AC_SUBST(network_targets)

dnl ---------------------------------
dnl Try to locate perl on the system:
dnl ---------------------------------

AC_MSG_CHECKING(for perl)
if test -x /bin/perl; then
	perl_exec="/bin/perl"
fi
if test -x /usr/bin/perl; then
	perl_exec="/usr/bin/perl"
fi
if test -x /usr/local/bin/perl; then
	perl_exec="/usr/local/bin/perl"
fi
if test "$perl_exec" = ""; then
	perl_exec="/usr/bin/perl"
	AC_MSG_RESULT("no - documentation cannot be compiled")
else
	AC_MSG_RESULT("found at $perl_exec")
fi
AC_SUBST(perl_exec)

dnl ----------------------------
dnl ClanLib version information:
dnl ----------------------------

version_major="0"
version_minor="0.4.4"
cl_version="0,4,4"

AC_SUBST(version_major)
AC_SUBST(version_minor)
AC_SUBST(cl_version)

dnl ---------------------
dnl Finish configuration:
dnl ---------------------

dnl Set installation prefix:
dnl AC_SUBST(prefix)

AC_OUTPUT(Makefile Makefile.conf Makefile.dep Documentation/perceps Documentation/Reference/Makefile clanlib-config)

dnl Set file permissions on perceps:
chmod a+x Documentation/perceps
chmod 755 clanlib-config

make dep > /dev/null 2>&1
