Wednesday, July 27, 2011

GNU Make Recursive Wildcard Function

A reader wrote in to ask me about an old message in a mailing list where I'd defined a recursive version of GNU Make's wildcard function.

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)

Labels:

If you enjoyed this blog post, you might enjoy my travel book for people interested in science and technology: The Geek Atlas. Signed copies of The Geek Atlas are available.

<$BlogCommentBody$>

<$BlogCommentDateTime$> <$BlogCommentDeleteIcon$>

Post a Comment

Links to this post:

<$BlogBacklinkControl$> <$BlogBacklinkTitle$> <$BlogBacklinkDeleteIcon$>
<$BlogBacklinkSnippet$>
Create a Link

<< Home