Start a Modula-2 experiment
This commit is contained in:
73
Rakefile
73
Rakefile
@@ -2,6 +2,45 @@ require 'pathname'
|
||||
require 'rake/clean'
|
||||
require 'open3'
|
||||
|
||||
M2C = 'gm2' # Modula-2 compiler.
|
||||
BOOT_OBJECTS = FileList['boot/*.mod']
|
||||
.map do |file|
|
||||
File.join('build', Pathname.new(file).sub_ext('.o'))
|
||||
end
|
||||
|
||||
directory 'build/boot'
|
||||
|
||||
CLEAN.include 'build'
|
||||
|
||||
rule(/build\/boot\/.+\.o$/ => ->(file) { test_for_out(file) }) do |t|
|
||||
sources = t.prerequisites.filter { |f| f.end_with? '.mod' }
|
||||
|
||||
sh M2C, '-c', '-I', 'boot', '-o', t.name, *sources
|
||||
end
|
||||
|
||||
file 'build/boot/Compiler.o' => ['build/boot', 'boot/Compiler.mod'] do |t|
|
||||
sources = t.prerequisites.filter { |f| f.end_with? '.mod' }
|
||||
|
||||
sh M2C, '-fscaffold-main', '-c', '-I', 'boot', '-o', t.name, *sources
|
||||
end
|
||||
|
||||
file 'build/boot/Compiler' => BOOT_OBJECTS do |t|
|
||||
sh M2C, '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
task default: 'build/boot/Compiler'
|
||||
task :default do |t|
|
||||
sh t.prerequisites.first
|
||||
end
|
||||
|
||||
def test_for_out(out_file)
|
||||
path = Pathname.new(out_file).relative_path_from('build')
|
||||
implementation = path.sub_ext('.mod').to_path
|
||||
definition = path.sub_ext('.def').to_path
|
||||
|
||||
['build/boot', implementation, definition]
|
||||
end
|
||||
|
||||
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
|
||||
BINARY = 'build/bin/elna'
|
||||
TESTS = FileList['tests/*.eln'].flat_map do |test|
|
||||
@@ -13,34 +52,15 @@ end
|
||||
|
||||
SOURCES = FileList['source/**/*.d']
|
||||
|
||||
directory 'build'
|
||||
|
||||
CLEAN.include 'build'
|
||||
CLEAN.include '.dub'
|
||||
|
||||
rule(/build\/riscv\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
|
||||
sh '/opt/riscv/bin/riscv32-unknown-elf-ld',
|
||||
'-o', t.name,
|
||||
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0',
|
||||
'-L/opt/riscv/riscv32-unknown-elf/lib',
|
||||
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
|
||||
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtbegin.o',
|
||||
t.source,
|
||||
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
|
||||
'/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/crtend.o'
|
||||
end
|
||||
|
||||
rule(/build\/riscv\/.+\.o$/ => ->(file) { test_for_object(file, '.eln') }) do |t|
|
||||
Pathname.new(t.name).dirname.mkpath
|
||||
sh BINARY, '-o', t.name, t.source
|
||||
end
|
||||
|
||||
file BINARY => SOURCES do |t|
|
||||
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc-12')
|
||||
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc')
|
||||
end
|
||||
|
||||
task default: BINARY
|
||||
|
||||
desc 'Run all tests and check the results'
|
||||
task test: TESTS
|
||||
task test: BINARY do
|
||||
@@ -55,6 +75,7 @@ task test: BINARY do
|
||||
if test.include? '/riscv/'
|
||||
spike = [
|
||||
'/opt/riscv/bin/spike',
|
||||
'--isa=RV32IMAC',
|
||||
'/opt/riscv/riscv32-unknown-elf/bin/pk',
|
||||
test
|
||||
]
|
||||
@@ -72,11 +93,6 @@ task test: BINARY do
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Run unittest blocks'
|
||||
task unittest: SOURCES do |t|
|
||||
sh('dub', 'test', '--compiler=gdc-12')
|
||||
end
|
||||
|
||||
def test_for_object(out_file, extension)
|
||||
test_source = Pathname
|
||||
.new(out_file)
|
||||
@@ -85,10 +101,3 @@ def test_for_object(out_file, extension)
|
||||
.to_path
|
||||
[test_source, BINARY]
|
||||
end
|
||||
|
||||
def test_for_out(out_file, extension)
|
||||
Pathname
|
||||
.new(out_file)
|
||||
.sub_ext(extension)
|
||||
.to_path
|
||||
end
|
||||
|
Reference in New Issue
Block a user