Blame mkinstalldirs

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