#! /bin/sh
#
# A (not so) simple configure script.
#
# Authors: Christian Holm Christensen and Fons Rademakers
#
# To help with debugging the script, some comments are preprended with
# 3 '#' echo and 3 '%' - replace that pattern with echo and 3 '%' to
# get printouts.  When done replace the pattern echo and 3 '%' with the
# original pattern of 3 '#' echo and 3 '%'.  Emacs command M-C-% does
# this easily.
#
######################################################################
#
### echo %%% Some global variables
#
found_lib=no
found_dir=no
found_hdr=no
show_pkglist=no
noact="no"

options="                 \
   enable_afs             \
   enable_alien           \
   enable_asimage         \
   enable_cern            \
   enable_chirp           \
   enable_dcache          \
   enable_exceptions      \
   enable_explicitlink    \
   enable_globus          \
   enable_krb5            \
   enable_ldap            \
   enable_mysql           \
   enable_opengl          \
   enable_openiv          \
   enable_pgsql           \
   enable_pythia          \
   enable_pythia6         \
   enable_qt              \
   enable_rfio            \
   enable_rpath           \
   enable_sapdb           \
   enable_shadowpw        \
   enable_shared          \
   enable_soversion       \
   enable_srp             \
   enable_table           \
   enable_thread          \
   enable_venus           \
"

#
# This sets all options to "yes" - we turn off those we don't want
# on per default explictly afterwards.
#
for c in $options ; do eval $c="yes" ; done

enable_afs=no
enable_explicitlink=no
enable_rpath=no
enable_shadowpw=
enable_soversion=no
enable_table=no
enable_thread=           # must be set explicitely via --enable-thread

#
# ./configure arguments and defaults set via supported env vars
#
envvars="
THREAD           \
OPENGL           \
IVROOT           \
MYSQL            \
PGSQL            \
QTDIR            \
SAPDB            \
RFIO             \
CERNLIB          \
PYTHIA           \
PYTHIA6          \
VENUS            \
DCACHE           \
CHIRP            \
ALIEN            \
ASIMAGE          \
LDAP             \
GLOBUS_LOCATION  \
SRP              \
AFS              \
TABLE            \
"
configenvvars=
for c in $envvars ; do
   cc=`eval echo "$"$c`
   if test ! "x$cc" = "x" ; then
      if test ! "x$configenvvars" = "x" ; then
         configenvvars="$configenvvars $c=$cc"
      else
         configenvvars="$c=$cc"
      fi
   fi
done

configargs="$*"

configoptions=
if test ! "x$configenvvars" = "x" ; then
   configoptions=$configenvvars
fi
if test ! "x$configargs" = "x" ; then
   if test ! "x$configoptions" = "x" ; then
      configoptions="$configoptions $configargs"
   else
      configoptions=$configargs
   fi
fi

######################################################################
#
### echo %%% Some common functions
#
#_____________________________________________________________________
message() {
    # Write a simple message to std out
    if test $# -lt 1 ; then
	echo "message: Too few arguments"
	return 1
    fi
    echo $ac_n "$* ... $ac_c"
}

#_____________________________________________________________________
checking_msg() {
    # Write a simple "checking" message to std out.
    if test $# -lt 1 ; then
	echo "checking_msg: Too few arguments"
	return 1
    fi
    echo $ac_n "Checking for$ac_c"
    while test $# -gt 1  ; do
	echo $ac_n " $1,$ac_c"
	shift
	if test $# -eq 1 ; then
	    echo $ac_n " or$ac_c"
	fi
    done
    echo $ac_n " $1 ... $ac_c"
}

#_____________________________________________________________________
check_library() {
    # This function will try to locate a library [$1] in the specific
    # directory [$3] or in a default path [$*].  If the second argument
    # [$2] is not "no", then shared libraries are favoured.
    # The result of the search is stored in found_lib and found_dir,
    # which should be immediately copied, since the variables value will
    # be overwritten at next invocation of this function.

    # Assert that we got enough arguments
    if test $# -lt 4 ; then
	echo "check_library: Too few arguments"
	return 1
    fi

    # Save arguments in local names
    lib=$1       ; shift
    shared=$1    ; shift
    libdirl=$1   ; shift
    libdirs="$*"

    # Write a message
    checking_msg $lib

    # check if we got a specific argument as to where the library
    # is to be found
    if test ! "x$libdirl" = "x" ; then
        libdirs=$libdirl
    fi
    found_lib=no
    found_dir=no

    # Make list of libraries to search for. The .lib extension is for
    # Windoze - note $shared is always "no" on windoze, since we need
    # the .lib export library to link.
    libs=""
    for i in $lib ; do
	for ext in .a .lib ; do
	    libs="$libs $i$ext"
	done
    done
    slibs=""
    for i in $lib ; do
        for ext in .so .sl .dylib .dll.a ; do      # .dll.a for cygwin gcc
            slibs="$slibs $i$ext"
        done
    done
    if test ! "x$shared" = "xno" ; then
	libs="$slibs $libs"
    else
        libs="$libs $slibs"
    fi

    # Loop over the list of possible directories, and see if we can
    # find any of the library files as determind above.
    for i in $libdirs ; do
        # look first in the lib32 directories
        if test "x$checklib32" = "xyes" ; then
            i32=`echo $i | sed 's|lib*|lib32|'`
            i="$i32 $i"
        fi
        # look first in the lib64 directories
        if test "x$checklib64" = "xyes" ; then
            i64=`echo $i | sed 's|lib*|lib64|'`
            i="$i64 $i"
        fi
        for l in $i ; do
            for j in ${libs} ; do
	        # if we found the file (it's readable by user), we set the
	        # logical variables and are on our way, otherwise we continue
                liblist=`echo $l/$j`    # expands wildcard in $l/$j
                for n in ${liblist} ; do
                    if test -r $n ; then
                        found_dir=$l
                        found_lib=$j
                        break 4
                    fi
                done
            done
        done
    done

    # skip cygwin libraries when in pure Win32 mode
    if test "x$platform" = "xwin32"; then
        case $found_dir in
           /lib|/usr/*) found_dir="no" ;;
        esac
    fi

    echo $found_dir
    unset libs
    unset slibs
    unset libdirs

    if test "x$found_dir" = "xno" || test "$found_lib" = "xno" ; then
	found_dir=""
	found_lib=""
    else
	flib=""
	for i in $lib ; do
	    for ext in .a .lib ; do
		if test "x$found_lib" = "x$i$ext" ; then
		    flib=$i$ext
		fi
	    done
	done
	if test "x$found_lib" = "x$flib" ; then
	    found_lib=${found_dir}/${found_lib}
	    found_dir=""
	else
	    found_lib=`echo $found_lib | sed 's|^lib\(.*\)\..*|-l\1|'`
	    found_dir=-L${found_dir}
            # Avoid inclusion of /usr/lib, which is always included anyway
            if test "x$found_dir" = "x-L/usr/lib"   || \
               test "x$found_dir" = "x-L/usr/lib32" || \
               test "x$found_dir" = "x-L/usr/lib64" ; then
		found_dir=""
	    fi
	fi

        # Correct path for win32
        if test "x$platform" = "xwin32"; then
            if test ! "x$found_lib" = "x" ; then
                found_lib=`cygpath -m $found_lib`
            fi
            if test ! "x$found_dir" = "x" ; then
               found_dir=`cygpath -m $found_dir`
            fi
        fi
    fi
    unset shared
    unset lib
    unset flib
    unset libdirl
}

#_____________________________________________________________________
check_header()  {
    # This function will try to locate a header [$1] in the specific
    # directory [$2] or in a default path [$*].
    # The result of the search is stored in found_hdr and found_dir,
    # which should be immediately copied, since the variables value will
    # be overwritten at next invocation of this function.

    # Assert that we got enough arguments
    if test $# -lt 3 ; then
	echo "check_header: Too few arguments"
	return 1
    fi

    # Save arguments in logical names
    hdrs=$1     ; shift
    hdrdir=$1   ; shift
    hdrdirs="$*"

    # Write a message
    checking_msg $hdrs

    # Check if we got a specific argument as to where the library
    # is to be found
    if test ! "x$hdrdir" = "x" ; then
        hdrdirs=$hdrdir
    fi
    found_hdr=no
    found_dir=no

    # Loop over the list of possible directories, and see if we can
    # find any of the library files as determind above.

    for i in $hdrdirs; do
        for j in ${hdrs} ; do
	    # if we found the file (it's readable by user), we set the
	    # logical variables and are on our way, otherwise we continue
            if test -r $i/$j ; then
                found_dir=$i
                found_hdr=$j
                break 2
            fi
        done
    done

    # skip cygwin headers when in pure Win32 mode
    if test "x$platform" = "xwin32"; then
        case $found_dir in
           /usr/*) found_dir="no" ;;
        esac
    fi

    echo $found_dir

    if test "x$found_hdr" = "xno" || test "$found_dir" = "xno" ; then
	found_hdr=""
	found_dir=""
    fi

    # Avoid inclusion of /usr/include, which is always included anyway
    if test "x$found_dir" = "x/usr/include" ; then
	found_dir="include"
    fi

    # Correct path for win32
    if test "x$platform" = "xwin32"; then
        if test ! "x$found_hdr" = "x" ; then
           found_hdr=`cygpath -m $found_hdr`
        fi
        if test ! "x$found_dir" = "x" ; then
           found_dir=`cygpath -m $found_dir`
        fi
    fi

    unset hdrs
    unset hdrdirs
    unset hdrdir
}

#_____________________________________________________________________
check_symbol() {
    # This function will try to locate a symbol [$1] in a specific
    # library [$2] and in a given directory [$3].
    # The result of the check is stored in found_symbol, 1 if true,
    # 0 otherwise, which should be immediately copied, since the variable
    # will be overwritten at next invocation of this function.

    # Assert that we got enough arguments
    if test $# -ne 3 ; then
	echo "check_symbol: Not 3 arguments"
	return 1
    fi

    # Save arguments in logical names
    symbol=$1     ; shift
    symbollib=$1  ; shift
    symboldir=$1

    # Check if we got a specific argument as to where the library
    # is to be found
    symbolfile=$symbollib
    if test ! "x$symboldir" = "x" ; then
        symbolfile=$symboldir/$symbollib
        if test ! -r $symbolfile ; then
            for i in .a .so .lib ; do
                if test -r $symbolfile$i ; then
                    symbolfile=$symbolfile$i
                    break
                fi
             done
        fi
    fi

    if test "x$symbolfile" = "x" || test ! -r $symbolfile ; then
       found_symbol=0
       return 1
    fi

    symbol_in_lib=`nm $symbolfile | grep $symbol > /dev/null 2>&1`
    if test $? -eq 0 ; then
        found_symbol=1
    else
        found_symbol=0
    fi
}

#_____________________________________________________________________
guess_architecture () {
    # Try to guess the architecture of the host system
    # Note, that there's no attempt at guessing the compiler.
    # The `native' compiler is used in all cases.
    # If a user really want a specifific compiler, s/he better use the
    # first argument to do so.
    arch=`uname -s | tr '[A-Z]' '[a-z]'`
    chip=`uname -m | tr '[A-Z]' '[a-z]'`
    rele=`uname -r`
    case "$arch:$chip:$rele" in
        aix*)                  arch=aix5            ;;
        osf1*:alpha:*)         arch=alphacxx6       ;;
        freebsd*:*:4*)         arch=freebsd4        ;;
        freebsd*:*:*)          arch=freebsd         ;;
        hp-ux:ia64:*)          arch=hpuxia64acc     ;;
        hp-ux:*:*)             arch=hpuxacc         ;;
        hurd*:*:*)             arch=hurddeb         ;;
        linux:ia64:*)          arch=linuxia64gcc    ;;
        linux:x86_64:*)        arch=linuxx8664gcc   ;;
        linux:alpha:*)         arch=linuxalphaegcs  ;;
        linux:arm*:*)          arch=linuxarm        ;;
        linux:ppc*:*)          arch=linuxppcegcs    ;;
        linux:i*86:*)          arch=linux           ;;
        lynx:*:*)              arch=lynxos          ;;
        darwin:power*:*)       arch=macosx          ;;
        irix*:sgi*:*)          arch=sgicc           ;;
        sunos:sun*:6*)         arch=solarisCC5      ;;
        sunos:sun*:5*)         arch=solarisCC5      ;;
        sunos:sun*:4*)         arch=solaris         ;;
        cygwin_*:*86:*)        arch=win32gdk        ;;
        cygwin_*:pentium:*)    arch=win32gdk        ;;
        cygwin_*:ia64)         arch=win32gdk        ;;
        *)
            echo "Attempts at guessing your architecture failed."
            echo "Please specify the architecture as the first argument."
            echo "Do '$0 --help' for a list of avaliable architectures."
            exit 1
            ;;
   esac
}

###################################################################
#
### echo %%% Some skeleton and config files
#
ARCHS=config/ARCHS
MAKEIN=config/Makefile.in
MAKEOUT=config/Makefile.config
CONFIN=config/config.in
CONFOUT=include/config.h
RCONFIN=config/root-config.in
RCONFOUT=bin/root-config
ROOTRCIN=config/rootrc.in
ROOTRCOUT=etc/system.rootrc
ROOTAUTHRCIN=config/rootauthrc.in
ROOTAUTHRCOUT=etc/system.rootauthrc
ROOTDAEMONRCIN=config/rootdaemonrc.in
ROOTDAEMONRCOUT=etc/system.rootdaemonrc
MEMPROBEIN=config/memprobe.in
MEMPROBEOUT=bin/memprobe
MIMEUNIXIN=config/mimes.unix.in
MIMEWIN32IN=config/mimes.win32.in
MIMEOUT=etc/root.mimes


######################################################################
#
### echo %%% Testing the echo features
#
if  `(echo "testing\c"; echo 1,2,3) | grep c > /dev/null` ; then
  if `(echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn > /dev/null`; then
    ac_n= ac_c='
' ac_t='	'
  else
    ac_n=-n ac_c= ac_t=
  fi
else
  ac_n= ac_c='\c' ac_t=
fi


######################################################################
#
### echo %%% Help function
#
confhelp() {
vers=`cat build/version_number`
cat <<EOF
\`configure' configures ROOT $vers to adapt to many kind of systems.

Usage:     $0 [architecture] [flag=value]

The architecture to build for will be guessed from the output of 'uname'.
If, however, that fails, or you don't want the 'native' compiler on the
host platform, you can specify the architecture to use by passing as the
FIRST argument one of the architecures given at the end of this message.

   FLAG            DESCRIPTION               DEFAULT
   --aclocaldir    Autoconf macro install dir(<prefix>/share/aclocal)
   --bindir        Binary installation dir   (<prefix>/bin)
   --build         Build configuration [debug, exceptions, ...],
                   overrides the ROOTBUILD shell variable
   --cintincdir    CINT interpeted headers   (<libdir>/cint)
   --datadir       Data installation dir     (<prefix>/share/root)
   --docdir        Documentation             (<prefix>/share/doc/root)
   --elispdir      Where to put Emacs Lisp   (<prefix>/share/emacs/site-lisp)
   --etcdir        Config installation dir   (/etc/root)
   --fontdir       Font installation dir     (<datadir>/fonts)
   --iconpath      Icon installation dir     (<datadir>/icons)
   --incdir        Header installation dir   (<prefix>/include/root)
   --libdir        Library installation dir  (<prefix>/lib/root)
   --macrodir      Macro installation dir    (<datadir>/macros)
   --mandir        Manpages installation dir (<prefix>/share/man/man1)
   --no-create     Do not create output files, dry run
   --prefix        Installation prefix       (/usr/local)
   --proofdir      PROOF utils dir           (<datadir>/proof)
   --srcdir        Sources installation dir  (<datadir>/src)
   --testdir       Tests                     (<docdir>/test)
   --tutdir        Tutorials                 (<docdir>/tutorial)

If any of the flags --cintincdir, --datadir, --docdir, --etcdir, --iconpath
--incdir, --libdir, --macrodir, --mandir, --prefix, or --proofdir is given,
ROOT will be compiled with static directory names, and you should not set
the ROOTSYS environment variable.

enable/disable options, prefix with either --enable- or --disable-
   afs             AFS support, requires AFS libs and objects
   alien           AliEn support, requires libAliEnAPI++ from ALICE
   asimage         Image processing support, requires libAfterImage
   cern            CERNLIB usage, build h2root and g2root
   chirp           Chirp support (Condor remote I/O), requires libchirp_client
   dcache          dCache support, requires libdcap from DESY
   exceptions      Turn on compiler exception handling capability
   explicitlink    Explicitly link with all dependent libraries
   globus          Globus authentication support, requires Globus toolkit
   krb5            Kerberos5 support, requires Kerberos libs
   ldap            LDAP support, requires (Open)LDAP libs
   mysql           MySQL support, requires libmysqlclient
   opengl          OpenGL support, requires libGL and libGLU
   openiv          OpenInventor support, requires libInventor and libInventorXt
   pgsql           PostgreSQL support, requires libpq
   pythia          Pythia5 EG support, requires libPythia
   pythia6         Pythia6 EG support, requires libPythia6
   rfio            SHIFT support, requires libshift from CERN
   rpath           Set run-time library load path on executables
   sapdb           SapDB support, requires libsqlod and libsqlrte
   shadowpw        Shadow password support
   shared          Use shared 3rd party libraries if possible
   soversion       Set version number in sonames (recommended)
   srp             SRP support, requires SRP source tree
   table           Build libTable contrib library
   thread          Thread support (currently only POSIX threads)
   venus           Venus EG support, requires libVenus

with options, prefix with --with-, enables corresponding support

   afs             AFS support, location of AFS distribution
   alien-incdir    AliEn support, location of AliEnAPI++.h
   alien-libdir    AliEn support, location of libAliEnAPI++
   cern-libdir     HBOOK converter, location of CERNLIB libraries
   chirp-incdir    Chirp support, location of chirp_client.h
   chirp-libdir    Chirp support, location of libchirp_client
   dcap-incdir     dCache support, location of dcap.h
   dcap-libdir     dCache support, location of libdcap
   krb5            Kerberos5 support, location of Kerberos distribution
   krb5-incdir     Kerberos5 support, location of krb5.h
   krb5-libdir     Kerberos5 support, location of libkrb5
   globus          Globus support, path to what should be GLOBUS_LOCATION
   globus-patch    Globus support, source dir for patch to versions 2.2.x (experimental, see README.GLOBUS)
   ldap-incdir     LDAP support, location of ldap.h
   ldap-libdir     LDAP support, location of libldap
   mysql-incdir    MySQL support, location of mysql.h
   mysql-libdir    MySQL support, location of libmysqlclient
   opengl-incdir   OpenGL support, location of GL/gl.h
   opengl-libdir   OpenGL support, location of libGL
   openiv-incdir   OpenInventor support, location of Inventor/SoType.h
   openiv-libdir   OpenInventor support, location of libInventor
   pgsql-incdir    PostgreSQL support, location of libpq-fe.h
   pgsql-libdir    PostgreSQL support, location of libpq
   pythia-libdir   PYHTIA support, location of libPythia
   pythia6-libdir  PYHTIA6 support, location of libPythia6
   sapdb-incdir    SapDB support, location of sql.h
   sapdb-libdir    SapDB support, location of libsqlod
   shift-incdir    RFIO support, location of rfio_api.h
   shift-libdir    RFIO support, location of libshift
   srp             Secure Remote Passwd support, location of SRP distribution
   srp-incdir      SRP support, location header of t_server.h
   srp-libdir      SRP support, location header of libsrp.a
   sys-iconpath    Extra icon path
   thread-libdir   Thread support, path to libpthread
   venus-libdir    VENUS support, location of libVenus
   x11-libdir      X11 support, path to libX11
   xpm-libdir      XPM support, path to libXpm

Supported Architectures:

EOF
   cat config/ARCHS | sed -e 's/^/   /'
cat <<EOF

Help output is rather long, so you may want to pipe it through a pager, like
for example

  $0 --help | more

Report bugs to <rootdev@root.cern.ch>
EOF
}

######################################################################
#
### echo %%% See if we got the architecture
#
if test $# -lt 1 ; then
   guess_architecture
else
   case $1 in
      -h|--help) confhelp ; exit 0 ;;
      -*) # in case the first argument wasn't an architecure but an option
          guess_architecture
          ;;
       *)
          arch=$1
          shift
          ;;
   esac
fi

# check that we got a valid architecture
if test "$arch" = "linuxegcs" ; then
    arch="linux"
fi

if `awk '{ print $1 }' $ARCHS | grep "^$arch$" > /dev/null  2>&1` ; then
   echo "Configuring for $arch"
else
   echo "Invalid architecture. Try $0 --help"
   exit 1
fi

if test "x$arch" = "xwin32" || test "x$arch" = "xwin32gdk" ; then
   platform="win32"
else
   platform=$arch
fi
if test "x$arch" = "xsgicc" ; then
   checklib32="yes"
fi
if test "x$arch" = "xlinuxx8664gcc" || test "x$arch" = "xsgicc64" ; then
   checklib64="yes"
fi

######################################################################
#
### echo %%% Some clean up
#
trap "rm -f Makefile.tmp config.tmp root-config.tmp rootrc.tmp \
      rootauthrc.tmp rootdaemonrc.tmp memprobe.tmp; exit 1" 1 2 3 15

######################################################################
#
### echo %%% Command line arguments
#
if test $# -gt 0 ; then
   while test ! "x$1" = "x" ; do
      case "$1" in
      -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
      *) optarg= ;;
      esac

      case $1 in
      --help|-h) confhelp ;   exit 0 ;;
      ################################################################
      #
      # With options to specifiy third part software
      #
      --no-create)             noact="yes"           ;;
      --with-afs=*)            afsdir=$optarg        ; enable_afs="yes"     ;;
      --with-alien-incdir=*)   alienincdir=$optarg   ; enable_alien="yes"   ;;
      --with-alien-libdir=*)   alienlibdir=$optarg   ; enable_alien="yes"   ;;
      --with-cern-libdir=*)    cernlibdir=$optarg    ; enable_cern="yes"    ;;
      --with-chirp-incdir=*)   chirpincdir=$optarg   ; enable_chirp="yes"   ;;
      --with-chirp-libdir=*)   chirplibdir=$optarg   ; enable_chirp="yes"   ;;
      --with-dcap-incdir=*)    dcapincdir=$optarg    ; enable_dcache="yes"  ;;
      --with-dcap-libdir=*)    dcaplibdir=$optarg    ; enable_dcache="yes"  ;;
      --with-globus=*)         globusdir=$optarg     ; enable_globus="yes"  ;;
      --with-krb5=*)           krb5dir=$optarg       ; enable_krb5="yes"    ;;
      --with-krb5-incdir=*)    krb5incdir=$optarg    ; enable_krb5="yes"    ;;
      --with-krb5-libdir=*)    krb5libdir=$optarg    ; enable_krb5="yes"    ;;
      --with-ldap-incdir=*)    ldapincdir=$optarg    ; enable_ldap="yes"    ;;
      --with-ldap-libdir=*)    ldaplibdir=$optarg    ; enable_ldap="yes"    ;;
      --with-mysql-incdir=*)   mysqlincdir=$optarg   ; enable_mysql="yes"   ;;
      --with-mysql-libdir=*)   mysqllibdir=$optarg   ; enable_mysql="yes"   ;;
      --with-opengl-incdir=*)  openglincdir=$optarg  ; enable_opengl="yes"  ;;
      --with-opengl-libdir=*)  opengllibdir=$optarg  ; enable_opengl="yes"  ;;
      --with-openiv-incdir=*)  openivincdir=$optarg  ; enable_openiv="yes"  ;;
      --with-openiv-libdir=*)  openivlibdir=$optarg  ; enable_openiv="yes"  ;;
      --with-pgsql-incdir=*)   pgsqlincdir=$optarg   ; enable_pgsql="yes"   ;;
      --with-pgsql-libdir=*)   pgsqllibdir=$optarg   ; enable_pgsql="yes"   ;;
      --with-pythia-libdir=*)  pythialibdir=$optarg  ; enable_pythia="yes"  ;;
      --with-pythia6-libdir=*) pythia6libdir=$optarg ; enable_pythia6="yes" ;;
      --with-qt-incdir=*)      qtincdir=$optarg      ; enable_qt="yes"      ;;
      --with-qt-libdir=*)      qtlibdir=$optarg      ; enable_qt="yes"      ;;
      --with-sapdb-incdir=*)   sapdbincdir=$optarg   ; enable_sapdb="yes"   ;;
      --with-sapdb-libdir=*)   sapdblibdir=$optarg   ; enable_sapdb="yes"   ;;
      --with-shift-incdir=*)   shiftincdir=$optarg   ; enable_rfio="yes"    ;;
      --with-shift-libdir=*)   shiftlibdir=$optarg   ; enable_rfio="yes"    ;;
      --with-srp=*)            srpdir=$optarg        ; enable_srp="yes"     ;;
      --with-srp-incdir=*)     srpincdir=$optarg     ; enable_srp="yes"     ;;
      --with-srp-libdir=*)     srplibdir=$optarg     ; enable_srp="yes"     ;;
      --with-sys-iconpath=*)   extraiconpath=$optarg ;;
      --with-thread-libdir=*)  threadlibdir=$optarg  ; enable_thread="yes"  ;;
      --with-venus-libdir=*)   venuslibdir=$optarg   ; enable_venus="yes"   ;;
      --with-x11-libdir=*)     x11libdir=$optarg     ;;
      --with-xpm-libdir=*)     xpmlibdir=$optarg     ;;
      ################################################################
      #
      # Enable/disable to turn on/off third party software linkage and
      # features
      #
      --enable-*)
	f=`echo $1 | sed -e 's/--//' -e 's/-/_/'`
	eval $f=yes
	for c in $options ; do
	   if test "x$c" = "x$f" ; then
	      f=""
	   fi
	done
	if test "x$f" != "x" ; then
	   echo "Invalid option '$1'. Try $0 --help" ; exit 1 ;
	fi
	;;
      --disable-*)
	f=`echo $1 | sed -e 's/--disable/enable/' -e 's/-/_/'`
	eval $f=no
	for c in $options ; do
	   if test "x$c" = "x$f" ; then
	      f=""
	   fi
	done
	if test "x$f" != "x" ; then
	   echo "Invalid option '$1'. Try $0 --help" ; exit 1 ;
	fi
	;;
      ################################################################
      #
      # Build steering option
      #
      --build=*)      rootbuild="ROOTBUILD      := $optarg"  ;;
      ################################################################
      #
      # Install path options
      #
      --aclocaldir=*) haveconfig=-DHAVE_CONFIG ; aclocaldir=$optarg  ;;
      --bindir=*)     haveconfig=-DHAVE_CONFIG ; bindir=$optarg      ;;
      --cintincdir=*) haveconfig=-DHAVE_CONFIG ; cintincdir=$optarg  ;;
      --datadir=*)    haveconfig=-DHAVE_CONFIG ; datadir=$optarg     ;;
      --docdir=*)     haveconfig=-DHAVE_CONFIG ; docdir=$optarg      ;;
      --elispdir=*)   haveconfig=-DHAVE_CONFIG ; elispdir=$optarg    ;;
      --etcdir=*)     haveconfig=-DHAVE_CONFIG ; etcdir=$optarg      ;;
      --fontdir=*)    haveconfig=-DHAVE_CONFIG ; fontdir=$optarg     ;;
      --iconpath=*)   haveconfig=-DHAVE_CONFIG ; iconpath=$optarg    ;;
      --incdir=*)     haveconfig=-DHAVE_CONFIG ; incdir=$optarg      ;;
      --libdir=*)     haveconfig=-DHAVE_CONFIG ; libdir=$optarg      ;;
      --macrodir=*)   haveconfig=-DHAVE_CONFIG ; macrodir=$optarg    ;;
      --mandir=*)     haveconfig=-DHAVE_CONFIG ; mandir=$optarg      ;;
      --pkglist*)     show_pkglist="yes"       ; noact="yes"         ;;
      --prefix*)      haveconfig=-DHAVE_CONFIG ; prefix=$optarg      ;;
      --proofdir=*)   haveconfig=-DHAVE_CONFIG ; proofdir=$optarg    ;;
      --srcdir=*)     haveconfig=-DHAVE_CONFIG ; srcdir=$optarg      ;;
      --testdir=*)    haveconfig=-DHAVE_CONFIG ; testdir=$optarg     ;;
      --tutdir=*)     haveconfig=-DHAVE_CONFIG ; tutdir=$optarg      ;;
      *)  echo "Invalid option '$1'. Try $0 --help" ; exit 1 ;;
      esac
      shift
   done
fi

######################################################################
#
### echo %%% Copy skeletons to temporary files
#
if test "x$noact" = "xno"; then
    cp -f $MAKEIN Makefile.tmp
    cp -f $CONFIN config.tmp
    cp -f $RCONFIN root-config.tmp
    cp -f $ROOTRCIN rootrc.tmp
    cp -f $ROOTAUTHRCIN rootauthrc.tmp
    cp -f $ROOTDAEMONRCIN rootdaemonrc.tmp
    cp -f $MEMPROBEIN memprobe.tmp
fi

######################################################################
#
### echo %%% Should sonames contain version numbers
#
if test "x$enable_soversion" = "xyes"; then
    major=`sed 's|\(.*\)\..*/.*|\1|' < build/version_number`
    minor=`sed 's|.*\.\(.*\)/.*|\1|' < build/version_number`
    revis=`sed 's|.*\..*/\(.*\)|\1|' < build/version_number`

    mkliboption="-v $major $minor $revis "
    unset major
    unset minor
    unset revis
fi

######################################################################
#
### echo %%% On Windoze always set enable_shared to no; need .lib
#
if test "x$platform" = "xwin32"; then
    enable_shared="no"
fi

######################################################################
#
### echo %%% X11 and XPM Library - Mandatory lib on Unix
#
# Mandatory test, must succeed
# Check for X11 and Xpm library (for X11 use always shared lib)
#
if test ! "$platform" = "win32"; then
    check_library "libX11" "yes" "$x11libdir" \
	/usr/lib /usr/X11R6/lib /usr/lib/X11 /usr/openwin/lib \
	/usr/local/lib /usr/local/lib/X11 /use/local/X11R6/lib \
	/usr/X11/lib /usr/lib/X11R5
    x11libdir=$found_dir

    if test "x$found_lib" = "x" ; then
	echo "`basename $0`: libX11 MUST be installed"
        exit 1
    fi

    check_library "libXpm" "$enable_shared" "$xpmlibdir" \
	$XPM $XPM/lib /usr/lib /usr/local/lib /usr/lib/X11 \
	/usr/local/lib/X11 /usr/X11R6/lib /use/local/X11R6/lib \
	/usr/X11/lib
    xpmlib=$found_lib
    xpmlibdir=$found_dir

    if test "x$xpmlib" = "x" ; then
	echo "`basename $0`: libXpm MUST be installed"
        exit 1
    fi
fi

######################################################################
#
### echo %%% Exceptions - compiler feature
#
if test "x$EXCEPTIONS" = "xno" ; then
    enable_exceptions=no
fi
e=`echo $rootbuild | sed 's/.*exceptions.*/1/'`
if test "x$e" = "x1" ; then
    enable_exceptions=no
fi

######################################################################
#
### echo %%% Explicitlink - explicitly link with all dependent libraries
#
case $platform in
freebsd*|aix*|win32*)
    enable_explicitlink="yes"
    ;;
esac
if test "$platform" = "macosx" ; then
    enable_explicitlink="no"
fi
if test "x$enable_explicitlink" = "xyes" && test ! "$platform" = "win32" ; then
    mkliboption=$mkliboption"-x "
fi

######################################################################
#
### echo %%% Posix Thread Library
#
# Check for posix thread library
#
case $platform in
linux|linuxdeb|linuxicc|linuxia64*|linuxx8664*|win32gcc|macosx)
    if test "x$enable_thread" = "x"; then
        enable_thread="yes"
    fi
    ;;
freebsd*)
    if test "x$enable_thread" = "xyes"; then
       threadlib="-pthread"
       threadlibdir=
    fi
    ;;
esac
if test "x$enable_thread" = "xyes" && \
   test ! "$platform" = "win32"    && \
   test ! "$platform" = "freebsd4" ; then
    check_library "libpthread" "$enable_shared" "$threadlibdir" \
	$THREAD $THREAD/lib /usr/lib /usr/local/lib /usr/lib/X11 \
	/usr/local/lib/X11 /usr/X11R6/lib /usr/local/X11R6/lib \
	/usr/X11/lib /usr/shlib
    threadlib=$found_lib
    threadlibdir=$found_dir

    if test "x$threadlib" = "x" ; then
        enable_thread="no"
    fi
fi

######################################################################
#
### echo %%% OpenGL Support - Third party libraries
#
# (see mesa3d.org)
#
if test ! "x$enable_opengl" = "xno" && test ! "$platform" = "win32" ; then
    # Check for OpenGL compatible include and library
    check_header "GL/gl.h" "$openglincdir" $OPENGL $OPENGL/include \
	/usr/include /usr/include/X11 /usr/X11/include \
	/usr/X11R6/include /usr/local/include/X11 \
	/usr/local/X11R6/include /usr/local/include \
	/usr/include/Mesa /usr/local/include/Mesa /usr/Mesa/include \
	/usr/local/Mesa/include /usr/Mesa /usr/local/Mesa /opt/Mesa \
	/opt/Mesa/include /opt/graphics/OpenGL/include
    openglinc=$found_hdr
    openglincdir=$found_dir

    opengllibdirs="$OPENGL $OPENGL/lib /usr/lib /usr/local/lib /usr/lib/X11 \
	/usr/X11R6/lib /usr/local/lib/X11 /usr/local/X11R6/lib \
        /usr/X11/lib /usr/lib/Mesa /usr/local/lib/Mesa /usr/Mesa/lib \
	/usr/local/Mesa/lib /usr/Mesa /usr/local/Mesa /opt/Mesa \
	/opt/Mesa/lib /opt/graphics/OpenGL/lib/hpux64 /opt/graphics/OpenGL/lib"

    keep=$opengllibdir
    check_library "libGL libMesaGL" "$enable_shared" \
	"$opengllibdir" $opengllibdirs
    opengllib=$found_lib
    opengllibdir=$found_dir

    check_library "libGLU libMesaGLU" "$enable_shared" \
	"$keep" $opengllibdirs
    openglulib=$found_lib
    openglulibdir=$found_dir

    if test "x$openglincdir" = "x" || \
       test "x$opengllib" = "x" || \
       test "x$openglulib" = "x" ; then
        enable_opengl="no"
    fi
fi

######################################################################
#
### echo %%% OpenInventor Support - Third party libraries
#
# (see http://oss.sgi.com/projects/inventor/)
#
if test "x$enable_opengl" = "xno" ; then
    enable_openiv="no"
fi
if test ! "x$enable_openiv" = "xno" ; then
    # Check for OpenInventor compatible include and library
    check_header "Inventor/SoType.h" "$openivincdir" $IVROOT $IVROOT/include \
	$IVROOT/usr/include /usr/include /usr/include/X11 /usr/X11/include \
	/usr/X11R6/include /usr/local/include/X11 \
	/usr/local/X11R6/include /usr/local/include \
	/usr/include/inventor /usr/local/include/inventor \
	/usr/inventor/include /usr/local/inventor/include \
	/usr/inventor/usr/include /usr/local/inventor/usr/include \
	/usr/local/inventor /opt/inventor /opt/inventor/include \
	/opt/inventor/usr/include
    openivinc=$found_hdr
    openivincdir=$found_dir

    openivlibdirs="$IVROOT $IVROOT/lib $IVROOT/usr/lib /usr/lib /usr/local/lib \
	/usr/lib/X11 /usr/X11R6/lib /usr/local/lib/X11 /usr/local/X11R6/lib \
        /usr/X11/lib /usr/lib/inventor /usr/local/lib/inventor \
	/usr/inventor/lib /usr/inventor/usr/lib /usr/local/inventor/lib \
	/usr/local/inventor/usr/lib /usr/inventor /usr/local/inventor \
	/opt/inventor /opt/inventor/lib /opt/inventor/usr/lib"

    keep=$openivlibdir
    check_library "libInventor libCoin coin*" "$enable_shared" \
	"$openivlibdir" $openivlibdirs
    openivlib=$found_lib
    openivlibdir=$found_dir

    check_library "libInventorXt libSoXt libSoQt soqt*" "$enable_shared" \
	"$keep" $openivlibdirs
    openivlib="$openivlib $found_lib"
    openivlibdir="$openivlibdir $found_dir"

    if test "x$openivincdir" = "x" || \
       test "x$openivlib" = "x" ; then
        enable_openiv="no"
    fi
fi

######################################################################
#
### echo %%% OpenGL support on Windoze
#
# On win32 we always have OpenGL available (is this true?)
#
if test "$platform" = "win32"; then
   enable_opengl="yes"
   openglincdir="include"
fi

######################################################################
#
### echo %%% MySQL Support - Third party libraries
#
# (See mysql.org)
#
# If the user has set the flags "--disable-mysql", we don't check for
# MySQL at all.
#
if test ! "x$enable_mysql" = "xno"; then
    # Check for MySQL include and library
    check_header "mysql.h" "$mysqlincdir" \
	$MYSQL $MYSQL/include /usr/local/include /usr/local/include/mysql \
        /usr/local/mysql /usr/local/mysql/include /opt/mysql \
        /opt/mysql/include /usr/include /usr/include/mysql \
	/usr/mysql /usr/mysql/include
    mysqlinc=$found_hdr
    mysqlincdir=$found_dir

    check_library "libmysqlclient" "$enable_shared" "$mysqllibdir" \
	$MYSQL $MYSQL/lib /usr/local/lib /usr/local/lib/mysql \
        /usr/local/mysql /usr/local/mysql/lib /opt/mysql /opt/mysql/lib \
        /usr/lib /usr/lib/mysql /usr/mysql /usr/mysql/lib
    mysqllib=$found_lib
    mysqllibdir=$found_dir

    # on linux, but maybe also other systems, explicitely add libz
    # (formally only needed when linking against the static libmysqlclient.a)
    if test ! "x$mysqllib" = "x" ; then
	case $arch in
	    linux*|win32gcc) mysqllib="$mysqllib -lz" ;;
	esac
    fi

    if test "x$mysqlincdir" = "x" || test "x$mysqllib" = "x"; then
        enable_mysql="no"
    fi
fi

######################################################################
#
### echo %%% PostgreSQL Support - Third party libraries
#
# (See postgresql.org)
#
# If the user has set the flags "--disable-pgsql", we don't check for
# PostgreSQL at all.
#
if test ! "x$enable_pgsql" = "xno"; then
    # Check for PgSQL include and library
    check_header "libpq-fe.h" "$pgsqlincdir" $PGSQL $PGSQL/include \
	/usr/include /usr/local/include /usr/local/pgsql/include \
        /usr/include/pgsql /usr/include/postgresql /usr/pgsql/include \
        /usr/local/include/pgsql /usr/local/include/postgresql \
	/usr/pgsql /usr/local/pgsql /opt/pgsql /opt/pgsql/include
    pgsqlinc=$found_hdr
    pgsqlincdir=$found_dir

    check_library "libpq" "$enable_shared" "$pgsqllibdir" \
	$PGSQL $PGSQL/lib /usr/local/pgsql/lib /usr/local/lib \
	/usr/lib/pgsql /usr/local/lib/pgsql /usr/pgsql/lib /usr/lib \
	/usr/pgsql /usr/local/pgsql /opt/pgsql /opt/pgsql/lib
    pgsqllib=$found_lib
    pgsqllibdir=$found_dir

    if test "x$pgsqlincdir" = "x" || test "x$pgsqllib" = "x"; then
        enable_pgsql="no"
    fi
fi

######################################################################
#
### echo %%% Qt Support - Optional alternative graphics backend
#
# If the user has set the flags "--disable-qt", we don't check for
# Qt at all.
#
if test ! "x$enable_qt" = "xno"; then
    # Check for Qt include and library
    check_header "qt.h" "$qtincdir" $QTDIR $QTDIR/include \
        /usr/local/include  /usr/local/qt/include /usr/include \
        /usr/include/qt
    qtinc=$found_hdr
    qtincdir=$found_dir

    check_library "libqt-mt libqt qt-mt* qt" "$enable_shared" \
        "$qtlibdir" $QTDIR $QTDIR/lib /usr/local/lib /usr/local/qt/lib \
        /usr/lib /usr/qt/lib
    qtlib=$found_lib
    qtlibdir=$found_dir

    if test "x$qtincdir" = "x" || test "x$qtlib" = "x"; then
        enable_qt="no"
    fi
fi

######################################################################
#
### echo %%% SapDB Support - Third party libraries
#
# (See www.sapdb.org)
#
# If the user has set the flags "--disable-sapdb", we don't check for
# SapDB at all.
#
if test ! "x$enable_sapdb" = "xno"; then
    # Check for SapDB include and library
    check_header "sql.h" "$sapdbincdir" $SAPDB $SAPDB/include \
	/opt/sapdb/interfaces/odbc/incl /usr/sapdb/interfaces/odbc/incl \
	/usr/sapdb/include /usr/local/sapdb/interfaces/odbc/incl \
	/usr/sapdb/web/incl /usr/include/sapdb /usr/local/include/sapdb \
	/usr/local/sapdb/include /usr/local/sapdb/web/incl /usr/sapdb \
	/usr/local/sapdb /opt/sapdb /opt/sapdb/include /opt/sapdb/web/incl
    sapdbinc=$found_hdr
    sapdbincdir=$found_dir

    check_library "libsqlod" "$enable_shared" "$sapdblibdir" \
	$SAPDB $SAPDB/lib /opt/sapdb/interfaces/odbc/lib \
	/usr/sapdb/interfaces/odbc/lib /usr/spadb/lib \
	/usr/local/sapdb/interfaces/odbc/lib /usr/local/sapdb/lib \
	/usr/lib/sapdb /usr/local/lib/sapdb /usr/sapdb/lib \
	/usr/local/sapdb/lib /usr/sapdb /usr/local/sapdb \
	/opt/sapdb /opt/sapdb/lib /usr/sapdb/web/lib \
	/usr/local/sapdb/web/lib /opt/sapdb/web/lib
    sapdblib=$found_lib
    sapdblibdir=$found_dir

    if test "x$sapdbincdir" = "x" || test "x$sapdblib" = "x"; then
        enable_sapdb="no"
    fi
fi

######################################################################
#
### echo %%% SHIFT Support - Third party libraries
#
# (See http://www.cern.ch)
#
# Check for rfio_api.h and libshift.a
#
shiftold=""
if test ! "x$enable_rfio" = "xno" ; then
    # Check for RFIO include and library
    check_header "rfio_api.h" "$shiftincdir" $RFIO $RFIO/include $RFIO/h \
	/cern/pro/include /cern/new/include /cern/old/include \
	/opt/shift/include /usr/local/shift/inlcude /usr/include/shift \
	/usr/local/include/shift /usr/include /usr/local/include
    shiftinc=$found_hdr
    shiftincdir=$found_dir

    if test ! "x$shiftincdir" = "x"; then
        message "Checking whether rfio_fchmod declared in $shiftinc"
        if `grep rfio_fchmod $shiftincdir/$shiftinc > /dev/null 2>&1` ; then
            echo "yes"
        else
            shiftincdir=""
            shiftold="yes"
            echo "no"
            echo "### Found old version of libshift, please uprade to >=1.5.2"
        fi
    fi

    check_library "libshift shiftmd shift" "$enable_shared" "$shiftlibdir" \
	$RFIO $RFIO/lib /cern/pro/lib /cern/new/lib /cern/old/lib \
	/opt/shift/lib /usr/local/shift/lib /usr/lib/shift \
	/usr/local/lib/shift /usr/lib /usr/local/lib
    shiftlib=$found_lib
    shiftlibdir=$found_dir

    if test "x$shiftincdir" = "x" || test "x$shiftlib" = "x"; then
        enable_rfio="no"
    else
        case $platform in
           linux*)     shiftlib="$shiftlib -lnsl" ;;
           solarisCC5) shiftlib="$shiftlib -lposix4" ;;
           win32)      shiftincdir="$shiftincdir -I$shiftincdir/../win32" ;;
        esac
    fi
fi

######################################################################
#
### echo %%% CERNLIB Usage - Third party libraries
#
# (See http://www.cern.ch)
#
# Check for CERN libs (libpacklib and libkernlib)
#
if test ! "x$enable_cern" = "xno"; then
    cernlibdirs="$CERNLIB $CERNLIB/lib ${CERN}/${CERN_LEVEL}/lib  \
	/cern/pro/lib /cern/new/lib /cern/old/lib /opt/cern/pro/lib \
	/opt/cern/new/lib /opt/cern/old/lib /usr/local/cern/pro/lib \
	/usr/local/cern/new/lib /usr/local/cern/old/lib /usr/lib \
	/usr/lib/cern /usr/local/lib /usr/local/lib/cern"
    check_library "libpacklib packmd packlib" "$enable_shared" "${cernlibdir}" \
	$cernlibdirs
    packlib=$found_lib
    packlibdir=$found_dir

    check_library "libkernlib kernmd kernlib" "$enable_shared" "${cernlibdir}" \
	$cernlibdirs
    kernlib=$found_lib
    kernlibdir=$found_dir

    if test ! "x$packlib" = "x" && test "x$enable_rfio" = "xno" ; then
        # check if libpacklib contains rfio references, if yes make further check
        check_symbol rfio "$packlib" "$packlibdir"
        if test  $found_symbol -eq 1 ; then
            # check if libpacklib contains rfio code (case of < 2002 version)
            check_symbol rfio_connect "$packlib" "$packlibdir"
            if test  $found_symbol -eq 0 ; then
                echo "### Need libshift with this version of $packlib"
                if test "x$shiftold" = "xyes"; then
                    echo "### Found old version of libshift, please uprade to >=1.5.2"
                else
                    echo "### Run configure with --enable-rfio or set --with-shift-libdir"
                fi
                packlib=""
            fi
        fi
    fi

    if test "x$packlib" = "x" || test "x$kernlib" = "x"; then
        enable_cern="no"
     else
        cernlib="$packlib $kernlib"
        cernlibdir="$packlibdir $kernlibdir"
    fi
fi

######################################################################
#
### echo %%% Pythia5 Usage - Third party libraries
#
# (See http://root.cern.ch and Lund)
#
# Check for libPythia
#
if test ! "x$enable_pythia" = "xno"; then
    check_library "libPythia" "$enable_shared" "$pythialibdir" \
	$PYTHIA $PYTHIA/lib /cern/pro/lib /opt/pythia /opt/pythia5 \
        /usr/lib/pythia /usr/local/lib/pythia /usr/lib/pythia5 \
	/usr/local/lib/pythia5 /usr/lib /usr/local/lib
    pythialib=$found_lib
    pythialibdir=$found_dir

    if test "x$pythialib" = "x"; then
        enable_pythia=no
    fi
fi

######################################################################
#
### echo %%% Pythia6  Usage - Third party libraries
#
# (See http://root.cern.ch and Lund)
#
# Check for libPythia6
#
if test ! "x$enable_pythia6" = "xno" ; then
    check_library "libPythia6" "$enable_shared" "$pythia6libdir" \
	$PYTHIA6 $PYTHIA6/lib /cern/pro/lib /opt/pythia /opt/pythia6 \
        /usr/lib/pythia /usr/local/lib/pythia /usr/lib/pythia6 \
	/usr/local/lib/pythia6 /usr/lib /usr/local/lib
    pythia6lib=$found_lib
    pythia6libdir=$found_dir

    if test "x$pythia6lib" = "x" ; then
        enable_pythia6=no
    fi
fi

######################################################################
#
### echo %%% Venus  Usage - Third party libraries
#
# (See http://root.cern.ch)
#
# Check for libVenus
#
if test ! "x$enable_venus" = "xno" ; then
    check_library "libVenus" "$enable_shared" "$venuslibdir" \
	$VENUS $VENUS/lib /cern/pro/lib /opt/venus /usr/lib/venus \
	/usr/local/lib/venus /usr/lib /usr/local/lib
    venuslib=$found_lib
    venuslibdir=$found_dir

    if test "x$venuslib" = "x" ; then
        enable_venus=no
    fi
fi

######################################################################
#
### echo %%% dCache Support - Third party libraries
#
# (See http://www.dcache.org)
#
# Check for libdcap
#
if test ! "x$enable_dcache" = "xno" ; then
    check_header "dcap.h" "$dcapincdir" $DCACHE $DCACHE/include \
        /products/dcache/include \
        /opt/dcache/include /usr/include /usr/local/include
    dcapincdir=$found_dir

    check_library "libdcap" "$enable_shared" "$dcaplibdir" $DCACHE $DCACHE/lib \
	/products/dcache/lib /opt/dcache/lib /usr/lib /usr/local/lib
    dcaplib=$found_lib
    dcaplibdir=$found_dir

    if test "x$dcapincdir" = "x" || test "x$dcaplib" = "x"; then
        enable_dcache="no"
    fi
fi

######################################################################
#
### echo %%% Chirp Support - Third party libraries
#
# (See http://www.cs.wisc.edu/condor/chirp)
#
# Check for libchirp_client
#
if test ! "x$enable_chirp" = "xno" ; then
    check_header "chirp_client.h" "$chirpincdir" $CHIRP $CHIRP/include \
	/opt/chirp/include /usr/include /usr/local/include
    chirpincdir=$found_dir

    #At this time, libchirp_client.a should always be prefered over .so,
    #to avoid problems with linkage on grid execute machines.

    check_library "libchirp_client" "no" "$chirplibdir" $CHIRP $CHIRP/lib \
	/opt/chirp/lib /usr/lib /usr/local/lib
    chirplib=$found_lib
    chirplibdir=$found_dir

    if test "x$chirpincdir" = "x" || test "x$chirplib" = "x"; then
        enable_chirp="no"
    fi
fi

######################################################################
#
### echo %%% AliEn Support - Third party libraries
#
# (See http://alien.cern.ch)
#
# Check for libAliEnAPI++
#
if test ! "x$enable_alien" = "xno" ; then
    check_header "AliEnAPI++.h" "$alienincdir" $ALIEN $ALIEN/include \
	/opt/alien/include /usr/local/alien/include /usr/include \
	/usr/local/include
    alienincdir=$found_dir

    if test ! "x$alienincdir" = "x" ; then
       alienincdir="$alienincdir -I$alienincdir/soap"
    fi

    check_library "libAliEnAPI++" "$enable_shared" "$alienlibdir" \
	$ALIEN $ALIEN/lib /opt/alien/lib /usr/local/alien/lib /usr/lib \
        /usr/local/lib
    alienlib=$found_lib
    alienlibdir=$found_dir

    if test "x$alienincdir" = "x" || test "x$alienlib" = "x"; then
        enable_alien="no"
    fi
fi

######################################################################
#
### echo %%% AfterImage Support - Third party libraries
#
# (See http://afterstep.sourceforge.net/afterimage/)
#
# Check for graphics libraries used by libAfterImage, like libjpeg, etc.
#
if test "x$platform" = "xwin32"; then
    enable_asimage="no"
fi
if test ! "x$enable_asimage" = "xno" ; then
    #Figure out where fink on Mac OS X is installed (if any)
    finkdir=`which fink 2>&1 | sed -ne "s/\/bin\/fink//p"`
    check_header "jpeglib.h" "" $ASIMAGE $ASIMAGE/include \
       /usr/local/include /usr/include /opt/include $finkdir/include
    asjpegincdir=$found_dir
    check_header "png.h" "" $ASIMAGE $ASIMAGE/include \
       /usr/local/include /usr/include /opt/include $finkdir/include
    aspngincdir=$found_dir
    check_header "tiffio.h" "" $ASIMAGE $ASIMAGE/include \
       /usr/local/include /usr/include /opt/include $finkdir/include
    astiffincdir=$found_dir
    check_header "gif_lib.h" "" $ASIMAGE $ASIMAGE/include \
       /usr/local/include /usr/include /opt/include $finkdir/include
    asgifincdir=$found_dir

    asextralib=""
    asextralibdir=""
    found_libz=""
    found_dirz=""
    # libz must be before libpng, if libz is not found don't
    # add libpng which needs libz
    for k in libjpeg libtiff libungif libz libpng ; do
        check_library $k "$enable_shared" "" \
            $ASIMAGE $ASIMAGE/lib /usr/local/lib /usr/lib /opt/lib $finkdir/lib
        if test "x$k" = "xlibz" ; then
            found_libz=$found_lib
            found_dirz=$found_dir
            continue;
        fi
        if test "x$k" = "xlibpng" && test "x$found_libz" = "x" ; then
            break;
        fi
        if test ! "x$found_lib" = "x" ; then
            asextralib="$asextralib $found_lib"
            asextralibdir="$asextralibdir $found_dir"
        fi
    done
    if test "x$asextralib" = "x" ; then
        asextralib=""
        asextralibdir=""
        asjpegincdir=""
        aspngincdir=""
        astiffincdir=""
        asgifincdir=""
        enable_asimage="no"
    else
        asextralib="$asextralib $found_libz"
        asextralibdir="$asextralibdir $found_dirz"
    fi
fi

######################################################################
#
### echo %%% LDAP Support - Third party libraries
#
# (See openldap.org)
#
# If the user has set the flags "--disable-ldap", we don't check for
# LDAP at all.
#
if test ! "x$enable_ldap" = "xno"; then
    # Check for ldap include and library
    check_header "ldap.h" "$ldapincdir" $LDAP $LDAP/include \
	/usr/include /usr/local/include /usr/local/ldap/include \
        /usr/include/ldap /usr/include/openldap /usr/ldap/include \
        /usr/local/include/ldap /usr/local/include/openldap \
	/usr/ldap /usr/local/ldap /opt/ldap /opt/ldap/include
    ldapinc=$found_hdr
    ldapincdir=$found_dir

    ldaplib=""
    ldaplibdir=""

    for i in libldap liblber ; do
        check_library $i "$enable_shared" "" $ldaplibdir \
            $LDAP $LDAP/lib /usr/local/ldap/lib /usr/local/lib \
            /usr/lib/ldap /usr/local/lib/ldap /usr/ldap/lib /usr/lib \
            /usr/ldap /usr/local/ldap /opt/ldap /opt/ldap/lib
        if test "x$found_lib" = "x" ; then
            ldaplib=""
            ldaplibdir=""
            enable_ldap="no"
            break
        fi
        ldaplib="$ldaplib $found_lib"
        ldaplibdir="$ldaplibdir $found_dir"
    done

    if test "x$ldapincdir" = "x" || test "x$ldaplib" = "x"; then
        enable_ldap="no"
    fi
fi

######################################################################
#
### echo %%% Globus Support - Third party libraries
#
# (See www.globus.org)
#
# If the user has set the flags "--disable-globus", we don't check for
# Globus at all.
#
glbextracflags=""
glbpatchcflags=""
haveglobus=""
if test ! "x$enable_globus" = "xno"; then
   # Check if the GLOBUS_LOCATION variable is set
   if test "x$globusdir" = "x" ; then
      echo "Checking for globusdir ... no"
      if test "x$GLOBUS_LOCATION" = "x" ; then
          globusdir=""
          enable_globus="no"
          echo "Checking for GLOBUS_LOCATION ... no"
      else
          globusdir=$GLOBUS_LOCATION
          echo "Checking for GLOBUS_LOCATION ... $GLOBUS_LOCATION"
      fi
   fi
fi

if test "x$enable_globus" = "xyes"; then

    pthr="pthr"
    #determine flavour tag of the building
    flavour=""
    if test -d $globusdir/include/gcc32; then
        flavour="gcc32"
    else
        flavour="gcc32dbg"
    fi
    globusincdir=""
    globuslibdir=""
    searchincdir=$globusdir/include

    inclist="openssl/x509.h openssl/pem.h globus_gss_assist.h globus_common.h"

    for i in $inclist ; do
        check_header $i "" "$searchincdir/$flavour"
        if test "x$found_hdr" = "x" ; then
            globusinc=""
            globusincdir=""
            enable_globus="no"
            break
        fi
        globusinc="$globusinc $found_hdr"
        if test "x$globusincdir" = "x" ; then
            globusincdir=$found_dir
        else
            for k in $globusincdir ; do
                if test "x$k" != "x$found_dir" ; then
                    if test "x$k" != "x-I$found_dir" ; then
                        globusincdir="$found_dir -I$globusincdir"
                    fi
                 fi
            done
        fi
    done
fi

if test "x$enable_globus" = "xyes"; then

   # With more recent versions we need an additional header
   check_header globus_gsi_credential.h "" "$searchincdir/$flavour"
   gsiversion="no"
   if test ! "x$found_hdr" = "x" ; then
       gsiversion="yes"
       globusinc="$globusinc $found_hdr"
       if test "x$globusincdir" = "x" ; then
           globusincdir=$found_dir
       else
           for k in $globusincdir ; do
               if test "x$k" != "x$found_dir" ; then
                   if test "x$k" != "x-I$found_dir" ; then
                       globusincdir="$found_dir -I$globusincdir"
                   fi
                fi
           done
       fi
       echo "Checking for gsi version ... yes"
   else
       echo "Checking for gsi version ... no"
       check_header sslutils.h "" "$searchincdir/$flavour"
       if test ! "x$found_hdr" = "x" ; then
          globusinc="$globusinc $found_hdr"
          if test "x$globusincdir" = "x" ; then
             globusincdir=$found_dir
          else
             for k in $globusincdir ; do
                 if test "x$k" != "x$found_dir" ; then
                    if test "x$k" != "x-I$found_dir" ; then
                       globusincdir="$found_dir -I$globusincdir"
                    fi
                 fi
             done
          fi
       else
         globusinc=""
         globusincdir=""
         enable_globus="no"
       fi
   fi
fi

if test "x$enable_globus" = "xyes"; then

   globuslib=""
   if test ! "x$globusdir" = "x" ; then
       searchlibdir=$globusdir/lib
   fi

   for i in libglobus_gss_assist_$flavour libglobus_gssapi_gsi_$flavour \
     libssl_$flavour libcrypto_$flavour ; do
     check_library $i "$enable_shared" "$searchlibdir" /usr/lib \
        /usr/local/lib
        if test "x$found_lib" = "x" ; then
            globuslib=""
            globuslibdir=""
            enable_globus="no"
            break
        fi
        globuslib="$globuslib $found_lib"
        if test "x$globuslibdir" = "x" ; then
            globuslibdir=$found_dir
        else
            for k in $globuslibdir ; do
                if test "x$k" != "x$found_dir" ; then
                    globuslibdir="$found_dir $globuslibdir"
                fi
            done
        fi
   done
fi

if test "x$enable_globus" = "xyes"; then

   # In more recent versions some functions are found in a separated library
   # so, if it exists, add it to the list
   check_library libglobus_gsi_credential_$flavour "$enable_shared" "$searchlibdir" \
          /usr/lib /usr/local/lib
   if test ! "x$found_lib" = "x" ; then
      globuslib="$globuslib $found_lib"
      if test "x$globuslibdir" = "x" ; then
         globuslibdir=$found_dir
      else
         for k in $globuslibdir ; do
             if test "x$k" != "x$found_dir" ; then
                globuslibdir="$found_dir $globuslibdir"
             fi
         done
      fi
   fi

   # Need to source this before init proxies
   sourcepath=""
   if test -s $globusdir/etc/globus-user-env.sh ; then
      sourcepath="$globusdir/etc"
   fi
   if test "x$sourcepath" = "x" ; then
      echo "Checking for globus-user-env.sh ... no (cannot run as client)"
   else
      echo "Checking for globus-user-env.sh ... $sourcepath"
   fi

   # Need this to init proxies
   initpath=""
   if test -s $globusdir/bin/grid-proxy-init ; then
      initpath="$globusdir/bin"
   fi
   if test "x$sourcepath" = "x" ; then
      echo "Checking for grid-proxy-init ... no (cannot run as client)"
   else
      echo "Checking for grid-proxy-init ... $initpath"
   fi

   if test "x$globusincdir" = "x" || test "x$globuslib" = "x"; then
      globuslib=""
      enable_globus="no"
   else
      haveglobus="globus"
   fi

fi

if test "x$enable_globus" = "xyes"; then

   glbextracflags="-DR__GLBS"
   if test "x$gsiversion" = "xyes" ; then
      glbextracflags="$glbextracflags -DR__GLBS22"
   fi

   # Everything seems ok: now check if there is the need for a patch
   patchneeded="no"
   tobepatched="globus_gsi_credential"
   package="globus_gsi_credential"
   packdir="$globusdir/etc/globus_packages/$package"
   if test -d $packdir ; then
      for i in pkg_data_${flavour}_rtl.gpt pkg_data_${flavour}_dev.gpt ; do
         if test -r $packdir/$i ; then
            packfileinfo=$packdir/$i
            break
         fi
      done
      version=""
      if test ! "x$packfileinfo" = "x" ; then
         packfiletmp=`basename $packfileinfo`
         echo "Checking $packfiletmp ... $packdir"
         versionstring=`grep Minor $packfileinfo`
         for i in $versionstring ; do
            for k in 5 7 8 9 ; do
               if test "Minor=\"$k\"" = "$i" ; then
                  version="0.$k"
                  break 2
               fi
            done
         done
      fi
      if test "x$version" = "x" ; then
         patchneeded="no"
         echo "Checking need for globus patch ... no"
      else
         patchneeded="yes"
         echo "Checking need for globus patch ... yes"
      fi

   else
      echo "Checking globus patch need ... no"
   fi

   # Now find includes needed for patch, if the case
   if test "x$patchneeded" = "xyes" ; then

      # build patching flags
      glbpatchcflags="-DR__GLBCPATCH"

      for i in globus_gsi_system_config.h globus_gsi_cert_utils.h ; do
         dirtmp=`find $globusincdir -name $i -exec dirname {} \;`
         if test ! "x$dirtmp" = "x" ; then
            echo "Checking for $i ... $dirtmp"
            add="yes"
            for k in $glbpatchcflags ; do
               if test "x$k" = "x-I$dirtmp" ; then
                  add="no"
               fi
            done
            if test "x$add" == "xyes" ; then
               glbpatchcflags="$glbpatchcflags -I$dirtmp"
            fi
         else
            echo "Checking for $i ... no (globus patch not applied)"
            patchneeded="no"
            glbpatchcflags=""
            break
         fi
      done
   fi

   if test "x$patchneeded" = "xyes" ; then

      # Path with patched files and includes
      globuspatchdir="globusauth/src/patches/$tobepatched/$version"

      # copy patched file in the globusauth/src directory
      cp -rp $globuspatchdir/$tobepatched.c globusauth/src/$tobepatched.c

      glbpatchcflags="$glbpatchcflags -I$globuspatchdir/include"

      if test ! "x$glbpatchcflags" = "x" ; then
         echo "Applying experimental patch to $tobepatched.c"
      fi
   fi
fi

######################################################################
#
### echo %%% SRP Support - Third party libraries
#
# (see  http://srp.stanford.edu/srp)
# Note: You can not make do with the libsrp package. You need the full
# source for this add-on.
#
# Check for SRP (libsrp.a)
#
srpextracflags=""
havesrp=""
if test ! "x$enable_srp" = "xno" ; then
    if test "x$srpincdir" = "x" && test ! "x$srpdir" = "x" ; then
	srpincdir=$srpdir/include
        if test ! -d $srpincdir ; then
            srpincdir=$srpdir/libsrp
        fi
    fi

    check_header "t_server.h" "$srpincdir" $SRP/include $SRP/libsrp \
        /usr/srp/include /usr/include /usr/include/srp /usr/local/include \
        /usr/local/srp/include /usr/local/include/srp
    srpinc=$found_hdr
    srpincdir=$found_dir

    if test "x$srpincdir" = "x" ; then
	enable_srp="no"
    fi

    if test "x$srplibdir" = "x" && test ! "x$srpdir" = "x" ; then
	srplibdir=$srpdir/lib
        if test ! -d $srplibdir ; then
            srplibdir=$srpdir/libsrp
        fi
    fi

    srplibdirs="$SRP $SRP/lib $SRP/libsrp /usr/srp/lib /usr/local/srp/lib \
        /usr/lib/srp /usr/local/lib/srp /usr/lib /usr/local/lib"

    check_library "libsrp" "no" "$srplibdir" $srplibdirs
    srplib=$found_lib
    srplibdir=$found_dir

    check_symbol BN_new "$srplib" "$srplibdir"

    if test $found_symbol -eq 0 ; then
        check_library "libgmp" "$enable_shared" "" $srplibdir $srplibdirs
        gmplib=$found_lib
        gmplibdir=$found_dir
    else
        check_library "libcrypto" "$enable_shared" "" $srplibdir $srplibdirs
        cryptolib=$found_lib
        cryptolibdir=$found_dir
        if test -r $cryptolib && test "x$enable_shared" = "xno" ; then
           case $arch in
               linux*) cryptolib="$cryptolib -ldl"
           esac
        fi
    fi

    if test "x$srplib" = "x" ; then
        enable_srp="no"
        srplibdir=""
    elif test "x$gmplib" = "x" && test "x$cryptolib" = "x" ; then
        enable_srp="no"
        gmplibdir=""
    else
        srplib="$srplib $gmplib"
        srplibdir="$srplibdir $gmplibdir"
    fi

    srputillib=""
    srputillibdir=""
    srplibdirs="$srpdir/base/libmisc $srpdir/base/lib \
        $SRP/base/libmisc $SRP/base/lib \
        /usr/local/srp/lib /usr/local/lib/srp /usr/srp/lib /usr/lib/srp \
        /usr/local/lib /usr/lib"
    for i in libmisc libshadow ; do
	check_library "$i" "no" "" $srplibdirs
	if test "x$found_lib" = "x" ; then
	    srputillib=""
	    srputillibdir=""
	    enable_srp="no"
	    break
        fi
	srputillib="$srputillib $found_lib"
	srputillibdir="$srputillibdir $found_dir"
    done


    if test ! "x$srpdir" = "x" ; then
	srputilincdir=$srpdir/base/lib
    fi
    check_header "pwauth.h" "$srputilincdir" $SRP $SRP/base/lib \
        /usr/local/srp/base/lib /usr/srp/base/lib
    srputilincdir=$found_dir

    if test "x$srputilincdir" = "x" ; then
	enable_srp="no"
    fi

    if test "x$enable_srp" = "xno" ; then
	srplib=""
	srputillib=""
    else
        srpextracflags="-DR__SRP"
        havesrp="srp"
    fi
fi

######################################################################
#
### echo %%% AFS Support - Third party libraries
#
# (See http://www.openafs.org)
#
# Check for AFS (libdes.a)
#
if test ! "x$enable_afs" = "xno" ; then
    if test ! "x$afsdir" = "x" ; then
	afsdir="$afsdir $afsdir/afs"
    fi

    afslibdirs="$AFS/lib /usr/afsws/lib /usr/local/afsws/lib \
        /opt/afs/lib /usr/local/afs/lib /usr/lib /usr/local/lib \
        /usr/athena/lib /usr/local/athena/lib"
    afslib=""
    afslibdir=""
    for i in afs/libkauth afs/libprot afs/libauth afs/libsys afs/libcmd \
             afs/libaudit afs/util libubik librx librxkad \
             liblwp libafsrpc libdes ; do
	check_library "$i" "no" "$afsdir" $afslibdirs
	if test "x$found_lib" = "x" ; then
	    afslib=""
	    afslibdir=""
	    enable_afs="no"
	    break
        fi
	afslib="$afslib $found_lib"
	afslibdir="$afslibdir $found_dir"
    done

    if test "x$afslib" = "x" ; then
        enable_afs="no"
    fi
fi

######################################################################
#
### echo %%% krb5 Support - Third party libraries
#
#
# Check for krb5 (libkrb5.a)
#
krb5extracflags=""
havekrb5=""
if test ! "x$enable_krb5" = "xno" ; then
    enable_krb5="yes"
    if test "x$krb5incdir" = "x" && test ! "x$krb5dir" = "x" ; then
	krb5incdir=$krb5dir/include
    fi
    check_header "krb5.h" "$krb5incdir" /usr/athena/include \
	    /usr/local/athena/include /usr/kerberos/include \
	    /usr/krb5/include /usr/local/kerberos/include \
	    /usr/include /usr/local/include
    if test "x$found_dir" = "x" ; then
	enable_krb5=no
    else
        krb5inc=$found_hdr
        krb5incdir=$found_dir
    fi

    krb5libdirorg=""
    if test ! "x$krb5libdir" = "x" ; then
	krb5libdirorg=$krb5libdir
    fi
    if test "x$krb5libdir" = "x" && test ! "x$krb5dir" = "x" ; then
	krb5libdirorg=$krb5dir/lib
    fi
    krb5libdirs="/usr/athena/lib /usr/local/athena/lib /usr/kerberos/lib \
                 /usr/krb5/lib /usr/local/kerberos/lib /usr/lib /usr/local/lib"

    # check whether using MIT krb5
    krb5mit=no
    krb5lib=""
    krb5libdir=""
    check_library libk5crypto "no" "$krb5libdirorg" $krb5libdirs
    if test ! "x$found_lib" = "x" ; then
	krb5mit=yes
        krb5lib=$found_lib
        krb5libdir=$found_dir
    fi
    message "Checking whether we're using MIT Kerberos"
    echo "$krb5mit"

    check_library libkrb5 "no" "$krb5libdirorg" $krb5libdirs
    if test "x$found_lib" = "x" ; then
	enable_krb5=no
    else
	# The order is important here
	krb5lib="$found_lib $krb5lib"
	krb5libdir="$found_dir $krb5libdir"
	if test "x$krb5mit" = "xyes" ; then
	    # check_library libss "no" "$krb5libdirorg" $krb5libdirs
	    # if test "x$found_lib" = "x" ; then
	    #    enable_krb5=no
	    # else
	    #    krb5lib="$krb5lib $found_lib"
	    #    krb5libdir="$krb5libdir $found_dir"
	    # fi
	    :
	elif test "x$cryptolib" = "x" ; then
            check_library "libcrypto" "$enable_shared" "$krb5libdirorg" $krb5libdirs
            cryptolib=$found_lib
            cryptolibdir=$found_dir
            if test -r $cryptolib && test "x$enable_shared" = "xno" ; then
               case $arch in
                   linux*) cryptolib="$cryptolib -ldl"
               esac
            fi
	    if test "x$cryptolib" = "x" ; then
                enable_krb5=no
	    fi
	fi
    fi

    krb5init=""
    krb5bindir=""
    if test ! "x$krb5dir" = "x" ; then
	krb5bindir=$krb5dir/bin
    fi
    for i in "$krb5bindir" /usr/athena/bin \
             /usr/local/athena/bin /usr/kerberos/bin \
             /usr/krb5/bin /usr/local/kerberos/bin \
             /usr/bin /usr/local/bin ; do
        if test -x $i/kinit ; then
            krb5init=$i/kinit
            break
        fi
    done

    if test "x$krb5init" = "x" ; then
        echo "Checking for kinit ... no"
    else
        echo "Checking for kinit ... $krb5init"
    fi

    if test ! "x$enable_krb5" = "xyes" ; then
        krb5incdir=""
        krb5lib=""
        krb5libdir=""
    else
        krb5extracflags="-DR__KRB5"
        havekrb5="krb5"
    fi
fi

######################################################################
#
### echo %%% Communication of errors library
#
# This library is needed by both AFS and Kerberos support, so to
# avoid duplicate linkage, this is done here.
#
if test "x$enable_afs" = "xyes" || test "x$enable_krb5" = "xyes" ; then
    if test ! "x$afsdir" = "x" ; then
        comerrlibdir=$afsdir
    fi
    if test ! "x$krb5libdirorg" = "x" ; then
        if test ! "x$comerrlibdir" = "x" ; then
            comerrlibdir="$comerrlibdir $krb5libdirorg"
        else
            comerrlibdir=$krb5libdirorg
        fi
    fi
    check_library libcom_err "$enable_shared" "$comerrlibdir" \
                                              "$afslibdirs $krb5libdirs"
    if test "x$found_lib" = "x" ; then
	enable_krb5=no
        krb5incdir=""
        krb5lib=""
        krb5libdir=""
        krb5extracflags=""
	enable_afs=no
        afslib=""
	comerrlib=""
	comerrlibdir=""
    else
	comerrlib=$found_lib
	comerrlibdir=$found_dir
    fi

    case $arch in
	linux*|solarisCC5) # Resolver lives in separate library
	    resolvlib="-lresolv"
	    ;;
    esac
fi

######################################################################
#
### echo %%% Shadow password support
#

checking_msg "shadow passwords"

if test "x$enable_shadowpw" = "x"; then
   if test -f "/etc/shadow"; then
      enable_shadowpw="yes"
   else
      enable_shadowpw="no"
   fi
fi

if test "x$enable_shadowpw" = "xyes"; then
   shadowpw="-DR__SHADOWPW "
fi

echo $enable_shadowpw

######################################################################
#
### echo %%% Table Library - Contributed library
#
message "Checking whether to build libTable"
if test "x$enable_table" = "xyes" || test ! "x$TABLE" = "x"; then
    enable_table="1"
    echo "yes"
else
    enable_table=""
    echo "no"
fi

######################################################################
#
### echo %%% Debian or Red Hat package list
#
# If we're asked to build for a set of RPMs or Debian packages, we
# make a list of the packages it's possible for us to build on this
# system.
#
if test "x$show_pkglist" = "xyes" ; then
    pkglist="root-daemon"
    test "x$enable_cern" = "xyes" && pkglist="$pkglist root-zebra"
    if test "x$enable_openiv" = "xyes" ; then
	pkglist="$pkglist root-gliv"
    elif test "x$enable_opengl" = "xyes" ; then
	pkglist="$pkglist root-gl"
    fi
    test "x$enable_mysql" = "xyes" && pkglist="$pkglist root-mysql"
    test "x$enable_pgsql" = "xyes" && pkglist="$pkglist root-pgsql"
    test "x$enable_sapdb" = "xyes" && pkglist="$pkglist root-sapdb"
    test "x$enable_pythia" = "xyes" && test "x$enable_pythia6" = "xyes" && pkglist="$pkglist root-pythia"
    test "x$enable_rfio" = "xyes" && pkglist="$pkglist root-shift"
    test "x$enable_srputil" = "xyes" && pkglist="$pkglist root-srp"

    pkglist="$pkglist root-cint root-doc libroot-dev root-bin libroot"
    # If we're called from the package preparation script, then
    # print out the package list and exit
    echo "packages: $pkglist"
    exit 0
fi

######################################################################
#
### echo %%% check for setresuid and setresgid
#
setresuid="undef"
case $arch in
    linux*)
        message "Checking whether setresuid declared in /usr/include/unistd.h"
        if `grep setresuid /usr/include/unistd.h > /dev/null 2>&1` ; then
            setresuid="define"
            echo "yes"
        else
            echo "no"
        fi ;;
esac

######################################################################
#
### echo %%% Exit here if this is a dry run
#
if test "x$noact" = "xyes" ; then
    exit 0
fi

######################################################################
#
### echo %%% Create needed directories
#
if test ! -d include ; then
   message "Creating include"
   mkdir include
   echo "done"
fi
if test ! -d bin ; then
   message "Creating bin"
   mkdir bin
   echo "done"
fi
if test ! -d lib ; then
   message "Creating lib"
   mkdir lib
   echo "done"
fi

######################################################################
#
### echo %%% Cleanup obsolete links and files
#
if test -h opengl ; then
   rm -f opengl
fi
if test -h ttf ; then
   rm -f ttf
fi
if test -f system.rootrc ; then
   rm -f system.rootrc
fi
if test -d new ; then
   rm -rf new
fi
if test -d star ; then
   rm -rf star
fi

######################################################################
#
### echo %%% Fleshin out paths
#
# First win32 does not support -L in ldflags, so remove @ldflags@.
#
if test "$platform" = "win32" ; then
    sed -e "s|@ldflags@||"        \
        < Makefile.tmp > Makefile.tmpp
    mv Makefile.tmpp Makefile.tmp
fi

if test ! "x$haveconfig" = "x" ; then
    ##################################################################
    #
    ### echo %%% Static directory build.
    #
    if test "x$prefix" = "x";       then prefix=/usr/local; fi
    if test "x$bindir" = "x";       then bindir=$prefix/bin; fi
    if test "x$libdir" = "x";       then libdir=$prefix/lib/root; fi
    if test "x$incdir" = "x";       then incdir=$prefix/include/root; fi
    if test "x$etcdir" = "x";       then etcdir=/etc/root; fi
    if test "x$mandir" = "x";       then mandir=$prefix/share/man/man1; fi
    if test "x$datadir" = "x";      then datadir=$prefix/share/root; fi
    if test "x$proofdir" = "x";     then proofdir=$datadir/proof; fi
    if test "x$macrodir" = "x";     then macrodir=$datadir/macros; fi
    if test "x$cintincdir" = "x";   then cintincdir=$libdir/cint; fi
    if test "x$iconpath" = "x";     then iconpath=$datadir/icons; fi
    if test "x$srcdir" = "x";       then srcdir=$datadir/src; fi
    if test "x$fontdir" = "x";      then fontdir=$datadir/fonts; fi
    if test "x$docdir" = "x";       then docdir=$prefix/share/doc/root; fi
    if test "x$testdir" = "x";      then testdir=$docdir/test; fi
    if test "x$tutdir" = "x";       then tutdir=$docdir/tutorials; fi
    if test "x$aclocaldir" = "x";   then aclocaldir=$prefix/share/aclocal; fi
    if test "x$elispdir" = "x";     then elispdir=$prefix/share/emacs/site-lisp; fi

    if test "x$enable_rpath" = "xyes" ; then
        if test "$platform" = "solarisCC5"; then
            sed -e "s|@ldflags@|-R$libdir @ldflags@|" \
                    < Makefile.tmp > Makefile.tmpp
        else
           if test "x$enable_globus" = "xyes" ; then
             sed -e "s|@ldflags@|-Wl,-rpath,$libdir -Wl,-rpath,$GLOBUS_LOCATION/lib @ldflags@|" \
                    < Makefile.tmp > Makefile.tmpp
           else
             sed -e "s|@ldflags@|-Wl,-rpath,$libdir @ldflags@|" \
                    < Makefile.tmp > Makefile.tmpp
           fi
        fi
        mv Makefile.tmpp Makefile.tmp
    fi

    sed -e "s|@useconfig@|TRUE|"                       \
        -e "s|@cflags@|-DHAVE_CONFIG|"                 \
            < Makefile.tmp > Makefile.tmpp
    mv Makefile.tmpp Makefile.tmp
else
    ##################################################################
    #
    ### echo %%% Environment driven build. Escape sequences very important
    #
    prefix=\$\(ROOTSYS\)
    bindir=\$\(ROOTSYS\)/bin
    libdir=\$\(ROOTSYS\)/lib
    incdir=\$\(ROOTSYS\)/include
    etcdir=\$\(ROOTSYS\)/etc
    datadir=\$\(ROOTSYS\)
    mandir=\$\(ROOTSYS\)/man/man1
    proofdir=\$\(ROOTSYS\)/proof
    macrodir=\$\(ROOTSYS\)/macros
    cintincdir=\$\(ROOTSYS\)/cint
    iconpath=\$\(ROOTSYS\)/icons
    srcdir=\$\(ROOTSYS\)/src
    fontdir=\$\(ROOTSYS\)/fonts
    docdir=\$\(ROOTSYS\)
    testdir=\$\(ROOTSYS\)/test
    tutdir=\$\(ROOTSYS\)/tutorials
    aclocaldir=\$\(ROOTSYS\)/build/misc
    elispdir=\$\(ROOTSYS\)/build/misc

    # when using rpath in this case build product is not relocatable
    if test "x$enable_rpath" = "xyes" ; then
        if test "$platform" = "solarisCC5"; then
            sed -e "s|@ldflags@|-R$libdir @ldflags@|" \
                    < Makefile.tmp > Makefile.tmpp
        else
            sed -e "s|@ldflags@|-Wl,-rpath,$libdir @ldflags@|" \
                    < Makefile.tmp > Makefile.tmpp
        fi
        mv Makefile.tmpp Makefile.tmp
    fi

    sed -e "s|@useconfig@|FALSE|" \
        -e "s|@cflags@||"         \
        -e "s|@ldflags@||"        \
            < Makefile.tmp > Makefile.tmpp
    mv Makefile.tmpp Makefile.tmp
fi

######################################################################
#
### echo %%% Writing files
#
#---------------------------------------------------------------------
# config/Makefile.config
#
message "Writing $MAKEOUT"
sed -e "s|@aclocaldir@|$aclocaldir|"            \
    -e "s|@afslib@|$afslib|"                    \
    -e "s|@afslibdir@|$afslibdir|"              \
    -e "s|@alienincdir@|$alienincdir|"          \
    -e "s|@alienlib@|$alienlib|"                \
    -e "s|@alienlibdir@|$alienlibdir|"          \
    -e "s|@architecture@|$arch|"                \
    -e "s|@asextralib@|$asextralib|"            \
    -e "s|@asextralibdir@|$asextralibdir|"      \
    -e "s|@asjpegincdir@|$asjpegincdir|"        \
    -e "s|@aspngincdir@|$aspngincdir|"          \
    -e "s|@astiffincdir@|$astiffincdir|"        \
    -e "s|@asgifincdir@|$asgifincdir|"          \
    -e "s|@bindir@|$bindir|"                    \
    -e "s|@buildasimage@|$enable_asimage|"      \
    -e "s|@cernlibdir@|$cernlibdir|"            \
    -e "s|@cernlibs@|$cernlib|"                 \
    -e "s|@chirpincdir@|$chirpincdir|"          \
    -e "s|@chirplib@|$chirplib|"                \
    -e "s|@chirplibdir@|$chirplibdir|"          \
    -e "s|@cintincdir@|$cintincdir|"            \
    -e "s|@datadir@|$datadir|"                  \
    -e "s|@dcapincdir@|$dcapincdir|"            \
    -e "s|@comerrlib@|$comerrlib|"              \
    -e "s|@comerrlibdir@|$comerrlibdir|"        \
    -e "s|@cryptolib@|$cryptolib|"              \
    -e "s|@cryptolibdir@|$cryptolibdir|"        \
    -e "s|@dcaplib@|$dcaplib|"                  \
    -e "s|@dcaplibdir@|$dcaplibdir|"            \
    -e "s|@docdir@|$docdir|"                    \
    -e "s|@elispdir@|$elispdir|"                \
    -e "s|@enable_table@|$enable_table|"        \
    -e "s|@enable_thread@|$enable_thread|"      \
    -e "s|@etcdir@|$etcdir|"                    \
    -e "s|@exceptions@|$enable_exceptions|"     \
    -e "s|@explicitlink@|$enable_explicitlink|" \
    -e "s|@globusincdir@|$globusincdir|"        \
    -e "s|@globuslib@|$globuslib|"              \
    -e "s|@globuslibdir@|$globuslibdir|"        \
    -e "s|@glbextracflags@|$glbextracflags|"    \
    -e "s|@glbpatchcflags@|$glbpatchcflags|"    \
    -e "s|@iconpath@|$iconpath|"                \
    -e "s|@incdir@|$incdir|"                    \
    -e "s|@krb5incdir@|$krb5incdir|"            \
    -e "s|@krb5lib@|$krb5lib|"                  \
    -e "s|@krb5libdir@|$krb5libdir|"            \
    -e "s|@krb5extracflags@|$krb5extracflags|"  \
    -e "s|@ldapincdir@|$ldapincdir|"            \
    -e "s|@ldaplib@|$ldaplib|"                  \
    -e "s|@ldaplibdir@|$ldaplibdir|"            \
        < Makefile.tmp > Makefile.tmpp
mv Makefile.tmpp Makefile.tmp

sed -e "s|@ldflags@||"                          \
    -e "s|@libdir@|$libdir|"                    \
    -e "s|@macrodir@|$macrodir|"                \
    -e "s|@mandir@|$mandir|"                    \
    -e "s|@mkliboption@|$mkliboption|"          \
    -e "s|@mysqlincdir@|$mysqlincdir|"          \
    -e "s|@mysqllib@|$mysqllib|"                \
    -e "s|@mysqllibdir@|$mysqllibdir|"          \
    -e "s|@openglincdir@|$openglincdir|"        \
    -e "s|@opengllib@|$opengllib|"              \
    -e "s|@opengllibdir@|$opengllibdir|"        \
    -e "s|@openglulib@|$openglulib|"            \
    -e "s|@openivincdir@|$openivincdir|"        \
    -e "s|@openivlib@|$openivlib|"              \
    -e "s|@openivlibdir@|$openivlibdir|"        \
    -e "s|@pgsqlincdir@|$pgsqlincdir|"          \
    -e "s|@pgsqllib@|$pgsqllib|"                \
    -e "s|@pgsqllibdir@|$pgsqllibdir|"          \
    -e "s|@proofdir@|$proofdir|"                \
    -e "s|@pythia6lib@|$pythia6lib|"            \
    -e "s|@pythia6libdir@|$pythia6libdir|"      \
    -e "s|@pythialib@|$pythialib|"              \
    -e "s|@pythialibdir@|$pythialibdir|"        \
    -e "s|@qtincdir@|$qtincdir|"                \
    -e "s|@qtlib@|$qtlib|"                      \
    -e "s|@qtlibdir@|$qtlibdir|"                \
    -e "s|@resolvlib@|$resolvlib|"              \
    -e "s|@rootbuild@|$rootbuild|"              \
    -e "s|@sapdbincdir@|$sapdbincdir|"          \
    -e "s|@sapdblib@|$sapdblib|"                \
    -e "s|@sapdblibdir@|$sapdblibdir|"          \
    -e "s|@shadowpw@|$shadowpw|"                \
    -e "s|@shiftincdir@|$shiftincdir|"          \
    -e "s|@shiftlib@|$shiftlib|"                \
    -e "s|@shiftlibdir@|$shiftlibdir|"          \
    -e "s|@srcdir@|$srcdir|"                    \
    -e "s|@srpincdir@|$srpincdir|"              \
    -e "s|@srplib@|$srplib|"                    \
    -e "s|@srplibdir@|$srplibdir|"              \
    -e "s|@srputilincdir@|$srputilincdir|"      \
    -e "s|@srputillib@|$srputillib|"            \
    -e "s|@srputillibdir@|$srputillibdir|"      \
    -e "s|@srpextracflags@|$srpextracflags|"    \
    -e "s|@testdir@|$testdir|"                  \
    -e "s|@threadlib@|$threadlib|"              \
    -e "s|@threadlibdir@|$threadlibdir|"        \
    -e "s|@ttffontdir@|$fontdir|"               \
    -e "s|@tutdir@|$tutdir|"                    \
    -e "s|@venuslib@|$venuslib|"                \
    -e "s|@venuslibdir@|$venuslibdir|"          \
    -e "s|@x11libdir@|$x11libdir|"              \
    -e "s|@xpmlib@|$xpmlib|"                    \
    -e "s|@xpmlibdir@|$xpmlibdir|"              \
    < Makefile.tmp > $MAKEOUT
rm -f Makefile.tmp

if test "x$platform" = "xwin32"; then
    sed -e 's@$(ROOTSYS)\(.*\)@$(shell cygpath -u \"$(ROOTSYS)\1")@' \
    < $MAKEOUT > Makefile.tmp
    mv -f Makefile.tmp $MAKEOUT
fi

echo "done"

#---------------------------------------------------------------------
# include/config.h
#
message "Writing $CONFOUT"
sed \
    -e "s|@architecture@|$arch|"           \
    -e "s|@bindir@|$bindir|"               \
    -e "s|@cintincdir@|$cintincdir|"       \
    -e "s|@datadir@|$datadir|"             \
    -e "s|@docdir@|$docdir|"               \
    -e "s|@etcdir@|$etcdir|"               \
    -e "s|@extraiconpath@|$extraiconpath|" \
    -e "s|@iconpath@|$iconpath|"           \
    -e "s|@incdir@|$incdir|"               \
    -e "s|@libdir@|$libdir|"               \
    -e "s|@macrodir@|$macrodir|"           \
    -e "s|@prefix@|$prefix|"               \
    -e "s|@srcdir@|$srcdir|"               \
    -e "s|@ttffontdir@|$fontdir|"          \
    -e "s|@setresuid@|$setresuid|"         \
    -e "s|@krb5init@|$krb5init|"           \
    -e "s|@configoptions@|$configoptions|" \
    < config.tmp > $CONFOUT
rm -f config.tmp
echo "done"

#---------------------------------------------------------------------
# bin/root-config
#
message "Writing $RCONFOUT"
prefix2=$prefix
incdir2=$incdir
libdir2=$libdir
if test "$prefix2" = "\$(ROOTSYS)" ; then
    prefix2=\$ROOTSYS
    libdir2=\$ROOTSYS/lib
    incdir2=\$ROOTSYS/include
fi
features=""
for f in $options ; do
    bar="$`echo $f`"
    if test "x`eval echo $bar`" = "xyes" ; then
       feat=`echo $f | sed 's/enable_//'`
       features="$features $feat"
    fi
done
sed -e "s|@architecture@|$arch|"           \
    -e "s|@prefix@|$prefix2|"              \
    -e "s|@incdir@|$incdir2|"              \
    -e "s|@libdir@|$libdir2|"              \
    -e "s|@features@|$features|"           \
   < root-config.tmp > $RCONFOUT
rm -f root-config.tmp
chmod 755 $RCONFOUT
echo "done"

#---------------------------------------------------------------------
# etc/system.rootrc
#
message "Writing $ROOTRCOUT"
sed -e "s|@libdir@|$libdir|"               \
    -e "s|@macrodir@|$macrodir|"           \
    -e "s|@bindir@|$bindir|"               \
    -e "s|@etcdir@|$etcdir|"               \
    -e "s|@ttffontdir@|$fontdir|"          \
    -e "s|@iconpath@|$iconpath|"           \
   < rootrc.tmp > $ROOTRCOUT
rm -f rootrc.tmp
echo "done"

#---------------------------------------------------------------------
# etc/system.rootauthrc
#
message "Writing $ROOTAUTHRCOUT"
sed -e "s|@havesrp@|$havesrp|"             \
    -e "s|@havekrb5@|$havekrb5|"           \
    -e "s|@haveglobus@|$haveglobus|"       \
   < rootauthrc.tmp > $ROOTAUTHRCOUT
rm -f rootauthrc.tmp
echo "done"

#---------------------------------------------------------------------
# etc/system.rootdaemonrc
#
message "Writing $ROOTDAEMONRCOUT"
sed -e "s|@havesrp@|$havesrp|"             \
    -e "s|@havekrb5@|$havekrb5|"           \
    -e "s|@haveglobus@|$haveglobus|"       \
   < rootdaemonrc.tmp > $ROOTDAEMONRCOUT
rm -f rootdaemonrc.tmp
echo "done"

#---------------------------------------------------------------------
# etc/root.mimes
#
message "Writing $MIMEOUT"
if test "$platform" = "win32" ; then
   cp -f $MIMEWIN32IN $MIMEOUT
else
   cp -f $MIMEUNIXIN $MIMEOUT
fi
echo "done"

#---------------------------------------------------------------------
# bin/memprobe
#
message "Writing $MEMPROBEOUT"
if test -x /usr/bin/env ; then
   perlexe="/usr/bin/env perl"
else
   perlexe=`which perl`
fi
sed -e "s|@perl@|$perlexe|"                \
   < memprobe.tmp > $MEMPROBEOUT
rm -f memprobe.tmp
chmod 755 $MEMPROBEOUT
echo "done"

#---------------------------------------------------------------------
# build/misc/root-help.el
#
message "Writing build/misc/root-help.el"
sed -e "s|@bindir@|$bindir|"           \
    -e "s|@incdir@|$incdir|"           \
    < config/root-help.el.in > build/misc/root-help.el
echo "done"


######################################################################
#
# FAT conversion in test/tutorials
#
# On win32 convert all files in tutorials and test to \r\n convention
# (only if CVS directory does not exist, otherwise cvs will already
# have made the conversion).
#
if test "x$platform" = "xwin32"  && test ! -d CVS ; then
   message "Converting files in tutorials and test to DOS format"
   for i in tutorials/*.C tutorials/*.sql test/*.cxx test/*.h \
            test/Makefile* test/README etc/system.rootrc
   do
      sed 's/$//' $i > r__tmp
      touch -r $i r__tmp
      mv -f r__tmp $i
   done
   echo "done"
fi

######################################################################
#
# Warning about recommended build options
#
echo ""
if test "x$enable_opengl" = "xno" ; then
    echo "To build the ROOT OpenGL add-on library see README/INSTALL."
    echo ""
    echo ""
fi

######################################################################
#
### echo %%% Final instructions
#
# List the possible Makefiles
#
echo "To build ROOT type:"
echo ""
if test "x$platform" = "xwin32" || test "x$platform" = "xwin32gcc" ; then
    echo "   make"
    if test ! "x$haveconfig" = "x" ; then
        echo "   make install"
    fi
else
    echo "   gmake"
    if test ! "x$haveconfig" = "x" ; then
        echo "   gmake install"
    fi
fi
echo ""

exit 0
