####################
HELP ()
{
   more <<EOHELP

   gen_share.sh [-h] [-64] [-p project] [-g] shared_object_name
                [-I include_path] [+f compiler_option]
		[-L library_ path] [-l library] [-usestatic]

   gen_share.sh will create a makefile and shared library in the
   current directory that incorporates all the interdependencies 
   of the FORTRAN and C files listed in the current directory.

   The output from gen_share.sh will include a makefile named
   "Makefile" and a shared library lib[project].${ext}.
   
   It will handle .F .f .inc .c and .h files.

Options:
   -h                       Print this help screen.

   -64                      Meanigful only for IRIX64 6.1 and 6.2
                            Causes the Makefile to uses -mips4 option.

   -p project	            The project name defines the name of the
                            shared_object_name.  Overrides shared_object
                            name.

   -g                       Sets the debug option for the compilers on
                            all platforms in the output Makefile.

   -L library_path          Path to additional shared or static libraries
                            which are required by the shared library to 
                            be built.

   -l library               Name of subordinate shared or static libraries
                            which satisfy external dependencies of the shared
                            library to be built. Library name is assumed to 
                            be preceed by lib. "-l myshared" would be assumed to
                            be locable as "libmyshared.so".

   -I includepath           Add additional include paths

   +f                       Add additional compiler options

   -usestatic               This option can be used to build shared libraries
			    from existing static libraries. Libraries to be
                            used in the build should be specified using the 
                            appropriate path -L and library -l.

Arguments:
   shared_object_name       The name of you want the shared object
                            to have when make creates it.



NOTES:
   This utility creates a makefile and runs make to generate a 
   shared library based on input arguments.  You may edit the
   resulting Makefile and run make to create modfied local versions
   of the shared object file.

   At times during the execution of this script, you may see the 
   message "No match" displayed to the screen.  This is normal.
   In this instance, gen_share.sh is searching the current directory for
   the different types of files -- your directory may not contain
   files of each type.

   As with any make process the shared library will not be created if
   errors occur during compilation or linking.

EOHELP
   exit 0
}

revn=161

currdir=`pwd`
calldir=`echo $0 | sed 's!/[a-zA-Z0-9_\.]*$!!'`
if test "$calldir" = "$0"
then
   calldir=`pwd`
fi
cd "$calldir"
if [ -d "../../" ]; then
   cd ../../ 2> /dev/null
fi
calldir=`pwd`
cd "$currdir"

if [ -f "$calldir/bin/anssh.ini" ]; then
   if [ ! -z "$DEBUG_ANSSCRIPTS" ]; then
      echo "Self located in gen_share..."
   fi
   ansdir="$calldir"
else
   ansdir=/ansys_inc/v$revn/ansys
fi

echo " "
ext=".so"
debug=""
projname="none"
libpath=""
libs=""
addflags=""
incpath=""
uselibs="0"
args=""
allex=""
BUILD64="FALSE"
PREPROC="FALSE"
PP_MACRO="PP ="
ANSYS_INCPATH="-I$ansdir/include"

cmdline="$0 $*"

# find out what platform we are executing under
uname_out=`uname -a`

if [ `uname -s` = "HP-UX" ]; then
   ext=".sl"
fi

if [ `uname -s` = "IRIX64" ]; then
   BUILD64="TRUE"
fi

# process arguments
if [ $# -gt 0 ]; then
   while [ $# -gt 0 ]
   do
      case $1 in
         # help
         -h )
            HELP
            ;;
         # catch 64 bit build switch
         -64 )
            BUILD64="TRUE"
            shift
            ;;
	 # set for 32 bit if that's what the user wants
	 -32 )
	    BUILD64="FALSE"
	    shift
            ;;
         # catch debug flag if set
         -g )
            debug="-g"
            shift
            ;;
         # catch use of static libraries
         -usestatic )
            uselibs="1"
            shift
            ;;
         # catch project name if provided
         -p )
            projname=$2
            shift
            shift
            ;;
	 # catch additional compilation flags
	 +f )
	    addflags="$addflags $2"
	    shift
	    shift
	    ;;
         #catch include paths
         -I )
            incpath="$incpath -I$2"
	    shift
            shift
            ;;
         #catch library paths
         -L )
            libpath="$libpath -L$2"
	    shift
            shift
            ;;
         #catch libraries
         -l )
            libs="$libs -l$2"
            shift
            shift
            ;;
         # catch any other switches
         -* )
            shift
            ;;
         * )
            args="$args $1"
            shift
            ;;
      esac
   done
 else
   BADARGS $0
fi

set -- $args
   
# at this point, args[] has all the command line arguments, with the
# options removed

#if [ $# -eq 0 ]; then
#   BADARGS $0
#fi

#clear 

if [ "$projname" = "none" ]; then
	libname=$1
else
	libname="lib$projname$ext"
fi

case `echo $uname_out | cut -d" " -f1` in

   # IRIX64 (devs14)
   IRIX | IRIX64 )
      # strings for echo features
      bs='\\'
      nl=''
      nn='\c'
      dn='' 

      # determine the operating system release number
      release=`echo $uname_out | cut -d" " -f3`

      #
      # set system dependent items
      #

         if [ "$BUILD64" = "FALSE" ]; then
            # macro for FORTRAN compile
            FC_MACRO='FC = f90 ${debug} ${ANSYS_INCPATH} -DFORTRAN -mp -mips3 -G 0 -n32 -macro_expand -O2 -c -DSGIR4K_SYS '
   
            # macro for C compile
            CC_MACRO='CC = cc ${debug} ${ANSYS_INCPATH} -c -G 0 -mips3 -n32 -O2 -mp -DSGIR4K_SYS -DSYSV '
      
            # macro for linker
            LN_MACRO="LN = ld -shared -all -n32 -mips3 -multigot -ignore_unresolved -o $libname -soname $libname $libpath " 
          elif [ "$BUILD64" = "TRUE" ]; then
            echo "Makefile will include -mips4 option"
            # macro for FORTRAN compile
            FC_MACRO='FC = f90 ${debug} ${ANSYS_INCPATH} -DFORTRAN -mips4 -64 -OPT:reorg_common=OFF -macro_expand -O2 -c -DSGIR8K_SYS '
   
            # macro for C compile
            CC_MACRO='CC = cc ${debug} ${ANSYS_INCPATH} -w -c -O2 -mips4 -64 -OPT:reorg_common=OFF -Dsgi -DxcCONFIG1 -DxcANSI_LIBS -DSGIR8K_SYS -DSYSV '
      
            # macro for linker
            LN_MACRO="LN = ld -mips4 -64 -multigot -shared -all -ignore_unresolved -o $libname -soname $libname $libpath "
         fi

      ;;
 

   HP-UX )

      # strings for echo features
      bs='\'
      nl=''
      nn='\c'
      dn='' 
      hp10='0' 
      hp11='0' 

      # determine the operating system release number
      release=`echo $uname_out | cut -d" " -f3`

      #HP-UX hp720 A.09.05 A 9000/735 2002418951 two-user license

      if [ "$release" = "B.10.20" ]; then
	  hp10='1'
	  hp_xtra='+DA2.0 +DS2.0'
          if [ "$uselibs" = "1" ]; then
              uselibs="3"
          fi
          FC_MACRO="FC = /opt/fortran90/bin/f90 ${debug} ${ANSYS_INCPATH} -Wc,-local_equivs +U77 -c +Z +O3 -DFORTRAN -DHP_SYS -DHP32_SYS $hp_xtra"
          # macro for C compile
          CC_MACRO="CC = cc ${debug} ${ANSYS_INCPATH} -c -Ae +O2 +Z $hp_xtra -DHP_SYS -DHP32_SYS -DSYSV -Wp,-H556000 "

          # macro for linker
          LN_MACRO="LN = ld -x -b -o $libname $libpath "
      fi
      if [ "$release" = "B.11.11" ]; then
	  hp11='1'
	  hp_xtra='+DA2.0W +DS2.0'
          if [ "$uselibs" = "1" ]; then
              allex=" +forceload "
          fi
          FC_MACRO="FC = /opt/fortran90/bin/f90 ${debug} ${ANSYS_INCPATH} +U77 -c +Z +O2 +Odataprefetch +Olibcalls -DFORTRAN -DHP_SYS -DHP64_SYS $hp_xtra"
          # macro for C compile
          CC_MACRO="CC = cc ${debug} ${ANSYS_INCPATH} -c -Ae +O2 +Odataprefetch +Z $hp_xtra +Olibcalls -DHP_SYS -DHP64_SYS -DSYSV -Wp,-H556000 "

          # macro for linker
          LN_MACRO="LN = ld -x -b -o $libname $libpath "
      fi
      if [ `uname -m` = "ia64" ]; then
          hp11='1'
          hp_xtra='+DD64 +DSitanium2'
          if [ "$uselibs" = "1" ]; then
              allex=" +forceload "
          fi
          FC_MACRO="FC = /opt/fortran90/bin/f90 ${debug} ${ANSYS_INCPATH} +U77 -c +Z +O2 +Odataprefetch +Olibcalls -DFORTRAN -DHP_SYS -DHPIA64_SYS $hp_xtra"
          # macro for C compile
          CC_MACRO="CC = /opt/ansic/bin/cc ${debug} ${ANSYS_INCPATH} -c -Ae +O2 +Odataprefetch +Z $hp_xtra +Olibcalls -DNOSPACEBALL -DHP_SYS -DHPIA64_SYS -DSYSV -Wp,-H556000 "

          # macro for linker
          LN_MACRO="LN = ld -x -b -o $libname $libpath "
      fi

      ;;


   # AIX 5.3
   AIX )

      # strings for echo features
      bs='\'
      nl=''
      nn='\'
      dn='' 
          if [ "$uselibs" = "1" ]; then
              uselibs="2"
          fi


      #AIX 5.3 pghrs630 


      PREPROC="TRUE"

      #
      # set system dependent items
      #
      # IBM 64 bit version
      #
      # changes made by pds on 10/5/05, amI64bit no longer used.
      # changes made by jtm on 10/12/00, until amI64bit can be resolved.
      #listTest=`ls $ansdir/bin/amI64bit` > /dev/null
      #if [ "$listTest" = "$ansdir/bin/amI64bit" ]; then
         #$ansdir/bin/amI64bit  > /dev/null
         #if ("$status" = "1") then
         #
         # macro for FORTRAN preprocessor
         PP_MACRO='PP = /usr/ccs/lib/cpp -P -qnolm -DELM_ON -DFORTRAN -DRS6000_SYS -DRS64K_SYS '

         # macro for FORTRAN compile
         FC_MACRO='FC = xlf_r ${debug} ${ANSYS_INCPATH} -c -q64 -qnolm -qfixed=72 -qmaxmem=4096 -qarch=com -qnosave -NA20000 -NQ50000 -ND3072 -NT120000 -qhalt=S  -DRS64K_SYS '

         # macro for C compile
         CC_MACRO='CC = xlC_r ${debug} ${ANSYS_INCPATH} -q64 -c -qnolm -qarch=com -DSYSV  -DRS64K_SYS -DRS6000_SYS '

         # macro for linker 5.3
          LN_MACRO="LN = ld -b64 -G -o $libname -bE:ansysAIX.exp  -bM:SRE /usr/lib/crt0_64.o -bnoentry  -bnro -bexpall $libpath  -liconv -lisode -lC -lxlf90 -lxlf -lc_r -lm -ldl"
      #fi

      ;;


   # SUN (uspark)
   SunOS )

      # strings for echo features
      bs='\'
      nl=''
      nn='\c'
#      dn='-n ' 
      dn='' 
      if [ "$uselibs" = "1" ]; then
          allex=" -z allextract "
      fi

      # determine the operating system release number
      release=`echo $uname_out | cut -d" " -f3`

      #SunOS uspark 5.5 Generic sun4u sparc SUNW,SPARCstation-fusion

      if [ "$release" != "5.10" ]; then
         echo "Making shared libraries on SunOS operating systems with release"
         echo "numbers other than 5.10 has not been tested by ANSYS, Inc."
         echo "$nl"
         echo "Continuing..."
      fi

      #
      # set system dependent items
      #

      # 32-bit -- no longer used
      # macro for FORTRAN compile
#      FC_MACRO='FC = f77 ${debug} ${ANSYS_INCPATH} -PIC -xcg92 -dalign -xlibmil -e -copyargs -c -DSOLARIS_SYS '

      # macro for C compile
#      CC_MACRO='CC = cc ${debug} ${ANSYS_INCPATH} -K PIC -mr -g -Xa -dalign -c -w -xcg92 -xlibmil -DSOLARIS_SYS '

      # macro for linker
#      LN_MACRO="LN = ld -G -o $libname -z nodefs $libpath  -B dynamic -ldl"


      #
      # fujitsu, usIII or sun64
      #
      #if [ "$BUILD64" = "TRUE" ]; then
#        case `uname -i` in
#         FJSV* )
#             FC_MACRO='FC = frt ${debug} ${ANSYS_INCPATH} -c -KPIC -Kfast_GP=2 -KV9 -Kdalign -Kthreadsafe -xlibmopt -fs -AR -Nmallocfree -DSUN64_SYS '
#             CC_MACRO="CC = fcc ${debug} ${ANSYS_INCPATH} -KPIC -Kdalign -fs -mt -AR -Nmallocfree -Kfast_GP=2 -KV9 -DSUN64_SYS"
#             LN_MACRO="LN = ld -64 -G -o $libname -znodefs -L/opt/FSUNf90/lib/sparcv9 -L$OPENWINHOME/lib/sparcv9 -L/usr/dt/lib/sparcv9 -L/usr/lib/sparcv9 -L/usr/ucblib/sparcv9 $libpath  -ldl "
#            ;;
#         * )
          isalist | grep i86 > /dev/null
          if [ $? -eq 0 ]; then
             SYS="SOLX64"
          fi
          isalist | grep sparcv9 > /dev/null
          if [ $? -eq 0 ]; then
             SYS="SOLUS64"
          fi
          if [ "$SYS" = "SOLUS64" ]; then
             FC_MACRO='FC = f77 ${debug} ${ANSYS_INCPATH} -c -PIC -dalign -libmil -m64 -xtarget=ultra3 -xarch=sparcvis2 -xprefetch -DSUN64_SYS '
             CC_MACRO="CC = cc ${debug} ${ANSYS_INCPATH} -KPIC -mr -g -Xa -dalign -c -w -m64 -xtarget=ultra3 -xarch=sparcvis2 -xprefetch -DSUN64_SYS"
             LN_MACRO="LN = ld -64 -G -o $libname -z nodefs $libpath  -ldl "
          elif [ "$SYS" = "SOLX64" ]; then
             FC_MACRO='FC = f90 -f77 ${debug} ${ANSYS_INCPATH} -c -PIC -dalign -libmil -m64 -xtarget=generic -xprefetch -DSOLX64 -DSUN64_SYS '
             CC_MACRO="CC = cc ${debug} ${ANSYS_INCPATH} -KPIC -mr -g -Xa -c -w -m64 -xtarget=generic -xprefetch -DSOLX64 -DSUN64_SYS"
             LN_MACRO="LN = ld -64 -G -o $libname -z nodefs $libpath -L/usr/lib/amd64 -ldl "
           fi
#          ;;
#          esac
      #fi
      ;;

   # the HP AlphaServer
   OSF1 )

      # strings for echo features
      bs='\'
      nl=''
      nn=''
      dn='-n ' 

      # determine the operating system release number
      release=`echo $uname_out | cut -d" " -f3`

      if [ "$release" != "V5.0" ]; then
         echo "Making shared libraries on Compaq Tru64 operating systems with release"
         echo "numbers other than V5.0 has not been tested by ANSYS, Inc."
         echo "$nl"
         echo "Continuing..."
      fi

      #
      # set system dependent items
      #

      # macro for FORTRAN compile
      FC_MACRO='FC = f90 ${debug} ${ANSYS_INCPATH} -c -automatic -recursive -arch generic -tune host -DDECAXPOSF_SYS -DFORTRAN '

      # macro for C compile
      CC_MACRO='CC = cc ${debug} ${ANSYS_INCPATH} -c -w -arch generic -tune host -DDECAXPOSF_SYS -DSYSV -DBYTE_ORDER -nodtk'

      # macro for linker
      escaped_star=\'\*\'

      LN_MACRO="LN = ld -shared -expect_unresolved $escaped_star -o $libname $libpath  "
      ;;

   # Linux
   Linux )

      LINIA32=0
      LINIA64=0
      LINX64=0

      # strings for echo features
      bs='\'
      nl=''
      nn=''
      dn='-n '

      #Linux 
      LINIA32=1
      if [ `uname -m` = "ia64" ]; then
         LINIA64=1
      fi
      if [ `uname -m` = "x86_64" ]; then
         LINX64=1
      fi


      #
      # set system dependent items
      #

      # macro for FORTRAN  & C compile
      FC_MACRO='FC = ifort ${debug} ${ANSYS_INCPATH} -c -w -w90 -fpp -vms -fpic -DLINUX_SYS -DLINUXIA32_SYS '
      CC_MACRO='CC = icc ${debug} ${ANSYS_INCPATH} -c -Qoption,cpp,--c99 -fpic -DLINUX_SYS -DLINUXIA32_SYS '
      LN_MACRO="LN = ld -shared -o $libname $libpath  "

      if [ "$LINIA64" = "1" ]; then
         FC_MACRO='FC = ifort ${debug} ${ANSYS_INCPATH} -c -w -w90 -fpp -vms -fpic -DLINUX_SYS -DLINUXIA64_SYS '
         CC_MACRO='CC = icc ${debug} ${ANSYS_INCPATH} -c -Qoption,cpp,--c99 -fpic -DLINUX_SYS -DLINUXIA64_SYS '
      fi

      # macro for linker
      escaped_star=\'\*\'

      # set Opteron macros
      if [ "$LINOP64" = "1" ]; then
         FC_MACRO='FC = pgf90 ${debug} ${ANSYS_INCPATH} -c -mp -fast -Mscalarsse -Mlarge_arrays -fpic -tp k8-64 -Mrecursive -DPGI_COMPILER -DLINUXIA64_SYS -DFORTRAN'
         CC_MACRO='CC = pgcc ${debug} ${ANSYS_INCPATH} -fpic -tp k8-64 -mp -fast -Mscalarsse -Mlarge_arrays -DPGI_COMPILER -DLINUXIA64_SYS -DNOSPACEBALL -DNOSTDCALL -DARGTRAIL'
         LN_MACRO="LN = pgf90 -shared -Kpic -o $libname $libpath "
      fi

      #set INTEL em64t macros
      if [ $LINX64 -eq 1 ]; then
         FC_MACRO='FC = ifort ${debug} ${ANSYS_INCPATH} -c -w -w90 -fpp -vms -fpic -DLINUX_SYS -DLINUXIA64_SYS '
         CC_MACRO='CC = icc ${debug} ${ANSYS_INCPATH} -c -Qoption,cpp,--c99 -fpic -DLINUX_SYS -DLINUXIA64_SYS '
         LN_MACRO="LN = ld -shared -o $libname $libpath  "
      fi

      ;;

   # unknown machine
   * )
      echo "This system has not been tested for shared objects yet!"
      echo "Please notify Rick Reynolds or Greg Sharpe"
      echo "uname reports: $uname_out"
      exit 2
      ;;
esac

#
# non-system dependent items
#

# macro for includes

# are we in-house?
if [ -d "$ansdir/include" ]; then
   IN_MACRO="IN = -I$ansdir/include -I/$ansdir/pde/include $incpath"
 else
   # assume this is a customer
   IN_MACRO="IN = -I$ansdir/customize/include $incpath"
fi

CC_MACRO="${CC_MACRO} ${addflags}"
FC_MACRO="${FC_MACRO} ${addflags}"

#
# Generate the makefile
#

# put out some comments so finders will know what's going on

echo '# This Makefile was automatically generated using gen_share.sh:' > Makefile
echo "$nl" >> Makefile

echo "# -> ${cmdline}" >> Makefile
echo "$nl" >> Makefile

echo '# It contains settings to create a shared library from the C and FORTRAN source' >> Makefile
echo '# files found in the current directory at the time of gen_share.shs run' >> Makefile
echo "$nl" >> Makefile

echo '# Note that in order to turn on debugging, type: make DB=-g' >> Makefile
echo "$nl" >> Makefile

# put out the macros for compiling and linking

echo '# macros for preprocessing' >> Makefile
echo "$PP_MACRO" >> Makefile
echo "$nl" >> Makefile

echo '# macros for compiling and linking' >> Makefile
echo "$FC_MACRO" >> Makefile
echo "$nl" >> Makefile

echo "$CC_MACRO" >> Makefile
echo "$nl" >> Makefile

echo "$LN_MACRO" >> Makefile
echo "$nl" >> Makefile

echo $IN_MACRO >> Makefile
echo "$nl" >> Makefile

# put out suffix rules

echo '# set suffix rules' >> Makefile
echo ".SUFFIXES : .o .c .F .f" >> Makefile
echo "$nl" >> Makefile

echo ".c.o :" >> Makefile
echo '	${CC} ${DB} ${IN} $<' >> Makefile
echo "$nl" >> Makefile

if [ "$PREPROC" = "FALSE" ]; then
   echo ".F.o :" >> Makefile
   echo '	${FC} ${DB} ${IN} $<' >> Makefile
   echo "$nl" >> Makefile
 else
   echo ".F.f :" >> Makefile
   echo '	${PP} ${IN} $< $@' >> Makefile
   echo "$nl" >> Makefile
fi

echo ".f.o :" >> Makefile
echo '	${FC} ${DB} ${IN} $<' >> Makefile
echo "$nl" >> Makefile

# generate file lists
cfiles=`ls -1 *.c 2>/dev/null` 
ffiles=`ls -1 *.F *.f 2>/dev/null`
hfiles=`ls -1 *.h 2>/dev/null`
if [ "$uselibs" = "1" ]; then
    afiles=`ls -1 *.a 2>/dev/null`
  else
  if [ "$uselibs" = "2" ]; then
    mkdir gs_arch_objs 2>/dev/null
    cp *.a gs_arch_objs
    cd gs_arch_objs
    for i in `find . -name "*.a"`
    do
    ar -X32_64 -x $i
    rm $i
    done
    cd ..
    find gs_arch_objs -name "*.o" > gr_ar_objlist
    afiles=` cat gr_ar_objlist 2>/dev/null`
    rm gr_ar_objlist
  else
  if [ "$uselibs" = "3" ]; then
    mkdir gs_arch_objs 2>/dev/null
    cp *.a gs_arch_objs
    cd gs_arch_objs
    for i in `find . -name "*.a"`
    do
    ar -x $i
    rm $i
    done
    cd ..
    find gs_arch_objs -name "*.o" > gr_ar_objlist
     afiles=" -c gr_ar_objlist "
  fi
  fi
fi
incfiles=`ls -1 *.inc 2>/dev/null`

#echo $afiles
#echo LIBS $libs

ofiles=`echo $cfiles $ffiles $allex $afiles | sed 's/\.c/\.o/g' | sed 's/\.F/\.o/g' | sed 's/\.f/\.o/g'`
if [ -z "$ofiles" ]; then
   echo "No source files found.  Exiting..."
   exit 0
fi

# create OBJS macro

echo '# The source files for these .o files were found in the current directory' >> Makefile
echo "OBJS = $bs" >> Makefile
set -- $ofiles
while [ $# -gt 1 ];
do
   echo " $1 $bs" >> Makefile
   shift
done
if [ "$libs" = "" ]; then
   echo " $1" >> Makefile
else
   echo " $1 $bs" >> Makefile
   set -- $libs
   while [ $# -gt 1 ];
   do
      echo " $1 $bs" >> Makefile
      shift
   done
   echo " $1" >> Makefile
fi

echo "$nl" >> Makefile

# put out main dependency so make will default correctly
echo '# main dependency' >> Makefile
echo "$libname $libpath : " '${OBJS}' '${FRC}' >> Makefile
echo '	${LN} ${OBJS} ' >> Makefile
echo "$nl" >> Makefile

# put out fake null dependency to allow make rebuild
echo "# rebuild dependency will force a complete rebuild of $libname $libpath" >> Makefile
echo "rebuild :" >> Makefile
echo "	make $libname $libpath FRC=force_rebuild" >> Makefile
echo "$nl" >> Makefile

echo '# force_rebuild is a fake dependency to allow complete rebuild' >> Makefile
echo "force_rebuild :" >> Makefile
echo "$nl" >> Makefile

echo '# relink will allow a quick relinking of the code' >> Makefile
echo "relink :" >> Makefile
echo '	${LN} ${OBJS}' >> Makefile
echo "$nl" >> Makefile

# deal with inc dependencies
echo '# These dependencies were found in the current directory' >> Makefile
for f in $ffiles
do
   file_not_printed="TRUE"
   for i in $incfiles
   do
      found=`grep -c "$i" $f`
      if [ "$found" != "0" ]; then
         if [ "$file_not_printed" = "TRUE" ]; then
            echo ${dn}"$f : $i ${nn}" >> Makefile
            file_not_printed="FALSE"
          else
	    echo " $i$ ${nn}" >> Makefile
         fi
      fi
   done
      echo " " >> Makefile

   if [ "$file_not_printed" = "FALSE" ]; then
      echo "$nl" >> Makefile
      echo "	touch $f" >> Makefile
      echo "$nl" >> Makefile
   fi
done

# deal with h dependencies
for c in $cfiles
do
   file_not_printed="TRUE"
   for h in $hfiles
   do
      found=`grep -c "$h" $c`
      if [ "$found" != "0" ]; then
         if [ "$file_not_printed" = "TRUE" ]; then
            echo $dn"$c : $h ${nn}" >> Makefile
            file_not_printed="FALSE"
          else
            echo $dn" $h ${nn}" >> Makefile
         fi
      fi
   done


   if [ "$file_not_printed" = "FALSE" ]; then
      echo "$nl" >> Makefile
      echo "	touch $c" >> Makefile
      echo "$nl" >> Makefile
   fi
done

# deal with inc-h dependencies
echo $incfiles > tinc
for i in $incfiles
do
   file_not_printed="TRUE"
   for h in $incfiles
   do
      found=`grep -c "$h" $i`
      if [ "$found" != "0" ]; then
         if [ "$file_not_printed" = "TRUE" ]; then
            echo ${dn}"$i : $h ${nn}" >> Makefile
            file_not_printed="FALSE"
          else
            echo ${dn}" $h ${nn}" >> Makefile
         fi
      fi
   done

   if [ "$file_not_printed" = "FALSE" ]; then
      echo "$nl" >> Makefile
      echo "	touch $i" >> Makefile
      echo "$nl" >> Makefile
   fi
done

# put out .o dependent on FRC
echo '${OBJS} : ${FRC}' >> Makefile

make -f Makefile

# general information applicable to all platforms
cat <<EOGENERAL

   A Makefile has been generated and run in the local directory.  

   Standard compilation and link error are displayed on standard out.

   You may edit and run make on the resulting file to modify the
   contents or links created by the make command during executions of
   gen_share.sh

EOGENERAL

# system dependent last information
case `echo $uname_out | cut -d" " -f1` in
   AIX )
      echo "AIX users:"
      echo " "
      echo "   In order for the shared library to link successfully, "
      echo "   be sure the ansysAIX.exp file (distributed on the "
      echo "   ansys media) is in the local directory before 'make'ing"
      echo "   the shared library."
      echo " "
      if [ "$uselibs" = "2" ];then
         echo "   Static library objects were used in this build"
         echo "   the objects were placed in gr_arch_objs."
         echo "   These object should be retained for use with"
         echo "   the gen_share.sh generated Makefile."
         echo " "
      fi
      ;;
   HP-UX )
      if [ "$release" = "B.10.20" ]; then
      if [ "$uselibs" = "3" ];then
         echo "   Static library objects were used in this build"
         echo "   the objects were placed in gr_arch_objs."
         echo "   These object should be retained for use with"
         echo "   the gen_share.sh generated Makefile."
         echo " "
      fi
      fi
      ;;
   * )
      ;;
esac

# normal exit
exit 0

# HELP section ##########################################
HELP:
   more <<EOHELP

   gen_share.sh [-h] [-64] [-p project] [-g] shared_object_name
                [-I include_path] [+f compiler_option]
		[-L library_ path] [-l library] [-usestatic]

   gen_share.sh will create a makefile in the current directory that
   incorporates all the interdependencies of the FORTRAN and C
   files listed in the current directory.
   
   It will handle .F .f .inc .c and .h files.

Options:
   -h                       Print this help screen.

   -64                      Meanigful only for IRIX64 6.1 and 6.2
                            Causes the Makefile to uses -mips4 option.

   -p project	            The project name defines the name of the
                            shared_object_name.  Overrides shared_object
                            name.

   -g                       Sets the debug option for the compilers on
                            all platforms in the output Makefile.

   -L library_path          Path to additional shared or static libraries
                            which are required by the shared library to 
                            be built.

   -l library               Name of subordinate shared or static libraries
                            which satisfy external dependencies of the shared
                            library to be built. Library name is assumed to 
                            be preceed by lib. "-l myshared" would be assumed to
                            be locable as "libmyshared.so".

   -I includepath           Add additional include paths

   +f                       Add additional compiler options

   -usestatic               This option can be used to build shared libraries
			    from existing static libraries. Libraries to be
                            used in the build should be specified using the 
                            appropriate path -L and library -l.



Arguments:
   shared_object_name       The name of you want the shared object
                            to have when make creates it.



NOTES:

   This utility creates a makefile and runs make to generate a 
   shared library based on input arguments.  You may edit the
   resulting Makefile and run make to create modfied local versions
   of the shared object file.

   At times during the execution of this script, you may see the 
   message "No match" displayed to the screen.  This is normal.
   In this instance, gen_share.sh is searching the current directory for
   the different types of files -- your directory may not contain
   files of each type.

   As with any make process the shared library will not be created if
   errors occur during compilation or linking.

EOHELP
   exit 0

