Created
October 24, 2024 14:19
-
-
Save amn/50207bca57f22c126d2cb1b512797008 to your computer and use it in GitHub Desktop.
A decent "resolve like using VPATH" [GNU] Make expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vpath-resolve = $(foreach path,$(1),$(or $(firstword $(wildcard $(path) $(addsuffix /$(path),$(patsubst %/,%,$(VPATH))))),$(error `$(path)` not found in any of `VPATH`.))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
vpath-resolve
function expressed with the above [GNU] Make file, is written to aid in situations where one wants to resolve a path (or list of paths) as if Make itself were looking for the file as a prerequisite. I.e. if you have a rule for a targetfoo
that hasbar
for prerequisite:foo: bar
...in a recipe for
foo
(omitted from the above for simplicity), the path of the prerequisite corresponding tobar
in the rule above, available with$<
or$^
, would actually be the path of some "bar" found according to "Searching Directories for Prerequisites" -- it wouldn't necessarily be "bar" relative to current working directory, but rather whichever "bar" was first found among paths specified withVPATH
.The
vpath-resolve
function offered with the gist attempts to replicate the prerequisite searching method results, meaning$(call vpath-resolve,bar)
should produce a path as if Make were searching for it as a prerequisite, as described by the linked documentation section.The reason I have added the function definition as a gist, is because I, for reasons I can't really understand, have come to expect the functionality on numerous occasions myself, so perhaps I am not the only one in need of it?
#opaqueabstractions #transparentabstractions