如何根据 menuconfig 标志修改 post-build 脚本中的文件?

How to modify files in post-build script depending on a menuconfig flag?

我需要在 Buildroot 编译之后和根据 menuconfig 创建 rootfs 之前找到 modify/edit 给定文件的方法 标记 selection。我可以在 Buildroot 文档中找到可以通过使用 post-build 脚本来做到这一点。

我的问题是,只有当我在 menuconfig 中 select 编辑某些内容时,我才会执行脚本操作,例如:

(x) Enable my_login_system;

如果我selectmy_login_system,那么我需要更改nsswitch.conf文件根据:

passwd:        my_login files

如果我在 menuconfig 中没有 select "my_login_system",那么 nsswitch.conf 应该是:

passwd:        files my_login

所以,我的主要问题是如何知道 "my_login_system" 是否在 post-build 脚本中被 select 编辑。

当执行 post-build 脚本时,它可以访问 BR2_CONFIG 环境变量,该变量包含 Buildroot .config 文件的路径。您的脚本可以解析该文件并采取相应行动。

因此你可能会遇到这样的情况:

if grep -q ^BR2_MY_LOGIN_SYSTEM=y ${BR2_CONFIG}
then
    # do some tweaks
else
    # do other tweaks
fi

或者,您可以使用 BR2_ROOTFS_POST_SCRIPT_ARGS 配置变量将任意命令行参数(相对于环境变量)传递给 post-build 脚本。

这两种可能性都记录在 Buildroot 手册的 Customizing the generated target filesystem 部分。