Find the answer to your Linux question:
Results 1 to 6 of 6
Hi.... I'm having some trouble creating the Makefile for a kernel module. Basically this module includes a few header files...which are just functions and structs and stuff. There are lots ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9

    Smile Creating Makefile for kernel module that uses a few dependencies...


    Hi....

    I'm having some trouble creating the Makefile for a kernel module. Basically this module includes a few header files...which are just functions and structs and stuff. There are lots of examples out there on how to compile a kernel module thats a single file...i.e module.c.

    But could someone show me how to create a Makefile, that for example has the files:

    module.c dep1.c dep1.h dep2.c dep2.h ......

    I'm sure its easy enough I just don't understand the way Makefiles work in 2.6.
    I could do it for 2.4.


    Thanks in advance,
    Cormac Redmond.

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    http://www.oreilly.com/catalog/linux.../book/ch02.pdf contains a brief rundown of the 2.6 build system.

  3. #3
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9
    Theres nothing in that really...

    I've no problem compiling a single filed module by the way.

    Thanks..

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! tb10alj's Avatar
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    31
    Try to use this as a template for your Makefile:

    Code:
    obj-m += my_driver.o
    
    my_driver-objs := mydriver1.o mydriver2.o
    all:
    	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    clean:
    	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

  6. #5
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9
    Thanks!

    Will that work, if for example, mydriver2.o is a dependency for mydriver1.o ?

    I'm a few hours off getting to the stage where I can test it, but thanks!


    Cormac Redmond

  7. #6
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9
    Yeah it worked nicely - thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •