summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-08-28 22:45:42 +0200
committerEugen Wissner <belka@caraus.de>2025-08-30 01:29:00 +0200
commit627975775c941130975ce0f9dbef08c723e69794 (patch)
tree0f7f4c2c6d83420262d89ff720e6435a67410c9a /Rakefile
parente614d43ea9af078301d538fcddb19e83eed7e879 (diff)
downloadelna-627975775c941130975ce0f9dbef08c723e69794.tar.gz
Start over
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile91
1 files changed, 78 insertions, 13 deletions
diff --git a/Rakefile b/Rakefile
index 6b38038..3c9a245 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,34 +5,99 @@
require 'open3'
require 'rake/clean'
-require 'term/ansicolor'
-CLEAN.include 'build/boot'
+CROSS_GCC = '../eugenios/build/rootfs/bin/riscv32-unknown-linux-gnu-gcc'
+SYSROOT = '../eugenios/build/sysroot'
+QEMU = 'qemu-riscv32'
+STAGES = Dir.glob('boot/stage*.elna').collect { |stage| File.basename stage, '.elna' }.sort
+
+CLEAN.include 'build/boot', 'build/valid'
directory 'build/boot'
+directory 'build/valid'
+
+task default: :boot
desc 'Final stage'
-task default: ['build/boot/stage2b', 'build/boot/stage2b.s', 'boot/stage2.elna'] do |t|
- exe, previous_output, source = t.prerequisites
+task boot: "build/valid/#{STAGES.last}"
+task boot: "build/valid/#{STAGES.last}.s"
+task boot: "boot/#{STAGES.last}.elna" do |t|
+ groupped = t.prerequisites.group_by { |stage| File.extname stage }.transform_values(&:first)
+ exe = groupped['']
+ expected = groupped['.s']
+ source = groupped['.elna']
cat_arguments = ['cat', source]
compiler_arguments = [QEMU, '-L', SYSROOT, exe]
- diff_arguments = ['diff', '-Nur', '--text', previous_output, '-']
+ diff_arguments = ['diff', '-Nur', '--text', expected, '-']
Open3.pipeline(cat_arguments, compiler_arguments, diff_arguments)
end
-file 'build/boot/test.s' => ['build/boot/stage1', 'boot/test.elna'] do |t|
- source, exe = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.elna' }
+desc 'Convert previous stage language into the current stage language'
+task :convert do
+ File.open('boot/stage4.elna', 'w') do |current_stage|
+ li_value = nil
- File.open t.name, 'w' do |output|
- assemble_stage output, exe, source
+ File.readlines('boot/stage3.elna').each do |line|
+ current_stage << line
+ end
end
end
-file 'build/boot/test' => ['build/boot/test.s', 'boot/common-boot.s'] do |t|
- sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
+STAGES.each do |stage|
+ previous = stage.delete_prefix('stage').to_i.pred
+
+ file "build/valid/#{stage}" => "build/valid/#{stage}.s" do |t|
+ sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
+ end
+
+ file "build/valid/#{stage}.s" => ["build/boot/#{stage}", "boot/#{stage}.elna"] do |t|
+ exe, source = t.prerequisites
+
+ cat_arguments = ['cat', source]
+ compiler_arguments = [QEMU, '-L', SYSROOT, exe]
+ last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
+
+ IO.copy_stream last_stdout, t.name
+ end
+
+ file "build/boot/#{stage}" => "build/boot/#{stage}.s" do |t|
+ sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
+ end
+
+ file "build/boot/#{stage}.s" => ["build/valid/stage#{previous}", "boot/#{stage}.elna"] do |t|
+ exe, source = t.prerequisites
+
+ cat_arguments = ['cat', source]
+ compiler_arguments = [QEMU, '-L', SYSROOT, exe]
+ last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
+
+ IO.copy_stream last_stdout, t.name
+ end
+end
+
+#
+# Stage 1.
+#
+
+file 'build/valid/stage1' => ['build/valid', 'build/valid/stage1.s'] do |t|
+ source = t.prerequisites.select { |prerequisite| prerequisite.end_with? '.s' }
+
+ sh CROSS_GCC, '-nostdlib', '-o', t.name, *source
end
-task test: 'build/boot/test' do |t|
- sh QEMU, '-L', SYSROOT, t.prerequisites.first
+file 'build/valid/stage1.s' => ['build/boot/stage1', 'boot/stage1.s', 'build/valid'] do |t|
+ source, exe, = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.s' }
+
+ cat_arguments = ['cat', *source]
+ compiler_arguments = [QEMU, '-L', SYSROOT, *exe]
+ last_stdout, wait_threads = Open3.pipeline_r(cat_arguments, compiler_arguments)
+
+ IO.copy_stream last_stdout, t.name
+end
+
+file 'build/boot/stage1' => ['build/boot', 'boot/stage1.s'] do |t|
+ source = t.prerequisites.select { |prerequisite| prerequisite.end_with? '.s' }
+
+ sh CROSS_GCC, '-nostdlib', '-o', t.name, *source
end