Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tools / cross / install_android_ndk.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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 # Setup Android Cross-Build Environment
18
19 usage()
20 {
21     echo "Usage: $0 [--ndk-version=NDKVersion] [--install-dir=InstallDir]"
22     echo "  NDKVersion : r20(default) or higher"
23     echo "  InstallDir : Path to be installed"
24     exit 1
25 }
26
27 __CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
28 __NDKVersion=r20
29 __UnprocessedBuildArgs=
30
31 while [[ $# -gt 0 ]]
32 do
33     key="$(echo $1 | awk '{print tolower($0)}')"
34     case "$key" in
35         -?|-h|--help)
36             usage
37             exit 1
38             ;;
39         --ndk-version)
40             __NDKVersion="$2"
41             shift
42             ;;
43         --ndk-version=*)
44             __NDKVersion="${1#*=}"
45             ;;
46         --install-dir)
47             __InstallDir="$2"
48             shift
49             ;;
50         --install-dir=*)
51             __InstallDir="${1#*=}"
52             ;;
53         *)
54             echo "Invalid option '$1'"
55             usage
56             exit 1
57             ;;
58     esac
59     shift
60 done
61
62 __InstallDir=${__InstallDir:-"${__CrossDir}/ndk/${__NDKVersion}"}
63
64 NDK_DIR=android-ndk-${__NDKVersion}
65 NDK_ZIP=${NDK_DIR}-linux-x86_64.zip
66
67 if [[ -e $__InstallDir ]]; then
68   echo "ERROR: $__InstallDir already exists"
69   exit 1
70 fi
71
72 echo "Downloading Android NDK ${__NDKVersion}"
73 mkdir -p "$__InstallDir"
74
75 wget -nv -nc https://dl.google.com/android/repository/$NDK_ZIP -O $__InstallDir/$NDK_ZIP
76
77 if [ $? -ne 0 ]; then
78     echo "Failed downloading. Please check NDK version and network connection."
79     exit 1
80 fi
81
82 echo "Unzipping Android NDK"
83 unzip -qq -o $__InstallDir/$NDK_ZIP -d $__InstallDir
84 rm $__InstallDir/$NDK_ZIP
85 mv  $__InstallDir/${NDK_DIR} "$__InstallDir/ndk" # This is necessary since Tensorflow Lite does include like `#include "ndk/sources/..."`