#![warn( missing_docs, unreachable_pub, unsafe_code, unused_crate_dependencies, variant_size_differences, clippy::pedantic, clippy::cargo, clippy::nursery )] #![allow(clippy::redundant_pub_crate, clippy::non_ascii_literal)] 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 mut args = Args::from_env_and_args(); // If no makefile is specified, try some options. if args.makefile.is_empty() { args.makefile = vec![if metadata("./makefile").is_ok() { "./makefile".into() } else if metadata("./Makefile").is_ok() { "./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); for filename in &args.makefile { if filename == &PathBuf::from("-") { makefile.and_read(stdin().lock()); } else { makefile.and_read_file(filename); }; } if args.print_everything { println!("{}", &makefile); } let targets = if args.targets().count() == 0 { vec![makefile .first_non_special_target .clone() .expect("couldn't find a target!")] } else { args.targets().cloned().collect() }; for target in targets { makefile.update_target(&target); } }