From 0b4bdb6dae6dbb3d37695555765acabbf2663849 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 16:29:52 -0600 Subject: implement function `addsuffix` --- src/makefile/functions.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 2192d26..c111fba 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -69,6 +69,10 @@ pub fn expand_call( assert_eq!(args.len(), 1); file_name::basename(macros, &args[0]) } + "addsuffix" => { + assert_eq!(args.len(), 2); + file_name::addsuffix(macros, &args[0], &args[1]) + } "addprefix" => { assert_eq!(args.len(), 2); file_name::addprefix(macros, &args[0], &args[1]) @@ -318,6 +322,20 @@ mod file_name { Ok(words.join(" ")) } + pub fn addsuffix( + macros: &MacroSet, + suffix: &TokenString, + targets: &TokenString, + ) -> Result { + let suffix = macros.expand(suffix)?; + let targets = macros.expand(targets)?; + let results = targets + .split_whitespace() + .map(|t| format!("{}{}", t, suffix)) + .collect::>(); + Ok(results.join(" ")) + } + pub fn addprefix( macros: &MacroSet, prefix: &TokenString, -- cgit v1.2.3