a3fa03e9bdc7d9b3c84d96154e6abcc561b6cbb6
[platform/upstream/automake.git] / mkinstalldirs
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
3 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
4 # Created: 1993-05-16
5 # Public domain
6
7 # $Id: mkinstalldirs,v 1.8 2001/09/29 06:01:15 eggert Exp $
8
9 errstatus=0
10 dirmode=""
11
12 usage="\
13 Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
14
15 # process command line arguments
16 while test $# -gt 0 ; do
17    case "${1}" in
18      -h | --help | --h* )                       # -h for help
19         echo "${usage}" 1>&2; exit 0 ;;
20      -m )                                       # -m PERM arg
21         shift
22         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
23         dirmode="${1}"
24         shift ;;
25      -- ) shift; break ;;                       # stop option processing
26      -* ) echo "${usage}" 1>&2; exit 1 ;;       # unknown option
27      * )  break ;;                              # first non-opt arg
28    esac
29 done
30
31 case $# in
32 0) exit 0 ;;
33 esac
34
35 case $dirmode in
36 '')
37   if mkdir -p -- . 2>/dev/null; then
38     echo "mkdir -p -- $*"
39     exec mkdir -p -- "$@"
40   fi ;;
41 *)
42   if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
43     echo "mkdir -m $dirmode -p -- $*"
44     exec mkdir -m "$dirmode" -p -- "$@"
45   fi ;;
46 esac
47
48 for file
49 do
50    set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
51    shift
52
53    pathcomp=
54    for d
55    do
56      pathcomp="$pathcomp$d"
57      case "$pathcomp" in
58        -* ) pathcomp=./$pathcomp ;;
59      esac
60
61      if test ! -d "$pathcomp"; then
62         echo "mkdir $pathcomp"
63
64         mkdir "$pathcomp" || lasterr=$?
65
66         if test ! -d "$pathcomp"; then
67           errstatus=$lasterr
68         else
69           if test ! -z "$dirmode"; then
70              echo "chmod $dirmode $pathcomp"
71
72              lasterr=""
73              chmod "$dirmode" "$pathcomp" || lasterr=$?
74
75              if test ! -z "$lasterr"; then
76                errstatus=$lasterr
77              fi
78           fi
79         fi
80      fi
81
82      pathcomp="$pathcomp/"
83    done
84 done
85
86 exit $errstatus
87
88 # Local Variables:
89 # mode: shell-script
90 # sh-indentation: 3
91 # End:
92 # mkinstalldirs ends here