elna/Rakefile

65 lines
1.6 KiB
Ruby
Raw Normal View History

2022-06-05 15:16:04 +02:00
require 'pathname'
require 'rake/clean'
require 'open3'
DFLAGS = ['--warn-no-deprecated', '-L/usr/lib64/gcc-12']
BINARY = 'build/bin/elna'
2022-06-11 00:38:03 +02:00
TESTS = FileList['tests/*.eln'].flat_map do |test|
2022-06-05 23:43:45 +02:00
build = Pathname.new 'build'
2022-06-11 00:38:03 +02:00
test_basename = Pathname.new(test).basename('')
2022-06-05 23:43:45 +02:00
2022-06-11 00:38:03 +02:00
[build + 'riscv' + test_basename].map { |path| path.sub_ext('').to_path }
2022-06-05 23:43:45 +02:00
end
2022-06-11 00:38:03 +02:00
2022-06-05 15:16:04 +02:00
SOURCES = FileList['source/**/*.d']
directory 'build'
CLEAN.include 'build'
CLEAN.include '.dub'
2022-06-11 00:38:03 +02:00
rule(/build\/riscv\/[^\/\.]+$/ => ->(file) { test_for_out(file, '.o') }) do |t|
sh '/opt/riscv/bin/riscv32-unknown-elf-ld',
'-o', t.name,
2024-02-15 15:13:47 +01:00
'-L/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/',
2022-06-11 00:38:03 +02:00
'-L/opt/riscv/riscv32-unknown-elf/lib',
'/opt/riscv/riscv32-unknown-elf/lib/crt0.o',
2024-02-15 15:13:47 +01:00
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtbegin.o',
2022-06-11 00:38:03 +02:00
t.source,
2022-06-11 22:52:13 +02:00
'--start-group', '-lgcc', '-lc', '-lgloss', '--end-group',
2024-02-15 15:13:47 +01:00
'/opt/riscv/lib/gcc/riscv32-unknown-elf/13.2.0/crtend.o'
2022-06-05 23:43:45 +02:00
end
2022-06-11 00:38:03 +02:00
rule(/build\/riscv\/.+\.o$/ => ->(file) { test_for_object(file, '.eln') }) do |t|
2022-06-05 15:16:04 +02:00
Pathname.new(t.name).dirname.mkpath
sh BINARY, '-o', t.name, t.source
end
2022-06-05 15:16:04 +02:00
file BINARY => SOURCES do |t|
2024-02-15 15:13:47 +01:00
sh({ 'DFLAGS' => (DFLAGS * ' ') }, 'dub', 'build', '--compiler=gdc')
2022-06-05 15:16:04 +02:00
end
2024-02-18 11:26:57 +01:00
task default: TESTS
2022-06-05 15:16:04 +02:00
task default: BINARY
desc 'Run unittest blocks'
task unittest: SOURCES do |t|
sh('dub', 'test', '--compiler=gdc-12')
end
2022-06-11 00:38:03 +02:00
def test_for_object(out_file, extension)
2022-06-05 15:16:04 +02:00
test_source = Pathname
.new(out_file)
2022-06-11 00:38:03 +02:00
.sub_ext(extension)
2022-06-05 23:43:45 +02:00
.sub(/^build\/[[:alpha:]]+\//, 'tests/')
2022-06-05 15:16:04 +02:00
.to_path
[test_source, BINARY]
end
2022-06-05 23:43:45 +02:00
def test_for_out(out_file, extension)
2022-06-05 23:43:45 +02:00
Pathname
.new(out_file)
.sub_ext(extension)
2022-06-05 23:43:45 +02:00
.to_path
end