How to exclude a particular file with GNUMake's wildcard function?

淺唱寂寞╮ 提交于 2020-01-06 05:25:16

问题


My project's directory structure is as follows:

My Makefile looks like this:

dir1_contents := $(wildcard dir1/*) 
dir3_contents := $(wildcard dir3/*)

all: clean_dir1 clean_dir3

clean_dir1:
    echo 'dir1_contents = $(dir1_contents)'

clean_dir3:
echo 'dir3_contents = $(dir3_contents)'

When I run make, this is what I get:

$ pwd
make-test

$ make -s
dir1_contents = dir1/dir2 dir1/file2.junk dir1/file3.junk
dir3_contents = dir3/file4.junk

I want to get the contents of dir1 in dir1_contents. But I want to exclude file3.junk from that list. How can I do it?

Perhaps I should use grep -v? But I'm not sure that's the best way. Is there a built-in GNUMake function I can use here?


回答1:


Use the $(filter-out pattern, text ) text function

 $(filter-out file3.junk,${dir1_contents})

(someone suggested to use %/file3.junk instead of file3.junk, but I believe you don't need that; I leave you to experiment)



来源:https://stackoverflow.com/questions/44877381/how-to-exclude-a-particular-file-with-gnumakes-wildcard-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!