aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/functions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r--src/makefile/functions.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 6815ac4..4ead48f 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -37,6 +37,10 @@ pub fn expand_call(
text::sort(macros, &args[0])
}
+ "dir" => {
+ assert_eq!(args.len(), 1);
+ file_name::dir(macros, &args[0])
+ }
"notdir" => {
assert_eq!(args.len(), 1);
file_name::notdir(macros, &args[0])
@@ -190,6 +194,20 @@ mod file_name {
use super::*;
+ pub fn dir(macros: &MacroSet, words: &TokenString) -> Result<String> {
+ let words = macros.expand(words)?;
+ let words = words
+ .split_whitespace()
+ .map(|word| {
+ Path::new(word)
+ .parent()
+ .and_then(Path::to_str)
+ .unwrap_or("./")
+ })
+ .collect::<Vec<_>>();
+ Ok(words.join(" "))
+ }
+
pub fn notdir(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
let words = words