aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-03 13:53:09 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-03 13:53:09 -0600
commitf7770e6743eb244dad708bc9d2b6de1c8fa3045d (patch)
treefe046d5cb0a9c0ce4f7ced3f82a4b106f6c18c53
parente6c4f309cafe2d0900a96f9c3ca3ac44fc2cd3f0 (diff)
downloadmakers-f7770e6743eb244dad708bc9d2b6de1c8fa3045d.tar.gz
makers-f7770e6743eb244dad708bc9d2b6de1c8fa3045d.zip
look for `GNUmakefile` if not in POSIX mode
-rw-r--r--src/main.rs31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index c5240fc..27e19fe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,7 +17,6 @@
)]
#![allow(clippy::missing_docs_in_private_items)]
-use std::env::current_dir;
use std::fs::metadata;
use std::io::stdin;
use std::path::PathBuf;
@@ -30,29 +29,25 @@ 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() {
- args.makefile = vec![if metadata("./makefile").is_ok() {
- "./makefile".into()
- } else if metadata("./Makefile").is_ok() {
- "./Makefile".into()
- } else {
- bail!(
- "no makefile specified and neither {} nor {} was found.",
- current_dir().map_or_else(
- |_| "./makefile".to_owned(),
- |path| path.join("makefile").display().to_string()
- ),
- current_dir().map_or_else(
- |_| "./Makefile".to_owned(),
- |path| path.join("Makefile").display().to_string()
- ),
- );
- }];
+ 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