|
Packit |
ea1746 |
#!/bin/bash
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Bash script to assert that the current version of the NDK is at least the
|
|
Packit |
ea1746 |
# specified version. Prints 'true' to standard out if it's the right version,
|
|
Packit |
ea1746 |
# 'false' if it's not.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Typically used like this, in your jni/Android.mk:
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# ifneq ($(shell $(LOCAL_PATH)/assert_ndk_version.sh "r5c" "ndk-dir"), true)
|
|
Packit |
ea1746 |
# $(error NDK version r5c or greater required)
|
|
Packit |
ea1746 |
# endif
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# See https://gist.github.com/2878774 for asserting SDK version.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Retrieved from: https://gist.github.com/jorgenpt/1961404 on 2014-06-03.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Copyright (c) 2012, Lookout, Inc. All rights reserved.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Redistribution and use in source and binary forms, with or without
|
|
Packit |
ea1746 |
# modification, are permitted provided that the following conditions are met:
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# 1. Redistributions of source code must retain the above copyright notice,
|
|
Packit |
ea1746 |
# this list of conditions and the following disclaimer.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
ea1746 |
# notice, this list of conditions and the following disclaimer in the
|
|
Packit |
ea1746 |
# documentation and/or other materials provided with the distribution.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
ea1746 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
Packit |
ea1746 |
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
Packit |
ea1746 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
Packit |
ea1746 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
Packit |
ea1746 |
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
Packit |
ea1746 |
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
Packit |
ea1746 |
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
Packit |
ea1746 |
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
Packit |
ea1746 |
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
Packit |
ea1746 |
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
ea1746 |
#
|
|
Packit |
ea1746 |
# Author: jorgenpt@gmail.com (Jorgen Tjerno)
|
|
Packit |
ea1746 |
# alexs.mac@gmail.com (Alex Stewart)
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Extracts 'r5c' into '5 c', also handles newer versions of the form
|
|
Packit |
ea1746 |
# 'r9d (64-bit)' and versions >= 10.
|
|
Packit |
ea1746 |
function get_major_minor() {
|
|
Packit |
ea1746 |
# r9d (64-bit) -> '9d', also handle versions >= 10.
|
|
Packit |
ea1746 |
local version=$(echo "$1" | sed 's/r\([0-9]\{1,2\}[a-z]\{0,1\}\).*/\1/')
|
|
Packit |
ea1746 |
local major=$(echo "$version" | sed 's/\([0-9]\{1,2\}\).*/\1/')
|
|
Packit |
ea1746 |
local minor=$(echo "$version" | sed 's/^[0-9]*//')
|
|
Packit |
ea1746 |
echo "$major $minor"
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if [[ -z "$2" ]]; then
|
|
Packit |
ea1746 |
echo "Usage: $0 <required version> <NDK_ROOT>" >&2
|
|
Packit |
ea1746 |
echo " For example: $0 r5c android-ndk-r9d" >&2
|
|
Packit |
ea1746 |
exit 1
|
|
Packit |
ea1746 |
fi
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Assert that the expected version is at least 4.
|
|
Packit |
ea1746 |
declare -a expected_version
|
|
Packit |
ea1746 |
expected_version=( $(get_major_minor "$1") )
|
|
Packit |
ea1746 |
if [[ ${expected_version[0]} -le 4 ]]; then
|
|
Packit |
ea1746 |
echo "Cannot test for versions less than r5: r4 doesn't have a version file." >&2
|
|
Packit |
ea1746 |
echo false
|
|
Packit |
ea1746 |
exit 1
|
|
Packit |
ea1746 |
fi
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
release_file="$2/RELEASE.TXT"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# NDK version r4 or earlier doesn't have a RELEASE.txt, and we just asserted
|
|
Packit |
ea1746 |
# that the person was looking for r5 or above, so that implies that this is an
|
|
Packit |
ea1746 |
# invalid version.
|
|
Packit |
ea1746 |
if [ ! -s "$release_file" ]; then
|
|
Packit |
ea1746 |
echo false
|
|
Packit |
ea1746 |
exit 0
|
|
Packit |
ea1746 |
fi
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
# Make sure the data is at least kinda sane.
|
|
Packit |
ea1746 |
version=$(grep '^r' $release_file)
|
|
Packit |
ea1746 |
declare -a actual_version
|
|
Packit |
ea1746 |
actual_version=( $(get_major_minor "$version") )
|
|
Packit |
ea1746 |
if [ -z "$version" ] || [ -z "${actual_version[0]}" ]; then
|
|
Packit |
ea1746 |
echo "Invalid RELEASE.txt: $(cat $release_file)" >&2
|
|
Packit |
ea1746 |
echo false
|
|
Packit |
ea1746 |
exit 1
|
|
Packit |
ea1746 |
fi
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if [[ ${actual_version[0]} -lt ${expected_version[0]} ]]; then
|
|
Packit |
ea1746 |
echo "false"
|
|
Packit |
ea1746 |
elif [[ ${actual_version[0]} -eq ${expected_version[0]} ]]; then
|
|
Packit |
ea1746 |
# This uses < and not -lt because they're string identifiers (a, b, c, etc)
|
|
Packit |
ea1746 |
if [[ "${actual_version[1]}" < "${expected_version[1]}" ]]; then
|
|
Packit |
ea1746 |
echo "false"
|
|
Packit |
ea1746 |
else
|
|
Packit |
ea1746 |
echo "true"
|
|
Packit |
ea1746 |
fi
|
|
Packit |
ea1746 |
else
|
|
Packit |
ea1746 |
echo "true"
|
|
Packit |
ea1746 |
fi
|