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