[bonnibel] Allow modules to list ld scripts in definition
Previously, to add a custom linker script, a module would need to modify its variables after the fact to add to ldflags. Now module constructors take a new keyword `ld_script` and handle the ldflags and dependencies properly.
This commit is contained in:
@@ -7,10 +7,18 @@ def resolve(path):
|
|||||||
return str(Path(path).resolve())
|
return str(Path(path).resolve())
|
||||||
|
|
||||||
class BuildOptions:
|
class BuildOptions:
|
||||||
def __init__(self, includes=tuple(), libs=tuple(), order_only=tuple()):
|
def __init__(self, includes=tuple(), libs=tuple(), order_only=tuple(), ld_script=None):
|
||||||
self.includes = list(includes)
|
self.includes = list(includes)
|
||||||
self.libs = list(libs)
|
self.libs = list(libs)
|
||||||
self.order_only = list(order_only)
|
self.order_only = list(order_only)
|
||||||
|
self.ld_script = ld_script and str(ld_script)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def implicit(self):
|
||||||
|
if self.ld_script is not None:
|
||||||
|
return self.libs + [self.ld_script]
|
||||||
|
else:
|
||||||
|
return self.libs
|
||||||
|
|
||||||
|
|
||||||
class Module:
|
class Module:
|
||||||
@@ -28,6 +36,7 @@ class Module:
|
|||||||
"default": (bool, False),
|
"default": (bool, False),
|
||||||
"description": (str, None),
|
"description": (str, None),
|
||||||
"no_libc": (bool, False),
|
"no_libc": (bool, False),
|
||||||
|
"ld_script": (str, None),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, modfile, root, **kwargs):
|
def __init__(self, name, modfile, root, **kwargs):
|
||||||
@@ -176,6 +185,7 @@ class Module:
|
|||||||
|
|
||||||
modopts = BuildOptions(
|
modopts = BuildOptions(
|
||||||
includes = [self.root, "${module_dir}"],
|
includes = [self.root, "${module_dir}"],
|
||||||
|
ld_script = self.ld_script and self.root / self.ld_script,
|
||||||
)
|
)
|
||||||
if self.public_headers:
|
if self.public_headers:
|
||||||
modopts.includes += [f"${{build_root}}/include/{self.name}"]
|
modopts.includes += [f"${{build_root}}/include/{self.name}"]
|
||||||
@@ -214,6 +224,9 @@ class Module:
|
|||||||
if modopts.libs:
|
if modopts.libs:
|
||||||
build.variable("libs", ["${libs}"] + modopts.libs)
|
build.variable("libs", ["${libs}"] + modopts.libs)
|
||||||
|
|
||||||
|
if modopts.ld_script:
|
||||||
|
build.variable("ldflags", ["${ldflags}"] + ["-T", modopts.ld_script])
|
||||||
|
|
||||||
header_deps = []
|
header_deps = []
|
||||||
|
|
||||||
inputs = []
|
inputs = []
|
||||||
@@ -237,16 +250,16 @@ class Module:
|
|||||||
gather_phony(build, header_deps, target_rel, add_headers=True)
|
gather_phony(build, header_deps, target_rel, add_headers=True)
|
||||||
|
|
||||||
output = target_rel(self.output)
|
output = target_rel(self.output)
|
||||||
dump = output + ".dump"
|
|
||||||
build.newline()
|
build.newline()
|
||||||
build.build(
|
build.build(
|
||||||
rule = self.kind,
|
rule = self.kind,
|
||||||
outputs = output,
|
outputs = output,
|
||||||
inputs = inputs,
|
inputs = inputs,
|
||||||
implicit = modopts.libs,
|
implicit = modopts.implicit,
|
||||||
order_only = modopts.order_only,
|
order_only = modopts.order_only,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
dump = output + ".dump"
|
||||||
build.newline()
|
build.newline()
|
||||||
build.build(
|
build.build(
|
||||||
rule = "dump",
|
rule = "dump",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ kernel = module("kernel",
|
|||||||
targets = [ "kernel" ],
|
targets = [ "kernel" ],
|
||||||
description = "jsix kernel",
|
description = "jsix kernel",
|
||||||
deps = [ "util", "cpu", "bootproto", "j6" ],
|
deps = [ "util", "cpu", "bootproto", "j6" ],
|
||||||
|
ld_script = "kernel.ld",
|
||||||
sources = [
|
sources = [
|
||||||
"apic.cpp",
|
"apic.cpp",
|
||||||
"assert.cpp",
|
"assert.cpp",
|
||||||
@@ -83,5 +84,3 @@ kernel.add_depends([
|
|||||||
"syscalls.inc.cog",
|
"syscalls.inc.cog",
|
||||||
"syscall_verify.cpp.cog",
|
"syscall_verify.cpp.cog",
|
||||||
], definitions)
|
], definitions)
|
||||||
|
|
||||||
kernel.variables['ldflags'] = ["${ldflags}", "-T", "${source_root}/src/kernel/kernel.ld"]
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ panic = module("panic.serial",
|
|||||||
deps = [ "util", "elf", "kernel" ],
|
deps = [ "util", "elf", "kernel" ],
|
||||||
includes = [ ".." ],
|
includes = [ ".." ],
|
||||||
description = "Serial panic handler",
|
description = "Serial panic handler",
|
||||||
|
ld_script = "panic.serial.ld",
|
||||||
sources = [
|
sources = [
|
||||||
"display.cpp",
|
"display.cpp",
|
||||||
"entry.s",
|
"entry.s",
|
||||||
@@ -14,5 +15,3 @@ panic = module("panic.serial",
|
|||||||
"symbol_table.cpp",
|
"symbol_table.cpp",
|
||||||
"../printf/printf.c",
|
"../printf/printf.c",
|
||||||
])
|
])
|
||||||
|
|
||||||
panic.variables['ldflags'] = ["${ldflags}", "-T", "${source_root}/src/kernel/panic.serial/panic.serial.ld"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user