Update to rscons 3.0.0

This commit is contained in:
Josh Holtrop 2022-02-28 13:40:08 -05:00
parent c6ae200a54
commit 56c3be9207
10 changed files with 235 additions and 230 deletions

6
.gitignore vendored
View File

@ -5,9 +5,5 @@
*.map *.map
*.bin *.bin
.rscons* .rscons*
/i686-elf-gcc/build*/ /i686-elf-gcc/
/i686-elf-gcc/*.xz
/i686-elf-gcc/binutils-*/
/i686-elf-gcc/gcc-*/
/i686-elf-gcc/i686-elf-gcc/
/build/ /build/

View File

@ -1,15 +0,0 @@
.PHONY: all
all:
./rscons build
.PHONY: run-efi
run-efi: all
qemu-system-x86_64 -bios OVMF.fd -hda build/hos-efi.img
.PHONY: run
run: all
qemu-system-x86_64 -hda build/hos.img
.PHONY: clean
clean:
./rscons clean

View File

@ -1,7 +1,7 @@
path_prepend "i686-elf-gcc/i686-elf-gcc/bin" path_prepend "i686-elf-gcc/bin"
configure do configure do
rscons "i686-elf-gcc" rscons "i686-elf-gcc.rb", "-b", "#{build_dir}/i686-elf-gcc"
check_c_compiler "i686-elf-gcc" check_c_compiler "i686-elf-gcc"
check_program "genext2fs" check_program "genext2fs"
check_program "grub-mkstandalone" check_program "grub-mkstandalone"
@ -10,17 +10,16 @@ configure do
check_cfg package: "freetype2", on_fail: "Install libfreetype-dev", use: "freetype" check_cfg package: "freetype2", on_fail: "Install libfreetype-dev", use: "freetype"
end end
build do require "tmpdir"
require "tmpdir"
# EFI (w/ GRUB) partition size (MiB) # EFI (w/ GRUB) partition size (MiB)
EFI_PART_SIZE = 8 EFI_PART_SIZE = 8
# HOS partition size (MiB) # HOS partition size (MiB)
HOS_PART_SIZE = 4 HOS_PART_SIZE = 4
# Kernel default font size # Kernel default font size
KFONT_SIZE = 15 KFONT_SIZE = 15
class BiosImage < Builder class BiosImage < Builder
def run(options) def run(options)
unless @cache.up_to_date?(@target, nil, @sources, @env) unless @cache.up_to_date?(@target, nil, @sources, @env)
print_run_message("Generating BIOS boot image #{@target}", nil) print_run_message("Generating BIOS boot image #{@target}", nil)
@ -32,8 +31,8 @@ build do
set default="0" set default="0"
set timeout=1 set timeout=1
menuentry "HOS" { menuentry "HOS" {
insmod multiboot2 insmod multiboot2
multiboot2 /hos.elf multiboot2 /hos.elf
} }
EOF EOF
end end
@ -47,9 +46,9 @@ EOF
end end
true true
end end
end end
class EfiImage < Builder class EfiImage < Builder
def run(options) def run(options)
unless @cache.up_to_date?(@target, nil, @sources, @env) unless @cache.up_to_date?(@target, nil, @sources, @env)
print_run_message("Generating EFI boot image #{@target}", nil) print_run_message("Generating EFI boot image #{@target}", nil)
@ -78,10 +77,10 @@ EOF
set default="0" set default="0"
set timeout=1 set timeout=1
menuentry "HOS" { menuentry "HOS" {
insmod part_gpt insmod part_gpt
insmod multiboot2 insmod multiboot2
set root=(hd0,gpt2) set root=(hd0,gpt2)
multiboot2 /hos.elf multiboot2 /hos.elf
} }
EOF EOF
end end
@ -98,21 +97,22 @@ EOF
end end
true true
end end
end end
class FontGen < Builder class FontGen < Builder
def run(options) def run(options)
if @command if @command
finalize_command finalize_command
else else
@sources += ["build/fontgen"] fontgen = @vars["fontgen"]
command = %W[build/fontgen #{@sources.first} #{KFONT_SIZE} #{@target}] @sources += [fontgen]
command = %W[#{fontgen} #{@sources.first} #{KFONT_SIZE} #{@target}]
standard_command("FontGen <target>#{@target}<reset>", command, {}) standard_command("FontGen <target>#{@target}<reset>", command, {})
end end
end end
end end
class Size < Builder class Size < Builder
def run(options) def run(options)
if @command if @command
finalize_command finalize_command
@ -123,16 +123,16 @@ EOF
standard_command("Size <target>#{@target}<reset>", command, stdout: @target) standard_command("Size <target>#{@target}<reset>", command, stdout: @target)
end end
end end
end end
# FontGen Environment # FontGen Environment
Environment.new(use: "freetype") do |env| fontgen_env = env "fontgen", use: "freetype" do |env|
env["CC"] = "gcc" env["CC"] = "gcc"
env.Program("build/fontgen", glob("fontgen/**/*.c")) env.Program("^/fontgen.bin", glob("fontgen/**/*.c"))
end end
# Kernel Environment # Kernel Environment
Environment.new do |env| kernel_env = env "kernel" do |env|
env.add_builder(EfiImage) env.add_builder(EfiImage)
env.add_builder(BiosImage) env.add_builder(BiosImage)
env.add_builder(FontGen) env.add_builder(FontGen)
@ -143,13 +143,24 @@ EOF
env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld] env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld]
env["LDFLAGS"] += %W[-Wl,-Map,${_TARGET}.map] env["LDFLAGS"] += %W[-Wl,-Map,${_TARGET}.map]
env["LIBS"] += %w[gcc] env["LIBS"] += %w[gcc]
env.FontGen("^/kfont/kfont.c", "font/Hack-Regular.ttf") env.FontGen("^/kfont/kfont.c", "font/Hack-Regular.ttf",
"fontgen" => fontgen_env.expand("^/fontgen.bin"))
env.barrier
env["CPPPATH"] += ["#{env.build_root}/kfont"] env["CPPPATH"] += ["#{env.build_root}/kfont"]
env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/kfont/kfont.c"]) env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/kfont/kfont.c"])
env.depends("#{env.build_root}/hos.elf", "src/link.ld") env.depends("#{env.build_root}/hos.elf", "src/link.ld")
env.Disassemble("^/hos.elf.txt", "^/hos.elf") env.Disassemble("^/hos.elf.txt", "^/hos.elf")
env.Size("^/hos.elf.size", "^/hos.elf") env.Size("^/hos.elf.size", "^/hos.elf")
env.EfiImage("build/hos-efi.img", %w[^/hos.elf]) env.EfiImage("^/hos-efi.img", %w[^/hos.elf])
env.BiosImage("build/hos.img", %w[^/hos.elf]) env.BiosImage("^/hos.img", %w[^/hos.elf])
end end
task "run", desc: "Run HOS in QEMU" do
img = kernel_env.expand("^/hos.img")
sh %W[qemu-system-x86_64 -hda #{img}]
end
task "run-efi", desc: "Run HOS EFI in QEMU" do
img = kernel_env.expand("^/hos-efi.img")
sh %W[qemu-system-x86_64 -bios OVMF.fd -hda #{img}]
end end

2
configure vendored
View File

@ -1,2 +0,0 @@
#!/bin/sh
exec ./rscons configure "$@"

75
i686-elf-gcc.rb Normal file
View File

@ -0,0 +1,75 @@
binutils_version = "2.35"
binutils_checksum = "1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85"
gcc_version = "10.2.0"
gcc_checksum = "b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"
install_path = File.expand_path("i686-elf-gcc")
target = "i686-elf"
path_prepend "#{install_path}/bin"
configure do
check_c_compiler "gcc"
check_program "make"
check_program "bison"
check_program "flex"
check_program "texi2any", on_fail: "Install the texinfo package"
check_program "wget"
check_lib "gmp", on_fail: "Install the libgmp-dev package"
check_lib "mpc", on_fail: "Install the libmpc-dev package"
check_lib "mpfr", on_fail: "Install the libmpfr-dev package"
end
default do
unless Dir.exist?(install_path)
# Download archives.
download "https://ftp.gnu.org/gnu/binutils/binutils-#{binutils_version}.tar.xz",
"#{build_dir}/binutils-#{binutils_version}.tar.xz",
sha256sum: binutils_checksum
download "https://ftp.gnu.org/gnu/gcc/gcc-#{gcc_version}/gcc-#{gcc_version}.tar.xz",
"#{build_dir}/gcc-#{gcc_version}.tar.xz",
sha256sum: gcc_checksum
# Extract archives.
sh "tar", "xJf", "binutils-#{binutils_version}.tar.xz",
chdir: build_dir
sh "tar", "xJf", "gcc-#{gcc_version}.tar.xz",
chdir: build_dir
# Build binutils.
rm_rf "#{build_dir}/build-binutils"
mkdir_p "#{build_dir}/build-binutils"
cd "#{build_dir}/build-binutils" do
sh %W[../binutils-#{binutils_version}/configure
--target=#{target} --prefix=#{install_path} --with-sysroot --disable-nls
--disable-werror]
sh "make"
sh "make install"
end
# Build gcc.
rm_rf "#{build_dir}/build-gcc"
mkdir_p "#{build_dir}/build-gcc"
cd "#{build_dir}/build-gcc" do
sh %W[../gcc-#{gcc_version}/configure
--target=#{target} --prefix=#{install_path} --disable-nls
--enable-languages=c,c++ --without-headers]
sh "make all-gcc"
sh "make all-target-libgcc"
sh "make install-gcc"
sh "make install-target-libgcc"
end
# Remove archives and build directories if everything succeeded.
rm_f "#{build_dir}/binutils-#{binutils_version}.tar.xz"
rm_rf "#{build_dir}/binutils-#{binutils_version}"
rm_rf "#{build_dir}/build-binutils"
rm_f "#{build_dir}/gcc-#{gcc_version}.tar.xz"
rm_rf "#{build_dir}/gcc-#{gcc_version}"
rm_rf "#{build_dir}/build-gcc"
end
end
distclean do
rm_rf install_path
end

View File

@ -1,17 +0,0 @@
configure do
check_c_compiler "gcc"
check_program "make"
check_program "bison"
check_program "flex"
check_program "texi2any", on_fail: "Install the texinfo package"
check_program "wget"
check_lib "gmp", on_fail: "Install the libgmp-dev package"
check_lib "mpc", on_fail: "Install the libmpc-dev package"
check_lib "mpfr", on_fail: "Install the libmpfr-dev package"
end
build do
unless File.exist?("i686-elf-gcc")
system("./build.sh")
end
end

View File

@ -1,64 +0,0 @@
#!/bin/bash
BINUTILS_VERSION="2.35"
BINUTILS_CHECKSUM="1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85"
GCC_VERSION="10.2.0"
GCC_CHECKSUM="b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"
if [ ! -e binutils-${BINUTILS_VERSION}.tar.xz ]; then
wget -O binutils-${BINUTILS_VERSION}.tar.xz https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz
fi
if [[ ! `sha256sum binutils-${BINUTILS_VERSION}.tar.xz` =~ $BINUTILS_CHECKSUM ]]; then
echo "Invalid binutils-${BINUTILS_VERSION}.tar.xz checksum"
exit
fi
if [ ! -d binutils-${BINUTILS_VERSION} ]; then
tar xJf binutils-${BINUTILS_VERSION}.tar.xz
fi
if [ ! -e gcc-${GCC_VERSION}.tar.xz ]; then
wget -O gcc-${GCC_VERSION}.tar.xz https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz
fi
if [[ ! `sha256sum gcc-${GCC_VERSION}.tar.xz` =~ $GCC_CHECKSUM ]]; then
echo "Invalid gcc-${GCC_VERSION}.tar.xz checksum"
exit
fi
if [ ! -d gcc-${GCC_VERSION} ]; then
tar xJf gcc-${GCC_VERSION}.tar.xz
fi
export PREFIX="$PWD/i686-elf-gcc"
export TARGET="i686-elf"
export PATH="$PREFIX/bin:$PATH"
function build_binutils()
{
rm -rf build-binutils
mkdir -p build-binutils
(
cd build-binutils
../binutils-${BINUTILS_VERSION}/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror && \
make && \
make install
)
}
function build_gcc()
{
rm -rf build-gcc
mkdir -p build-gcc
(
cd build-gcc
../gcc-${GCC_VERSION}/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers && \
make all-gcc && \
make all-target-libgcc && \
make install-gcc && \
make install-target-libgcc
)
}
build_binutils && build_gcc

View File

@ -1,2 +0,0 @@
#!/bin/sh
rm -rf build build-* binutils* gcc-*

View File

@ -1,2 +0,0 @@
#!/bin/sh
exec ../rscons configure

31
rscons

File diff suppressed because one or more lines are too long