#!/bin/sh
#
# Merge between "autoconf" and "configure" by Jordan NININ
#
# "configure" for ampl/solvers (called ASL below)
# Originally written by David M. Gay at Sandia National Labs, where it
# was Approved for Unclassified-Unlimited release: SAND Number 2005-7812P
# Modified to permit "path/to/ASL/configure" invocations.

## When in the ASL (AMPL/Solver interface Library) source directory, invoke
##	./configure
## (no args) to make system-dependent files in directory $OBJDIR
## (default sys.`uname -m`.`uname -s`).

## Alternatively, when in another directory, invoke
##	path/to/ASL/configure
## to make system-dependent files in the current directory,
## which becomes $OBJDIR.

## Among other things, create $OBJDIR/makefile there from makefile.u.
## Specify CC before invoking to adjust the CC setting in makefile.
## Specify CFLAGS before invoking to adjust CFLAGS setting in the makefile.
## CFLAGS may be further adjusted by tests done below.

## When invoked in the ASL directory, this script also adds there a
## short makefile that forwards "make" and
## "make clean" to $OBJDIR and that removes $OBJDIR with "make veryclean".




# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
  return $1
} # as_fn_set_status

# as_fn_exit STATUS
# -----------------
# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
as_fn_exit ()
{
  set +e
  as_fn_set_status $1
  exit $1
} # as_fn_exit


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  $as_echo "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error


prefix=NONE
ac_prev=
ac_dashdash=
for ac_option
do
  # If the previous option needs an argument, assign it.
  if test -n "$ac_prev"; then
    eval $ac_prev=\$ac_option
    ac_prev=
    continue
  fi

  case $ac_option in
  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
  *=)   ac_optarg= ;;
  *)    ac_optarg=yes ;;
  esac


  # Accept the important Cygnus configure options, so we can diagnose typos.

  case $ac_dashdash$ac_option in
  --)
    ac_dashdash=yes ;;

  -enable-* | --enable-*)
  # nothing to do
  ;;
  
  -disable-* | --disable-*)
  # nothing to do
  ;;  
    
  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
    ac_prev=prefix ;;
  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
    prefix=$ac_optarg ;;

  -*) as_fn_error $? "unrecognized option: \`$ac_option'
Try \`$0 --help' for more information"
    ;;


  
  *=*)
    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
    # Reject names that are not valid shell variable names.
    case $ac_envvar in #(
      '' | [0-9]* | *[!_$as_cr_alnum]* )
      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
    esac
    eval $ac_envvar=\$ac_optarg
    export $ac_envvar ;;

  *)
    # FIXME: should be removed in autoconf 3.0.
    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
    ;;

  esac
done

if test -n "$ac_prev"; then
  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
  as_fn_error $? "missing argument to $ac_option"
fi

if test -n "$ac_unrecognized_opts"; then
  case $enable_option_checking in
    no) ;;
    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
  esac
fi

# Check all directory arguments for consistency.
for ac_var in	prefix 
do
  eval ac_val=\$$ac_var
  # Remove trailing slashes.
  case $ac_val in
    */ )
      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
      eval $ac_var=\$ac_val;;
  esac
  # Be sure to have absolute directory names.
  case $ac_val in
    [\\/$]* | ?:[\\/]* )  continue;;
    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
  esac
  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
done


###################################################"

OBJDIR=${OBJDIR=sys.`uname -m`.`uname -s`}
rm -rf $OBJDIR makefile Makefile
cat <<! >makefile
amplsolver:
	cd $OBJDIR; make

shared:
	cd $OBJDIR; make shared

install:
	cd $OBJDIR; make install prefix=$prefix

clean:
	cd $OBJDIR; make clean

veryclean:
	rm -rf $OBJDIR

distclean:
	rm -rf sys.*.*
!

mkdir $OBJDIR

ln `sed 's/	.*//' xsum0.out` xsum0.out $OBJDIR || \
cp -p `sed 's/	.*//' xsum0.out` xsum0.out $OBJDIR
# cp -p is for cygwin
cd $OBJDIR
./configurehere



