Blame ar-lib

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