Ignore:
Timestamp:
Dec 19, 2019 2:57:20 AM (4 years ago)
Author:
nanang
Message:

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).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/configure-android

    r6033 r6120  
    6767  ADD_CFLAGS="0" 
    6868  ADD_CXXFLAGS="0" 
     69  ADD_LDFLAGS="0" 
    6970  ADD_NDK_TOOLCHAIN="0" 
    7071  ADD_NDK_TARGET="0" 
    7172  if test "x${IGNORE_CFLAGS}" = "x"; then 
    72     IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>" 
     73    IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O" 
     74  fi 
     75  if test "x${IGNORE_CPPFLAGS}" = "x"; then 
     76    IGNORE_CPPFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O\|\-std\=" 
    7377  fi 
    7478   
     
    8589  fi 
    8690 
    87    echo "=====" 
    88    echo "NDK_OUT : ${NDK_OUT}" 
    89    echo "=====" 
     91  #echo "=====" 
     92  #echo "NDK_OUT : ${NDK_OUT}" 
     93  #echo "=====" 
    9094 
    9195  for i in $NDK_OUT; do 
     
    97101        continue 
    98102      fi 
     103      if test "$i" = "-c"; then 
     104        continue 
     105      fi 
    99106      if test "x`echo $i|grep 'dummy'`" != "x"; then 
    100107        continue 
    101108      fi 
    102       if test "x`echo $i|grep '\-\-sysroot='`" != "x"; then 
    103         ANDROID_SYSROOT=`echo $i|sed 's/--sysroot=//'`; 
    104       fi 
    105       NDK_CXXFLAGS="${NDK_CXXFLAGS} $i" 
     109      if test "x`echo $i|grep ${IGNORE_CPPFLAGS}`" = "x"; then 
     110        NDK_CXXFLAGS="${NDK_CXXFLAGS} $i" 
     111      fi 
    106112      continue 
    107113    fi 
     
    133139    fi 
    134140 
     141    # Parse NDK LDFLAGS 
     142    if test "${ADD_LDFLAGS}" = "1"; then 
     143      if test "$i" = "-o"; then 
     144        ADD_LDFLAGS="0" 
     145        continue 
     146      fi 
     147      if test "x`echo $i|grep 'dummy'`" != "x"; then 
     148        continue 
     149      fi 
     150      if test "x`echo $i|grep '.so'`" != "x"; then 
     151        continue 
     152      fi 
     153      NDK_LDFLAGS="${NDK_LDFLAGS} $i" 
     154      continue 
     155    fi 
     156 
    135157    # Find gcc or clang 
    136158    if test "x${NDK_CC}" = "x"; then 
     
    142164          #echo "---using llvm" 
    143165        fi 
     166        continue 
    144167      fi 
    145168    fi 
     
    150173        NDK_CXX=$i 
    151174        ADD_CXXFLAGS="1" 
     175        continue 
     176      fi 
     177    fi 
     178 
     179    # Find linking/LDFLAGS 
     180    if test "x${NDK_LDFLAGS}" = "x"; then 
     181      if test "x`echo $i | grep '\-\<shared\>'`" != "x"; then 
     182        ADD_LDFLAGS="1" 
     183        continue 
    152184      fi 
    153185    fi 
    154186 
    155187    # Find ar tool 
    156     if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ar'`" != "x"; then 
    157       if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then 
     188    if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ar\>'`" != "x"; then 
     189      # In some NDKs, e.g: r17c, gcc/clang and ar have different path 
     190      #if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then 
    158191        NDK_AR=$i 
    159192        #echo "--- found AR=${NDK_AR}" 
    160       fi 
     193        continue 
     194      #fi 
    161195    fi 
    162196 
    163197    # Find ranlib tool 
    164     if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ranlib'`" != "x"; then 
    165       if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then 
     198    if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ranlib\>'`" != "x"; then 
     199      #if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then 
    166200        NDK_RANLIB=$i 
    167201        #echo "--- found RANLIB=${NDK_RANLIB}" 
    168       fi 
     202      #fi 
    169203    fi 
    170204  done 
     
    193227      NDK_AR=`find ${NDK_CC_DIR} -name "*ar" | grep -m 1 -v "gcc"` 
    194228    fi 
    195     export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT}" 
     229    export LDFLAGS="${LDFLAGS}" 
    196230  else 
    197231    # find ar and ranlib 
     
    202236      NDK_RANLIB=`find ${NDK_TOOLCHAIN}/bin/ -name "*-ranlib" | grep -m 1 -v "gcc"` 
    203237    fi 
    204     export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}" 
     238    export LDFLAGS="${LDFLAGS} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}" 
    205239  fi 
    206240 
     
    220254  export CXX="${NDK_CXX}" 
    221255 
    222   export LIBS="${LIBS} -lc -lgcc -ldl" 
     256  export LDFLAGS="${NDK_LDFLAGS}" 
     257  export LIBS="${LIBS}" 
    223258  export CFLAGS="${NDK_CFLAGS} ${CFLAGS}" 
    224   export CPPFLAGS="${CFLAGS} -fexceptions -frtti" 
    225   export CXXFLAGS="${NDK_CXXFLAGS} -fexceptions -frtti" 
     259  export CPPFLAGS="${NDK_CXXFLAGS} ${CPPFLAGS}" 
     260  export CXXFLAGS="${CPPFLAGS}" 
    226261 
    227262else 
     
    272307  # llvm 
    273308  STDCPP_TC="${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++" 
    274   STDCPP_CFLAGS="-I${STDCPP_TC}/include" 
    275   STDCPP_LIBS="-lc++_static -lc++abi" 
    276   STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/" 
     309  #STDCPP_CFLAGS="-I${STDCPP_TC}/include" 
     310  #STDCPP_LIBS="-lc++_static -lc++abi" 
     311  STDCPP_LIBS="${STDCPP_TC}/libs/${TARGET_ABI}/libc++_shared.so" 
     312  #STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/" 
    277313else 
    278314  # gnustl 
     
    291327export LIBS="${STDCPP_LIBS} ${LIBS}" 
    292328export LDFLAGS="${LDFLAGS} ${STDCPP_LDFLAGS}" 
     329export CPPFLAGS="${CPPFLAGS} ${STDCPP_CFLAGS}" 
     330export CXXFLAGS="${CPPFLAGS}" 
    293331 
    294332# Print settings 
Note: See TracChangeset for help on using the changeset viewer.