2011年7月4日 星期一

how to configure Kconfig and Makefile


假設我們要在kernel source下的drivers目錄下如下用於 test driver 的樹型目錄:
/driver/test/
/driver/test/Kconfig
/driver/test/Makefile
/driver/test/ *.c

除了在新driver的目錄下新增 Kconfig Makefile 檔外,新增目錄的父目錄中的 Kconfig Makefile 檔也需要修改,以使新增的 Kconfig Makefile 檔能被引用.
Kconfig 範例:

menu "Test Driver "                                           // menu上顯示的名稱
comment "Test Driver"                                     // 進入menu後的注解
config TEST                                                      // fun1
bool "TEST suport"                                          // fun1 只有yes 跟no可選
config TEST_USER                                        // fun2
tristate "TEST user-space interface"             // fun2 有yes, no , module三種可選 
depends on TEST                                           // fun2 相依於fun1
endmenu

為了使這個 Kconfig 檔能起作用,需要修改 drivers/Kconfig ,增加以下內容:
source "drivers/test/Kconfig"


在新增的 test 目錄下,另外包含 Makefile :
#drivers/test/Makefile
#
#Makefile for the TEST
#
obj-$(CONFIG_TEST) += test.o
obj-$(CONFIG_TEST_USER) += test_ioctl.o
obj-$(CONFIG_PROC_FS) += test_proc.o
obj-$(CONFIG_TEST_CPU) += cpu/
 
由於 test 目錄中包含一個子目錄 cpu ,CONFIG_TEST_CPU=y ,需要將 cpu 目錄加入列表.
test 目錄中的 cpu 目錄也需包含如下的 Makefile :
# drivers/test/cpu/Makefile
#
# Makefile for the TEST cpu
#
obj-$(CONFIG_TEST_CPU) += cpu.o
為了使得整個 test 目錄能夠被編譯命令作用到, test 目錄父目錄中的 Makefile 檔也需新增如下腳本:
obj-$(CONFIG_TEST) += test/

這樣整個工作就算完成了

沒有留言: