Makefile中的wilcard函式

2021-08-31 13:53:18 字數 679 閱讀 1293

在makefile規則中,會對萬用字元進行展開,但是在變數的定義和函式的引用的時候萬用字元就會失效,這種情況下若是想讓萬用字元有效,就需要使用函式"wildcard",使用方法是:$(wildcard pattern…) 。在makefile中,它被展開為已經存在的、使用空格分開的、匹配此模式的所有檔案列表。如果不存在任何符合此模式的檔案,函式會忽略模式字元並返回空。

一般我們可以使用「$(wildcard *.c)

」來獲取工作目錄下的所有的.c檔案列表。

下面這句的作用就是將當前檔案資料夾下的所有的.c檔案列表換成.o檔案列表,並將其賦值給objects

#sample makefile

objects :=

$(patsubst %.c,%.o,$(wildcard *.c)

)

使用上訴指令生成的.o檔案,最終生成ser可執行檔案

ser :

$(objects)

cc -o ser $(objects)

這裡我們使用了make的隱含規則來編譯.c的原始檔。對變數的賦值也用到了乙個特殊的符號(:=)。

1、wildcard : 擴充套件萬用字元

2、notdir : 去除路徑

3、patsubst :替換萬用字元

Makefile 中 的區別

在makefile中我們經常看到 這幾個賦值運算子,那麼他們有什麼區別呢?我們來做個簡單的實驗 新建乙個makefile,內容為 ifdef define vre vre hello world else endif ifeq opt define vre hello world first end...

Makefile 中 的區別

在makefile中我們經常看到 這幾個賦值運算子,那麼他們有什麼區別呢?我們來做個簡單的實驗 新建乙個makefile,內容為 ifdef define vre vre hello world else endif ifeq opt define vre hello world first end...

Makefile 中 的區別

在makefile中我們經常看到 這幾個賦值運算子,那麼他們有什麼區別呢?我們來做個簡單的實驗 新建乙個makefile,內容為 ifdef define vre vre hello world else endif ifeq opt define vre hello world first end...