Is it possible to compile a kernel module without a makefile and if so, how?

  • 2
    Certainly yes, because make is simply running commands (e.g. compilation commands) described by the Makefile/ – Basile Starynkevitch Sep 23 '15 at 10:11

No, that is not possible because the kernel Makefile that you have to use to compile a module has to call another Makefile defining obj-m.

The usual Makefile for an out of tree module loks like that:

obj-m := mymodule.o
KDIR := /lib/modules/`uname -r`/build

        $(MAKE) -C $(KDIR) M=$$PWD

The first time it is called, KERNELRELEASE is not defined, it will then call the kernel Makefile with the M=$$PWD parameter. Finally, the kernel Makefile will use M, finding and calling the module Makefile again, this time with KERNELRELEASE defined and obj-m will get filled. The module will then be compiled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.