簡體   English   中英

GNU Make:如果字符串包含“dirToExclude”,則從帶有子目錄的數組中刪除字符串

[英]GNU Make: Remove string from array with subdirectories if string contains "dirToExclude"

我有一個目錄,其中包含許多包含源文件的子目錄。 因此,我正在尋找每個子目錄 for.c-files: cSources = $(shell dir /s /b *.c)

但是,有些子目錄包含我不想編譯的源文件。 如果我有一個變量dirToExclude = dirName如何刪除cSources中包含“dirName”的每個字符串?

我知道有findstring 但我不知道如何在數組中的每個字符串上使用findstring 我正在尋找某種方法來獲得像(偽代碼)這樣的嵌套循環:

foreach (var in cSources)
   if (var.contains(dirToExclude))
       cSources -= var
   endif

如果你知道dirToExclude總是在字符串的開頭,你可以寫:

cSources := $(filter-out $(dirToExclude)%,$(cSources))

如果要刪除字符串出現在任何位置的任何文件名,可以使用:

cSources := $(foreach S,$(cSources),$(if $(findstring $(dirToExclude),$(S)),,$(S)))

https://www.gnu.org/software/make/manual/html_node/Functions.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM