By: fu linux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!
简要说明
我们经常在一些bb文件中看到require、DEPENDS、inherit等关键词,不知道你有没有总结出他们分别如何使用呢?
先看下面的例子:
在meta/recipes-kernel/linux/linux-yocto.inc文件中有:
inherit kernel
inherit kernel-yocto
- 1
- 2
在meta/recipes-kernel/linux/linux-yocto_5.4.bb文件中有:
require recipes-kernel/linux/linux-yocto.inc
...
DEPENDS += "openssl-native util-linux-native"
- 1
- 2
- 3
其中openssl-native对应的bb文件就是
meta/recipes-connectivity/openssl/openssl_1.1.1g.bb
- 1
可能你已经悟出什么了~
inherit关键词
继承一个或多个class类,通常就是继承bbclass文件的类,主要是一些函数或者任务。
比如上面的
inherit kernel
inherit kernel-yocto
- 1
- 2
继承的的就是meta/classes/kernel.bbclass和meta/classes/kernel-yocto.bbclass文件。
kernel_do_compile()
do_compile_kernelmodules()
addtask compile_kernelmodules after do_compile before do_strip
kernel_do_install()
...
- 1
- 2
- 3
- 4
- 5
总之,如果是引用bbclass文件的内容,使用inherit关键词声明。
tips: 如果是在conf文件中继承class,用大写的INHERIT
require关键词
有些通用的recipe比如kernel适用于多个平台,可能仅仅是版本或者一些变量上有些差异,于是将一些共性的东西,比如linux kernel下载地址编译选项和依赖的recipes或者命名规则等放到一个共有的文件,这个就是inc头文件,比如上面提及的meta/recipes-kernel/linux/linux-yocto.inc文件。
其他的linux的bb文件,想要使用linux-yocto.inc文件的内容,就可以通过下面的方式引用:
require recipes-kernel/linux/linux-yocto.inc
- 1
省去了很多不必要的冗余编程。
总之,如果是引用inc文件的内容,使用require关键词声明。
DEPENDS关键词
很多的recipes文件中可以看到DEPENDS关键词,主要是用来告知当前的recipe依赖其他的recipe。
打个比方说你有个程序foo,需要依赖bar库和baz库,那么必然有这三个bb文件:
meta-*/recipes-*/foo_*.bb
meta-*/recipes-*/bar_*.bb
meta-*/recipes-*/baz_*.bb
- 1
- 2
- 3
其中在meta- /recipes- /foo_*.bb文件中有这样的声明:
DEPENDS = "bar"
DEPENDS_append = "baz"
或者这样:
DEPENDS = "bar"
DEPENDS += "baz"
或者这样:
DEPENDS = "bar baz"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
总之,如果是需要依赖其他的bb文件,使用DEPENDS关键词声明。
可以帮我点个赞吗