1. 程式人生 > >makefile中如何判斷一個檔案是否存在

makefile中如何判斷一個檔案是否存在

               

轉載:http://blog.csdn.net/qiaoliang328/article/details/7568141

makefile判斷檔案存在如下的兩種方法:

1. 呼叫shell的函式進行判斷

exist = $(shell if [ -f $(FILE) ]; then echo "exist"; else echo "notexist"; fi;)ifeq (exist, "exist")#do something hereendif
當然,這個方法很土,但是能夠工作!!
2. 使用makefile的函式進行判斷
ifeq ($(FILE), $(wildcard $(FILE)))#do something here
endif
$(wildcard $(FILE))的意思是當前路徑下的檔名匹配FILE的檔案展開。
假設當前路徑下存在a.c 和 b.c,那麼執行src=$(wildcard *.c)
src的值就為a.c b.c;
如果不使用萬用字元,比如src=$(wildcard c.c);那麼就是要展開當前路徑下,檔名為c.c的檔案,因為當前路徑下檔案不存在,因此src為空字串。