I want to call a python interpreter in a shell, from an android make file. Initially I tried this:
$(shell python -c "import sys;print('hello')")
The result is an error:
Android.mk:150: *** missing separator. Stop.
I suspect this is caused by ndk-build misinterpreting nested quotes. I couldn't find an alternative that would be a legal make file and contain a string representing a legal python script at the same time. How can this be done?
For reference, the full make file:
##########################################################
# Main-Project - start.
##########################################################
# store caller info (all LOCAL_XXX variables cleared by CLEAR_VARS operation,
# to be able to re-constructed on exit)
NEW_PROJECT_USER_LOCAL_PATH := $(LOCAL_PATH)
NEW_PROJECT_USER_LOCAL_C_INCLUDES := $(LOCAL_C_INCLUDES)
NEW_PROJECT_USER_LOCAL_CFLAGS := $(LOCAL_CFLAGS)
NEW_PROJECT_USER_LOCAL_CPPFLAGS := $(LOCAL_CPPFLAGS)
NEW_PROJECT_USER_LOCAL_STATIC_LIBRARIES := $(LOCAL_STATIC_LIBRARIES)
NEW_PROJECT_USER_LOCAL_SHARED_LIBRARIES := $(LOCAL_SHARED_LIBRARIES)
NEW_PROJECT_USER_LOCAL_LDLIBS := $(LOCAL_LDLIBS)
# switch to current module
LOCAL_PATH := $(call my-dir)
NEW_PROJECT_PATH := $(LOCAL_PATH)
CURRENT_DIR_ABS_PATH := $(CURDIR)
export BUILD_NESTED_PROJECT_1_SHARED_LIBRARY := false
export BUILD_NESTED_PROJECT_2_SHARED_LIBRARY := false
export BUILD_NESTED_PROJECT_2_EXE := false
export MY_UTILS_FOR_NESTED_PROJECT_1_PATH := $(LOCAL_PATH)/MY_Utils
export CP_NESTED_PROJECT_1_ABS_PATH:= $(LOCAL_PATH)/NestedProject1
export OPENCV_JNI = $(OPENCV_DIR)/Android/$(APP_STL)/$(APP_ABI)/staticlibs/sdk/native/jni
###############################
# Exports
###############################
export ARM_ARCH:=AARCH64
export RELEASE_MODE:=false
#Set to true to enable log prints
export ENABLE_LOGCAT:=true
export PRINT_TIMING:=0
ifeq ($(RELEASE_MODE),true)
export ENABLE_LOGCAT:=false
export PRINT_TIMING:=0
endif
#Android log print is default.
export ENABLE_STRINGLOGGER:=false
export ENABLE_ANDROID_LOG_FILE:=false
export COMMON_API_VERSION?=12
export SVL_MY_UTILS_PATH:=$(LOCAL_PATH)/MY_Utils
export SVL_PATH:=$(LOCAL_PATH)
export BUILD_SVL_SHARED_LIBRARY:=false
$(info OPEN_CV_ENABLE=$(OPEN_CV_ENABLE))
$(info ENABLE_LOGCAT=$(ENABLE_LOGCAT))
$(info RELEASE_MODE=$(RELEASE_MODE))
$(info PRINT_TIMING=$(PRINT_TIMING))
include $(CLEAR_VARS)
ifneq ($(call set_is_member,$(__ndk_modules),mainproject),$(true))
ifeq ($(OPEN_CV_ENABLE),true)
LOCAL_CFLAGS += -DOPEN_CV_ENABLE
#OpenCV start
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
include $(OPENCV_JNI)/OpenCV.mk
LOCAL_LDLIBS := # clean LOCAL_LDLIBS
#OpenCV end
endif
########### GLOBAL Flags: #######################################################
ifeq ($(RELEASE_MODE),true)
GLOBAL_FLAGS += -DRELEASE_MODE=1
else
GLOBAL_FLAGS += -DRELEASE_MODE=0
endif
GLOBAL_FLAGS += -DDUMP_PATH=$(DUMP_PATH_ALL)
GLOBAL_FLAGS += -DRECORDER_PATH=$(DUMP_PATH_ALL)\"recorderDumps/\"
GLOBAL_FLAGS += -DPARAM_PLAYER=0 # loads stored on file params
GLOBAL_FLAGS += -DPARAM_RECORDER=0 # records params such runtime, frames params, out info
GLOBAL_FLAGS += -DDISPLAY_WIDE_ONLY=0 # 0-display all cameras possible, 1-display wide only
ifeq ($(PARAM_PLAYER), 1) # when playing params, recording is disabled
PARAM_RECORDER=0
endif
##############
#Log Control #
##############
#Logger tag
ifneq (PROJECT_TAG,$(findstring PROJECT_TAG,$(GLOBAL_FLAGS))) # no need to define twice
GLOBAL_FLAGS += -DPROJECT_TAG=\"MAIN_PROJECT\"
endif
ifeq ($(ENABLE_LOGCAT),true)
ifeq ($(ENABLE_STRINGLOGGER),true)
GLOBAL_FLAGS += -DUSE_LOG_TO_STR_FILE
else
ifeq ($(ENABLE_ANDROID_LOG_FILE),true)
GLOBAL_FLAGS += -DUSE_ANDROID_LOG_FILE
endif
endif
else
GLOBAL_FLAGS += -DLOG_DBG_PRINTS_CANCLED
endif
#############
########### .mk includes #######################################################
include $(NEW_PROJECT_PATH)/MY_Utils/Android.mk
include $(NEW_PROJECT_PATH)/MY_Utils/CPModules/PrismPredictor/Android.mk
include $(NEW_PROJECT_PATH)/NestedProject1/jni/Android.mk
include $(NEW_PROJECT_PATH)/SomeModule1/Android.mk
include $(NEW_PROJECT_PATH)/SomeModule2/Android.mk
$(shell python -c "import sys;print('hello')")
include $(NEW_PROJECT_PATH)/SomeModule3/Android.mk
include $(NEW_PROJECT_PATH)/SomeModule4/Android.mk
include $(NEW_PROJECT_PATH)/SomeModule5/Android.mk
LOCAL_C_INCLUDES += $(EXTERNAL_PATH)/$(PLATFORM)/$(GPU)/include/
LOCAL_C_INCLUDES += $(EXTERNAL_PATH)/$(PLATFORM)/android/include/$(AVRS)
LOCAL_C_INCLUDES += $(NEW_PROJECT_PATH)/include/
LOCAL_C_INCLUDES += $(NEW_PROJECT_PATH)/API/API_VER_$(API_VERSION)/external/
LOCAL_C_INCLUDES += $(NEW_PROJECT_PATH)/MY_Utils/CommonAPI/CommonAPI$(COMMON_API_VERSION)
LOCAL_SRC_FILES += $(NEW_PROJECT_PATH)/API/API_VER_$(API_VERSION)/src/API.cpp
LOCAL_SRC_FILES += $(NEW_PROJECT_PATH)/src/SomeSource1.cpp
LOCAL_CFLAGS += $(OPTION_FLAGS)
LOCAL_CFLAGS += $(GLOBAL_FLAGS)
LOCAL_MODULE := mainproject
include $(BUILD_SHARED_LIBRARY)
ifeq ($(BUILD_OFFLINE_TEST), true)
$(info -----------------Buildingoffline test-----------------------)
include $(NEW_PROJECT_PATH)/MY_Utils/Manager/Android.mk
include $(NEW_PROJECT_PATH)/UnitTestAndroid/Android.mk
endif
endif
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(NEW_PROJECT_USER_LOCAL_C_INCLUDES)
LOCAL_CFLAGS:=$(NEW_PROJECT_USER_LOCAL_CFLAGS)
LOCAL_CPPFLAGS:=$(NEW_PROJECT_USER_LOCAL_CPPFLAGS)
LOCAL_STATIC_LIBRARIES:=$(NEW_PROJECT_USER_LOCAL_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES:=$(NEW_PROJECT_USER_LOCAL_SHARED_LIBRARIES)
LOCAL_LDLIBS:=$(NEW_PROJECT_USER_LOCAL_LDLIBS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/external
LOCAL_SHARED_LIBRARIES += mainproject
LOCAL_PATH := $(NEW_PROJECT_USER_LOCAL_PATH)
##########################################################
# Main-Project - end.
##########################################################
To use the $() in Makefiles, you have to declare a variable like this HELLO = $(shell python -c "import sys;print('hello')")
, and now HELLO has the value of "hello"
If you want to print something on the screen, just use echo
or printf
in the target's script