diff options
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | src/main.rs | 13 |
3 files changed, 38 insertions, 7 deletions
@@ -6,13 +6,19 @@ MANDIR = ${DPREFIX}/share/man target = target/release/mmv +mmv = $${MMV_NAME:-mmv} +mcp = $${MCP_NAME:-mcp} + all: ${target} ${target}: src/main.rs cargo build --release install: mkdir -p ${DPREFIX}/bin ${DPREFIX}/share/man/man1 - cp ${target} ${DPREFIX}/bin/mmv - cp ${target} ${DPREFIX}/bin/mcp - cp mmv.1 ${MANDIR}/man1 - ln -srf ${MANDIR}/man1/mmv.1 ${MANDIR}/man1/mcp.1 + cp ${target} ${DPREFIX}/bin/${mmv} + cp mmv.1 ${MANDIR}/man1/${mmv}.1 + ln -srf ${DPREFIX}/bin/${mmv} ${DPREFIX}/bin/${mcp} + ln -srf ${MANDIR}/man1/${mmv}.1 ${MANDIR}/man1/${mcp}.1 + +clean: + rm -rf target @@ -18,6 +18,24 @@ $ make $ sudo make install ``` +The following environment variables can also be set at compile-time to modify +the names of the generated binaries: + +- `$MMV_NAME` + + The name of the file-moving binary (default is `mmv`). This is also used + to name the backups folder in `$XDG_CACHE_HOME`. +- `$MCP_NAME` + + The name of the file-copying binary (default is `mcp`). + +If you are compiling with a custom binary name, you want to make sure that the +environment variables actually get used when performing a `make install`. If +you’re using `sudo`, you want to do this with the `-E` flag. + +``` +$ MMV_NAME=mmv-rs MCP_NAME=mcp-rs make +$ MMV_NAME=mmv-rs MCP_NAME=mcp-rs sudo -E make install +``` + ## Examples and Documentation To avoid repeating myself everywhere, if you would like to see usage examples diff --git a/src/main.rs b/src/main.rs index e8fb883..9885a82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,10 @@ use { tempfile::tempdir, }; + +const MMV_DEFAULT_NAME: &str = "mmv"; +const MCP_DEFAULT_NAME: &str = "mcp"; + struct Flags { pub backup: bool, pub dryrun: bool, @@ -54,7 +58,8 @@ impl Flags { let argv0 = env::args().next().unwrap(); let p = Path::new(&argv0).file_name().unwrap(); - if p == "mcp" { + let mcp_name = option_env!("MCP_NAME").unwrap_or(MCP_DEFAULT_NAME); + if p == mcp_name { flags.mcp = true; flags.backup = false; } @@ -85,7 +90,8 @@ fn usage(bad_flags: Option<lexopt::Error>) -> ! { } let argv0 = env::args().next().unwrap(); let p = Path::new(&argv0).file_name().unwrap(); - if p == "mcp" { + let mcp_name = option_env!("MCP_NAME").unwrap_or(MCP_DEFAULT_NAME); + if p == mcp_name { eprintln!("Usage: {} [-0deiv] command [argument ...]", p.to_str().unwrap()); } else { eprintln!("Usage: {} [-0deinv] command [argument ...]", p.to_str().unwrap()); @@ -173,9 +179,10 @@ fn work() -> Result<(), io::Error> { let cache_base = env::var("XDG_CACHE_HOME").unwrap_or_else(|_| { err!("XDG_CACHE_HOME variable must be set"); }); + let mmv_name = option_env!("MMV_NAME").unwrap_or(MMV_DEFAULT_NAME); cache_dir = [ Path::new(cache_base.as_str()), - Path::new("mmv"), + Path::new(mmv_name), Path::new(ts.as_str()), ] .iter() |