build-scripts/mkinstalldirs
branchSDL-1.2
changeset 12335 5e68900d2232
parent 1361 19418e4422cb
     1.1 --- a/build-scripts/mkinstalldirs	Sun Oct 14 15:25:04 2018 +0300
     1.2 +++ b/build-scripts/mkinstalldirs	Thu Oct 18 11:55:16 2018 +0300
     1.3 @@ -1,29 +1,59 @@
     1.4  #! /bin/sh
     1.5  # mkinstalldirs --- make directory hierarchy
     1.6 -# Author: Noah Friedman <friedman@prep.ai.mit.edu>
     1.7 +
     1.8 +scriptversion=2009-04-28.21; # UTC
     1.9 +
    1.10 +# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
    1.11  # Created: 1993-05-16
    1.12 -# Public domain
    1.13 +# Public domain.
    1.14 +#
    1.15 +# This file is maintained in Automake, please report
    1.16 +# bugs to <bug-automake@gnu.org> or send patches to
    1.17 +# <automake-patches@gnu.org>.
    1.18  
    1.19 +nl='
    1.20 +'
    1.21 +IFS=" ""	$nl"
    1.22  errstatus=0
    1.23 -dirmode=""
    1.24 +dirmode=
    1.25  
    1.26  usage="\
    1.27 -Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
    1.28 +Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
    1.29 +
    1.30 +Create each directory DIR (with mode MODE, if specified), including all
    1.31 +leading file name components.
    1.32 +
    1.33 +Report bugs to <bug-automake@gnu.org>."
    1.34  
    1.35  # process command line arguments
    1.36  while test $# -gt 0 ; do
    1.37 -   case "${1}" in
    1.38 -     -h | --help | --h* )			# -h for help
    1.39 -	echo "${usage}" 1>&2; exit 0 ;;
    1.40 -     -m )					# -m PERM arg
    1.41 -	shift
    1.42 -	test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
    1.43 -	dirmode="${1}"
    1.44 -	shift ;;
    1.45 -     -- ) shift; break ;;			# stop option processing
    1.46 -     -* ) echo "${usage}" 1>&2; exit 1 ;;	# unknown option
    1.47 -     * )  break ;;				# first non-opt arg
    1.48 -   esac
    1.49 +  case $1 in
    1.50 +    -h | --help | --h*)         # -h for help
    1.51 +      echo "$usage"
    1.52 +      exit $?
    1.53 +      ;;
    1.54 +    -m)                         # -m PERM arg
    1.55 +      shift
    1.56 +      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
    1.57 +      dirmode=$1
    1.58 +      shift
    1.59 +      ;;
    1.60 +    --version)
    1.61 +      echo "$0 $scriptversion"
    1.62 +      exit $?
    1.63 +      ;;
    1.64 +    --)                         # stop option processing
    1.65 +      shift
    1.66 +      break
    1.67 +      ;;
    1.68 +    -*)                         # unknown option
    1.69 +      echo "$usage" 1>&2
    1.70 +      exit 1
    1.71 +      ;;
    1.72 +    *)                          # first non-opt arg
    1.73 +      break
    1.74 +      ;;
    1.75 +  esac
    1.76  done
    1.77  
    1.78  for file
    1.79 @@ -36,64 +66,97 @@
    1.80  done
    1.81  
    1.82  case $# in
    1.83 -0) exit 0 ;;
    1.84 +  0) exit 0 ;;
    1.85  esac
    1.86  
    1.87 +# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
    1.88 +# mkdir -p a/c at the same time, both will detect that a is missing,
    1.89 +# one will create a, then the other will try to create a and die with
    1.90 +# a "File exists" error.  This is a problem when calling mkinstalldirs
    1.91 +# from a parallel make.  We use --version in the probe to restrict
    1.92 +# ourselves to GNU mkdir, which is thread-safe.
    1.93  case $dirmode in
    1.94 -'')
    1.95 -  if mkdir -p -- . 2>/dev/null; then
    1.96 -    echo "mkdir -p -- $*"
    1.97 -    exec mkdir -p -- "$@"
    1.98 -  fi ;;
    1.99 -*)
   1.100 -  if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
   1.101 -    echo "mkdir -m $dirmode -p -- $*"
   1.102 -    exec mkdir -m "$dirmode" -p -- "$@"
   1.103 -  fi ;;
   1.104 +  '')
   1.105 +    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
   1.106 +      echo "mkdir -p -- $*"
   1.107 +      exec mkdir -p -- "$@"
   1.108 +    else
   1.109 +      # On NextStep and OpenStep, the 'mkdir' command does not
   1.110 +      # recognize any option.  It will interpret all options as
   1.111 +      # directories to create, and then abort because '.' already
   1.112 +      # exists.
   1.113 +      test -d ./-p && rmdir ./-p
   1.114 +      test -d ./--version && rmdir ./--version
   1.115 +    fi
   1.116 +    ;;
   1.117 +  *)
   1.118 +    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
   1.119 +       test ! -d ./--version; then
   1.120 +      echo "mkdir -m $dirmode -p -- $*"
   1.121 +      exec mkdir -m "$dirmode" -p -- "$@"
   1.122 +    else
   1.123 +      # Clean up after NextStep and OpenStep mkdir.
   1.124 +      for d in ./-m ./-p ./--version "./$dirmode";
   1.125 +      do
   1.126 +        test -d $d && rmdir $d
   1.127 +      done
   1.128 +    fi
   1.129 +    ;;
   1.130  esac
   1.131  
   1.132  for file
   1.133  do
   1.134 -   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
   1.135 -   shift
   1.136 +  case $file in
   1.137 +    /*) pathcomp=/ ;;
   1.138 +    *)  pathcomp= ;;
   1.139 +  esac
   1.140 +  oIFS=$IFS
   1.141 +  IFS=/
   1.142 +  set fnord $file
   1.143 +  shift
   1.144 +  IFS=$oIFS
   1.145  
   1.146 -   pathcomp=
   1.147 -   for d
   1.148 -   do
   1.149 -     pathcomp="$pathcomp$d"
   1.150 -     case "$pathcomp" in
   1.151 -       -* ) pathcomp=./$pathcomp ;;
   1.152 -     esac
   1.153 -
   1.154 -     if test ! -d "$pathcomp"; then
   1.155 -	echo "mkdir $pathcomp"
   1.156 +  for d
   1.157 +  do
   1.158 +    test "x$d" = x && continue
   1.159  
   1.160 -	mkdir "$pathcomp" || lasterr=$?
   1.161 +    pathcomp=$pathcomp$d
   1.162 +    case $pathcomp in
   1.163 +      -*) pathcomp=./$pathcomp ;;
   1.164 +    esac
   1.165 +
   1.166 +    if test ! -d "$pathcomp"; then
   1.167 +      echo "mkdir $pathcomp"
   1.168 +
   1.169 +      mkdir "$pathcomp" || lasterr=$?
   1.170  
   1.171 -	if test ! -d "$pathcomp"; then
   1.172 -	  errstatus=$lasterr
   1.173 -	else
   1.174 -	  if test ! -z "$dirmode"; then
   1.175 -	     echo "chmod $dirmode $pathcomp"
   1.176 +      if test ! -d "$pathcomp"; then
   1.177 +	errstatus=$lasterr
   1.178 +      else
   1.179 +	if test ! -z "$dirmode"; then
   1.180 +	  echo "chmod $dirmode $pathcomp"
   1.181 +	  lasterr=
   1.182 +	  chmod "$dirmode" "$pathcomp" || lasterr=$?
   1.183  
   1.184 -	     lasterr=""
   1.185 -	     chmod "$dirmode" "$pathcomp" || lasterr=$?
   1.186 -
   1.187 -	     if test ! -z "$lasterr"; then
   1.188 -	       errstatus=$lasterr
   1.189 -	     fi
   1.190 +	  if test ! -z "$lasterr"; then
   1.191 +	    errstatus=$lasterr
   1.192  	  fi
   1.193  	fi
   1.194 -     fi
   1.195 +      fi
   1.196 +    fi
   1.197  
   1.198 -     pathcomp="$pathcomp/"
   1.199 -   done
   1.200 +    pathcomp=$pathcomp/
   1.201 +  done
   1.202  done
   1.203  
   1.204  exit $errstatus
   1.205  
   1.206  # Local Variables:
   1.207  # mode: shell-script
   1.208 -# sh-indentation: 3
   1.209 +# sh-indentation: 2
   1.210 +# eval: (add-hook 'write-file-hooks 'time-stamp)
   1.211 +# time-stamp-start: "scriptversion="
   1.212 +# time-stamp-format: "%:y-%02m-%02d.%02H"
   1.213 +# time-stamp-time-zone: "UTC"
   1.214 +# time-stamp-end: "; # UTC"
   1.215  # End:
   1.216 -# mkinstalldirs ends here