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

前提是你 提交于 2019-12-30 03:14:30

问题


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?


回答1:


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.




回答2:


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




回答3:


Since richq's Answer doesn't 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


来源:https://stackoverflow.com/questions/9869349/shell-script-call-from-android-mk-standard-output-and-missing-separator-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!