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