Blame build-aux/ar-lib

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