makefile.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # modified version of Rake's provided make-style dependency loader
  2. # customizations:
  3. # (1) handles windows drives in paths -- colons don't confuse task demarcation
  4. # (2) handles spaces in directory paths
  5. module Rake
  6. # Makefile loader to be used with the import file loader.
  7. class MakefileLoader
  8. # Load the makefile dependencies in +fn+.
  9. def load(fn)
  10. open(fn) do |mf|
  11. lines = mf.read
  12. lines.gsub!(/#[^\n]*\n/m, "") # remove comments
  13. lines.gsub!(/\\\n/, ' ') # string together line continuations into single line
  14. lines.split("\n").each do |line|
  15. process_line(line)
  16. end
  17. end
  18. end
  19. private
  20. # Process one logical line of makefile data.
  21. def process_line(line)
  22. # split on presence of task demaractor followed by space (i.e don't get confused by a colon in a win path)
  23. file_tasks, args = line.split(/:\s/)
  24. return if args.nil?
  25. # split at non-escaped space boundary between files (i.e. escaped spaces in paths are left alone)
  26. dependents = args.split(/\b\s+/)
  27. # replace escaped spaces and clean up any extra whitespace
  28. dependents.map! { |path| path.gsub(/\\ /, ' ').strip }
  29. file_tasks.strip.split.each do |file_task|
  30. file file_task => dependents
  31. end
  32. end
  33. end
  34. # Install the handler
  35. Rake.application.add_loader('mf', MakefileLoader.new)
  36. end