mkinstalldirs 3.4 KB

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