dnl  Process this file with autoconf to produce a configure script.
dnl  Copyright (C) 1998 John Harper <john@dcs.warwick.ac.uk>
dnl  $Id: configure.in,v 1.104.2.1 2000/09/28 15:18:59 john Exp $
dnl
dnl  This file is part of sawmill.
dnl
dnl  sawmill is free software; you can redistribute it and/or modify it
dnl  under the terms of the GNU General Public License as published by
dnl  the Free Software Foundation; either version 2, or (at your option)
dnl  any later version.
dnl
dnl  sawmill is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl  GNU General Public License for more details.
dnl
dnl  You should have received a copy of the GNU General Public License
dnl  along with sawmill; see the file COPYING.  If not, write to
dnl  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

AC_REVISION($Revision: 1.104.2.1 $)

AC_INIT(src/sawmill.h)
AC_CONFIG_HEADER(config.h)
AC_CONFIG_AUX_DIR(etc)

dnl Release versioning info
version="0.31.1"

output_files="src/Makefile lisp/Makefile scripts/Makefile themes/Makefile\
 lisp/sawfish/ui/Makefile lisp/sawfish/gtk/Makefile sounds/Makefile\
 man/Makefile po/Makefile Makedefs Makefile sawfish.spec"

SUBDIRS="src lisp scripts themes sounds man po"
AC_SUBST(SUBDIRS)

add_subdir () {
  sub=$1; shift
  SUBDIRS="$SUBDIRS $sub"
  output_files="$output_files $sub/Makefile"
  for ext in $*; do
    output_files="$output_files $sub/$ext"
  done
  unset sub
}

dnl Find the system type
AC_CANONICAL_HOST

dnl Remove trailing slash in $prefix if necessary
case "${prefix}" in
  */)
    prefix=`echo ${prefix} | sed -e 's/^\(.*\)\/$/\1/'`
    ;;
esac

sawfishdir='${datadir}/sawfish'
lispdir='${sawfishdir}/${version}/lisp'
localedir='${sawfishdir}/${version}/locale'
sawfishexecdir='${libexecdir}/sawfish/${version}/${host_type}'

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_GCC_TRADITIONAL

dnl Workaround etc/install-sh not being found from subdirectories
if test "$INSTALL" = "$ac_install_sh"; then
  dnl Why is the backslash needed?
  INSTALL='\${top_srcdir}/etc/install-sh -c'
fi

dnl Checks for libraries.
AC_CHECK_LIB(nsl, xdr_void)
AC_CHECK_LIB(socket, bind)

dnl Checks for header files.
AC_PATH_XTRA
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h sys/time.h sys/utsname.h unistd.h memory.h X11/SM/SMlib.h X11/extensions/Xdbe.h)

XINERAMA_LIBS=""
AC_SUBST(XINERAMA_LIBS)
AC_CHECK_LIB(Xinerama, XineramaQueryScreens,
	     [XINERAMA_LIBS="-lXinerama"
	      AC_CHECK_HEADERS(X11/extensions/Xinerama.h)],
	     [],[$X_LIBS -lX11 -lXext])

dnl Check for librep
AM_PATH_REP(0.13)

rep_gtk_function=gtk-main-iteration-do
rep_gtk_version=0.14

AC_MSG_CHECKING([for correct rep-gtk version])
cat >conftest <<EOF
(condition-case nil
    (progn
      (require 'gui.gtk.gtk)
      $rep_gtk_function
      (throw 'quit 0))
  (error
    (throw 'quit 1)))
EOF
if REP_GTK_DONT_INITIALIZE=1 rep ./conftest 2>&5; then
  AC_MSG_RESULT([yes])
else
  AC_MSG_RESULT([no])
  AC_MSG_ERROR([You need rep-gtk version ${rep_gtk_version}+])
fi
rm -f conftest

dnl is X available?
if test "${no_x}" != "yes"; then
  AC_DEFINE(HAVE_X11)
else
  AC_MSG_ERROR([You need X11 for sawfish])
fi

dnl Check for image handling libraries
AC_ARG_WITH(gdk-pixbuf,
 [  --with-gdk-pixbuf	  Use gdk-pixbuf for image management
  --without-gdk-pixbuf	  Use Imlib1 instead], [],
 [with_gdk_pixbuf=no])
if test "$with_gdk_pixbuf" != "no"; then
  AC_MSG_CHECKING([for gdk_pixbuf (xlib version)])
  dnl gnome-config is the most broken shell script I've ever
  dnl encountered. It often returns true even if it can't
  dnl find the named module..!
  if gnome-config gdk_pixbuf_xlib --cflags >/dev/null 2>&1; then
    GDK_PIXBUF_VERSION=`gnome-config gdk_pixbuf_xlib --modversion`
    AC_MSG_RESULT($GDK_PIXBUF_VERSION)
    GDK_PIXBUF_CFLAGS=`gnome-config gdk_pixbuf_xlib --cflags`
    GDK_PIXBUF_LIBS=`gnome-config gdk_pixbuf_xlib --libs`
    AC_SUBST(GDK_PIXBUF_VERSION)
    AC_SUBST(GDK_PIXBUF_CFLAGS)
    AC_SUBST(GDK_PIXBUF_LIBS)
    AC_DEFINE(HAVE_GDK_PIXBUF,1)
    AC_DEFINE(NEED_PIXMAP_CACHE,1)
    IMAGE_LIBS='${GDK_PIXBUF_LIBS}'
    IMAGE_CFLAGS='${GDK_PIXBUF_CFLAGS}'
    with_gdk_pixbuf=yes
  else
    AC_MSG_RESULT(no)
    if test "$with_gdk_pixbuf" = "yes"; then
      AC_MSG_ERROR([can't locate gdk-pixbuf-xlib library])
    else
      with_gdk_pixbuf=no
    fi
  fi
fi
if test "$with_gdk_pixbuf" = "no"; then
  AM_PATH_IMLIB
  if $IMLIB_CONFIG --libs | grep " -lpng" >/dev/null 2>&1; then true; else
    AC_MSG_ERROR([imlib must be built with support for png images])
  fi
  AC_DEFINE(HAVE_IMLIB,1)
  IMAGE_LIBS='${IMLIB_LIBS}'
  IMAGE_CFLAGS='${IMLIB_CFLAGS}'
fi
AC_SUBST(IMAGE_LIBS)
AC_SUBST(IMAGE_CFLAGS)

AM_PATH_GTK(1.2.0)

AC_MSG_CHECKING([for audiofile library])
AC_ARG_WITH(audiofile,
 [  --with-audiofile	  Use libaudiofile for sound manipulation
  --without-audiofile], [], [with_audiofile=yes])
if test "$with_audiofile" = "yes"; then
  AUDIOFILE_VERSION="`audiofile-config --version`"
  if test $? -eq 0; then
    AUDIOFILE_LIBS="`audiofile-config --libs`"
    AUDIOFILE_CFLAGS="`audiofile-config --cflags`"
    AC_MSG_RESULT([$AUDIOFILE_VERSION])
    AC_SUBST(AUDIOFILE_LIBS)
    AC_SUBST(AUDIOFILE_CFLAGS)
    AC_DEFINE(HAVE_LIBAUDIOFILE)
  else
    AC_MSG_RESULT([no])
  fi
fi

AC_MSG_CHECKING([for enlightened sound daemon])
AC_ARG_WITH(esd,
 [  --with-esd		  Use the Enlightened Sound Daemon
  --without-esd], [], [with_esd=yes])
if test "$with_esd" = "yes"; then
  ESD_VERSION="`esd-config --version`"
  if test $? -eq 0; then
    ESD_LIBS="`esd-config --libs`"
    ESD_CFLAGS="`esd-config --cflags`"
    AC_MSG_RESULT([$ESD_VERSION])
    AC_SUBST(ESD_LIBS)
    AC_SUBST(ESD_CFLAGS)
    AC_DEFINE(HAVE_ESD)
  else
    AC_MSG_RESULT([no])
  fi
fi

AC_ARG_ENABLE(capplet,
 [  --enable-capplet	  Build the sawfish GNOME capplet [default]
  --disable-capplet	  Don't built the capplet], [],
 [enable_capplet=yes])

if test "$enable_capplet" = "yes"; then
  AC_MSG_CHECKING([for GNOME control center config])
  GNOME_CC_CFLAGS="`gnome-config --cflags capplet`"
  GNOME_CC_LIBS="`gnome-config --libs capplet`"
  if test $? -ne 0; then
    AC_MSG_RESULT([no])
    AC_MSG_WARN([Can't run "gnome-config capplet", not building capplet])
  else
    AC_MSG_RESULT([yes])
    AC_SUBST(GNOME_CC_CFLAGS)
    AC_SUBST(GNOME_CC_LIBS)
    add_subdir "capplet"
  fi
fi

AC_ARG_ENABLE(themer,
 [  --enable-themer	  Build the sawfish-themer program [default]
  --disable-themer	  Don't build the themer], [],
 [enable_themer=yes])

if test "$enable_themer" = yes; then
  dnl configure redirects &5 to config.log
  AC_MSG_CHECKING([for rep-gtk libglade wrapper])
  if REP_GTK_DONT_INITIALIZE=1 rep --batch -l libglade 2>&5; then 
    AC_MSG_RESULT([yes])
    add_subdir "themer"
  else 
    AC_MSG_RESULT([no])
    AC_MSG_WARN([Can't load rep's libglade wrapper, not building themer])
  fi
fi

AC_ARG_ENABLE(gnome-widgets,
 [  --enable-gnome-widgets  Use GNOME widgets in places [default]
  --disable-gnome-widgets Don't use GNOME widgets], [],
 [enable_gnome_widgets=maybe])

if test "$enable_gnome_widgets" != "no"; then
  AC_MSG_CHECKING([for rep-gtk GNOME wrappers])
  if REP_GTK_DONT_INITIALIZE=1 rep --batch -l gnomeui -l gdk-pixbuf -l gnome-canvas-pixbuf 2>&5; then 
    AC_MSG_RESULT([yes])
    REP_GTK_GNOME=yes
  else 
    AC_MSG_RESULT([no])
    REP_GTK_GNOME=no
    AC_MSG_WARN([Can't load rep's gnome wrappers])
  fi
else
  REP_GTK_GNOME=no
fi
AC_SUBST(REP_GTK_GNOME)

dnl Check for Doug Lea's malloc in libc, otherwise compile dlmalloc.c
doug_lea_malloc=yes
AC_CHECK_FUNC(malloc_get_state, , doug_lea_malloc=no)
AC_CHECK_FUNC(malloc_set_state, , doug_lea_malloc=no)
if test "$doug_lea_malloc" = "no"; then
  case ${host} in
    *-dec-osf*)
      dnl dlmalloc is broken on Tru64
      AC_DEFINE(LIBC_MALLOC)
      ;;
    *)
      LIBOBJS="${LIBOBJS} dlmalloc.o"
      AC_DEFINE(DOUG_LEA_MALLOC)
      ;;
  esac
else
  AC_DEFINE(DOUG_LEA_MALLOC)
  AC_DEFINE(LIBC_MALLOC)
fi

dnl Check for GNOME location
AC_ARG_WITH(gnome_prefix,
 [  --with-gnome-prefix=DIR Root of GNOME installation], [],
 [ with_gnome_prefix="" ])
AC_MSG_CHECKING([for GNOME prefix])
if test "x$with_gnome_prefix" = "x"; then
  with_gnome_prefix=`gnome-config --prefix 2>/dev/null`
  if test $? -ne 0; then
    with_gnome_prefix='${prefix}'
  fi
fi
AC_MSG_RESULT([$with_gnome_prefix])
GNOMEDIR=$with_gnome_prefix
AC_SUBST(GNOMEDIR)

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

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gethostname socket snprintf getpagesize)

dnl Custom tests

dnl How do we get dependency lines in the Makefile?
if test "x${GCC}" = "xyes"; then
  MAKEDEP='$(CC) -MM'
else
  case ${host} in
    *-dec-osf*)
      dnl works on Tru64
      MAKEDEP='$(CC) -M'
      ;;
    *-sun-solaris*)
      dnl works on Solaris
      MAKEDEP='/usr/lib/cpp -M'
      ;;
    *)
      dnl disable dependences?
      MAKEDEP='true'
      ;;
  esac
fi
AC_SUBST(MAKEDEP)

dnl If using GCC and it doesn't look as though the cflags have been
dnl set explicitly, add some warning options. Turn off implicit-int
dnl warnings since the X11 includes on Solaris generate a lot of these
if test "x${GCC}" = "xyes" -a "x$CFLAGS" = "x-g -O2"; then
  CFLAGS="${CFLAGS} -Wall -Wmissing-prototypes -Wno-implicit-int"
fi

AC_MSG_CHECKING(for languages to install)
AC_ARG_ENABLE(linguas,
  [  --enable-linguas=LANGS... Install language catalogs for language codes LANGS],
  [ LINGUAS="$enableval" ], [ LINGUAS="" ])
if test "x$LINGUAS" = x; then
  changequote({,})
  LINGUAS="`echo $srcdir/po/*.po | sed -e 's/[^ ]*\/po\/\([^ ]*\)\.po/\1/g'`"
  changequote([,])
fi
dnl too gross for words..
if test $REP_MSGFMT = true; then
  LINGUAS=""
fi
AC_MSG_RESULT($LINGUAS)
AC_SUBST(LINGUAS)

dnl Nonstandard exported symbols
AC_SUBST(version)
AC_SUBST(sawfishdir)
AC_SUBST(sawfishexecdir)
AC_SUBST(lispdir)
AC_SUBST(localedir)
AC_SUBST(HAVE_X11)
AC_SUBST(LIBOBJS)
AC_SUBST(CPPFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(LIBS)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)
AC_SUBST(X_EXTRA_LIBS)
AC_SUBST(IMLIB_CFLAGS)
AC_SUBST(IMLIB_LIBS)

dnl Build all files
AC_OUTPUT(${output_files})

dnl If it doesn't look like GNU Make is being used, give a friendly warning
tem=`make --version -f /dev/null 2>&1 | grep GNU`
if test "x$tem" = "x"; then
  AC_MSG_WARN([You need to use GNU Make when compiling sawfish])
fi

dnl Local variables:
dnl major-mode: sh-mode
dnl End:
