project generation works well. Changing a lot of things as far as makefile generation goes so its easier to add new targets

unstable
Penguin 3 years ago
parent 6294c3868a
commit 28ec6d3624

2
Cargo.lock generated

@ -170,7 +170,7 @@ dependencies = [
[[package]]
name = "igloo"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"igloo_agent",
"igloo_core",

@ -64,6 +64,11 @@ fn igloo_run_cli() -> clap::ArgMatches
.required(false)
.about("Release or Debug build type\n\
Defaults to Debug")),)
.subcommand(App::new("build")
.about("Builds all targets unless otherwise specified.")
.arg(Arg::new("build_type")
.required(false)
.about("Options are release, debug, and clean")))
.subcommand(App::new("push")
.about("Pushes/flashes target(s)")
.arg(Arg::new("build_type")

@ -288,7 +288,6 @@ impl<'a> IglooProject<'a>
{
igloo_debug!(ERROR, ret);
break;
}
ret = self.generate_igloo_main();
@ -327,12 +326,46 @@ impl<'a> IglooProject<'a>
pub fn generate_igloo_header(&self) -> IglooStatus
{
let mut ret = IS_GOOD;
let prj_header_path = self.root.join("inc").join("igloo.h");
let mut prj_header_file = std::fs::File::create(&prj_header_path).unwrap();
// begin ifdef guards for igloo_h
prj_header_file.write("#ifndef _IGLOO_H_\n".as_bytes()).unwrap();
prj_header_file.write("#define _IGLOO_H_\n".as_bytes()).unwrap();
// now do targets
for target in &self.targets
{
prj_header_file.write(
format!("\n// Header files for {}\n", target.config.name)
.as_bytes()).unwrap();
for include in &target.config.includes
{
prj_header_file.write(
format!("#include \"{}\"", include).as_bytes()).unwrap();
}
}
prj_header_file.write("\n\n#endif\n".as_bytes()).unwrap();
IS_GOOD
}
pub fn generate_igloo_main(&self) -> IglooStatus
{
IS_GOOD
let mut ret = IS_GOOD;
let prj_main_path = self.root.join("src").join("main.c");
let mut prj_main_file = std::fs::File::create(&prj_main_path).unwrap();
prj_main_file.write("#include \"igloo.h\"
int main()
{
for(;;){}
// should never get here
return 0;
}
".as_bytes()).unwrap();
ret
}
pub fn generate_project_config(&self) -> IglooStatus

@ -27,9 +27,9 @@ use std::io::prelude::*;
#[derive(Serialize, Deserialize, Debug)]
pub struct IglooTargetConfig
{
name: String,
pub name: String,
links: Vec<String>,
includes: Vec<String>,
pub includes: Vec<String>,
scripts: Vec<String>,
series: String,
}
@ -38,8 +38,8 @@ pub struct IglooTargetConfig
pub struct IglooTarget
{
root: std::path::PathBuf,
makeopts: HashMap<String, config::Value>,
config: IglooTargetConfig,
pub makeopts: HashMap<String, config::Value>,
pub config: IglooTargetConfig,
}
impl IglooTargetConfig
@ -238,6 +238,7 @@ impl IglooTarget
pub fn generate_makefile(&self, project: &IglooProject) -> IglooStatus
{
let mut ret = IS_GOOD;
let target_root = self.root.clone();
// If the Makefile already exists, trash it
@ -362,7 +363,7 @@ impl IglooTarget
writeln!(app_file, "").unwrap();
// Write out our compiler flags
writeln!(app_file, "## Compiler Flags").unwrap();
write!(app_file, "\n## Compiler Flags").unwrap();
ret = self.makefile_write_var(
"CFLAGS",
&mut app_file);
@ -371,6 +372,7 @@ impl IglooTarget
break;
}
writeln!(app_file, "").unwrap();
ret = self.makefile_write_var(
"ELF_FLAGS",
&mut app_file);
@ -379,6 +381,7 @@ impl IglooTarget
break;
}
writeln!(app_file, "").unwrap();
ret = self.makefile_write_var(
"HEX_FLAGS",
&mut app_file);
@ -429,34 +432,21 @@ impl IglooTarget
break;
}
writeln!(app_file, "").unwrap();
ret = self.makefile_write_var(
"DIR_INCLUDES",
&mut app_file);
if ret != IS_GOOD
{
break;
}
// Write our DEPS and DEPS_AS_ARGS vars
writeln!(app_file, "\n").unwrap();
writeln!(app_file, "DEPS=$(OBJS_AS_ARGS:%.o=%.d)").unwrap();
writeln!(app_file, "DEPS_AS_ARGS=$(OBJS:%.o=%.d)").unwrap();
writeln!(app_file, "").unwrap();
ret = self.makefile_write_var(
"DEPS",
&mut app_file);
if ret != IS_GOOD
{
break;
}
writeln!(app_file, "").unwrap();
ret = self.makefile_write_var(
"DEPS_AS_ARGS",
"DIR_INCLUDES",
&mut app_file);
if ret != IS_GOOD
{
break;
}
writeln!(app_file, "\nvpath %.c ../../../").unwrap();
writeln!(app_file, "\n\nvpath %.c ../../../").unwrap();
writeln!(app_file, "vpath %.s ../../../").unwrap();
writeln!(app_file, "vpath %.S ../../../\n").unwrap();
writeln!(app_file, ".PHONY: debug push clean\n").unwrap();
@ -502,7 +492,10 @@ impl IglooTarget
if ret != IS_GOOD
{
igloo_debug!(ERROR, ret, "Failed to write some var to the makefile for target {}", self.config.name);
igloo_debug!(ERROR,
ret,
"Failed to write some var to the makefile for target {}",
self.config.name);
}
ret
}
@ -520,7 +513,10 @@ impl IglooTarget
None =>
{
ret = IS_FAILED_TO_EXTRACT_MF_VAR;
igloo_debug!(WARNING, ret, "Failed to write make var {} -- wasn't found", name);
igloo_debug!(WARNING,
ret,
"Failed to write make var {} -- wasn't found",
name);
}
Some(v) =>
{
@ -1064,18 +1060,20 @@ endif\n").unwrap();
ret
}
fn gather_esf_inc_files(&self, project: &IglooProject) -> IglooStatus
{
let mut ret = IS_GOOD;
ret
}
pub fn collect_makefile(&mut self, project: &IglooProject) -> IglooStatus
{
let mut ret: IglooStatus = IS_GOOD;
let (dummy, arch, family, mcu_name) = sscanf::scanf!(
self.config.series, "{}.{}.{}.{}", String, String, String, String).unwrap();
// NOTE: Add
//
// DEPS = "$(OBJS:%.o=%.d)"
// DEPS_AS_ARGS = "$(OBJS_AS_ARGS:%.o=%.d)"
// Convert OBJS to OBJS_AS_ARGS
// add esf/...guts.../mcu/src to SUB_DIRS
/*let (dummy, arch, family, mcu_name) = sscanf::scanf!(
self.config.series, "{}.{}.{}.{}", String, String, String, String).unwrap(); */
// collect makefile data
let mut make_table_head = &self.config.series[0..self.config.series.len()];
let mut b_quit: bool = false;
loop
@ -1113,6 +1111,33 @@ endif\n").unwrap();
break;
}
}
if ret != IS_GOOD
{
igloo_debug!(ERROR, ret);
return ret;
}
// Generate the remaining variables from the makefile data
// Convert OBJS to OBJS_AS_ARGS
let mut objs_as_args: Vec<String> = Vec::new();
let mut sub_dirs: Vec<String> = Vec::new();
let objs = self.makeopts.get("OBJS").unwrap();
for obj in objs.clone().into_array().unwrap()
{
let obj_as_arg_string: String = format!(
"$(QUOTE){}$(QUOTE)",
obj.clone().into_str().unwrap());
let mut sub_dir_as_string = String::from(&obj.into_str().unwrap());
sub_dir_as_string = String::from(
&sub_dir_as_string[0..sub_dir_as_string.rfind('/').unwrap()]);
objs_as_args.push(obj_as_arg_string);
// println!("{}", &sub_dir_as_string);
sub_dirs.push(sub_dir_as_string);
}
self.makeopts.insert("OBJS_AS_ARGS".to_owned(), config::Value::from(objs_as_args));
self.makeopts.insert("SUB_DIRS".to_owned(), config::Value::from(sub_dirs));
// generate SUB_DIRS
ret
}

Loading…
Cancel
Save