简体   繁体   中英

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.

For example, if my sources are 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.

My current Makefile is like this:

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?

Many Thanks!

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).

Yes you can do it in makefile like below

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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