Out-of-tree module build in a dedicated build directory.

Greg KH greg at kroah.com
Thu Mar 15 10:01:31 EDT 2018


On Thu, Mar 15, 2018 at 02:33:31PM +0100, Aleksei Fedotov wrote:
> >> It looks like passing O= or KBUILD_OUTPUT= doesn't work for out of tree modules.
> 
> > It doesn't?  It should, what is the result when you try to do that?
> 
> It is trying to use path specified in O= as path to the pre-build
> kernel and fails to find kernel scripts:
> 
> $ make V=1 -C $(KDIR) M=`pwd` O=`pwd`/build_x86
> make: Entering directory '/home/lexa/linux'
> make -C /home/lexa/module/build_x86 KBUILD_SRC=/home/lexa/linux \
> -f /home/lexa/linux/Makefile
> make[1]: Entering directory '/home/lexa/module/build_x86'
> mkdir -p /home/lexa/module/.tmp_versions ; rm -f
> /home/lexa/module/.tmp_versions/*
> 
>   WARNING: Symbol version dump ./Module.symvers
>            is missing; modules will have no dependencies and modversions.
> 
> make -f /home/lexa/linux/scripts/Makefile.build obj=/home/lexa/module
> make -f /home/lexa/linux/scripts/Makefile.build
> obj=/home/lexa/module/module1 need-builtin=1
>    rm -f /home/lexa/module/module1/built-in.o; ar rcSTPD
> /home/lexa/module/module1/built-in.o
>   gcc -Wp,-MD,/home/lexa/module/module1/.task1.o.d  -nostdinc -isystem
> /usr/lib/gcc/x86_64-linux-gnu/5/include
> -I/home/lexa/linux/arch/x86/include -I./arch/x86/include/generated
> -I/home/lexa/linux/include -I./include
> -I/home/lexa/linux/arch/x86/include/uapi
> -I./arch/x86/include/generated/uapi -I/home/lexa/linux/include/uapi
> -I./include/generated/uapi -include
> /home/lexa/linux/include/linux/kconfig.h  -I/home/lexa/module/module1
> -I/home/lexa/module/module1 -D__KERNEL__ -Wall -Wundef
> -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
> -fshort-wchar -Werror-implicit-function-declaration
> -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2
> -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
> -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
> -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time
> -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1
> -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1
> -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1
> -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1
> -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables
> -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE
> -fno-delete-null-pointer-checks -O2 --param=allow-store-data-races=0
> -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong
> -Wno-unused-but-set-variable -fno-var-tracking-assignments -g
> -gdwarf-4 -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement
> -Wno-pointer-sign -fno-strict-overflow -fno-stack-check
> -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes
> -Werror=date-time -Werror=incompatible-pointer-types
> -Werror=designated-init  -DMODULE  -DKBUILD_BASENAME='"task1"'
> -DKBUILD_MODNAME='"mod1"' -c -o /home/lexa/module/module1/.tmp_task1.o
> /home/lexa/module/module1/task1.c
> /bin/sh: 1: scripts/basic/fixdep: not found
> /home/lexa/linux/scripts/Makefile.build:316: recipe for target
> '/home/lexa/module/module1/task1.o' failed

That's the error.


> make[3]: *** [/home/lexa/module/module1/task1.o] Error 127
> /home/lexa/linux/scripts/Makefile.build:575: recipe for target
> '/home/lexa/module/module1' failed
> make[2]: *** [/home/lexa/module/module1] Error 2
> /home/lexa/linux/Makefile:1509: recipe for target
> '_module_/home/lexa/module' failed
> make[1]: *** [_module_/home/lexa/module] Error 2
> make[1]: Leaving directory '/home/lexa/module/build_x86'
> Makefile:146: recipe for target 'sub-make' failed
> make: *** [sub-make] Error 2
> make: Leaving directory '/home/lexa/linux'
> 
> 
> 
> > And do you have a pointer to your Makefile, perhaps you are doing
> > something "wrong" in it?
> 
> I don't use Makefile in my module, I solely rely only on Kbuild files.
> Is that wrong?

Yes, you should have a simple Makefile to set all of the above up for
you correctly.  You do not need any Kbuild files for an external module.
Look at one of the many examples for how to do this properly, that's the
issue here.

good luck!

greg k-h



More information about the Kernelnewbies mailing list