需求:
1, 当前有多个架构的config文件,但是需要不同架构使用不同config文件
2, 必须将config文件拷贝到out/host目录下
常规思路
在Android.bp中, 一般在编译多架构文件时,都会使用arch属性,如例子:
cc_test {
name: "kselftest_breakpoints_tests",
relative_install_path: "linux-kselftest/breakpoints",
srcs: [
"tools/testing/selftests/breakpoints/step_after_suspend_test.c",
],
defaults: ["kselftest_defaults"],
arch: {
arm: {
enabled: false,
},
arm64: {
srcs: [
"tools/testing/selftests/breakpoints/breakpoint_test_arm64.c",
],
},
x86: {
srcs: [
"tools/testing/selftests/breakpoints/breakpoint_test.c",
],
},},
}
Androd.bp中预编译主要有如下:
var prebuiltTypes = map[string]string{
"SHARED_LIBRARIES": "cc_prebuilt_library_shared",
"STATIC_LIBRARIES": "cc_prebuilt_library_static",
"EXECUTABLES": "cc_prebuilt_binary",
"JAVA_LIBRARIES": "java_import",
"ETC": "prebuilt_etc",
}
Android.bp相关文档中:
所以可能满足需求的就是:prebuilt_etc_host,但是也没有找到arch属性:
例子:
prebuilt_etc_host {
name: "kernel_config",
src: "config",
filename: "config",
sub_dir: "kernel_config",
}
即使强行加上arch,其实也是不生效的,如:
prebuilt_etc_host {
name: "kernel_config",
src: "config",
arch: {
arm: {
src: "arm/config",
},
arm64: {
src: "aarch64/config",
},
x86: {
src: "x86/config",
},
x86_64: {
src: "x86_64/config",
},
},
filename: "config",
sub_dir: "kernel_config",
}
所以只能通过相关模板找解决方法,其中发现了TARGET_PREBUILT_TAG这个变量,这个变量的值可以通过 get_bulid_var获取:
get_build_var TARGET_PREBUILT_TAG
android-x86
也可以是android-arm64, 可以利用这个来进行区分。
解决方法
1,建立目录结构
android-arm android-arm64 Android.bp Android.mk android-x86 android-x86_64
2, Android.bp和Android.mk编写
vim Android.bp
subdirs=["*"]
vim Androd.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := config
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(HOST_OUT)/etc/kernel_config
LOCAL_SRC_FILES := $(TARGET_PREBUILT_TAG)/config
LOCAL_IS_HOST_MODULE := true
include $(BUILD_PREBUILT)