Copy in the android--compilation system

Source: Internet
Author: User
Tags vars

In the development of the Andriod system layer, or porting, often need to add files to the compilation system, in the final compilation to the out, and finally packaged into a mirror, here to summarize the copy file method, here is my Android 4.2.1 for example.

If there is no wrong or other alternative, welcome to make a brick message ~


Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/40615801


A. Product_copy_files:

This variable is used to mark the copy operation, the more common form is as follows:

#jscese 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/etc/apns-full-conf.xml: System/etc/apns-conf.xml     #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

You can see the format <source file>:<dest file> in the middle with ":" Separated!



The compiled source knows that it will appear at the beginning of the compilation:

Product_copy_files frameworks/base/data/sounds/effects/ogg/effect_tick.ogg:system/media/audio/ui/effect_ Tick.ogg ignored. Product_copy_files frameworks/base/data/sounds/effects/ogg/keypressstandard.ogg:system/media/audio/ui/ Keypressstandard.ogg ignored. Product_copy_files frameworks/base/data/sounds/effects/ogg/keypressspacebar.ogg:system/media/audio/ui/ Keypressspacebar.ogg ignored. Product_copy_files frameworks/base/data/sounds/effects/ogg/keypressdelete.ogg:system/media/audio/ui/ Keypressdelete.ogg ignored. Product_copy_files frameworks/base/data/sounds/effects/ogg/keypressreturn.ogg:system/media/audio/ui/ Keypressreturn.ogg ignored ....
This kind of print, now tell you where this thing is playing out ~ /build/core/makefileIn the beginning:

#-----------------------------------------------------------------# 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/etc/file.xml". # The filter section 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 pairdefine check-product-copy-files$ (if $ (filter%.apk, $ (1)), $ (Error prebuilt apk found in Product_copy_files: $ (1), use 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)), $ (EVA         L $ (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: =

This is where product_copy_files works! You can see the above comment, describe the rule usage, only copy file!

That is, the source of the above compiled print, which represents the ignore item. Detailed rules can follow up to look at, nothing but rely on copy and the like.



One thing to note here is that Product_copy_files cannot use Add new COPY entry in Android.mk !

See /build/core/main.mk for details:

# Can ' t use First-makefiles-under here because#--mindepth=2 makes the prunes not work.subdir_makefiles: = $ (Shell build/t ools/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.mkifeq ($ (Stash_product_vars), True)  $ (call Assert-product-vars, __stashed) endif

Load all the android.mk here, focusing on the back of the assert-product-vars function:

# # Assert that the ' the the variable stashed by Stash-product-vars remains untouched.# $ (1): The prefix as supplied to STASH-PR Oduct-vars#define assert-product-vars$ (Strip   $ (eval changed_variables:=)  $ (foreach v,$ (_product_stash_var _list),     $ (if $ (call streq,$ ($ (v)), $ ($ ($ (strip $ (1)) _$ (call rot13,$ (v))),         $ (eval $ (Warning $ (v) have been Modified: $ ($ (v))) $ (         eval $ (Warning previous value: $ ($ (strip $ (1)) _$ (call rot13,$ (v))))         $ (eval changed_ Variables: = $ (changed_variables) $ (v)))    )   $ (if $ (changed_variables),    $ (eval $ (Error the following Variables has been changed: $ (changed_variables))),)) Endef

If there is a change will be error, the compilation error is as follows:

build/core/main.mk:528: * * * The following variables has been changed:product_copy_files. Stop it.


The use of product_copy_files should be considered the most commonly used COPY File method, can be directly added to the DEVICE.MK!




Two. Copy_to Copy_from all_prebuilt:

This method is used in ANDROID.MK and can be referenced in /system/core/rootdir/android.mk:

Copy_from + = etc/init.goldfish.shcopy_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)

Can see Copy_from is need copy, copy_to is the destination!

You can look at the rules, defined in/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) ([email protected]) "$ (copy-file-to-target) endef

Define Copy-file-to-target@mkdir-p $ (dir [email protected]) $ (hide) $ (ACP)-fp $< [email protected]endef

It is important to note that if we add some files ourselves to the Copy_from, it will appear:

build/core/main.mk:533: * * * Some files has been added to all_prebuilt.build/core/main.mk:534: *build/core/main.mk:535: * All_prebuilt is a deprecated mechanism thatbuild/core/main.mk:536: * should not being used for new files.build/core/main.mk : 537: * As an alternative, use product_copy_files inbuild/core/main.mk:538: * The appropriate PRODUCT Definition.build/cor e/main.mk:539: * Build/target/product/core.mk is the productbuild/core/main.mk:540: * definition used in all Products.bui ld/core/main.mk:541: *build/core/main.mk:542: * Unexpected USB_MODESWITCH.H in all_prebuiltbuild/core/main.mk:542: * Unexpected usb_modeswitch.sh in all_prebuiltbuild/core/main.mk:542: * Unexpected USB_MODESWITCH.TCL in ALL_ prebuiltbuild/core/main.mk:543: *build/core/main.mk:544: * * * all_prebuilt contains unexpected files. Stop it.

Error occurred in /build/core/main.mk

Include $ (Build_system)/legacy_prebuilts.mkifneq ($ (filter-out $ (grandfathered_all_prebuilt), $ (strip $ (Notdir $ (all _prebuilt))),)  $ (WARNING * * * * Some files has been added to all_prebuilt.)  $ (WARNING *)  $ (Warning * all_prebuilt is a deprecated mechanism this)  $ (warning * should not being used for new files .)  $ (Warning * As an alternative, use Product_copy_files in)  $ (WARNING * The appropriate PRODUCT definition.)  $ (Warning * BUILD/TARGET/PRODUCT/CORE.MK is the product)  $ (warning * definition used in all products.)  $ (WARNING *)  $ (foreach bad_prebuilt,$ (filter-out $ (grandfathered_all_prebuilt), $ (strip $ (Notdir $ (all_prebuilt ))), $ (WARNING * Unexpected $ (bad_prebuilt) in all_prebuilt))  $ (Warning *)  $ (Error all_prebuilt contains Unexpected files) endif


The above printing information tells us that All_prebuilt is an outdated mechanism, has not been used to COPY new files, the recommended use of product_copy_files !


The members that can be added into the all_prebuilt variable are defined in legacy_prebuilts.mk :

# This is the list of modules grandfathered to use all_prebuilt# does not ADD any NEW MODULE to this file## all_prebuilt MoD Ules is hard-to-control and audit and we don ' t want# to add any new such module in the systemgrandfathered_all_prebuilt: =     akmd2     am     ap_gain.bin ...

The notes are very clear!

So if we want to add a file to compile copy, we can not use copy_from copy_to all_prebuilt this mechanism!




Three. Build_prebuilt:

In this way, the file is treated as a compilation project, and the android.mk copy

Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = usb_modeswitch.conf Local_module_class: = ETC  Local_module_path: = $ (target_out)/etc Local_src_files: =$ (Local_module)  

The above is the copy usb_modeswitch.conf file to the ETC directory under out, this directory is often used to store configuration related files.

All of the above are said to be copy file but if you need to copy a file directory all you need another exercise!




Four. Copy Directory

Take the example of the copyUsb-modewitch.d Data Catalog in the Usb-modeswitch (ii) of the android--4.2-3g in front of my blog.

In the android.mk there I used the shell command copy:

$ (Shell CP-RF $ (Local_path)/usb_modeswitch.d $ (target_out)/etc/usb_modeswitch.d)  

This is not a problem when the source code has been compiled, because the $ (target_out)/etc directory already exists, but as a new compilation is not copy,

So in the Android compiler system also have to follow the mechanism provided by Android to operate, like this shell trickery, is convenient, but not the right way!

I am now dealing with:

In the upper shell where the include handles the copy Usb-modewitch.d's Mk file, the contents are as follows:

# $ (1): module name# $ (2): Source file# $ (3): Destination Directorydefine Include-prebuilt-with-destination-directoryinclude $$ (clear_vars) Local_module: = $ (1) Local_additional_ DEPENDENCIES: = $ (local_path)/usb_modeswitch_data.mklocal_module_stem: = $ (Notdir $ (2)) Local_module_tags: = Optionallocal_module_class: = Etclocal_module_path: = $ (3) Local_src_files: = $ (2) include $$ (build_prebuilt) endef#== Rename ' s/:/_/' * = = #usb_modeswitch_data: = $ (Notdir $ (wildcard $ (local_path)/usb_modeswitch.d/*)) $ (Warning Jscese display-usb_modeswitch_data--$ (Usb_modeswitch_data)) Usb_modeswitch_data_target_directory: = $ (TARGET_OUT)/etc/ usb_modeswitch.d$ (foreach data, $ (usb_modeswitch_data), $ (eval $ (call Include-prebuilt-with-destination-directory, target-data-$ (Notdir $ (data)), usb_modeswitch.d/$ (data), $ (usb_modeswitch_data_target_directory))) Usb_modeswitch _data_target: = $ (Addprefix $ (usb_modeswitch_data_target_directory)/,$ (foreach cacert,$ (usb_modeswitch_data), $ ( Notdir $ (usb_modeswitch_data))). Phony: Usb_modeswitch_data_targetusb_modeswitch_data: $ (usb_modeswitch_data_target) # This was so that build/target/product/ Core.mk can use Usb_modeswitch_data in Product_packagesall_modules.usb_modeswitch_data. Installed: = $ (Usb_modeswitch_data_target)

You can see that the principle is the same as the Copy of a separate file is build_prebuilt, but is to traverse the folder, and this as a module to handle the write-in product_packages

The role of the product_packages variable can be referenced in my previous post android--The control factor for compiling and installing the module


In addition, because the file name is xxxx:xxxx type, I will first use the REANME command directly: replace it with the full _

If not replaced, resulting in the passing of the file makefile the middle: may be as a dependency symbol ~ will error

If I use subst : Replace with \: Add the escape symbol, as if the file is not found, do not know if you have encountered this situation ....





Copy in the android--compilation system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.