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