Redirecting output of linux module build

2019-08-12 05:27发布

问题:

I'd like to redirect the output of my module build to segregate the artifacts from the source.

My makefile looks like:

    obj-m += hello-1.o

all:
    make ARCH=arm CROSS_COMPILE=arm-eabi- -C /work/TI-Android-ICS-4.0.3_AM37x_3.0.0/kernel M=$(PWD) modules

clean:
    make ARCH=arm CROSS_COMPILE=arm-eabi- -C /work/TI-Android-ICS-4.0.3_AM37x_3.0.0/kernel M=$(PWD) clean

This works correctly, except that the module output happens to be in my source directory. I tried adding O={path to my output dirctory} in each line, but then it failed to build with something like...

ERROR: Kernel configuration is invalid. include/generated/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it.

WARNING: Symbol version dump /work/development/linux/driver/blah/Module.symvers is missing; modules will have no dependencies and modversions.

I assume this stems from the fact that there is some output file from the kernel build that's used in the module build, and changing the output directory with "O=" collides with that.

Is there a method for accomplishing this using the existing build infrastructure?

回答1:

Looking at the documentation for the module system, it doesn't look good. Perhaps you can copy .config into your build directory and do a make oldconfig && make modules-prepare with O= set.


Alternatively, what happens if you run make from another directory?

/somewhere/else$ make -C /path/to/kernel ARCH=arm CROSS_COMPILE=arm-eabi- M=/your/module/dir modules


回答2:

This Makefile will solve your query

 obj-m += hello-1.o

all:
make ARCH=arm CROSS_COMPILE=arm-eabi- -C /work/TI-Android-ICS-4.0.3_AM37x_3.0.0/kernel M=$(PWD) modules_install INSTALL_MOD_PATH=<output directory for modules>

clean:
make ARCH=arm CROSS_COMPILE=arm-eabi- -C /work/TI-Android-ICS-4.0.3_AM37x_3.0.0/kernel M=$(PWD) clean