mkinstalldirs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #! /bin/sh
  2. # mkinstalldirs --- make directory hierarchy
  3. scriptversion=2004-02-15.20
  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 0
  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 0
  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. set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
  96. shift
  97. pathcomp=
  98. for d
  99. do
  100. pathcomp="$pathcomp$d"
  101. case $pathcomp in
  102. -*) pathcomp=./$pathcomp ;;
  103. esac
  104. if test ! -d "$pathcomp"; then
  105. echo "mkdir $pathcomp"
  106. mkdir "$pathcomp" || lasterr=$?
  107. if test ! -d "$pathcomp"; then
  108. errstatus=$lasterr
  109. else
  110. if test ! -z "$dirmode"; then
  111. echo "chmod $dirmode $pathcomp"
  112. lasterr=""
  113. chmod "$dirmode" "$pathcomp" || lasterr=$?
  114. if test ! -z "$lasterr"; then
  115. errstatus=$lasterr
  116. fi
  117. fi
  118. fi
  119. fi
  120. pathcomp="$pathcomp/"
  121. done
  122. done
  123. exit $errstatus
  124. # Local Variables:
  125. # mode: shell-script
  126. # sh-indentation: 2
  127. # eval: (add-hook 'write-file-hooks 'time-stamp)
  128. # time-stamp-start: "scriptversion="
  129. # time-stamp-format: "%:y-%02m-%02d.%02H"
  130. # time-stamp-end: "$"
  131. # End: