diff --git a/Rakefile b/Rakefile index 870de81..cbf111a 100644 --- a/Rakefile +++ b/Rakefile @@ -3,42 +3,45 @@ require 'rake/clean' require 'open3' M2C = 'gm2' # Modula-2 compiler. -BOOT_OBJECTS = FileList['boot/*.mod'] +BOOT_OBJECTS = FileList['source/*.elna'] .map do |source| Pathname.new(source).basename.sub_ext('.o') end -def source_for_object(out_file) - path = Pathname.new(out_file).relative_path_from('build') - result = ['build/boot'] - - definition = File.join('boot', path.basename.sub_ext('.def')) - result << definition if File.exist? definition - - implementation = path.sub_ext('.mod').to_path - implementation = File.join 'build', implementation unless File.exist? implementation - - result << implementation -end - directory 'build/boot' directory 'build/self' CLEAN.include 'build' -rule(/build\/.+\.o$/ => ->(file) { source_for_object(file) }) do |t| +rule(/build\/boot\/.+\.o$/ => ->(file) { + path = Pathname.new('source') + Pathname.new(file).basename + + ['build/boot', path.sub_ext('.def'), path.sub_ext('.elna')] +}) do |t| + sources = t.prerequisites.filter { |f| f.end_with? '.elna' } + + sh M2C, '-fmod=.elna', '-c', '-I', 'source', '-o', t.name, *sources +end + +rule(/build\/self\/.+\.o$/ => ->(file) { + path = Pathname.new(file).relative_path_from('build') + result = [] + + result << File.join('source', path.basename.sub_ext('.def')) + result << File.join('build', path.sub_ext('.mod')) +}) do |t| sources = t.prerequisites.filter { |f| f.end_with? '.mod' } - sh M2C, '-c', '-I', 'boot', '-o', t.name, *sources + sh M2C, '-c', '-I', 'source', '-o', t.name, *sources end rule(/build\/self\/.+\.mod$/ => [ 'build/self', 'build/boot/Compiler', - ->(file) { File.join('boot', Pathname.new(file).basename) } + ->(file) { File.join('source', Pathname.new(file).basename.sub_ext('.elna')) } ]) do |t| sources, compiler = t.prerequisites .reject { |f| File.directory? f } - .partition { |f| f.end_with? '.mod' } + .partition { |f| f.end_with? '.elna' } File.open t.name, 'w' do |output| puts @@ -62,16 +65,23 @@ end end compiler_object = compiler_binary.sub_ext('.o') - file compiler_object.to_path => source_for_object(compiler_object) do |t| - sources = t.prerequisites.filter { |f| f.end_with? '.mod' } +end - sh M2C, '-fscaffold-main', '-c', '-I', 'boot', '-o', t.name, *sources - end +file 'build/boot/Compiler.o' => ['build/boot', 'source/Compiler.elna'] do |t| + sources = t.prerequisites.filter { |f| f.end_with? '.elna' } + + sh M2C, '-fscaffold-main', '-fmod=.elna', '-c', '-I', 'source', '-o', t.name, *sources +end + +file 'build/self/Compiler.o' => ['build/self/Compiler.mod'] do |t| + sources = t.prerequisites.filter { |f| f.end_with? '.mod' } + + sh M2C, '-fscaffold-main', '-c', '-I', 'source', '-o', t.name, *sources end task default: 'build/self/Compiler' task default: 'build/self/Compiler.mod' -task default: 'boot/Compiler.mod' +task default: 'source/Compiler.elna' task :default do |t| exe, previous_output, source = t.prerequisites diff --git a/boot/Compiler.mod b/source/Compiler.elna similarity index 100% rename from boot/Compiler.mod rename to source/Compiler.elna diff --git a/boot/Lexer.def b/source/Lexer.def similarity index 100% rename from boot/Lexer.def rename to source/Lexer.def diff --git a/boot/Lexer.mod b/source/Lexer.elna similarity index 100% rename from boot/Lexer.mod rename to source/Lexer.elna diff --git a/boot/Transpiler.def b/source/Transpiler.def similarity index 100% rename from boot/Transpiler.def rename to source/Transpiler.def diff --git a/boot/Transpiler.mod b/source/Transpiler.elna similarity index 100% rename from boot/Transpiler.mod rename to source/Transpiler.elna