2016-09-22 121 views
1

我試圖爲我的makefile製作這個版本規則 它的工作是複製文件夾中的目錄,除了少數(如目標等) 我已經看過makefile 過濾器函數,但它似乎不工作在bash循環內部? 有沒有簡單的方法來篩選出bash中列表中的項目?使用Makefile列表過濾掉目錄

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; 

回答

0

filter-out function是製作功能,所以如果你想使用它,你必須傳遞命令前殼使用它。

你可以用它外治:

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