2009年8月16日 星期日

makefile for u-boot image

在等compile的時候 我將寫了一個u-boot script的makefile
就順便當作我看makefile manual的筆記吧
tftpDirectory := /var/lib/tftpboot
uBootImage := nfsLinux.img hdLinux.img

.PHONY : all clean
all: $(uBootImage)
@echo "finish make u-boot image"

$(uBootImage) : %.img : %
mkimage -T script -C none -n "set $<" -d $< $@
cp $@ $(tftpDirectory)

clean:
rm *.img
rm $(tftpDirectory)/*.img
一開始定義兩個variable 這裡定義的方式是用:= 這表示是立即要輸入進去兩個variable
接下來出現.PHONY這是代表後面寫得clean跟all 是特別的字
寫all跟clean的意義是要跟make說
不會因為檔案名稱是clean跟all存在檔案系統中 就根據檔案系統中的clean跟all的時間來決定是不是要執行下面的指令
接下來的all是在所有u-boot image都要執行完 才執行的 這裡只是輸出一些結束資訊

接下這行是根據每個不同的img 各自執行自己對應的command
這裡用的是makefile中的static pattern rule這就去查makefile的manual
重要的是他的command用了$<$@
$<這是指:過來的第一個名稱也就是這裡%所代表的東西
$@這是指:左邊的檔名也就是nfsLinux.img或hdLinux.img

這裡還要注意的是當reference的時候要記得要家括號 也就是要打$(tftpDirectory)不能打$tftpDirectory
大致上就是這些

沒有留言:

張貼留言