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