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