maintainer-makefile: Prohibit BSD4.3/SysV u_char etc types.
[gnulib.git] / build-aux / mkinstalldirs
blob83e8e31ecddbc92f192fd001984ebfef589d0e82
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
4 scriptversion=2023-11-23.18; # UTC
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 nl='
16 IFS=" "" $nl"
17 errstatus=0
18 dirmode=
20 usage="\
21 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
23 Create each directory DIR (with mode MODE, if specified), including all
24 leading file name components.
26 Report bugs to <bug-automake@gnu.org>.
27 GNU Automake home page: <https://www.gnu.org/software/automake/>.
28 General help using GNU software: <https://www.gnu.org/gethelp/>."
30 # process command line arguments
31 while test $# -gt 0 ; do
32 case $1 in
33 -h | --help | --h*) # -h for help
34 echo "$usage"
35 exit $?
37 -m) # -m PERM arg
38 shift
39 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
40 dirmode=$1
41 shift
43 --version)
44 echo "$0 $scriptversion"
45 exit $?
47 --) # stop option processing
48 shift
49 break
51 -*) # unknown option
52 echo "$usage" 1>&2
53 exit 1
55 *) # first non-opt arg
56 break
58 esac
59 done
61 for file
63 if test -d "$file"; then
64 shift
65 else
66 break
68 done
70 case $# in
71 0) exit 0 ;;
72 esac
74 # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
75 # mkdir -p a/c at the same time, both will detect that a is missing,
76 # one will create a, then the other will try to create a and die with
77 # a "File exists" error. This is a problem when calling mkinstalldirs
78 # from a parallel make. We use --version in the probe to restrict
79 # ourselves to GNU mkdir, which is thread-safe.
80 case $dirmode in
81 '')
82 if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
83 echo "mkdir -p -- $*"
84 exec mkdir -p -- "$@"
85 else
86 # On NextStep and OpenStep, the 'mkdir' command does not
87 # recognize any option. It will interpret all options as
88 # directories to create, and then abort because '.' already
89 # exists.
90 test -d ./-p && rmdir ./-p
91 test -d ./--version && rmdir ./--version
95 if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
96 test ! -d ./--version; then
97 echo "umask 22"
98 umask 22
99 echo "mkdir -m $dirmode -p -- $*"
100 exec mkdir -m "$dirmode" -p -- "$@"
101 else
102 # Clean up after NextStep and OpenStep mkdir.
103 for d in ./-m ./-p ./--version "./$dirmode";
105 test -d $d && rmdir $d
106 done
109 esac
111 echo "umask 22"
112 umask 22
114 for file
116 case $file in
117 /*) pathcomp=/ ;;
118 *) pathcomp= ;;
119 esac
120 oIFS=$IFS
121 IFS=/
122 set fnord $file
123 shift
124 IFS=$oIFS
126 for d
128 test "x$d" = x && continue
130 pathcomp=$pathcomp$d
131 case $pathcomp in
132 -*) pathcomp=./$pathcomp ;;
133 esac
135 if test ! -d "$pathcomp"; then
136 echo "mkdir $pathcomp"
138 mkdir "$pathcomp" || lasterr=$?
140 if test ! -d "$pathcomp"; then
141 errstatus=$lasterr
145 pathcomp=$pathcomp/
146 done
148 if test ! -z "$dirmode"; then
149 echo "chmod $dirmode $file"
150 chmod "$dirmode" "$file" || errstatus=$?
152 done
154 exit $errstatus
156 # Local Variables:
157 # mode: shell-script
158 # sh-indentation: 2
159 # eval: (add-hook 'before-save-hook 'time-stamp)
160 # time-stamp-start: "scriptversion="
161 # time-stamp-format: "%:y-%02m-%02d.%02H"
162 # time-stamp-time-zone: "UTC0"
163 # time-stamp-end: "; # UTC"
164 # End: