fixed directory structure and changed build message

This commit is contained in:
Noah Swerhun 2024-03-04 11:00:22 -06:00
parent 6eb94ff3d8
commit 676c1d91a8

View file

@ -39,7 +39,7 @@ fn print_table(table: &Table, depth: usize) {
} }
fn target_generator(name: &str, config_table: &Table) -> String { fn target_generator(name: &str, config_table: &Table) -> String {
let mut ret = String::from(""); let mut ret = String::from("\n");
let clang = Value::String(String::from("clang")); let clang = Value::String(String::from("clang"));
let blank = Value::String(String::from("")); let blank = Value::String(String::from(""));
@ -68,20 +68,17 @@ fn target_generator(name: &str, config_table: &Table) -> String {
ret.push_str(&format!( ret.push_str(&format!(
r#"# BEGIN TARGET {name} r#"# BEGIN TARGET {name}
cflags_{name} = {compiler_flags}
linker_flags_{name} = {linker_flags}
linker_libs_{name} = {linker_libs}
rule cc_{name} rule cc_{name}
deps = gcc deps = gcc
depfile = $out.d depfile = $dep
command = {compiler} $cflags_{name} -MD -MF $out.d -o $out -c $in command = {compiler} {compiler_flags} -MD -MF $dep -o $out -c $in
description = Building [{name}] object $out description = Building object $out
rule link_{name} rule link_{name}
command = {linker} $linker_flags_{name} -o $out $in $linker_libs_{name} command = {linker} {linker_flags} -o $out $in {linker_libs}
description = Linking [{name}] $out description = Linking $out
build $builddir/{name}: mkdir build $builddir/{name}/obj: mkdir
build $builddir/{name}/dep: mkdir
"# "#
)); ));
let sources = config_table let sources = config_table
@ -95,9 +92,11 @@ build $builddir/{name}: mkdir
for elem in a { for elem in a {
match elem { match elem {
Value::String(s) => { Value::String(s) => {
let obj_name = format!("$builddir/{name}/{s}.o"); let s = s.replace("/", "-");
let obj_name = format!("$builddir/{name}/obj/{s}.o");
let dep_name = format!("$builddir/{name}/dep/{s}.o.d");
ret.push_str(&format!( ret.push_str(&format!(
"build {obj_name}: cc_{name} {s} | build.ninja || $builddir/{name}\n" "build {obj_name}: cc_{name} {s} | build.ninja || $builddir/{name}/obj $builddir/{name}/dep\n dep = {dep_name}\n"
)); ));
source_list.push(obj_name); source_list.push(obj_name);
} }
@ -113,7 +112,7 @@ build $builddir/{name}: mkdir
ret.push_str(&format!("\nbuild $builddir/{name}/{name}: link_{name} ")); ret.push_str(&format!("\nbuild $builddir/{name}/{name}: link_{name} "));
ret.push_str(&source_list.join(" ")); ret.push_str(&source_list.join(" "));
ret.push_str(&format!(" \nbuild {name}: phony $builddir/{name}/{name}\n")); ret.push_str(&format!(" \nbuild {name}: phony $builddir/{name}/{name}\n"));
ret.push_str(&format!("# END TARGET {name}\n\n")); ret.push_str(&format!("# END TARGET {name}\n"));
ret ret
} }
@ -140,7 +139,6 @@ rule regen
build build.ninja: regen ngen.toml build build.ninja: regen ngen.toml
pool = console pool = console
"#, "#,
); );