前言
buildroot 编译的通常流程是:下载 tar 包、解压、配置、编译、安装。tar 包下载到 dl 目录中,编译时解压到 output/build/package-,这是一个临时目录,每当使用 make clean 时,该目录会被完全删除。
所以,当开发一个组件时,直接在 output/build/package- 目录中修改不是一个合适的解决方案。
override
为此,buildroot 提供了一种特定的机制:_OVERRIDE_SRCDIR。buildroot 读取 override 文件(默认是 $(CONFIG_DIR)/local.mk),文件内容示例如下:
<pkg1>_OVERRIDE_SRCDIR = /path/to/pkg1/sources
<pkg2>_OVERRIDE_SRCDIR = /path/to/pkg2/sources
这样,在执行 make _rebuild 的时候,buildroot 就会将指定目录的源码拷贝到 output/build/package-custom,然后编译、安装。
优化
编译时可能会报如下错误
comm: /xxx/buildroot-xxx/xxx/build/xxx-custom/.files-list-images.before: No such file or directory
添加一行命令做个优化即可
vim package/pkg-generic.mk
# Rsync the source directory if the <pkg>_OVERRIDE_SRCDIR feature is
# used.
$(BUILD_DIR)/%/.stamp_rsynced:
@$(call step_start,rsync)
@$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
@mkdir -p $(@D)
$(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
@test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
rsync -au --chmod=u=rwX,go=rX $($(PKG)_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS) $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
# 添加的命令
touch $(@D)/.files-list.before; touch $(@D)/.files-list-staging.before; touch $(@D)/.files-list-host.before;
$(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
@$(call step_end,rsync)
$(Q)touch $@