Add my homegrown cross compiler scripts

This commit is contained in:
2025-05-05 23:11:52 +02:00
parent df1c0486c5
commit 3bd86e6e1c
8 changed files with 1042 additions and 640 deletions

View File

@ -7,28 +7,12 @@ require 'open3'
require 'rake/clean'
require 'term/ansicolor'
CLOBBER.include 'build'
CLEAN.include 'build/boot'
CROSS_GCC = '../riscv32-ilp32d--glibc/bin/riscv32-linux-gcc'
SYSROOT = '../riscv32-ilp32d--glibc/riscv32-buildroot-linux-gnu/sysroot'
QEMU = 'qemu-riscv32'
def assemble_stage(output, compiler, source)
arguments = [QEMU, '-L', SYSROOT, *compiler]
puts Term::ANSIColor.green(arguments * ' ')
puts
Open3.popen2(*arguments) do |qemu_in, qemu_out|
qemu_in.write File.read(*source)
qemu_in.close
IO.copy_stream qemu_out, output
qemu_out.close
end
end
directory 'build/boot'
desc 'Final stage'
task default: ['build/stage2b', 'build/stage2b.s', 'boot/stage2.elna'] do |t|
task default: ['build/boot/stage2b', 'build/boot/stage2b.s', 'boot/stage2.elna'] do |t|
exe, previous_output, source = t.prerequisites
cat_arguments = ['cat', source]
@ -36,40 +20,3 @@ task default: ['build/stage2b', 'build/stage2b.s', 'boot/stage2.elna'] do |t|
diff_arguments = ['diff', '-Nur', '--text', previous_output, '-']
Open3.pipeline(cat_arguments, compiler_arguments, diff_arguments)
end
directory 'build'
Dir.glob('boot/*.s').each do |assembly_source|
target_object = Pathname.new('build') + Pathname.new(assembly_source).basename.sub_ext('.o')
file target_object.to_s => [assembly_source, 'build'] do |t|
sh CROSS_GCC, '-c', '-o', t.name, assembly_source
end
end
desc 'Initial stage'
file 'build/stage1' => ['build/tokenizer.o', 'build/stage1.o', 'build/common-boot.o'] do |t|
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
end
file 'build/stage2a.s' => ['build/stage1', 'boot/stage2.elna'] do |t|
source, exe = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.elna' }
File.open t.name, 'w' do |output|
assemble_stage output, exe, source
end
end
['build/stage2a', 'build/stage2b'].each do |exe|
file exe => [exe.ext('.s'), 'build/common-boot.o'] do |t|
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
end
end
file 'build/stage2b.s' => ['build/stage2a', 'boot/stage2.elna'] do |t|
source, exe = t.prerequisites.partition { |prerequisite| prerequisite.end_with? '.elna' }
File.open t.name, 'w' do |output|
assemble_stage output, exe, source
end
end