#!/bin/sh
##############################################################################
# unix2nt_ar: Maps UNIX ar command options to 
# Microsoft Visual C++ 6.0 LIB command line options.
#
# Known bugs: pathnames with spaces may cause quoting problems.
#
# Orion Sky Lawlor, olawlor@acm.org, 1/24/2001
##############################################################################

# Configurable option: Location of MSDEV
#VCC_DIR="C:/Program Files/Microsoft Visual Studio/Vc98"
if test -z "$VCINSTALLDIR"
then
  VCC_DIR="C:/Program Files/Microsoft Visual Studio 9.0/VC"
else
  VCC_DIR=$VCINSTALLDIR
fi

LIB_CMD="$VCC_DIR/BIN/LIB.EXE"
LIB_OPTS='/nologo'

if [ "x$LIB" = "x" ]
then
	export INCLUDE="$VCC_DIR/include"
	export LIB="$VCC_DIR/lib"
fi

###################################################################
#
#  Utility routines used below
#
###################################################################

# PrintUsage: prints a helpful command-line usage message and quits
# Args: any additional messages
printUsage() {
    echo "Usage: unix2nt_ar <output file> <input files>"
    echo
	echo "Version 1.0, Parallel Programming Lab, UIUC, 2001"
    echo $*
    exit 1
}

# End blows away the temporary files (unless SAVE is true) and exits
# Args: <exit code>
End() {
    exit $1
}

# This procedure prints an error message and exits.
# ("1>&2" redirects the echo output to stderr).
# Args: written to stderr
Abort() {
	echo "unix2nt_ar Fatal Error in directory "`pwd` 1>&2
	echo "   $*" 1>&2
	echo "unix2nt_ar exiting..." 1>&2
	End 1
}

##############################################################################
#
# Parse & convert the arguments
#
##############################################################################

[ $# -eq 1 ] && exit 0
[ $# -lt 2 ] && printUsage "Error: Not enough arguments given."

out=$(cygpath -w $1)
shift
args="/out:$out $@"

"$LIB_CMD" $LIB_OPTS $args

if [ $? != 0 ]
then
	Abort "Error executing" "$LIB_CMD" $LIB_OPTS $args
fi

exit 0
