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