linux-kernel – 如何在Kbuild中为生成的源文件添加依赖项?
发布时间:2020-12-14 02:14:41 所属栏目:Linux 来源:网络整理
导读:让generate_testapi.py成为我的 Linux内核模块源代码树中的一个脚本,它接收mymod_test.h并生成一个面向userland的接口源文件(ioctl,debugfs,你可以命名),然后命名为$(obj)/mymod_test_interfaces.gen .C. 在Kbuild makefile中,让mymod-y成为包含构成模块的目
让generate_testapi.py成为我的
Linux内核模块源代码树中的一个脚本,它接收mymod_test.h并生成一个面向userland的接口源文件(ioctl,debugfs,你可以命名),然后命名为$(obj)/mymod_test_interfaces.gen .C.
在Kbuild makefile中,让mymod-y成为包含构成模块的目标文件列表的变量,即 Kbuild-ish规则是如何形成的,它将生成源中的目标文件编译作为mymod的依赖关系添加,并描述生成过程. 以下,我对这样一个规则集的第一次天真尝试是行不通的. obj-m := mymod.o mymod-y := mymod_kmod.o $(obj)/mymod_test_interfaces.gen.o $(obj)/mymod_test_interfaces.gen.o: $(src)/mymod_test.h $(src)/generate_testapi.py $(src)/generate_testapi.py < $(src)/mymod_test.h > $< 试图使用它,产生的错误是,没有规则来制作mymod_test_interfaces.gen.o. 更新(由Alexandre Belloni发表评论) 是的,我也尝试了表单的生成器规则 $(obj)/mymod_test_interfaces.gen.c: $(src)/mymod_test.h $(src)/generate_testapi.py $(src)/generate_testapi.py < $(src)/mymod_test.h > $< 具有相同的结果,即它不起作用. 解决方法
还有一个问题:在尝试构建多文件模块时,您不能拥有与模块同名的C文件.将mymod.c重命名为mymod-core.c
然后,以下应该工作: obj-m := mymod.o mymod-objs := mymod-core.o mymod_test_interfaces.gen.o $(obj)/mymod_test_interfaces.gen.c: $(src)/mymod_test.h $(src)/generate_testapi.py $(src)/generate_testapi.py < $(src)/mymod_test.h > $@ 我实际上测试了以下内容: diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 4387ccb79e64..47fdc3a73c75 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -71,3 +71,8 @@ OBJCOPYFLAGS_lkdtm_rodata_objcopy.o := --rename-section .text=.rodata $(obj)/lkdtm_rodata_objcopy.o: $(obj)/lkdtm_rodata.o $(call if_changed,objcopy) + +obj-m := mymod.o +mymod-objs := mymod-core.o mymod_test_interfaces.gen.o +$(obj)/mymod_test_interfaces.gen.c: + echo "int variable;" > $@ diff --git a/drivers/misc/mymod-core.c b/drivers/misc/mymod-core.c new file mode 100644 index 000000000000..b39aa4b9ae8d --- /dev/null +++ b/drivers/misc/mymod-core.c @@ -0,0 +1,19 @@ +#include <linux/module.h> +#include <linux/platform_device.h> + +extern int mymod_variable; + +static int mymod_probe(struct platform_device *pdev) +{ + mymod_variable = 2; + + return 0; +} + +static struct platform_driver mymod_driver = { + .driver = { + .name = "mymod",+ },+ .probe = mymod_probe,+}; +module_platform_driver(mymod_driver); 它恰当地导致: $make CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CHK include/generated/bounds.h CHK include/generated/timeconst.h CHK include/generated/asm-offsets.h CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC [M] drivers/misc/mymod-core.o echo "int variable;" > drivers/misc/mymod_test_interfaces.gen.c CC [M] drivers/misc/mymod_test_interfaces.gen.o LD [M] drivers/misc/mymod.o LD arch/x86/boot/compressed/vmlinux ZOFFSET arch/x86/boot/zoffset.h AS arch/x86/boot/header.o LD arch/x86/boot/setup.elf OBJCOPY arch/x86/boot/setup.bin OBJCOPY arch/x86/boot/vmlinux.bin BUILD arch/x86/boot/bzImage (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |