1*4559860eSchristos#! /bin/sh 2*4559860eSchristos# Wrapper for Microsoft lib.exe 3*4559860eSchristos 4*4559860eSchristosme=ar-lib 5*4559860eSchristosscriptversion=2012-03-01.08; # UTC 6*4559860eSchristos 7*4559860eSchristos# Copyright (C) 2010-2017 Free Software Foundation, Inc. 8*4559860eSchristos# Written by Peter Rosin <peda@lysator.liu.se>. 9*4559860eSchristos# 10*4559860eSchristos# This program is free software; you can redistribute it and/or modify 11*4559860eSchristos# it under the terms of the GNU General Public License as published by 12*4559860eSchristos# the Free Software Foundation; either version 2, or (at your option) 13*4559860eSchristos# any later version. 14*4559860eSchristos# 15*4559860eSchristos# This program is distributed in the hope that it will be useful, 16*4559860eSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*4559860eSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*4559860eSchristos# GNU General Public License for more details. 19*4559860eSchristos# 20*4559860eSchristos# You should have received a copy of the GNU General Public License 21*4559860eSchristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 22*4559860eSchristos 23*4559860eSchristos# As a special exception to the GNU General Public License, if you 24*4559860eSchristos# distribute this file as part of a program that contains a 25*4559860eSchristos# configuration script generated by Autoconf, you may include it under 26*4559860eSchristos# the same distribution terms that you use for the rest of that program. 27*4559860eSchristos 28*4559860eSchristos# This file is maintained in Automake, please report 29*4559860eSchristos# bugs to <bug-automake@gnu.org> or send patches to 30*4559860eSchristos# <automake-patches@gnu.org>. 31*4559860eSchristos 32*4559860eSchristos 33*4559860eSchristos# func_error message 34*4559860eSchristosfunc_error () 35*4559860eSchristos{ 36*4559860eSchristos echo "$me: $1" 1>&2 37*4559860eSchristos exit 1 38*4559860eSchristos} 39*4559860eSchristos 40*4559860eSchristosfile_conv= 41*4559860eSchristos 42*4559860eSchristos# func_file_conv build_file 43*4559860eSchristos# Convert a $build file to $host form and store it in $file 44*4559860eSchristos# Currently only supports Windows hosts. 45*4559860eSchristosfunc_file_conv () 46*4559860eSchristos{ 47*4559860eSchristos file=$1 48*4559860eSchristos case $file in 49*4559860eSchristos / | /[!/]*) # absolute file, and not a UNC file 50*4559860eSchristos if test -z "$file_conv"; then 51*4559860eSchristos # lazily determine how to convert abs files 52*4559860eSchristos case `uname -s` in 53*4559860eSchristos MINGW*) 54*4559860eSchristos file_conv=mingw 55*4559860eSchristos ;; 56*4559860eSchristos CYGWIN*) 57*4559860eSchristos file_conv=cygwin 58*4559860eSchristos ;; 59*4559860eSchristos *) 60*4559860eSchristos file_conv=wine 61*4559860eSchristos ;; 62*4559860eSchristos esac 63*4559860eSchristos fi 64*4559860eSchristos case $file_conv in 65*4559860eSchristos mingw) 66*4559860eSchristos file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 67*4559860eSchristos ;; 68*4559860eSchristos cygwin) 69*4559860eSchristos file=`cygpath -m "$file" || echo "$file"` 70*4559860eSchristos ;; 71*4559860eSchristos wine) 72*4559860eSchristos file=`winepath -w "$file" || echo "$file"` 73*4559860eSchristos ;; 74*4559860eSchristos esac 75*4559860eSchristos ;; 76*4559860eSchristos esac 77*4559860eSchristos} 78*4559860eSchristos 79*4559860eSchristos# func_at_file at_file operation archive 80*4559860eSchristos# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 81*4559860eSchristos# for each of them. 82*4559860eSchristos# When interpreting the content of the @FILE, do NOT use func_file_conv, 83*4559860eSchristos# since the user would need to supply preconverted file names to 84*4559860eSchristos# binutils ar, at least for MinGW. 85*4559860eSchristosfunc_at_file () 86*4559860eSchristos{ 87*4559860eSchristos operation=$2 88*4559860eSchristos archive=$3 89*4559860eSchristos at_file_contents=`cat "$1"` 90*4559860eSchristos eval set x "$at_file_contents" 91*4559860eSchristos shift 92*4559860eSchristos 93*4559860eSchristos for member 94*4559860eSchristos do 95*4559860eSchristos $AR -NOLOGO $operation:"$member" "$archive" || exit $? 96*4559860eSchristos done 97*4559860eSchristos} 98*4559860eSchristos 99*4559860eSchristoscase $1 in 100*4559860eSchristos '') 101*4559860eSchristos func_error "no command. Try '$0 --help' for more information." 102*4559860eSchristos ;; 103*4559860eSchristos -h | --h*) 104*4559860eSchristos cat <<EOF 105*4559860eSchristosUsage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...] 106*4559860eSchristos 107*4559860eSchristosMembers may be specified in a file named with @FILE. 108*4559860eSchristosEOF 109*4559860eSchristos exit $? 110*4559860eSchristos ;; 111*4559860eSchristos -v | --v*) 112*4559860eSchristos echo "$me, version $scriptversion" 113*4559860eSchristos exit $? 114*4559860eSchristos ;; 115*4559860eSchristosesac 116*4559860eSchristos 117*4559860eSchristosif test $# -lt 3; then 118*4559860eSchristos func_error "you must specify a program, an action and an archive" 119*4559860eSchristosfi 120*4559860eSchristos 121*4559860eSchristosAR=$1 122*4559860eSchristosshift 123*4559860eSchristoswhile : 124*4559860eSchristosdo 125*4559860eSchristos if test $# -lt 2; then 126*4559860eSchristos func_error "you must specify a program, an action and an archive" 127*4559860eSchristos fi 128*4559860eSchristos case $1 in 129*4559860eSchristos -lib | -LIB \ 130*4559860eSchristos | -ltcg | -LTCG \ 131*4559860eSchristos | -machine* | -MACHINE* \ 132*4559860eSchristos | -subsystem* | -SUBSYSTEM* \ 133*4559860eSchristos | -verbose | -VERBOSE \ 134*4559860eSchristos | -wx* | -WX* ) 135*4559860eSchristos AR="$AR $1" 136*4559860eSchristos shift 137*4559860eSchristos ;; 138*4559860eSchristos *) 139*4559860eSchristos action=$1 140*4559860eSchristos shift 141*4559860eSchristos break 142*4559860eSchristos ;; 143*4559860eSchristos esac 144*4559860eSchristosdone 145*4559860eSchristosorig_archive=$1 146*4559860eSchristosshift 147*4559860eSchristosfunc_file_conv "$orig_archive" 148*4559860eSchristosarchive=$file 149*4559860eSchristos 150*4559860eSchristos# strip leading dash in $action 151*4559860eSchristosaction=${action#-} 152*4559860eSchristos 153*4559860eSchristosdelete= 154*4559860eSchristosextract= 155*4559860eSchristoslist= 156*4559860eSchristosquick= 157*4559860eSchristosreplace= 158*4559860eSchristosindex= 159*4559860eSchristoscreate= 160*4559860eSchristos 161*4559860eSchristoswhile test -n "$action" 162*4559860eSchristosdo 163*4559860eSchristos case $action in 164*4559860eSchristos d*) delete=yes ;; 165*4559860eSchristos x*) extract=yes ;; 166*4559860eSchristos t*) list=yes ;; 167*4559860eSchristos q*) quick=yes ;; 168*4559860eSchristos r*) replace=yes ;; 169*4559860eSchristos s*) index=yes ;; 170*4559860eSchristos S*) ;; # the index is always updated implicitly 171*4559860eSchristos c*) create=yes ;; 172*4559860eSchristos u*) ;; # TODO: don't ignore the update modifier 173*4559860eSchristos v*) ;; # TODO: don't ignore the verbose modifier 174*4559860eSchristos *) 175*4559860eSchristos func_error "unknown action specified" 176*4559860eSchristos ;; 177*4559860eSchristos esac 178*4559860eSchristos action=${action#?} 179*4559860eSchristosdone 180*4559860eSchristos 181*4559860eSchristoscase $delete$extract$list$quick$replace,$index in 182*4559860eSchristos yes,* | ,yes) 183*4559860eSchristos ;; 184*4559860eSchristos yesyes*) 185*4559860eSchristos func_error "more than one action specified" 186*4559860eSchristos ;; 187*4559860eSchristos *) 188*4559860eSchristos func_error "no action specified" 189*4559860eSchristos ;; 190*4559860eSchristosesac 191*4559860eSchristos 192*4559860eSchristosif test -n "$delete"; then 193*4559860eSchristos if test ! -f "$orig_archive"; then 194*4559860eSchristos func_error "archive not found" 195*4559860eSchristos fi 196*4559860eSchristos for member 197*4559860eSchristos do 198*4559860eSchristos case $1 in 199*4559860eSchristos @*) 200*4559860eSchristos func_at_file "${1#@}" -REMOVE "$archive" 201*4559860eSchristos ;; 202*4559860eSchristos *) 203*4559860eSchristos func_file_conv "$1" 204*4559860eSchristos $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $? 205*4559860eSchristos ;; 206*4559860eSchristos esac 207*4559860eSchristos done 208*4559860eSchristos 209*4559860eSchristoselif test -n "$extract"; then 210*4559860eSchristos if test ! -f "$orig_archive"; then 211*4559860eSchristos func_error "archive not found" 212*4559860eSchristos fi 213*4559860eSchristos if test $# -gt 0; then 214*4559860eSchristos for member 215*4559860eSchristos do 216*4559860eSchristos case $1 in 217*4559860eSchristos @*) 218*4559860eSchristos func_at_file "${1#@}" -EXTRACT "$archive" 219*4559860eSchristos ;; 220*4559860eSchristos *) 221*4559860eSchristos func_file_conv "$1" 222*4559860eSchristos $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $? 223*4559860eSchristos ;; 224*4559860eSchristos esac 225*4559860eSchristos done 226*4559860eSchristos else 227*4559860eSchristos $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member 228*4559860eSchristos do 229*4559860eSchristos $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $? 230*4559860eSchristos done 231*4559860eSchristos fi 232*4559860eSchristos 233*4559860eSchristoselif test -n "$quick$replace"; then 234*4559860eSchristos if test ! -f "$orig_archive"; then 235*4559860eSchristos if test -z "$create"; then 236*4559860eSchristos echo "$me: creating $orig_archive" 237*4559860eSchristos fi 238*4559860eSchristos orig_archive= 239*4559860eSchristos else 240*4559860eSchristos orig_archive=$archive 241*4559860eSchristos fi 242*4559860eSchristos 243*4559860eSchristos for member 244*4559860eSchristos do 245*4559860eSchristos case $1 in 246*4559860eSchristos @*) 247*4559860eSchristos func_file_conv "${1#@}" 248*4559860eSchristos set x "$@" "@$file" 249*4559860eSchristos ;; 250*4559860eSchristos *) 251*4559860eSchristos func_file_conv "$1" 252*4559860eSchristos set x "$@" "$file" 253*4559860eSchristos ;; 254*4559860eSchristos esac 255*4559860eSchristos shift 256*4559860eSchristos shift 257*4559860eSchristos done 258*4559860eSchristos 259*4559860eSchristos if test -n "$orig_archive"; then 260*4559860eSchristos $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $? 261*4559860eSchristos else 262*4559860eSchristos $AR -NOLOGO -OUT:"$archive" "$@" || exit $? 263*4559860eSchristos fi 264*4559860eSchristos 265*4559860eSchristoselif test -n "$list"; then 266*4559860eSchristos if test ! -f "$orig_archive"; then 267*4559860eSchristos func_error "archive not found" 268*4559860eSchristos fi 269*4559860eSchristos $AR -NOLOGO -LIST "$archive" || exit $? 270*4559860eSchristosfi 271