automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New auxiliary archive script


From: Peter Rosin
Subject: Re: New auxiliary archive script
Date: Wed, 04 Aug 2010 12:14:28 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1

Hi Ralf,

Den 2010-08-01 20:06 skrev Ralf Wildenhues:
* Peter Rosin wrote on Sun, Aug 01, 2010 at 06:54:57PM CEST:
The script still needs @<file>-support, in order to make it
possible for libtool to avoid falling back to "-r -o"
piecewise linking when the command line gets long, so that's
a TODO, and the options handling could be better in order to
better support more than just the very minimal ar features.
It also needs the file conversion stuff from the compile
script in order to support absolute file names. So, far from
perfect...

Would it be possible to include this new auxiliary script and
a macro similar to the one that triggers the use of the compile
script?

Yes, in principle: when them bugs are fixed.  Would you be willing to
rewrite the script so it

- has the blurb header similar to 'compile',
- half-way decent option handling (doesn't barf on "shift" if given too
   few options, diagnoses unknown options, treats contents of ARFLAGS as
   options not members, etc.)
- prints error messages on stderr and exits nonzero then,

I have all of the above fixed, with the (minor IMHO) limitation that
only archive members can be specified in @files. Also, I have not
fixed handling of ARFLAGS, since I don't understand what you mean.
The archiver has no knowledge of ARFLAGS, it just sees a bunch of
options, but I'm sure you know that so you must mean something
different...

I wonder whether we can and should call it 'archive', or whether that
would clash with user file names in case they don't use
AC_CONFIG_AUX_DIR.  OTOH, a script named 'ar' may not be installable
anywhere due to the ar binary already there.  Thoughts?

Let's use the prefix am, and append the short form ar -> amar. Because
who can resist a little bit of love in the source trees? FWIW, I came up
with no relevant hits for that in codesearch.

Wrt. introducing a macro to set $AR, let's call it AM_PROG_AR, yes,
that's easy to add as well, but will require developer adjustment of her
configure.ac to have, and we need to coordinate with Libtool.  Or we
could call it straight from AM_INIT_AUTOMAKE, hmm.  For now a viable
workaround is to just
   make AR=/path/to/archive

or, if Libtool is in the game,
   configure AR=...

I'll get to the macros next, and I'll get back to the list if I need help.
I just wanted to show the current version of the script and ask the above
question about ARFLAGS.

AR=$1
shift
action=$1
shift
archive=$1
shift
members=$@

This doesn't work in general.  Just keep using "$@" below in place of
$members (after extracting other flags).

Fixed.

case $action in
cru)
   $AR -NOLOGO -OUT:"$archive" $members

Some users may have hand-written ar calls with other flags, e.g.,
'ar r', or other combinations.  Any chance we can help them, too?

Fixed.

For actual applicability, it is sufficient if you provide a working
script, post testsuite results with it in place (you might want to
   MAKE='make AR=...'

in order to force-test it), NEWS and doc blurb, but no need for changes
to automake.in in the first iteration.

I Still need to run the automake test suite with it...

Thanks for the review!

Cheers,
Peter

--------------------8<---------------------
#! /bin/sh
# Wrapper for Microsoft lib.exe

scriptversion=2010-08-04.10; # UTC

# Copyright (C) 2010 Free Software
# Foundation, Inc.
# Written by Peter Rosin <address@hidden>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.

# This file is maintained in Automake, please report
# bugs to <address@hidden> or send patches to
# <address@hidden>.


file_conv=

# func_file_conv build_file
# Convert a $build file to $host form and store it in $file
# Currently only supports Win32 hosts.
func_file_conv ()
{
  file=$1
  case $file in
    / | /[^/]*) # absolute file, and not a UNC file
      if test -z "$file_conv"; then
        # lazily determine how to convert abs files
        case `uname -s` in
          MINGW*)
            file_conv=mingw
            ;;
          CYGWIN*)
            file_conv=cygwin
            ;;
          *)
            file_conv=wine
            ;;
        esac
      fi
      case $file_conv in
        mingw)
          file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
          ;;
        cygwin)
          file=`cygpath -m "$file" || echo "$file"`
          ;;
        wine)
          file=`winepath -w "$file" || echo "$file"`
          ;;
      esac
      ;;
  esac
}

case $1 in
  '')
     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
     exit 1;
     ;;
  -h | --h*)
    cat <<\EOF
Usage: amar [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]

Members can be specified on separate lines in a file named with @<file>.
EOF
    exit $?
    ;;
  -v | --v*)
    echo "amar, the lib.exe wrapper v0.2"
    exit $?
    ;;
esac

if test $# -lt 3; then
  echo "amar: you must specify a program, an action and an archive" 1>&2
  exit 1
fi

AR=$1
shift
action=$1
shift
orig_archive=$1
func_file_conv "$orig_archive"
archive=$file
shift

# strip leading dash in $action
case $action in
  -*) action="${action#-}" ;;
esac

delete=
extract=
list=
replace=
create=

while test -n "$action"
do
  case $action in
    d*)
      delete=yes
      action="${action#d}"
      ;;
    x*)
      extract=yes
      action="${action#x}"
      ;;
    t*)
      list=yes
      action="${action#t}"
      ;;
    r*)
      replace=yes
      action="${action#r}"
      ;;
    c*)
      create=yes
      action="${action#c}"
      ;;
    u*)
      # TODO: don't ignore update modifier
      action="${action#u}"
      ;;
    ?*)
      echo "amar: unknown action specified" 1>&2
      exit 1
      ;;
  esac
done

case $delete$extract$list$replace in
  yes)
    ;;
  yesyes*)
    echo "amar: more than one action specified" 1>&2
    exit 1
    ;;
  *)
    echo "amar: no action specified" 1>&2
    exit 1
    ;;
esac

if test -n "$delete"; then
  if test ! -f "$orig_archive"; then
    echo "amar: archive not found" 1>&2
    exit 1
  fi
  for member
  do
    case $1 in
      @*)
        # When interpreting the content of the @file, do NOT
        # use func_file_conv, since the user would need to
        # supply preconverted file names to binutils ar, at
        # least for MinGW.
        cat "address@hidden" | while read file
        do
          $AR -NOLOGO -REMOVE:"$file" "$archive"
        done
        ;;
      *)
        func_file_conv "$1"
        $AR -NOLOGO -REMOVE:"$file" "$archive"
        ;;
    esac
  done

elif test -n "$extract"; then
  if test ! -f "$orig_archive"; then
    echo "amar: archive not found" 1>&2
    exit 1
  fi
  if test $# -gt 0; then
    for member
    do
      case $1 in
        @*)
          cat "address@hidden" | while read file
          do
            $AR -NOLOGO -EXTRACT:"$file" "$archive"
          done
          ;;
        *)
          func_file_conv "$1"
          $AR -NOLOGO -EXTRACT:"$file" "$archive"
          ;;
      esac
    done
  else
    $AR -NOLOGO -LIST "$archive" | while read member
    do
      func_file_conv "$member"
      $AR -NOLOGO -EXTRACT:"$file" "$archive"
    done
  fi

elif test -n "$replace"; then
  if test ! -f "$orig_archive"; then
    if test -z "$create"; then
      echo "amar: creating $orig_archive"
    fi
    orig_archive=
  else
    orig_archive=$archive
  fi

  for member
  do
    case $1 in
    @*)
      func_file_conv "address@hidden"
      set x "$@" "@$file"
      shift
      ;;
    *)
      func_file_conv "$1"
      set x "$@" "$file"
      shift
      ;;
    esac
    shift
  done

  if test -n "$orig_archive"; then
    $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@"
  else
    $AR -NOLOGO -OUT:"$archive" "$@"
  fi

elif test -n "$list"; then
  if test ! -f "$orig_archive"; then
    echo "amar: archive not found" 1>&2
    exit 1
  fi
  $AR -NOLOGO -LIST "$archive"
fi
--------------------8<---------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]