head 1.26; access; symbols SHTOOL_2_0_8:1.26 SHTOOL_2_0_7:1.25 SHTOOL_2_0_6:1.24 SHTOOL_2_0_5:1.24 SHTOOL_2_0_4:1.24 SHTOOL_2_0_3:1.23 SHTOOL_2_0_2:1.23 SHTOOL_2_0_1:1.21 SHTOOL_2_0_0:1.21 SHTOOL_2_0b3:1.21 SHTOOL_2_0b2:1.21 SHTOOL_2_0b1:1.21 SHTOOL_1_6:1.17.0.2 SHTOOL_1_6_2:1.17 SHTOOL_1_6_1:1.17 SHTOOL_1_6_0:1.17 SHTOOL_1_5:1.15.0.2 SHTOOL_1_5_4:1.15 SHTOOL_1_5_3:1.15 SHTOOL_1_5_2:1.15 SHTOOL_1_5_1:1.14 SHTOOL_1_5_0:1.14 SHTOOL_1_4_9:1.14 SHTOOL_1_4_8:1.14 SHTOOL_1_4_7:1.12 SHTOOL_1_4_6:1.10 SHTOOL_1_4_5:1.10 SHTOOL_1_4_4:1.10 SHTOOL_1_4_3:1.10 SHTOOL_1_4_2:1.10 SHTOOL_1_4_1:1.9 SHTOOL_1_4_0:1.9 SHTOOL_1_3_3:1.6 SHTOOL_1_3_2:1.5 SHTOOL_1_3_1:1.4 SHTOOL_1_3_0:1.4 SHTOOL_1_2_9:1.1.1.1 SHTOOL_1_2_8:1.1.1.1 SHTOOL_1_2_7:1.1.1.1 SHTOOL_1_2_6:1.1.1.1 SHTOOL_1_2_5:1.1.1.1 SHTOOL_1_2_4:1.1.1.1 SHTOOL_1_2_3:1.1.1.1 SHTOOL_1_2_2:1.1.1.1 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.26 date 2008.04.02.20.13.43; author rse; state Exp; branches; next 1.25; commitid eB5Wirx8MdMyDzXs; 1.25 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.24; commitid OPUF1UBbllBTwzis; 1.24 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.23; commitid oWk7BmnyAitJtfkr; 1.23 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.22; 1.22 date 2005.06.15.08.11.16; author rse; state Exp; branches; next 1.21; 1.21 date 2004.02.12.16.06.26; author rse; state Exp; branches; next 1.20; 1.20 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.19; 1.19 date 2003.02.11.13.00.49; author rse; state Exp; branches; next 1.18; 1.18 date 2003.02.11.12.56.39; author rse; state Exp; branches; next 1.17; 1.17 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.16; 1.16 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.15; 1.15 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.14; 1.14 date 2000.03.12.13.28.24; author rse; state Exp; branches; next 1.13; 1.13 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.12; 1.12 date 99.12.24.15.11.23; author rse; state Exp; branches; next 1.11; 1.11 date 99.12.24.14.11.30; author rse; state Exp; branches; next 1.10; 1.10 date 99.07.09.15.45.22; author rse; state Exp; branches; next 1.9; 1.9 date 99.07.02.08.24.07; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.01.15.02.47; author rse; state Exp; branches; next 1.7; 1.7 date 99.07.01.14.58.37; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.29.17.37.34; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.17.15.24.41; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.2; 1.2 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.20.00; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.20.00; author rse; state Exp; branches; next ; desc @@ 1.26 log @adjust copyright for year 2008 @ text @## ## arx -- Extended archive command ## Copyright (c) 1999-2008 Ralf S. Engelschall ## ## This file is part of shtool and 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 of the License, or (at your option) any later version. ## ## This file 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, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## str_tool="arx" str_usage="[-t|--trace] [-C|--command ] [ ...]" arg_spec="2+" opt_spec="t.C:" opt_alias="t:trace,C:command" opt_t=no opt_C="ar" . ./sh.common ar_prg="$opt_C" ar_cmd="$1"; shift archive="$1"; shift files="$*" # walk through the file list and expand archives members ar_tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'` nfiles='' if [ ".$files" != . ]; then for file in $files; do if [ ! -f $file ]; then echo "$msgprefix:Error: input file not found: $file" 1>&2 shtool_exit 1 fi case $file in *.a ) if [ ! -d $ar_tmpdir ]; then if [ ".$opt_t" = .yes ]; then echo "mkdir $ar_tmpdir" 1>&2 fi mkdir $ar_tmpdir fi case $ar_tmpdir in .arx ) from="../$file" ;; * ) dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'` base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'` from="`cd $dir; pwd`/$base" ;; esac if [ ".$opt_t" = .yes ]; then echo "(cd $ar_tmpdir && $ar_prg x $from)" 1>&2 fi (cd $ar_tmpdir && eval $ar_prg x $from) if [ $? -ne 0 ]; then echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2 shtool_exit 1 fi for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do [ ".$member" = .- ] && continue nfiles="$nfiles $ar_tmpdir/$member" done ;; * ) nfiles="$nfiles $file" ;; esac done fi # run the final archive command if [ ".$opt_t" = .yes ]; then echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2 fi eval $ar_prg $ar_cmd $archive $nfiles if [ $? -ne 0 ]; then echo "$msgprefix:Error: archive command failed" 1>&2 shtool_exit $? fi # cleanup and die gracefully if [ -d $ar_tmpdir ]; then if [ ".$opt_t" = .yes ]; then echo "rm -rf $ar_tmpdir" 1>&2 fi rm -rf $ar_tmpdir fi shtool_exit 0 ## ## manual page ## =pod =head1 NAME B - B ar(1) extensional command =head1 SYNOPSIS B [B<-t>|B<--trace>] [B<-C>|B<--command> I] I I I [I ...] =head1 DESCRIPTION B is a wrapper around the archiving tool ar(1). It provides the ability to create archives out of existing archives, i.e., if one of I matches "C<*.a>", the archive member files of I are used instead of I itself. The trick of this command is the automatic handling of archive members which is especially interesting if one wants to construct a (usually top-level) library archive out of pre-built sub-library archives (usually staying inside subdirs) in a large source tree. For B based projects, a similar functionality is provided by B internally, too. =head1 OPTIONS The following command line options are available. =over 4 =item B<-t>, B<--trace> Shows the actually involved shell commands. =item B<-C>, B<--command> I Set the used ar(1) command to I instead of just "ar" (searched in C<$PATH>). =back =head1 EXAMPLE # Makefile AR=ar RANLIB=ranlib : OBJS=foo.o bar.o LIBS=baz/libbaz.a quux/libquux.a : libfoo.a: $(OBJS) $(LIBS) shtool arx -C $(AR) rc libfoo.a $(OBJS) $(LIBS) $(RANLIB) libfoo.a =head1 HISTORY The B B command was originally written by Ralf S. Engelschall Erse@@engelschall.comE in 1999 for B. It was prompted by need to build libraries out of sub-libraries inside the B project. =head1 SEE ALSO shtool(1), ar(1). =cut @ 1.25 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1999-2007 Ralf S. Engelschall @ 1.24 log @Adjust copyright for year 2006 @ text @d3 1 a3 1 ## Copyright (c) 1999-2006 Ralf S. Engelschall @ 1.23 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1999-2005 Ralf S. Engelschall @ 1.22 log @Fix insecure temporary file handling (CAN-2005-1751, CAN-2005-1759). Submitted by: Eric Romang @ text @d3 1 a3 1 ## Copyright (c) 1999-2004 Ralf S. Engelschall @ 1.21 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d37 1 a37 1 tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'` d47 1 a47 1 if [ ! -d $tmpdir ]; then d49 1 a49 1 echo "mkdir $tmpdir" 1>&2 d51 1 a51 1 mkdir $tmpdir d53 1 a53 1 case $tmpdir in d64 1 a64 1 echo "(cd $tmpdir && $ar_prg x $from)" 1>&2 d66 1 a66 1 (cd $tmpdir && eval $ar_prg x $from) d73 1 a73 1 nfiles="$nfiles $tmpdir/$member" d94 1 a94 1 if [ -d $tmpdir ]; then d96 1 a96 1 echo "rm -rf $tmpdir" 1>&2 d98 1 a98 1 rm -rf $tmpdir @ 1.20 log @Bump copyright year for 2004 @ text @a3 1 ## Originally written for shtool d100 77 @ 1.19 log @Bump year in copyright messages to cover new year 2003. @ text @d3 1 a3 1 ## Copyright (c) 1999-2003 Ralf S. Engelschall @ 1.18 log @Fixed error exit in all commands by introducing an "shtool_exit" function (which correctly cleans up temporary files) and replacing all "exit" calls with "shtool_exit". THIS THE FIRST TIME INTRODUCED THE USAGE OF A SHELL FUNCTION TO THE SHTOOL CODE. This is known to break on _very_ anchient and broken Bourne-Shell implementations and is considered to be no longer a real problem in the year 2003. Especially there is no alternative way anyway. @ text @d3 1 a3 1 ## Copyright (c) 1999-2002 Ralf S. Engelschall @ 1.17 log @bump copyright years @ text @d44 1 a44 1 exit 1 d70 1 a70 1 exit 1 d91 1 a91 1 exit $? @ 1.16 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999-2001 Ralf S. Engelschall @ 1.15 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-t] [-C] [ ...]" d26 1 @ 1.14 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999-2000 Ralf S. Engelschall @ 1.13 log @*** empty log message *** @ text @d25 2 a26 1 opt_spec="tC:" @ 1.12 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1999 Ralf S. Engelschall @ 1.11 log @*** empty log message *** @ text @d25 1 a25 1 opt_spec="tC:!" @ 1.10 log @*** empty log message *** @ text @d70 1 a70 1 for member in - `eval $ar_prg t $file`; do @ 1.9 log @*** empty log message *** @ text @a0 1 #!/bin/sh @ 1.8 log @*** empty log message *** @ text @d24 2 a25 2 str_usage="[-t] [-C] [ ...]" arg_spec="3+" d31 1 a31 1 ar_prg="$opt_C"; shift d39 24 a62 8 for file in $files; do if [ ! -f $file ]; then echo "$msgprefix:Error: input file not found: $file" 1>&2 exit 1 fi case $file in *.a ) if [ ! -d $tmpdir ]; then d64 6 a69 1 echo "mkdir $tmpdir" 1>&2 d71 11 a81 30 mkdir $tmpdir fi case $tmpdir in .arx ) from="../$file" ;; * ) dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'` base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'` from="`cd $dir; pwd`/$base" ;; esac if [ ".$opt_t" = .yes ]; then echo "(cd $tmpdir && $ar_prg x $from)" 1>&2 fi (cd $tmpdir && eval $ar_prg x $from) if [ $? -ne 0 ]; then echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2 exit 1 fi for member in - `eval $ar_prg t $file`; do [ ".$member" = .- ] && continue nfiles="$nfiles $tmpdir/$member" done ;; * ) nfiles="$nfiles $file" ;; esac done @ 1.7 log @*** empty log message *** @ text @d45 1 a45 1 *.a ) @ 1.6 log @*** empty log message *** @ text @d24 1 a24 1 str_usage="[-v] [-C] [ ...]" d26 1 a26 1 opt_spec="vC:!" d47 2 a48 2 if [ ".$opt_v" = .yes ]; then echo "mkdir $tmpdir" d62 2 a63 2 if [ ".$opt_v" = .yes ]; then echo "(cd $tmpdir && $ar_prg x $from)" d82 2 a83 2 if [ ".$opt_v" = .yes ]; then echo "$ar_prg $ar_cmd $archive $nfiles" d93 2 a94 2 if [ ".$opt_v" = .yes ]; then echo "rm -rf $tmpdir" @ 1.5 log @*** empty log message *** @ text @d53 1 a53 1 .arx ) @ 1.4 log @*** empty log message *** @ text @d29 1 a29 1 . sh.common @ 1.3 log @*** empty log message *** @ text @d38 1 a38 1 nfiles="" @ 1.2 log @*** empty log message *** @ text @d4 1 a4 1 ## Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. d6 15 @ 1.1 log @Initial revision @ text @d3 1 a3 1 ## arx -- Archive (ar) wrapper command. d5 1 a5 1 ## Usage: arx [-v] [ ...] d8 11 a18 17 # # command line parsing # verbose=no while [ ".$1" != . ]; do case $1 in -v) verbose=yes; shift; continue ;; *) break ;; esac done if [ $# -le 4 ]; then echo "$0:Usage: arx [-v] [ ...]" 1>&2 exit 1 fi ar_prg=$1; shift ar_cmd=$1; shift archive=$1; shift a20 1 # a21 1 # d26 1 a26 1 echo "$0:Error: input file not found: $file" 1>&2 d32 1 a32 1 if [ $verbose = yes ]; then d47 1 a47 1 if [ $verbose = yes ]; then d52 1 a52 1 echo "$0:Error: member extraction failed for archive: $file" 1>&2 a65 1 # d67 1 a67 2 # if [ $verbose = yes ]; then d72 1 a72 1 echo "$0:Error: archive command failed" 1>&2 a75 1 # a76 1 # d78 1 a78 1 if [ $verbose = yes ]; then a82 1 exit 0 @ 1.1.1.1 log @Import of shtool 1.2.0 @ text @@