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