• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16PROGDIR=$(dirname "$0")
17
18OUT=$PROGDIR/obj/local
19PREBUILTS_DIR=$PROGDIR/prebuilts
20PREBUILTS_DIR=$(cd "$PREBUILTS_DIR" && pwd)
21
22if [ -n "$APP_ABI" ]; then
23  ABIS="$APP_ABI"
24else
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
38fi
39
40# Step 0: Remove obj/ and libs/ to ensure everything is clean
41rm -rf obj/ libs/
42rm -rf $PREBUILTS_DIR/obj/ $PREBUILTS_DIR/libs/
43
44# Step 1: Build prebuilt libraries.
45if [ -z "$APP_ABI" ]; then
46  $NDK/ndk-build -C "$PREBUILTS_DIR"
47  RET=$?
48else
49  $NDK/ndk-build -C "$PREBUILTS_DIR" APP_ABI="$APP_ABI"
50  RET=$?
51fi
52
53if [ $RET != 0 ]; then
54  echo "ERROR: Can't build prebuilt libraries!"
55  exit 1
56fi
57
58# Step 2: Build the project
59if [ -z "$APP_ABI" ]; then
60  PREBUILTS_DIR=$PREBUILTS_DIR $NDK/ndk-build -C "$PROGDIR"
61  RET=$?
62else
63  PREBUILTS_DIR=$PREBUILTS_DIR $NDK/ndk-build -C "$PROGDIR" APP_ABI="$APP_ABI"
64  RET=$?
65fi
66
67if [ $RET != 0 ]; then
68  echo "ERROR: Can't build project!"
69  exit 1
70fi
71
72# Step 3: Check that the prebuilt shared library was copied to the
73#         right location.
74#
75
76FAILURES=0
77for 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
95done
96
97if [ "$FAILURES" = 0 ]; then
98  echo "Everything's ok. Congratulations!"
99  exit 0
100else
101  echo "Found $FAILURES failures! Please fix ndk-build!"
102  exit 1
103fi
104