]> granicus.if.org Git - postgresql/blob - config/mkinstalldirs
Modify Solaris compiler build rules to use the cpp preprocessor, the the
[postgresql] / config / mkinstalldirs
1 #! /bin/sh
2 # mkinstalldirs --- make directory hierarchy
3
4 # $PostgreSQL: pgsql/config/mkinstalldirs,v 1.5 2006/03/11 04:38:28 momjian Exp $
5
6 scriptversion=2005-02-02.21
7
8 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
9 # Created: 1993-05-16
10 # Public domain.
11 #
12 # This file is maintained in Automake, please report
13 # bugs to <bug-automake@gnu.org> or send patches to
14 # <automake-patches@gnu.org>.
15
16 errstatus=0
17 dirmode=""
18
19 usage="\
20 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
21
22 Create each directory DIR (with mode MODE, if specified), including all
23 leading file name components.
24
25 Report bugs to <bug-automake@gnu.org>."
26
27 # process command line arguments
28 while test $# -gt 0 ; do
29   case $1 in
30     -h | --help | --h*)         # -h for help
31       echo "$usage"
32       exit $?
33       ;;
34     -m)                         # -m PERM arg
35       shift
36       test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
37       dirmode=$1
38       shift
39       ;;
40     --version)
41       echo "$0 $scriptversion"
42       exit $?
43       ;;
44     --)                         # stop option processing
45       shift
46       break
47       ;;
48     -*)                         # unknown option
49       echo "$usage" 1>&2
50       exit 1
51       ;;
52     *)                          # first non-opt arg
53       break
54       ;;
55   esac
56 done
57
58 for file
59 do
60   if test -d "$file"; then
61     shift
62   else
63     break
64   fi
65 done
66
67 case $# in
68   0) exit 0 ;;
69 esac
70
71 # Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
72 # mkdir -p a/c at the same time, both will detect that a is missing,
73 # one will create a, then the other will try to create a and die with
74 # a "File exists" error.  This is a problem when calling mkinstalldirs
75 # from a parallel make.  We use --version in the probe to restrict
76 # ourselves to GNU mkdir, which is thread-safe.
77 case $dirmode in
78   '')
79     if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
80       echo "mkdir -p -- $*"
81       exec mkdir -p -- "$@"
82     else
83       # On NextStep and OpenStep, the `mkdir' command does not
84       # recognize any option.  It will interpret all options as
85       # directories to create, and then abort because `.' already
86       # exists.
87       test -d ./-p && rmdir ./-p
88       test -d ./--version && rmdir ./--version
89     fi
90     ;;
91   *)
92     if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
93        test ! -d ./--version; then
94       echo "mkdir -m $dirmode -p -- $*"
95       exec mkdir -m "$dirmode" -p -- "$@"
96     else
97       # Clean up after NextStep and OpenStep mkdir.
98       for d in ./-m ./-p ./--version "./$dirmode";
99       do
100         test -d $d && rmdir $d
101       done
102     fi
103     ;;
104 esac
105
106 for file
107 do
108   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
109   shift
110
111   pathcomp=
112   for d
113   do
114     pathcomp="$pathcomp$d"
115     case $pathcomp in
116       -*) pathcomp=./$pathcomp ;;
117     esac
118
119     if test ! -d "$pathcomp"; then
120       echo "mkdir $pathcomp"
121
122       mkdir "$pathcomp" || lasterr=$?
123
124       if test ! -d "$pathcomp"; then
125         errstatus=$lasterr
126       else
127         if test ! -z "$dirmode"; then
128           echo "chmod $dirmode $pathcomp"
129           lasterr=""
130           chmod "$dirmode" "$pathcomp" || lasterr=$?
131
132           if test ! -z "$lasterr"; then
133             errstatus=$lasterr
134           fi
135         fi
136       fi
137     fi
138
139     pathcomp="$pathcomp/"
140   done
141 done
142
143 exit $errstatus
144
145 # Local Variables:
146 # mode: shell-script
147 # sh-indentation: 2
148 # eval: (add-hook 'write-file-hooks 'time-stamp)
149 # time-stamp-start: "scriptversion="
150 # time-stamp-format: "%:y-%02m-%02d.%02H"
151 # time-stamp-end: "$"
152 # End: