build-scripts/mkinstalldirs
author Ozkan Sezer <sezeroz@gmail.com>
Thu, 18 Oct 2018 11:55:16 +0300
branchSDL-1.2
changeset 12335 5e68900d2232
parent 1361 19418e4422cb
permissions -rwxr-xr-x
use less ancient versions of autofoo scripts
slouken@1361
     1
#! /bin/sh
slouken@1361
     2
# mkinstalldirs --- make directory hierarchy
sezeroz@12335
     3
sezeroz@12335
     4
scriptversion=2009-04-28.21; # UTC
sezeroz@12335
     5
sezeroz@12335
     6
# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
slouken@1361
     7
# Created: 1993-05-16
sezeroz@12335
     8
# Public domain.
sezeroz@12335
     9
#
sezeroz@12335
    10
# This file is maintained in Automake, please report
sezeroz@12335
    11
# bugs to <bug-automake@gnu.org> or send patches to
sezeroz@12335
    12
# <automake-patches@gnu.org>.
slouken@1361
    13
sezeroz@12335
    14
nl='
sezeroz@12335
    15
'
sezeroz@12335
    16
IFS=" ""	$nl"
slouken@1361
    17
errstatus=0
sezeroz@12335
    18
dirmode=
slouken@1361
    19
slouken@1361
    20
usage="\
sezeroz@12335
    21
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
sezeroz@12335
    22
sezeroz@12335
    23
Create each directory DIR (with mode MODE, if specified), including all
sezeroz@12335
    24
leading file name components.
sezeroz@12335
    25
sezeroz@12335
    26
Report bugs to <bug-automake@gnu.org>."
slouken@1361
    27
slouken@1361
    28
# process command line arguments
slouken@1361
    29
while test $# -gt 0 ; do
sezeroz@12335
    30
  case $1 in
sezeroz@12335
    31
    -h | --help | --h*)         # -h for help
sezeroz@12335
    32
      echo "$usage"
sezeroz@12335
    33
      exit $?
sezeroz@12335
    34
      ;;
sezeroz@12335
    35
    -m)                         # -m PERM arg
sezeroz@12335
    36
      shift
sezeroz@12335
    37
      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
sezeroz@12335
    38
      dirmode=$1
sezeroz@12335
    39
      shift
sezeroz@12335
    40
      ;;
sezeroz@12335
    41
    --version)
sezeroz@12335
    42
      echo "$0 $scriptversion"
sezeroz@12335
    43
      exit $?
sezeroz@12335
    44
      ;;
sezeroz@12335
    45
    --)                         # stop option processing
sezeroz@12335
    46
      shift
sezeroz@12335
    47
      break
sezeroz@12335
    48
      ;;
sezeroz@12335
    49
    -*)                         # unknown option
sezeroz@12335
    50
      echo "$usage" 1>&2
sezeroz@12335
    51
      exit 1
sezeroz@12335
    52
      ;;
sezeroz@12335
    53
    *)                          # first non-opt arg
sezeroz@12335
    54
      break
sezeroz@12335
    55
      ;;
sezeroz@12335
    56
  esac
slouken@1361
    57
done
slouken@1361
    58
slouken@1361
    59
for file
slouken@1361
    60
do
slouken@1361
    61
  if test -d "$file"; then
slouken@1361
    62
    shift
slouken@1361
    63
  else
slouken@1361
    64
    break
slouken@1361
    65
  fi
slouken@1361
    66
done
slouken@1361
    67
slouken@1361
    68
case $# in
sezeroz@12335
    69
  0) exit 0 ;;
slouken@1361
    70
esac
slouken@1361
    71
sezeroz@12335
    72
# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
sezeroz@12335
    73
# mkdir -p a/c at the same time, both will detect that a is missing,
sezeroz@12335
    74
# one will create a, then the other will try to create a and die with
sezeroz@12335
    75
# a "File exists" error.  This is a problem when calling mkinstalldirs
sezeroz@12335
    76
# from a parallel make.  We use --version in the probe to restrict
sezeroz@12335
    77
# ourselves to GNU mkdir, which is thread-safe.
slouken@1361
    78
case $dirmode in
sezeroz@12335
    79
  '')
sezeroz@12335
    80
    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
sezeroz@12335
    81
      echo "mkdir -p -- $*"
sezeroz@12335
    82
      exec mkdir -p -- "$@"
sezeroz@12335
    83
    else
sezeroz@12335
    84
      # On NextStep and OpenStep, the 'mkdir' command does not
sezeroz@12335
    85
      # recognize any option.  It will interpret all options as
sezeroz@12335
    86
      # directories to create, and then abort because '.' already
sezeroz@12335
    87
      # exists.
sezeroz@12335
    88
      test -d ./-p && rmdir ./-p
sezeroz@12335
    89
      test -d ./--version && rmdir ./--version
sezeroz@12335
    90
    fi
sezeroz@12335
    91
    ;;
sezeroz@12335
    92
  *)
sezeroz@12335
    93
    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
sezeroz@12335
    94
       test ! -d ./--version; then
sezeroz@12335
    95
      echo "mkdir -m $dirmode -p -- $*"
sezeroz@12335
    96
      exec mkdir -m "$dirmode" -p -- "$@"
sezeroz@12335
    97
    else
sezeroz@12335
    98
      # Clean up after NextStep and OpenStep mkdir.
sezeroz@12335
    99
      for d in ./-m ./-p ./--version "./$dirmode";
sezeroz@12335
   100
      do
sezeroz@12335
   101
        test -d $d && rmdir $d
sezeroz@12335
   102
      done
sezeroz@12335
   103
    fi
sezeroz@12335
   104
    ;;
slouken@1361
   105
esac
slouken@1361
   106
slouken@1361
   107
for file
slouken@1361
   108
do
sezeroz@12335
   109
  case $file in
sezeroz@12335
   110
    /*) pathcomp=/ ;;
sezeroz@12335
   111
    *)  pathcomp= ;;
sezeroz@12335
   112
  esac
sezeroz@12335
   113
  oIFS=$IFS
sezeroz@12335
   114
  IFS=/
sezeroz@12335
   115
  set fnord $file
sezeroz@12335
   116
  shift
sezeroz@12335
   117
  IFS=$oIFS
slouken@1361
   118
sezeroz@12335
   119
  for d
sezeroz@12335
   120
  do
sezeroz@12335
   121
    test "x$d" = x && continue
slouken@1361
   122
sezeroz@12335
   123
    pathcomp=$pathcomp$d
sezeroz@12335
   124
    case $pathcomp in
sezeroz@12335
   125
      -*) pathcomp=./$pathcomp ;;
sezeroz@12335
   126
    esac
slouken@1361
   127
sezeroz@12335
   128
    if test ! -d "$pathcomp"; then
sezeroz@12335
   129
      echo "mkdir $pathcomp"
slouken@1361
   130
sezeroz@12335
   131
      mkdir "$pathcomp" || lasterr=$?
slouken@1361
   132
sezeroz@12335
   133
      if test ! -d "$pathcomp"; then
sezeroz@12335
   134
	errstatus=$lasterr
sezeroz@12335
   135
      else
sezeroz@12335
   136
	if test ! -z "$dirmode"; then
sezeroz@12335
   137
	  echo "chmod $dirmode $pathcomp"
sezeroz@12335
   138
	  lasterr=
sezeroz@12335
   139
	  chmod "$dirmode" "$pathcomp" || lasterr=$?
slouken@1361
   140
sezeroz@12335
   141
	  if test ! -z "$lasterr"; then
sezeroz@12335
   142
	    errstatus=$lasterr
slouken@1361
   143
	  fi
slouken@1361
   144
	fi
sezeroz@12335
   145
      fi
sezeroz@12335
   146
    fi
slouken@1361
   147
sezeroz@12335
   148
    pathcomp=$pathcomp/
sezeroz@12335
   149
  done
slouken@1361
   150
done
slouken@1361
   151
slouken@1361
   152
exit $errstatus
slouken@1361
   153
slouken@1361
   154
# Local Variables:
slouken@1361
   155
# mode: shell-script
sezeroz@12335
   156
# sh-indentation: 2
sezeroz@12335
   157
# eval: (add-hook 'write-file-hooks 'time-stamp)
sezeroz@12335
   158
# time-stamp-start: "scriptversion="
sezeroz@12335
   159
# time-stamp-format: "%:y-%02m-%02d.%02H"
sezeroz@12335
   160
# time-stamp-time-zone: "UTC"
sezeroz@12335
   161
# time-stamp-end: "; # UTC"
slouken@1361
   162
# End: