#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/ranlib                      */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 14:04:49 1995                          */
#*    Last change :  Wed Jan 15 14:24:40 2003 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Checking for ranlib                                              */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cc=gcc
cflags=
tmp=/tmp
user=bigloo

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --user=*)
      user="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cc=*|-cc=*)
      cc="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cflags=*|-cflags=*)
      cflags="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --tmp=*|-tmp=*)
      tmp="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$tmp/actest$user
aout=$tmp/Xactest$user
obj=`basename $file`

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compile="$cc $cflags -c $file.c >/dev/null 2> /dev/null"

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if test -f $file.c; then
   rm -f $file.c || exit $?
fi

cd $tmp

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
int main () { ; }
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if $cc $cflags -c $file.c -o $obj.o >/dev/null 2>&1
then
   true
else
   exit $?
fi

#*---------------------------------------------------------------------*/
#*    We build a library                                               */
#*---------------------------------------------------------------------*/
ar qcv $file.a $obj.o > /dev/null 2> /dev/null || exit $?

#*---------------------------------------------------------------------*/
#*    We try to run ranlib                                             */
#*---------------------------------------------------------------------*/
if eval "ranlib $file.a  > /dev/null 2>&1" > /dev/null 2> /dev/null
then
   rm -f $file.*
   echo 1
else
   rm -f $file.*
   echo 0
fi
