Ignore:
Timestamp:
Sep 15, 2006, 7:09:38 AM (19 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/config/install-sh

    • Property svn:executable set to *
    r151 r503  
    22# install - install a program, script, or datafile
    33
    4 scriptversion=2004-01-12.10
     4scriptversion=2005-05-14.22
    55
    66# This originates from X11R5 (mit/util/scripts/install.sh), which was
     
    5959mkdirprog="${MKDIRPROG-mkdir}"
    6060
    61 transformbasename=
    62 transform_arg=
    63 instcmd="$mvprog"
    6461chmodcmd="$chmodprog 0755"
    6562chowncmd=
     
    7168dst=
    7269dir_arg=
    73 
    74 usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
     70dstarg=
     71no_target_directory=
     72
     73usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
    7574   or: $0 [OPTION]... SRCFILES... DIRECTORY
    76    or: $0 -d DIRECTORIES...
    77 
    78 In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
    79 In the second, create the directory path DIR.
     75   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
     76   or: $0 [OPTION]... -d DIRECTORIES...
     77
     78In the 1st form, copy SRCFILE to DSTFILE.
     79In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
     80In the 4th, create DIRECTORIES.
    8081
    8182Options:
    82 -b=TRANSFORMBASENAME
    83 -c         copy source (using $cpprog) instead of moving (using $mvprog).
     83-c         (ignored)
    8484-d         create directories instead of installing files.
    85 -g GROUP   $chgrp installed files to GROUP.
    86 -m MODE    $chmod installed files to MODE.
    87 -o USER    $chown installed files to USER.
    88 -s         strip installed files (using $stripprog).
    89 -t=TRANSFORM
     85-g GROUP   $chgrpprog installed files to GROUP.
     86-m MODE    $chmodprog installed files to MODE.
     87-o USER    $chownprog installed files to USER.
     88-s         $stripprog installed files.
     89-t DIRECTORY  install into DIRECTORY.
     90-T         report an error if DSTFILE is a directory.
    9091--help     display this help and exit.
    9192--version  display version info and exit.
     
    9798while test -n "$1"; do
    9899  case $1 in
    99     -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
    100         shift
    101         continue;;
    102 
    103     -c) instcmd=$cpprog
    104         shift
     100    -c) shift
    105101        continue;;
    106102
     
    114110        continue;;
    115111
    116     --help) echo "$usage"; exit 0;;
     112    --help) echo "$usage"; exit $?;;
    117113
    118114    -m) chmodcmd="$chmodprog $2"
     
    130126        continue;;
    131127
    132     -t=*) transformarg=`echo $1 | sed 's/-t=//'`
    133         shift
    134         continue;;
    135 
    136     --version) echo "$0 $scriptversion"; exit 0;;
     128    -t) dstarg=$2
     129        shift
     130        shift
     131        continue;;
     132
     133    -T) no_target_directory=true
     134        shift
     135        continue;;
     136
     137    --version) echo "$0 $scriptversion"; exit $?;;
    137138
    138139    *)  # When -d is used, all remaining arguments are directories to create.
    139         test -n "$dir_arg" && break
     140        # When -t is used, the destination is already specified.
     141        test -n "$dir_arg$dstarg" && break
    140142        # Otherwise, the last argument is the destination.  Remove it from $@.
    141143        for arg
     
    175177
    176178    if test -d "$dst"; then
    177       instcmd=:
     179      mkdircmd=:
    178180      chmodcmd=
    179181    else
    180       instcmd=$mkdirprog
     182      mkdircmd=$mkdirprog
    181183    fi
    182184  else
    183     # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
     185    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
    184186    # might cause directories to be created, which would be especially bad
    185187    # if $src (and thus $dsttmp) contains '*'.
     
    203205    # if double slashes aren't ignored.
    204206    if test -d "$dst"; then
     207      if test -n "$no_target_directory"; then
     208        echo "$0: $dstarg: Is a directory" >&2
     209        exit 1
     210      fi
    205211      dst=$dst/`basename "$src"`
    206212    fi
     
    208214
    209215  # This sed command emulates the dirname command.
    210   dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
     216  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
    211217
    212218  # Make sure that the destination directory exists.
     
    215221  if test ! -d "$dstdir"; then
    216222    defaultIFS='
    217         '
     223         '
    218224    IFS="${IFS-$defaultIFS}"
    219225
     
    221227    # Some sh's can't handle IFS=/ for some reason.
    222228    IFS='%'
    223     set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
     229    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
     230    shift
    224231    IFS=$oIFS
    225232
     
    229236      pathcomp=$pathcomp$1
    230237      shift
    231       test -d "$pathcomp" || $mkdirprog "$pathcomp"
     238      if test ! -d "$pathcomp"; then
     239        $mkdirprog "$pathcomp"
     240        # mkdir can fail with a `File exist' error in case several
     241        # install-sh are creating the directory concurrently.  This
     242        # is OK.
     243        test -d "$pathcomp" || exit
     244      fi
    232245      pathcomp=$pathcomp/
    233246    done
     
    235248
    236249  if test -n "$dir_arg"; then
    237     $doit $instcmd "$dst" \
     250    $doit $mkdircmd "$dst" \
    238251      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
    239252      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
     
    242255
    243256  else
    244     # If we're going to rename the final executable, determine the name now.
    245     if test -z "$transformarg"; then
    246       dstfile=`basename "$dst"`
    247     else
    248       dstfile=`basename "$dst" $transformbasename \
    249                | sed $transformarg`$transformbasename
    250     fi
    251 
    252     # don't allow the sed command to completely eliminate the filename.
    253     test -z "$dstfile" && dstfile=`basename "$dst"`
     257    dstfile=`basename "$dst"`
    254258
    255259    # Make a couple of temp file names in the proper directory.
     
    258262
    259263    # Trap to clean up those temp files at exit.
    260     trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
     264    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
    261265    trap '(exit $?); exit' 1 2 13 15
    262266
    263     # Move or copy the file name to the temp name
    264     $doit $instcmd "$src" "$dsttmp" &&
     267    # Copy the file name to the temp name.
     268    $doit $cpprog "$src" "$dsttmp" &&
    265269
    266270    # and set any options; do chmod last to preserve setuid bits.
     
    268272    # If any of these fail, we abort the whole thing.  If we want to
    269273    # ignore errors from any of these, just make sure not to ignore
    270     # errors from the above "$doit $instcmd $src $dsttmp" command.
     274    # errors from the above "$doit $cpprog $src $dsttmp" command.
    271275    #
    272276    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
     
    275279      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
    276280
    277     # Now remove or move aside any old file at destination location.  We
    278     # try this two ways since rm can't unlink itself on some systems and
    279     # the destination file might be busy for other reasons.  In this case,
    280     # the final cleanup might fail but the new file should still install
    281     # successfully.
    282     {
    283       if test -f "$dstdir/$dstfile"; then
    284         $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
    285         || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
    286         || {
    287           echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
    288           (exit 1); exit
    289         }
    290       else
    291         :
    292       fi
    293     } &&
    294 
    295281    # Now rename the file to the real destination.
    296     $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
    297   fi || { (exit 1); exit; }
     282    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
     283      || {
     284           # The rename failed, perhaps because mv can't rename something else
     285           # to itself, or perhaps because mv is so ancient that it does not
     286           # support -f.
     287
     288           # Now remove or move aside any old file at destination location.
     289           # We try this two ways since rm can't unlink itself on some
     290           # systems and the destination file might be busy for other
     291           # reasons.  In this case, the final cleanup might fail but the new
     292           # file should still install successfully.
     293           {
     294             if test -f "$dstdir/$dstfile"; then
     295               $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
     296               || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
     297               || {
     298                 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
     299                 (exit 1); exit 1
     300               }
     301             else
     302               :
     303             fi
     304           } &&
     305
     306           # Now rename the file to the real destination.
     307           $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
     308         }
     309    }
     310  fi || { (exit 1); exit 1; }
    298311done
    299312
    300313# The final little trick to "correctly" pass the exit status to the exit trap.
    301314{
    302   (exit 0); exit
     315  (exit 0); exit 0
    303316}
    304317
Note: See TracChangeset for help on using the changeset viewer.