#!/bin/sh

# $Id: getPNMDirs,v 1.10 2014/02/21 11:48:58 svein Exp $

# Determine the pnm directory parameters

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

if [ -f $makefile ]
then
  pnm_inc_def=`egrep '^ *PNM_INC_DIR *= *' $makefile | awk '{print $3}'`
  pnm_lib_def=`egrep '^ *PNM_LIB_DIR *= *' $makefile | awk '{print $3}'`
  if [ -n "$pnm_inc_def" -a -n "$pnm_lib_def" ]; then
    pnm_install="y"
  fi
fi

if test "$pnm_install" = "n" -a \( -z "$PNM_INC_DIR" -o -z "$PNM_LIB_DIR" \)
then

cat <<EOF 1>&2

This software provides converters between the XITE image file
format and the pnm file formats (including pbm, pgm and ppm), supplied by
the free software packages pbmplus and netpbm.

If the pbm, pgm, ppm and pnm libraries are already installed on your
platform, you may want these converters installed also.

EOF
  echo "If you want the pnm 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 pnm and " 1>&2
  $echoNl "XITE? ([y]/n) " 1>&2

  read pnm_install

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

  if test "$pnm_install" = "y"
  then
    pnm_inc_def=/usr/include/netpbm

    if test "$XITE_HOSTTYPE" = "Linux_x86_64"
    then
        pnm_lib_def=/usr/lib64
    else
        pnm_lib_def=/usr/lib
    fi
  fi
elif test "$PNM_INC_DIR" = "-" -o "$PNM_LIB_DIR" = "-"
then
  pnm_install="n"
  pnm_inc_def=""
  pnm_lib_def=""
else
  pnm_install="y"
fi

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

if test "$pnm_install" = "y"
then
  PNM_INC_DIR=`$getDir "$PNM_INC_DIR" "$pnm_inc_def" 'pnm include directory' "$TMP_INSTALL" "stderr" $check`

  PNM_LIB_DIR=`$getDir "$PNM_LIB_DIR" "$pnm_lib_def" 'pnm library directory' "$TMP_INSTALL" "stderr" $check`
else
  PNM_INC_DIR="-"
  PNM_LIB_DIR="-"
  exceptionDirs="$exceptionDirs pnm"
fi

echo "PNM_INC_DIR=$PNM_INC_DIR; PNM_LIB_DIR=$PNM_LIB_DIR"
echo "pnm_install=$pnm_install; exceptionDirs='$exceptionDirs'"
echo "export PNM_INC_DIR PNM_LIB_DIR pnm_install exceptionDirs"
