#![warn( unsafe_code, unused_crate_dependencies, variant_size_differences, clippy::cargo, clippy::nursery, clippy::missing_docs_in_private_items, clippy::str_to_string, clippy::unwrap_used, clippy::integer_arithmetic, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unwrap_in_result, clippy::clone_on_ref_ptr, clippy::todo )] #![allow(clippy::missing_docs_in_private_items)] use std::fs::metadata; use std::io::stdin; use std::path::PathBuf; use eyre::{bail, Result}; mod args; mod makefile; use args::Args; use makefile::{Makefile, MakefileReader}; const DEFAULT_PATHS: &[&str] = &[ #[cfg(feature = "full")] "GNUmakefile", "makefile", "Makefile", ]; fn main() -> Result<()> { jane_eyre::install()?; let mut args = Args::from_env_and_args(); // If no makefile is specified, try some options. if args.makefile.is_empty() { let default_makefile = DEFAULT_PATHS.iter().find(|name| metadata(name).is_ok()); let default_makefile = match default_makefile { Some(x) => x, None => bail!("no makefile found (tried {})", DEFAULT_PATHS.join(", ")), }; args.makefile = vec![default_makefile.into()]; } // 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("-") { let macros = makefile.macros.with_overlay(); let file = MakefileReader::read(&args, macros, stdin().lock())?.finish(); makefile.extend(file); } else { let macros = makefile.macros.with_overlay(); let file = MakefileReader::read_file(&args, macros, filename)?.finish(); makefile.extend(file); }; } if args.print_everything { println!("{}", &makefile); } let targets = if args.targets().count() == 0 { let first_target = makefile.first_non_special_target.clone(); match first_target { Some(x) => vec![x], None => bail!("no targets given on command line or found in makefile."), } } else { args.targets().cloned().collect() }; for target in targets { makefile.update_target(&target)?; } Ok(()) }