os161.mkdirs.mk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # MKDIRS logic
  3. #
  4. # This generates rules for all intermediate directories as well as
  5. # the directories listed. (That is, if you say MKDIRS=/usr/bin/foo
  6. # you get rules for /usr and /usr/bin as well as /usr/bin/foo.)
  7. #
  8. # Variable for complete list of dirs. Start empty.
  9. _MKDIRS_=
  10. # For each dir in the list...
  11. .for _DIR_ in $(MKDIRS)
  12. #
  13. # Initialize some temporaries.
  14. # _HEAD_ contains / if the path was absolute.
  15. # _INCR_DIR_ accumulates the full directory name incrementally.
  16. #
  17. # Use := to force full evaluation of the RHS of each expression while
  18. # still in the loop, instead of when the variables are used later.
  19. #
  20. _HEAD_:=$(_DIR_:M/*:C/..*/\//)
  21. _INCR_DIR_:=
  22. # For each component in the directory, split on slashes...
  23. .for _COMPONENT_ in $(_DIR_:S/\// /g)
  24. # Add the component to _INCR_DIR_.
  25. _INCR_DIR_:=$(_INCR_DIR_)$(_COMPONENT_)/
  26. # Add the current partial directory to the main list.
  27. # Lose the trailing slash.
  28. _MKDIRS_:=$(_MKDIRS_) $(_HEAD_)$(_INCR_DIR_:S/\/$//)
  29. .endfor # _COMPONENT_
  30. .endfor # _DIR_
  31. #
  32. # Now issue a rule for each directory in the expanded list,
  33. # ordering and uniquifying it.
  34. #
  35. # XXX use /dev/null to suppress curious messages like "../../.. is up
  36. # to date". This scheme probably ought to be reworked.
  37. #
  38. .for _DIR_ in $(_MKDIRS_:O:u)
  39. .if !target($(_DIR_))
  40. $(_DIR_):
  41. .for _PRE_ in $(_DIR_:M*/*:H:N..)
  42. @$(MAKE) $(_PRE_) >/dev/null 2>&1
  43. .endfor
  44. mkdir $(_DIR_)
  45. .endif
  46. .endfor
  47. # Clear MKDIRS in case we're included again.
  48. MKDIRS=
  49. # End.