Hi Ralf,
and thank you right back for _your_ work on this! :-)
Den 2010-08-04 22:18 skrev Ralf Wildenhues:
thanks for your work on this!
* Peter Rosin wrote on Wed, Aug 04, 2010 at 12:14:28PM CEST:
Den 2010-08-01 20:06 skrev Ralf Wildenhues:
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.
I'm really not that excited about the name: It doesn't make it too clear
what the tool does (unlike am-ar maybe) and we don't use the 'am' prefix
anywhere else: depcomp, compile, mkinstalldirs, gendocs, gnupload. Why
should that be different here? What's wrong with 'archive', is it taken
already? If you care about it wrapping MS lib only for now: it could
wrap other junk as well in the future, no?
Now if you insist, then maybe we can just find another compromise name.
Please set $me to the name and use that throughout, so at least a change
is easily done. ;-)
I'm perfectly fine with 'archive', so let's go back to that. I found only
one problematic project on codesearch, and that was an ancient version
of gimp (0.54, 1997?):
http://archive.debian.org/debian-archive/debian/dists/Debian-1.3.1/contrib/source/gimp_0.54.1.orig.tar.gz
A quick peek at more recent versions of gimp shows that they no longer have
any clashing archive script. But I don't know when it was actually removed
from from the gimp source. It does not appear to be there in gimp 2.4 from
a couple of years ago.
Should the AM_PROG_AR macro perhaps be required when AC_PROG_RANLIB is
seen? Hmmm, but the ranlib macro is from autoconf so probably not...
I found a few nits, but nothing substantial, so if you can format your
next iteration as git patch, and given testing, it can just go in.
What branch should I base this on? master, maint or msvc?
-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>.
I think s/can/may/ sounds better because that is not mandatory.
Please use @FILE not @<file>; the capitalization is already meant to
denote metasyntactic variables (as is done by info pages).
I wanted to, but binutils ar has this in its --help:
@<file> - read options from <file>
and I thought that when @FILE support for the archiver is added to
libtool it would be done similar to how it was done for the name
lister, i.e.
if test "$lt_cv_nm_interface" = "MS dumpbin"; then
nm_file_list_spec='@'
elif $NM --help 2>/dev/null | grep '[...@]]file' >/dev/null; then
nm_file_list_spec='@'
fi
So, I just wanted to save a future bifurcation in libtool. Should
I still change the help text to @FILE?
EOF
# strip leading dash in $action
case $action in
-*) action="${action#-}" ;;
esac
The case statement is unnecessary, you can use just
action=${action#-}
Right.
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}"
;;
You can factor out all the action=... lines to after the case statement
as
action=${action#?}
Indeed.
?*)
echo "amar: unknown action specified" 1>&2
exit 1
;;
esac
done
if test -n "$delete"; then
if test ! -f "$orig_archive"; then
Can it be a symbolic link or another non-regular file type?
Won't $AR detect a non-existing file?
I doubt that lib will work with anything but regular files.
What I'm trying to accomplish is that lib will recreate the
archive every time if you do
lib -out:foo.lib foo.obj
lib -out:foo.lib bar.obj
lib -out:foo.lib baz.obj
so that you end up with a foo.lib that only contains baz.obj.
You have to do this:
lib -out:foo.lib foo.obj
lib -out:foo.lib foo.lib bar.obj
lib -out:foo.lib foo.lib baz.obj
to create an archive that contains all three objects (unless
you create it all in one go of course). If foo.lib doesn't
exist, lib falls over if you use the latter syntax. So, you
have to know in advance if you are adding to an existing
archive or if you are creating a new one.
Per POSIX, ar should print a diagnostic if it has to create
an archive and the c modifier isn't specified, so I just hooked
that into the existing test.
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 "$...@}" | while read file
do
$AR -NOLOGO -REMOVE:"$file" "$archive"
done
You can omit the cat and pipe and just
done< "$...@}"
OTOH, it is common (at least in newer GCC and binutils) to allow @file
contents to be just whitespace-separated, including single or double
quoting. That could be done with something like
atfile_contents=`cat "$...@}"`
eval set x "$atfile_contents"
shift
which you might want to factor out into a function to reuse below.
I have no idea whether native w32 tools do something similar, though.
You are correct, lib supports @FILEs with content like:
"some object.obj" "other object.obj"
foo.obj
bar.obj baz.obj
So, I'm going with the function approach.
Shouldn't the script stop and fail if one of the $AR commands fails?
Probably, will fix.
;;
*)
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
Repeated code, could be in an 'error' function.
Yes, *fixing*.
fi
if test $# -gt 0; then
for member
do
case $1 in
@*)
cat "$...@}" | 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"
Is this file conversion necessary, or even right?
I mean, is it really that '$AR -list' prints names that
'$AR -extract:' cannot eat? Or am I missing something?
Oh. Good catch! It's not right of course. *fixing*
Does lib have no way to just extract the whole archive?
No. Come on, what do you expect? :-)
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 "$...@}"
set x "$@" "@$file"
shift
;;
*)
func_file_conv "$1"
set x "$@" "$file"
shift
The two shifts can be factored outside the case.
*fixing*
;;
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
Cheers,
Peter