#!/bin/csh
#>
#> PACT-ANALYZE - analyze the current UNIX environment
#>
#> Generally used by the script pact-config (pact-make-configs).
#>
#> Usage: pact-analyze [-c] [-h] [-t]
#>
#> Options:
#>   -c     Check C Declarations
#>   -h     Help Package
#>   -t     Analyzing Programming Environment Characteristics for
#>          $HostName
#> WARNING: This analysis is partly based on your PATH and MANPATH.
#>          The analysis may not reflect the complete state of this system.
#>
#
# Shared library configuration contributed by
#           Matthias Klose <doko@cs.tu-berlin.de>
#
#-----------------------------------------------------------------------
#
# Source Version: 2.0
# Software Release #92-0043
#
# include "cpyright.h"
#

set help     = FALSE
set RealHome = `pwd`
set UserDir  = `pwd | sed "s|$RealHome|$home|"` 
set HelpCode = ./$0                      

set HostOS    = `uname -s`
set HostOSRel = `uname -r`
set HostName  = `uname -n`

if ($?USER == 0) then
   if ($?LOGNAME == 0) then
      set USER = "anonymous"
   else
      set USER = $LOGNAME
   endif
endif

set MajorVersion = `expr $HostOSRel : "\(.\)"`

set ToTTY  = FALSE

set ANSIHdrs  = ( "stdlib.h" "stddef.h" "stdarg.h" "limits.h" "errno.h" "float.h" )
set OtherHdrs = ( "alloc.h" "conio.h" "ctype.h" "errno.h" "malloc.h" )
set OtherHdrs = ( $OtherHdrs "math.h" "setjmp.h" "signal.h" "stdio.h" )
set OtherHdrs = ( $OtherHdrs "string.h" "time.h" "sys/types.h" "varargs.h" )

if ($?CCType) then
   if ("$HostOS" != "Windows_NT") then
      set CDecls = TRUE
   else
      set CDecls = FALSE
   endif
   set ANSI   = $CCType
   set MeOnly = FALSE
else
   set CDecls = FALSE
   set ANSI   = ANSI
   set MeOnly = TRUE
endif

if (!($?ParCommSupport)) then
   set ParCommSupport = "PARC"
endif

if (!($?CFLAGS)) then
   set CFLAGS = ""
endif

if (!($?CCmpLdr)) then
   set CCmpLdr = ""
endif

if (!($?FrontEnd)) then
   set FrontEnd = ""
endif

if (!($?BackEnd)) then
   set BackEnd = ""
endif

if (!($?UseX)) then
   set UseX = TRUE
endif

if ("$HostOS" == "IRIX") then

   if (!($?UseOGL)) then
      set UseOGL = TRUE
   endif

   if (!($?UseIGL)) then
      set UseIGL = TRUE
   endif

else

   if (!($?UseOGL)) then
      set UseOGL = FALSE
   endif

   if (!($?UseIGL)) then
      set UseIGL = FALSE
   endif

endif

while ($#argv > 0)
   switch ($1)
      case -c:
           set CDecls = TRUE
           shift
           set ANSI   = $1
           breaksw

      case -h:
           set help = "TRUE"

      case -t:
           set ToTTY = TRUE
           breaksw
   endsw
   shift
end

if ($help == "TRUE") then
   awk '($1 == "#>") {print}' $HelpCode  #Print Usage:
   exit(1)
endif

if ($ToTTY == TRUE) then

   echo ""
   echo "Analyzing Programming Environment Characteristics for $HostName"
   echo ""
   echo "WARNING: This analysis is partly based on your PATH and MANPATH."
   echo "         The analysis may not reflect the complete state of this system."
   echo ""

endif

#--------------------------------------------------------------------------

#                     CHARACTERIZE THE OPERATING SYSTEM

#--------------------------------------------------------------------------

echo -n "   Operating System: "

if (!($?OSType)) then
   if (("$HostOS" == "Windows_NT") || (("$HostOS" == "Linux") && (-e /usr/include/termio.h)) || (-e /usr/include/sys/termio.h)) then
      set OSType = "SYSV"
   else
      set OSType = "BSD"
   endif
endif

# there are systems that put out garbage if this is on a single echo (AIX)
echo -n `uname -s` `uname -r`
echo " ($OSType)"

#--------------------------------------------------------------------------

#                    FIND AND CHARACTERIZE THE C COMPILER

#--------------------------------------------------------------------------

echo -n "   C Compiler: "

rm -f tmp.c
touch tmp.c

echo "#include <stdio.h>" >> tmp.c
echo "main()" >> tmp.c
echo "{" >> tmp.c
echo "#ifdef __STDC__" >> tmp.c
echo 'printf("ANSI");' >> tmp.c
echo "#else" >> tmp.c
echo 'printf("PCC");' >> tmp.c
echo "#endif" >> tmp.c
echo "return(0);}" >> tmp.c

set CC = ""
set CList = ""
set CCompilerList = (cc gcc xlc c89 pgcc icc sicc)

if ($?CCompiler) then
   set SaveCCompiler = $CCompiler
endif
if ($CCmpLdr != "") then
   set CCompiler = $CCmpLdr
endif
set SaveCFLAGS = ($CFLAGS)
if ($?MachDepInc) then
   if ($MachDepInc != "") then
      set CFLAGS = ($CFLAGS -I$MachDepInc)
   endif
endif
if ($?LDFLAGS) then
   set CFLAGS = ($CFLAGS $LDFLAGS)
endif
if ($?MachDepLib) then
   set CFLAGS = ($CFLAGS $MachDepLib)
endif

if ($?CCompiler) then
   foreach i ($CCompilerList)
      if ($CCompiler == $i) then
         set CCompilerFlag =
      endif
   end
   if (!($?CCompilerFlag)) then
      set CCompilerList = ($CCompilerList $CCompiler)
   endif
endif

if ($?SaveCCompiler) then
   foreach i ($CCompilerList)
      if ($SaveCCompiler == $i) then
         set SaveCCompilerFlag =
      endif
   end
   if (!($?SaveCCompilerFlag)) then
      set CCompilerList = ($CCompilerList $SaveCCompiler)
   endif
endif

foreach i ($CCompilerList)
   set res = `./pwhich $i`
   if (`expr $res[1] : "/."` >= 1) then
      $i $CFLAGS tmp.c -o tmp >& /dev/null
      $FrontEnd ./tmp $BackEnd >& /dev/null
      if ($status == 0) then
         set CList = ($CList $i)
         set ret = `$FrontEnd ./tmp $BackEnd`
         if (("$ret" == "ANSI") || ("$ret" == "PCC")) then
            set CC = ($CC $i"("$ret")")
         endif
      endif
   endif
end

if ("$CList" == "") then
   echo " none"
endif
set CC1 = $CList[1]

if ($?CCompiler) then
   unset CCompilerFlag
   foreach i ($CList)
      if ($CCompiler == $i) then
         set CCompilerFlag =
      endif
   end
   if (!($?CCompilerFlag)) then
# Compiler requested in configuration file not found or no good
      set CCompiler = ""
   endif
else
   set CCompiler = ""
endif

if ($CCompiler == "") then
   set CCompiler = $CC1
endif

if ($CCompiler != "") then
   $CCompiler $CFLAGS tmp.c -o tmp >& /dev/null
   set CCType = `$FrontEnd ./tmp $BackEnd`
   set ANSI   = $CCType

   rm -f tmp.c

# determine whether a FORTRAN integer can hold a pointer

   touch tmp.c

   echo "#include <stdio.h>" >> tmp.c
   echo "main()" >> tmp.c
   echo "{" >> tmp.c
   echo "if (sizeof(int) != sizeof(char *))" >> tmp.c
   echo 'printf("F77_INT_SIZE_PTR_DIFFER");' >> tmp.c
   echo "return(0);}" >> tmp.c

   $CCompiler $CFLAGS tmp.c -o tmp >& /dev/null
   set F77IntPtrDiffer = `$FrontEnd ./tmp $BackEnd`

   rm -f tmp.c

# determine if long is 64 bits

   touch tmp.c

   echo "#include <stdio.h>" >> tmp.c
   echo "main()" >> tmp.c
   echo "{" >> tmp.c
   echo "if (sizeof(long) == 8)" >> tmp.c
   echo 'printf("LONG64");' >> tmp.c
   echo "return(0);}" >> tmp.c

   $CCompiler $CFLAGS tmp.c -o tmp >& /dev/null
   set LONG64 = `$FrontEnd ./tmp $BackEnd`

   rm -f tmp.c tmp tmp.o

   echo $CC

   if ("$F77IntPtrDiffer" != "") then
      echo "         NOTE: Pointer size differs from F77 INTEGER size"
   endif

endif
#--------------------------------------------------------------------------

#                      CHECK C DECLARATIONS

#--------------------------------------------------------------------------

if ($CDecls == TRUE) then

   echo "   C Header Files"

   rm -f tmp
   touch tmp

   echo "#\!/bin/csh -f" >> tmp
   echo "" >> tmp

   echo 'set nlines = `cat $1 | wc -l`' >> tmp
   echo 'set iline  = 0' >> tmp
   echo 'set ANSI   = $2' >> tmp
   echo 'rm -f _tmp_' >> tmp
   echo "" >> tmp

   echo 'if (-e file.cd) then' >> tmp
   echo '   set OutDev = file.cd' >> tmp
   echo 'else' >> tmp
   echo '   if ($?prompt) then' >> tmp
   echo '      set OutDev = /dev/tty' >> tmp
   echo '   else' >> tmp
   echo '      set OutDev = _tmp_' >> tmp
   echo '      touch $OutDev' >> tmp
   echo '   endif' >> tmp
   echo 'endif' >> tmp
   echo "" >> tmp

   echo 'set noglob' >> tmp
   echo 'while (`expr $iline \< $nlines`)' >> tmp
   echo '   set iline = `expr $iline + 1`' >> tmp
   echo '   set Line  = `echo $<`' >> tmp
   echo '   if ($#Line > 3) then' >> tmp
   echo '      set Func  = $Line[1]' >> tmp
   echo '      set Decl  = "$Line[3-4]"' >> tmp
   echo '      if ($#Line > 4) then' >> tmp
   echo '         set Args  = "$Line[5-]"' >> tmp
   echo '      else' >> tmp
   echo '         set Args  = "Variable"' >> tmp
   echo '      endif' >> tmp
   echo "      set Pattn = '[^a-zA-Z0-9_]'"'$Func'"'[^a-zA-Z0-9_]'" >> tmp
   echo "" >> tmp
   echo '      unset noglob' >> tmp

   if ("$ANSI" == "ANSI") then
      echo '      set Hdrs = (' "$ANSIHdrs" "$OtherHdrs" ')' >> tmp
   else
      echo '      set Hdrs = (' "$OtherHdrs" ')' >> tmp
   endif

   echo '      set GotIt = FALSE' >> tmp
   echo '      foreach file ($Hdrs)' >> tmp
   echo '         if (-e "/usr/include/$file") then' >> tmp
   echo '            egrep "$Pattn" /usr/include/$file >>& /dev/null' >> tmp
   echo '            if ($status == 0) then' >> tmp
   echo '               set GotIt = TRUE' >> tmp
   echo '               break' >> tmp
   echo '            endif' >> tmp
   echo '         endif' >> tmp
   echo '      end' >> tmp
   echo '      if ($GotIt == FALSE) then' >> tmp
   echo '         if ("$Args" == "Variable") then' >> tmp
   echo '            echo "extern $Decl;" >>& $OutDev' >> tmp
   echo '         else if ($ANSI == ANSI) then' >> tmp
   echo '            echo "extern $Decl$Args;" >>& $OutDev' >> tmp
   echo '         else ' >> tmp
   echo '            echo "extern $Decl();" >>& $OutDev' >> tmp
   echo '         endif' >> tmp
   echo '      endif' >> tmp

   echo '      set noglob' >> tmp
   echo '   endif' >> tmp
   echo 'end' >> tmp

   echo 'if (-e _tmp_) then' >> tmp
   echo '   cat _tmp_' >> tmp
   echo '   rm -f _tmp_' >> tmp
   echo 'endif' >> tmp
   echo 'unset noglob' >> tmp
   echo "" >> tmp

   echo 'exit($status)' >> tmp
   echo "" >> tmp

   chmod a+x tmp
   cat clib.fncs | tmp clib.fncs $ANSI

   rm -f tmp

   if ($MeOnly == TRUE) then
      goto done
   endif

endif

#--------------------------------------------------------------------------

#                           CHARACTERIZE CSH

#--------------------------------------------------------------------------

echo "   System CSH"

if (!($?BackSlash)) then
   set BackSlash = "\\"
endif

rm -f tmp
echo $BackSlash > tmp
if (`cat tmp` == "$BackSlash") then
   set BackSlash = "\"
endif

rm -f tmp

#--------------------------------------------------------------------------

#                      FIND AND CHARACTERIZE MAKE

#--------------------------------------------------------------------------

echo -n "   System MAKE: "

rm -f tmp.c tmp.a tmp.make

touch tmp.make
echo '.c.a :' >> tmp.make
echo '	ar r tmp.a $<' >> tmp.make
echo "" >> tmp.make
echo 'tmp.a : tmp.a(tmp.o)' >> tmp.make
echo "" >> tmp.make

touch tmp.c
make -f tmp.make tmp.a >>& /dev/null
if (($status != 0) || !(-e tmp.a)) then
   set BuildStrategy = "none"
   echo "Minimal"
else
   set BuildStrategy = "SpaceSaving"
   echo "Library aware"
endif

rm -f tmp.c tmp.a tmp.make

#--------------------------------------------------------------------------

#                            SYSTEM UTILITIES

#--------------------------------------------------------------------------

echo -n "   System Utilities: "

rm -f foo.c foo.o bar.c bar.o main.c libfoo.a tmp load

# this script is necessary because some idiot ld writers insist
# that error messages be printed directly to /dev/tty in addition to
# stdout or stderr
echo "#\!/bin/csh -f" > load
echo 'rm -f tmp.err' >> load
echo "$CCompiler $CFLAGS" 'main.c -o tmp $1 >& tmp.err' >> load
echo 'grep -i "$1" tmp.err' >> load
echo 'set Value = $status' >> load
echo 'rm -f tmp.err' >> load
echo 'exit($Value)' >> load
chmod a+x load

if ($CC1 != "") then

# build something to stick in an archive
   echo "extern int bar();" > foo.c
   echo "foo(x){return(bar(x));}" >> foo.c
   $CC1 -c foo.c >>& /dev/null

   echo "bar(x){return(x);}" > bar.c
   $CC1 -c bar.c >>& /dev/null

# build a main to load with
   echo "extern int foo();" > main.c
   echo "main(){return(foo(0));}" >> main.c

# get the AR options sorted out if they were not pre-defined
   if (!($?ArcInstOpt)) then
      foreach i (rsc rc)
         set ArcInstOpt = $i
         ar $ArcInstOpt libfoo.a bar.o foo.o >& /dev/null
         if ($status == 0) then
            break
         endif
      end
   endif

# figure out what to do about RANLIB
   foreach i (touch ranlib)

      rm -f libfoo.a
      ar $ArcInstOpt libfoo.a bar.o foo.o

      $i libfoo.a >>& /dev/null
      if ($status != 0) then
         continue
      endif

      load libfoo.a >>& /dev/null
      if ($status == 0) then
         continue
      endif

      $FrontEnd tmp $BackEnd
      if ($status != 0) then
         continue
      endif

      set RANLIB = "$i"
      break

   end

   set Util  = "No ranlib, "
   if ($RANLIB == ranlib) then
      ranlib -t libfoo.a
      if ($status == 0) then
         set UPDATE = "ranlib -t"
      else
         set UPDATE = "ranlib"
      endif
      set Util  = "Uses ranlib, "
   else
      set UPDATE = $RANLIB
   endif

   echo -n "$Util "

endif

rm -f foo.c foo.o bar.c bar.o main.c libfoo.a tmp load

#
# let's understand install on this system
# but let's not use it
#
   set res = `./pwhich install`
   if (`expr $res[1] : "/."` >= 1) then
      set MINSTALL = "install"
      echo -n " Has install"
   else if (-e /etc/install) then
      set MINSTALL = "install"
      echo -n " Has install"
   else   
      set MINSTALL = "cp"
      echo -n " No install"
   endif

echo ""

#--------------------------------------------------------------------------

#                        FIGURE OUT THE I/O HANDLING

#--------------------------------------------------------------------------

echo -n "   I/O Options: "

set IOHandling = ""

foreach i ("select" "poll")
   rm -f tmp.res
   man $i >& tmp.res

# AIX grep says: "No match found in database for foo"
# UNIX grep says: "No manual entry for foo"
# ULTRIX says: grep exits with 0 if it doesn't crash outright (can't use $status)

   set res = `head tmp.res | grep -i "no ma"`
   if ("$res" == "") then
      set IOHandling = ($IOHandling $i)
      switch ($i)
         case poll:
              ls /usr/include/stropts.h >>& /dev/null
              if ($status == 0) then
                 if ($?HAVE_SELECT_P) then
                    if ($HAVE_SELECT_P == FALSE) then
                       set HAVE_STREAMS_P = Envir
                    endif
                 else
                    set HAVE_STREAMS_P = Envir
                 endif
                 echo -n "poll "
              endif
              breaksw
         case select:
              set HAVE_SELECT_P = Envir
              echo -n "select "
      endsw
   endif
   rm -f tmp.res
end
echo ""

#--------------------------------------------------------------------------

#                 FIGURE OUT THE PARALLEL COMMUNICATION LIBRARIES

#--------------------------------------------------------------------------

echo -n "   Parallel Communication Support: "

if (!($?MachDepInc)) then
   set MachDepInc = ""
endif
set ParComm = ""
foreach i ("mpi" "mpsc" "lmps")
   foreach j ("/usr/include" $MachDepInc)
      if ((-e "$j/$i/$i.h") || (-e "$j/$i.h")) then
         set ParComm = ( $i $ParComm )
         if ("$ParCommSupport" == "") then
            set ParCommSupport = `echo $i | tr "[a-z]" "[A-Z]"`
         endif
      endif
   end
end
if ("$ParComm" != "") then
   echo $ParComm
else
   echo "none"
endif

rm -f tmp.res

#--------------------------------------------------------------------------

#                        FIGURE OUT THE MATH LIBRARIES

#--------------------------------------------------------------------------

echo -n "   System Math Libraries: "

set MathLib = ""
foreach i ("foo" "blas" "linpack" "slatec" "imsl" "mathlib")
   rm -f tmp.res
   (man $i | head) >& tmp.res

# AIX grep says: "No match found in database for foo"
# UNIX grep says: "No manual entry for foo"
# ULTRIX says: grep exits with 0 if it doesn't crash outright (can't use $status)

   set res = `grep -i "no ma" tmp.res`
   if ("$res" == "") then
      set MathLib = ($MathLib $i)
   endif
end
if ("$MathLib" != "") then
   echo $MathLib
else
   echo "none"
endif

rm -f tmp.res

#--------------------------------------------------------------------------

#                      SEARCH OUT GRAPHICS INFO

#--------------------------------------------------------------------------

echo -n "   System Graphics Options: "

if (!($?JPEGlibloc)) then
   set JPEGlibloc = ""
endif

if (!($?MachDepGraphicsLib)) then
   set MachDepGraphicsLib = ""
endif

if (!($?MachDepGraphicsInc)) then
   set MachDepGraphicsInc = ""
endif

if (!($?GraphicsDevices)) then
   set GraphicsDevices = ""
endif

if (!($?GraphicsFlag)) then
   set GraphicsFlag = ""
endif

if ("$HostOS" == "IRIX") then
   if ($UseIGL == TRUE) then
      if ($MajorVersion == "4") then
         if (-e /usr/lib/libgl_s.a) then
            set GraphicsDevices = ( $GraphicsDevices "IGL" )
            set GraphicsFlag = ( $GraphicsFlag "-DIGL" )
            set MachDepGraphicsLib = ( $MachDepGraphicsLib -lgl_s )
            echo -n "IrisGL "
         endif
      else
         if (-e /usr/lib/libgl.so) then
            set GraphicsDevices = ( $GraphicsDevices "IGL" )
            set GraphicsFlag = ( $GraphicsFlag "-DIGL" )
            set MachDepGraphicsLib = ( $MachDepGraphicsLib -lgl )
            echo -n "IrisGL "
         endif
      endif
   endif
   if ($UseOGL == TRUE) then
      if (-e /usr/lib/libGL.so) then
         set GraphicsDevices = ( $GraphicsDevices "OGL" )
         set GraphicsFlag = ( $GraphicsFlag "-DOGL" )
         set MachDepGraphicsLib = ( $MachDepGraphicsLib -lGL -lX11)
         echo -n "OpenGL "
      endif
   endif
endif

if ($UseX == TRUE) then
   foreach i ("/usr/lib" "/lib" "/usr/local/lib" "/usr/openwin/lib")
      if (`expr "$MachDepGraphicsLib" : '.*X11.*'` == 0) then
         if (-e $i/libX11.a) then
            set MachDepGraphicsLib = ( $MachDepGraphicsLib $i/libX11.a )
         else if (-e $i/libX11.so) then
            set MachDepGraphicsLib = ( $MachDepGraphicsLib -lX11 )
         endif
      endif
   end
   if (`expr "$MachDepGraphicsLib" : '.*X11.*'` == 0) then
      (find /usr/lib -name "libX11.a" -print >! tmp) >& /dev/null
      set MachDepGraphicsLib = ( $MachDepGraphicsLib `cat tmp` )
   endif
   
# NOTE: some sites have two places (e.g. X11R4 and X11R5) and this causes problems
   if (`expr "$MachDepGraphicsLib" : '.*X11.*'` == 0) then
      (find /usr/local -name "libX11.a" -print >! tmp) >& /dev/null
      set MachDepGraphicsLib = ( $MachDepGraphicsLib `cat tmp` )
   endif
   if (`expr "$MachDepGraphicsLib" : '.*X11.*'` == 0) then
      echo -n "none"
   else
      echo -n "X11 "
   endif
   
   if ("$MachDepGraphicsInc" == "") then
      foreach i ("/usr/include" "/usr/local/include" "/usr/openwin/include")
         if ("$MachDepGraphicsInc" == "") then
            if (-e $i/X11/Xlib.h) then
               set MachDepGraphicsInc = "-I$i"
            endif
         endif
      end
      if ("$MachDepGraphicsInc" == "") then
 	 (find /usr/include -name "Xlib.h" -print >! tmp) >& /dev/null
         set tmp = `cat tmp`
         if ($#tmp > 1) then
            set tmp = $tmp[1]:h
         else
            set tmp = $tmp:h
         endif
         set MachDepGraphicsInc = "-I$tmp:h"
      endif
      if (("$MachDepGraphicsInc" == "") && (-d /usr/local/include)) then
 	 (find /usr/local/include -name "Xlib.h" -print >! tmp) >& /dev/null
         set tmp = `cat tmp`
         if ($#tmp > 1) then
            set tmp = $tmp[1]:h
         else
            set tmp = $tmp:h
         endif
         set MachDepGraphicsInc = "-I$tmp:h"
      endif
   endif
   rm -f tmp
endif

echo ""

if (($UseX == "TRUE") && (`expr "$MachDepGraphicsLib" : '.*X11.*'` != 0) && ("$MachDepGraphicsInc" != "")) then
   set GSYS = "X"
   set GraphicsFlag = ( $GraphicsFlag "-DX11" )
   set GraphicsDevices = ( $GraphicsDevices "X" )
   set HAVE_SOCKETS_P = Envir
   set LPath = `expr "$MachDepGraphicsLib" : '\(/.*\)/libX11.a'`
   if ($LPath == "") then
      set LPath = "$MachDepGraphicsLib"
   endif
   set IPath = `expr "$MachDepGraphicsInc" : '-I\(.*\)'`
   echo "      X Windows Library Path: $LPath"
   echo "      X Windows Include Path: $IPath"
else if ($UseOGL == "TRUE") then
   set GSYS = "OGL"
else if ($UseIGL == "TRUE") then
   set GSYS = "IGL"
else
   set GSYS   = ""
   set UseX   = FALSE
   set UseOGL = FALSE
   set UseIGL = FALSE
endif

#--------------------------------------------------------------------------

# JPEG library

#--------------------------------------------------------------------------

echo "   Checking for jpeg library"

set jpeglib = FALSE
set jpeginc = FALSE
set HAVE_JPEGLIB = ""
set GraphicsDevices = ( $GraphicsDevices "JPG" )

if ("$JPEGlibloc" != "") then
   if ("$JPEGlibloc" != "none") then
      set jpeglib = TRUE
   endif
else
   foreach i ("/usr/local/apps/lib" "/usr/local/lib" "/usr/lib" "/lib")
      if (-d $i) then
         if (-e $i/libjpeg.a) then
            set jpeglib = TRUE
            set JPEGlibloc = $i
            break
         endif
      endif
   end
endif

if ($jpeglib == TRUE) then

   if ("$MachDepGraphicsInc" == "-I/usr/include") then
      set MachDepGraphicsInc = ""
   endif

   foreach i ("/usr/local/apps/include" "/usr/local/include" "/usr/include")
      if (-d $i) then
         if (-e $i/jpeglib.h && -e $i/jconfig.h && -e $i/jmorecfg.h &&\
             -e $i/jerror.h) then
            set jpeginc = TRUE
            if ("$i" != "/usr/include") then
               set MachDepGraphicsInc = ( $MachDepGraphicsInc -I$i )
            endif
            break            
         endif
      endif
   end 
endif


if ($jpeglib == TRUE && $jpeginc == TRUE) then
   echo "      JPEG library and headers found - JPEG device will be built"
   set MachDepGraphicsLib = ( $MachDepGraphicsLib $JPEGlibloc/libjpeg.a )
   set HAVE_JPEGLIB = TRUE
else
   echo "      JPEG library not found - no JPEG device will be built"
endif

#--------------------------------------------------------------------------

#                            INSTALLATION DIRECTORIES

#--------------------------------------------------------------------------

if ($?InstBase) then
   if (($InstBase != "none") && \
       (!(-e $InstBase/bin) || \
        !(-e $InstBase/lib) || \
        !(-e $InstBase/include) || \
        !(-e $InstBase/$ScmDir))) then

      echo ""
      echo "WARNING:"
      if (!(-e $InstBase/bin)) then
         echo "   $InstBase/bin does NOT exist"
      endif
      if (!(-e $InstBase/lib)) then
         echo "   $InstBase/lib does NOT exist"
      endif
      if (!(-e $InstBase/include)) then
         echo "   $InstBase/include does NOT exist"
      endif
      if (!(-e $InstBase/$ScmDir)) then
         echo "   $InstBase/$ScmDir does NOT exist"
      endif

      echo ""
      echo 'You will not be able to install PACT properly unless you create'
      echo 'all of the missing directories. You may change the InstBase variable'
      echo 'in your configuration file, or specify another base directory with'
      echo 'the -i option to PACT-CONFIG. Use a value of "none" if you wish'
      echo 'to build but not install PACT.'
      echo ""
   endif
endif

#--------------------------------------------------------------------------

#                            PRINT RESULTS

#--------------------------------------------------------------------------

if ($ToTTY != TRUE) then

# MAKE Variables

   if ("$MachDepInc" == "/usr/include") then
      set MachDepInc = ""
   endif

   if ("$MachDepGraphicsInc" == "-I/usr/include") then
      set MachDepGraphicsInc = ""
   endif

endif

echo ""

done:

if ($?SaveCCompiler) then
   set CCompiler = $SaveCCompiler
endif
set CFLAGS = ($SaveCFLAGS)

exit($status)
