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