1#!/bin/bash
2# Copyright 2015 The Gemmlowp Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16if [ -z "$CXX" ]
17then
18  echo "please set the CXX environment variable to point to your native Android toolchain C++ compiler"
19  exit 1
20fi
21
22default_cflags="-O3"
23
24if [ "$#" -eq 0 ]
25then
26  echo "Usage: $0 files... [cflags...]"
27  echo "All command-line parameters are passed along to the C++ compiler, so they can \
28be either source files, or compiler flags."
29  echo "Default cflags: $default_cflags"
30  echo "Relies on the CXX environment variable to point to an Android C++ toolchain compiler."
31  exit 1
32fi
33
34EXE=gemmlowp-android-binary
35
36if [[ $CXX =~ .*aarch64.* ]]
37then
38  NEON_FLAGS=
39else
40  NEON_FLAGS="-mfpu=neon -mfloat-abi=softfp"
41fi
42
43$CXX \
44 --std=c++11 \
45 -Wall -Wextra -pedantic \
46 -fPIE -pie $NEON_FLAGS \
47 -lstdc++ -latomic \
48 -I . -I .. \
49 -o $EXE \
50 -Wno-unused-variable -Wno-unused-parameter \
51 $default_cflags \
52 $*
53
54if [ $? != 0 ]; then
55  echo "build failed"
56  exit 1
57fi
58
59adb root
60
61if [ $? != 0 ]; then
62  echo "$0: adb root failed"
63  exit 1
64fi
65
66adb shell mkdir -p /data/local/tmp
67
68if [ $? != 0 ]; then
69  echo "$0: adb shell failed to mkdir /data/local/tmp"
70  exit 1
71fi
72
73adb push $EXE /data/local/tmp
74
75if [ $? != 0 ]; then
76  echo "$0: adb push failed to write to /data/local/tmp"
77  exit 1
78fi
79
80echo adb shell "/data/local/tmp/$EXE $TESTARGS"
81
82adb shell "/data/local/tmp/$EXE $TESTARGS" | tee "log-$EXE"
83
84if [ $? != 0 ]; then
85  echo "$0: adb shell failed to run binary on device"
86  exit 1
87fi
88