kusano 7d535a
#! /bin/sh
kusano 7d535a
# mkinstalldirs --- make directory hierarchy
kusano 7d535a
kusano 7d535a
scriptversion=2006-05-11.19
kusano 7d535a
kusano 7d535a
# Original author: Noah Friedman <friedman@prep.ai.mit.edu></friedman@prep.ai.mit.edu>
kusano 7d535a
# Created: 1993-05-16
kusano 7d535a
# Public domain.
kusano 7d535a
#
kusano 7d535a
# This file is maintained in Automake, please report
kusano 7d535a
# bugs to <bug-automake@gnu.org> or send patches to</bug-automake@gnu.org>
kusano 7d535a
# <automake-patches@gnu.org>.</automake-patches@gnu.org>
kusano 7d535a
kusano 7d535a
nl='
kusano 7d535a
'
kusano 7d535a
IFS=" ""	$nl"
kusano 7d535a
errstatus=0
kusano 7d535a
dirmode=
kusano 7d535a
kusano 7d535a
usage="\
kusano 7d535a
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
kusano 7d535a
kusano 7d535a
Create each directory DIR (with mode MODE, if specified), including all
kusano 7d535a
leading file name components.
kusano 7d535a
kusano 7d535a
Report bugs to <bug-automake@gnu.org>."</bug-automake@gnu.org>
kusano 7d535a
kusano 7d535a
# process command line arguments
kusano 7d535a
while test $# -gt 0 ; do
kusano 7d535a
  case $1 in
kusano 7d535a
    -h | --help | --h*)         # -h for help
kusano 7d535a
      echo "$usage"
kusano 7d535a
      exit $?
kusano 7d535a
      ;;
kusano 7d535a
    -m)                         # -m PERM arg
kusano 7d535a
      shift
kusano 7d535a
      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
kusano 7d535a
      dirmode=$1
kusano 7d535a
      shift
kusano 7d535a
      ;;
kusano 7d535a
    --version)
kusano 7d535a
      echo "$0 $scriptversion"
kusano 7d535a
      exit $?
kusano 7d535a
      ;;
kusano 7d535a
    --)                         # stop option processing
kusano 7d535a
      shift
kusano 7d535a
      break
kusano 7d535a
      ;;
kusano 7d535a
    -*)                         # unknown option
kusano 7d535a
      echo "$usage" 1>&2
kusano 7d535a
      exit 1
kusano 7d535a
      ;;
kusano 7d535a
    *)                          # first non-opt arg
kusano 7d535a
      break
kusano 7d535a
      ;;
kusano 7d535a
  esac
kusano 7d535a
done
kusano 7d535a
kusano 7d535a
for file
kusano 7d535a
do
kusano 7d535a
  if test -d "$file"; then
kusano 7d535a
    shift
kusano 7d535a
  else
kusano 7d535a
    break
kusano 7d535a
  fi
kusano 7d535a
done
kusano 7d535a
kusano 7d535a
case $# in
kusano 7d535a
  0) exit 0 ;;
kusano 7d535a
esac
kusano 7d535a
kusano 7d535a
# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
kusano 7d535a
# mkdir -p a/c at the same time, both will detect that a is missing,
kusano 7d535a
# one will create a, then the other will try to create a and die with
kusano 7d535a
# a "File exists" error.  This is a problem when calling mkinstalldirs
kusano 7d535a
# from a parallel make.  We use --version in the probe to restrict
kusano 7d535a
# ourselves to GNU mkdir, which is thread-safe.
kusano 7d535a
case $dirmode in
kusano 7d535a
  '')
kusano 7d535a
    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
kusano 7d535a
      echo "mkdir -p -- $*"
kusano 7d535a
      exec mkdir -p -- "$@"
kusano 7d535a
    else
kusano 7d535a
      # On NextStep and OpenStep, the `mkdir' command does not
kusano 7d535a
      # recognize any option.  It will interpret all options as
kusano 7d535a
      # directories to create, and then abort because `.' already
kusano 7d535a
      # exists.
kusano 7d535a
      test -d ./-p && rmdir ./-p
kusano 7d535a
      test -d ./--version && rmdir ./--version
kusano 7d535a
    fi
kusano 7d535a
    ;;
kusano 7d535a
  *)
kusano 7d535a
    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
kusano 7d535a
       test ! -d ./--version; then
kusano 7d535a
      echo "mkdir -m $dirmode -p -- $*"
kusano 7d535a
      exec mkdir -m "$dirmode" -p -- "$@"
kusano 7d535a
    else
kusano 7d535a
      # Clean up after NextStep and OpenStep mkdir.
kusano 7d535a
      for d in ./-m ./-p ./--version "./$dirmode";
kusano 7d535a
      do
kusano 7d535a
        test -d $d && rmdir $d
kusano 7d535a
      done
kusano 7d535a
    fi
kusano 7d535a
    ;;
kusano 7d535a
esac
kusano 7d535a
kusano 7d535a
for file
kusano 7d535a
do
kusano 7d535a
  case $file in
kusano 7d535a
    /*) pathcomp=/ ;;
kusano 7d535a
    *)  pathcomp= ;;
kusano 7d535a
  esac
kusano 7d535a
  oIFS=$IFS
kusano 7d535a
  IFS=/
kusano 7d535a
  set fnord $file
kusano 7d535a
  shift
kusano 7d535a
  IFS=$oIFS
kusano 7d535a
kusano 7d535a
  for d
kusano 7d535a
  do
kusano 7d535a
    test "x$d" = x && continue
kusano 7d535a
kusano 7d535a
    pathcomp=$pathcomp$d
kusano 7d535a
    case $pathcomp in
kusano 7d535a
      -*) pathcomp=./$pathcomp ;;
kusano 7d535a
    esac
kusano 7d535a
kusano 7d535a
    if test ! -d "$pathcomp"; then
kusano 7d535a
      echo "mkdir $pathcomp"
kusano 7d535a
kusano 7d535a
      mkdir "$pathcomp" || lasterr=$?
kusano 7d535a
kusano 7d535a
      if test ! -d "$pathcomp"; then
kusano 7d535a
	errstatus=$lasterr
kusano 7d535a
      else
kusano 7d535a
	if test ! -z "$dirmode"; then
kusano 7d535a
	  echo "chmod $dirmode $pathcomp"
kusano 7d535a
	  lasterr=
kusano 7d535a
	  chmod "$dirmode" "$pathcomp" || lasterr=$?
kusano 7d535a
kusano 7d535a
	  if test ! -z "$lasterr"; then
kusano 7d535a
	    errstatus=$lasterr
kusano 7d535a
	  fi
kusano 7d535a
	fi
kusano 7d535a
      fi
kusano 7d535a
    fi
kusano 7d535a
kusano 7d535a
    pathcomp=$pathcomp/
kusano 7d535a
  done
kusano 7d535a
done
kusano 7d535a
kusano 7d535a
exit $errstatus
kusano 7d535a
kusano 7d535a
# Local Variables:
kusano 7d535a
# mode: shell-script
kusano 7d535a
# sh-indentation: 2
kusano 7d535a
# eval: (add-hook 'write-file-hooks 'time-stamp)
kusano 7d535a
# time-stamp-start: "scriptversion="
kusano 7d535a
# time-stamp-format: "%:y-%02m-%02d.%02H"
kusano 7d535a
# time-stamp-end: "$"
kusano 7d535a
# End: