內核驅動編譯之Makefile shell pwd路徑問題


一般我們在寫Makefile的時候為了獲取到當前Makefile所在的文件夾路徑,會使用TopDIR ?= $(shell pwd)來定義,后續的文件路徑都是基於此TopDIR基礎上使用。

今天在移植一個rtl8822bu的wifi驅動到平台上編譯的時候出現錯誤,

drivers/net/wireless/rtl8822bu/Makefile:809: /home/liuxueneng/workCode/allwinner_h2_2018-0907/lichee/linux-4.4/rtl8822b.mk: No such file or directory

找不到lichee/linux-4.4/rtl8822b.mk這個文件

打開Makefile看一下,


806 ########### HAL_RTL8822B 807 ################################# 808 ifeq ($(CONFIG_RTL8822B), y) 809 include $(TopDIR)/rtl8822b.mk 810 endif

出錯的地方正式使用了TopDIR的路徑,Makefile的本意是包含當前驅動文件夾下(rtl8822bu)的rtl8822b.mk文件,現在編譯的時候卻找到了linux-4.4的目錄下,說明使用pwd獲取到的就是linux-4.4的目錄,換句話說這個Makefile在linux-4.4目錄下面被調用執行。

現在要修正這個路徑獲取問題,

仔細看了下這個Makefile,后面還涉及到文件路徑指定使用的參考路徑 src變量,但是這個變量不是自己定義的,說明是環境別人傳遞進來的

                                                                              
 242                                                                               
 243 EXTRA_CFLAGS += -I$(src)/platform                                             
 244 _PLATFORM_FILES := platform/platform_ops.o                                    
 245                                                                               
 246 EXTRA_CFLAGS += -I$(src)/hal/btc 

於是把TopDIR也換成這個src,驗證了一下編譯通過。

TopDIR ?= $(src)

這個src是從linux-4.4/scripts/Makefile.modsign 傳進來的。

   1 # ==========================================================================  
   2 # Signing modules                                                             
   3 # ==========================================================================  
   4                                                                               
   5 PHONY := __modsign                                                            
   6 __modsign:                                                                    
   7                                                                               
   8 include scripts/Kbuild.include                                                
   9                                                                               
  10 __modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
  11 modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))               
  12                                                                               
  13 PHONY += $(modules)                                                           
  14 __modsign: $(modules)                                                         
  15         @:                                                                    
  16                                                                               
  17 quiet_cmd_sign_ko = SIGN [M] $(2)/$(notdir $@)                                
  18         cmd_sign_ko = $(mod_sign_cmd) $(2)/$(notdir $@)                       
  19                                                                               
  20 # Modules built outside the kernel source tree go into extra by default       
  21 INSTALL_MOD_DIR ?= extra                                                      
  22 ext-mod-dir = $(INSTALL_MOD_DIR)$(subst $(patsubst %/,%,$(KBUILD_EXTMOD)),,$(@D))
  23                                                                               
  24 modinst_dir = $(if $(KBUILD_EXTMOD),$(ext-mod-dir),kernel/$(@D))              
  25                                                                               
  26 $(modules):                                                                   
  27         $(call cmd,sign_ko,$(MODLIB)/$(modinst_dir))                          
  28                                                                               
  29 # Declare the contents of the .PHONY variable as phony.  We keep that         
  30 # information in a variable se we can use it in if_changed and friends.       
  31                                                                               
  32 .PHONY: $(PHONY) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM