#!/bin/sh

# "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".

ASLdir=`dirname $0`
case $ASLdir in
	.)
	OBJDIR=${OBJDIR=sys.`uname -m`.`uname -s`}
	rm -rf $OBJDIR makefile Makefile
	cat <<\! >makefile
amplsolver:
	cd $${OBJDIR=sys.`uname -m`.`uname -s`}; make

clean:
	cd $${OBJDIR=sys.`uname -m`.`uname -s`}; make clean

veryclean:
	rm -rf $${OBJDIR=sys.`uname -m`.`uname -s`}

distclean:
	rm -rf sys.*.*
!
	mkdir $OBJDIR
	;; *)
	OBJDIR=`pwd`
	rm -f `sed 's/	.*//' $ASLdir/xsum0.out` makefile Makefile xsum0.out
	cd $ASLdir
	;; esac

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