18fa80f29Smrg#!/bin/sh 28fa80f29Smrg# Wrapper for Microsoft lib.exe 38fa80f29Smrg 48fa80f29Smrgme=ar-lib 58fa80f29Smrgscriptversion=2012-03-01.08; # UTC 68fa80f29Smrg 7*062d2d48Smrg# Copyright (C) 2010-2014 Free Software Foundation, Inc. 88fa80f29Smrg# Written by Peter Rosin <peda@lysator.liu.se>. 98fa80f29Smrg# 108fa80f29Smrg# This program is free software; you can redistribute it and/or modify 118fa80f29Smrg# it under the terms of the GNU General Public License as published by 128fa80f29Smrg# the Free Software Foundation; either version 2, or (at your option) 138fa80f29Smrg# any later version. 148fa80f29Smrg# 158fa80f29Smrg# This program is distributed in the hope that it will be useful, 168fa80f29Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 178fa80f29Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 188fa80f29Smrg# GNU General Public License for more details. 198fa80f29Smrg# 208fa80f29Smrg# You should have received a copy of the GNU General Public License 218fa80f29Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 228fa80f29Smrg 238fa80f29Smrg# As a special exception to the GNU General Public License, if you 248fa80f29Smrg# distribute this file as part of a program that contains a 258fa80f29Smrg# configuration script generated by Autoconf, you may include it under 268fa80f29Smrg# the same distribution terms that you use for the rest of that program. 278fa80f29Smrg 288fa80f29Smrg# This file is maintained in Automake, please report 298fa80f29Smrg# bugs to <bug-automake@gnu.org> or send patches to 308fa80f29Smrg# <automake-patches@gnu.org>. 318fa80f29Smrg 328fa80f29Smrg 338fa80f29Smrg# func_error message 348fa80f29Smrgfunc_error () 358fa80f29Smrg{ 368fa80f29Smrg echo "$me: $1" 1>&2 378fa80f29Smrg exit 1 388fa80f29Smrg} 398fa80f29Smrg 408fa80f29Smrgfile_conv= 418fa80f29Smrg 428fa80f29Smrg# func_file_conv build_file 438fa80f29Smrg# Convert a $build file to $host form and store it in $file 448fa80f29Smrg# Currently only supports Windows hosts. 458fa80f29Smrgfunc_file_conv () 468fa80f29Smrg{ 478fa80f29Smrg file=$1 488fa80f29Smrg case $file in 498fa80f29Smrg / | /[!/]*) # absolute file, and not a UNC file 508fa80f29Smrg if test -z "$file_conv"; then 518fa80f29Smrg # lazily determine how to convert abs files 528fa80f29Smrg case `uname -s` in 538fa80f29Smrg MINGW*) 548fa80f29Smrg file_conv=mingw 558fa80f29Smrg ;; 568fa80f29Smrg CYGWIN*) 578fa80f29Smrg file_conv=cygwin 588fa80f29Smrg ;; 598fa80f29Smrg *) 608fa80f29Smrg file_conv=wine 618fa80f29Smrg ;; 628fa80f29Smrg esac 638fa80f29Smrg fi 648fa80f29Smrg case $file_conv in 658fa80f29Smrg mingw) 668fa80f29Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 678fa80f29Smrg ;; 688fa80f29Smrg cygwin) 698fa80f29Smrg file=`cygpath -m "$file" || echo "$file"` 708fa80f29Smrg ;; 718fa80f29Smrg wine) 728fa80f29Smrg file=`winepath -w "$file" || echo "$file"` 738fa80f29Smrg ;; 748fa80f29Smrg esac 758fa80f29Smrg ;; 768fa80f29Smrg esac 778fa80f29Smrg} 788fa80f29Smrg 798fa80f29Smrg# func_at_file at_file operation archive 808fa80f29Smrg# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 818fa80f29Smrg# for each of them. 828fa80f29Smrg# When interpreting the content of the @FILE, do NOT use func_file_conv, 838fa80f29Smrg# since the user would need to supply preconverted file names to 848fa80f29Smrg# binutils ar, at least for MinGW. 858fa80f29Smrgfunc_at_file () 868fa80f29Smrg{ 878fa80f29Smrg operation=$2 888fa80f29Smrg archive=$3 898fa80f29Smrg at_file_contents=`cat "$1"` 908fa80f29Smrg eval set x "$at_file_contents" 918fa80f29Smrg shift 928fa80f29Smrg 938fa80f29Smrg for member 948fa80f29Smrg do 958fa80f29Smrg $AR -NOLOGO $operation:"$member" "$archive" || exit $? 968fa80f29Smrg done 978fa80f29Smrg} 988fa80f29Smrg 998fa80f29Smrgcase $1 in 1008fa80f29Smrg '') 1018fa80f29Smrg func_error "no command. Try '$0 --help' for more information." 1028fa80f29Smrg ;; 1038fa80f29Smrg -h | --h*) 1048fa80f29Smrg cat <<EOF 1058fa80f29SmrgUsage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...] 1068fa80f29Smrg 1078fa80f29SmrgMembers may be specified in a file named with @FILE. 1088fa80f29SmrgEOF 1098fa80f29Smrg exit $? 1108fa80f29Smrg ;; 1118fa80f29Smrg -v | --v*) 1128fa80f29Smrg echo "$me, version $scriptversion" 1138fa80f29Smrg exit $? 1148fa80f29Smrg ;; 1158fa80f29Smrgesac 1168fa80f29Smrg 1178fa80f29Smrgif test $# -lt 3; then 1188fa80f29Smrg func_error "you must specify a program, an action and an archive" 1198fa80f29Smrgfi 1208fa80f29Smrg 1218fa80f29SmrgAR=$1 1228fa80f29Smrgshift 1238fa80f29Smrgwhile : 1248fa80f29Smrgdo 1258fa80f29Smrg if test $# -lt 2; then 1268fa80f29Smrg func_error "you must specify a program, an action and an archive" 1278fa80f29Smrg fi 1288fa80f29Smrg case $1 in 1298fa80f29Smrg -lib | -LIB \ 1308fa80f29Smrg | -ltcg | -LTCG \ 1318fa80f29Smrg | -machine* | -MACHINE* \ 1328fa80f29Smrg | -subsystem* | -SUBSYSTEM* \ 1338fa80f29Smrg | -verbose | -VERBOSE \ 1348fa80f29Smrg | -wx* | -WX* ) 1358fa80f29Smrg AR="$AR $1" 1368fa80f29Smrg shift 1378fa80f29Smrg ;; 1388fa80f29Smrg *) 1398fa80f29Smrg action=$1 1408fa80f29Smrg shift 1418fa80f29Smrg break 1428fa80f29Smrg ;; 1438fa80f29Smrg esac 1448fa80f29Smrgdone 1458fa80f29Smrgorig_archive=$1 1468fa80f29Smrgshift 1478fa80f29Smrgfunc_file_conv "$orig_archive" 1488fa80f29Smrgarchive=$file 1498fa80f29Smrg 1508fa80f29Smrg# strip leading dash in $action 1518fa80f29Smrgaction=${action#-} 1528fa80f29Smrg 1538fa80f29Smrgdelete= 1548fa80f29Smrgextract= 1558fa80f29Smrglist= 1568fa80f29Smrgquick= 1578fa80f29Smrgreplace= 1588fa80f29Smrgindex= 1598fa80f29Smrgcreate= 1608fa80f29Smrg 1618fa80f29Smrgwhile test -n "$action" 1628fa80f29Smrgdo 1638fa80f29Smrg case $action in 1648fa80f29Smrg d*) delete=yes ;; 1658fa80f29Smrg x*) extract=yes ;; 1668fa80f29Smrg t*) list=yes ;; 1678fa80f29Smrg q*) quick=yes ;; 1688fa80f29Smrg r*) replace=yes ;; 1698fa80f29Smrg s*) index=yes ;; 1708fa80f29Smrg S*) ;; # the index is always updated implicitly 1718fa80f29Smrg c*) create=yes ;; 1728fa80f29Smrg u*) ;; # TODO: don't ignore the update modifier 1738fa80f29Smrg v*) ;; # TODO: don't ignore the verbose modifier 1748fa80f29Smrg *) 1758fa80f29Smrg func_error "unknown action specified" 1768fa80f29Smrg ;; 1778fa80f29Smrg esac 1788fa80f29Smrg action=${action#?} 1798fa80f29Smrgdone 1808fa80f29Smrg 1818fa80f29Smrgcase $delete$extract$list$quick$replace,$index in 1828fa80f29Smrg yes,* | ,yes) 1838fa80f29Smrg ;; 1848fa80f29Smrg yesyes*) 1858fa80f29Smrg func_error "more than one action specified" 1868fa80f29Smrg ;; 1878fa80f29Smrg *) 1888fa80f29Smrg func_error "no action specified" 1898fa80f29Smrg ;; 1908fa80f29Smrgesac 1918fa80f29Smrg 1928fa80f29Smrgif test -n "$delete"; then 1938fa80f29Smrg if test ! -f "$orig_archive"; then 1948fa80f29Smrg func_error "archive not found" 1958fa80f29Smrg fi 1968fa80f29Smrg for member 1978fa80f29Smrg do 1988fa80f29Smrg case $1 in 1998fa80f29Smrg @*) 2008fa80f29Smrg func_at_file "${1#@}" -REMOVE "$archive" 2018fa80f29Smrg ;; 2028fa80f29Smrg *) 2038fa80f29Smrg func_file_conv "$1" 2048fa80f29Smrg $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $? 2058fa80f29Smrg ;; 2068fa80f29Smrg esac 2078fa80f29Smrg done 2088fa80f29Smrg 2098fa80f29Smrgelif test -n "$extract"; then 2108fa80f29Smrg if test ! -f "$orig_archive"; then 2118fa80f29Smrg func_error "archive not found" 2128fa80f29Smrg fi 2138fa80f29Smrg if test $# -gt 0; then 2148fa80f29Smrg for member 2158fa80f29Smrg do 2168fa80f29Smrg case $1 in 2178fa80f29Smrg @*) 2188fa80f29Smrg func_at_file "${1#@}" -EXTRACT "$archive" 2198fa80f29Smrg ;; 2208fa80f29Smrg *) 2218fa80f29Smrg func_file_conv "$1" 2228fa80f29Smrg $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $? 2238fa80f29Smrg ;; 2248fa80f29Smrg esac 2258fa80f29Smrg done 2268fa80f29Smrg else 2278fa80f29Smrg $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member 2288fa80f29Smrg do 2298fa80f29Smrg $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $? 2308fa80f29Smrg done 2318fa80f29Smrg fi 2328fa80f29Smrg 2338fa80f29Smrgelif test -n "$quick$replace"; then 2348fa80f29Smrg if test ! -f "$orig_archive"; then 2358fa80f29Smrg if test -z "$create"; then 2368fa80f29Smrg echo "$me: creating $orig_archive" 2378fa80f29Smrg fi 2388fa80f29Smrg orig_archive= 2398fa80f29Smrg else 2408fa80f29Smrg orig_archive=$archive 2418fa80f29Smrg fi 2428fa80f29Smrg 2438fa80f29Smrg for member 2448fa80f29Smrg do 2458fa80f29Smrg case $1 in 2468fa80f29Smrg @*) 2478fa80f29Smrg func_file_conv "${1#@}" 2488fa80f29Smrg set x "$@" "@$file" 2498fa80f29Smrg ;; 2508fa80f29Smrg *) 2518fa80f29Smrg func_file_conv "$1" 2528fa80f29Smrg set x "$@" "$file" 2538fa80f29Smrg ;; 2548fa80f29Smrg esac 2558fa80f29Smrg shift 2568fa80f29Smrg shift 2578fa80f29Smrg done 2588fa80f29Smrg 2598fa80f29Smrg if test -n "$orig_archive"; then 2608fa80f29Smrg $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $? 2618fa80f29Smrg else 2628fa80f29Smrg $AR -NOLOGO -OUT:"$archive" "$@" || exit $? 2638fa80f29Smrg fi 2648fa80f29Smrg 2658fa80f29Smrgelif test -n "$list"; then 2668fa80f29Smrg if test ! -f "$orig_archive"; then 2678fa80f29Smrg func_error "archive not found" 2688fa80f29Smrg fi 2698fa80f29Smrg $AR -NOLOGO -LIST "$archive" || exit $? 2708fa80f29Smrgfi 271