3

Let's say I have the following wildcard matches in a makefile:

data-files = $(wildcard $(ptdf)/*.png) \
    $(wildcard $(ptdf)/*.gif) \
    $(wildcard $(ptdf)/*.bmp) \
    $(wildcard $(ptdf)/*.jpg) \
    $(wildcard $(ptdf)/*.ico) \
    $(wildcard $(ptdf)/*.dist) \
    $(wildcard $(ptdf)/*.html)

Can the wildcard syntax give me the power to match, for example, file names containing from 1 to 2 letters, as the regexp \w{1,2} would do? With no filename extension?

If not, how can I do that with other syntax with linux command (such as find, etc)?

newfurniturey
  • 37,556
  • 9
  • 94
  • 102
PatlaDJ
  • 1,226
  • 2
  • 17
  • 31

1 Answers1

8

Downloading the source code and grepping for wildcard, we find the definition of the function on line 1332 of function.cwildcard calls string_glob, which just does globbing, not regular expressions. And grepping the source code for regex turns up nothing :/

Since make has no built-in regex function, we'll have to use an external command. grepping for regex on the find(1) man page shows that the following will work:

data-files = $(shell find . -regextype posix-extended -regex '.*\.\w{1,2}')
andrewdotn
  • 32,721
  • 10
  • 101
  • 130
  • Just to clarify even more for seekers: This one is exactly what did the job: find . -maxdepth 1 -regextype posix-extended -regex '.*/\w{1,2}' It matches the files with one or two \w characters only, with no extension, in the current directory – PatlaDJ Nov 12 '12 at 17:23
  • 5
    I really like the habit of **looking inside free software's source code**. I find that a lot of newbies are not using the freedom given by free software. – Basile Starynkevitch Nov 12 '12 at 19:56
  • 1
    Basile Starynkevitch: When you say 'newbie', you should know, that I am software developer for at least 10+ years, and I accept your point only because I am into GNU / C++ stuff so recently. So yes, I am newbie in these. But what if? I just want the job done for now. Nothing else. The question is relevant and the answer is superb, what'ss the point of making 'parties' qualification? – PatlaDJ Nov 12 '12 at 20:07
  • I just say that you could have limited your comment to the habit of looking inside free software's source code, and skip the 'newbie' part. – PatlaDJ Nov 12 '12 at 20:13