Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2010 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 
     18 # Extract current directory
     19 PROGDIR=$(dirname $0)
     20 PROGDIR=$(cd $PROGDIR && pwd)
     21 PROGNAME=$(basename $0)
     22 
     23 # Compute NDK directory, we assume we are under tests/
     24 NDK=$(dirname $PROGDIR)
     25 
     26 
     27 NDK_BUILDTOOLS_PATH=$NDK/build/tools
     28 . $NDK_BUILDTOOLS_PATH/prebuilt-common.sh
     29 
     30 # Prepare the temporary standalone toolchain
     31 ROOTDIR=/tmp/ndk-$USER/tests/standalone
     32 
     33 PROGRAM_PARAMETERS=""
     34 PROGRAM_DESCRIPTION="Run the standalone toolchain tests."
     35 
     36 ARCH=arm
     37 register_var_option "--arch=<name>" ARCH "Specify architecture"
     38 
     39 PLATFORM=android-9
     40 register_var_option "--platform=<platform>" PLATFORM "Specify target platform"
     41 
     42 process_options $@
     43 
     44 # Where we're going to place generated files
     45 OBJDIR=$ROOTDIR/obj
     46 mkdir -p $OBJDIR
     47 
     48 # Install standalone toolchain
     49 # $1: API level (e.g. android-3)
     50 # $2: Architecture name
     51 # This sets TOOLCHAINDIR and TOOLCHAINPREFIX
     52 install_toolchain ()
     53 {
     54     local LEVEL
     55     LEVEL=${1##android-}  # remove initial 'android-'
     56     TOOLCHAINDIR=$ROOTDIR/toolchain-$LEVEL
     57     mkdir -p $TOOLCHAINDIR
     58     echo "Installing $ARCH standalone toolchain into: $TOOLCHAINDIR"
     59     $NDK/build/tools/make-standalone-toolchain.sh --install-dir=$TOOLCHAINDIR --platform=$1 --arch=$2
     60     if [ $? != 0 ] ; then
     61         echo "ERROR: Could not install toolchain for platform $1."
     62         exit 1
     63     fi
     64     # XXX: TODO: Extract dynamically
     65     TOOLCHAINPREFIX=$TOOLCHAINDIR/bin/$(get_default_toolchain_prefix_for_arch $ARCH)
     66 }
     67 
     68 # Compile and link a C++ source file
     69 compile_and_link_cxx ()
     70 {
     71     local EXENAME="$(basename $1)"
     72     EXENAME=${EXENAME##.c}
     73     EXENAME=${EXENAME##.cpp}
     74     echo "Building C++ test: $EXENAME"
     75     $TOOLCHAINPREFIX-g++ -o $OBJDIR/$EXENAME $1
     76     if [ $? != 0 ] ; then
     77         echo "ERROR: Could not compile C++ source file: $1"
     78         exit 2
     79     fi
     80 }
     81 
     82 install_toolchain android-9 $ARCH
     83 
     84 for CXXSRC in $PROGDIR/standalone/*/*.cpp $PROGDIR/standalone/*/*.c; do
     85     compile_and_link_cxx $CXXSRC
     86 done
     87 
     88 echo "Cleaning up."
     89 rm -rf $ROOTDIR
     90