#! /bin/sh
#
# If these # comments don't work, trim them. Don't worry about any other
# shell scripts, Configure will trim # comments from them for you.
#
# (If you are trying to port this package to a machine without sh,
# I would suggest you have a look at the prototypical config_h.SH file
# and edit it to reflect your system. Some packages may include samples
# of config.h for certain machines, so you might look for one of those.)
#
# Yes, you may rip this off to use in other distribution packages. This
# script belongs to the public domain and cannot be copyrighted.
#
# (Note: this Configure script was generated automatically. Rather than
# working with this copy of Configure, you may wish to get metaconfig.
# The dist-3.0 package (which contains metaconfig) was posted in
# comp.sources.misc and is available on CPAN under authors/id/RAM so
# you may fetch it yourself from your nearest archive site.)
#

# $Id: Configure,v 1.20 2001/12/14 12:19:57 sadilov Exp $
#
# Generated on Fri Dec 14 13:19:47 CET 2001 [metaconfig 3.0 PL70]

cat >/tmp/c1$$ <<EOF
WARNING!!!!!

SCO csh still thinks true is false!  /bin/csh needs to be updated.
EOF
cat >/tmp/c2$$ <<EOF

You didn't run Configure with sh!
I'll attempt to run sh for you...
EOF

true || cat /tmp/c1$$ /tmp/c2$$
true || exec sh $0 $argv:q

(exit $?0) || cat /tmp/c2$$
(exit $?0) || exec sh $0 $argv:q
rm -f /tmp/c1$$ /tmp/c2$$

: compute my invocation name
me=$0
case "$0" in
*/*)
	me=`echo $0 | sed -e 's!.*/\(.*\)!\1!' 2>/dev/null`
	test "$me" || me=$0
	;;
esac

: Proper PATH separator
p_=:
: On OS/2 this directory should exist if this is not floppy only system :-]
if test -d c:/.; then
	p_=\;
	PATH=`cmd /c "echo %PATH%" | tr '\\\\' / `
	OS2_SHELL=`cmd /c "echo %OS2_SHELL%" | tr '\\\\' / | tr '[A-Z]' '[a-z]'`
fi

: Proper PATH setting
paths='/bin /usr/bin /usr/local/bin /usr/ucb /usr/local /usr/lbin'
paths="$paths /opt/bin /opt/local/bin /opt/local /opt/lbin"
paths="$paths /usr/5bin /etc /usr/gnu/bin /usr/new /usr/new/bin /usr/nbin"
paths="$paths /opt/gnu/bin /opt/new /opt/new/bin /opt/nbin"
paths="$paths /sys5.3/bin /sys5.3/usr/bin /bsd4.3/bin /bsd4.3/usr/ucb"
paths="$paths /bsd4.3/usr/bin /usr/bsd /bsd43/bin /usr/ccs/bin"
paths="$paths /etc /usr/lib /usr/ucblib /lib /usr/ccs/lib"
paths="$paths /sbin /usr/sbin /usr/libexec"

for p in $paths
do
	case "$p_$PATH$p_" in
	*$p_$p$p_*) ;;
	*) test -d $p && PATH=$PATH$p_$p ;;
	esac
done

PATH=.$p_$PATH
export PATH

: shall we be using ksh?
inksh=''
needksh=''
avoidksh=''
newsh=/bin/ksh
changesh=''
if (PATH=.; alias -x) >/dev/null 2>&1; then
		inksh=true
fi
if test -f /hp-ux -a -f /bin/ksh; then
	needksh='to avoid sh bug in "here document" expansion'
fi
if test -d /usr/lpp -a -f /usr/bin/bsh -a -f /usr/bin/uname; then
	if test X`/usr/bin/uname -v` = X4; then
		avoidksh="to avoid AIX 4's /bin/sh"
		newsh=/usr/bin/bsh
	fi
fi
case "$inksh/$needksh" in
/[a-z]*)
		unset ENV
		changesh=true
		reason="$needksh"
	;;
esac
case "$inksh/$avoidksh" in
true/[a-z]*)
	changesh=true
	reason="$avoidksh"
	;;
esac
case "$inksh/$needksh-$avoidksh-" in
true/--)
		cat <<EOM
(I see you are using the Korn shell.  In case of problems
 try the Bourne shell instead.)
EOM
	;;
esac
case "$changesh" in
true)
	echo "(Feeding myself to $newsh $reason.)"
	case "$0" in
	Configure|*/Configure) exec $newsh $0 "$@";;
	*) exec $newsh Configure "$@";;
	esac
	;;
esac

: Configure runs within the UU subdirectory
test -d .config/UU || mkdir -p .config/UU
unset CDPATH
cd .config/UU && rm -f ./*

eunicefix=''
g4compiler=''
g4osname=''
g4system=''
hint=''
myuname=''
osname=''
osvers=''
Author=''
Date=''
Header=''
Id=''
Locker=''
Log=''
RCSfile=''
Revision=''
Source=''
State=''
cf_by=''
cf_time=''
contains=''
d_portable=''
g4base=''
g4conf=''
g4include=''
g4install=''
g4workdir=''
g4bin=''
g4lib=''
g4tmp=''
g4data=''
g4ledata=''
g4levelgammadata=''
g4neutronhpcrosssections=''
g4radioactivedata=''
g4clhep_base_dir=''
g4clhep_include_dir=''
g4clhep_lib=''
g4clhep_lib_dir=''
g4global=''
g4granular=''
g4lib_use_granular=''
g4debug=''
g4lib_build_shared=''
g4lib_build_static=''
g4lib_use_shared=''
g4lib_use_static=''
g4_build_wo_session=''
g4ui_build_gag_session=''
g4ui_build_terminal_session=''
g4ui_build_win32_session=''
g4ui_build_xaw_session=''
g4ui_build_xm_session=''
g4ui_use_gag=''
g4ui_use_tcsh=''
g4ui_use_terminal=''
g4ui_use_win32=''
g4ui_use_wo=''
g4ui_use_xaw=''
g4ui_use_xm=''
g4vis_build_asciitree_driver=''
g4vis_build_dawn_driver=''
g4vis_build_dawnfile_driver=''
g4vis_build_oiwin32_driver=''
g4vis_build_oix_driver=''
g4vis_build_opacs_driver=''
g4vis_build_openglwin32_driver=''
g4vis_build_openglx_driver=''
g4vis_build_openglxm_driver=''
g4vis_build_raytracer_driver=''
g4vis_build_vrml_driver=''
g4vis_build_vrmlfile_driver=''
g4vis_use_asciitree=''
g4vis_use_dawn=''
g4vis_use_dawnfile=''
g4vis_use_oiwin32=''
g4vis_use_oix=''
g4vis_use_opacs=''
g4vis_use_openglwin32=''
g4vis_use_openglx=''
g4vis_use_openglxm=''
g4vis_use_raytracer=''
g4vis_use_vrml=''
g4vis_use_vrmlfile=''
g4use_hepodbms=''
g4wanalysis_build=''
g4wanalysis_build_jas=''
g4wanalysis_build_lab=''
g4wanalysis_build_lizard=''
g4wanalysis_use=''
g4wanalysis_use_jas=''
g4wanalysis_use_lab=''
g4wanalysis_use_lizard=''
lns=''
c=''
n=''
package=''
spackage=''
sh=''
sharpbang=''
shsharp=''
spitshell=''
src=''
startsh=''
CONFIG=''

define='define'
undef='undef'
smallmach='pdp11 i8086 z8000 i80286 iAPX286'
rmlist=''

: We must find out about Eunice early
eunicefix=':'
if test -f /etc/unixtovms; then
	eunicefix=/etc/unixtovms
fi
if test -f /etc/unixtovms.exe; then
	eunicefix=/etc/unixtovms.exe
fi


: Find the basic shell for Bourne shell scripts
case "$sh" in
'')
	case "$SYSTYPE" in
	*bsd*|sys5*) xxx="/$SYSTYPE/bin/sh";;
	*) xxx='/bin/sh';;
	esac
	if test -f "$xxx"; then
		sh="$xxx"
	else
		: Build up a list and do a single loop so we can 'break' out.
		pth=`echo $PATH | sed -e "s/$p_/ /g"`
		for xxx in sh bash ksh pdksh ash; do
			for p in $pth; do
				try="$try ${p}/${xxx}"
			done
		done
		for xxx in $try; do
			if test -f "$xxx"; then
				sh="$xxx";
				break
			elif test -f "$xxx.exe"; then
				sh="$xxx";
				break
			fi
		done
	fi
	;;
esac

case "$sh" in
'')	cat <<EOM >&2
$me:  Fatal Error:  I can't find a Bourne Shell anywhere.  

Usually it's in /bin/sh.
Please contact Serguei.Sadilov@cern.ch and 
we'll try to straighten this all out.
EOM
	exit 1
	;;
esac

: see if sh knows # comments
if `$sh -c '#' >/dev/null 2>&1`; then
	shsharp=true
	spitshell=cat
	xcat=/bin/cat
	test -f $xcat || xcat=/usr/bin/cat
	echo "#!$xcat" >try
	$eunicefix try
	chmod +x try
	./try > today
	if test -s today; then
		sharpbang='#!'
	else
		echo "#! $xcat" > try
		$eunicefix try
		chmod +x try
		./try > today
		if test -s today; then
			sharpbang='#! '
		else
			sharpbang=': use '
		fi
	fi
else
	echo " "
	echo "Your $sh doesn't grok # comments--I will strip them later on."
	shsharp=false
	cd ..
	echo "exec grep -v '^[ 	]*#'" >spitshell
	chmod +x spitshell
	$eunicefix spitshell
	spitshell=`pwd`/spitshell
	cd UU
	echo "I presume that if # doesn't work, #! won't work either!"
	sharpbang=': use '
fi
rm -f try today

: figure out how to guarantee sh startup
case "$startsh" in
'') startsh=${sharpbang}${sh} ;;
*)
esac
cat >try <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS

chmod +x try
$eunicefix try
if ./try; then
	: echo "Yup, it does."
else
	echo "Hmm... '$startsh' does not guarantee sh startup..."
	echo "You may have to fix up the shell scripts to make sure $sh runs them."
fi
rm -f try

: produce awk script to parse command line options
cat >options.awk <<'EOF'
BEGIN {
	optstr = "dD:eEf:hKOrsSU:V";	# getopt-style specification

	len = length(optstr);
	for (i = 1; i <= len; i++) {
		c = substr(optstr, i, 1);
		if (i < len) a = substr(optstr, i + 1, 1); else a = "";
		if (a == ":") {
			arg[c] = 1;
			i++;
		}
		opt[c] = 1;
	}
}
{
	expect = 0;
	str = $0;
	if (substr(str, 1, 1) != "-") {
		printf("'%s'\n", str);
		next;
	}
	len = length($0);
	for (i = 2; i <= len; i++) {
		c = substr(str, i, 1);
		if (!opt[c]) {
			printf("-%s\n", substr(str, i));
			next;
		}
		printf("-%s\n", c);
		if (arg[c]) {
			if (i < len)
				printf("'%s'\n", substr(str, i + 1));
			else
				expect = 1;
			next;
		}
	}
}
END {
	if (expect)
		print "?";
}
EOF

: process the command line options
set X `for arg in "$@"; do echo "X$arg"; done |
	sed -e s/X// | awk -f options.awk`
eval "set $*"
shift
rm -f options.awk

: set up default values
fastread=''
reuseval=false
config_sh=''
alldone=''
error=''
silent=''
extractsh=''
override=''
knowitall=''
rm -f optdef.sh
cat >optdef.sh <<EOS
$startsh
EOS


: option parsing
while test $# -gt 0; do
	case "$1" in
	-d) shift; fastread=yes;;
	-e) shift; alldone=cont;;
	-install) shift; install=yes;;
	-f)
		shift
		cd ../..
		if test -r "$1"; then
			config_sh="$1"
		else
			echo "$me: cannot read config file $1." >&2
			error=true
		fi
		cd .config/UU
		shift;;
	-h) shift; error=true;;
	-r) shift; reuseval=true;;
	-s) shift; silent=true; realsilent=true;;
	-E) shift; alldone=exit;;
	-K) shift; knowitall=true;;
	-O) shift; override=true;;
	-S) shift; silent=true; extractsh=true;;
	-D)
		shift
		case "$1" in
		*=)
			echo "$me: use '-U symbol=', not '-D symbol='." >&2
			echo "$me: ignoring -D $1" >&2
			;;
		*=*) echo "$1" | \
				sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;;
		*) echo "$1='define'" >> optdef.sh;;
		esac
		shift
		;;
	-U)
		shift
		case "$1" in
		*=) echo "$1" >> optdef.sh;;
		*=*)
			echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2
			echo "$me: ignoring -U $1" >&2
			;;
		*) echo "$1='undef'" >> optdef.sh;;
		esac
		shift
		;;
	-V) echo "$me generated by metaconfig 3.0 PL70." >&2
		exit 0;;
	--) break;;
	-*) echo "$me: unknown option $1" >&2; shift; error=true;;
	*) break;;
	esac
done

case "$error" in
true)
	cat >&2 <<EOM
Usage: $me [-dehrsEKOSV] [-install] [-f config.sh] [-D symbol] [-D symbol=value]
                 [-U symbol] [-U symbol=]
  -d : use defaults for all answers.
  -e : go on without questioning past the production of config.sh.
  -install : start configuration AND installation of Geant4 libraries. 
  -f : specify an alternate default configuration file.
  -h : print this help message and exit (with an error status).
  -r : reuse C symbols value if possible (skips costly nm extraction).
  -s : silent mode, only echoes questions and essential information.
  -D : define symbol to have some value:
         -D symbol         symbol gets the value 'define'
         -D symbol=value   symbol gets the value 'value'
  -E : stop at the end of questions, after having produced config.sh.
  -K : do not use unless you know what you are doing.
  -O : let -D and -U override definitions from loaded configuration file.
  -S : perform variable substitutions on all .SH files (can mix with -f)
  -U : undefine symbol:
         -U symbol    symbol gets the value 'undef'
         -U symbol=   symbol gets completely empty
  -V : print version number and exit (with a zero status).
EOM
	exit 1
	;;
esac

: Sanity checks
case "$fastread$alldone" in
yescont|yesexit) ;;
*)
	if test ! -t 0; then
		echo "Say 'sh Configure', not 'sh <Configure'"
		exit 1
	fi
	;;
esac

exec 4>&1
case "$silent" in
true) exec 1>/dev/null;;
esac

: run the defines and the undefines, if any, but leave the file out there...
touch optdef.sh
. ./optdef.sh

: set package name
package=g4conf

: Some greps do not return status, grrr.
echo "grimblepritz" >grimble
if grep blurfldyick grimble >/dev/null 2>&1 ; then
	contains=contains
elif grep grimblepritz grimble >/dev/null 2>&1 ; then
	contains=grep
else
	contains=contains
fi
rm -f grimble
: the following should work in any shell
case "$contains" in
contains*)
	echo " "
	echo "Grep doesn't return a status!!  Attempting remedial action."
	cat >contains <<'EOSS'
grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
EOSS
chmod +x contains
esac

: first determine how to suppress newline on echo command
echo " "
#echo "Checking echo to see how to suppress newlines..."
(echo "hi there\c" ; echo " ") >.echotmp
if $contains c .echotmp >/dev/null 2>&1 ; then
#	echo "...using -n."
	n='-n'
	c=''
else
#	cat <<'EOM'
#...using \c
#EOM
	n=''
	c='\c'
fi
#echo $n "The star should be here-->$c"
#echo '*'
rm -f .echotmp

: compute the number of columns on the terminal for proper question formatting
case "$COLUMNS" in
'') COLUMNS='80';;
esac

: set up the echo used in my read
myecho="case \"\$xxxm\" in
'') echo $n \"\$rp $c\" >&4;;
*) case \"\$rp\" in
	'') echo $n \"[\$xxxm] $c\";;
	*)
		if test \`echo \"\$rp [\$xxxm]  \" | wc -c\` -ge $COLUMNS; then
			echo \"\$rp\" >&4
			echo $n \"[\$xxxm] $c\" >&4
		else
			echo $n \"\$rp [\$xxxm] $c\" >&4
		fi
		;;
	esac;;
esac"

: now set up to do reads with possible shell escape and default assignment
cat <<EOSC >myread
$startsh
xxxm=\$dflt
$myecho
ans='!'
case "\$fastread" in
yes) case "\$dflt" in
	'') ;;
	*) ans='';
		case "\$silent-\$rp" in
		true-) ;;
		*) echo " " >&4;;
		esac;;
	esac;;
*) case "\$silent" in
	true) case "\$rp" in
		'') ans='';;
		esac;;
	esac;;
esac
while expr "X\$ans" : "X!" >/dev/null; do
	read answ
	set x \$xxxm
	shift
	aok=''; eval "ans=\\"\$answ\\"" && aok=y
	case  "\$answ" in
	"!")
		sh 1>&4
		echo " "
		$myecho
		;;
	!*)
		set x \`expr "X\$ans" : "X!\(.*\)\$"\`
		shift
		sh 1>&4 -c "\$*"
		echo " "
		$myecho
		;;
	"\$ans")
		case "\$ans" in
		\\&*)
			set x \`expr "X\$ans" : "X&\(.*\)\$"\`
			shift
			case "\$1" in
			-d)
				fastread=yes
				echo "(OK, I'll run with -d after this question.)" >&4
				;;
			-*)
				echo "*** Sorry, \$1 not supported yet." >&4
				;;
			esac
			$myecho
			ans=!
			;;
		esac;;
	*)
		case "\$aok" in
		y)
			echo "*** Substitution done -- please confirm."
			xxxm="\$ans"
			ans=\`echo $n "\$ans$c" | tr '\012' ' '\`
			xxxm="\$ans"
			ans=!
			;;
		*)
			echo "*** Error -- try again."
			ans=!
			;;
		esac
		$myecho
		;;
	esac
	case "\$ans\$xxxm\$nostick" in
	'')
		ans=!
		$myecho
		;;
	esac
done
case "\$ans" in
'') ans="\$xxxm";;
esac
EOSC

: Find the path to the source tree
case "$src" in
'') src=`echo $0 | sed -e 's%/[^/][^/]*$%%'`
#echo "src=$src"
;;
esac
case "$src" in
'')
	src=.
	rsrc=..
	;;
/*) rsrc="$src/.."
#echo "rsrc=$rsrc"
;;
./*) 	cur_dir=`pwd`
	cd ../../$src
	src=`pwd`
	cd $cur_dir
	rsrc="$src/.."
rsrc="$src/.."
#echo "src=$src"
#echo "rsrc=$rsrc"
;;
*) rsrc="../../$src"
#echo "rsrc=$rsrc"
;;
esac
#cur_dir=`pwd`
#echo "cur_dir=$cur_dir"
if test -f $src/Configure && \
	$contains "^package=$package" $src/Configure >/dev/null 2>&1
then
   : found it, so we are ok.
else
	rsrc=''
	for src in . .. ../.. ../../.. ../../../..; do
		if test -f ../../$src/Configure && \
			$contains "^package=$package" ../../$src/Configure >/dev/null 2>&1
		then
			rsrc=../../$src
			break
		fi
	done
fi
case "$rsrc" in
'')
	echo " "
#	dflt=
#	rp="Directory where sources for $package are located?"
#	. ./myread
#	src="$ans"
	rsrc="$src"
#echo "src=$src"
#echo "rsrc=$rsrc"
	if test -f $rsrc/Configure && \
		$contains "^package=$package" $rsrc/Configure >/dev/null 2>&1
	then
		echo "Ok, I've found them under $src"
	else
		echo "Sorry, I can't seem to be able to locate $package sources." >&4
		echo "Please, use absolute path or relative with './' to Configure." >&4
		exit 1
	fi
	;;
../../.) ;;
*)
	echo " "
	echo "Sources for $package found in $src" >&4
	;;
esac

: script used to extract .SH files with variable substitutions
cat >extract <<'EOS'
CONFIG=true
#echo "Doing variable substitutions on .SH files..."
if test -f $src/MANIFEST; then
	set x `awk '{print $1}' <$src/MANIFEST | grep '\.SH'`
else
#	echo "(Looking for .SH files under the source directory.)"
	set x `(cd $src; find ./config/scripts -name "*.SH" -print)`
fi
shift
case $# in
0) set x `(cd $src; echo *.SH)`; shift;;
esac
if test ! -f $src/$1; then
	shift
fi
mkdir_p='
name=$1;
create="";
while test $name; do
	if test ! -d "$name"; then
		create="$name $create";
		name=`echo $name | sed -e "s|^[^/]*$||"`;
		name=`echo $name | sed -e "s|\(.*\)/.*|\1|"`;
	else
		name="";
	fi;
done;
for file in $create; do
	mkdir $file;
done
'
for file in $*; do
	case "$src" in
	".")
		case "$file" in
		*/*)
			dir=`expr X$file : 'X\(.*\)/'`
			file_SH=`expr X$file : 'X.*/\(.*\)'`
			file_EX=`expr X$file : 'X.*/\(.*\).SH'`
			(cd $dir && . ./$file_SH && mkdir -p $abssrc/.config/bin/$g4system && mv $file_EX $abssrc/.config/bin/$g4system)
#			echo Sergei_1
#			echo "file_SH=$file_SH"
#			echo "file_EX=$file_EX"
#			echo "file=$file"
#			echo "dir=$dir"
#			echo "src=$src"
#			echo "g4system=$g4system"
#			echo Sergei_1
			;;
		*)
			file_SH=`expr X$file : 'X.*/\(.*\)'`
			file_EX=`expr X$file : 'X.*/\(.*\).SH'`
			(. ./$file && mkdir -p $abssrc/.config/bin/$g4system && mv file-SH $abssrc/.config/bin/$g4system)
#			echo Sergei_2
#			echo "file_SH=$file_SH"
#			echo "file_EX=$file_EX"
#			echo "file=$file"
#			echo "dir=$dir"
#			echo "src=$src"
#			echo "g4system=$g4system"
#			echo Sergei_2
			;;
		esac
		;;
	*)
		case "$file" in
		*/*)
			dir=`expr X$file : 'X\(.*\)/'`
			file_SH=`expr X$file : 'X.*/\(.*\)'`
			file_EX=`expr X$file : 'X.*/\(.*\)\.SH'`
			(set x $dir; shift; eval $mkdir_p)

			(sh <$src/$dir/$file_SH && mkdir -p $src/.config/bin/$g4system && mv $file_EX $src/.config/bin/$g4system)

#			echo Sergei_3
#			echo "dir=$dir"
#			echo "file=$file"

#			echo Sergei_3
			;;
		*)
			file_SH=`expr X$file : 'X.*/\(.*\)'`
			file_EX=`expr X$file : 'X.*/\(.*\)\.SH'`
			(sh <$src/$file && mkdir -p $src/.config/bin/$g4system && mv $file_EX $src/.config/bin/$g4system)
			echo Sergei_4
			;;
		esac
		;;
	esac
done
if test -f $src/config_h.SH; then
	if test ! -f config.h; then
	: oops, they left it out of MANIFEST, probably, so do it anyway.
	. $src/config_h.SH
	fi
fi
EOS

: extract files and exit if asked to do so
case "$extractsh" in
true)
	case "$realsilent" in
	true) ;;
	*) exec 1>&4;;
	esac
	case "$config_sh" in
	'') config_sh='$g4conf/config.sh'; config="$g4conf/config.sh";;
	/*) config="$g4conf/$config_sh";;
	*) config="$g4conf/$config_sh";;
	esac
	echo " "
	echo "Fetching answers from $config_sh..."
	. $config
	test "$override" && . ./optdef.sh
	echo " "
	cd ../..
	. .config/UU/extract
	rm -rf .config/UU
	echo "Done."
	exit 0
	;;
esac

: Eunice requires " " instead of "", can you believe it
echo " "
: Here we go...
if [ X$install = Xyes ] ; then
echo " "
echo " "
echo " "
echo "                --- Geant4 Toolkit Installation  ---"
echo " "
echo " "
echo " "
echo " "
else
echo " "
echo " "
echo " "
echo "                --- Geant4 Toolkit Installation  ---"
echo "                  (setting environments for USER )"
echo " "
echo " "
echo " "
fi

trap 'echo " ";rm -rf ../../.config/UU; test -d ../../.config/UU && rm -rf X $rmlist; exit 1' 1 2 3 15

: create .config dir to save info across Configure sessions
test -d ../.config || mkdir ../.config
cat >../.config/README <<EOF
This directory created by Configure to save information that should
persist across sessions for $package.

You may safely delete it if you wish.
EOF

: general instructions
needman=true
firsttime=true
user=`(logname) 2>/dev/null`
case "$user" in
'') user=`whoami 2>&1`;;
esac
if [ X$install = Xyes ] ; then
if $contains "^$user\$" ../../.config/instruct >/dev/null 2>&1; then
	firsttime=false
	echo " "
	rp='Would you like to see the instructions?'
	dflt=n
	. ./myread
	case "$ans" in
	[yY]*) ;;
	*) needman=false;;
	esac
fi
fi

if [ X$install = X ] ; then
needman=false
fi

if $needman; then
	cat <<EOH
 
This installation shell script will examine your system and ask you questions
to determine how the Geant4 Toolkit should be installed.  If you get stuck on
a question, you may use a ! shell escape to start a subshell or execute a
command.  Many of the questions will have default answers in square brackets;
typing carriage return will set the default.

On AFS it is allowed to specify either absolute or relative
paths (i.e. starting with the ~username construct).

EOH
	rp=''
	dflt='Type carriage return to continue'
	. ./myread
	cat <<'EOH'

The prompt used in this script allows you to use shell variables and backticks
in your answers. You may use $1, $2, etc...  to refer to the words in the
default answer, as if the default line was a set of arguments given to a
script shell. This means you may also use $* to repeat the whole default line.

Everytime there is a substitution, you will have to confirm.  If there is an
error (e.g. an unmatched backtick), the default answer will remain unchanged
and you will be prompted again.

Running 'Configure -d' will bypass nearly all the questions and
use the computed defaults (or answers saved in a configuration
previously generated).

Type 'Configure -h' for a list of options.

You may also start interactively and then answer '& -d' at any prompt to turn
on the non-interactive behaviour for the rest of the execution.

EOH
	. ./myread
	cat <<EOH

Much effort has been spent to ensure that this shell script will run on any
Unix system. If despite that you can't run Configure for some reason, you'll
have to set the proper environment variables by hand and follow the "manual"
installation as specified in the Geant4 Installation Guide.

EOH
	dflt='Type carriage return to continue'
	. ./myread
	case "$firsttime" in
	true) echo $user >>../../.config/instruct;;
	esac
fi

: find out where common programs are
#echo " "
#echo "Locating common programs..." >&4
cat <<EOSC >loc
$startsh
case \$# in
0) exit 1;;
esac
thing=\$1
shift
dflt=\$1
shift
for dir in \$*; do
	case "\$thing" in
	.)
	if test -d \$dir/\$thing; then
		echo \$dir
		exit 0
	fi
	;;
	*)
	for thisthing in \$dir/\$thing; do
		: just loop through to pick last item
	done
	if test -f \$thisthing; then
		echo \$thisthing
		exit 0
	elif test -f \$dir/\$thing.exe; then
		: on Eunice apparently
		echo \$dir/\$thing
		exit 0
	fi
	;;
	esac
done
echo \$dflt
exit 1
EOSC
chmod +x loc
$eunicefix loc
loclist="
awk
cat
expr
rm
sed
touch
tr
"
trylist="
date
gcc
ln
test
uname
"
pth=`echo $PATH | sed -e "s/$p_/ /g"`
pth="$pth /lib /usr/lib"
for file in $loclist; do
	eval xxx=\$$file
	case "$xxx" in
	/*|?:[\\/]*)
		if test -f "$xxx"; then
			: ok
		else
			echo "WARNING: no $xxx -- ignoring your setting for $file." >&4
			xxx=`./loc $file $file $pth`
		fi
		;;
	'') xxx=`./loc $file $file $pth`;;
	*) xxx=`./loc $xxx $xxx $pth`;;
	esac
	eval $file=$xxx
	eval _$file=$xxx
	case "$xxx" in
	/*)
		echo "$file is in $xxx." > /dev/null
		;;
	?:[\\/]*)
		echo "$file is in $xxx." > /dev/null
		;;
	*)
		echo "I don't know where '$file' is." >&4
		echo "Please, install it or fix your PATH settings!" >&4
		exit 1
		;;
	esac
done
#echo " "
#echo "Don't worry if any of the following aren't found..."
say=offhand
for file in $trylist; do
	eval xxx=\$$file
	case "$xxx" in
	/*|?:[\\/]*)
		if test -f "$xxx"; then
			: ok
		else
			echo "WARNING: no $xxx -- ignoring your setting for $file." >&4
			xxx=`./loc $file $file $pth`
		fi
		;;
	'') xxx=`./loc $file $file $pth`;;
	*) xxx=`./loc $xxx $xxx $pth`;;
	esac
	eval $file=$xxx
	eval _$file=$xxx
	case "$xxx" in
	/*)
		echo "$file is in $xxx." > /dev/null
		;;
	?:[\\/]*)
		echo "$file is in $xxx." > /dev/null
		;;
	*)
		echo "I don't see $file out there, $say."
		say=either
		;;
	esac
done
case "$egrep" in
egrep)
#	echo "Substituting grep for egrep."
	egrep=$grep
	;;
esac
case "$ln" in
ln)
#	echo "Substituting cp for ln."
	ln=$cp
	;;
esac
case "$test" in
test)
	echo "Hopefully test is built into your sh." > /dev/null
	;;
*)
	if `sh -c "PATH= test true" >/dev/null 2>&1`; then
		echo "Using the test built into your sh." > /dev/null
		test=test
		_test=test
	fi
	;;
esac
case "$echo" in
echo)
	echo "Hopefully echo is built into your sh." > /dev/null
	;;
'') ;;
*)
#	echo " "
#echo "Checking compatibility between $echo and builtin echo (if any)..." >&4
	$echo $n "hi there$c" >foo1
	echo $n "hi there$c" >foo2
	if cmp foo1 foo2 >/dev/null 2>&1; then
		echo "They are compatible.  In fact, they may be identical." > /dev/null
	else
		case "$n" in
		'-n') n='' c='\c';;
		*) n='-n' c='';;
		esac
		cat <<FOO
They are not compatible!  You are probably running ksh on a non-USG system.
I'll have to use $echo instead of the builtin, since Bourne shell doesn't
have echo built in and we may have to run some Bourne shell scripts.  That
means I'll have to use '$n$c' to suppress newlines now.

FOO
		$echo $n "The star should be here-->$c"
		$echo "*"
	fi
	$rm -f foo1 foo2
	;;
esac

: determine whether symbolic links are supported
#echo " "
$touch blurfl
if $ln -s blurfl sym > /dev/null 2>&1 ; then
#	echo "Symbolic links are supported." >&4
	lns="$ln -s"
else
#	echo "Symbolic links are NOT supported." >&4
	lns="$ln"
fi
$rm -f blurfl sym

: see whether [:lower:] and [:upper:] are supported character classes
#echo " "
up='[A-Z]'
low='[a-z]'
case "`echo AbyZ | $tr '[:lower:]' '[:upper:]' 2>/dev/null`" in
ABYZ)
#	echo "Good, your tr supports [:lower:] and [:upper:] to convert case." >&4
	up='[:upper:]'
	low='[:lower:]'
	;;
*)
#	echo "Your tr only supports [a-z] and [A-Z] to convert case." >&4
	;;
esac
: set up the translation script tr, must be called with ./tr of course
cat >tr <<EOSC
$startsh
case "\$1\$2" in
'[A-Z][a-z]') exec $tr '$up' '$low';;
'[a-z][A-Z]') exec $tr '$low' '$up';;
esac
exec $tr "\$@"
EOSC
chmod +x tr
$eunicefix tr

: Try to determine whether config.sh was made on this system
case "$config_sh" in
'')
myuname=`( ($uname -a) 2>/dev/null || hostname) 2>&1`

mygcc=`( ($g++ -v) 2>/dev/null) 2>&1`
myuname=`echo $myuname | $sed -e 's/^[^=]*=//' -e 's/\///g' | \
	./tr '[A-Z]' '[a-z]' | tr '\012' ' '`
newmyuname="$myuname"
dflt=n
case "$knowitall" in
'')
	if test -f ../config.sh; then
		if $contains myuname= ../config.sh >/dev/null 2>&1; then
			eval "`grep myuname= ../config.sh`"
		fi
		if test "X$myuname" = "X$newmyuname"; then
			dflt=y
		fi
	fi
	;;
*) dflt=y;;
esac

: Get old answers from old config file if Configure was run on the
: same system, otherwise use the hints.
hint=default
cd ../..

	if $test -d $src/hints ; then
	(cd $src/hints; ls -C *.sh 2> /dev/null) | $sed 's/\.sh/   /g' >&4 
	fi
	dflt=''
	: Half the following guesses are probably wrong... If you have better
	: tests or hints, please send them to Serguei.Sadilov@cern.ch
	: The metaconfig authors would also appreciate a copy...
	$test -f /irix && osname=irix
	$test -f /xenix && osname=sco_xenix
	$test -f /dynix && osname=dynix
	$test -f /dnix && osname=dnix
	$test -f /lynx.os && osname=lynxos
	$test -f /unicos && osname=unicos && osvers=`$uname -r`
	$test -f /unicosmk.ar && osname=unicosmk && osvers=`$uname -r`
	$test -f /bin/mips && /bin/mips && osname=mips
	$test -d /NextApps && set X `hostinfo | grep 'NeXT Mach.*:' | \
		$sed -e 's/://' -e 's/\./_/'` && osname=next && osvers=$4
	$test -d /usr/apollo/bin && osname=apollo
	$test -f /etc/saf/_sactab && osname=svr4
	$test -d /usr/include/minix && osname=minix
	if $test -d /MachTen; then
		osname=machten
		if $test -x /sbin/version; then
			osvers=`/sbin/version | $awk '{print $2}' |
			$sed -e 's/[A-Za-z]$//'`
		elif $test -x /usr/etc/version; then
			osvers=`/usr/etc/version | $awk '{print $2}' |
			$sed -e 's/[A-Za-z]$//'`
		else
			osvers="$2.$3"
		fi
	fi
	if $test -f $uname; then
		set X $myuname
		shift

		case "$5" in
		fps*) osname=fps ;;
		mips*)
			case "$4" in
			umips) osname=umips ;;
			*) osname=mips ;;
			esac;;
		[23]100) osname=mips ;;
		next*) osname=next ;;
		news*) osname=news ;;
		i386*)
			if $test -f /etc/kconfig; then
				osname=isc
				if test "$lns" = "ln -s"; then
					osvers=4
				elif $contains _SYSV3 /usr/include/stdio.h > /dev/null 2>&1 ; then
					osvers=3
				elif $contains _POSIX_SOURCE /usr/include/stdio.h > /dev/null 2>&1 ; then
					osvers=2
				fi
			fi
			;;
		esac

		case "$1" in
		aix) osname=aix
			tmp=`( (oslevel) 2>/dev/null || echo "not found") 2>&1`
			case "$tmp" in
			'not found') osvers="$4"."$3" ;;
			'<3240'|'<>3240') osvers=3.2.0 ;;
			'=3240'|'>3240'|'<3250'|'<>3250') osvers=3.2.4 ;;
			'=3250'|'>3250') osvers=3.2.5 ;;
			*) osvers=$tmp;;
			esac
			;;
		*dc.osx) osname=dcosx
			osvers="$3"
			;;
		dnix) osname=dnix
			osvers="$3"
			;;
		domainos) osname=apollo
			osvers="$3"
			;;
		dgux) osname=dgux 
			osvers="$3"
			;;
		dynixptx*) osname=dynixptx
			osvers="$3"
			;;
		freebsd) osname=freebsd 
			osvers="$3" ;;
		genix) osname=genix ;;
		hp*) osname=hpux 
			case "$3" in
			*.08.*) osvers=9 ;;
			*.09.*) osvers=9 ;;
			*.10.*) osvers=10 ;;
			*)	osvers="$3" ;;
			esac
			;;
		irix*) osname=irix
			case "$3" in
			4*) osvers=4 ;;
			5*) osvers=5 ;;
			*)	osvers="$3" ;;
			esac
			;;
		linux) osname=linux
			case "$3" in
			1*) osvers=1 ;;
			*)	osvers="$3" ;;
			esac
			;;
		netbsd*) osname=netbsd 
			osvers="$3"
			;;
		bsd386) osname=bsd386
			osvers=`$uname -r`
			;;
		next*) osname=next ;;
		solaris) osname=solaris
			case "$3" in
			5*) osvers=`echo $3 | $sed 's/^5/2/g'` ;;
			*)	osvers="$3" ;;
			esac
			;;
		sunos) osname=sunos
			case "$3" in
			5*) osname=solaris
				osvers=`echo $3 | $sed 's/^5/2/g'` ;;
			*)	osvers="$3" ;;
			esac
			;;
		titanos) osname=titanos
			case "$3" in
			1*) osvers=1 ;;
			2*) osvers=2 ;;
			3*) osvers=3 ;;
			4*) osvers=4 ;;
			*)	osvers="$3" ;;
			esac
			;;
		ultrix) osname=ultrix
			osvers="$3"
			;;
		osf1|mls+)	case "$5" in
				alpha)
					osname=dec_osf
					osvers=`echo "$3" | sed 's/^[vt]//'`
					;;
			hp*)	osname=hp_osf1	;;
			mips)	osname=mips_osf1 ;;
			esac
			;;
		uts) osname=uts 
			osvers="$3"
			;;
		qnx) osname=qnx
			osvers="$4"
			;;
		$2) case "$osname" in
			*isc*) ;;
			*freebsd*) ;;
			svr*)
				: svr4.x or possibly later
				case "svr$3" in	
				${osname}*)
					osname=svr$3
					osvers=$4
					;;
				esac
				case "$osname" in
				svr4.0)
					: Check for ESIX
					if test -f /stand/boot ; then
						eval `grep '^INITPROG=[a-z/0-9]*$' /stand/boot`
						if test -n "$INITPROG" -a -f "$INITPROG"; then
			isesix=`strings -a $INITPROG|grep 'ESIX SYSTEM V/386 Release 4.0'`
							if test -n "$isesix"; then
								osname=esix4
							fi
						fi
					fi
					;;
				esac
				;;
			*)	if test -f /etc/systemid; then
					osname=sco
					set `echo $3 | $sed 's/\./ /g'` $4
					if $test -f sco_$1_$2_$3.sh; then
						osvers=$1.$2.$3
					elif $test -f sco_$1_$2.sh; then
						osvers=$1.$2
					elif $test -f sco_$1.sh; then
						osvers=$1
					fi
				else
					case "$osname" in
					'') : Still unknown.  Probably a generic Sys V.
						osname="sysv"
						osvers="$3"
						;;
					esac
				fi
				;;
			esac
			;;
		*)	case "$osname" in
			'') : Still unknown.  Probably a generic BSD.
				osname="$1"
				osvers="$3"
				;;
			esac
			;;
		esac
	else
		if test -f /vmunix -a -f $src/hints/news_os.sh; then
			(what /vmunix | .config/UU/tr '[A-Z]' '[a-z]') > .config/UU/kernel.what 2>&1
			if $contains news-os .config/UU/kernel.what >/dev/null 2>&1; then
				osname=news_os
			fi
			$rm -f .config/UU/kernel.what
		elif test -d c:/.; then
			set X $myuname
			osname=os2
			osvers="$5"
		fi
	fi
	: Now look for a hint file osname_osvers, unless one has been
	: specified already.
	case "$hintfile" in
	''|' ')
		file=`echo "${osname}_${osvers}" | $sed -e 's@\.@_@g' -e 's@_$@@'`
		: Also try without trailing minor version numbers.
		xfile=`echo $file | $sed -e 's@_[^_]*$@@'`
		xxfile=`echo $xfile | $sed -e 's@_[^_]*$@@'`
		xxxfile=`echo $xxfile | $sed -e 's@_[^_]*$@@'`
		xxxxfile=`echo $xxxfile | $sed -e 's@_[^_]*$@@'`
		case "$file" in
		'') dflt=none ;;
		*)  case "$osvers" in
			'') dflt=$file
				;;
			*)  if $test -f $src/hints/$file.sh ; then
					dflt=$file
				elif $test -f $src/hints/$xfile.sh ; then
					dflt=$xfile
				elif $test -f $src/hints/$xxfile.sh ; then
					dflt=$xxfile
				elif $test -f $src/hints/$xxxfile.sh ; then
					dflt=$xxxfile
				elif $test -f $src/hints/$xxxxfile.sh ; then
					dflt=$xxxxfile
				elif $test -f "$src/hints/${osname}.sh" ; then
					dflt="${osname}"
				else
					dflt=none
				fi
				;;
			esac
			;;
		esac
		;;
	*)
		dflt=`echo $hintfile | $sed 's/\.sh$//'`
		;;
	esac

if [ X$install = Xnever ] ; then
	$cat <<EOM

You may give one or more space-separated answers, or "none" if appropriate.
If your OS version has no hints, DO NOT give a wrong version -- say "none".

EOM
	rp="Which of these apply, if any?"
	. .config/UU/myread
	tans=$ans
	for file in $tans; do
		if $test -f $src/hints/$file.sh; then
			. $src/hints/$file.sh
			$cat $src/hints/$file.sh >> .config/UU/config.sh
		elif $test X$tans = X -o X$tans = Xnone ; then
			: nothing
		else
			: Give one chance to correct a possible typo.
			echo "$file.sh does not exist"
			dflt=$file
			rp="hint to use instead?"
			. .config/UU/myread
			for file in $ans; do
				if $test -f "$src/hints/$file.sh"; then
					. $src/hints/$file.sh
					$cat $src/hints/$file.sh >> .config/UU/config.sh
				elif $test X$ans = X -o X$ans = Xnone ; then
					: nothing
				else
					echo "$file.sh does not exist -- ignored."
				fi
			done
		fi
	done
fi

	hint=recommended
	: Remember our hint file for later.
	if $test -f "$src/hints/$file.sh" ; then
		hintfile="$file"
	else
		hintfile=''
	fi
	: Sadilov: g4system.U - inserted here.
	: 'current' directory is where 'Configure' is started 
echo " "
case "$g4osname" in

'')
	case "$osname" in
		'aix')		g4osname=AIX
				;;
		'dec_osf')	g4osname=DEC
				;;
		'hpux')		g4osname=HP
				;;
		'linux')	g4osname=Linux
				;;
		'irix')		g4osname=SGI
				;;
		'sunos')	g4osname=SUN
				;;
	esac
esac

echo " "

case  "$g4compiler" in

'')	
	case "$g4osname" in
		'AIX')
				g4compiler=xlC
				;;
		'DEC')
				g4compiler=cxx
				;;
		'HP')
				g4compiler=aCC
				;;
		'Linux')
#				g4compiler=g++
# Assume if "gcc" is in place then "g++" is here
	gcccompiler=`( ($gcc -v) 1>/dev/null || echo "ERROR: There is no 'gcc' ('g++'?) compiler.") 2>&1`
				case $gcccompiler in
				*egcs*) g4compiler=egcs
				;;
				*2.96*) 
				echo "WARNING: Found version of 'g++' (2.96.XXX) is known to be buggy!"
				g4compiler="g++"
				;;
				*) g4compiler="g++"
				;;
				esac				

				;;
		'SGI')
				g4compiler=CC
				;;
		'SUN')
				g4compiler=CC
				;;
	esac
esac

if [ X$install = Xyes ] ; then
while test 1 = 1  ; do

g4message=`cat << EOM

Definition of G4SYSTEM variable.

1) OS		: $g4osname

2) Compiler	: $g4compiler

Select from list above (e.g. 2) 
EOM`

dflt="Press [Enter] for default settings"
rp=$g4message
. .config/UU/myread
gans=$ans

	case $gans in

	1) 
		case "$osname" in
			'aix')
					g4osnamerec=AIX
					;;
			'dec_osf')
					g4osnamerec=DEC
					;;
			'hpux')	
					g4osnamerec=HP
					;;
			'linux')
					g4osnamerec=Linux
					;;
			'irix')	
					g4osnamerec=SGI
					;;
			'sunos')
					g4osnamerec=SUN
					;;
		esac
		dflt=$g4osname
		rp="What is your OS'?"
		. .config/UU/myread
		tans=$ans

		if test X$tans != X$g4osnamerec ; then
		echo ""

cat << EOM

		You are running 'Configure' on NOT native platform!
		You are on your own way !!!

EOM

		dflt=$tans
		rp="Confirm your selection or set native '$g4osnamerec'!"
		. .config/UU/myread
		tans=$ans
		fi

		g4osname=$tans
		;;
	2) 
		case "$g4osname" in
			'AIX')
					g4compilerrec=xlC
					;;
			'DEC')
					g4compilerrec=cxx
					;;
			'HP')
					g4compilerrec=aCC
					;;
			'Linux')
					g4compilerrec=g++
					;;
			'SGI')
					g4compilerrec=CC
					;;
			'SUN')
					g4compilerrec=CC
					;;
		esac
		dflt=$g4compiler
		rp="Which C++ compiler?"
		. .config/UU/myread
		tans=$ans

		if test X$tans != X$g4compilerrec ; then
		echo ""

cat << EOM

		The recommmended compiler for this platform ($g4osname) is $g4compilerrec.
		You are on your own way !!!

EOM

		dflt=$tans
		rp="Confirm your selection or set recommended '$g4compilerrec'!"
		. .config/UU/myread
		tans=$ans
		fi

		g4compiler=$tans
		;;
#	[eE]) 
#		break
#		;;
	*) 
#		echo " "
		break
		;;
	esac
done
fi

#
# Ask about compiler used. 
#
g4system=$g4osname-$g4compiler

cat << EOM

G4SYSTEM is now set to $g4system.

EOM

cd .config/UU

myuname=`( ($uname -a) 2>/dev/null || hostname) 2>&1`
myuname=`echo $myuname | $sed -e 's/^[^=]*=//' -e 's/\///g' | \
	./tr '[A-Z]' '[a-z]' | tr '\012' ' '`
newmyuname="$myuname"
dflt=n

cd ../..
if [ X$install = X ] ; then
	if test -f $src/.config/bin/$g4system/env.sh; then
	cat >&2 <<EOM
---------------------------------------------------
The Geant4 toolkit installation was found.
The files env.[c]sh will be copied to your current directory.
For setting Geant4 environments you should make:

source env.csh

or

. env.sh

It will also check G4WORKDIR setting and set it to
your HOME if needed.
You can use these files also for further modifications
(adding your own environments).
---------------------------------------------------
EOM
	$rm -rf .config/UU

cp -i $src/.config/bin/$g4system/env.csh .
cp -i $src/.config/bin/$g4system/env.sh  .

	exit 1
else
	echo " "
	echo "WARNING: Geant4 is NOT installed yet!"
	echo "You (or the administrator if you have not enough privileges)"
	echo "should start with \$G4INSTALL/Configure -install."
	echo "(where \$G4INSTALL is Geant4 install directory)."
	echo " "
	$rm -rf .config/UU
	exit 1
	fi
fi
cd .config/UU

case "$knowitall" in
'')
	cd ../..
	if test -f $src/.config/bin/$g4system/config.sh; then
		if $contains myuname= $src/.config/bin/$g4system/config.sh >/dev/null 2>&1; then
			eval "`grep myuname= $src/.config/bin/$g4system/config.sh`"
		fi
		if test "X$myuname" = "X$newmyuname"; then
			dflt=y
		fi
	fi
	cd .config/UU
	;;
*) dflt=y;;
esac

cd ../..

if test -f $src/.config/bin/$g4system/config.sh; then
	echo " "
	rp="There exists a config.sh file. Shall I use it to set the defaults?"
	. .config/UU/myread
	case "$ans" in
	n*|N*) echo "OK, I'll ignore it."; mv $src/.config/bin/$g4system/config.sh $src/.config/bin/$g4system/config.sh.old;;
	*)  echo "Fetching default answers from your old config.sh file..." >&4
		tmp_n="$n"
		tmp_c="$c"
		tmp_sh="$sh"
		. $src/.config/bin/$g4system/config.sh
		cp $src/.config/bin/$g4system/config.sh .config/UU
		n="$tmp_n"
		c="$tmp_c"
		: Older versions did not always set $sh.  Catch re-use of such
		: an old config.sh.
		case "$sh" in
		'') sh="$tmp_sh" ;;
		esac
		hint=previous
		;;
	esac
fi

cd .config/UU
;;
*)
	echo " "
	echo "Fetching default answers from $config_sh..." >&4
	tmp_n="$n"
	tmp_c="$c"
	cd ../..
	cp $config_sh config.sh 2>/dev/null
	chmod +w config.sh
	. ./config.sh
	cd .config/UU
	cp ../config.sh .
	n="$tmp_n"
	c="$tmp_c"
	hint=previous
	;;
esac
test "$override" && . ./optdef.sh
myuname="$newmyuname"

: Restore computed paths
for file in $loclist $trylist; do
	eval $file="\$_$file"
done


: who configured the system
cf_time=`$date 2>&1`
cf_by=`(logname) 2>/dev/null`
case "$cf_by" in
"")
	cf_by=`(whoami) 2>/dev/null`
	case "$cf_by" in
	"") cf_by=unknown ;;
	esac ;;
esac

: decide how portable to be
case "$d_portable" in
"$define") dflt=y;;
*)	dflt=n;;
esac
$cat <<'EOH'
 
I can set things up so that your shell scripts and binaries are more portable,
at what may be a noticable cost in performance.  In particular, if you
ask to be portable, the following happens:

     1) Shell scripts will rely on the PATH variable rather than using
	the paths derived above.
     2) ~username interpretations will be done at run time rather than
	by Configure.

EOH
rp="Do you expect to run these scripts and binaries on multiple machines?"
. ./myread
case "$ans" in
	y*) d_portable="$define"
	;;
	*)  d_portable="$undef" ;;
esac

: set up shell script to do ~ expansion
cat >filexp <<EOSS
$startsh
: expand filename
case "\$1" in
 ~/*|~)
	echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
	;;
 ~*)
	if $test -f /bin/csh; then
		/bin/csh -f -c "glob \$1"
		failed=\$?
		echo ""
		exit \$failed
	else
		name=\`$expr x\$1 : '..\([^/]*\)'\`
		dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
		if $test ! -d "\$dir"; then
			me=\`basename \$0\`
			echo "\$me: can't locate home directory for: \$name" >&2
			exit 1
		fi
		case "\$1" in
		*/*)
			echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
			;;
		*)
			echo \$dir
			;;
		esac
	fi
	;;
*)
	echo \$1
	;;
esac
EOSS
chmod +x filexp
$eunicefix filexp

: now set up to get a file name
cat <<EOS >getfile
$startsh
EOS
cat <<'EOSC' >>getfile
tilde=''
fullpath=''
already=''
skip=''
none_ok=''
exp_file=''
nopath_ok=''
orig_rp="$rp"
orig_dflt="$dflt"

case "$fn" in
*\(*)
	expr $fn : '.*(\(.*\)).*' | tr ',' '\012' >getfile.ok
	fn=`echo $fn | sed 's/(.*)//'`
	;;
esac

case "$fn" in
*:*)
	loc_file=`expr $fn : '.*:\(.*\)'`
	fn=`expr $fn : '\(.*\):.*'`
	;;
esac

case "$fn" in
*~*) tilde=true;;
esac
case "$fn" in
*/*) fullpath=true;;
esac
case "$fn" in
*+*) skip=true;;
esac
case "$fn" in
*n*) none_ok=true;;
esac
case "$fn" in
*e*) exp_file=true;;
esac
case "$fn" in
*p*) nopath_ok=true;;
esac

case "$fn" in
*f*) type='File';;
*d*) type='Directory';;
*l*) type='Locate';;
esac

what="$type"
case "$what" in
Locate) what='File';;
esac

case "$exp_file" in
'')
	case "$d_portable" in
	"$define") ;;
	*) exp_file=true;;
	esac
	;;
esac

cd ../..
while test "$type"; do
	redo=''
	rp="$orig_rp"
	dflt="$orig_dflt"
	case "$tilde" in
	true) rp="$rp ";;
	esac
	. .config/UU/myread
	if test -f .config/UU/getfile.ok && \
		$contains "^$ans\$" .config/UU/getfile.ok >/dev/null 2>&1
	then
		value="$ans"
		ansexp="$ans"
		break
	fi
	case "$ans" in
	none)
		value=''
		ansexp=''
		case "$none_ok" in
		true) type='';;
		esac
		;;
	*)
		case "$tilde" in
		'') value="$ans"
			ansexp="$ans";;
		*)
			value=`.config/UU/filexp $ans`
			case $? in
			0)
				if test "$ans" != "$value"; then
					echo "(That expands to $value on this system.)"
				fi
				;;
			*) value="$ans";;
			esac
			ansexp="$value"
			case "$exp_file" in
			'') value="$ans";;
			esac
			;;
		esac
		case "$fullpath" in
		true)
			case "$ansexp" in
			/*) value="$ansexp" ;;
			*)
				redo=true
				case "$already" in
				true)
				echo "I shall only accept a full path name, as in /bin/ls." >&4
				echo "Use a ! shell escape if you wish to check pathnames." >&4
					;;
				*)
				echo "Please give a full path name, starting with slash." >&4
					case "$tilde" in
					true)
				echo "Note that using ~username is ok provided it expands well." >&4
						already=true
						;;
					esac
				esac
				;;
			esac
			;;
		esac
		case "$redo" in
		'')
			case "$type" in
			File)
				if test -f "$ansexp"; then
					type=''
				elif test -r "$ansexp" || (test -h "$ansexp") >/dev/null 2>&1
				then
					echo "($value is not a plain file, but that's ok.)"
					type=''
				fi
				;;
			Directory)
				if test -d "$ansexp"; then
					type=''
				fi
				;;
			Locate)
				if test -d "$ansexp"; then
					echo "(Looking for $loc_file in directory $value.)"
					value="$value/$loc_file"
					ansexp="$ansexp/$loc_file"
				fi
				if test -f "$ansexp"; then
					type=''
				fi
				case "$nopath_ok" in
				true)	case "$value" in
					*/*) ;;
					*)	echo "Assuming $value will be in people's path."
						type=''
						;;
					esac
					;;
				esac
				;;
			esac

			case "$skip" in
			true) type='';
			esac

			case "$type" in
			'') ;;
			*)
				if test "$fastread" = yes; then
					dflt=y
				else
					dflt=n
				fi
				rp="$what $value doesn't exist.  Use that name anyway?"
				. .config/UU/myread
				dflt=''
				case "$ans" in
				y*) type='';;
				*) echo " ";;
				esac
				;;
			esac
			;;
		esac
		;;
	esac
done
cd .config/UU
ans="$value"
rp="$orig_rp"
dflt="$orig_dflt"
rm -f getfile.ok
EOSC

echo " "

#echo "SSS"
#echo `pwd`
#echo "SSS"

if [ X$src = X. ] ; then
	cd ../..
	abssrc=`pwd`
	cd .config/UU
else
	abssrc=$src
fi

case "$g4conf" in
'')
	g4conf=$abssrc/.config/bin/$g4system
	;;
esac

#echo "g4conf=$g4conf"

case "$g4install" in
'')
	g4install=$HOME/geant4
	;;
esac

case "$g4workdir" in
'')
	g4workdir=$g4install
	;;
esac

case "$g4includes_flag" in
'')
	g4includes_flag=n
	;;
esac

case "$g4include" in
'')
	g4include=$g4install/include
	;;
esac

g4message=`cat << EOM

Where is Geant4 installed?
EOM`

#dflt="NO DEFAULT ANSWER"
dflt=$g4install
fn='d~'
rp=$g4message
. ./getfile
g4install=$ans
g4workdir=$g4install

g4message=`cat << EOM

Do you want to copy all Geant4 headers 
in one directory?
EOM`

#dflt="NO DEFAULT ANSWER"
dflt=$g4includes_flag
#fn='d~'
rp=$g4message
. ./myread
g4includes_flag=$ans

if [ X$g4includes_flag = Xy ] ; then

g4message=`cat << EOM

Where will be directory to copy all Geant4 headers?
EOM`

#dflt="NO DEFAULT ANSWER"
dflt=$g4install/include
fn='d~+'
rp=$g4message
. ./getfile
g4include=$ans

fi

#if test "X$g4include" = "X[NOT DEFINED]" ; then
#g4include=""
#fi

echo " "

case "$g4tmp" in
'')
	g4tmp=$g4workdir/tmp
	;;
esac

case "$g4lib" in
'')
	g4lib=$g4workdir/lib
	;;
esac

while test 1 = 1  ; do

g4message=`cat << EOM

(OPTIONAL) You can now customise installation directories:
  G4TMP - tmp/ containing temporary dependency (.d) and object (.o) files;
  G4LIB - lib/ containing final static (.a) or shared (.so) libraries;

1) G4TMP:		$g4tmp

2) G4LIB:		$g4lib

Select from list above (e.g. 2) 
EOM`

#dflt="NO DEFAULT ANSWER"
dflt="Press [Enter] for default settings"
#fn='d~'
rp=$g4message
. ./myread
gans=$ans


	case $gans in

	1) 
		dflt=$g4tmp
		fn='d~+'
		rp="Where will be your Geant4 tmp directory?"
		. ./getfile
		g4tmp=$ans
		;;
	2) 
		dflt=$g4lib
		fn='d~+'
		rp="Where will be your Geant4 lib directory?"
		. ./getfile
		g4lib=$ans
		;;
#	3) 
#		dflt=$g4bin
#		fn='d~+'
#		rp="Where will be your Geant4 bin directory?"
#		. ./getfile
#		g4bin=$ans
#		;;

#	[eE]) 
#		break
#		;;
	*) 
		break
#		echo " "
		;;
	esac
done

echo " "

case "$g4data" in
'')
	g4data=$g4install/data
	;;
esac

case "$g4levelgammadata" in
'')
	g4levelgammadata=$g4data/PhotonEvaporation
	;;
esac

case "$g4radioactivedata" in
'')
	g4radioactivedata=$g4data/RadiativeDecay
	;;
esac

case "$g4ledata" in
'')
	g4ledata=$g4install/../G4EMLOW0.5
	;;
esac

case "$g4neutronhpcrosssections" in
'')
	g4neutronhpcrosssections=$g4install/../G4NDL3.5
	;;
esac

while test 1 = 1  ; do

g4message=`cat << EOM

Please, specify directories where the Geant4 data is installed:

1) G4LEVELGAMMADATA:		$g4levelgammadata

2) G4RADIOACTIVEDATA:		$g4radioactivedata

Data which is not part of the default Geant4 distribution:

3) G4LEDATA:			$g4ledata

4) NeutronHPCrossSections:	$g4neutronhpcrosssections

Select from list above (e.g. 2) 
EOM`

#dflt="NO DEFAULT ANSWER"
dflt="Press [Enter] for default settings"
#fn='d~'
rp=$g4message
. ./myread
gans=$ans


	case $gans in

	1) 
		dflt=$g4levelgammadata
		fn='f~'
		rp="Where is Geant4 PhotonEvaporation data installed?"
		. ./getfile
		g4levelgammadata=$ans
		;;
	2) 
		dflt=$g4radioactivedata
		fn='f~'
		rp="Where is Geant4 RadiativeDecay data installed?"
		. ./getfile
		g4radioactivedata=$ans
		;;
	3) 
		dflt=$g4ledata
		fn='f~'
		rp="Where is G4EMLOW0.5 data installed ?"
		. ./getfile
		g4ledata=$ans
		;;
	4) 
		dflt=$g4neutronhpcrosssections
		fn='f~'
		rp="Where is G4NDL3.5 installed?"
		. ./getfile
		g4neutronhpcrosssections=$ans
		;;
#	[eE]) 
#		break
#		;;
	*) 
		break
#		echo " "
		;;
	esac
done

echo " "
case "$g4clhep_base_dir" in
'')
	g4clhep_base_dir=/usr/local
	;;
esac

case "$g4clhep_include_dir" in
'')
	g4clhep_include_dir=$g4clhep_base_dir/include
	;;
esac

case "$g4clhep_lib_dir" in
'')
	g4clhep_lib_dir=$g4clhep_base_dir/lib
	;;
esac

case "$g4clhep_lib" in
'')
	g4clhep_lib=CLHEP
	;;
esac

#while test 1 = 1  ; do

g4message=`cat << EOM

Please, specify where CLHEP is installed:

CLHEP_BASE_DIR:			$g4clhep_base_dir

According to it will be set:

CLHEP_INCLUDE_DIR		
CLHEP_LIB_DIR			
CLHEP_LIB		

You will be asked about customizing these next.
EOM`


#dflt="Press [Enter] for default settings"
#fn='d~'
rp=$g4message
#. ./myread
#gans=$ans

#	case $gans in

#	1) 
		dflt=$g4clhep_base_dir
		fn='d~'
#		rp="Where is CLHEP installed?"
		. ./getfile
		g4clhep_base_dir=$ans
		g4clhep_include_dir=$ans/include
		g4clhep_lib_dir=$ans/lib
#		;;
#	2) 
#		dflt=$g4clhep_include_dir
#		fn='d~'
#		rp="Where is CLHEP include directory?"
#		. ./getfile
#		g4clhep_include_dir=$ans
#		;;
#	3) 
#		dflt=$g4clhep_lib_dir
#		fn='d~'
#		rp="Where is CLHEP lib directory?"
#		. ./getfile
#		g4clhep_lib_dir=$ans
#		;;
#	4) 
#		dflt=$g4clhep_lib
#		rp="What is CLHEP lib title?"
#		. ./myread
#		g4clhep_lib=$ans
#		;;
##	[eE]) 
##		break
##		;;
#	*) 
#		echo " "
#		break
#		;;
#	esac
#done

while test 1 = 1  ; do

g4message=`cat << EOM

You can customize paths of you CLHEP installation:

1) CLHEP_INCLUDE_DIR:		$g4clhep_include_dir
2) CLHEP_LIB_DIR:		$g4clhep_lib_dir
3) CLHEP_LIB:			$g4clhep_lib

Select from list above (e.g. 2) 
EOM`


dflt="Press [Enter] for default settings"
#fn='d~'
rp=$g4message
. ./myread
gans=$ans

	case $gans in

	1) 
		dflt=$g4clhep_include_dir
		fn='d~'
		rp="Where is CLHEP include directory?"
		. ./getfile
		g4clhep_include_dir=$ans
		;;
	2) 
		dflt=$g4clhep_lib_dir
		fn='d~'
		rp="Where is CLHEP lib directory?"
		. ./getfile
		g4clhep_lib_dir=$ans
		;;
	3) 
		dflt=$g4clhep_lib
		rp="What is CLHEP lib title?"
		. ./myread
		g4clhep_lib=$ans
		;;
#	[eE]) 
##		break
##		;;
	*) 
#		echo " "
		break
		;;
	esac
done



echo " "
case "$g4global" in
'')
	g4global=n
	;;
esac

echo " "
# By default it's 'grabular'!
case "$g4granular" in
'')
	g4granular=y
	;;
esac

echo " "
# Will be set (if needed) in GNUmakefile!
case "$g4lib_use_granular" in
'')
	g4lib_use_granular=n
	;;
esac

#
# Ask about g4global - default "(empty)". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

Do you want to build 'global' compound libraries?
EOM`

dflt=$g4global
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4global=n
		g4granular=y
		g4lib_use_granular=n
		break
		;;
	y*|Y*) 
		g4global=y
		g4granular=n
		g4lib_use_granular=n
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done

if [ X$g4global = Xy ] ; then
#
# Ask about g4granular - default "n". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

Granular libraries are used by defaults, you asked to build global
compound libraries. Do you want to build 'granular' libraries too?
EOM`

dflt=$g4granular
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4granular=n
		break
		;;
	y*|Y*) 
		g4granular=y
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done

if [ X$g4granular = Xy ] ; then
#
# Ask about g4lib_use_granular - default "n". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

Global libraries are used by defaults, you asked to build global
compound libraries and granular libraries. 
Do you want to use 'granular' libraries instead?
EOM`

dflt=$g4lib_use_granular
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		break
		;;
	y*|Y*) 
		g4lib_use_granular=y
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done
fi
fi

### End file - without will be problem! Check in others...


echo " "
case "$g4debug" in
'')
	g4debug=""
	;;
esac

#
# Ask about g4debug - default "(empty)". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

Do you want to compile libraries in DEBUG mode (-g)?
EOM`

dflt="n"
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		break
		;;
	y*|Y*) 
		g4debug=1
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done


echo " "
case "$g4lib_build_shared" in
'')
	g4lib_build_shared=n
	;;
esac

echo " "
case "$g4lib_build_static" in
'')
	g4lib_build_static=n
	;;
esac

echo " "
case "$g4lib_use_shared" in
'')
	g4lib_use_shared=n
	;;
esac

echo " "
case "$g4lib_use_static" in
'')
	g4lib_use_static=n
	;;
esac

#
# Ask about building of SHARED|STATIC libraries - default STATIC. 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

By default 'static' (.a) libraries are built.

Do you want to build 'shared' (.so) libraries?
EOM`

dflt=$g4lib_build_shared
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		break
		;;
	y*|Y*) 
		g4lib_build_shared=y
#		g4lib_build_static=""
#		g4lib_use_shared=1
#		g4lib_use_static=""
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done

if [ X$g4lib_build_shared = Xy ] ; then
#
# Ask about g4lib_build_static - default "n". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

You selected to build 'shared' (.so) libraries. 
Do you want to build 'static' (.a) libraries too?
EOM`

dflt=$g4lib_build_static
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		break
		;;
	y*|Y*) 
#		g4lib_build_shared=1
		g4lib_build_static=y
#		g4lib_use_shared=1
#		g4lib_use_static=""
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done

if [ X$g4lib_build_static = Xy ] ; then
#
# Ask about g4lib_use_static - default "n". 
#
echo ""

while test 1 = 1  ; do

g4message=`cat << EOM

You selected to build 'shared' (.so) and 'static' (.a) libraries. 
Do you want to use 'static' (.a) libraries?
EOM`

dflt=$g4lib_use_static
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		break
		;;
	y*|Y*) 
#		g4lib_build_shared=1
#		g4lib_build_static=1
#		g4lib_use_shared=1
		g4lib_use_static=y
		break
		;;
#	[eE]) 
#		break
#		;;
#	*) 
#		echo " "
#		break
#		;;
	esac
done
fi

fi


echo " "

case "$g4ui_none" in
'')
	g4ui_none=n
	;;
esac

# Set by default!
case "$g4ui_build_terminal_session" in
'')
	g4ui_build_terminal_session=y
	;;
esac

# Set by default!
case "$g4ui_use_terminal" in
'')
	g4ui_use_terminal=y
	;;
esac

# Set by default!
case "$g4ui_build_gag_session" in
'')
	g4ui_build_gag_session=y
	;;
esac

# Set by default!
case "$g4ui_use_gag" in
'')
	g4ui_use_gag=y
	;;
esac

case "$g4ui_build_xm_session" in
'')
	g4ui_build_xm_session=n
	;;
esac

case "$g4ui_use_xm" in
'')
	g4ui_use_xm=n
	;;
esac

case "$g4ui_build_xaw_session" in
'')
	g4ui_build_xaw_session=n
	;;
esac

case "$g4ui_use_xaw" in
'')
	g4ui_use_xaw=n
	;;
esac

case "$g4ui_build_wo_session" in
'')
	g4ui_build_wo_session=n
	;;
esac

case "$g4ui_use_wo" in
'')
	g4ui_use_wo=n
	;;
esac

case "$g4ui_build_win32_session" in
'')
	g4ui_build_win32_session=n
	;;
esac

case "$g4ui_use_win32" in
'')
	g4ui_use_win32=n
	;;
esac

# Set by default!
case "$g4ui_use_tcsh" in
'')
	g4ui_use_tcsh=y
	;;
esac

echo ""

g4message=`cat << EOM

  G4UI_NONE

If set, no UI sessions nor any UI libraries are built. This can be useful
when running a pure batch job or in a user framework having its own UI system.

EOM`

dflt=$g4ui_none
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4ui_none=n
		;;
	y*|Y*) 
		g4ui_none=y
		;;
	esac

case $g4ui_none in

n)

g4message=`cat << EOM

  G4UI_BUILD_TERMINAL_SESSION
  Specifies to include in kernel library a basic dumb terminal
  user interface (default).

  G4UI_USE_TERMINAL
  Specifies to use dumb terminal interface in the application to be
  built (default).
EOM`

dflt=$g4ui_use_terminal
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4ui_build_terminal_session=n
		g4ui_use_terminal=n
		;;
	y*|Y*) 
		g4ui_build_terminal_session=y
		g4ui_use_terminal=y
		;;
	esac

g4message=`cat << EOM

  G4UI_BUILD_GAG_SESSION
  Specifies to include in kernel library the GAG based
  user interface.

  G4UI_USE_GAG
  Specifies to use the GAG interface in the application to be
  built.
EOM`

dflt=$g4ui_use_gag
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4ui_build_gag_session=n
		g4ui_use_gag=n
		;;
	y*|Y*) 
		g4ui_build_gag_session=y
		g4ui_use_gag=y
		;;
	esac

g4message=`cat << EOM

  G4UI_BUILD_XAW_SESSION
  G4UI_USE_XAW

  Specifies to include and use the XAW interfaces in the
  application to be built.
  The XAW (X11 Athena Widget set) extensions are required to activate 
  and build this driver.
EOM`

dflt=$g4ui_use_xaw
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4ui_build_xaw_session=n
		g4ui_use_xaw=n
		;;
	y*|Y*) 
		g4ui_build_xaw_session=y
		g4ui_use_xaw=y
		;;
	esac

g4message=`cat << EOM

  G4UI_BUILD_XM_SESSION
  G4UI_USE_XM

  Specifies to include and use the XM Motif based user interfaces.
  The XM Motif extensions are required to activate and build this
  driver.

EOM`

dflt=$g4ui_use_xm
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4ui_build_xm_session=n
		g4ui_use_xm=n
		;;
	y*|Y*) 
		g4ui_build_xm_session=y
		g4ui_use_xm=y
		;;
	esac


g4message=`cat << EOM

  G4UI_BUILD_WIN32_SESSION
  G4UI_USE_WIN32

  Specifies to include and use the terminal interface for 
  Windows systems.

EOM`

dflt=$g4ui_use_win32
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4ui_build_win32_session=n
		g4ui_use_win32=n
		;;
	y*|Y*) 
		g4ui_build_win32_session=y
		g4ui_use_win32=y
		;;
	esac

g4message=`cat << EOM

  G4UI_BUILD_WO_SESSION
  G4UI_USE_WO

  Specifies to include in kernel library and use the OPACS WO terminal
  interface for the OPACS system. The OPACS tool must be installed
  to activate and build this driver !

EOM`

dflt=$g4ui_use_wo
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4ui_build_wo_session=n
		g4ui_use_wo=n
		;;
	y*|Y*) 
		g4ui_build_wo_session=y
		g4ui_use_wo=y
		;;
	esac

g4message=`cat << EOM

  G4UI_USE_TCSH
  Specifies to use the tcsh-style terminal in the application
  to be built.
EOM`

dflt=$g4ui_use_tcsh
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4ui_use_tcsh=n
		;;
	y*|Y*) 
		g4ui_use_tcsh=y
		;;
	esac

;;
esac


echo " "
case "$g4vis_none" in
'')
	g4vis_none=n
	;;
esac

case "$g4vis_build_openglwin32_driver" in
'')
	g4vis_build_openglwin32_driver=n
	;;
esac

case "$g4vis_use_openglwin32" in
'')
	g4vis_use_openglwin32=n
	;;
esac

case "$g4vis_build_oiwin32_driver" in
'')
	g4vis_build_oiwin32_driver=n
	;;
esac

case "$g4vis_use_oiwin32" in
'')
	g4vis_use_oiwin32=n
	;;
esac

case "$g4vis_build_dawn_driver" in
'')
	g4vis_build_dawn_driver=n
	;;
esac

case "$g4vis_use_dawn" in
'')
	g4vis_use_dawn=n
	;;
esac

# Set by default!
case "$g4vis_build_dawnfile_driver" in
'')
	g4vis_build_dawnfile_driver=y
	;;
esac

# Set by default!
case "$g4vis_use_dawnfile" in
'')
	g4vis_use_dawnfile=y
	;;
esac

case "$g4vis_build_opacs_driver" in
'')
	g4vis_build_opacs_driver=n
	;;
esac

case "$g4vis_use_opacs" in
'')
	g4vis_use_opacs=n
	;;
esac

case "$g4vis_build_openglx_driver" in
'')
	g4vis_build_openglx_driver=n
	;;
esac

case "$g4vis_use_openglx" in
'')
	g4vis_use_openglx=n
	;;
esac

case "$g4vis_build_openglxm_driver" in
'')
	g4vis_build_openglxm_driver=n
	;;
esac

case "$g4vis_use_openglxm" in
'')
	g4vis_use_openglxm=n
	;;
esac

case "$g4vis_build_oix_driver" in
'')
	g4vis_build_oix_driver=n
	;;
esac

case "$g4vis_use_oix" in
'')
	g4vis_use_oix=n
	;;
esac

# Set by default!
case "$g4vis_build_raytracer_driver" in
'')
	g4vis_build_raytracer_driver=y
	;;
esac

# Set by default!
case "$g4vis_use_raytracer" in
'')
	g4vis_use_raytracer=y
	;;
esac

case "$g4vis_build_vrml_driver" in
'')
	g4vis_build_vrml_driver=n
	;;
esac

case "$g4vis_use_vrml" in
'')
	g4vis_use_vrml=n
	;;
esac

# Set by default!
case "$g4vis_build_asciitree_driver" in
'')
	g4vis_build_asciitree_driver=y
	;;
esac

# Set by default!
case "$g4vis_use_asciitree" in
'')
	g4vis_use_asciitree=y
	;;
esac

# Set by default!
case "$g4vis_build_gagtree_driver" in
'')
	g4vis_build_gagtree_driver=y
	;;
esac

# Set by default!
case "$g4vis_use_gagtree" in
'')
	g4vis_use_gagtree=y
	;;
esac

echo ""

g4message=`cat << EOM

  G4VIS_NONE

If specified, no visualization drivers will be built or used.

EOM`

dflt=$g4vis_none
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_none=n
		;;
	y*|Y*) 
		g4vis_none=y
		;;
	esac

case $g4vis_none in

n)

g4message=`cat << EOM

  G4VIS_BUILD_OPENGLX_DRIVER
  G4VIS_USE_OPENGLX

It is an interface to the de facto standard 3D graphics library,
OpenGL. It is well suited for real-time fast visualization
and prototyping. The X11 version of the OpenGL libraries is
required.
EOM`

dflt=$g4vis_use_openglx
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_openglx_driver=n
		g4vis_use_openglx=n
		;;
	y*|Y*) 
		g4vis_build_openglx_driver=y
		g4vis_use_openglx=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_OPENGLXM_DRIVER
  G4VIS_USE_OPENGLXM

It is an interface to the de facto standard 3D graphics library,
OpenGL. It is well suited for real-time fast visualization
and prototyping. The X11 version of the OpenGL libraries and 
the Motif Xm extension is required.

EOM`

dflt=$g4vis_use_openglxm
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_openglxm_driver=n
		g4vis_use_openglxm=n
		;;
	y*|Y*) 
		g4vis_build_openglxm_driver=y
		g4vis_use_openglxm=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_OPENGLWIN32_DRIVER
  G4VIS_USE_OPENGLWIN32

It is an interface to the de facto standard 3D graphics library,
OpenGL. It is well suited for real-time fast visualization
and prototyping. The Windows version of the OpenGL libraries is
required.

EOM`

dflt=$g4vis_use_openglwin32
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_openglwin32_driver=n
		g4vis_use_openglwin32=n
		;;
	y*|Y*) 
		g4vis_build_openglwin32_driver=y
		g4vis_use_openglwin32=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_DAWN_DRIVER
  G4VIS_USE_DAWN

DAWN drivers are interfaces to the Fukui Renderer DAWN. DAWN is
a vectorized 3D PostScript processor suited to prepare technical
high quality outputs for presentation and/or documentation.

EOM`

dflt=$g4vis_use_dawn
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_dawn_driver=n
		g4vis_use_dawn=n
		;;
	y*|Y*) 
		g4vis_build_dawn_driver=y
		g4vis_use_dawn=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_OIX_DRIVER
  G4VIS_USE_OIX

This driver is based on the "Hepvis" class library.
The OpenInventor driver and the Hepvis class library are based
on OpenInventor technology for scientific visualization.
The X11 version of OpenInventor is required.

EOM`

dflt=$g4vis_use_oix
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_oix_driver=n
		g4vis_use_oix=n
		;;
	y*|Y*) 
		g4vis_build_oix_driver=y
		g4vis_use_oix=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_OIWIN32_DRIVER
  G4VIS_USE_OIWIN32

Specifies to build and use the driver for the free X11 version of
OpenInventor on Windows systems.
The Windows version of OpenInventor is required.

EOM`

dflt=$g4vis_use_oiwin32
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_oiwin32_driver=n
		g4vis_use_oiwin32=n
		;;
	y*|Y*) 
		g4vis_build_oiwin32_driver=y
		g4vis_use_oiwin32=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_DAWNFILE_DRIVER
  G4VIS_USE_DAWNFILE

DAWN drivers are interfaces to Fukui Renderer DAWN. It is a vectorized 3D 
PostScript processor, and so well suited to prepare technical high
quality outputs for presentation and/or documentation. 
The DAWNFILE driver sends 3D data to DAWN via an intermediate file, 
named g4.prim in the current directory. The file g4.prim is able to 
be re-visualized later without the help of Geant4. 
EOM`

dflt=$g4vis_use_dawnfile
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4vis_build_dawnfile_driver=n
		g4vis_use_dawnfile=n
		;;
	y*|Y*) 
		g4vis_build_dawnfile_driver=y
		g4vis_use_dawnfile=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_OPACS_DRIVER
  G4VIS_USE_OPACS

OPACS is a visualization environment based on X windows and OpenGL. 
It is written in ANSI C and is highly portable (UNIX, NT/X11, VMS). 
The OPACS tool is required to activate and build this driver.

EOM`

dflt=$g4vis_use_opacs
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_opacs_driver=n
		g4vis_use_opacs=n
		;;
	y*|Y*) 
		g4vis_build_opacs_driver=y
		g4vis_use_opacs=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_RAYTRACER_DRIVER
  G4VIS_USE_RAYTRACER

It performs ray-tracing visualization using the tracking routines of Geant4. 
It is, therefore, available for debugging tracking routines. 
It is well suited for photo-realistic high quality output for 
presentation, and for intuitive debugging of detector geometry. 
EOM`

dflt=$g4vis_use_raytracer
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4vis_build_raytracer_driver=n
		g4vis_use_raytracer=n
		;;
	y*|Y*) 
		g4vis_build_raytracer_driver=y
		g4vis_use_raytracer=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_VRML_DRIVER
  G4VIS_USE_VRML

These driver generate VRML files, which describe 3D scenes to be 
visualized with a proper VRML viewer.

EOM`

dflt=$g4vis_use_vrml
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4vis_build_vrml_driver=n
		g4vis_use_vrml=n
		;;
	y*|Y*) 
		g4vis_build_vrml_driver=y
		g4vis_use_vrml=y
		;;
	esac

g4message=`cat << EOM

  G4VIS_BUILD_VRMLFILE_DRIVER
  G4VIS_USE_VRMLFILE

This driver generates VRML files, which describe 3D scenes to be 
visualized with a proper VRML viewer, at either a local or a remote host. 
The VRMLFILE driver sends 3D data to your VRML viewer, which is running 
in the same host machine as Geant4, via an intermediate file named 
g4.wrl created in the current directory. This file is available for 
re-visualization afterwards. In visualization, you should specify a 
name of the VRML viewer by setting the environment variable G4VRML_VIEWER 
beforehand.
EOM`

dflt=$g4vis_use_vrmlfile
rp=$g4message
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4vis_build_vrmlfile_driver=n
		g4vis_use_vrmlfile=n
		;;
	y*|Y*) 
		g4vis_build_vrmlfile_driver=y
		g4vis_use_vrmlfile=y
		;;
	esac


g4message=`cat << EOM

  G4VIS_BUILD_ASCIITREE_DRIVER
  G4VIS_USE_ASCIITREE

Description????????????????????????
EOM`

dflt=$g4vis_use_asciitree
rp=$g4message
# Don't ask by default and set to 'y'!
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4vis_build_asciitree_driver=n
		g4vis_use_asciitree=n
		;;
	y*|Y*) 
		g4vis_build_asciitree_driver=y
		g4vis_use_asciitree=y
		;;
	esac


g4message=`cat << EOM

  G4VIS_BUILD_GAGTREE_DRIVER
  G4VIS_USE_GAGTREE

Description????????????????????????
EOM`

dflt=$g4vis_use_gagtree
rp=$g4message
# Don't ask by default and set to 'y'!
#. ./myread
#gans=$ans
gans=y

	case $gans in
	
	n*|N*) 
		g4vis_build_gagtree_driver=n
		g4vis_use_gagtree=n
		;;
	y*|Y*) 
		g4vis_build_gagtree_driver=y
		g4vis_use_gagtree=y
		;;
	esac

;;
esac


echo " "
case "$g4use_hepodbms" in
'')
	g4use_hepodbms=n
	;;
esac

g4message=`cat << EOM

G4USE_HEPODBMS
In Geant4, object persistency is provided as an optional category, so
that the users could be able to run Geant4 with or without a commercial 
ODBMS package. How to store and retrieve Geant4 events, hits and geometry 
objects is explained in documentation.

For setting this you should have an ODMG compliant database
(e.g. Objectivity/DB) installed and running on your system!
EOM`

dflt=$g4use_hepodbms
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4use_hepodbms=n
		;;
	y*|Y*) 
		g4use_hepodbms=y
		;;
	esac



echo " "

case "$g4wanalysis_use" in
'')
	g4wanalysis_use=n
	;;
esac

echo ""

g4message=`cat << EOM

  G4ANALYSIS_USE

Activates the configuration setup for allowing plugins to
analysis tools based on AIDA (Astract Interfaces for Data
Analysis). In order to use AIDA features and compliant analysis
tools, the proper environment for these tools will have to be
set (see documentation for the specific analysis tools).
EOM`

dflt=$g4wanalysis_use
rp=$g4message
. ./myread
gans=$ans

	case $gans in
	
	n*|N*) 
		g4wanalysis_use=n
		;;
	y*|Y*) 
		g4wanalysis_use=y
		;;
	esac


: end of configuration questions
echo " "
echo "End of configuration phase."
echo " "

: back to where it started
if test -d ../../.config/UU; then
	cd ../..
fi

: configuration may be patched via a 'config.over' file
if $test -f config.over; then
	echo " "
	dflt=y
	rp='A config.over file exists.  Do you wish to load it?'
	. .config/UU/myread
	case "$ans" in
	n*) echo "OK, I'll ignore it.";;
	*)	. ./config.over
		echo "Configuration settings have been loaded."
		;;
	esac
fi

: in case they want portability, strip down executable paths
case "$d_portable" in
"$define")
	echo " "
	echo "Stripping down executable paths..." >&4
	for file in $loclist $trylist; do
		eval $file="\$file"
	done
	;;
esac

: create config.sh file
echo " "
echo "Creating configuration setup file..." >&4
mkdir -p $g4conf
$spitshell <<EOT > $g4conf/config.sh
$startsh
#
# This file was produced by running the Configure script. It holds all the
# definitions figured out by Configure. Should you modify one of these values,
# do not forget to propagate your changes by running "Configure -der". You may
# instead choose to run each of the .SH files by yourself, or "Configure -S".
#

# Package name      : $package
# Source directory  : $src
# Configuration time: $cf_time
# Configured by     : $cf_by
# Target system     : $myuname

Author='$Author'
Date='$Date'
Header='$Header'
Id='$Id'
Locker='$Locker'
Log='$Log'
RCSfile='$RCSfile'
Revision='$Revision'
Source='$Source'
State='$State'
c='$c'
cf_by='$cf_by'
cf_time='$cf_time'
contains='$contains'
d_portable='$d_portable'
eunicefix='$eunicefix'
g4_build_wo_session='$g4_build_wo_session'
g4base='$g4base'
g4bin='$g4bin'
g4clhep_base_dir='$g4clhep_base_dir'
g4clhep_include_dir='$g4clhep_include_dir'
g4clhep_lib='$g4clhep_lib'
g4clhep_lib_dir='$g4clhep_lib_dir'
g4compiler='$g4compiler'
g4conf='$g4conf'
g4data='$g4data'
g4debug='$g4debug'
g4global='$g4global'
g4granular='$g4granular'
g4include='$g4include'
g4install='$g4install'
g4ledata='$g4ledata'
g4levelgammadata='$g4levelgammadata'
g4lib='$g4lib'
g4lib_build_shared='$g4lib_build_shared'
g4lib_build_static='$g4lib_build_static'
g4lib_use_granular='$g4lib_use_granular'
g4lib_use_shared='$g4lib_use_shared'
g4lib_use_static='$g4lib_use_static'
g4neutronhpcrosssections='$g4neutronhpcrosssections'
g4osname='$g4osname'
g4radioactivedata='$g4radioactivedata'
g4system='$g4system'
g4tmp='$g4tmp'
g4ui_build_gag_session='$g4ui_build_gag_session'
g4ui_build_terminal_session='$g4ui_build_terminal_session'
g4ui_build_win32_session='$g4ui_build_win32_session'
g4ui_build_xaw_session='$g4ui_build_xaw_session'
g4ui_build_xm_session='$g4ui_build_xm_session'
g4ui_use_gag='$g4ui_use_gag'
g4ui_use_tcsh='$g4ui_use_tcsh'
g4ui_use_terminal='$g4ui_use_terminal'
g4ui_use_win32='$g4ui_use_win32'
g4ui_use_wo='$g4ui_use_wo'
g4ui_use_xaw='$g4ui_use_xaw'
g4ui_use_xm='$g4ui_use_xm'
g4use_hepodbms='$g4use_hepodbms'
g4vis_build_asciitree_driver='$g4vis_build_asciitree_driver'
g4vis_build_dawn_driver='$g4vis_build_dawn_driver'
g4vis_build_dawnfile_driver='$g4vis_build_dawnfile_driver'
g4vis_build_oiwin32_driver='$g4vis_build_oiwin32_driver'
g4vis_build_oix_driver='$g4vis_build_oix_driver'
g4vis_build_opacs_driver='$g4vis_build_opacs_driver'
g4vis_build_openglwin32_driver='$g4vis_build_openglwin32_driver'
g4vis_build_openglx_driver='$g4vis_build_openglx_driver'
g4vis_build_openglxm_driver='$g4vis_build_openglxm_driver'
g4vis_build_raytracer_driver='$g4vis_build_raytracer_driver'
g4vis_build_vrml_driver='$g4vis_build_vrml_driver'
g4vis_build_vrmlfile_driver='$g4vis_build_vrmlfile_driver'
g4vis_use_asciitree='$g4vis_use_asciitree'
g4vis_use_dawn='$g4vis_use_dawn'
g4vis_use_dawnfile='$g4vis_use_dawnfile'
g4vis_use_oiwin32='$g4vis_use_oiwin32'
g4vis_use_oix='$g4vis_use_oix'
g4vis_use_opacs='$g4vis_use_opacs'
g4vis_use_openglwin32='$g4vis_use_openglwin32'
g4vis_use_openglx='$g4vis_use_openglx'
g4vis_use_openglxm='$g4vis_use_openglxm'
g4vis_use_raytracer='$g4vis_use_raytracer'
g4vis_use_vrml='$g4vis_use_vrml'
g4vis_use_vrmlfile='$g4vis_use_vrmlfile'
g4wanalysis_build='$g4wanalysis_build'
g4wanalysis_build_jas='$g4wanalysis_build_jas'
g4wanalysis_build_lab='$g4wanalysis_build_lab'
g4wanalysis_build_lizard='$g4wanalysis_build_lizard'
g4wanalysis_use='$g4wanalysis_use'
g4wanalysis_use_jas='$g4wanalysis_use_jas'
g4wanalysis_use_lab='$g4wanalysis_use_lab'
g4wanalysis_use_lizard='$g4wanalysis_use_lizard'
g4workdir='$g4workdir'
hint='$hint'
lns='$lns'
myuname='$myuname'
n='$n'
osname='$osname'
osvers='$osvers'
package='$package'
sh='$sh'
sharpbang='$sharpbang'
shsharp='$shsharp'
spackage='$spackage'
spitshell='$spitshell'
src='$src'
startsh='$startsh'
EOT

: add special variables
mkdir -p $g4conf
$test -f $src/patchlevel.h && \
awk '/^#define/ {printf "%s=%s\n",$2,$3}' $src/patchlevel.h >> $g4conf/config.sh
echo "CONFIG=true" >> $g4conf/config.sh

: propagate old symbols
if $test -f .config/UU/config.sh; then
	<.config/UU/config.sh sort | uniq >.config/UU/oldconfig.sh
	sed -n 's/^\([a-zA-Z_0-9]*\)=.*/\1/p' config.sh config.sh .config/UU/oldconfig.sh |\
	sort | uniq -u >.config/UU/oldsyms
	set X `cat .config/UU/oldsyms`
	shift
	case $# in
	0) ;;
	*)
		cat <<EOM
		
Hmm...You had some extra variables I don't know about...
      I'll try to keep 'em...

EOM
		echo "# Variables propagated from previous config.sh file." >>.config/bin/$g4system/config.sh
		for sym in `cat .config/UU/oldsyms`; do
			echo "    Propagating $hint variable "'$'"$sym..."
			eval 'tmp="$'"${sym}"'"'
			echo "$tmp" | \
				sed -e "s/'/'\"'\"'/g" -e "s/^/$sym='/" -e "s/$/'/" >>.config/bin/$g4system/config.sh
		done
		;;
	esac
fi

: preserve RCS keywords in files with variable substitution, grrr
Id='$Id'

: Finish up by extracting the .SH files
case "$alldone" in
exit)
	$rm -rf .config/UU
	echo "Done."
	exit 0
	;;
cont)
	;;
'')
	dflt=''
	nostick=true
	$cat <<EOM

WARNING: the generated configuration file
can be edited if necessary!
You can introduce any change to the configuration file
$g4conf/config.sh before the final installation. 
To do so, use a shell escape now (e.g. !vi $g4conf/config.sh).

EOM
	rp="Press [Enter] to start installation or use a shell escape to edit config.sh:"
	. .config/UU/myread
	nostick=''
	case "$ans" in
	'') ;;
	*) : in case they cannot read
		sh 1>&4 -c "$ans";;
	esac
	;;
esac

: if this fails, just run all the .SH files by hand
. $g4conf/config.sh

echo " "
exec 1>&4
. ./.config/UU/extract

if $contains '^depend:' [Mm]akefile >/dev/null 2>&1; then
	dflt=y
	case "$silent" in
	true) ;;
	*)
		$cat <<EOM

Now you need to generate make dependencies by running "make depend".
You might prefer to run it in background: "make depend > makedepend.out &"
It can take a while, so you might not want to run it right now.

EOM
		;;
	esac
	rp="Run make depend now?"
	. .config/UU/myread
	case "$ans" in
	y*)
		make depend && echo "Now you must run a make."
		;;
	*)
		echo "You must run 'make depend' then 'make'."
		;;
	esac
elif test -f [Mm]akefile; then
	echo " "
	echo "Now you must run a make."
elif test -f $g4conf/install.sh; then
	echo " "
	echo "Now starting Geant4 libraries installation..."
	echo " "
	. $g4conf/install.sh
else
	echo " "
	echo "WARNING: Geant4 is NOT installed yet!"
	echo "You (or the administrator if you have not enough privileges)"
	echo "should start with \$G4INSTALL/Configure -install"
	echo "(where \$G4INSTALL is Geant4 install directory)."
	echo " "
fi

$rm -f kit*isdone ark*isdone
$rm -rf .config/UU

: End of Configure

