|
|
|
use config::{Config, Environment, Value};
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use std::path::Path;
|
|
|
|
fn main()
|
|
|
|
{
|
|
|
|
let mut mcu_lookup_table = Config::new();
|
|
|
|
let mut make_manifest: Config = Config::new();
|
|
|
|
mcu_lookup_table.merge(config::File::with_name("\
|
|
|
|
/storage/Shared/Documents/Projects/ePenguin/\
|
|
|
|
ePenguin-Software-Framework/arch/mcu-lookup.toml")).unwrap();
|
|
|
|
make_manifest.merge(config::File::with_name("\
|
|
|
|
/storage/Shared/Documents/Projects/ePenguin/\
|
|
|
|
ePenguin-Software-Framework/arch/make-manifest.toml")).unwrap();
|
|
|
|
let mut _table_name = mcu_lookup_table.get_str("make.mcu.samd21j18a").unwrap();
|
|
|
|
let mut table_head = &_table_name[0.._table_name.len()];
|
|
|
|
let mut makefile: HashMap<String, config::Value> = HashMap::new();
|
|
|
|
let mut b_quit: bool = false;
|
|
|
|
loop
|
|
|
|
{
|
|
|
|
let mut _active_table = make_manifest.get_table(&table_head).unwrap();
|
|
|
|
for (name, val) in _active_table
|
|
|
|
{
|
|
|
|
match val.clone().into_table()
|
|
|
|
{
|
|
|
|
Err(_e) =>
|
|
|
|
{
|
|
|
|
if !makefile.contains_key(&name)
|
|
|
|
{
|
|
|
|
makefile.insert(name, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let mut new_arr = makefile
|
|
|
|
.get_key_value(&name).unwrap().1.clone().into_array().unwrap();
|
|
|
|
println!("\n\n\n\nPRINTING THINGY\n\n\n\n\n");
|
|
|
|
for x in &new_arr
|
|
|
|
{
|
|
|
|
println!("{:?}", x);
|
|
|
|
}
|
|
|
|
println!("\n\n\n\n\nPRINTING THINGY OVER\n\n\n\n");
|
|
|
|
new_arr.push(config::Value::from(val.into_array().unwrap()));
|
|
|
|
println!("\n\n\n\nPRINTING THINGY\n\n\n\n\n");
|
|
|
|
for x in &new_arr
|
|
|
|
{
|
|
|
|
println!("{:?}", x);
|
|
|
|
}
|
|
|
|
println!("\n\n\n\n\nPRINTING THINGY OVER\n\n\n\n");
|
|
|
|
|
|
|
|
makefile.insert(name, config::Value::from(new_arr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(_v) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match table_head.rfind('.')
|
|
|
|
{
|
|
|
|
None => b_quit = true,
|
|
|
|
Some(v) => table_head = &table_head[0..v],
|
|
|
|
}
|
|
|
|
if b_quit
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (key_id, val) in &makefile
|
|
|
|
{
|
|
|
|
println!("\n{}: {:?}", key_id, val);
|
|
|
|
}
|
|
|
|
gen_makefile(&makefile);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn gen_makefile(mkfile: &HashMap<String, config::Value>) -> bool
|
|
|
|
{
|
|
|
|
// If the Makefile already exists, trash it
|
|
|
|
if Path::new("Makefile").exists()
|
|
|
|
{
|
|
|
|
std::fs::remove_file("Makefile");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make our Makefile, set it to append mode
|
|
|
|
File::create("Makefile").unwrap();
|
|
|
|
let mut app_file = OpenOptions::new()
|
|
|
|
.write(true)
|
|
|
|
.append(true)
|
|
|
|
.open("Makefile")
|
|
|
|
.unwrap();
|
|
|
|
//
|
|
|
|
writeln!(app_file, "# ePenguin Generated Variables").unwrap();
|
|
|
|
|
|
|
|
// Get our knowns out of the way
|
|
|
|
match mkfile.get("TOOLCHAIN")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("TOOLCHAIN Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "TOOLCHAIN=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("CC")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("CC Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "CC=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("CXX")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("CXX Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "CXX=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("OBJCOPY")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("OBJCOPY Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "OBJCOPY=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("OBJDUMP")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("OBJDUMP Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "OBJDUMP=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("GDB")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("GDB Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "OBJDUMP=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("SIZE")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("SIZE Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "SIZE=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("AS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("AS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "AS=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
writeln!(app_file, "\n").unwrap();
|
|
|
|
|
|
|
|
// MCU Specifics now
|
|
|
|
match mkfile.get("MCPU")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("MCPU Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "MCPU=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("MCU")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("MCU Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "MCU=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("LD_PATH")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("LD_PATH Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "LD_PATH=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
match mkfile.get("LD_SCRIPT")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("LD_SCRIPT Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "LD_SCRIPT=").unwrap();
|
|
|
|
writeln!(app_file, "{}", v.to_string()).unwrap();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
writeln!(app_file, "\n").unwrap();
|
|
|
|
|
|
|
|
// CFLAGS
|
|
|
|
match mkfile.get("CFLAGS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("CFLAGS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "CFLAGS=").unwrap();
|
|
|
|
for cflag in v.clone().into_array().unwrap()
|
|
|
|
{
|
|
|
|
writeln!(app_file, " \\").unwrap();
|
|
|
|
write!(app_file, "{}", cflag).unwrap();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
writeln!(app_file, "\n").unwrap();
|
|
|
|
// ELF FLAGS
|
|
|
|
match mkfile.get("EFLAGS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("EFLAGS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "EFLAGS=").unwrap();
|
|
|
|
for cflag in v.clone().into_array().unwrap()
|
|
|
|
{
|
|
|
|
writeln!(app_file, " \\").unwrap();
|
|
|
|
write!(app_file, "{}", cflag).unwrap();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
writeln!(app_file, "\n").unwrap();
|
|
|
|
// Write SystemRoot config stuff for cross compatibility
|
|
|
|
let sysroot: String = String::from("ifdef SystemRoot
|
|
|
|
SHELL = cmd.exe\n\
|
|
|
|
MK_DIR = mkdir\n\
|
|
|
|
else\n\
|
|
|
|
ifeq ($(shell uname), Linux)\n\
|
|
|
|
MK_DIR = mkdir -p\n\
|
|
|
|
endif\n\
|
|
|
|
\n\
|
|
|
|
ifeq ($(shell uname | cut -d _ -f 1), CYGWIN)\n\
|
|
|
|
MK_DIR = mkdir -p\n\
|
|
|
|
endif\n\
|
|
|
|
\n\
|
|
|
|
ifeq ($(shell uname | cut -d _ -f 1), MINGW32)\n\
|
|
|
|
MK_DIR = mkdir -p\n\
|
|
|
|
endif\n\
|
|
|
|
\n\
|
|
|
|
ifeq ($(shell uname | cut -d _ -f 1), MINGW64)\n\
|
|
|
|
MK_DIR = mkdir -p\n\
|
|
|
|
endif\n\
|
|
|
|
\n\
|
|
|
|
ifeq ($(shell uname | cut -d _ -f 1), DARWIN)\n\
|
|
|
|
MK_DIR = mkdir -p\n\
|
|
|
|
endif\n\
|
|
|
|
endif\n\
|
|
|
|
");
|
|
|
|
|
|
|
|
writeln!(app_file, "{}\n", sysroot).unwrap();
|
|
|
|
match mkfile.get("SUB_DIRS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("SUB_DIRS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "SUB_DIRS+=").unwrap();
|
|
|
|
for cflag in v.clone().into_array().unwrap()
|
|
|
|
{
|
|
|
|
writeln!(app_file, " \\").unwrap();
|
|
|
|
write!(app_file, "{}", cflag).unwrap();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(app_file, "\n").unwrap();
|
|
|
|
match mkfile.get("OBJS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("OBJS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "OBJS+=").unwrap();
|
|
|
|
for cflag in v.clone().into_array().unwrap()
|
|
|
|
{
|
|
|
|
writeln!(app_file, " \\").unwrap();
|
|
|
|
write!(app_file, "{}", cflag).unwrap();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(app_file, "\n").unwrap();
|
|
|
|
match mkfile.get("OBJS_AS_ARGS")
|
|
|
|
{
|
|
|
|
None =>
|
|
|
|
{
|
|
|
|
println!("OBJS_AS_ARGS Not found");
|
|
|
|
}
|
|
|
|
Some(v) =>
|
|
|
|
{
|
|
|
|
write!(app_file, "OBJS_AS_ARGS+=").unwrap();
|
|
|
|
for cflag in v.clone().into_array().unwrap()
|
|
|
|
{
|
|
|
|
writeln!(app_file, " \\").unwrap();
|
|
|
|
write!(app_file, "{}", cflag).unwrap();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|