Home | History | Annotate | Line # | Download | only in build-aux
      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  mrg scriptversion=2019-07-04.01; # UTC
      6      1.1  mrg 
      7  1.1.1.2  mrg # Copyright (C) 2010-2021 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  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  mrg 	    file_conv=mingw
     55      1.1  mrg 	    ;;
     56      1.1  mrg 	  CYGWIN* | MSYS*)
     57      1.1  mrg 	    file_conv=cygwin
     58      1.1  mrg 	    ;;
     59      1.1  mrg 	  *)
     60      1.1  mrg 	    file_conv=wine
     61      1.1  mrg 	    ;;
     62      1.1  mrg 	esac
     63      1.1  mrg       fi
     64      1.1  mrg       case $file_conv in
     65      1.1  mrg 	mingw)
     66      1.1  mrg 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
     67      1.1  mrg 	  ;;
     68      1.1  mrg 	cygwin | msys)
     69      1.1  mrg 	  file=`cygpath -m "$file" || echo "$file"`
     70      1.1  mrg 	  ;;
     71      1.1  mrg 	wine)
     72      1.1  mrg 	  file=`winepath -w "$file" || echo "$file"`
     73      1.1  mrg 	  ;;
     74      1.1  mrg       esac
     75      1.1  mrg       ;;
     76      1.1  mrg   esac
     77      1.1  mrg }
     78      1.1  mrg 
     79      1.1  mrg # func_at_file at_file operation archive
     80      1.1  mrg # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
     81      1.1  mrg # for each of them.
     82      1.1  mrg # When interpreting the content of the @FILE, do NOT use func_file_conv,
     83      1.1  mrg # since the user would need to supply preconverted file names to
     84      1.1  mrg # binutils ar, at least for MinGW.
     85      1.1  mrg func_at_file ()
     86      1.1  mrg {
     87      1.1  mrg   operation=$2
     88      1.1  mrg   archive=$3
     89      1.1  mrg   at_file_contents=`cat "$1"`
     90      1.1  mrg   eval set x "$at_file_contents"
     91      1.1  mrg   shift
     92      1.1  mrg 
     93      1.1  mrg   for member
     94      1.1  mrg   do
     95      1.1  mrg     $AR -NOLOGO $operation:"$member" "$archive" || exit $?
     96      1.1  mrg   done
     97      1.1  mrg }
     98      1.1  mrg 
     99      1.1  mrg case $1 in
    100      1.1  mrg   '')
    101      1.1  mrg      func_error "no command.  Try '$0 --help' for more information."
    102      1.1  mrg      ;;
    103      1.1  mrg   -h | --h*)
    104      1.1  mrg     cat <<EOF
    105      1.1  mrg Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
    106      1.1  mrg 
    107      1.1  mrg Members may be specified in a file named with @FILE.
    108      1.1  mrg EOF
    109      1.1  mrg     exit $?
    110      1.1  mrg     ;;
    111      1.1  mrg   -v | --v*)
    112      1.1  mrg     echo "$me, version $scriptversion"
    113      1.1  mrg     exit $?
    114      1.1  mrg     ;;
    115      1.1  mrg esac
    116      1.1  mrg 
    117      1.1  mrg if test $# -lt 3; then
    118      1.1  mrg   func_error "you must specify a program, an action and an archive"
    119      1.1  mrg fi
    120      1.1  mrg 
    121      1.1  mrg AR=$1
    122      1.1  mrg shift
    123      1.1  mrg while :
    124      1.1  mrg do
    125      1.1  mrg   if test $# -lt 2; then
    126      1.1  mrg     func_error "you must specify a program, an action and an archive"
    127      1.1  mrg   fi
    128      1.1  mrg   case $1 in
    129      1.1  mrg     -lib | -LIB \
    130      1.1  mrg     | -ltcg | -LTCG \
    131      1.1  mrg     | -machine* | -MACHINE* \
    132      1.1  mrg     | -subsystem* | -SUBSYSTEM* \
    133      1.1  mrg     | -verbose | -VERBOSE \
    134      1.1  mrg     | -wx* | -WX* )
    135      1.1  mrg       AR="$AR $1"
    136      1.1  mrg       shift
    137      1.1  mrg       ;;
    138      1.1  mrg     *)
    139      1.1  mrg       action=$1
    140      1.1  mrg       shift
    141      1.1  mrg       break
    142      1.1  mrg       ;;
    143      1.1  mrg   esac
    144      1.1  mrg done
    145      1.1  mrg orig_archive=$1
    146      1.1  mrg shift
    147      1.1  mrg func_file_conv "$orig_archive"
    148      1.1  mrg archive=$file
    149      1.1  mrg 
    150      1.1  mrg # strip leading dash in $action
    151      1.1  mrg action=${action#-}
    152      1.1  mrg 
    153      1.1  mrg delete=
    154      1.1  mrg extract=
    155      1.1  mrg list=
    156      1.1  mrg quick=
    157      1.1  mrg replace=
    158      1.1  mrg index=
    159      1.1  mrg create=
    160      1.1  mrg 
    161      1.1  mrg while test -n "$action"
    162      1.1  mrg do
    163      1.1  mrg   case $action in
    164      1.1  mrg     d*) delete=yes  ;;
    165      1.1  mrg     x*) extract=yes ;;
    166      1.1  mrg     t*) list=yes    ;;
    167      1.1  mrg     q*) quick=yes   ;;
    168      1.1  mrg     r*) replace=yes ;;
    169      1.1  mrg     s*) index=yes   ;;
    170      1.1  mrg     S*)             ;; # the index is always updated implicitly
    171      1.1  mrg     c*) create=yes  ;;
    172      1.1  mrg     u*)             ;; # TODO: don't ignore the update modifier
    173      1.1  mrg     v*)             ;; # TODO: don't ignore the verbose modifier
    174      1.1  mrg     *)
    175      1.1  mrg       func_error "unknown action specified"
    176      1.1  mrg       ;;
    177      1.1  mrg   esac
    178      1.1  mrg   action=${action#?}
    179      1.1  mrg done
    180      1.1  mrg 
    181      1.1  mrg case $delete$extract$list$quick$replace,$index in
    182      1.1  mrg   yes,* | ,yes)
    183      1.1  mrg     ;;
    184      1.1  mrg   yesyes*)
    185      1.1  mrg     func_error "more than one action specified"
    186      1.1  mrg     ;;
    187      1.1  mrg   *)
    188      1.1  mrg     func_error "no action specified"
    189      1.1  mrg     ;;
    190      1.1  mrg esac
    191      1.1  mrg 
    192      1.1  mrg if test -n "$delete"; then
    193      1.1  mrg   if test ! -f "$orig_archive"; then
    194      1.1  mrg     func_error "archive not found"
    195      1.1  mrg   fi
    196      1.1  mrg   for member
    197      1.1  mrg   do
    198      1.1  mrg     case $1 in
    199      1.1  mrg       @*)
    200      1.1  mrg         func_at_file "${1#@}" -REMOVE "$archive"
    201      1.1  mrg         ;;
    202      1.1  mrg       *)
    203      1.1  mrg         func_file_conv "$1"
    204      1.1  mrg         $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
    205      1.1  mrg         ;;
    206      1.1  mrg     esac
    207      1.1  mrg   done
    208      1.1  mrg 
    209      1.1  mrg elif test -n "$extract"; then
    210      1.1  mrg   if test ! -f "$orig_archive"; then
    211      1.1  mrg     func_error "archive not found"
    212      1.1  mrg   fi
    213      1.1  mrg   if test $# -gt 0; then
    214      1.1  mrg     for member
    215      1.1  mrg     do
    216      1.1  mrg       case $1 in
    217      1.1  mrg         @*)
    218      1.1  mrg           func_at_file "${1#@}" -EXTRACT "$archive"
    219      1.1  mrg           ;;
    220      1.1  mrg         *)
    221      1.1  mrg           func_file_conv "$1"
    222      1.1  mrg           $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
    223      1.1  mrg           ;;
    224      1.1  mrg       esac
    225      1.1  mrg     done
    226      1.1  mrg   else
    227      1.1  mrg     $AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \
    228      1.1  mrg       | while read member
    229      1.1  mrg         do
    230      1.1  mrg           $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
    231      1.1  mrg         done
    232      1.1  mrg   fi
    233      1.1  mrg 
    234      1.1  mrg elif test -n "$quick$replace"; then
    235      1.1  mrg   if test ! -f "$orig_archive"; then
    236      1.1  mrg     if test -z "$create"; then
    237      1.1  mrg       echo "$me: creating $orig_archive"
    238      1.1  mrg     fi
    239      1.1  mrg     orig_archive=
    240      1.1  mrg   else
    241      1.1  mrg     orig_archive=$archive
    242      1.1  mrg   fi
    243      1.1  mrg 
    244      1.1  mrg   for member
    245      1.1  mrg   do
    246      1.1  mrg     case $1 in
    247      1.1  mrg     @*)
    248      1.1  mrg       func_file_conv "${1#@}"
    249      1.1  mrg       set x "$@" "@$file"
    250      1.1  mrg       ;;
    251      1.1  mrg     *)
    252      1.1  mrg       func_file_conv "$1"
    253      1.1  mrg       set x "$@" "$file"
    254      1.1  mrg       ;;
    255      1.1  mrg     esac
    256      1.1  mrg     shift
    257      1.1  mrg     shift
    258      1.1  mrg   done
    259      1.1  mrg 
    260      1.1  mrg   if test -n "$orig_archive"; then
    261      1.1  mrg     $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
    262      1.1  mrg   else
    263      1.1  mrg     $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
    264      1.1  mrg   fi
    265      1.1  mrg 
    266      1.1  mrg elif test -n "$list"; then
    267      1.1  mrg   if test ! -f "$orig_archive"; then
    268      1.1  mrg     func_error "archive not found"
    269      1.1  mrg   fi
    270      1.1  mrg   $AR -NOLOGO -LIST "$archive" || exit $?
    271      1.1  mrg fi
    272