2013-03-03 64 views
0

這是一種愚蠢的問題,但這是我第一次使用Makefile。 我在選擇文件時遇到問題。當我使用這個命令時,如何用Makefile選擇* .c文件?

target1: 

    $(CC) -o target *.c 

它運行良好。 但這不起作用,

SRCS = dir1/*.c 
target1: 

    $(CC) -o target $(SRCS) 

並吐出此錯誤。

clang: error: no such file or directory: 'dir1/*.c' 

顯然這是因爲我的變量SRCS在通過之前已經轉義了。 我該如何讓Makefile傳遞字符串?還是有另一種傳統/設計的方式來做到這一點? (通過模式選擇文件)

+0

你可能會在這裏http://stackoverflow.com找到答案/問題/ 1139271/makefile文件與 - 源文件正在不同的目錄 – A4L 2013-03-03 00:09:07

回答

1

可以使用wildcard關鍵字來選擇所有匹配特定模式像這樣的文件:

SRCS = $(wildcard dir1/*.c) 
target1: 

    $(CC) -o target $(SRCS) 
1
SRCS := $(shell echo dir1/*.c) 
target1: 
    $(CC) -o target $(SRCS)