Blame ar-lib

rpm-build d42185
#! /bin/sh
rpm-build d42185
# Wrapper for Microsoft lib.exe
rpm-build d42185
rpm-build d42185
me=ar-lib
rpm-build d42185
scriptversion=2012-03-01.08; # UTC
rpm-build d42185
rpm-build d42185
# Copyright (C) 2010, 2012 Free Software Foundation, Inc.
rpm-build d42185
# Written by Peter Rosin <peda@lysator.liu.se>.
rpm-build d42185
#
rpm-build d42185
# This program is free software; you can redistribute it and/or modify
rpm-build d42185
# it under the terms of the GNU General Public License as published by
rpm-build d42185
# the Free Software Foundation; either version 2, or (at your option)
rpm-build d42185
# any later version.
rpm-build d42185
#
rpm-build d42185
# This program is distributed in the hope that it will be useful,
rpm-build d42185
# but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build d42185
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rpm-build d42185
# GNU General Public License for more details.
rpm-build d42185
#
rpm-build d42185
# You should have received a copy of the GNU General Public License
rpm-build d42185
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
rpm-build d42185
rpm-build d42185
# As a special exception to the GNU General Public License, if you
rpm-build d42185
# distribute this file as part of a program that contains a
rpm-build d42185
# configuration script generated by Autoconf, you may include it under
rpm-build d42185
# the same distribution terms that you use for the rest of that program.
rpm-build d42185
rpm-build d42185
# This file is maintained in Automake, please report
rpm-build d42185
# bugs to <bug-automake@gnu.org> or send patches to
rpm-build d42185
# <automake-patches@gnu.org>.
rpm-build d42185
rpm-build d42185
rpm-build d42185
# func_error message
rpm-build d42185
func_error ()
rpm-build d42185
{
rpm-build d42185
  echo "$me: $1" 1>&2
rpm-build d42185
  exit 1
rpm-build d42185
}
rpm-build d42185
rpm-build d42185
file_conv=
rpm-build d42185
rpm-build d42185
# func_file_conv build_file
rpm-build d42185
# Convert a $build file to $host form and store it in $file
rpm-build d42185
# Currently only supports Windows hosts.
rpm-build d42185
func_file_conv ()
rpm-build d42185
{
rpm-build d42185
  file=$1
rpm-build d42185
  case $file in
rpm-build d42185
    / | /[!/]*) # absolute file, and not a UNC file
rpm-build d42185
      if test -z "$file_conv"; then
rpm-build d42185
	# lazily determine how to convert abs files
rpm-build d42185
	case `uname -s` in
rpm-build d42185
	  MINGW*)
rpm-build d42185
	    file_conv=mingw
rpm-build d42185
	    ;;
rpm-build d42185
	  CYGWIN*)
rpm-build d42185
	    file_conv=cygwin
rpm-build d42185
	    ;;
rpm-build d42185
	  *)
rpm-build d42185
	    file_conv=wine
rpm-build d42185
	    ;;
rpm-build d42185
	esac
rpm-build d42185
      fi
rpm-build d42185
      case $file_conv in
rpm-build d42185
	mingw)
rpm-build d42185
	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
rpm-build d42185
	  ;;
rpm-build d42185
	cygwin)
rpm-build d42185
	  file=`cygpath -m "$file" || echo "$file"`
rpm-build d42185
	  ;;
rpm-build d42185
	wine)
rpm-build d42185
	  file=`winepath -w "$file" || echo "$file"`
rpm-build d42185
	  ;;
rpm-build d42185
      esac
rpm-build d42185
      ;;
rpm-build d42185
  esac
rpm-build d42185
}
rpm-build d42185
rpm-build d42185
# func_at_file at_file operation archive
rpm-build d42185
# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
rpm-build d42185
# for each of them.
rpm-build d42185
# When interpreting the content of the @FILE, do NOT use func_file_conv,
rpm-build d42185
# since the user would need to supply preconverted file names to
rpm-build d42185
# binutils ar, at least for MinGW.
rpm-build d42185
func_at_file ()
rpm-build d42185
{
rpm-build d42185
  operation=$2
rpm-build d42185
  archive=$3
rpm-build d42185
  at_file_contents=`cat "$1"`
rpm-build d42185
  eval set x "$at_file_contents"
rpm-build d42185
  shift
rpm-build d42185
rpm-build d42185
  for member
rpm-build d42185
  do
rpm-build d42185
    $AR -NOLOGO $operation:"$member" "$archive" || exit $?
rpm-build d42185
  done
rpm-build d42185
}
rpm-build d42185
rpm-build d42185
case $1 in
rpm-build d42185
  '')
rpm-build d42185
     func_error "no command.  Try '$0 --help' for more information."
rpm-build d42185
     ;;
rpm-build d42185
  -h | --h*)
rpm-build d42185
    cat <
rpm-build d42185
Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
rpm-build d42185
rpm-build d42185
Members may be specified in a file named with @FILE.
rpm-build d42185
EOF
rpm-build d42185
    exit $?
rpm-build d42185
    ;;
rpm-build d42185
  -v | --v*)
rpm-build d42185
    echo "$me, version $scriptversion"
rpm-build d42185
    exit $?
rpm-build d42185
    ;;
rpm-build d42185
esac
rpm-build d42185
rpm-build d42185
if test $# -lt 3; then
rpm-build d42185
  func_error "you must specify a program, an action and an archive"
rpm-build d42185
fi
rpm-build d42185
rpm-build d42185
AR=$1
rpm-build d42185
shift
rpm-build d42185
while :
rpm-build d42185
do
rpm-build d42185
  if test $# -lt 2; then
rpm-build d42185
    func_error "you must specify a program, an action and an archive"
rpm-build d42185
  fi
rpm-build d42185
  case $1 in
rpm-build d42185
    -lib | -LIB \
rpm-build d42185
    | -ltcg | -LTCG \
rpm-build d42185
    | -machine* | -MACHINE* \
rpm-build d42185
    | -subsystem* | -SUBSYSTEM* \
rpm-build d42185
    | -verbose | -VERBOSE \
rpm-build d42185
    | -wx* | -WX* )
rpm-build d42185
      AR="$AR $1"
rpm-build d42185
      shift
rpm-build d42185
      ;;
rpm-build d42185
    *)
rpm-build d42185
      action=$1
rpm-build d42185
      shift
rpm-build d42185
      break
rpm-build d42185
      ;;
rpm-build d42185
  esac
rpm-build d42185
done
rpm-build d42185
orig_archive=$1
rpm-build d42185
shift
rpm-build d42185
func_file_conv "$orig_archive"
rpm-build d42185
archive=$file
rpm-build d42185
rpm-build d42185
# strip leading dash in $action
rpm-build d42185
action=${action#-}
rpm-build d42185
rpm-build d42185
delete=
rpm-build d42185
extract=
rpm-build d42185
list=
rpm-build d42185
quick=
rpm-build d42185
replace=
rpm-build d42185
index=
rpm-build d42185
create=
rpm-build d42185
rpm-build d42185
while test -n "$action"
rpm-build d42185
do
rpm-build d42185
  case $action in
rpm-build d42185
    d*) delete=yes  ;;
rpm-build d42185
    x*) extract=yes ;;
rpm-build d42185
    t*) list=yes    ;;
rpm-build d42185
    q*) quick=yes   ;;
rpm-build d42185
    r*) replace=yes ;;
rpm-build d42185
    s*) index=yes   ;;
rpm-build d42185
    S*)             ;; # the index is always updated implicitly
rpm-build d42185
    c*) create=yes  ;;
rpm-build d42185
    u*)             ;; # TODO: don't ignore the update modifier
rpm-build d42185
    v*)             ;; # TODO: don't ignore the verbose modifier
rpm-build d42185
    *)
rpm-build d42185
      func_error "unknown action specified"
rpm-build d42185
      ;;
rpm-build d42185
  esac
rpm-build d42185
  action=${action#?}
rpm-build d42185
done
rpm-build d42185
rpm-build d42185
case $delete$extract$list$quick$replace,$index in
rpm-build d42185
  yes,* | ,yes)
rpm-build d42185
    ;;
rpm-build d42185
  yesyes*)
rpm-build d42185
    func_error "more than one action specified"
rpm-build d42185
    ;;
rpm-build d42185
  *)
rpm-build d42185
    func_error "no action specified"
rpm-build d42185
    ;;
rpm-build d42185
esac
rpm-build d42185
rpm-build d42185
if test -n "$delete"; then
rpm-build d42185
  if test ! -f "$orig_archive"; then
rpm-build d42185
    func_error "archive not found"
rpm-build d42185
  fi
rpm-build d42185
  for member
rpm-build d42185
  do
rpm-build d42185
    case $1 in
rpm-build d42185
      @*)
rpm-build d42185
        func_at_file "${1#@}" -REMOVE "$archive"
rpm-build d42185
        ;;
rpm-build d42185
      *)
rpm-build d42185
        func_file_conv "$1"
rpm-build d42185
        $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
rpm-build d42185
        ;;
rpm-build d42185
    esac
rpm-build d42185
  done
rpm-build d42185
rpm-build d42185
elif test -n "$extract"; then
rpm-build d42185
  if test ! -f "$orig_archive"; then
rpm-build d42185
    func_error "archive not found"
rpm-build d42185
  fi
rpm-build d42185
  if test $# -gt 0; then
rpm-build d42185
    for member
rpm-build d42185
    do
rpm-build d42185
      case $1 in
rpm-build d42185
        @*)
rpm-build d42185
          func_at_file "${1#@}" -EXTRACT "$archive"
rpm-build d42185
          ;;
rpm-build d42185
        *)
rpm-build d42185
          func_file_conv "$1"
rpm-build d42185
          $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
rpm-build d42185
          ;;
rpm-build d42185
      esac
rpm-build d42185
    done
rpm-build d42185
  else
rpm-build d42185
    $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
rpm-build d42185
    do
rpm-build d42185
      $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
rpm-build d42185
    done
rpm-build d42185
  fi
rpm-build d42185
rpm-build d42185
elif test -n "$quick$replace"; then
rpm-build d42185
  if test ! -f "$orig_archive"; then
rpm-build d42185
    if test -z "$create"; then
rpm-build d42185
      echo "$me: creating $orig_archive"
rpm-build d42185
    fi
rpm-build d42185
    orig_archive=
rpm-build d42185
  else
rpm-build d42185
    orig_archive=$archive
rpm-build d42185
  fi
rpm-build d42185
rpm-build d42185
  for member
rpm-build d42185
  do
rpm-build d42185
    case $1 in
rpm-build d42185
    @*)
rpm-build d42185
      func_file_conv "${1#@}"
rpm-build d42185
      set x "$@" "@$file"
rpm-build d42185
      ;;
rpm-build d42185
    *)
rpm-build d42185
      func_file_conv "$1"
rpm-build d42185
      set x "$@" "$file"
rpm-build d42185
      ;;
rpm-build d42185
    esac
rpm-build d42185
    shift
rpm-build d42185
    shift
rpm-build d42185
  done
rpm-build d42185
rpm-build d42185
  if test -n "$orig_archive"; then
rpm-build d42185
    $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
rpm-build d42185
  else
rpm-build d42185
    $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
rpm-build d42185
  fi
rpm-build d42185
rpm-build d42185
elif test -n "$list"; then
rpm-build d42185
  if test ! -f "$orig_archive"; then
rpm-build d42185
    func_error "archive not found"
rpm-build d42185
  fi
rpm-build d42185
  $AR -NOLOGO -LIST "$archive" || exit $?
rpm-build d42185
fi