Unfortunately, there's an error in that message and the correct function is as follows:
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))Usage is as follows. First, all C files in the current directory (or below).
$(call rwildcard,,*.c)Then all C files in /tmp:
$(call rwildcard,/tmp/,*.c)Multiple patterns can be used. Here are all C and H files:
$(call rwildcard,/tmp/,*.c *.h)
6 comments:
Thank you for posting this, I could not wrap my head around it myself.
Thank you, this post saved me a lot of headaches.
Thanks a lot!
Thanks a lot!
Many thanks for this, I was afraid I might have to do something very ugly, but thanks to you I guess I won't :D
A minor change of the code makes it capabale of searching in a list of base directories:
rwildcard = $(foreach d,$(wildcard $(addsuffix *,$(1))),$(call rwildcard,$(d)/,$(2)) $(filter $(subst *,%,$(2)),$(d)))
The $(addsuffix *,$(1)) instead of $(1)* expands a list of directories in the root invocation into directory candidates for further procesing.
Just a tip: A $(strip ...) around the complete RHS makes it better maintainable in case you want to print the output.
Post a Comment