1

Is it possible to provide an output folder when building a kernel module? These questions are very similar to mine but the answers are non conclusive Link1, Link2 (I have tested these proposals without success).

I have the following project structure and would like to put all outputs from the compiling of the kernel module into the build folder.

Makefile
src/
   -main.c
build/

This is my current Makefile:

# name of the module to be built
MODULE_NAME ?= test_module

BASE := .
# define all module sources
SRCS :=                                 \
    src/main.c                          

# extract required object files
OBJ_SRCS :=  $(SRCS:.c=.o)

# define path to directories containing header files
INCLUDE_DIRS =                          \
    -I$(src)/src                        

# Products from the 'make all' command should be placed in this folder
BUILD_DIR := $(BASE)/build

# ccflags to pass at compile time
ccflags-y :=                            \
    $(INCLUDE_DIRS)                     

# setup kbuild stuff
obj-m += $(MODULE_NAME).o
$(MODULE_NAME)-y := $(OBJ_SRCS)

$(MAKE) = make
KERNEL_DIR=/lib/modules/$(shell uname -r)/build

all:
    $(MAKE) -C $(KERNEL_DIR)  M=$(PWD) modules
clean:
    $(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean

I have tried to add O=$(BUILD_DIR) as (as stated in the link above without success).

$(MAKE) -C $(KERNEL_DIR) O=$(BUILD_DIR) M=$(PWD) modules

Can anyone confirm if it is possible to redirect to output(the files generated during the compilation) when compiling the kernel module or not? (A suggestion would be much appreciated)

Is the only solution to put the Makefile in the build folder and update the all paths in the Makefile?

Thanks!

Community
  • 1
  • 1
Henrik
  • 405
  • 1
  • 8
  • 19

0 Answers0