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