added object suffix option

This commit is contained in:
Noah Swerhun 2024-04-03 17:17:50 -05:00
parent ba48d09072
commit e79e1a1e06
5 changed files with 21 additions and 10 deletions

View file

@ -370,7 +370,7 @@ sources = [
] ]
``` ```
An option `opts.comple_cmd_fmt` also exists. Its default is `{compiler} An option `opts.compile_cmd_fmt` also exists. Its default is `{compiler}
{compiler_flags} -MD -MF {depfile} -o {object} -c {source}`. Note that if you {compiler_flags} -MD -MF {depfile} -o {object} -c {source}`. Note that if you
remove the `-MD -MF {depfile}` component, ninja will have no way to discover remove the `-MD -MF {depfile}` component, ninja will have no way to discover
what header files your source file depends on. what header files your source file depends on.

View file

@ -125,8 +125,14 @@ build $builddir/{name}/dep: mkdir
for source in &target.sources { for source in &target.sources {
let new_file = source.replace('/', "-"); let new_file = source.replace('/', "-");
let obj_name = format!("$builddir/{}/obj/{}.o", name, new_file); let obj_name = format!(
let dep_name = format!("$builddir/{}/dep/{}.o.d", name, new_file); "$builddir/{}/obj/{}{}",
name, new_file, target.opts.object_suffix
);
let dep_name = format!(
"$builddir/{}/dep/{}{}.d",
name, new_file, target.opts.object_suffix
);
ret.push_str(&format!( ret.push_str(&format!(
"build {}: cc_{} {}\n dep = {}\n", "build {}: cc_{} {}\n dep = {}\n",
obj_name, name, source, dep_name obj_name, name, source, dep_name

View file

@ -23,6 +23,7 @@ pub struct DeserTargetOptions {
pub default: Option<bool>, pub default: Option<bool>,
pub compile_cmd_fmt: Option<String>, pub compile_cmd_fmt: Option<String>,
pub link_cmd_fmt: Option<String>, pub link_cmd_fmt: Option<String>,
pub object_suffix: Option<String>,
} }
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]

View file

@ -24,13 +24,13 @@ impl<'a> Target<'a> {
ret.opts = opts.clone(); ret.opts = opts.clone();
if let Some(parent) = parent { if let Some(parent) = parent {
if let None = deser.outfile { if deser.outfile.is_none() {
ret.outfile = parent.outfile; ret.outfile = parent.outfile;
} }
if let None = deser.compiler { if deser.compiler.is_none() {
ret.compiler = parent.compiler; ret.compiler = parent.compiler;
} }
if let None = deser.linker { if deser.linker.is_none() {
ret.linker = parent.linker; ret.linker = parent.linker;
} }
for string in parent.compiler_flags.clone() { for string in parent.compiler_flags.clone() {
@ -60,11 +60,9 @@ impl<'a> Target<'a> {
} }
if let Some(v) = &deser.linker { if let Some(v) = &deser.linker {
ret.linker = v; ret.linker = v;
} else { } else if let Some(v) = &deser.compiler {
if let Some(v) = &deser.compiler {
ret.linker = v; ret.linker = v;
} }
}
if let Some(v) = &deser.linker_flags { if let Some(v) = &deser.linker_flags {
for string in v { for string in v {
ret.linker_flags.push(string); ret.linker_flags.push(string);

View file

@ -8,6 +8,7 @@ pub struct TargetOptions<'a> {
pub depend_on: Vec<&'a str>, pub depend_on: Vec<&'a str>,
pub compile_cmd_fmt: &'a str, pub compile_cmd_fmt: &'a str,
pub link_cmd_fmt: &'a str, pub link_cmd_fmt: &'a str,
pub object_suffix: &'a str,
} }
impl<'a> From<&'a DeserTargetOptions> for TargetOptions<'a> { impl<'a> From<&'a DeserTargetOptions> for TargetOptions<'a> {
@ -40,6 +41,10 @@ impl<'a> From<&'a DeserTargetOptions> for TargetOptions<'a> {
ret.link_cmd_fmt = v; ret.link_cmd_fmt = v;
} }
if let Some(v) = &value.object_suffix {
ret.object_suffix = v;
}
ret ret
} }
} }
@ -54,6 +59,7 @@ impl<'a> TargetOptions<'a> {
compile_cmd_fmt: compile_cmd_fmt:
"{compiler} {compiler_flags} -MD -MF {depfile} -o {object} -c {source}", "{compiler} {compiler_flags} -MD -MF {depfile} -o {object} -c {source}",
link_cmd_fmt: "{linker} {linker_flags} -o {outfile} {objects} {linker_libs}", link_cmd_fmt: "{linker} {linker_flags} -o {outfile} {objects} {linker_libs}",
object_suffix: ".o",
} }
} }
} }