【问题标题】:how to run perl in kbuild makefile如何在 kbuild makefile 中运行 perl
【发布时间】:2019-12-15 18:44:19
【问题描述】:

我正在尝试向当前版本添加新功能。要编译,我已将 obj-y += mynewfeature.c 添加到同一目录中的 makefile 中。但我仍然需要使用同一目录中的 perl 脚本生成或更新现有的头文件。我无法处理的问题是如何从 kbuild 文件中调用这个 perl 脚本。似乎 makefile 无法找到 perl 脚本的正确路径。那么我应该在 kbuild 文件的顶部添加什么来调用这个 perl 脚本文件

谢谢

dir
 |- mynewfeature.c
 |- generator.pl
 |- some_template //perl script will read this file and generate a header file
 |- Makefile

Makefile:
code_to_call_perl_script // how to write this line
obj-y += mynewfeature.o

我试过 Ian 的代码,perl 脚本甚至没有执行。那么有没有办法强制执行 perl?

【问题讨论】:

  • 你尝试$(shell perl_script)调用脚本了吗?
  • @kurtfu 是的,但困扰我的是我不知道如何获得正确的文件路径,运行此命令失败,没有此类文件或目录错误
  • 您从 Makefile 调用脚本的确切命令是什么?还有其他 perl 脚本吗?如果没有,也许你可以使用find 命令来获取确切的路径?

标签: perl makefile linux-kernel


【解决方案1】:

Makefile 规则应该是这样的:

obj-y += mynewfeature.o

# Add dependency: mynewfeature.o depends on generated header mynewheader.h.
# Note: Generated sources go in $(obj).
$(obj)/mynewfeature.o: $(obj)/mynewheader.h

# Add rule to generate the header file mynewheader.h.
# It depends on the script and the template file.
# Note: Generated sources go in $(obj).
$(obj)/mynewheader.h: $(src)/generator.pl $(src)/some_template
    # (I don't know the exact command you use, but here is an example)
    $(PERL) -s $(src)/generator.pl $(src)/some_template > $@

# Allow generated header file to be cleaned by "make clean".
clean-files := mynewheader.h

参考:Special Rules in Linux Kernel Makefiles in Kernel Build System in The Linux Kernel documentation

具体例子见drivers/scsi/Makefile中“53c700_d.h”的生成。

【讨论】:

  • 似乎 $(src) 不是指向当前文件夹,而是它的父文件夹和 out/target 文件夹。是否可以强制在当前文件夹中执行 makefile?谢谢
猜你喜欢
  • 2015-06-21
  • 2016-01-21
  • 2013-06-14
  • 2010-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-07
相关资源
最近更新 更多