From 28ec6d36246a7a200c435710b21e64fcd310388f Mon Sep 17 00:00:00 2001 From: Penguin Date: Fri, 31 Dec 2021 13:30:21 -0600 Subject: [PATCH] project generation works well. Changing a lot of things as far as makefile generation goes so its easier to add new targets --- Cargo.lock | 2 +- igloo_core/src/igloo_cli.rs | 5 ++ igloo_core/src/igloo_project.rs | 37 ++++++++++++- igloo_core/src/igloo_target.rs | 95 +++++++++++++++++++++------------ 4 files changed, 101 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9e62cf..df35607 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,7 +170,7 @@ dependencies = [ [[package]] name = "igloo" -version = "0.1.0" +version = "0.1.1" dependencies = [ "igloo_agent", "igloo_core", diff --git a/igloo_core/src/igloo_cli.rs b/igloo_core/src/igloo_cli.rs index 2b6d17a..afbf9bf 100644 --- a/igloo_core/src/igloo_cli.rs +++ b/igloo_core/src/igloo_cli.rs @@ -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") diff --git a/igloo_core/src/igloo_project.rs b/igloo_core/src/igloo_project.rs index 793ce29..555d0c1 100644 --- a/igloo_core/src/igloo_project.rs +++ b/igloo_core/src/igloo_project.rs @@ -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 diff --git a/igloo_core/src/igloo_target.rs b/igloo_core/src/igloo_target.rs index 5e291e4..a333bcd 100644 --- a/igloo_core/src/igloo_target.rs +++ b/igloo_core/src/igloo_target.rs @@ -27,9 +27,9 @@ use std::io::prelude::*; #[derive(Serialize, Deserialize, Debug)] pub struct IglooTargetConfig { - name: String, + pub name: String, links: Vec, - includes: Vec, + pub includes: Vec, scripts: Vec, series: String, } @@ -38,8 +38,8 @@ pub struct IglooTargetConfig pub struct IglooTarget { root: std::path::PathBuf, - makeopts: HashMap, - config: IglooTargetConfig, + pub makeopts: HashMap, + 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; - } - - writeln!(app_file, "").unwrap(); - ret = self.makefile_write_var( - "DEPS", - &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_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) => { @@ -532,7 +528,7 @@ impl IglooTarget // is an array for element in arr { - writeln!(makefile, " \\").unwrap(); + writeln!(makefile, "\\").unwrap(); write!(makefile, "{}", element).unwrap(); } } @@ -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 = Vec::new(); + let mut sub_dirs: Vec = 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 }