使用Makefile列表过滤掉目录

时间:2016-09-22 14:00:54

标签: bash makefile build

我试图为我的makefile制作此版本规则 它的工作是复制文件夹中的目录,除了少数(如目的地等) 我查看了makefile 过滤器函数,但似乎它没有在bash循环中工作? 有没有一种简单的方法可以过滤掉bash中列表中的项目?

SOURCE_DIR=builds/$(NAME)_$(VERSION)

#List of items to ignore
IGNORE=builds cfg compiled

release:
if [ -d "cfg" ]; then \
    cp -r cfg $(SOURCE_DIR)/cfg; \
fi;
for folder in *; do \
    if [ -d "$$folder" ]; then \
            if [[ $(IGNORE) != $$folder ]]; then \
                cp -r $$folder $(SOURCE_DIR)/addons/; \
            fi; \
    fi; \
done;

1 个答案:

答案 0 :(得分:0)

filter-out function是一个Make函数,所以如果你想使用它,你必须在将命令传递给shell之前使用它。

您可以在规则之外使用它:

THINGS := $(wildcard *)
IGNORE = builds cfg compiled
THINGS := $(filter-out $(IGNORE), $(THINGS))

release:
    @for folder in $(THINGS); do \
      if [ -d $$folder ]; then \
        echo $$folder; \
      fi; \
     done

或在规则内:

THINGS := $(wildcard *)
IGNORE = builds cfg compiled

release:
    @for folder in $(filter-out $(IGNORE), $(THINGS)); do \
      if [ -d $$folder ]; then \
        echo $$folder; \
      fi; \
     done

或者您可以坚持使用for folder in *...并过滤bash中的列表:

IGNORE = builds cfg compiled

release:
    @for folder in *; do \
      if [ -d $$folder ]; then \
        [[ "$(IGNORE)" =~ $$folder ]] || echo $$folder; \
      fi; \
     done