#! /bin/sh

# local options:  ac_help is the help message that describes them
# and LOCAL_AC_OPTIONS is the script that interprets them.  LOCAL_AC_OPTIONS
# is a script that's processed with eval, so you need to be very careful to
# make certain that what you quote is what you want to quote.

ac_help='--screen=WxH	how large should displayed images be? (640x480)
--thumb=WxH	how large should the thumbnails be? (128x128)
--icons=path	URL path where the icons can be found (/icons/)
--icondir=path	host path where the icons are to be installed (/usr/local/www/icons)
--nrcols=N	How many thumbnails per row (5)
--with-php	Build php image viewers'

argument() {
    expr "$1" : '^[^=]*=\(.*\)$'
}

LOCAL_AC_OPTIONS='
case X"$1" in
X--screen=*)
	    screen=`argument "$1"`
	    shift 1 ;;
X--screen)  screen=$2
	    shift 2 ;;
X--thumb=*) thumb=`argument "$1"`
	    shift 1 ;;
X--thumb)   thumb=$2
	    shift 2 ;;
X--icons=*) icons=`argument "$1"`
	    shift 1 ;;
X--icons)   icons=$2
	    shift 2 ;;
X--icondir=*) icondir=`argument "$1"`
	    shift 1 ;;
X--icondir) icondir=$2
	    shift 2 ;;
X--nr=*)    thumbsperrow=`argument "$1"`
	    shift 1 ;;
X--nr)	    thumbsperrow=$2
	    shift 2 ;;
*)	    ac_error=1
	    ;;
esac'

# load in the configuration file
#
screen=640x480
thumb=128x128
icons=/icons/
icondir=/usr/local/www/icons
thumbsperrow=5

. ./configure.inc


# and away we go
#
AC_INIT automat

MUST_HAVE() {
    if ! MF_PATH_INCLUDE $1 $1; then
	if [ "$2" ]; then
	    FMT=`acLookFor fmt`

	    TLOG '***'
	    if [ "$FMT" ]; then
		(   echo "$1 is required to build Automat;"
		    echo "you can get it from $2"
		    test "$3" && echo "in the file $3"
		) | $FMT -c | sed -e 's/^/*** /' 1>&5
	    else
		TLOG "*** $1 is required to build Automat; you can get it"
		if [ "$3" ]; then
		    TLOG "*** from $2 in the file $3"
		else
		    TLOG "*** from $2"
		fi
	    fi
	    TLOG '***'
	fi
	exit 1
    fi
}

VALID_NUMBER() {
    if ! expr "$1" : "[0-9][0-9]*" ; then
	TLOG "$2"
	exit 1
    fi
}

AC_PROG_SED

scr_w=`expr $screen : '^\(.*\)x.*$'`
scr_d=`expr $screen : '.*x\(.*\)$'`
thumb_w=`expr $thumb : '^\(.*\)x.*$'`
thumb_d=`expr $thumb : '.*x\(.*\)$'`

VALID_NUMBER $scr_w "screen image width is bogus"
AC_SUB SCR_W $scr_w
VALID_NUMBER $scr_d "screen image depth is bogus"
AC_SUB SCR_D $scr_d
VALID_NUMBER $thumb_w "thumbnail width is bogus"
AC_SUB THUMB_W $thumb_w
VALID_NUMBER $thumb_d "thumbnail depth is bogus"
AC_SUB THUMB_D $thumb_d
VALID_NUMBER $thumbsperrow "nrcols is bogus"
AC_SUB NRCOLS $thumbsperrow

if [ ! -d $icondir ]; then
    TLOG "icondir does not exist";
    exit 1
fi
AC_SUB ICONDIR $icondir
AC_SUB ICONS $icons
AC_SUB WITH_PHP "$WITH_PHP"

MUST_HAVE awk
MUST_HAVE cjpeg "ftp://ftp.uu.net/graphics/jpeg/" "jpegsrc.v6b.tar.gz"
MUST_HAVE djpeg "ftp://ftp.uu.net/graphics/jpeg/" "jpegsrc.v6b.tar.gz"
MUST_HAVE pnmscale "http://netpbm.sourceforge.net/"
MUST_HAVE pbmmake "http://netpbm.sourceforge.net/"
MUST_HAVE pnmcomp "http://netpbm.sourceforge.net/"
MUST_HAVE pngtopnm "http://netpbm.sourceforge.net/"


AC_OUTPUT mkindex.sh Makefile

