From 1844cb79ae82e71610573f133c5ed7aeeb0c50b6 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 23 Mar 2021 23:27:45 -0600 Subject: man i don't even fuckin know anymore --- src/main.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 2316546..4048886 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,40 @@ +use std::fs::metadata; +use std::io::stdin; +use std::path::PathBuf; mod args; +mod makefile; use args::Args; +use makefile::Makefile; fn main() { - let args = Args::from_env_and_args(); - dbg!(args); + let mut args = Args::from_env_and_args(); + // If no makefile is specified, try some options. + if args.makefile.is_empty() { + if metadata("./makefile").is_ok() { + args.makefile = vec!["./makefile".into()]; + } else if metadata("./Makefile").is_ok() { + args.makefile = vec!["./Makefile".into()]; + } else { + // TODO handle error gracefully + panic!("no makefile found"); + } + } + // Read in the makefile(s) specified. + // TODO dump command-line args into MAKEFLAGS + // TODO dump command-line macros into environment + // TODO add SHELL macro + let mut makefile = Makefile::new(args.clone()); + if !args.no_builtin_rules { + makefile.add_builtins(); + } + makefile.add_env(); + for filename in &args.makefile { + if filename == &PathBuf::from("-") { + makefile.and_read(stdin().lock()); + } else { + makefile.and_read_file(filename); + }; + } } -- cgit v1.2.3