4

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.
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
Rookie
  • 735
  • 5
  • 11
  • 30

5 Answers5

6

Finally I did it in a very unusual way.

I had 3 options:

  1. 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
  2. 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.
  3. 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.

Rookie
  • 735
  • 5
  • 11
  • 30
5

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.

pera
  • 882
  • 11
  • 21
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.

Yury
  • 20,618
  • 7
  • 58
  • 86
  • Thanks Yury, but in your case I may need to check and fix the compilation issue when the glibc is compiled using android toolchain. It might compile perfectly without any changes. – Rookie Feb 06 '13 at 18:05
  • I do not understand. Do you try to add a prebuilt binaries or you want to compile glibc with android toolchains? – Yury Feb 06 '13 at 18:10
  • Hi Yuri, I need to add bunch of prebuild binaries in a particular folder structure, i.e. I have whole lot of binaries in a folder structure in glibc folder which needs to be added in /system/ directory as is – Rookie Feb 06 '13 at 19:05
  • Then my answer is a possible solution. The code will be not compiled with android toolchains, it will be simply copied. – Yury Feb 07 '13 at 09:04
  • after I did as per you mentioned in your answer (I created glibc folder and copied everything into it), when I compile the code I get below output. build/core/main.mk:499: * unexpected glibc in ALL_PREBUILT 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. – Rookie Feb 08 '13 at 23:48
  • What version of Android do you try to compile? Meanwhile, do you know how Stackoverflow work? You should not ask additional questions in the form of answers. You should modify your question highlighting new content with the bold work Update, ... Update n. Moreover, you should accept answers that are correct. – Yury Feb 09 '13 at 08:59
  • Hi Yuri, I am sorry I started using stackoverflow just recently and was not aware of many things. I will surely keep in mind the suggestion given by you. How do I accept the correct answer given by you Well, to answer your question, I am using JB & ICS version of Android. – Rookie Feb 11 '13 at 20:10
  • I put the comment that this approach is described for Gingerbread. It's need to be researched how to do this in JB and ICS. P.S. to accept an answer you should mark the tick near the answer. Moreover, it's recommended to upvote the answer if it was helpful for you. – Yury Feb 11 '13 at 20:57
  • Hi yuri, Thanks for you reply. I knew from your answer that it is meant for Gingerbread. Could you please let me know same thing for ICS or JB? – Rookie Feb 11 '13 at 22:08
1

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)
Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36
evilwombat
  • 11
  • 1
0

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?

Rookie
  • 735
  • 5
  • 11
  • 30