linux載入驅動的兩種makefile檔案

來源:互聯網
上載者:User


linux載入驅動的兩種makefile檔案 載入驅動過程中,需要個Makefile檔案來完成編譯的命令。自己經常把把Makefile裡面的命令搞混,這次,專門的研究了一下Makefile檔案裡面的東東,特寫出來和大家分享一下 一 一個簡單的驅動程式例子:  www.2cto.com  [plain] /*======================================================================      A kernel module: book      This example is to introduce module params                 The initial developer of the original code is Baohua Song      <author@linuxdriver.cn>. All Rights Reserved.  ======================================================================*/  #include <linux/init.h>                                  #include <linux/module.h>                                  MODULE_LICENSE("Dual BSD/GPL");                                    www.2cto.com                              static char *book_name = "dissecting Linux Device Driver";                static int num = 4000;                                                                    static int book_init(void)                                  {                                      printk(KERN_INFO " book name:%s\n",book_name);                              printk(KERN_INFO " book num:%d\n",num);                                     return 0;                                  }                                  static void book_exit(void)                                  {                                      printk(KERN_INFO " Book module exit\n ");                              }                                  module_init(book_init);                                  module_exit(book_exit);                                  module_param(num, int, S_IRUGO);                                  module_param(book_name, charp, S_IRUGO);                                    MODULE_AUTHOR("Song Baohua, author@linuxdriver.cn");  MODULE_DESCRIPTION("A simple Module for testing module params");  MODULE_VERSION("V1.0");  二 Makefile檔案有兩種寫法:  一種是: [html] # Add your debugging flag (or not) to CFLAGS  ifneq ($(KERNELRELEASE),)      obj-m := boot.o  else      KERNELDIR ?= /lib/modules/$(shell uname -r)/build      PWD := $(shell pwd)  default:      $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  endif    www.2cto.com  另外一種是:[plain] # Add your debugging flag (or not) to CFLAGS  ifneq ($(KERNELRELEASE),)      obj-m := boot.o  else      KERNELDIR ?= /usr/src/linux-headers-2.6.38-8-generic      PWD := $(shell pwd)  default:      $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  endif   比較兩者可以發現,該兩個Makefile的唯一差別是KERNELDIR的不同

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.