Compiling a kernel module outside the tree with any tree of kernel sources in the file system

I am trying to compile a module with any source tree in the file system, but I am having problems with the Makefile. This was the original Makefile I had against the specified kernel:

obj-m += new-mod.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

This Makefile will compile correctly, but the goal is to compile it against any source tree. I tried just:

obj-m += new-mod.o

I thought everything was supposed to be, but I get the error:

make: *** No targets.  Stop.

I also added:

all: 

in the Makefile no difference except for the error message:

make: Nothing to be done for `all'

I tried a lot of documentation but no luck. I would really appreciate any help.

+5
1

goal is to have it compile against any source tree

, , compiled source-code path

make -C /lib/modules/$(shell uname -r)/build M=$PWD modules

make -C <path-to-compiled-src-code> M=$PWD modules

make -C /home/vinay/linux-3.9 M=$PWD modules

makefile

Makefile -

# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m := new-mod.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
  else
    KERNEL_SOURCE := /usr/src/linux
    PWD := $(shell pwd)
default:
      ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
      ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif

KERNEL_SOURCE := /usr/src/linux → .--> sr- KERNEL_SOURCE := <path to compiled-src-code>

,

/lib/modules?

Linux

Linux

+9

Source: https://habr.com/ru/post/1531474/


All Articles