Makefile 小記

1.關於makefile變量賦值

+= := ?= =

http://stackoverflow.com/questions/448910/makefile-variable-assignment

2.makefile提供若干函數:

  subst patsubst shell if foreach origin sort filter filter_out findstring strip word words firstword wordlist dir basename call etc.......

詳細參考: http://wiki.ubuntu.org.cn/%E8%B7%9F%E6%88%91%E4%B8%80%E8%B5%B7%E5%86%99Makefile:%E4%BD%BF%E7%94%A8%E5%87%BD%E6%95%B0

--------------------------------------------------- 分割線  ---------------------------------------------------

3.自動生成文件依賴 :

-include $(OBJS:.o=.d)

%.d:%.c
  @set -e; \
  rm -f $@; \
  $(CC) -MM $< $(INCLUDEFLAGS) > $@.$$$$; \
  sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  rm -f $@.$$$$

4.makefile 中文件依賴可以分成多個行寫

$(TARGET): $(LIBS)

$(TARGET): %: %.o
  $(CC) $(CFLAGS) $< -o $@ $(LIBS)

但是最好只有一個依賴附帶執行命令序列,不然會給出警告.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章