dnl $Id: $

dnl PURPOSE: configure clips package for unix systems.
dnl AUTHOR:  Javier Fernandez-Sanguino Pen~a <jfs@computer.org>


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

AC_REVISION($Revision: $)

AC_INIT(configure.in)

VERSION_MAJOR="6"
VERSION_MINOR="0"
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}"
AC_SUBST(VERSION_MAJOR)
AC_SUBST(VERSION_MINOR)
AC_SUBST(VERSION)

HAVE_GENERIC=0
HAVE_UNIX_V=0
HAVE_UNIX_7=0
WANT_EMACS_EDITOR=0
WANT_WINDOW_INTERFACE=0
AC_SUBST(HAVE_GENERIC)
AC_SUBST(HAVE_UNIX_V)
AC_SUBST(HAVE_UNIX_7)
AC_SUBST(WANT_EMACS_EDITOR)
AC_SUBST(WANT_WINDOW_INTERFACE)

dnl Create config files
AC_CONFIG_HEADER(clips_config.h)

dnl Checks for editor support (like emacs)
AC_ARG_ENABLE(emeditor,
[  --enable-emeditor       build internal (like emacs) editor])
if test "$enable_emeditor" = yes; then
   WANT_EMACS_EDITOR=1
   AC_CHECK_LIB(termcap, main)
fi

dnl Checks for X support (xclips)
AC_ARG_ENABLE(xclips,
[  --enable-xclips         build xclips instead clips])
if test "$enable_xclips" = yes; then
  WANT_WINDOW_INTERFACE=1
fi

dnl ----------------------------
dnl Checks for programs.
dnl

AC_PATH_PROGS(SH, sh)
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_LN_S
AC_PROG_INSTALL
AC_CHECK_PROGS(MKINSTALLDIRS,mkinstalldirs,no)
if test $MKINSTALLDIRS = no; then
  AC_MSG_WARN(You need 'mkinstalldirs' utility to build binary distributions.)
fi
AC_CHECK_PROG(HAVE_AUTOCONF, autoconf, yes)

dnl ----------------------------
dnl Checks for libraries.
dnl

AC_CHECK_LIB(m,main)

dnl This is a litle strange. It must place next line before call
dnl AC_PATH_X macro (AC_PATH_aunAC_PATH_os 5.5.1) ?;-\ to avoid further
dnl configure problems
AC_CHECK_HEADERS( stdio.h )

if (test "${WANT_WINDOW_INTERFACE}" = 1); then
  dnl Checks for X-files.
  AC_CHECK_LIB(socket,socket)
  AC_PATH_X
  AC_SUBST(x_libraries)
  LDFLAGS="$LDFLAGS -L$x_libraries"

  dnl WARNING: library search ORDER is very important !!!!

  AC_CHECK_LIB(X11,main,,,-L${x_libraries})
  AC_CHECK_LIB(Xext,main,,,-L${x_libraries})
  AC_CHECK_LIB(ICE,main,,,-L${x_libraries})
  AC_CHECK_LIB(SM,main,,,-L${x_libraries})
  AC_CHECK_LIB(Xt,main,,,-L${x_libraries})
  AC_CHECK_LIB(Xmu,main,,,-L${x_libraries})
  AC_CHECK_LIB(Xaw3d, main,,
       AC_CHECK_LIB(Xaw, main,,,
      -L${x_libraries}),
    -L${x_libraries})
fi

dnl ----------------------------
dnl Checks for header files.
dnl

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS( fcntl.h limits.h malloc.h sgtty.h strings.h )


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

dnl AC_TYPE_SIZE_T
AC_STRUCT_TM


dnl ----------------------------
dnl Checks for library functions.
dnl

AC_TYPE_SIGNAL
AC_CHECK_FUNCS(ftime getwd)


dnl ----------------------------
dnl Check for system characteristics.
dnl

AC_MSG_CHECKING([system version])
system=`uname -s`-`uname -r`
if test "$?" -ne 0 ; then
    AC_MSG_RESULT([unknown (can't find uname command)])
    system=unknown
else
    # Special check for weird MP-RAS system (uname returns weird
    # results, and the version is kept in special file).

    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
	system=MP-RAS-`awk '{print $3}' /etc/.relid'`
    fi
    if test "`uname -s`" = "AIX" ; then
	system=AIX-`uname -v`.`uname -r`
    fi
    AC_MSG_RESULT($system)
fi
case $system in
    BSD/OS-2.1*|BSD/OS-3*)
      HAVE_UNIX_V=1
      ;;
    HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
      HAVE_UNIX_V=1
      ;;
    Linux*)
      HAVE_UNIX_V=1
      ;;
    NetBSD-*|FreeBSD-*|OpenBSD-*)
      HAVE_UNIX_V=1
      ;;
    SunOS-4*)
      HAVE_UNIX_7=1
      AC_DEFINE(SOLARIS)
      ;;
    UNIX_SV*)
      HAVE_UNIX_V=1
      ;;
    *)
      HAVE_GENERIC=1
      ;;
esac

#
# Debido al uso indiscriminado de globales y su utilizaci�n como
# arrays en funciones como "getwd", el no forzar -fno-common
# es motivo de una gran inestabilidad, sobre todo en ciertas funciones
# definidas en "xmenu_file.c".
#

CFLAGS="$CFLAGS -fno-common"

dnl Checks for statically linked clips
AC_ARG_ENABLE(static-clips,
[  --enable-static-clips   build statically linked clips])
if test "$enable_static_clips" = yes; then
  WANT_STATIC_CLIPS=yes
  AC_SUBST(WANT_STATIC_CLIPS)
fi

dnl Checks for debug
AC_ARG_ENABLE(debug, 
[  --enable-debug          enable debugging ])
if test "$enable_debug" = yes; then
    AC_DEFINE(DEBUG)
    CFLAGS="$CFLAGS -g -Wall"
    CXXFLAGS="$CXXFLAGS -g -Wall"
    AC_CHECK_LIB(efence, malloc, LIBS="$LIBS -lefence")
fi

dnl Checks for no compiler optimization
AC_ARG_ENABLE(nooptimize,
[  --enable-nooptimize     enable don't optimize])
if test "$enable_nooptimize" = yes; then
   CFLAGS="$CFLAGS -O0"
   CXXFLAGS="$CXXFLAGS -O0"
fi

if test `expr "$CFLAGS" : ".*-g"` -eq 0  ; then
  CFLAGS="$CFLAGS -fomit-frame-pointer"
fi

AC_OUTPUT([
    Makefile
    setup.h],
  echo timestamp > .stamp-h.in)
