var rename + added newline

This commit is contained in:
Noah Swerhun 2024-03-04 11:18:47 -06:00
parent c7e5ba1c55
commit cdbb2e15a2

View file

@ -43,6 +43,7 @@ fn target_generator(name: &str, config_table: &Table) -> String {
let clang = Value::String(String::from("clang"));
let blank = Value::String(String::from(""));
let aout = Value::String(String::from("a.out"));
let compiler = match config_table.get("compiler").unwrap_or(&clang) {
Value::String(s) => s,
@ -60,6 +61,10 @@ fn target_generator(name: &str, config_table: &Table) -> String {
Value::String(s) => s,
_ => panic!("fatal: {name}.linker_libs: invalid type (must be string)"),
};
let filename = match config_table.get("filename").unwrap_or(&aout) {
Value::String(s) => s,
_ => panic!("fatal: {name}.filename: invalid type (must be string)"),
};
let compiler_linker = Value::String(compiler.to_string());
let linker = match config_table.get("linker").unwrap_or(&compiler_linker) {
Value::String(s) => s,
@ -79,13 +84,14 @@ rule link_{name}
build $builddir/{name}/obj: mkdir
build $builddir/{name}/dep: mkdir
"#
));
let sources = config_table
.get("sources")
.unwrap_or_else(|| panic!("fatal: must provide sources"));
let mut source_list: Vec<String> = Vec::new();
let mut object_list: Vec<String> = Vec::new();
match sources {
Value::Array(a) => {
@ -98,7 +104,7 @@ build $builddir/{name}/dep: mkdir
ret.push_str(&format!(
"build {obj_name}: cc_{name} {s} | build.ninja || $builddir/{name}/obj $builddir/{name}/dep\n dep = {dep_name}\n"
));
source_list.push(obj_name);
object_list.push(obj_name);
}
_ => panic!(
"fatal: element in {name}.sources: invalid source type (must be a string)"
@ -109,9 +115,13 @@ build $builddir/{name}/dep: mkdir
_ => panic!("fatal: {name}.sources: invalid sources type (must be a list of strings)"),
};
ret.push_str(&format!("\nbuild $builddir/{name}/{name}: link_{name} "));
ret.push_str(&source_list.join(" "));
ret.push_str(&format!(" \nbuild {name}: phony $builddir/{name}/{name}\n"));
ret.push_str(&format!(
"\nbuild $builddir/{name}/{filename}: link_{name} "
));
ret.push_str(&object_list.join(" "));
ret.push_str(&format!(
" \nbuild {name}: phony $builddir/{name}/{filename}\n"
));
ret.push_str(&format!("# END TARGET {name}\n"));
ret