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