annotate ar-lib @ 1888:5f478ecf65e4

Identify more local definitions as functions that should be lifted to the top level, which has synergistic effects on inlining later
author Adam Chlipala <adam@chlipala.net>
date Tue, 05 Nov 2013 11:58:52 -0500
parents 40557fb08e98
children
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@1806 5 scriptversion=2012-03-01.08; # 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@1806 156 quick=
adam@1760 157 replace=
adam@1806 158 index=
adam@1760 159 create=
adam@1760 160
adam@1760 161 while test -n "$action"
adam@1760 162 do
adam@1760 163 case $action in
adam@1760 164 d*) delete=yes ;;
adam@1760 165 x*) extract=yes ;;
adam@1760 166 t*) list=yes ;;
adam@1806 167 q*) quick=yes ;;
adam@1760 168 r*) replace=yes ;;
adam@1806 169 s*) index=yes ;;
adam@1806 170 S*) ;; # the index is always updated implicitly
adam@1760 171 c*) create=yes ;;
adam@1760 172 u*) ;; # TODO: don't ignore the update modifier
adam@1760 173 v*) ;; # TODO: don't ignore the verbose modifier
adam@1760 174 *)
adam@1760 175 func_error "unknown action specified"
adam@1760 176 ;;
adam@1760 177 esac
adam@1760 178 action=${action#?}
adam@1760 179 done
adam@1760 180
adam@1806 181 case $delete$extract$list$quick$replace,$index in
adam@1806 182 yes,* | ,yes)
adam@1760 183 ;;
adam@1760 184 yesyes*)
adam@1760 185 func_error "more than one action specified"
adam@1760 186 ;;
adam@1760 187 *)
adam@1760 188 func_error "no action specified"
adam@1760 189 ;;
adam@1760 190 esac
adam@1760 191
adam@1760 192 if test -n "$delete"; then
adam@1760 193 if test ! -f "$orig_archive"; then
adam@1760 194 func_error "archive not found"
adam@1760 195 fi
adam@1760 196 for member
adam@1760 197 do
adam@1760 198 case $1 in
adam@1760 199 @*)
adam@1760 200 func_at_file "${1#@}" -REMOVE "$archive"
adam@1760 201 ;;
adam@1760 202 *)
adam@1760 203 func_file_conv "$1"
adam@1760 204 $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
adam@1760 205 ;;
adam@1760 206 esac
adam@1760 207 done
adam@1760 208
adam@1760 209 elif test -n "$extract"; then
adam@1760 210 if test ! -f "$orig_archive"; then
adam@1760 211 func_error "archive not found"
adam@1760 212 fi
adam@1760 213 if test $# -gt 0; then
adam@1760 214 for member
adam@1760 215 do
adam@1760 216 case $1 in
adam@1760 217 @*)
adam@1760 218 func_at_file "${1#@}" -EXTRACT "$archive"
adam@1760 219 ;;
adam@1760 220 *)
adam@1760 221 func_file_conv "$1"
adam@1760 222 $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
adam@1760 223 ;;
adam@1760 224 esac
adam@1760 225 done
adam@1760 226 else
adam@1760 227 $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
adam@1760 228 do
adam@1760 229 $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
adam@1760 230 done
adam@1760 231 fi
adam@1760 232
adam@1806 233 elif test -n "$quick$replace"; then
adam@1760 234 if test ! -f "$orig_archive"; then
adam@1760 235 if test -z "$create"; then
adam@1760 236 echo "$me: creating $orig_archive"
adam@1760 237 fi
adam@1760 238 orig_archive=
adam@1760 239 else
adam@1760 240 orig_archive=$archive
adam@1760 241 fi
adam@1760 242
adam@1760 243 for member
adam@1760 244 do
adam@1760 245 case $1 in
adam@1760 246 @*)
adam@1760 247 func_file_conv "${1#@}"
adam@1760 248 set x "$@" "@$file"
adam@1760 249 ;;
adam@1760 250 *)
adam@1760 251 func_file_conv "$1"
adam@1760 252 set x "$@" "$file"
adam@1760 253 ;;
adam@1760 254 esac
adam@1760 255 shift
adam@1760 256 shift
adam@1760 257 done
adam@1760 258
adam@1760 259 if test -n "$orig_archive"; then
adam@1760 260 $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
adam@1760 261 else
adam@1760 262 $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
adam@1760 263 fi
adam@1760 264
adam@1760 265 elif test -n "$list"; then
adam@1760 266 if test ! -f "$orig_archive"; then
adam@1760 267 func_error "archive not found"
adam@1760 268 fi
adam@1760 269 $AR -NOLOGO -LIST "$archive" || exit $?
adam@1760 270 fi