Android——编译体系中的【PRODUCT_COPY_FILES】【ALL_PREBU。。。

更新时间:2023-05-28 08:27:41 阅读: 评论:0

Android——编译体系中的【PRODUCT_COPY_FILES】
【ALL_PREBU。。。
对andriod系统层进⾏开发,或者进⾏移植时,时常需要添加⽂件到编译体系中,在最终的编译中复制到out中,最后打包成镜像,这⾥总结⼀下Copy File ⽅法,这⾥以我的 android 4.2.1为例.
nobody
如有不对或者有其它的新招,欢迎拍砖留⾔~
⼀.PRODUCT_COPY_FILES :
这个变量就是⽤来标记Copy操作的,⽐较常见的形式如下:
#jsce cp 3g script and
PRODUCT_COPY_FILES += \
$(DEVICE_SOURCES)/3g-script/ip-up-datakey:system/etc/ppp/ip-up-datakey \
$(DEVICE_SOURCES)/3g-script/ip-down-datakey:system/etc/ppp/ip-down-datakey \
$(DEVICE_SOURCES)/3g-script/init.gprs-pppd:system/etc/ppp/init.gprs-pppd \
device/sample/l:system/l \
#external/usb-modeswitch/usb_modeswitch.d:system/etc/usb_modeswitch.d
#PRODUCT_COPY_FILES += \
#$(DEVICE_SOURCES)/3g-script/ip-down-datakey:system/etc/ppp/ip-down-datakey
#end
可以看到 格式<source file>:<dest file> 中间⽤ “ :  ” 隔开!
编译过源码的都知道在最开始 编译的时候 都会出现:
PRODUCT_COPY_FILES frameworks/ba/data/sounds/effects/ogg/:system/media/audio/ui/ ignored.
PRODUCT_COPY_FILES frameworks/ba/data/sounds/effects/:system/media/audio/
ignored. PRODUCT_COPY_FILES frameworks/ba/data/sounds/effects/:system/media/audio/ ignored. PRODUCT_COPY_FILES frameworks/ba/data/sounds/effects/:system/media/audio/ ignored. PRODUCT_COPY_FILES frameworks/ba/data/sounds/effects/:system/media/audio/ ignored.
大度读人...
这样的打印,现在告诉你这东西在哪⾥打出来的~  /build/core/Makefile 中最开始的:
成人免费# -----------------------------------------------------------------
# Define rules to copy PRODUCT_COPY_FILES defined by the product.
# PRODUCT_COPY_FILES contains words like <source file>:<dest file>[:<owner>].
# <dest file> is relative to $(PRODUCT_OUT), so it should look like,
# e.g., "system/l".
# The filter part means "only eval the copy-one-file rule if this
# src:dest pair is the first one to match the same dest"
#$(1): the src:dest pair
define check-product-copy-files
$(if $(filter %.apk, $(1)),$(error \
Prebuilt apk found in PRODUCT_COPY_FILES: $(1), u BUILD_PREBUILT instead!))
endef
# filter out the duplicate <source file>:<dest file> pairs.
unique_product_copy_files_pairs :=
$(foreach cf,$(PRODUCT_COPY_FILES), \
$(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
$(eval unique_product_copy_files_pairs += $(cf))))
unique_product_copy_files_destinations :=
$(foreach cf,$(unique_product_copy_files_pairs), \
$(eval _src := $(call word-colon,1,$(cf))) \
$(eval _dest := $(call word-colon,2,$(cf))) \
$(call check-product-copy-files,$(cf)) \
$(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
$(info PRODUCT_COPY_FILES $(cf) ignored.), \
$(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
$(if $(filter %.xml,$(_dest)),\
$(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
$(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
$(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
$(eval unique_product_copy_files_destinations += $(_dest))))
unique_product_copy_files_pairs :=
unique_product_copy_files_destinations :=
这就是 PRODUCT_COPY_FILES 起作⽤的地⽅! 可以看上⾯注释,描述了规则⽤法,只能copy file!也就是上⾯编译打印的出处,代表忽略项. 详细的规则可跟进去细看,⽆⾮是依赖Copy之类的.
这⾥需要注意⼀点, PRODUCT_COPY_FILES 不能在 Android.mk 中使⽤ 添加新的Copy 项!
详情可看/build/core/main.mk 中的:
# Can't u first-makefiles-under here becau
# --mindepth=2 makes the prunes not work.
subdir_makefiles := \
$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)
include $(subdir_makefiles)
endif # ONE_SHOT_MAKEFILE
# Now with all Android.mks loaded we can do post cleaning steps.
include $(BUILD_SYSTEM)/post_clean.mk
看错了ifeq ($(stash_product_vars),true)
$(call asrt-product-vars, __STASHED)
endif
在这⾥加载所有的Android.mk ,重点在后⾯的 asrt-product-vars 函数:
#
# Asrt that the the variable stashed by stash-product-vars remains untouched.
# $(1): The prefix as supplied to stash-product-vars
#
define asrt-product-vars
$(strip \
$(eval changed_variables:=)
$(foreach v,$(_product_stash_var_list), \
$(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \
$(eval $(warning $(v) has been modified: $($(v)))) \
$(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
$(eval changed_variables := $(changed_variables) $(v))) \
) \
$(if $(changed_variables),\
verina
$(eval $(error The following variables have been changed: $(changed_variables))),)
)
endef
如果有改变就会报错的,编译出错如下:
build/core/main.mk:528: *** The following variables have been changed: PRODUCT_COPY_FILES。停⽌。
使⽤ PRODUCT_COPY_FILES 应该算是最常⽤的Copy File 的⽅法了,⼀般可直接加在 device.mk 中!
⼆ .copy_to copy_from ALL_PREBUILT:
这个⽅法⽤在Android.mk中,可参考 /system/core/rootdir/Android.mk:
copy_from += ldfish.sh
copy_to := $(addprefix $(TARGET_OUT)/,$(copy_from))
copy_from := $(addprefix $(LOCAL_PATH)/,$(copy_from))
政治考试
$(copy_to) : PRIVATE_MODULE := system_etcdir
$(copy_to) : $(TARGET_OUT)/% : $(LOCAL_PATH)/% | $(ACP)
$(transform-prebuilt-to-target)
ALL_PREBUILT += $(copy_to)
可以看到copy_from 就是需要copy的,copy_to 就是⽬的地!
可以看下规则,定义在/build/core/definitions.mk中:
# Copy a prebuilt file to a target location.
define transform-prebuilt-to-target
@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"推荐一本书 五年级
北京环球雅思学校
$(copy-file-to-target)
endef
define copy-file-to-target
@mkdir -p $(dir $@)
$(hide) $(ACP) -fp $< $@
endef
需要注意的是,如果我们⾃⼰添加⼀些⽂件到 copy_from中,就会出现 :
build/core/main.mk:533: *** Some files have been added to ALL_PREBUILT.
build/core/main.mk:534: *
build/core/main.mk:535: * ALL_PREBUILT is a deprecated mechanism that
build/core/main.mk:536: * should not be ud for new files.
build/core/main.mk:537: * As an alternative, u PRODUCT_COPY_FILES in
build/core/main.mk:538: * the appropriate product definition.
build/core/main.mk:539: * build/target/product/core.mk is the product
build/core/main.mk:540: * definition ud in all products.
build/core/main.mk:541: *
build/core/main.mk:542: * unexpected usb_modeswitch.h in ALL_PREBUILT
build/core/main.mk:542: * unexpected usb_modeswitch.sh in ALL_PREBUILT
build/core/main.mk:542: * unexpected l in ALL_PREBUILT环球职业教育在线
build/core/main.mk:543: *
build/core/main.mk:544: *** ALL_PREBUILT contains unexpected files。停⽌。
错误发⽣在 /build/core/main.mk
include $(BUILD_SYSTEM)/legacy_prebuilts.mk
ifneq ($(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),)
$(warning *** Some files have been added to ALL_PREBUILT.)
$(warning *)
$(warning * ALL_PREBUILT is a deprecated mechanism that)
$(warning * should not be ud for new files.)
$(warning * As an alternative, u PRODUCT_COPY_FILES in)
$(warning * the appropriate product definition.)
$(warning * build/target/product/core.mk is the product)
$(warning * definition ud in all products.)
$(warning *)
$(foreach bad_prebuilt,$(filter-out $(GRANDFATHERED_ALL_PREBUILT),$(strip $(notdir $(ALL_PREBUILT)))),$(warning * unexpected $(bad_prebuilt) in ALL_  $(warning *)
$(error ALL_PREBUILT contains unexpected files)
endif
上⾯的打印信息告诉我们  ALL_PREBUILT  是⼀种过时的机制,已经不让⽤于copy新的⽂件了,推荐使⽤
PRODUCT_COPY_FILES  !
⽽可以添加进 ALL_PREBUILT 变量的成员定义在 legacy_prebuilts.mk中:
# This is the list of modules grandfathered to u ALL_PREBUILT
# DO NOT ADD ANY NEW MODULE TO THIS FILE
#
# ALL_PREBUILT modules are hard to control and audit and we don't want
# to add any new such module in the system
GRANDFATHERED_ALL_PREBUILT := \
akmd2 \
am \
ap_gain.bin \
...
注释写的很明⽩了!
所以如果我们⾃⼰想加个⽂件编译copy ,就不能使⽤ copy_from copy_to ALL_prebuilt 这种机制 !
三 .BUILD_PREBUILT :
这种⽅式把⽂件当成编译项⽬,在Android.mk中copy⼀个file:
LOCAL_PATH := $(call my-dir)
甄嬛体
include $(CLEAR_VARS) \
LOCAL_MODULE := f \
LOCAL_MODULE_CLASS := ETC  \
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc \
LOCAL_SRC_FILES :=$(LOCAL_MODULE)  \
include $(BUILD_PREBUILT)
上⾯的就是copy f ⽂件到 OUT 下⾯的 etc⽬录,这个⽬录常⽤来存放配置相关⽂件。
上⾯所有的都说的是Copy File  但是如果需要 Copy ⼀个⽂件⽬录下所有就需要另做操作了!
四 .Copy Directory
以我前⾯的博客    中copyusb-modewitch.d 数据⽬录 为例.
在那⾥的Android.mk 中我使⽤了shell命令Copy:
$(shell cp -rf $(LOCAL_PATH)/usb_modeswitch.d $(TARGET_OUT)/etc/usb_modeswitch.d)
这样做在源码已经编译好了的情况下,是没有问题的,因为$(TARGET_OUT)/etc ⽬录已经存在,但是作为新编译是不会Copy的,所以说在android的编译体系中 还得按照android提供的机制来进⾏操作,像这种shell取巧,是⽅便,但不是正途!

本文发布于:2023-05-28 08:27:41,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/125545.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:编译   规则   需要   环球   机制   镜像   打印   操作
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图