190a8ff21Smrg#!/bin/sh 290a8ff21Smrg# Wrapper for Microsoft lib.exe 390a8ff21Smrg 490a8ff21Smrgme=ar-lib 590a8ff21Smrgscriptversion=2019-07-04.01; # UTC 690a8ff21Smrg 7*367b8279Smrg# Copyright (C) 2010-2021 Free Software Foundation, Inc. 890a8ff21Smrg# Written by Peter Rosin <peda@lysator.liu.se>. 990a8ff21Smrg# 1090a8ff21Smrg# This program is free software; you can redistribute it and/or modify 1190a8ff21Smrg# it under the terms of the GNU General Public License as published by 1290a8ff21Smrg# the Free Software Foundation; either version 2, or (at your option) 1390a8ff21Smrg# any later version. 1490a8ff21Smrg# 1590a8ff21Smrg# This program is distributed in the hope that it will be useful, 1690a8ff21Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1790a8ff21Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1890a8ff21Smrg# GNU General Public License for more details. 1990a8ff21Smrg# 2090a8ff21Smrg# You should have received a copy of the GNU General Public License 2190a8ff21Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2290a8ff21Smrg 2390a8ff21Smrg# As a special exception to the GNU General Public License, if you 2490a8ff21Smrg# distribute this file as part of a program that contains a 2590a8ff21Smrg# configuration script generated by Autoconf, you may include it under 2690a8ff21Smrg# the same distribution terms that you use for the rest of that program. 2790a8ff21Smrg 2890a8ff21Smrg# This file is maintained in Automake, please report 2990a8ff21Smrg# bugs to <bug-automake@gnu.org> or send patches to 3090a8ff21Smrg# <automake-patches@gnu.org>. 3190a8ff21Smrg 3290a8ff21Smrg 3390a8ff21Smrg# func_error message 3490a8ff21Smrgfunc_error () 3590a8ff21Smrg{ 3690a8ff21Smrg echo "$me: $1" 1>&2 3790a8ff21Smrg exit 1 3890a8ff21Smrg} 3990a8ff21Smrg 4090a8ff21Smrgfile_conv= 4190a8ff21Smrg 4290a8ff21Smrg# func_file_conv build_file 4390a8ff21Smrg# Convert a $build file to $host form and store it in $file 4490a8ff21Smrg# Currently only supports Windows hosts. 4590a8ff21Smrgfunc_file_conv () 4690a8ff21Smrg{ 4790a8ff21Smrg file=$1 4890a8ff21Smrg case $file in 4990a8ff21Smrg / | /[!/]*) # absolute file, and not a UNC file 5090a8ff21Smrg if test -z "$file_conv"; then 5190a8ff21Smrg # lazily determine how to convert abs files 5290a8ff21Smrg case `uname -s` in 5390a8ff21Smrg MINGW*) 5490a8ff21Smrg file_conv=mingw 5590a8ff21Smrg ;; 5690a8ff21Smrg CYGWIN* | MSYS*) 5790a8ff21Smrg file_conv=cygwin 5890a8ff21Smrg ;; 5990a8ff21Smrg *) 6090a8ff21Smrg file_conv=wine 6190a8ff21Smrg ;; 6290a8ff21Smrg esac 6390a8ff21Smrg fi 6490a8ff21Smrg case $file_conv in 6590a8ff21Smrg mingw) 6690a8ff21Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6790a8ff21Smrg ;; 6890a8ff21Smrg cygwin | msys) 6990a8ff21Smrg file=`cygpath -m "$file" || echo "$file"` 7090a8ff21Smrg ;; 7190a8ff21Smrg wine) 7290a8ff21Smrg file=`winepath -w "$file" || echo "$file"` 7390a8ff21Smrg ;; 7490a8ff21Smrg esac 7590a8ff21Smrg ;; 7690a8ff21Smrg esac 7790a8ff21Smrg} 7890a8ff21Smrg 7990a8ff21Smrg# func_at_file at_file operation archive 8090a8ff21Smrg# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 8190a8ff21Smrg# for each of them. 8290a8ff21Smrg# When interpreting the content of the @FILE, do NOT use func_file_conv, 8390a8ff21Smrg# since the user would need to supply preconverted file names to 8490a8ff21Smrg# binutils ar, at least for MinGW. 8590a8ff21Smrgfunc_at_file () 8690a8ff21Smrg{ 8790a8ff21Smrg operation=$2 8890a8ff21Smrg archive=$3 8990a8ff21Smrg at_file_contents=`cat "$1"` 9090a8ff21Smrg eval set x "$at_file_contents" 9190a8ff21Smrg shift 9290a8ff21Smrg 9390a8ff21Smrg for member 9490a8ff21Smrg do 9590a8ff21Smrg $AR -NOLOGO $operation:"$member" "$archive" || exit $? 9690a8ff21Smrg done 9790a8ff21Smrg} 9890a8ff21Smrg 9990a8ff21Smrgcase $1 in 10090a8ff21Smrg '') 10190a8ff21Smrg func_error "no command. Try '$0 --help' for more information." 10290a8ff21Smrg ;; 10390a8ff21Smrg -h | --h*) 10490a8ff21Smrg cat <<EOF 10590a8ff21SmrgUsage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...] 10690a8ff21Smrg 10790a8ff21SmrgMembers may be specified in a file named with @FILE. 10890a8ff21SmrgEOF 10990a8ff21Smrg exit $? 11090a8ff21Smrg ;; 11190a8ff21Smrg -v | --v*) 11290a8ff21Smrg echo "$me, version $scriptversion" 11390a8ff21Smrg exit $? 11490a8ff21Smrg ;; 11590a8ff21Smrgesac 11690a8ff21Smrg 11790a8ff21Smrgif test $# -lt 3; then 11890a8ff21Smrg func_error "you must specify a program, an action and an archive" 11990a8ff21Smrgfi 12090a8ff21Smrg 12190a8ff21SmrgAR=$1 12290a8ff21Smrgshift 12390a8ff21Smrgwhile : 12490a8ff21Smrgdo 12590a8ff21Smrg if test $# -lt 2; then 12690a8ff21Smrg func_error "you must specify a program, an action and an archive" 12790a8ff21Smrg fi 12890a8ff21Smrg case $1 in 12990a8ff21Smrg -lib | -LIB \ 13090a8ff21Smrg | -ltcg | -LTCG \ 13190a8ff21Smrg | -machine* | -MACHINE* \ 13290a8ff21Smrg | -subsystem* | -SUBSYSTEM* \ 13390a8ff21Smrg | -verbose | -VERBOSE \ 13490a8ff21Smrg | -wx* | -WX* ) 13590a8ff21Smrg AR="$AR $1" 13690a8ff21Smrg shift 13790a8ff21Smrg ;; 13890a8ff21Smrg *) 13990a8ff21Smrg action=$1 14090a8ff21Smrg shift 14190a8ff21Smrg break 14290a8ff21Smrg ;; 14390a8ff21Smrg esac 14490a8ff21Smrgdone 14590a8ff21Smrgorig_archive=$1 14690a8ff21Smrgshift 14790a8ff21Smrgfunc_file_conv "$orig_archive" 14890a8ff21Smrgarchive=$file 14990a8ff21Smrg 15090a8ff21Smrg# strip leading dash in $action 15190a8ff21Smrgaction=${action#-} 15290a8ff21Smrg 15390a8ff21Smrgdelete= 15490a8ff21Smrgextract= 15590a8ff21Smrglist= 15690a8ff21Smrgquick= 15790a8ff21Smrgreplace= 15890a8ff21Smrgindex= 15990a8ff21Smrgcreate= 16090a8ff21Smrg 16190a8ff21Smrgwhile test -n "$action" 16290a8ff21Smrgdo 16390a8ff21Smrg case $action in 16490a8ff21Smrg d*) delete=yes ;; 16590a8ff21Smrg x*) extract=yes ;; 16690a8ff21Smrg t*) list=yes ;; 16790a8ff21Smrg q*) quick=yes ;; 16890a8ff21Smrg r*) replace=yes ;; 16990a8ff21Smrg s*) index=yes ;; 17090a8ff21Smrg S*) ;; # the index is always updated implicitly 17190a8ff21Smrg c*) create=yes ;; 17290a8ff21Smrg u*) ;; # TODO: don't ignore the update modifier 17390a8ff21Smrg v*) ;; # TODO: don't ignore the verbose modifier 17490a8ff21Smrg *) 17590a8ff21Smrg func_error "unknown action specified" 17690a8ff21Smrg ;; 17790a8ff21Smrg esac 17890a8ff21Smrg action=${action#?} 17990a8ff21Smrgdone 18090a8ff21Smrg 18190a8ff21Smrgcase $delete$extract$list$quick$replace,$index in 18290a8ff21Smrg yes,* | ,yes) 18390a8ff21Smrg ;; 18490a8ff21Smrg yesyes*) 18590a8ff21Smrg func_error "more than one action specified" 18690a8ff21Smrg ;; 18790a8ff21Smrg *) 18890a8ff21Smrg func_error "no action specified" 18990a8ff21Smrg ;; 19090a8ff21Smrgesac 19190a8ff21Smrg 19290a8ff21Smrgif test -n "$delete"; then 19390a8ff21Smrg if test ! -f "$orig_archive"; then 19490a8ff21Smrg func_error "archive not found" 19590a8ff21Smrg fi 19690a8ff21Smrg for member 19790a8ff21Smrg do 19890a8ff21Smrg case $1 in 19990a8ff21Smrg @*) 20090a8ff21Smrg func_at_file "${1#@}" -REMOVE "$archive" 20190a8ff21Smrg ;; 20290a8ff21Smrg *) 20390a8ff21Smrg func_file_conv "$1" 20490a8ff21Smrg $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $? 20590a8ff21Smrg ;; 20690a8ff21Smrg esac 20790a8ff21Smrg done 20890a8ff21Smrg 20990a8ff21Smrgelif test -n "$extract"; then 21090a8ff21Smrg if test ! -f "$orig_archive"; then 21190a8ff21Smrg func_error "archive not found" 21290a8ff21Smrg fi 21390a8ff21Smrg if test $# -gt 0; then 21490a8ff21Smrg for member 21590a8ff21Smrg do 21690a8ff21Smrg case $1 in 21790a8ff21Smrg @*) 21890a8ff21Smrg func_at_file "${1#@}" -EXTRACT "$archive" 21990a8ff21Smrg ;; 22090a8ff21Smrg *) 22190a8ff21Smrg func_file_conv "$1" 22290a8ff21Smrg $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $? 22390a8ff21Smrg ;; 22490a8ff21Smrg esac 22590a8ff21Smrg done 22690a8ff21Smrg else 22790a8ff21Smrg $AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \ 22890a8ff21Smrg | while read member 22990a8ff21Smrg do 23090a8ff21Smrg $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $? 23190a8ff21Smrg done 23290a8ff21Smrg fi 23390a8ff21Smrg 23490a8ff21Smrgelif test -n "$quick$replace"; then 23590a8ff21Smrg if test ! -f "$orig_archive"; then 23690a8ff21Smrg if test -z "$create"; then 23790a8ff21Smrg echo "$me: creating $orig_archive" 23890a8ff21Smrg fi 23990a8ff21Smrg orig_archive= 24090a8ff21Smrg else 24190a8ff21Smrg orig_archive=$archive 24290a8ff21Smrg fi 24390a8ff21Smrg 24490a8ff21Smrg for member 24590a8ff21Smrg do 24690a8ff21Smrg case $1 in 24790a8ff21Smrg @*) 24890a8ff21Smrg func_file_conv "${1#@}" 24990a8ff21Smrg set x "$@" "@$file" 25090a8ff21Smrg ;; 25190a8ff21Smrg *) 25290a8ff21Smrg func_file_conv "$1" 25390a8ff21Smrg set x "$@" "$file" 25490a8ff21Smrg ;; 25590a8ff21Smrg esac 25690a8ff21Smrg shift 25790a8ff21Smrg shift 25890a8ff21Smrg done 25990a8ff21Smrg 26090a8ff21Smrg if test -n "$orig_archive"; then 26190a8ff21Smrg $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $? 26290a8ff21Smrg else 26390a8ff21Smrg $AR -NOLOGO -OUT:"$archive" "$@" || exit $? 26490a8ff21Smrg fi 26590a8ff21Smrg 26690a8ff21Smrgelif test -n "$list"; then 26790a8ff21Smrg if test ! -f "$orig_archive"; then 26890a8ff21Smrg func_error "archive not found" 26990a8ff21Smrg fi 27090a8ff21Smrg $AR -NOLOGO -LIST "$archive" || exit $? 27190a8ff21Smrgfi 272