elna/Rakefile

42 lines
1.1 KiB
Ruby

require 'open3'
require 'rake/clean'
CLOBBER.include 'build'
CROSS_GCC = '../riscv32-ilp32d--glibc/bin/riscv32-linux-gcc'
SYSROOT = '../riscv32-ilp32d--glibc/riscv32-buildroot-linux-gnu/sysroot'
QEMU = 'qemu-riscv32'
desc 'Final stage'
task default: 'build/stage2'
directory 'build'
desc 'Initial stage'
file 'build/stage1' => ['boot/echo-boot.s', 'boot/common-boot.s', 'build'] do |t|
assembler = t.prerequisites.filter { |prerequisite| prerequisite.end_with? '.s' }
sh CROSS_GCC, '-nostdlib', '-o', t.name, *assembler
end
file 'build/stage2.s' => ['build/stage1', 'boot/stage2.elna'] do |t|
assembler, exe = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.elna' }
arguments = [QEMU, '-L', SYSROOT, *exe]
puts(arguments * ' ')
puts
Open3.popen2(*arguments) do |qemu_in, qemu_out|
qemu_in.write File.read(*assembler)
qemu_in.close
File.open t.name, 'w' do |output|
IO.copy_stream qemu_out, output
end
qemu_out.close
end
end
file 'build/stage2' => ['build/stage2.s', 'boot/common-boot.s'] do |t|
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
end