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