summaryrefslogtreecommitdiff
path: root/rakelib
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-02-02 12:10:40 +0100
committerEugen Wissner <belka@caraus.de>2026-02-04 18:17:47 +0100
commit8e89d33c214e3dad03a86057c2c45a0dc7608ad7 (patch)
tree6d6b52362c6e04a8466a3f393093157f49162588 /rakelib
parent39197fe88ab23bf452e00569ef36b556b787a421 (diff)
downloadelna-8e89d33c214e3dad03a86057c2c45a0dc7608ad7.tar.gz
Split up the rakefile
Diffstat (limited to 'rakelib')
-rw-r--r--rakelib/ninja.rake75
1 files changed, 75 insertions, 0 deletions
diff --git a/rakelib/ninja.rake b/rakelib/ninja.rake
new file mode 100644
index 0000000..702f9b5
--- /dev/null
+++ b/rakelib/ninja.rake
@@ -0,0 +1,75 @@
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/.
+# frozen_string_literal: true
+
+require 'rake/clean'
+
+CLEAN.include 'build/boot', 'build/valid'
+
+file 'build/build.ninja' => ['build'] do |t|
+ File.open t.name, 'w' do |f|
+ f << <<~NINJA
+ builddir = build
+ cflags = -fpie -g
+
+ rule cc
+ command = gcc $cflags -nostdlib -o $out $in
+
+ rule as
+ command = gcc $cflags -c -o $out $in
+
+ rule link1
+ command = ld -o $out $in
+
+ rule link2
+ command = ld -o $out --dynamic-linker /lib32/ld-linux-riscv32-ilp32d.so.1 /usr/lib/crt1.o /usr/lib/crti.o -lc $in /usr/lib/crtn.o
+
+ rule bootstrap
+ command = $bootstrap < \$in > \$out
+ NINJA
+ f << <<~NINJA
+
+ build build/boot/stage1/cl: cc boot/stage1.s
+ build build/valid/stage1/cl.s: bootstrap boot/stage1.s | build/boot/stage1/cl
+ bootstrap = build/boot/stage1/cl
+
+ build build/valid/stage1/cl.o: as build/valid/stage1/cl.s
+ build build/valid/stage1/cl: link1 build/valid/stage1/cl.o
+ NINJA
+ STAGES.each do |stage|
+ stage_number = stage.delete_prefix('stage').to_i
+
+ arguments_path = Pathname.new('boot') + stage + 'linker.arg'
+ if arguments_path.exist?
+ link = 'link2'
+ else
+ link = 'link1'
+ end
+ boot_stage = "build/boot/stage#{stage_number}"
+ valid_stage = "build/valid/stage#{stage_number}"
+ f << <<~NINJA
+
+ build #{boot_stage}/cl.s: bootstrap boot/stage#{stage_number}/cl.elna | build/valid/stage#{stage_number.pred}/cl
+ bootstrap = build/valid/stage#{stage_number.pred}/cl
+
+ build #{boot_stage}/cl.o: as #{boot_stage}/cl.s
+ build #{boot_stage}/cl: #{link} #{boot_stage}/cl.o
+
+ build #{valid_stage}/cl.s: bootstrap boot/stage#{stage_number}/cl.elna | #{boot_stage}/cl
+ bootstrap = build/boot/stage#{stage_number}/cl
+
+ build #{valid_stage}/cl.o: as #{valid_stage}/cl.s
+ build #{valid_stage}/cl: #{link} #{valid_stage}/cl.o
+ NINJA
+ end
+ f << <<~NINJA
+
+ default build/valid/#{STAGES.last}/cl
+ NINJA
+ end
+end
+
+file "build/valid/#{STAGES.last}/cl" => 'build/build.ninja' do |t|
+ sh 'ninja', '-f', t.prerequisites.first
+end