#!/bin/sh

# Wrapper around MS's lib.exe to make it act more like Unix ar

case $MACHTYPE in
    *-msys)
        slash="-"
        ;;
    *)
        slash="/"
        ;;
esac

# prog specifies the program that should be run cl.exe
prog=lib
# opts specifies the command line to pass to the MSVC program
libopt="${slash}nologo"
verbose=1

processargs()
{
    # Ignore first argument (q, rfs...)
    shift
    # Add out library
    libopt="${libopt},${slash}out:${1}"
    shift
    # Modify path for files
    for arg in $@; do
        path=$(cygpath -w "${arg}")
        libopt="${libopt},${path}"
    done

}

IFS=""
processargs $@

# Default LIB environment variable is overwritten by some makefiles ...
# So we just add it with LIBPATH (LIB is backed up in VC_LIB)
IFS=";"
for p in ${VC_LIB}; do
  libopt="${libopt},${slash}LIBPATH:${p}"
done

if test "x$V" = "x1" ; then
    verbose=1
fi

IFS=","
if test -n "$verbose" ; then
  printf "%s" "$prog"
  for opt in ${libopt} ; do
    printf "%s" " \"$opt\""
  done
  echo ""
fi

exec ${prog} ${libopt}

