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