#!/bin/sh
#
# Configure Script for WebMagick
# Copyright Bob Friesenhahn, 1997,1999
# 
# $Id: configure.in,v 1.24 2001/08/21 17:48:56 clindell Exp $
#
dnl Process this file with autoconf to produce a configure script.
AC_INIT(webmagick.in)
AM_INIT_AUTOMAKE(WebMagick,2.02, ' ')

# Ensure that make can run correctly
AM_SANITY_CHECK

# Checks for programs.
AC_PROG_INSTALL
AC_PATH_PROG(PERL, perl, /usr/local/bin/perl )

#
# Find the X11 RGB database
#
if test "$with_x" != 'no'
then
  AC_CACHE_CHECK(for RGB database,webmagick_cv_x_rgbdb,
  [# Look for the header file in a standard set of common directories.
   # Check X11 before X11Rn because it is often a symlink to the current
   # release.
   for ac_dir in               \
    /lib/usr/lib/X11	  \
    /usr/X11/lib          \
    /usr/X11R4/lib        \
    /usr/X11R5/lib        \
    /usr/X11R6/lib        \
    /usr/X386/lib         \
    /usr/XFree86/lib/X11  \
    /usr/athena/lib       \
    /usr/lib              \
    /usr/lib/X11          \
    /usr/lib/X11R4        \
    /usr/lib/X11R5        \
    /usr/lib/X11R6        \
    /usr/local/X11/lib    \
    /usr/local/X11R4/lib  \
    /usr/local/X11R5/lib  \
    /usr/local/X11R6/lib  \
    /usr/local/lib        \
    /usr/local/lib/X11    \
    /usr/local/lib/X11R4  \
    /usr/local/lib/X11R5  \
    /usr/local/lib/X11R6  \
    /usr/local/x11r5/lib  \
    /usr/lpp/Xamples/lib  \
    /usr/openwin/lib      \
    /usr/openwin/share/lib \
    /usr/unsupported/lib  \
    /usr/x386/lib         \
    ; \
   do
    if test -f "$ac_dir/X11/rgb.txt"
    then
        webmagick_cv_x_rgbdb="$ac_dir/X11/rgb.txt"
	break
    elif test -f "$ac_dir/rgb.txt"
    then 
        webmagick_cv_x_rgbdb="$ac_dir/rgb.txt"
        break
    fi

   done])
else
  webmagick_cv_x_rgbdb='/dev/null'
fi

RGBDB=$webmagick_cv_x_rgbdb
AC_SUBST(RGBDB)

#
# Check for available fonts
#
if test "$with_x" != 'no'
then
  AC_PATH_PROG(XLSFONTS, xlsfonts, xlsfonts )
  if test "${XLSFONTS}X" != "X"
  then
    AC_CACHE_CHECK(for default font, webmagick_cv_defaultfont,
    [
    font1=''
    font2=''
    font3=''
    font4=''
    font5='fixed'
    tmpfile="/tmp/configure$$"
    $XLSFONTS > $tmpfile
    exec < $tmpfile
    while read font
    do
      case "$font"
      in
      -*-lucida-medium-r-*-*-12-*-*-*-*-*-*-* )
	  font1='-*-lucida-medium-r-*-*-12-*-*-*-*-*-*-*'
	  ;;
      -*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-* )
	  font2='-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*'
	  ;;
      -*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-* )
	  font3='-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*'
	  ;;
       -*-courier-medium-r-normal--12-*-*-*-*-*-*-* )
	  font4='-*-courier-medium-r-normal--12-*-*-*-*-*-*-*'
	  ;;
       -*-times-medium-r-normal--12-*-*-*-*-*-*-* )
	  font5='-*-times-medium-r-normal--12-*-*-*-*-*-*-*'
	  ;;
      esac
    done

    exec < /dev/tty
    rm $tmpfile
  fi

  if test -n "$font1"
  then
    webmagick_cv_defaultfont=$font1
  elif test -n "$font2"
  then
    webmagick_cv_defaultfont=$font2
  elif test -n "$font3"
  then
    webmagick_cv_defaultfont=$font3
  elif test -n "$font4"
  then
    webmagick_cv_defaultfont=$font4
  elif test -n "$font5"
  then
    webmagick_cv_defaultfont=$font5
  else
    webmagick_cv_defaultfont='fixed'
  fi

  ])
else
  webmagick_cv_defaultfont='courier';
fi

DEFAULTFONT=$webmagick_cv_defaultfont
AC_SUBST(DEFAULTFONT)

#
# Check for server root path
#
AC_MSG_CHECKING(for server root path)
AC_CACHE_VAL(webmagick_cv_rootpath,
[
echo '

In order to map paths into URLs, WebMagick must know the path to your
servers HTML files. For example, if your servers address is
"http://yourdomain/" and this URL resolves to "/usr/local/share/htdocs"
on the system, then the appropriate answer is "/usr/local/share/htdocs".

What is the path to your servers root? '
read webmagick_cv_rootpath
])
if test -d "$webmagick_cv_rootpath"
then
   AC_MSG_RESULT($webmagick_cv_rootpath)
else
   AC_MSG_RESULT($webmagick_cv_rootpath)
   AC_MSG_WARN(directory $webmagick_cv_rootpath does not exist!)
fi
ROOTPATH=$webmagick_cv_rootpath
AC_SUBST(ROOTPATH)

#
# Check for WebMagick icon path
#
AC_MSG_CHECKING(for WebMagick icon path)
AC_CACHE_VAL(webmagick_cv_iconpath,
[
echo '

In order to find its navigation icons, WebMagick must know the
remaining path (in addition to the servers root path) to the WebMagick
icons. This should not contain any preceding or trailing "/". For
example, if the server root path is "/usr/local/share/htdocs" and the icons
are located in "/usr/local/share/htdocs/Images/webmagick" the appropriate
answer would be "Images/webmagick".

What is the remaining path to the WebMagick icons? '
read webmagick_cv_iconpath
echo ''
])
if test -d "$webmagick_cv_rootpath/$webmagick_cv_iconpath"
then
   AC_MSG_RESULT($webmagick_cv_rootpath/$webmagick_cv_iconpath)
else
   AC_MSG_RESULT($webmagick_cv_rootpath/$webmagick_cv_iconpath)
   AC_MSG_WARN(directory $webmagick_cv_rootpath/$webmagick_cv_iconpath does not exist!)
fi
ICONPATH=$webmagick_cv_iconpath
AC_SUBST(ICONPATH)

#
# Check for URL prefix
#
AC_MSG_CHECKING(for URL prefix)
AC_CACHE_VAL(webmagick_cv_prefixpath,
[
echo '

Sometimes the URL to the top of the HTML files is an offset past
the servers root. This is common for personal home directories
which are addressed as "http://yourdomain/~username" in which case
the appropriate answer would be "~username".

What prefix URL is required (if any)? '
read webmagick_cv_prefixpath
])
if test -z "$webmagick_cv_prefixpath"
then
   AC_MSG_RESULT(none)
else
   AC_MSG_RESULT($webmagick_cv_prefixpath)
fi
PREFIXPATH=$webmagick_cv_prefixpath
AC_SUBST(PREFIXPATH)

#
# Check for imagemap program path
#
AC_MSG_CHECKING(for imagemap program)
AC_CACHE_VAL(webmagick_cv_htimage,
[
echo '

This question concerns how your server handles server-side
imagemap processing. Recent servers provide built in support for
imagemaps. These include recent versions of NCSA, Apache, phttpd,
and others. Older servers may require an external CGI program to
handle imagemaps. CERN servers often name this program "htimage".
NCSA names this program "imagemap". WebMagick requires the relative
URL to this program if your server requires it. Typical answers
will be "/cgi-bin/htimage" or "/cgi-bin/imagemap". If your server
does not require an external program, just hit RETURN.

What is the URL to the program you use to handle imagemaps (if any)?'
read webmagick_cv_htimage
echo ''
])
if test -z "$webmagick_cv_htimage"
then
   AC_MSG_RESULT(none)
else
   AC_MSG_RESULT($webmagick_cv_htimage)
fi
HTIMAGE=$webmagick_cv_htimage
AC_SUBST(HTIMAGE)

#
# Check for server-side imagemap format
#
AC_MSG_CHECKING(for server-side imagemap format)
AC_CACHE_VAL(webmagick_cv_maptype,
[
echo '

There are two formats for imagemap files in common use, CERN and
NCSA.  NCSA & Apache use the NCSA format.  CERN uses the CERN format.
Phttpd can handle either format.  Appropriate answers to this question
are "cern" or "ncsa".

What format ("cern" or "ncsa") does your server use for imagemaps?'
read webmagick_cv_maptype
dnl Lower case string
webmagick_cv_maptype=`echo $webmagick_cv_maptype | tr '[A-Z]' '[a-z]'`
])

AC_MSG_RESULT($webmagick_cv_maptype)
MAPTYPE=$webmagick_cv_maptype
AC_SUBST(MAPTYPE)

AC_OUTPUT(Makefile doc/Makefile doc/fig/Makefile icons/Makefile utils/Makefile \
webmagick webmagickrc )
chmod 555 webmagick
