Fix #2256: Mini refactored Android configure script:

- added CXXFLAGS & LDFLAGS parsing (from ndk-build output), CXXFLAGS was set to CFLAGS.
 - updated WebRTC instruction set to use SSE2, was generic, for Android emulator (x86 ABI).
 - updated C++ library/STL backend to use c++_shared, somehow '-lc++_static' is ignored after the refactor, also the official NDK docs mentions that c++_static may cause undefined behavior for app with multiple shared libraries (note pjsua2 app may use other shared libraries).



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@6120 74dad513-b988-da41-8d7b-12977e46ad98
remotes/origin/bitrise-android
Nanang Izzuddin 5 years ago
parent dfb6aa264d
commit 192a6bfc43

@ -9022,6 +9022,9 @@ $as_echo "Checking if libwebrtc is disabled...no" >&6; }
mips*)
ac_webrtc_instset=mips
;;
x86*)
ac_webrtc_instset=sse2
;;
*)
ac_webrtc_instset=generic
;;

@ -2084,6 +2084,9 @@ AC_ARG_ENABLE(libwebrtc,
mips*)
ac_webrtc_instset=mips
;;
x86*)
ac_webrtc_instset=sse2
;;
*)
ac_webrtc_instset=generic
;;

@ -66,10 +66,14 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
ADD_CFLAGS="0"
ADD_CXXFLAGS="0"
ADD_LDFLAGS="0"
ADD_NDK_TOOLCHAIN="0"
ADD_NDK_TARGET="0"
if test "x${IGNORE_CFLAGS}" = "x"; then
IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>"
IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O"
fi
if test "x${IGNORE_CPPFLAGS}" = "x"; then
IGNORE_CPPFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O\|\-std\="
fi
if test -f ${ANDROID_NDK_ROOT}/build/ndk-build; then
@ -84,9 +88,9 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
exit 1
fi
echo "====="
echo "NDK_OUT : ${NDK_OUT}"
echo "====="
#echo "====="
#echo "NDK_OUT : ${NDK_OUT}"
#echo "====="
for i in $NDK_OUT; do
@ -96,13 +100,15 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
ADD_CXXFLAGS="0"
continue
fi
if test "$i" = "-c"; then
continue
fi
if test "x`echo $i|grep 'dummy'`" != "x"; then
continue
fi
if test "x`echo $i|grep '\-\-sysroot='`" != "x"; then
ANDROID_SYSROOT=`echo $i|sed 's/--sysroot=//'`;
if test "x`echo $i|grep ${IGNORE_CPPFLAGS}`" = "x"; then
NDK_CXXFLAGS="${NDK_CXXFLAGS} $i"
fi
NDK_CXXFLAGS="${NDK_CXXFLAGS} $i"
continue
fi
@ -132,6 +138,22 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
continue
fi
# Parse NDK LDFLAGS
if test "${ADD_LDFLAGS}" = "1"; then
if test "$i" = "-o"; then
ADD_LDFLAGS="0"
continue
fi
if test "x`echo $i|grep 'dummy'`" != "x"; then
continue
fi
if test "x`echo $i|grep '.so'`" != "x"; then
continue
fi
NDK_LDFLAGS="${NDK_LDFLAGS} $i"
continue
fi
# Find gcc or clang
if test "x${NDK_CC}" = "x"; then
if test "x`echo $i | grep 'gcc'`" != "x" -o "x`echo $i | grep 'clang'`" != "x"; then
@ -141,6 +163,7 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
IS_USING_LLVM="1"
#echo "---using llvm"
fi
continue
fi
fi
@ -149,23 +172,34 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
if test "x`echo $i | grep 'g++'`" != "x"; then
NDK_CXX=$i
ADD_CXXFLAGS="1"
continue
fi
fi
# Find linking/LDFLAGS
if test "x${NDK_LDFLAGS}" = "x"; then
if test "x`echo $i | grep '\-\<shared\>'`" != "x"; then
ADD_LDFLAGS="1"
continue
fi
fi
# Find ar tool
if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ar'`" != "x"; then
if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ar\>'`" != "x"; then
# In some NDKs, e.g: r17c, gcc/clang and ar have different path
#if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
NDK_AR=$i
#echo "--- found AR=${NDK_AR}"
fi
continue
#fi
fi
# Find ranlib tool
if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ranlib'`" != "x"; then
if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ranlib\>'`" != "x"; then
#if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
NDK_RANLIB=$i
#echo "--- found RANLIB=${NDK_RANLIB}"
fi
#fi
fi
done
@ -192,7 +226,7 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
NDK_CC_DIR=$(dirname "${NDK_CC}")
NDK_AR=`find ${NDK_CC_DIR} -name "*ar" | grep -m 1 -v "gcc"`
fi
export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT}"
export LDFLAGS="${LDFLAGS}"
else
# find ar and ranlib
if test "x${NDK_AR}" = "x"; then
@ -201,7 +235,7 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
if test "x${NDK_RANLIB}" = "x"; then
NDK_RANLIB=`find ${NDK_TOOLCHAIN}/bin/ -name "*-ranlib" | grep -m 1 -v "gcc"`
fi
export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}"
export LDFLAGS="${LDFLAGS} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}"
fi
if test "x${NDK_RANLIB}" = "x"; then
@ -219,10 +253,11 @@ if test "$1" = "--use-ndk-cflags" || [ "${NDK_VER}" -ge "17" ]; then
export CC="${NDK_CC}"
export CXX="${NDK_CXX}"
export LIBS="${LIBS} -lc -lgcc -ldl"
export LDFLAGS="${NDK_LDFLAGS}"
export LIBS="${LIBS}"
export CFLAGS="${NDK_CFLAGS} ${CFLAGS}"
export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
export CXXFLAGS="${NDK_CXXFLAGS} -fexceptions -frtti"
export CPPFLAGS="${NDK_CXXFLAGS} ${CPPFLAGS}"
export CXXFLAGS="${CPPFLAGS}"
else
@ -271,9 +306,10 @@ fi
if test "${IS_USING_LLVM}" = "1"; then
# llvm
STDCPP_TC="${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++"
STDCPP_CFLAGS="-I${STDCPP_TC}/include"
STDCPP_LIBS="-lc++_static -lc++abi"
STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/"
#STDCPP_CFLAGS="-I${STDCPP_TC}/include"
#STDCPP_LIBS="-lc++_static -lc++abi"
STDCPP_LIBS="${STDCPP_TC}/libs/${TARGET_ABI}/libc++_shared.so"
#STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/"
else
# gnustl
STDCPP_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/[0-9]* | sort -gr | head -1`
@ -290,6 +326,8 @@ fi
export CFLAGS="${CFLAGS} ${STDCPP_CFLAGS}"
export LIBS="${STDCPP_LIBS} ${LIBS}"
export LDFLAGS="${LDFLAGS} ${STDCPP_LDFLAGS}"
export CPPFLAGS="${CPPFLAGS} ${STDCPP_CFLAGS}"
export CXXFLAGS="${CPPFLAGS}"
# Print settings
if test "1" = "1"; then

@ -1,15 +1,12 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_static
LOCAL_SRC_FILES := dummy.c
LOCAL_SRC_FILES := dummy.c dummy2.cc
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_shared
LOCAL_STATIC_LIBRARIES := dummy_static
LOCAL_SRC_FILES := dummy.c
LOCAL_SRC_FILES := dummy.c dummy2.cc
include $(BUILD_SHARED_LIBRARY)

@ -1 +1,3 @@
APP_ABI := all
APP_ABI := all
APP_CPPFLAGS := -fexceptions -frtti
APP_STL := c++_shared

@ -0,0 +1,11 @@
#include <string>
#include <stdint.h>
#include <math.h>
int main() {
uint64_t blah = 0;
size_t blah2 = 1;
std::string blah3 = "3";
return 0;
}

@ -163,9 +163,11 @@ all: $(LIBPJSUA2_SO) java
$(LIBPJSUA2_SO): $(OUT_DIR)/pjsua2_wrap.o
ifeq ($(OS),android)
mkdir -p android/app/src/main/jniLibs/$(TARGET_ARCH)
# copy libc++_shared.so manually
cp -f ${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TARGET_ARCH}/libc++_shared.so android/app/src/main/jniLibs/$(TARGET_ARCH)
endif
$(PJ_CXX) -shared -o $(LIBPJSUA2_SO) $(OUT_DIR)/pjsua2_wrap.o \
$(MY_CFLAGS) $(MY_LDFLAGS)
$(MY_LDFLAGS)
$(OUT_DIR)/pjsua2_wrap.o: $(OUT_DIR)/pjsua2_wrap.cpp Makefile
$(PJ_CXX) -c $(OUT_DIR)/pjsua2_wrap.cpp -o $(OUT_DIR)/pjsua2_wrap.o \

@ -12,6 +12,12 @@ android {
ndk {
moduleName "libpjsua2"
}
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
}
buildTypes {

@ -46,8 +46,12 @@ export _CFLAGS := $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
$(CC_INC)../../pjlib-util/include \
$(CC_INC)../../pjnath/include \
$(CC_INC)../../pjmedia/include
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS)
export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS) $(CC_INC)../include \
$(CC_INC)../../pjlib/include \
$(CC_INC)../../pjlib-util/include \
$(CC_INC)../../pjnath/include \
$(CC_INC)../../pjmedia/include
export _LDFLAGS := $(APP_THIRD_PARTY_LIBS) \
$(APP_THIRD_PARTY_EXT) \
$(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
@ -140,7 +144,7 @@ export PJSUA2_LIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
account.o endpoint.o json.o persistent.o types.o \
siptypes.o call.o presence.o media.o
export PJSUA2_LIB_CFLAGS += $(_CFLAGS) $(PJ_VIDEO_CFLAGS)
export PJSUA2_LIB_CXXFLAGS = $(_CXXFLAGS) $(PJSUA2_LIB_CFLAGS)
export PJSUA2_LIB_CXXFLAGS = $(_CXXFLAGS)
export PJSUA2_LIB_LDFLAGS += $(PJSUA_LIB_LDLIB) \
$(PJSIP_UA_LDLIB) \
$(PJSIP_SIMPLE_LDLIB) \

@ -20,7 +20,7 @@ endif
export _CFLAGS := $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
$(CFLAGS) $(CC_INC). $(CC_INC)../../webrtc/src \
$(CC_INC)../../../pjlib/include
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS)
export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
$(LDFLAGS)

@ -19,8 +19,8 @@ endif
export _CFLAGS := $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) \
$(CFLAGS) $(CC_INC). $(CC_INC)../../yuv/include \
$(CC_INC)../../../pjlib/include
export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS)
export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
$(HOST_CXXFLAGS) $(CXXFLAGS) $(CC_INC). $(CC_INC)../../yuv/include
export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
$(LDFLAGS)

Loading…
Cancel
Save