#!/bin/csh -f
#
# ABACUS library generation tool
#
# $Id: make-lib,v 1.5 1998/10/19 09:14:40 boehm Exp $

set name = $0

if ($name:h != $name:t) then
  cd $name:h
endif

if ($#argv == 0) then
  echo "Use this program to build LP solver specific versions of the ABACUS library."
  echo ""
  echo "usage:    make-lib <interfaces> ..."
  echo ""
  echo "where <interfaces> is one of"
  echo ""
  echo "cplex22, cplex30, cplex40, cplex50, cplex60, soplex, xpress"
  echo ""
  echo "or a combination of them (connected by the character '-')."
  echo "The relative order of the strings must be preserved."
  echo ""
  echo "Examples:"
  echo "make-lib cplex40                 build library for Cplex 4.0"
  echo "make-lib soplex                  build library for Soplex"
  echo "make-lib xpress                  build library for Xpress 10"
  echo "make-lib soplex-xpress           build library for Soplex and Xpress 10"
  echo "make-lib cplex60-soplex-xpress   build library for Cplex 6.0, Soplex and Xpress"
  exit
endif


foreach i ($*)

  # create the ABACUS library
  set abacus = libabacus-$i.a
  echo "creating $abacus ..."

  # copy the basic ABACUS library
  cp stuff/abacus-base.a $abacus

  # add the LP solver interface libraries
  foreach f (`echo $i | tr '-' ' '`)
    set name = stuff/interface-$f.a
    if (! -f $name) then
      echo "LP solver interface $f does not exist."
      echo "Aborting."
      rm -rf $abacus
      exit
    endif

    # extract objects and add them to the archive $abacus
    set files = `ar t $name | grep '\.o'`
    echo "adding $files..."
    ar x $name $files
    ar r $abacus $files
    rm $files
  end

  # add the interface object file
  set name = `echo stuff/lpif-$i.o | tr -d 0-9`
  if (! -f $name) then
      echo "Interface file $name does not exist."
      echo "(The interfaces must be specified in the order cplex-soplex-xpress.)"
      rm -rf $abacus
      echo "Aborting."
      exit
  endif
  echo "adding $name..."
  ar r $abacus $name

  ranlib $abacus

  echo "$abacus was created successfully."
end
