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/b.c ; I want the .o files to go to A/new-dir/a1.o A/new-dir/a2.o B/new-dir/b.o and so on.
例如,如果我的来源是A / a1.c,A / a2.c,B / b.c;我希望.o文件转到A / new-dir / a1.o A / new-dir / a2.o B / new-dir / b.o等等。
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. 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? How can it be done?
它会在与相应的.c文件相同的目录中创建.o文件。是否可以修改Makefile以在每个源目录中插入新目录并在那里移动.o文件?如何做呢?
Many Thanks!
2 个解决方案
#1
0
The main kernel Makefile tells of two ways of placing output elsewhere (not like you ask, but it could be useful). Look for KBUILD_OUTPUT (can be set as an environment variable or as O=where/to/put to make).
主内核Makefile讲述了将输出放在别处的两种方法(不像你问的那样,但它可能很有用)。查找KBUILD_OUTPUT(可以设置为环境变量或O = where / to / put to make)。
#2
0
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/
#1
0
The main kernel Makefile tells of two ways of placing output elsewhere (not like you ask, but it could be useful). Look for KBUILD_OUTPUT (can be set as an environment variable or as O=where/to/put to make).
主内核Makefile讲述了将输出放在别处的两种方法(不像你问的那样,但它可能很有用)。查找KBUILD_OUTPUT(可以设置为环境变量或O = where / to / put to make)。
#2
0
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/