linux下的hello_world驅動的Makefile

            學習linux驅動編寫的第一步應該就是helloworld了。但是這個helloworld卻比起我所見過的其他的helloworld要困難的多。

             其中最困難的就是hellowolrd的編譯。書上都寫了很多makefile,但是在我這裏就是行不通。不是因爲他們不對,而是我的使用不對。下面就對具體的使用過程做出說明。

             hello.c的內容在這裏就不說了,主要講一下Makefile。

# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)

 obj-m := hello.o 
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else

 KERNELDIR ?= /lib/modules/$(shell uname -r)/build
 PWD := $(shell pwd) 
default:
 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif 

             注意1:obj-m,KERNELDIR,PWD,$(MAKE)這些前面必須要使用TAB鍵。

        注意2:obj-m :=hello.o這裏的hello必須要和C文件的文件名一致,否則就會報錯。

        我遇到的問題就這兩個,比較基礎,也比較容易被初學者所忽視。做下記錄供大家參考。

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