| 1 |
module Rake |
| 2 |
|
| 3 |
# Makefile loader to be used with the import file loader. |
| 4 |
class MakefileLoader |
| 5 |
include Rake::DSL |
| 6 |
|
| 7 |
SPACE_MARK = "\0" |
| 8 |
|
| 9 |
# Load the makefile dependencies in +fn+. |
| 10 |
def load(fn) |
| 11 |
lines = File.read fn |
| 12 |
lines.gsub!(/\\ /, SPACE_MARK) |
| 13 |
lines.gsub!(/#[^\n]*\n/m, "") |
| 14 |
lines.gsub!(/\\\n/, ' ') |
| 15 |
lines.each_line do |line| |
| 16 |
process_line(line) |
| 17 |
end |
| 18 |
end |
| 19 |
|
| 20 |
private |
| 21 |
|
| 22 |
# Process one logical line of makefile data. |
| 23 |
def process_line(line) |
| 24 |
file_tasks, args = line.split(':', 2) |
| 25 |
return if args.nil? |
| 26 |
dependents = args.split.map { |d| respace(d) } |
| 27 |
file_tasks.scan(/\S+/) do |file_task| |
| 28 |
file_task = respace(file_task) |
| 29 |
file file_task => dependents |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
def respace(str) |
| 34 |
str.tr SPACE_MARK, ' ' |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
# Install the handler |
| 39 |
Rake.application.add_loader('mf', MakefileLoader.new) |
| 40 |
end |