diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-07 13:27:37 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-07 13:27:37 -0600 |
commit | f2bb81496304981ac208ad664597172e532b17d5 (patch) | |
tree | 7ae75d2602b72d7e89ad15a8d2e37ca18d091e9e | |
parent | 1216aceec6e007fbb84d1358e28be7b573c66501 (diff) | |
download | makers-f2bb81496304981ac208ad664597172e532b17d5.tar.gz makers-f2bb81496304981ac208ad664597172e532b17d5.zip |
let macros in dependencies use $@ to get targets
-rw-r--r-- | src/makefile/input.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 460a8a0..beb517a 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -497,7 +497,42 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { log::error!("rule-specific macros are not implemented yet"); return Ok(()); } - let prerequisites = self.expand_macros(&prerequisites)?; + let prerequisites = self + .macros + .with_lookup(&|macro_name: &str| { + let macro_pieces = if macro_name.starts_with('@') { + // The $@ shall evaluate to the full target name of the + // current target. + targets.iter() + } else { + bail!("unknown internal macro") + }; + + let macro_pieces = if macro_name.ends_with('D') { + macro_pieces + .map(|x| { + Path::new(x) + .parent() + .ok_or_else(|| eyre!("no parent")) + .map(|x| x.to_string_lossy().into()) + }) + .collect::<Result<Vec<String>, _>>()? + } else if macro_name.ends_with('F') { + macro_pieces + .map(|x| { + Path::new(x) + .file_name() + .ok_or_else(|| eyre!("no filename")) + .map(|x| x.to_string_lossy().into()) + }) + .collect::<Result<Vec<String>, _>>()? + } else { + macro_pieces.map(|&x| x.to_owned()).collect::<Vec<String>>() + }; + + Ok(macro_pieces.join(" ")) + }) + .expand(&prerequisites)?; let prerequisites = prerequisites .split_whitespace() .map(|x| x.into()) |