help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Filtering-out files from a list


From: John Dill
Subject: RE: Filtering-out files from a list
Date: Fri, 27 May 2011 16:43:16 -0400

 
>From: R?mi Delmas <address@hidden>
>To: address@hidden
>Subject: Filtering-out files from a list
>Message-ID: <address@hidden>
>Content-Type: text/plain; charset=ISO-8859-1
>
>Hello,
>
>In the project I am working on, I build the list of files to compile with
>the following expression:
>
>BMS_SRCS ?=$(foreach w,*.cpp *.c,$(wildcard src/$(w))))
>
>This line is actually generated, as the user can specify wildcards (he
>specified *.cpp and *.c in that case).
>
>Now, I would like to be able to achieve the same result, but to be able to
>filter out some files based on a pattern. A general-purpose pattern would be
>nice, but what I really need right now is to filter-out files matching the
>regexp ".*_[A-Z]*\..*" (= any file where the name ends with an underscore
>and capital letters).
>
>Looking at documentation, it seems to me that this is not doable with
>wildcards. Am I wrong? Is there any other way to achieve this?
>
>Thanks a lot in advance,

You're going to have to pass off the filtering aspect to an external program 
run in a $(shell) command.  I'm most familiar with sed, so you can try the 
following.

space_to_line_delimiter_sed_script:=-e "G" -e ":loop" -e "s/ 
\(.*\)\(.\)$/\2\1\2/" -e "tloop" -e "s/.$//"
my_file_filter:=-e "/.*_[A-Z]*\..*/d"

FILTERED_BMS_SRCS:=$(shell echo $(BMS_SRCS) | sed 
$(space_to_line_delimiter_sed_script) | sed $(my_file_filter))

I put the raw script in the makefile variable.  Will likely need to replace '$' 
with '$$'.  Try it in the shell first.  Hopefully you have access to a sed 
program, or can apply the same technique in another text scripting language 
like sed, awk, perl, etc.  Not tested.

Hope it helps,
John Dill

<<winmail.dat>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]