Run shell script before include $(BUILD_PREBUILT)

428 views
Skip to first unread message

Abhayadev S

unread,
Nov 8, 2021, 5:14:48 PM11/8/21
to Android Building
Hi,

I need to run a shell script so that the libs and bins will be generated beofre Android can pick them up.

A structure of the makefile i am trying to comeup is below, not sure if this is really possible.. any inputs are appreciated.

LOCAL_PATH := $(call my-dir)

<this where i need to run the script so that bins will be generated for Android build to pickup>

include $(CLEAR_VARS)
LOCAL_MODULE        := my_modules
LOCAL_MODULE_OWNER  := Me
LOCAL_MODULE_TAGS   := optional
LOCAL_SRC_FILES     := ./my_bin_001
LOCAL_MODULE_PATH   := $(PRODUCT_OUT)/system/bin
include $(BUILD_PREBUILT)


i am not sure how can i add my build script which generates the my_bin_001
there are several bins its generating and i cant really convert the shell script in to a Makefile for practical reasons.

reagrds,
abhay

Paulo Maia

unread,
Dec 13, 2021, 5:50:00 PM12/13/21
to Android Building
Have you tried using $(shell) ? 
RESULT:= $(shell ($(LOCAL_PATH)/yourscript.sh))

Also you I think you could put in buiod/core/app_prebuilt_internal.mk if this is going to be repetitive.

BR,
Paulo

Dan Willemsen

unread,
Dec 13, 2021, 7:40:59 PM12/13/21
to android-...@googlegroups.com
Embedding build systems into one another is a very complicated issue, and requires deep knowledge of both build systems in order to keep all the functionality of both systems. Given that the Android build attempts to provide safe, fast incremental builds that work on any machine, it gets very difficult to preserve those features while calling out to another build system. If the scripts are simpler (bash/python script that reads a known set of inputs and writes to a know set of outputs, and doesn't use any other tools), then this doesn't get too difficult. But keep in mind that you do need to declare all inputs and outputs, and most tools you use need to be referenced by paths (and also be inputs), not in $PATH. Android.bp has the `genrule` concept that makes this easier.

<this where i need to run the script so that bins will be generated for Android build to pickup>

Keep in mind that we're not linearly executing Android.mk files -- that only happens in the first minute or two of the build to generate commands for what comes later. So you shouldn't actually be running the script there, but defining some Make logic to run your script later. You may be able to find references to Android.mk files using base_rules.mk and defining rules to build $(LOCAL_BUILT_MODULE), but you could also look into writing Android.bp files with genrules, which makes this simpler and adds some checks for common issues.
 
Have you tried using $(shell) ? 
RESULT:= $(shell ($(LOCAL_PATH)/yourscript.sh))

Definitely don't do this, it will slow down every build as we serially execute every one of these every time (even if there's nothing to build).

- Dan

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/2824e7a8-3745-45b7-9037-fc5c1eaf8930n%40googlegroups.com.

Paulo Maia

unread,
Dec 14, 2021, 2:49:48 PM12/14/21
to android-...@googlegroups.com
Hello,
The $(shell) inside you mk will for sure slow down your build as Dan pointed out (sorry I forgot to mention this) I currently have a setup like this and Im trying to refactor it,  still trying to find the best solution for my use case.
Thanks,
Paul

You received this message because you are subscribed to a topic in the Google Groups "Android Building" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-building/k5P_dxROmOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/CALQgHdmuC3RcAfmF6GvmQVEqGyemMHW-7K0ovbP1RkZkZam-fA%40mail.gmail.com.

Abhayadev S

unread,
Dec 21, 2021, 4:11:27 PM12/21/21
to Android Building
thanks Dan and Paulo...
i will look in to how i can make use of the genrule....
do you see any official man page for this... i am kind of lost in the google !

Dan Willemsen

unread,
Dec 21, 2021, 5:09:12 PM12/21/21
to android-...@googlegroups.com
General soong docs: build/soong/README.md

For genrule properties, there's auto-generated reference docs here

It can also be helpful to look at examples in AOSP.

- Dan

Abhayadev S

unread,
Dec 28, 2021, 9:51:59 PM12/28/21
to Android Building
Dan,
Thank you very much for sharing the info/links...
i will refer them....
Reply all
Reply to author
Forward
0 new messages