elna/Rakefile

65 lines
1.6 KiB
Ruby

require 'pathname'
require 'rake/clean'
require 'open3'
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
BINARY = 'build/bin/elna'
TESTS = FileList['tests/*.eln'].flat_map do |test|
build = Pathname.new 'build'
test_basename = Pathname.new(test).basename('')
[build + 'riscv' + test_basename].map { |path| path.sub_ext('').to_path }
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/13.2.0/',
'-L/opt/riscv/riscv32-unknown-elf/lib',
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtbegin.o',
t.source,
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.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')
end
task default: TESTS
task default: BINARY
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)
.sub_ext(extension)
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
.to_path
[test_source, BINARY]
end
def test_for_out(out_file, extension)
Pathname
.new(out_file)
.sub_ext(extension)
.to_path
end