File indexing completed on 2024-12-22 04:04:20
0001 #! /bin/sh 0002 # mkinstalldirs --- make directory hierarchy 0003 0004 scriptversion=2018-03-07.03; # UTC 0005 0006 # Original author: Noah Friedman <friedman@prep.ai.mit.edu> 0007 # Created: 1993-05-16 0008 # Public domain. 0009 # 0010 # This file is maintained in Automake, please report 0011 # bugs to <bug-automake@gnu.org> or send patches to 0012 # <automake-patches@gnu.org>. 0013 0014 nl=' 0015 ' 0016 IFS=" "" $nl" 0017 errstatus=0 0018 dirmode= 0019 0020 usage="\ 0021 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 0022 0023 Create each directory DIR (with mode MODE, if specified), including all 0024 leading file name components. 0025 0026 Report bugs to <bug-automake@gnu.org>." 0027 0028 # process command line arguments 0029 while test $# -gt 0 ; do 0030 case $1 in 0031 -h | --help | --h*) # -h for help 0032 echo "$usage" 0033 exit $? 0034 ;; 0035 -m) # -m PERM arg 0036 shift 0037 test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 0038 dirmode=$1 0039 shift 0040 ;; 0041 --version) 0042 echo "$0 $scriptversion" 0043 exit $? 0044 ;; 0045 --) # stop option processing 0046 shift 0047 break 0048 ;; 0049 -*) # unknown option 0050 echo "$usage" 1>&2 0051 exit 1 0052 ;; 0053 *) # first non-opt arg 0054 break 0055 ;; 0056 esac 0057 done 0058 0059 for file 0060 do 0061 if test -d "$file"; then 0062 shift 0063 else 0064 break 0065 fi 0066 done 0067 0068 case $# in 0069 0) exit 0 ;; 0070 esac 0071 0072 # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 0073 # mkdir -p a/c at the same time, both will detect that a is missing, 0074 # one will create a, then the other will try to create a and die with 0075 # a "File exists" error. This is a problem when calling mkinstalldirs 0076 # from a parallel make. We use --version in the probe to restrict 0077 # ourselves to GNU mkdir, which is thread-safe. 0078 case $dirmode in 0079 '') 0080 if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 0081 echo "mkdir -p -- $*" 0082 exec mkdir -p -- "$@" 0083 else 0084 # On NextStep and OpenStep, the 'mkdir' command does not 0085 # recognize any option. It will interpret all options as 0086 # directories to create, and then abort because '.' already 0087 # exists. 0088 test -d ./-p && rmdir ./-p 0089 test -d ./--version && rmdir ./--version 0090 fi 0091 ;; 0092 *) 0093 if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 0094 test ! -d ./--version; then 0095 echo "mkdir -m $dirmode -p -- $*" 0096 exec mkdir -m "$dirmode" -p -- "$@" 0097 else 0098 # Clean up after NextStep and OpenStep mkdir. 0099 for d in ./-m ./-p ./--version "./$dirmode"; 0100 do 0101 test -d $d && rmdir $d 0102 done 0103 fi 0104 ;; 0105 esac 0106 0107 for file 0108 do 0109 case $file in 0110 /*) pathcomp=/ ;; 0111 *) pathcomp= ;; 0112 esac 0113 oIFS=$IFS 0114 IFS=/ 0115 set fnord $file 0116 shift 0117 IFS=$oIFS 0118 0119 for d 0120 do 0121 test "x$d" = x && continue 0122 0123 pathcomp=$pathcomp$d 0124 case $pathcomp in 0125 -*) pathcomp=./$pathcomp ;; 0126 esac 0127 0128 if test ! -d "$pathcomp"; then 0129 echo "mkdir $pathcomp" 0130 0131 mkdir "$pathcomp" || lasterr=$? 0132 0133 if test ! -d "$pathcomp"; then 0134 errstatus=$lasterr 0135 else 0136 if test ! -z "$dirmode"; then 0137 echo "chmod $dirmode $pathcomp" 0138 lasterr= 0139 chmod "$dirmode" "$pathcomp" || lasterr=$? 0140 0141 if test ! -z "$lasterr"; then 0142 errstatus=$lasterr 0143 fi 0144 fi 0145 fi 0146 fi 0147 0148 pathcomp=$pathcomp/ 0149 done 0150 done 0151 0152 exit $errstatus 0153 0154 # Local Variables: 0155 # mode: shell-script 0156 # sh-indentation: 2 0157 # eval: (add-hook 'before-save-hook 'time-stamp) 0158 # time-stamp-start: "scriptversion=" 0159 # time-stamp-format: "%:y-%02m-%02d.%02H" 0160 # time-stamp-time-zone: "UTC0" 0161 # time-stamp-end: "; # UTC" 0162 # End: