Akshay
Akshay

Reputation: 1137

Copy multiple txt files in /system using Android.mk

Aim : I want to copy multiple txt files in /system ( of Android Device ) using Android.mk

My Findings :

We can copy file using two approach 1) Use PRODUCT_COPY_FILES. This is done from devices/ / makefile.mk

ex:

PRODUCT_COPY_FILES := \
  frameworks/base/data/etc/telephony.gsm.xml:system/etc/permissions/telephony.gsm.xml \
  some/other/sourc/file:some/destination \
  some/other/sourcefile2: some/destination

2) Using BUILD_PREBUILD

ex :

##############copy txt file##################
include $(CLEAR_VARS)
#LOCAL_MODULE := mydata.txt
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT)/myfolder
LOCAL_SRC_FILES := mydata.txt
include $(BUILD_PREBUILT)

for above to work make entry of mydata.txt in build/target/product/core.mk

My Specific Query is : Now i can copy multiple files using 2nd approach by re-writing the above code one after the other. But i want to use 2nd approach (BUILD_PERBUILD ) to copy multiple txt files without re-writing code for all files.

1) Can i do that with just one include $(BUILD_PREBUILT) call ?

2 )Can BUILD_MULTI_PREBUILD be used to solve the purpose? how ?

Upvotes: 10

Views: 17245

Answers (2)

Jeff Johnson
Jeff Johnson

Reputation: 1

See the following example in Android font handling: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk#66

This creates a makefile function for a single font file, and uses a foreach loop to iterate over multiple files: https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/Android.mk#79

You can use any mechanism to populate font_src_files

Upvotes: 0

Akshay
Akshay

Reputation: 1137

Ok, I found one hack ( which i knew exists ) ,which i was not looking for but it worked and solved my problem in a very simple way.

You can run shell commands in mk file.

So if you want to copy multiple files just in a single go use following code and place it in your mk file.

In following scenario the files i need to copy are present in file_folder ( directory ) , which is in same directory where my mk file is. And i wan to copy all the files present in file_folder to system/file_folder.

#create a directory in /system/
    $(shell mkdir -p $(TARGET_OUT)/file_folder/)
#copy stuff
    $(shell cp $(LOCAL_PATH)/file_folder/* `pwd`/$(TARGET_OUT)/file_folder/)

This worked fine. So now in all we have 3 ways to do it. Hope it will help someone like me.

Upvotes: 16

Related Questions