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