Makefile不是Make Loveweb
從前在學校,混了四年,沒有學到任何東西,天天就是逃課,上網,玩遊戲,睡覺。畢業的時候,人家跟我說Makefile我徹底不知,可是一說Make Love我就來勁了,如今想來依然以爲丟人。學習
絕不誇張地說,Kconfig和Makefile是咱們瀏覽內核代碼時最爲依仗的兩個文件。基本上,Linux內核中每個目錄下邊都會有一個Kconfig文件和一個Makefile文件。 對於一個但願可以在Linux內核的汪洋代碼裏看到一絲曙光的人來講,將它們放在怎麼重要的地位都不過度。this
咱們去香港,經過海關的時候,總會有免費的地圖和各類指南拿,有了它們在手裏咱們纔不至於無頭蒼蠅般迷惘的行走在陌生的街道上。即便在內地出去旅遊的時候通常來講也老是會首先找份地圖,固然了,這時就是要去買了,拿是拿不到的,不一樣的地方有不一樣的特點, 只不過有的特點是服務,有的特點是索取。spa
Kconfig和Makefile就是Linux Kernel迷宮裏的地圖。地圖引導咱們去認識一個城市,而Kconfig和Makefile則可讓咱們瞭解一個Kernel目錄下面的結構。咱們每次瀏覽kernel尋找屬於本身的那一段代碼時,都應該首先看看目錄下的這兩個文件。debug
利用Kconfig和Makefile尋找目標代碼code
就像利用地圖尋找目的地同樣,咱們須要利用Kconfig和Makefile來尋找所要研究的目標代碼。遊戲
好比咱們打算研究U盤驅動的實現,由於U盤是一種storage設備,因此咱們應該先進入到drivers/usb/storage/目錄。可是該目錄下的文件不少,那麼究竟哪些文件纔是咱們須要關注的?這時就有必要先去閱讀Kconfig和Makefile文件。get
對於Kconfig文件,咱們能夠看到下面的選項。flash
34 config USB_STORAGE_DATAFAB
35 bool "Datafab Compact Flash Reader support (EXPERIMENTAL)"
36 depends on USB_STORAGE && EXPERIMENTAL
37 help
38 Support for certain Datafab CompactFlash readers.
39 Datafab has a web page at <http://www.datafabusa.com/>.產品
顯然,這個選項和咱們的目的沒有關係。首先它專門針對Datafab公司的產品,其次雖然CompactFlash reader是一種flash設備,但顯然不是U盤。由於drivers/usb/storage目錄下的代碼是針對usb mass storage這一類設備,而不是針對某一種特定的設備。U盤只是usb mass storage設備中的一種。再好比:
101 config USB_STORAGE_SDDR55
102 bool "SanDisk SDDR-55 SmartMedia support (EXPERIMENTAL)"
103 depends on USB_STORAGE && EXPERIMENTAL
104 help
105 Say Y here to include additional code to support the Sandisk SDDR-55
106 SmartMedia reader in the USB Mass Storage driver.
很顯然這個選項是有關SanDisk產品的,而且針對的是SM卡,一樣不是U盤,因此咱們也不須要去關注。
事實上,很容易肯定,只有選項CONFIG_USB_STORAGE纔是咱們真正須要關注的。
9 config USB_STORAGE
10 tristate "USB Mass Storage support"
11 depends on USB && SCSI
12 ---help---
13 Say Y here if you want to connect USB mass storage devices to your
14 computer's USB port. This is the driver you need for USB
15 floppy drives, USB hard disks, USB tape drives, USB CD-ROMs,
16 USB flash devices, and memory sticks, along with
17 similar devices. This driver may also be used for some cameras
18 and card readers.
19
20 This option depends on 'SCSI' support being enabled, but you
21 probably also need 'SCSI device support: SCSI disk support'
22 (BLK_DEV_SD) for most USB storage devices.
23
24 To compile this driver as a module, choose M here: the
25 module will be called usb-storage.
接下來閱讀Makefile文件。
0 #
1 # Makefile for the USB Mass Storage device drivers.
2 #
3 # 15 Aug 2000, Christoph Hellwig
4 # Rewritten to use lists instead of if-statements.
5 #
6
7 EXTRA_CFLAGS := -Idrivers/scsi
8
9 obj-$(CONFIG_USB_STORAGE) += usb-storage.o
10
11 usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o
12 usb-storage-obj-$(CONFIG_USB_STORAGE_USBAT) += shuttle_usbat.o
13 usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o
14 usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o
15 usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o
16 usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o
17 usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o
18 usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
19 usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
20 usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o
21 usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
22 usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o
23
24 usb-storage-objs := scsiglue.o protocol.o transport.o usb.o /
25 initializers.o $(usb-storage-obj-y)
26
27 ifneq ($(CONFIG_USB_LIBUSUAL),)
28 obj-$(CONFIG_USB) += libusual.o
29 endif
前面經過Kconfig文件的分析,咱們肯定了只須要去關注CONFIG_USB_STORAGE選項。在Makefile文件裏查找CONFIG_USB_STORAGE,從第9行得知,該選項對應的模塊爲usb-storage。
由於Kconfig文件裏的其餘選項咱們都不須要關注,因此Makefile的11~22行能夠忽略。第24行意味着咱們只須要關注scsiglue.c、protocol.c、transport.c、usb.c、initializers.c以及它們同名的.h頭文件。
Kconfig和Makefile很好的幫助咱們定位到了所要關注的目標,就像咱們到一個陌生的地方要隨身攜帶地圖,當咱們學習Linux內核時,也要謹記尋求Kconfig和Makefile的幫助。