#!/bin/sh
#
# Shell script to configure SPIM.
#
# Copyright (C) 1992 by James Larus (larus@cs.wisc.edu).
# ALL RIGHTS RESERVED.
#
# SPIM is distributed under the following conditions:
#
#   You may make copies of SPIM for your own use and modify those copies.
#
#   All copies of SPIM must retain my name and copyright notice.
#
#   You may not sell SPIM or distributed SPIM in conjunction with a commerical
#   product or service without the expressed written consent of James Larus.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE.
#
# $Header: /home/primost/larus/RCS/Configure,v 1.6 1993/01/18 15:00:43 larus Exp larus $
#
# Shell script to create proper links to machine-dependent files for SPIM.
#
#
# Usage: Configure
#

echo Check if this machine is big-endian or little-endian.
echo This may take a few minutes.
rm -f configuration
cc endian.c -o endian
if ./endian; then
  # Big endian
  rm -f Tests/tt.s Tests/tt.OK configuration
  cd Tests
  ln -s tt.be.s tt.s
  ln -s tt.be.OK tt.OK
  cd ..
  echo "-DBIGENDIAN" > configuration
  echo I believe this is a big-endian machine.
else
  # Little endian
  rm -f Tests/tt.s Tests/tt.OK configuration
  cd Tests
  ln -s tt.le.s tt.s
  ln -s tt.le.OK tt.OK
  cd ..
  echo "-DLITTLEENDIAN" > configuration
  echo I believe this is a little-endian machine.
fi;
rm -f endian

if [ -f /usr/lib/libc.a ]; then
  # BSD Universe:
  echo Looks like a BSD-based system...
  echo Scaning libc
  nm /usr/lib/libc.a > library_contents
  echo
  echo Checking if libc on this machine contains vsprintf
  if  grep -s 'vsprintf' library_contents; then
    echo "Yes, I think so"
  else
    # No vsprintf
    echo "-DNEED_VSPRINTF" >> configuration
    echo "No, I don't think so"
  fi;

  echo
  echo Checking if libc on this machine contains strtoul
  if grep -s 'strtoul' library_contents; then
    echo "Yes, I think so"
  else
    # No strtol
    echo "-DNEED_STRTOL" >> configuration
    echo "No, I don't think so"
  fi;

  echo
  echo Checking if libc on this machine contains strtol
  if grep -s 'strtol' library_contents; then
    echo "Yes, I think so"
  else
    # No strtol
    echo "-DNEED_STRTOL" >> configuration
    echo "No, I don't think so"
  fi;

else if [ -f /lib/libc.a ]; then
  # System V Universe:
  echo Looks like a System V-based system...
  echo Scaning libc
  nm /lib/libc.a > library_contents
  echo
  echo Checking if libc on this machine contains vsprintf
  if  grep -q 'vsprintf' library_contents; then
    echo "Yes, I think so"
  else
    # No vsprintf
    echo "-DNEED_VSPRINTF" >> configuration
    echo "No, I don't think so"
  fi;

  echo
  echo Checking if libc on this machine contains strtoul
  if grep -q 'strtoul' library_contents; then
    echo "Yes, I think so"
  else
    # No strtol
    echo "-DNEED_STRTOL" >> configuration
    echo "No, I don't think so"
  fi;

  echo
  echo Checking if libc on this machine contains strtol
  if grep -q 'strtol' library_contents; then
    echo "Yes, I think so"
  else
    # No strtol
    echo "-DNEED_STRTOL" >> configuration
    echo "No, I don't think so"
  fi;

fi;
fi;

rm -f library_contents
