-
Notifications
You must be signed in to change notification settings - Fork 218
/
make.sh
executable file
·150 lines (129 loc) · 2.94 KB
/
make.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
#
# vdexExtractor
# -----------------------------------------
#
# Anestis Bechtsoudis <anestis@census-labs.com>
# Copyright 2017 by CENSUS S.A. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e # fail on unhandled error
set -u # fail on undefined variable
#set -x # debug
declare -a sysTools=( "make" )
readonly MODULE_NAME="vdexExtractor"
function commandExists()
{
type "$1" &> /dev/null
}
function usage()
{
echo "$(basename "$0") [gcc|clang|cross-android|clean] (default is gcc)"
exit 1
}
function build_cross_android()
{
local cpu cpuBaseDir
if [[ -z ${NDK+x} ]]; then
# Search in $PATH
if [[ $(which ndk-build) != "" ]]; then
NDK=$(dirname "$(which ndk-build)")
else
echo "[-] Could not detect Android NDK dir"
exit 1
fi
fi
local ndk_extra_args=""
if [ "$DEBUG_BUILD" = true ]; then
ndk_extra_args+="V=1 NDK_DEBUG=1 APP_OPTIM=debug"
fi
"$NDK/ndk-build" clean
"$NDK/ndk-build" $ndk_extra_args || {
echo "[-] android build failed"
exit 1
}
local baseDir=libs
if [ "$DEBUG_BUILD" = true ]; then
baseDir=obj/local
fi
find libs -mindepth 1 -maxdepth 1 -type d | while read -r cpuBaseDir
do
cpu=$(basename "$cpuBaseDir")
cp "$baseDir/$cpu/$MODULE_NAME" "bin/$MODULE_NAME-android-$cpu"
done
}
function build()
{
local compiler="$1"
if [[ "$compiler" == "" ]]; then
if [[ -z ${CC+x} || "$CC" == "" ]]; then
compiler="gcc"
else
compiler="$CC"
fi
fi
make clean -C src || {
echo "[-] make clean failed"
exit 1
}
CC=$compiler DEBUG=$DEBUG_BUILD make -C src || {
echo "[-] build failed"
exit 1
}
}
function clean()
{
make clean -C src || {
echo "[-] make clean failed"
exit 1
}
if [[ -z ${NDK+x} ]]; then
# Search in $PATH
if [[ $(which ndk-build) != "" ]]; then
NDK=$(dirname "$(which ndk-build)")
"$NDK/ndk-build" clean
fi
fi
}
# Check that common system tools exist
for i in "${sysTools[@]}"
do
if ! commandExists "$i"; then
echo "[-] '$i' command not found"
exit 1
fi
done
if [ $# -gt 1 ]; then
echo "[-] Invalid args"
exit 1
fi
if [ $# -eq 0 ]; then
target=""
else
target="$1"
fi
if [[ -z ${DEBUG+x} || $DEBUG != true ]]; then
DEBUG_BUILD=false
else
DEBUG_BUILD=true
fi
case "$target" in
"") build "";;
"gcc") build "gcc";;
"clang") build "clang";;
"cross-android") build_cross_android;;
"clean") clean;;
*) usage;;
esac
exit 0