#!/bin/sh

# $Id: getPNGDirs,v 1.4 2007/09/12 08:40:37 svein Exp $

# Determine the PNG directory parameters

png_install="n"
makefile=$XITE_HOME/etc/Makefile.$XITE_HOSTTYPE

if [ -f $makefile ]
then
  png_inc_def=`egrep '^ *PNG_INC_DIR *= *' $makefile | awk '{print $3}'`
  png_lib_def=`egrep '^ *PNG_LIB_DIR *= *' $makefile | awk '{print $3}'`
  if [ -n "$png_inc_def" -a -n "$png_lib_def" ]; then
    png_install="y"
  fi
fi

if test "$png_install" = "n" -a \( -z "$PNG_INC_DIR" -o -z "$PNG_LIB_DIR" \)
then

cat <<EOF 1>&2

This software provides converters between the XITE BIFF image file
format and the PNG file format, supplied by the libpng library.

If libpng library is already installed on your platform, you may want these
converters installed also.

EOF
  echo "If you want the png converters, you will need to specify where" 1>&2
  echo "the libraries and include files are located." 1>&2
  $echoNl "Would you like to install the converters between png and " 1>&2
  $echoNl "XITE? ([y]/n) " 1>&2

  read png_install

  if test -z "$png_install" -o "$png_install" = "yes" \
	  -o "$png_install" = "y"
  then
    png_install="y"
  else
    png_install="n"
  fi

  if test "$png_install" = "y"
  then
    png_inc_def=/usr/include

    if test "$XITE_HOSTTYPE" = "Linux_x86_64"
    then
        png_lib_def=/usr/lib64
    else
        png_lib_def=/usr/lib
    fi
  fi
elif test "$PNG_INC_DIR" = "-" -o "$PNG_LIB_DIR" = "-"
then
  png_install="n"
  png_inc_def=""
  png_lib_def=""
else
  png_install="y"
fi

check=1
[ "$XITE_HOSTTYPE" = "Win32" ] && check=0

if test "$png_install" = "y"
then
  PNG_INC_DIR=`$getDir "$PNG_INC_DIR" "$png_inc_def" 'png include directory' "$TMP_INSTALL" "stderr" $check`

  PNG_LIB_DIR=`$getDir "$PNG_LIB_DIR" "$png_lib_def" 'png library directory' "$TMP_INSTALL" "stderr" $check`
else
  PNG_INC_DIR="-"
  PNG_LIB_DIR="-"
  exceptionDirs="$exceptionDirs png"
fi

echo "PNG_INC_DIR=$PNG_INC_DIR; PNG_LIB_DIR=$PNG_LIB_DIR"
echo "png_install=$png_install; exceptionDirs='$exceptionDirs'"
echo "export PNG_INC_DIR PNG_LIB_DIR png_install exceptionDirs"
