xenocara/app/appres/mkinstalldirs

163 lines
3.5 KiB
Plaintext
Raw Normal View History

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