aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-02 19:28:31 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-02 19:28:31 -0600
commit77923a4d12717902137f8cd29a512796eff1a3af (patch)
tree14bf489bbe8251409b1a0db667a8979fa7843f29 /src/makefile
parentb9ebee54da296f99ceab32c3db31ae38fe8709a1 (diff)
downloadmakers-77923a4d12717902137f8cd29a512796eff1a3af.tar.gz
makers-77923a4d12717902137f8cd29a512796eff1a3af.zip
implement `if`
Diffstat (limited to 'src/makefile')
-rw-r--r--src/makefile/functions.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index a4d206f..bc244cb 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -36,6 +36,11 @@ pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Resul
file_name::wildcard(macros, &args[0])
}
+ "if" => {
+ assert!(args.len() == 2 || args.len() == 3);
+ conditional::r#if(macros, &args[0], &args[1], args.get(2))
+ }
+
// foreach
"foreach" => {
assert_eq!(args.len(), 3);
@@ -183,6 +188,32 @@ mod file_name {
}
}
+// Functions for Conditionals
+mod conditional {
+ use super::*;
+
+ pub fn r#if(
+ macros: &MacroSet,
+ condition: &TokenString,
+ if_true: &TokenString,
+ if_false: Option<&TokenString>,
+ ) -> Result<String> {
+ let mut condition = condition.clone();
+ condition.trim_start();
+ condition.trim_end();
+ let condition = macros.expand(&condition)?;
+ if condition.is_empty() {
+ if let Some(if_false) = if_false {
+ macros.expand(if_false)
+ } else {
+ Ok(String::new())
+ }
+ } else {
+ macros.expand(if_true)
+ }
+ }
+}
+
// foreach
mod foreach {
use super::*;