#!/bin/sh
#
# Setup SM for new sites
#
# First find what sort of system we are running
#
if [ "`echo -n`" = "" ]; then # echo supports -n
n=-n
fi
if cp -p set_opts .tst > /dev/null 2>&1; then
p=-p # cp supports -p
fi
rm -f .tst
#
# Try to guess the byte order
#
if [ "`echo d2 |od -d |sed -n -e 's/^00* *\([^ ]*\).*/\1/p'`" = 25650 ]; then
byte_swap=0
else
byte_swap=1; # DEC/Intel byte order
fi
# Where to install SM
#
dest="/usr/local"
#
# See what platform we are on.
#
machine=""
if sh -c uname > /dev/null 2>&1 ; then
case `uname` in
AIX)
machine=rs6000;;
HP-UX)
machine=hp;;
FreeBSD)
machine=freebsd;;
Linux)
machine=linux;;
IRIX|IRIX64)
machine=sgi;;
OSF1)
machine=alpha;;
SunOS)
machine=sun;;
ULTRIX)
machine=ultrix;;
esac
fi
#
# Parse arguments
#
while [ X"$1" != X"" ]; do
case $1 in
-d)
desired_devs="$2"
shift;;
-f)
force=1;;
-[h?])
echo "Usage: set_opts [ options]"
echo "options are:"
echo " -d \"dev_list\" Desired devices"
echo " -f Force; don't ask user questions"
echo " -h Print this message"
echo " -i install_dir Choose an installation directory"
echo " -m name Specify a machine type"
echo " -n Don't make any changes"
echo " -q Suppress some messages"
echo " -s [no]swap Force SM to [not] byte swap binary data"
echo " -v Be more verbose"
echo ""
exit 0;;
-i) # specify an installation directory
if [ X"$2" = X"" ]; then
echo "You must specify a directory with -i" >&2
else
dest=$2
destflag=1
fi
shift;;
-m) # specify a machine
if [ X"$2" = X"" ]; then
echo "You must specify a machine name with -m" >&2
else
machine=$2
mflag=1
fi
shift;;
-n)
nochange=1;;
-q)
quiet=1;;
-s)
case "$2" in
noswap)
byte_swap=0;;
swap)
byte_swap=1;;
*)
echo "You must specify noswap or swap with -s" >&2
echo "" >&2
esac
if [ X"$2" != X"" ]; then
shift
fi;;
-v)
verbose=1;;
*)
echo "Unknown flag: $1" >&2
$0 -h >&2
exit 1;;
esac
shift
done
#
# We are ready to talk to the user
#
cflags=""
ldflags=""
incfiles="`pwd`/src"
#
if [ "$quiet" = "" -a "$force" = "" ]; then
cat <
&2
echo "this isn't true! PLEASE tell rhl@astro.princeton.edu" >&2
fi
if [ -f /usr/X11R6/include/X11/Xlib.h -a \
! -f /usr/include/X11/Xlib.h ]; then
sysincX11="/usr/X11R6/include"
fi
if [ -f /usr/X11R6/lib/libX11.a -a \
! -f /usr/lib/libX11.a ]; then
syslibX11="/usr/X11R6/lib"
fi
devs="X11";;
rs6000)
version="`uname -a | awk '{print $4}'`"
case $version in
3*)
cc="c89 -Drs6000";;
*)
cc="cc -g -DSYSV -DAIXV3 -Drs6000 -qchars=signed";;
esac
devs="IMAGEN SGI TK X11";;
sgi)
if [ "$force" = "" ]; then
echo $n "Do you want to use gcc? [n/y] "
read ans
else
ans=""
fi
case $ans in
y*)
cc="gcc -Wall -D_POSIX_SOURCE -Dsgi";;
*)
cc="cc -ansiposix -Dsgi -fullwarn";
case `uname -r` in
4*)
# Warnings turned off:
# 24: constant in conditional; used by . Grrr
# 183,262,287: problems with static functions not
# having protos
# 269: very picky signed/unsigned intermediate result
cc="$cc -woff 24,183,262,269,287";;
5*)
# Warnings turned off:
# 835: no prototypes for static functions
cc="$cc -woff 835";;
*)
# Warnings turned off:
# 1116 non-void function "..." should return a value
# 1174 function "..." was declared but never referenced
# 1196 function declared implicitly
# 1429 the type "long long" is nonstandard
# 1498 no prototype for the call to ...
# 1506 implicit conversion from float to unsigned long
# 1692 prototyped function redeclared without prototype
cc="$cc -woff 1116,1174,1196,1429,1498,1506,1692";;
esac;;
esac
case `uname -r` in
4*)
cc="$cc -Dsgi4";;
esac
devs="IMAGEN TK X11 SGI";;
sun)
version=`uname -r | sed -e 's/^\(.\).*/\1/'`
if [ "$version" -ge "5" ]; then
solaris=1 # Oh deary me
fi
sysincX11=""
syslibX11=""
if [ -f /usr/openwin/include/X11/Xlib.h ]; then
echo $n "Do you wish to use the openwindows version of X Windows? [y/n] "
read ans
case $ans in
n*)
;;
*)
sysincX11="/usr/openwin/include"
syslibX11="/usr/openwin/lib";;
esac
fi
if [ "X$sysincX11" = "X" -a -f /usr/include/X11/Xlib.h ]; then
echo $n "Do you wish to use the version of X in /usr/include/X11 and /usr/lib/X11? [y/n] "
read ans
case $ans in
n*)
;;
*)
sysincX11="/usr/include"
syslibX11="/usr/lib/X11";;
esac
fi
while [ "$sysincX11" = X"" ]; do
echo $n "Specify location of X include files "
read sysincX11
if [ ! -d "$sysincX11" ]; then
echo "$sysincX11 isn't a directory; please try again"
unset sysincX11
fi
done
while [ X"$syslibX11" = X"" ]; do
echo $n "Specify location of X lib files "
read syslibX11
if [ ! -d "$syslibX11" ]; then
echo "$syslibX11 isn't a directory; please try again"
unset syslibX11
fi
done
echo $n "Do you want to use gcc? [n/y] "
read ans
case $ans in
y*)
if [ "$solaris" = "1" ]; then
cc="gcc -Wall -Wno-uninitialized -Dsolaris"
else
cc="gcc -Wall"
echo $n "Do you have ANSI include files? [n/y] "
read ans
case $ans in
y)
cc="$cc -DANSI_INCLUDE"
echo $n "how about POSIX include files? [n/y] "
read ans
case $ans in
y)
cc="$cc -DPOSIX_INCLUDE";;
esac;;
esac
fi;;
*)
if [ "$solaris" = "1" ]; then
cc="cc -Xc -Dsun -Dsolaris"
else
echo $n "How about acc? [n/y] "
read ans
case $ans in
y*)
echo \
"You'll get compilation warnings from sun's system headers. Ignore them."
cc="acc -Dsun";;
*)
cc="cc";;
esac
fi;;
esac
if [ "$solaris" = "1" ]; then
devs="IMAGEN TK X11"
else
devs="IMAGEN SUN_VIEW TK X11"
fi;;
vax)
echo "This installation on a vax is not tested"
echo "If appropriate, you might try saying that you are running ultrix"
echo "If it works please send mail to rhl@astro.princeton.edu"
cc="cc -Dvax"
devs="IMAGEN TK X11";;
ultrix)
echo $n "Do you want to use gcc? [n/y] "
read ans
case $ans in
y*)
cc="gcc -Wall -Dultrix";;
*)
cc="cc -Dultrix";;
esac
devs="IMAGEN TK X11";;
3b1)
devs="IMAGEN UNIXPC";;
*)
echo "I don't understand $machine; please configure by hand"
echo "When you are happy, please send mail to rhl@astro.princeton.edu"
exit 1;;
esac
#
if [ "$force" = "" ]; then
echo "You are on a $machine using the"
echo " $cc"
echo $n "compiler; is this OK? [y|n] "
read reply
else
reply=""
fi
case $reply in
n*)
echo "type compiler command or q to exit"
read reply
case $reply in
q*)
exit 0;;
*)
cc="$reply";;
esac
esac
#
if [ "$force" = "" ]; then
echo $n "What debugging/optimisation flags do you want? [-g] "
read reply
else
reply=""
fi
case $reply in
"")
cflags="-g";;
*)
cflags="$reply";;
esac
#
# On at least some machines (e.g. solaris boxes), specifying -L isn't enough
# to save the user from needing a LD_LIBRARY_PATH; on at least some of these
# machines, -R will save us
#
if [ "$syslibX11" != "" ]; then
bypass_ld_library_path=""
echo $n "Do you want to bypass LD_LIBRARY_PATH? [n/y] "
read reply
if [ "$reply" = "y" ]; then
bypass_ld_library_path=1
fi
fi
#
# Choose devices, if not chosen on command line
#
if [ "$desired_devs" = "" ]; then
get_devs=1
fi
while [ "$get_devs" = 1 ]; do
echo "What devices do you want to compile in? Your options are:"
for f in "$devs"; do
echo $n "$f "
done
if [ X"$n" != X"" ]; then echo; fi
echo "Choose one at a time, carriage return on an empty line to finish"
while true; do
read dev
if [ "$dev" = "" ]; then
break
fi
ok=0
for f in $devs; do
if [ "$dev" = "$f" ]; then
if [ "$desired_devs" = "" ]; then
desired_devs=$dev
else
# add to list; SGI must come before X11
if [ "$dev" = "SGI" ]; then
desired_devs="$dev $desired_devs"
else
desired_devs="$desired_devs $dev"
fi
fi
ok=1
break
fi
done
if [ $ok = 0 ]; then
echo Illegal device: $dev
fi
done
if [ "$desired_devs" = "" ]; then
echo $n "You have not selected any devices; ok? [y|n] "
else
echo $n "You have selected devices: $desired_devs; ok? [y|n] "
fi
read reply
case $reply in
n*)
continue;;
esac
break;
done
#
# TK needs some non-standard include files/libraries
#
for f in $desired_devs; do
case $f in
TK)
have_tk=1
if [ -f /usr/include/tcl.h -a -f /usr/include/tk.h ]; then
#
# The O/S seems to provide both tcl _and_ tk;
#
continue
fi
sysincTCL="/usr/local/include"
while [ ! -f $sysincTCL/tcl.h ]; do
echo "Where are the Tcl/Tk include files?"
read sysincTCL
if [ -f $sysincTCL/tcl.h ]; then
break
fi
echo "I don't see tcl.h in $sysincTCL; try again"
done
sysincTK=$sysincTCL
while [ ! -f $sysincTK/tk.h ]; do
echo "I see the TCL include files, what about Tk?"
read sysincTK
if [ -f $sysincTK/tk.h ]; then
break
fi
echo "I don't see tk.h in $sysincTK; try again"
done
syslibTCL=`echo $sysincTCL | sed -e 's/include/lib/'`
while [ ! -f $syslibTCL/libtcl.a ]; do
echo Where are the Tcl/Tk library files?
read syslibTCL
if [ -f $syslibTCL/libtcl.a ]; then
break
fi
echo "I don't see libtcl.a in $syslibTCL; try again"
done
if [ ! -f $syslibTCL/libtk.a ]; then
syslibTK=`echo $sysincTK | sed -e 's/include/lib/'`
while [ ! -f $syslibTK/libtk.a ]; do
echo "I see the TCL libraries, what about Tk?"
read syslibTK
if [ -f $syslibTK/libtk.a ]; then
break
fi
echo \
"I don't see libtk.a in $syslibTK; try again"
done
fi;;
X11)
have_x11=1;;
esac
done
if [ "$have_tk" != "" -a "$have_x11" = "" ]; then
echo "Hmm, TK but no X11... adding X11 to your devices"
desired_devs="$desired_devs X11"
fi
#
# Now configure more obscure SM features
#
if [ "$force" = "" ]; then
echo \
We can help you configure things for which the defaults are usually OK
fi
while true; do
if [ "$force" = "" ]; then
echo $n "Do you want to do so? [n|y|list] "
read reply
else
reply=""
fi
case $reply in
l*)
echo "Configurable options:"
echo " Data type for arithmetic vectors"
echo " Length of longest macro"
echo " Length of each element of string-valued-vectors"
echo " Recognise octal numbers (e.g. 0377)"
;;
n*|"")
obscure=0; break;;
y*)
obscure=1; break;;
esac
done
#
# This if should really be indented, but...
#
if [ $obscure = 1 ]; then
#
# Do you want to use doubles or floats for vectors?
#
while true; do
echo $n \
"Choose data type for vectors, \"float\" or \"double\"? [float] "
read reply
case $reply in
float|"")
REAL=float; break;;
double)
REAL=double; break;;
*)
echo "$reply is not a valid datatype; please try again" >&2;;
esac
done
if [ "$REAL" = "float" ]; then
libsuffix=""
else
d="_d"
echo $n \
"Suffix for installed library names (e.g. libdevices$d.a) [$d] "
read reply
case $reply in
"")
libsuffix="$d";;
*)
libsuffix="$reply";;
esac
fi
#
# Set MACROSIZE
#
macrosize=10000
while true; do
echo $n "Choose length of longest macro [$macrosize] "
read reply
case $reply in
"")
break;;
[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9])
macrosize=$reply;
break;;
*)
echo "$reply is not a valid choice; please try again" >&2;;
esac
done
#
# Set VEC_STR_SIZE
#
vec_str_size=40
while true; do
echo $n \
"Choose length for string-valued-vector's elements [$vec_str_size] "
read reply
case $reply in
"")
break;;
[1-9]|[1-9][0-9]|[1-9][0-9][0-9])
vec_str_size=$reply;
break;;
*)
echo "$reply is not a valid choice; please try again" >&2;;
esac
done
#
# Choose whether to support octal numbers
#
octal="n"
while true; do
echo $n \
"Do you want to treat numbers starting 0 as octal? [$octal] "
read reply
case $reply in
"")
break;;
[yn]*)
octal=$reply;
break;;
*)
echo "$reply is not a valid choice; please try again" >&2;;
esac
done
if [ $octal = "y" ]; then
octal=1
else
octal=0
fi
fi
#
# End of obscure options if
#
#
# Do you want to install libparser.a?
#
if [ "$force" = "" ]; then
echo $n \
"Do you want to build and install the callable parser, libparser.a? [n] "
read reply
else
reply=""
fi
case $reply in
y*)
choose_parser="s/^\(all :.*\)/\1 Parser/";;
*)
choose_parser="/\(to call the SM parser.\)$/{
p
s/.*/# (not built by default)/
}"
esac
#
# Decide where to install SM
#
if [ "$destflag" != "1" ]; then
echo $n "Top level path to install things? [$dest] "
read reply
if [ "$reply" != "" ]; then
dest=$reply
fi
fi
destbin=$dest/bin
destlib=$dest/lib
destetc=$destlib/sm
destinfo=$dest/info
destman=$dest/man/man1
#
while [ "$destflag" != "1" ]; do
echo "The commands make install (and make installinfo)"\
"will install files as follows:"
echo " binaries $destbin"
echo " linkable libraries $destlib"
echo " SM files (e.g. graphcap) $destetc"
echo " info files $destinfo"
echo " manual pages $destman"
echo $n "is this ok? [y|n] "
read reply
case $reply in
n*)
echo "Please specify your preferences:"
echo $n "Binaries [$destbin] "
read reply; if [ "$reply" != "" ]; then destbin=$reply; fi
echo $n "Libraries [$destlib] "
read reply; if [ "$reply" != "" ]; then destlib=$reply; fi
echo $n "SM Files [$destetc] "
read reply; if [ "$reply" != "" ]; then destetc=$reply; fi
echo $n "Info files [$destinfo] "
read reply; if [ "$reply" != "" ]; then destinfo=$reply; fi
echo $n "Man pages [$destman] "
read reply; if [ "$reply" != "" ]; then destman=$reply; fi
;;
*)
break;;
esac
done
#
# See if they want to install SM-mode for (gnu)emacs
#
if [ "$force" = "" ]; then
echo $n "Do you want to install SM-mode for (gnu)emacs? [y|n] "
read reply
else
reply="n"
fi
case $reply in
n*)
destlisp=""
;;
*)
destlisp="$dest/emacs/site-lisp"
echo $n "In which directory? [$destlisp] "
read reply
if [ "$reply" != "" ]; then destlisp=$reply; fi
;;
esac
#
# try to convert those destinations to canonical form
#
if [ "$verbose" = "1" ]; then
echo "Canonicalising Makefile variables..."
fi
if [ "$machine" != "freebsd" ]; then
for f in destbin destlib destetc destinfo destman destlisp; do
ff=`eval echo '$'$f`
eval $f=`echo $ff | sed -e "s|$dest|'\\$(DEST)'|"`
if [ "$verbose" = "1" ]; then
F=`echo $f | tr a-z A-Z`
echo $F = `eval echo '$'$f`
fi
done
fi
#
# Now we know what to do, so it
#
if [ "$nochange" != "" ]; then
echo "You told me not to modify any files; exiting" >&2
exit 0;
fi
if [ "$force" = "" ]; then
echo $n "I am about to start modifying files, proceed? [y|n] "
read reply
case $reply in
n*)
echo "I am not making any changes. Goodbye"
exit 0;;
esac
fi
#
# Prepare to modify Makefiles to allow for the devices chosen
#
for f in $desired_devs; do
case $f in
SGI)
ldflags="$ldflags \$(SGILIB)";;
SUN_VIEW)
ldflags="$ldflags \$(SUNVLIB)";;
TK)
if [ "$sysincTCL" != "" ]; then
cc="$cc -I$sysincTCL -I$sysincTK"
fi
if [ "$syslibTCL" != "" ]; then
# if [ "$bypass_ld_library_path" != "" ]; then
# ldflags="$ldflags -R$syslibTCL -R$syslibTK"
# fi
ldflags="$ldflags -L$syslibTCL -L$syslibTK"
fi
ldflags="$ldflags \$(TKLIB)";;
X11)
if [ "$sysincX11" != "" ]; then
cc="$cc -I$sysincX11"
fi
if [ "$syslibX11" != "" ]; then
if [ "$bypass_ld_library_path" != "" ]; then
ldflags="$ldflags -R$syslibX11"
fi
ldflags="$ldflags -L$syslibX11"
fi
ldflags="$ldflags \$(XLIB11)";;
esac
done
ldflags="$ldflags -lm"
if [ "$solaris" = "1" ]; then
ldflags="$ldflags -lsocket -lnsl"
fi
#
# Trap ^C
#
trap 'echo "Aborting setup"
for f in Makefile src/Makefile src/options.h; do
if [ -f $f.orig ]; then
cp $f.orig $f
else
rm -f $f .config~
fi
done
exit 1' 2 3
#
# Update or create .config file
#
if uname -a > /dev/null 2>&1; then
if [ "$machine" = "freebsd" ]; then
uname="(`uname -a | awk '{print $1 " " $2 " " $3 " " $4}'`)"
else
uname="(`uname -a`)"
fi
else
uname=
fi
if [ -f .config ]; then
cp .config .config~
if grep 'set_opts' .config > /dev/null 2>&1; then
sed -e "2s/.*/set_opts -m $machine $uname/" .config~ > .config
else
sed -e "1{
p
s/.*/set_opts -m $machine $uname/
}" .config~ > .config
fi
rm -f .config~
else
date > .config
echo "set_opts -m $machine $uname" >> .config
fi
#
# Start with Makefile
#
echo "Creating Makefile..."
sed -e "s#^CC = .*#CC = $cc#" \
-e "s|^CFLAGS = .*|CFLAGS = $cflags -I$incfiles|" \
-e "s|^DEST = .*|DEST = $dest|" \
-e "s|^DESTDIR =.*|DESTDIR = $destbin|" \
-e "s|^DESTLIB =.*|DESTLIB = $destlib|" \
-e "s|^DESTETC =.*|DESTETC = $destetc|" \
-e "s|^DESTINFO =.*|DESTINFO = $destinfo|" \
-e "s|^DESTLISP =.*|DESTLISP = $destlisp|" \
-e "s|^DESTMAN =.*|DESTMAN = $destman|" \
-e "s|^LIBSUFFIX =.*|LIBSUFFIX = $libsuffix|" \
-e "$choose_parser" \
< Makefile.skl > Makefile~
if [ -f Makefile ]; then
cp $p Makefile Makefile.orig
fi
mv Makefile~ Makefile
#
# Fix up options.h
#
# build the search pattern for awk
#
echo "Creating src/options.h..."
if [ "$desired_devs" = "" ]; then
cp src/options.skl src/options.h~
else
devs=""
for f in $desired_devs; do
if [ "$devs" = "" ]; then
devs=$f
else
devs="$devs|$f"
fi
done
awk 'BEGIN {
line = "**NO_PRINT**";
}
/#define ('$devs')/ {
if(line ~ /\*\//) {
print $0;
next;
}
}
{
'"if(line ~ /($devs)/) {"'
if($0 ~ /\*\//) {
print $0;
print line;
line = "**NO_PRINT**";
next;
}
}
if(line != "**NO_PRINT**") {
print line;
}
line = $0;
}
END {
print line;
}' < src/options.skl > src/options.h~
if [ -f src/options.h ]; then
cp $p src/options.h src/options.h.orig
fi
fi
#
# and now set values in the options file with sed
#
sedopts=""
if [ "$REAL" != "" ]; then
sedopts="$sedopts -e 's/typedef float REAL/typedef $REAL REAL/'"
fi
if [ "$macrosize" != "" ]; then
sedopts="$sedopts -e 's/\(#define MACROSIZE \).*/\1$macrosize/'"
fi
if [ "$vec_str_size" != "" ]; then
sedopts="$sedopts -e 's/\(#define VEC_STR_SIZE \).*/\1$vec_str_size/'"
fi
if [ "$octal" = "1" ]; then
sedopts="$sedopts -e 's/\(#define OCTAL_NUMBERS \).*/\1$octal/'"
fi
if [ "$sedopts" = "" ]; then
mv src/options.h~ src/options.h
else
eval sed $sedopts src/options.h~ > src/options.h
/bin/rm -f src/options.h~
fi
#
# And now src/Makefile
#
echo "Creating src/Makefile..."
#
if [ -f src/Makefile ]; then
cp $p src/Makefile src/Makefile.orig
fi
sedopts="-e 's|^\(LDFLAGS.*\)|\1 $ldflags|'"
eval sed $sedopts < src/Makefile.skl > src/Makefile
#
# And now callable/Makefile
#
echo "Creating callable/Makefile..."
#
if [ -f callable/Makefile ]; then
cp $p callable/Makefile callable/Makefile.orig
fi
eval sed $sedopts \
-e "'s|^CC = .*|CC = $cc|'" \
-e "'s|^CFLAGS = .*|CFLAGS = $cflags -I$incfiles|'" \
< callable/Makefile.skl > callable/Makefile
#
# Done. Tell them about copyright stuff if it's there
#
if grep "#error You must edit options.h" src/options.h > /dev/null 2>&1 ; then
echo ""
echo "You will be ready to make SM as soon as you have edited"
echo "src/options.h to remove our copyright notice."
else
echo "You are now ready to make SM."
fi