Shell script call from Android.mk, standard output and no separator error

I have a simple Android.mk file:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) $(shell ($(LOCAL_PATH)/echo_test.sh)) LOCAL_MODULE := libecho_test LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) 

An interesting thing he does is call the "echo_test.sh" bash script. In the case where the contents of the script is equal

 #!/bin/bash echo 'echo is working' >&2 

or

 #!/bin/bash echo 'echo is working' >/dev/null 

everything is good.

Things go wrong if bash script

 #!/bin/bash echo 'echo is working' 

or

 #!/bin/bash echo 'echo is working' >&1 

Then the error returned

 Android.mk:4: *** missing separator. Stop. 

This happens both with Android NDK 7 and when you enable this module during the build of Android Ice Cream Sandwich 4.0.3.

I really can’t understand what the deal is with standard output and the Android build system. Does anyone have an explanation?

+6
source share
3 answers

The Android NDK build system is actually GNU Make . All code in the Android.mk file must be a valid make .

When you run $ (shell) and don't save the value in a variable, it looks like you copied the standard script output to your Android.mk file. that is, as if your file contained the following:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) echo is working LOCAL_MODULE := libecho_test LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) 

.. which is invalid, does the syntax. Redirecting to> & 2 in your script works because the output goes to the error output and then displays on the console.

As Vishrut mentions, use $ (info) or $ (warning) to print messages. Or if you really want to run the script at build time, save its output in a variable:

 ECHO_RESULT := $(shell ($(LOCAL_PATH)/echo_test.sh)) 

Here you will not see the echo output of the script, it goes into a variable.

+10
source

Try $(info $(shell ($(LOCAL_PATH)/echo_test.sh))) , it works.

+8
source

Since richq's answer does not work for me, I use this:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libecho_test LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) all: echo hello 
0
source

Source: https://habr.com/ru/post/911654/


All Articles