use super::*; use crate::deser::*; #[derive(Debug, Clone)] pub struct Target<'a> { pub outfile: &'a str, pub compiler: &'a str, pub compiler_flags: Vec<&'a str>, pub linker: &'a str, pub linker_flags: Vec<&'a str>, pub linker_libs: Vec<&'a str>, pub sources: Vec<&'a str>, pub opts: TargetOptions<'a>, } impl<'a> Target<'a> { pub fn new( opts: &TargetOptions<'a>, deser: &'a DeserTarget, parent: Option<&Target<'a>>, ) -> Self { let mut ret = Self::get_default(); ret.opts = opts.clone(); if let Some(parent) = parent { if let None = deser.outfile { ret.outfile = parent.outfile; } if let None = deser.compiler { ret.compiler = parent.compiler; } if let None = deser.linker { ret.linker = parent.linker; } for string in parent.compiler_flags.clone() { ret.compiler_flags.push(string); } for string in parent.linker_flags.clone() { ret.linker_flags.push(string); } for string in parent.linker_libs.clone() { ret.linker_libs.push(string); } for string in parent.sources.clone() { ret.sources.push(string); } } if let Some(v) = &deser.outfile { ret.outfile = v; } if let Some(v) = &deser.compiler { ret.compiler = v; } if let Some(v) = &deser.compiler_flags { for string in v { ret.compiler_flags.push(string); } } if let Some(v) = &deser.linker { ret.linker = v; } else { if let Some(v) = &deser.compiler { ret.linker = v; } } if let Some(v) = &deser.linker_flags { for string in v { ret.linker_flags.push(string); } } if let Some(v) = &deser.linker_libs { for string in v { ret.linker_libs.push(string); } } if let Some(v) = &deser.sources { for string in v { ret.sources.push(string); } } ret } pub fn get_default() -> Self { Target { outfile: "a.out", compiler: "cc", compiler_flags: vec![], linker: "cc", linker_flags: vec![], linker_libs: vec![], sources: vec![], opts: TargetOptions::get_default(), } } }