From 1216aceec6e007fbb84d1358e28be7b573c66501 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 21:16:37 -0600 Subject: implement GNUful Static Pattern Rules --- src/makefile/input.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 9c895e1..460a8a0 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -474,6 +474,16 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { let (targets, not_targets) = line_tokens .split_once(':') .ok_or_else(|| eyre!("read_rule couldn't find a ':' on line {}", line_number))?; + #[cfg(feature = "full")] + let (static_targets, targets, not_targets) = if not_targets.contains_text(":") { + // ugh, this is probably a Static Pattern Rule + let (pattern, not_targets) = not_targets + .split_once(':') + .ok_or_else(|| eyre!("bro hold the fuck up it literally just had that"))?; + (Some(targets), pattern, not_targets) + } else { + (None, targets, not_targets) + }; let targets = self.expand_macros(&targets)?; let targets = targets.split_whitespace().collect::>(); let (prerequisites, mut commands) = match not_targets.split_once(';') { @@ -534,7 +544,26 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { commands, }; - self.inference_rules.push(new_rule); + if let Some(static_targets) = static_targets { + let static_targets = self.expand_macros(&static_targets)?; + let static_targets = static_targets.split_whitespace(); + for real_target in static_targets { + if new_rule.matches(real_target)? { + let new_target = Target { + name: real_target.to_owned(), + prerequisites: new_rule.prereqs(real_target)?.collect(), + commands: new_rule.commands.clone(), + stem: new_rule + .first_match(real_target)? + .and_then(|x| x.get(1).map(|x| x.as_str().to_owned())), + already_updated: Cell::new(false), + }; + self.targets.insert(real_target.to_owned(), new_target); + } + } + } else { + self.inference_rules.push(new_rule); + } return Ok(()); } -- cgit v1.2.3