• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
19PROGDIR=$(dirname $0)
20PROGDIR=$(cd $PROGDIR && pwd)
21PROGNAME=$(basename $0)
22
23# Compute NDK directory, we assume we are under tests/
24NDK=$(dirname $PROGDIR)
25
26
27NDK_BUILDTOOLS_PATH=$NDK/build/tools
28. $NDK_BUILDTOOLS_PATH/prebuilt-common.sh
29
30# Prepare the temporary standalone toolchain
31ROOTDIR=/tmp/ndk-$USER/tests/standalone
32
33PROGRAM_PARAMETERS=""
34PROGRAM_DESCRIPTION="Run the standalone toolchain tests."
35
36ARCH=arm
37register_var_option "--arch=*" ARCH "Specify architecture"
38
39PLATFORM=android-9
40register_var_option "--platform=*" PLATFORM "Specify target platform"
41
42process_options $@
43
44# Where we're going to place generated files
45OBJDIR=$ROOTDIR/obj
46mkdir -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
52install_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)
66}
67
68# Compile and link a C++ source file
69compile_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
82install_toolchain android-9 $ARCH
83
84for CXXSRC in $PROGDIR/standalone/*/*.cpp $PROGDIR/standalone/*/*.c; do
85    compile_and_link_cxx $CXXSRC
86done
87
88echo "Cleaning up."
89rm -rf $ROOTDIR
90