Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! probe's Avatar
    Join Date
    Oct 2009
    Belgrade, Serbia

    Angry Makefile for kernel modules

    Dear all,

    I have a question about kernel modules compilation. I understand the
    way how make/Makefile works,
    for example if I have two source files, hexdump3.asm and textlib.asm,
    my Makefile will look like this:
    hexdump3: hexdump3.o
    ld -o hexdump3 hexdump3.o textlib.o
    hexdump3.o: hexdump3.asm
    nasm -f elf -g -F stabs hexdump3.asm
    textlib.o: textlib.asm
    nasm -f elf -g -F stabs textlib.asm
    and I understand how this works, it goes bottom up, building dependencies first.

    But if I have two kernel modules source files, for example, start.c
    and stop.c, my Makefile will look like this:
    obj-m += startstop.o
    startstop-objs := start.o stop.o

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    But this does not work on my machine, it runs without errors but does
    not produce startstop.ko file.
    Also, when I run make on my machine, first line that appears is:
    make -C /lib/modules/
    M=/home/maiev/work/modules/parts modules

    So, does anybody know what are lines for manual kernel module
    compilation using probably gcc,
    without 'obj-m +=' or at least how Makefile should look for multiple
    kernel module source files ???

    Kind regards

    Dragoslav Zaric

    Professional Programmer
    MSc Astrophysics

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    See my answer to your other post regarding kernel make files. Since you are obviously building your own kernel module, you should look at the makefiles of other drivers/modules to use as a template. Also, you will need to make them available to the configuration tools in the master kernel makefile if you want it to be built with the kernel. On the other hand, if you are just building a kernel module that you can manually load/unload into the kernel, then you should read one of the recent kernel programming books that are available which go into these issues in some detail.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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