summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile41
1 files changed, 41 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..368abfa
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,41 @@
+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