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