Skip to contentSkip to conversation

M= modules build w/ objects in different directory

DISCUSSION Daniel Walker (danielwa) 2 participants 4 messages Mar 19, 2024 – Mar 30, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

Masahiro,

I found this commit,

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23a0cb8e3225122496bfa79172005c587c2d64bf

It had this note,

[masahiro: I do not think "M=$(OUT_DIR) src=$(PWD)" is the official way, but this patch is a nice clean up anyway.]

Is there an official way or recommended way to build objects in a directory outside the external modules source directory and outside the original kernel source directory ?

Daniel

#1 lore raw
Quoted 10 lines · Daniel Walker (danielwa)

Masahiro,

I found this commit,

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23a0cb8e3225122496bfa79172005c587c2d64bf

It had this note,

Quoted 8 lines

[masahiro: I do not think "M=$(OUT_DIR) src=$(PWD)" is the official way, but this patch is a nice clean up anyway.]

Is there an official way or recommended way to build objects in a directory outside the external modules source directory and outside the original kernel source directory ?

Daniel

There is no official way.
One known tip is to use a relative path for M=.

For example, the relative path from your kernel source to your external module directory is ../path/to/module

 $ make O=path/to/output  M=../path/to/module

The module objects will be output into
path/to/output/../path/to/module/.

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
Quoted 25 lines · Masahiro Yamada
Quoted 10 lines · Daniel Walker (danielwa)

Masahiro,

I found this commit,

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23a0cb8e3225122496bfa79172005c587c2d64bf

It had this note,

Quoted 8 lines

[masahiro: I do not think "M=$(OUT_DIR) src=$(PWD)" is the official way, but this patch is a nice clean up anyway.]

Is there an official way or recommended way to build objects in a directory outside the external modules source directory and outside the original kernel source directory ?

Daniel

There is no official way.
One known tip is to use a relative path for M=.

Quoted 8 lines

For example, the relative path from your kernel source to your external module directory is ../path/to/module

 $ make O=path/to/output  M=../path/to/module

The module objects will be output into
path/to/output/../path/to/module/.

It seems that this does place objects into the output directory, but there is an issue where the build system expects include files to exist inside the output directory as well. For example if the modules includes linux/module.h this file exists and is found, but module.h also includes asm/rwonce.h which is not found. I think it's located in include/asm-generic/rwonce.h . I think these asm location are linked or added as special -I additions during the build but using O= results in these asm directories not appearing to exist correctly.

Daniel

#3 lore raw
Quoted 44 lines · Daniel Walker (danielwa)
Quoted 25 lines · Masahiro Yamada
Quoted 10 lines · Daniel Walker (danielwa)

Masahiro,

I found this commit,

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23a0cb8e3225122496bfa79172005c587c2d64bf

It had this note,

Quoted 8 lines

[masahiro: I do not think "M=$(OUT_DIR) src=$(PWD)" is the official way, but this patch is a nice clean up anyway.]

Is there an official way or recommended way to build objects in a directory outside the external modules source directory and outside the original kernel source directory ?

Daniel

There is no official way.
One known tip is to use a relative path for M=.

Quoted 8 lines

For example, the relative path from your kernel source to your external module directory is ../path/to/module

 $ make O=path/to/output  M=../path/to/module

The module objects will be output into
path/to/output/../path/to/module/.

It seems that this does place objects into the output directory, but there is an issue where the build system expects include files to exist inside the output directory as well. For example if the modules includes linux/module.h this file exists and is found, but module.h also includes asm/rwonce.h which is not found. I think it's located in include/asm-generic/rwonce.h . I think these asm location are linked or added as special -I additions during the build but using O= results in these asm directories not appearing to exist correctly.

Quoted 1 line

Daniel

To use this workaround, you need to build the kernel with O= first.

asm/rwonce.h is a generated header, and exists in
the output directory specified with O=.

  # configure and build the kernel
  $ make O=path/to/output defconfig
  $ make O=path/to/output
  # build the module
  $ make O=path/to/output  M=../path/to/module
Signature · 2 lines
Best Regards
Masahiro Yamada