1 #!/bin/sh 2 3 # The purpose of this script is the following: 4 # 5 # 1/ Build the libraries under prebuilts/jni/ 6 # 7 # 2/ Build the project under jni/ 8 # 9 # 3/ Check that the prebuilt shared library was copied to 10 # $NDK_OUT/<abi>/objs. 11 # 12 # 4/ Check that the prebuilt static library was not copied to 13 # the same directory. 14 # 15 16 PROGDIR=$(dirname "$0") 17 18 OUT=$PROGDIR/obj/local 19 PREBUILTS_DIR=$PROGDIR/prebuilts 20 PREBUILTS_DIR=$(cd "$PREBUILTS_DIR" && pwd) 21 22 if [ -n "$APP_ABI" ]; then 23 ABIS="$APP_ABI" 24 else 25 ABIS= 26 for OPT; do 27 case $OPT in 28 APP_ABI=*) 29 ABIS=${OPT##APP_ABI=} 30 APP_ABI=$ABIS 31 ;; 32 esac 33 done 34 35 if [ -z "$ABIS" ]; then 36 ABIS="armeabi armeabi-v7a x86 mips armeabi-v7a-hard" 37 fi 38 fi 39 40 # Step 0: Remove obj/ and libs/ to ensure everything is clean 41 rm -rf obj/ libs/ 42 rm -rf $PREBUILTS_DIR/obj/ $PREBUILTS_DIR/libs/ 43 44 # Step 1: Build prebuilt libraries. 45 if [ -z "$APP_ABI" ]; then 46 $NDK/ndk-build -C "$PREBUILTS_DIR" 47 RET=$? 48 else 49 $NDK/ndk-build -C "$PREBUILTS_DIR" APP_ABI="$APP_ABI" 50 RET=$? 51 fi 52 53 if [ $RET != 0 ]; then 54 echo "ERROR: Can't build prebuilt libraries!" 55 exit 1 56 fi 57 58 # Step 2: Build the project 59 if [ -z "$APP_ABI" ]; then 60 PREBUILTS_DIR=$PREBUILTS_DIR $NDK/ndk-build -C "$PROGDIR" 61 RET=$? 62 else 63 PREBUILTS_DIR=$PREBUILTS_DIR $NDK/ndk-build -C "$PROGDIR" APP_ABI="$APP_ABI" 64 RET=$? 65 fi 66 67 if [ $RET != 0 ]; then 68 echo "ERROR: Can't build project!" 69 exit 1 70 fi 71 72 # Step 3: Check that the prebuilt shared library was copied to the 73 # right location. 74 # 75 76 FAILURES=0 77 for ABI in $ABIS; do 78 printf "Checking for $ABI shared library: " 79 SHARED_LIB=$(ls $OUT/*$ABI/libfoo.so 2>/dev/null) 80 if [ $? != 0 ]; then 81 printf "KO! missing file: $SHARED_LIB\n" 82 FAILURES=$(( $FAILURES + 1 )) 83 else 84 printf "ok\n" 85 fi 86 87 printf "Checking for $ABI static library: " 88 STATIC_LIB=$(ls $OUT/*$ABI/libbar.a 2>/dev/null) 89 if [ $? = 0 ]; then 90 printf "KO! file should not exist: $STATIC_LIB\n" 91 FAILURES=$(( $FAILURES + 1 )) 92 else 93 printf "ok\n" 94 fi 95 done 96 97 if [ "$FAILURES" = 0 ]; then 98 echo "Everything's ok. Congratulations!" 99 exit 0 100 else 101 echo "Found $FAILURES failures! Please fix ndk-build!" 102 exit 1 103 fi 104