Brian Paul wrote:
> 
> "make install" uses two tools to install files: $(INSTALL) and
> $(COPY_LIBS).  $INSTALL is 'install' but $COPY_LIBS is "cp -f -d" (on
> linux anyway).
> 
> We need COPY_LIBS because 'install' doesn't preserve symbolic links.
> Unfortunately, not all versions of 'cp' support the -d option either.
>  Kind of a mess.
> 
> To fix all this I've written a shell script that replaces install.  It
> supports the -d and -m options and keeps symbolic links in tact.  This
> script will eliminate the need for INSTALL and COPY_LIBS.
> 
> I thought I'd post it here for review first.  I'm not a bash script
> expert by any means.

Some suggestions inline, mostly for portability and allowing spaces in
the destination or target paths.

Thanks,
Donnie

> 
> -Brian
> 
> 
> ------------------------------------------------------------------------
> 
> #!/bin/sh
> 
> 
> # A minimal replacement for 'install' that supports installing symbolic links.
> # Only a limited number of options are supported:
> # -d dir          Create a directory
> # -m mode         Sets a file's mode when installing
> 
> 
> MODE=""
> 
> if [ "$1" == "-d" ] ; then

"=" rather than "==" is the portable form.

>       # make a directory path
>       # XXX if the -p option isn't univeral, we'll have to fix this
>       mkdir -p $2

It pretty much is, except old Solaris (8 or so) and Next/OpenStep. Take
a look at /usr/share/aclocal-1.9/mkdirp.m4 or similar if you'd like some
more details. Might want "$2" to allow spaces.

>       exit 0
> fi
> 
> if [ "$1" == "-m" ] ; then
>       # set file mode
>       MODE=$2
>       shift
>       shift

Try 'shift 2'

> fi
> 
> # install file(s) into destination
> if [ $# -ge 2 ] ; then
> 
>       # Find last cmd line arg, it's the dest dir
>       for v in $* ; do

You might want "$@" instead, with the quotes. That'll allow for spaces
in parameters.

>               DEST=$v
>       done
>       #echo dest is $DEST

You could count the number of args and take the last one instead of looping.

> 
>       # Loop over args, moving them to DEST directory
>       I=1
>       for FILE in $@ ; do

Same..

>               if [ $I == $# ] ; then
>                       # stop, don't want to install $DEST into $DEST
>                       exit 0
>               fi
> 
>               # determine file's type
>               if [ -h $FILE ] ; then

Quote $FILE to allow for spaces..

>                       #echo $FILE is a symlink
>                       # Unfortunately, cp -d isn't universal so we have to
>                       # use a work-around.
> 
>                       # Use ls -l to find the target that the link points to
>                       LL=`ls -l $FILE`

Same..

>                       for L in $LL ; do
>                               TARGET=$L
>                       done

Can you assume existence of readlink? That's nicer, with -f flag

>                       #echo $FILE is a symlink pointing to $TARGET
> 
>                       FILE=`basename $FILE`

Allow for spaces again

>                       # Go to $DEST and make the link
>                       pushd $DEST
>                               ln -s $TARGET $FILE

Spaces in all of these..

Is 'ln -s' portable? Symlinks don't exist on some platforms to which
mesa is portable, like Windows. autoconf uses 'cp -p' instead for them.
See /usr/share/autoconf/autoconf/autoconf.m4f

>                       popd

Are pushd and popd portable?

> 
>               elif [ -f $FILE ] ; then
>                       #echo $FILE is a regular file
>                       cp $FILE $DEST
>                       if [ $MODE ] ; then
>                               chmod $MODE $DEST/$FILE
>                       fi
>               else
>                       echo "Unknown type of argument: " $FILE

More allowing for spaces in all this

>                       exit 1
>               fi
> 
>               I=`expr $I + 1`
>       done
> 
>       exit 0
> fi
> 
> # If we get here, we didn't find anything to do
> echo "Usage:"
> echo "  install -d dir                      Create named directory"
> echo "  install [-m mode] file [...] dest   Install files in destination"

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to