* bin/autoupdate.in: Define __file__ so that warnings
[autoconf.git] / config / mkinstalldirs
blob6504b744b00bc19141cea554f123d2036611bda3
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
4 scriptversion=2003-11-08.23
6 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
7 # Created: 1993-05-16
8 # Public domain.
10 # This file is maintained in Automake, please report
11 # bugs to <bug-automake@gnu.org> or send patches to
12 # <automake-patches@gnu.org>.
14 errstatus=0
15 dirmode=""
17 usage="\
18 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
20 Create each directory DIR (with mode MODE, if specified), including all
21 leading file name components.
23 Report bugs to <bug-automake@gnu.org>."
25 # process command line arguments
26 while test $# -gt 0 ; do
27 case $1 in
28 -h | --help | --h*) # -h for help
29 echo "$usage"
30 exit 0
32 -m) # -m PERM arg
33 shift
34 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
35 dirmode=$1
36 shift
38 --version)
39 echo "$0 $scriptversion"
40 exit 0
42 --) # stop option processing
43 shift
44 break
46 -*) # unknown option
47 echo "$usage" 1>&2
48 exit 1
50 *) # first non-opt arg
51 break
53 esac
54 done
56 for file
58 if test -d "$file"; then
59 shift
60 else
61 break
63 done
65 case $# in
66 0) exit 0 ;;
67 esac
69 case $dirmode in
70 '')
71 if mkdir -p -- . 2>/dev/null; then
72 echo "mkdir -p -- $*"
73 exec mkdir -p -- "$@"
74 else
75 # On NextStep and OpenStep, the `mkdir' command does not
76 # recognize any option. It will interpret all options as
77 # directories to create, and then abort because `.' already
78 # exists.
79 test -d ./-p && rmdir ./-p
80 test -d ./-- && rmdir ./--
84 if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
85 echo "mkdir -m $dirmode -p -- $*"
86 exec mkdir -m "$dirmode" -p -- "$@"
87 else
88 # Clean up after NextStep and OpenStep mkdir.
89 for d in ./-m ./-p ./-- "./$dirmode";
91 test -d $d && rmdir $d
92 done
95 esac
97 for file
99 set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
100 shift
102 pathcomp=
103 for d
105 pathcomp="$pathcomp$d"
106 case $pathcomp in
107 -*) pathcomp=./$pathcomp ;;
108 esac
110 if test ! -d "$pathcomp"; then
111 echo "mkdir $pathcomp"
113 mkdir "$pathcomp" || lasterr=$?
115 if test ! -d "$pathcomp"; then
116 errstatus=$lasterr
117 else
118 if test ! -z "$dirmode"; then
119 echo "chmod $dirmode $pathcomp"
120 lasterr=""
121 chmod "$dirmode" "$pathcomp" || lasterr=$?
123 if test ! -z "$lasterr"; then
124 errstatus=$lasterr
130 pathcomp="$pathcomp/"
131 done
132 done
134 exit $errstatus
136 # Local Variables:
137 # mode: shell-script
138 # sh-indentation: 2
139 # eval: (add-hook 'write-file-hooks 'time-stamp)
140 # time-stamp-start: "scriptversion="
141 # time-stamp-format: "%:y-%02m-%02d.%02H"
142 # time-stamp-end: "$"
143 # End: