SLToolchainEmitter.sleela
lib/operating-system/os-creator/SLToolchainEmitter.sleela · 134 line(s) · sleela
<< lib/operating-system/os-creator/SLToolchainEmitter.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLToolchainEmitter — the OS Creator(TM) emitter for the
build tooling placed into /os-development. Given an SLOSModel it produces a
top-level Makefile that compiles every emitted piece (firmware, loaders,
OS) with cc/c++ and then invokes the ISO recipe, plus a build.sh (POSIX,
for Linux/macOS shapes) and a build.ps1 (PowerShell, for the Windows shape)
that drive the Makefile. The emitted toolchain turns the written C/C++ into
the OS and the bootable ISO.
This is the "place the compilation tools (make, build) into /os-development"
requirement: running them builds the OS top-down from the generated sources.
Output is String concatenation on OP_ADD.
Family: operating-system. OS Creator(TM) emitter; consumes SLOSModel. >>
#sleela 2.5
material;
class SLToolchainEmitter {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10941;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-10";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
String intToStr(int v) { return "" + v; }
< The top-level Makefile that builds all pieces and authors the ISO. >
String emitMakefile(SLOSModel m, boolean withDesktop) {
String arch = m.architectures().primaryArch().arch();
String mk = "# Makefile - generated by OS Creator(TM) for " + m.identity() + "\n";
mk = mk + "CC ?= cc\nCXX ?= c++\nARCH ?= " + arch + "\n";
mk = mk + "BUILD = build\n\n";
mk = mk + ".PHONY: all pieces os iso clean\n\n";
mk = mk + "all: iso\n\n";
< One object per piece. >
mk = mk + "PIECES = \\\n";
mk = mk + " firmware/uefi/uefi \\\n";
mk = mk + " firmware/bios/bios \\\n";
mk = mk + " boot/loader/bootloader \\\n";
mk = mk + " boot/kernel-loader/kernel_loader \\\n";
mk = mk + " kernel/driver-loader/driver_loader \\\n";
mk = mk + " userspace/os-loader/os_loader";
if (withDesktop) { mk = mk + " \\\n desktop/gui-loader/gui_loader"; }
mk = mk + "\n\n";
mk = mk + "pieces: $(BUILD)\n";
mk = mk + "\t@for p in $(PIECES); do \\\n";
mk = mk + "\t echo \"CC $$p.c\"; $(CC) -c $$p.c -o $(BUILD)/$$(echo $$p | tr / _).o; \\\n";
mk = mk + "\t echo \"CXX $$p.cpp\"; $(CXX) -c $$p.cpp -o $(BUILD)/$$(echo $$p | tr / _)_cpp.o; \\\n";
mk = mk + "\tdone\n\n";
mk = mk + "os: pieces\n";
mk = mk + "\t$(CC) -c os/os_boot.c -o $(BUILD)/os_boot.o\n";
mk = mk + "\t$(CXX) -c os/os_image.cpp -o $(BUILD)/os_image.o\n\n";
mk = mk + "iso: os\n";
mk = mk + "\tsh tools/gen-iso.sh\n\n";
mk = mk + "$(BUILD):\n\tmkdir -p $(BUILD)\n\n";
mk = mk + "clean:\n\trm -rf $(BUILD)\n";
return mk;
}
< POSIX build driver (Linux / macOS shapes). >
String emitBuildSh(SLOSModel m) {
String s = "#!/bin/sh\n# build.sh - generated by OS Creator(TM) for " + m.name() + "\n";
s = s + "set -eu\n";
s = s + "cd \"$(dirname \"$0\")\"\n";
s = s + "echo \"Building " + m.identity() + "\"\n";
s = s + "make all\n";
s = s + "echo \"ISO ready: " + isoName(m) + "\"\n";
return s;
}
< PowerShell build driver (Windows shape). >
String emitBuildPs1(SLOSModel m) {
String s = "#requires -Version 5\n# build.ps1 - generated by OS Creator(TM) for " + m.name() + "\n";
s = s + "Set-Location -Path $PSScriptRoot\n";
s = s + "Write-Host \"Building " + m.identity() + "\"\n";
s = s + "make all\n";
s = s + "Write-Host \"ISO ready: " + isoName(m) + "\"\n";
return s;
}
< The global os.conf config carrying the model identity. >
String emitOsConf(SLOSModel m) {
String c = "# os.conf - generated by OS Creator(TM)\n";
c = c + "name = " + m.name() + "\n";
c = c + "version = " + m.osVersion() + "\n";
c = c + "edition = " + m.osEdition() + "\n";
c = c + "shape = " + m.osShape().name() + "\n";
c = c + "arch = " + m.architectures().primaryArch().arch() + "\n";
c = c + "kernel = " + m.kernelSpec().name() + " " + m.kernelSpec().kernelVersion() + "\n";
c = c + "rootfs = " + m.layout().fsFormat() + "\n";
c = c + "init = " + m.serviceSet().serviceManager() + "\n";
return c;
}
String isoName(SLOSModel m) {
return m.name() + "-" + m.osVersion() + "-" + m.architectures().primaryArch().arch() + ".iso";
}
}