Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script call from Android.mk, standard output and missing 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)

The interesting thing that it does is to call the 'echo_test.sh' bash script. In the case when the contents of the script are

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

or

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

everything is OK.

Things go wrong when the bash script is

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

or

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

Then the returned error is

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

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

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

like image 655
Sogartar Avatar asked Mar 26 '12 09:03

Sogartar


2 Answers

The Android NDK build system is actually GNU Make. All of the code in the Android.mk file has to be valid make.

When you run $(shell) and don't store the value in a variable, then it is as if you copied the standard output of the script into your Android.mk file. i.e. it 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 not valid make syntax. Redirecting to >&2 in your script works because the output goes to the error output and is then shown on the console.

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

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

Here you won't see the echo output of the script, it goes into the variable.

like image 110
richq Avatar answered Nov 13 '22 01:11

richq


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

like image 31
Vishrut Avatar answered Nov 13 '22 01:11

Vishrut