简体   繁体   English

如何在从多个目录/文件编译内核模块的同时创建新目录并向其中移动.o文件

[英]How to create new directories and move .o files to it while compiling a kernel module from multiple directories/files

I'm trying to build a kernel module from files in multiple directories. 我正在尝试从多个目录中的文件构建内核模块。 I want to place the resulting .o files in new directories, created corresponding to each source directories. 我想将生成的.o文件放在与每个源目录相对应的新目录中。

For example, if my sources are A/a1.c , A/a2.c , B/bc ; 例如,如果我的来源是A / a1.c,A / a2.c,B / bc; I want the .o files to go to A/new-dir/a1.o A/new-dir/a2.o B/new-dir/bo and so on. 我希望.o文件转到A / new-dir / a1.o A / new-dir / a2.o B / new-dir / bo等。

My current Makefile is like this: 我当前的Makefile是这样的:

obj-m += foo.o

lavya-objs := lavya_module1.o  lavya_module2.o

lavya-objs += $(A_DIR)/a1.o $(A_DIR)/a2.o $(B_DIR)/b.o 


all: 

        make -C $KERNEL_PATH  M=$(PWD) modules

and it creates .o files in the same directories as the corresponding .c files. 并在与相应.c文件相同的目录中创建.o文件。 Is it possible to modify the Makefile to insert a new directory in each of the source directories and move the .o files there instead? 是否可以修改Makefile在每个源目录中插入一个新目录,然后将.o文件移动到那里? How can it be done? 如何做呢?

Many Thanks! 非常感谢!

The main kernel Makefile tells of two ways of placing output elsewhere (not like you ask, but it could be useful). 主内核Makefile讲述了两种将输出放置到其他位置的方法(虽然不像您所要求的那样,但这可能很有用)。 Look for KBUILD_OUTPUT (can be set as an environment variable or as O=where/to/put to make). 查找KBUILD_OUTPUT(可以设置为环境变量,也可以设置为O =在何处/要放置/放置)。

Yes you can do it in makefile like below 是的,您可以在makefile中执行以下操作

obj-m += foo.o

lavya-objs := lavya_module1.o  lavya_module2.o

lavya-objs += $(A_DIR)/a1.o $(A_DIR)/a2.o $(B_DIR)/b.o 


all: 
    make -C $KERNEL_PATH  M=$(PWD) modules
    mkdir -p $(A_DIR)/objs && mv $(A_DIR)/*.o $(A_DIR)/objs/
    mkdir -p $(B_DIR)/objs && mv $(B_DIR)/*.o $(B_DIR)/objs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM