问题
I have glibc compiled for arm which is different from Android glibc or the bionic C as the glibc environment I have complied will help in providing more api's. Now I can copy the glibc environment on /system/ folder while Android is running, and on doing chroot I can run my programs on glibc environment.
Currently I am compiling glibc and Android separately and then tarring the glibc and copying it on Android emulator sdcard and then untarring it on /system folder and then doing chroot on /system/glibc
I compile glibc separately and then place it somewhere in Android source code. Now while compiling Android source, what should I do so that the entire prebuilt folder structure of glibc gets copied to /system folder and become part of part of system.img.
With this when I copy the system.img to Android emulator and launch it, glibc is already present in /system folder and just need to run the apps in glibc environment.
UPDATE
after I did as per Yuri mentioned in his answer (I created glibc folder and copied everything into it), when I compile the code I get below output.
build/core/main.mk:490: * Some files have been added to ALL_PREBUILT.
build/core/main.mk:491: *
build/core/main.mk:492: * ALL_PREBUILT is a deprecated mechanism that
build/core/main.mk:493: * should not be used for new files.
build/core/main.mk:494: * As an alternative, use PRODUCT_COPY_FILES in
build/core/main.mk:495: * the appropriate product definition.
build/core/main.mk:496: * build/target/product/core.mk is the product
build/core/main.mk:497: * definition used in all products.
build/core/main.mk:498: *
build/core/main.mk:499: * unexpected glibc in ALL_PREBUILT
build/core/main.mk:500: *
build/core/main.mk:501: * ALL_PREBUILT contains unexpected files. Stop.
So I added glibc in build/core/legacy_prebuilts.mk
But then I get
make: * No rule to make target mkdir', needed byout/target/product/generic/root/glibc'. Stop.
回答1:
Here is an example from the book "Embedded Android" that will help you. Create a folder in the root of your aosp project called rootfs-glibc
, put there the code that you want to copy, and create there Android.mk
file with the following content:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# This part is a hack, we're doing "addprefix" because if we don't,
# this dependency will be stripped out by the build system
GLIBC_ROOTFS := $(addprefix $(TARGET_ROOT_OUT)/, rootfs-glibc)
$(GLIBC_ROOTFS): mkdir -p $(TARGET_ROOT_OUT) cp -af $(TOPDIR)rootfs-glibc/* $(TARGET_ROOT_OUT) rm
# The last command just gets rid of this very .mk since it's copied as-is
ALL_PREBUILT += $(GLIBC_ROOTFS)
There is a note that this is true for Gingerbread. Maybe in newer versions of Android the make system has been changed.
回答2:
Finally I did it in a very unusual way.
I had 3 options:
- Use BUILD_PREBUILT variable, but drawback it you can do it for a single file, but I had multiple files and in a particular forlder structure
- Use PRODUCT_COPY_FILES. But somehow it was not working for me PRODUCT_COPY_FILES is for a device, and it was not a new device for me. I was working on emulator.
- Using the solution given by Yuri, using ALL_PREBUILT +=, but as Yuri mentioned it was for GB and I am using JB and ICS and hence was not working for me.
The approach i took is to use shell script within the Android.mk file. I used some like this: Assume you have a folder named my_folder containing entire prebuilt folder structure which needs to be copied to anddroid out folder as is, inside my_folder, I created Android.mk and entered below text:
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) $(shell mkdir -p $(TARGET_OUT)/my_folder/) $(shell cp -rf $(LOCAL_PATH)/* `pwd`/$(TARGET_OUT)/my_folder/)
This way all my prebuilt set of files and folders in my_folder directory were copied as is to system folder in android out.
I hope this helps someone.
回答3:
PRODUCT_COPY_FILES must be placed in product mk files (device/mydevice/..), not module files (Android.mk). This is mentioned here.
This format is used for copying dirs:
PRODUCT_COPY_FILES += $(call find-copy-subdir-files,*,vendor/mydir,system/app)
This command is not working for apk files though, giving error:
build/core/Makefile: *** Prebuilt apk found in PRODUCT_COPY_FILES: vendor/mydir/ray-system-ui-release.apk:system/app/ui-release.apk, use BUILD_PREBUILT instead!. Stop.
回答4:
Consider using a PHONY_PACKAGE with a custom installation step.
Unlike the $(shell cp whatever) answer above, this will only run during the installation step, rather than on every Make step (which is certainly not what you want).
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := some_module
LOCAL_ADDITIONAL_DEPENDENCIES := FORCE # Decide if you need this
LOCAL_POST_INSTALL_CMD = cd $(LOCAL_PATH) && cp -a mystuff $(TARGET_OUT_WHATEVER)
include $(BUILD_PHONY_PACKAGE)
回答5:
I was thinking if I could do this way 1. I have both android and glibc compiled separetely. 2. Once both are compiled, I manually copy the glibc entire folder to /out/target/product/generic/system/glibc/ folder 3. Then I run "make snod"
Would that work?
来源:https://stackoverflow.com/questions/14718852/adding-prebuilt-set-of-files-structured-in-folders-to-android-out-folder