aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 33 insertions, 2 deletions
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);
+ };
+ }
}