-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.sh
executable file
·149 lines (134 loc) · 3.78 KB
/
build.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
#!/data/data/com.termux/files/usr/bin/bash
# File : build.sh
# Author : rendiix <vanzdobz@gmail.com>
# Create date: 22-Jan-2020 19:04
if [[ $(which ndk-build) != "" ]]; then
NDK=$(which ndk-build);
else
echo -e "$1: Could not find Android NDK directory !\nMake sure you have installed android NDK!"; exit 1;
fi
build ()
{
JOBS=$(grep -c ^processor /proc/cpuinfo);
if [ "$OPT_DEBUG" = "true" ]; then
DEBUGFLAGS="NDK_DEBUG=1 APP_OPTIM=debug";
fi;
TOOLCHAINS=${COMPILER} BUILD=${OPT_TARGET_ARCH} STATIC=${OPT_STATIC} $NDK ${DEBUGFLAGS} V=${OPT_VERBOSE} -j${JOBS};
if [ "$?" = 0 ]; then
find libs -mindepth 1 -maxdepth 1 -type d | while read -r meki; do
DIR_ABI=$(basename "$meki");
if [ ! -d "prebuilt_binary" ]; then
mkdir prebuilt_binary;
fi;
if [ "$OPT_NO_COPY" = "0" ]; then
for binary in "make_ext4fs" "img2simg" "simg2img" "sefcontext_decompile";
do
cp -f "libs/${DIR_ABI}/${binary}" "prebuilt_binary/${binary}_android_${DIR_ABI}";
done;
fi;
done;
fi;
rm -rf libs;
rm -rf obj
}
HELP ()
{
echo -e "Usage $0 <options>
Options:
-t, --target <arm|arm64|x86|x86_64>
build single target executable i.e: <arm|aarch64|x86|x86_64>.
-c, --compiler <clang|gcc>
select compiler gcc or clang.
-s, --static compile static executable binary.
-n, --no-copy dont copy compiled binary to bin folder.
-d, --debug compile with debugable binary.
-v, --verbose verbose compilation.
-h, --help show this help message and exit.
-q, --quiet build with silent stdout"
}
OPTS=`busybox getopt -o t:c:vsndhq --long target:,compiler:verbose,static,no-copy,debug,quiet,help -n "$0" -- "$@"`
if [ "$?" -ne "0" ]; then
HELP; exit 1;
fi
eval set -- "$OPTS"
OPT_DEBUG="0"
OPT_TARGET_ARCH="all"
OPT_VERBOSE="0"
OPT_STATIC="0"
OPT_HELP="false"
OPT_QUIET="0"
OPT_NO_COPY="0"
COMPILER=clang
if [ -z "$1" ]; then
echo -e "No options was given, building with default options.
To see more options:
$0 --help\n";
fi
while true; do
case "$1" in
-t | --target)
OPT_TARGET_ARCH="$2"; shift
;;
-c | --compiler)
if [[ "$2" -ne "clang" || "$2" -ne "gcc" ]]; then
echo "$2 is not valid compiler, use gcc or clang"; HELP; exit 1;
fi; COMPILER="$2"; shift
;;
-h | --help)
OPT_HELP=true
;;
-d | --debug)
OPT_DEBUG=true
;;
-v | --verbose)
OPT_VERBOSE=1
;;
-n | --no-copy)
OPT_NO_COPY=1
;;
-s | --static)
OPT_STATIC=1
;;
-q | --quiet)
OPT_QUIET=1
;;
--)
shift; break
;;
*)
break
;;
esac; shift;
done
info ()
{
echo -e "\nBuild start with cofiguration:\n";
echo -e "BUILD TARGET ARCH: $OPT_TARGET_ARCH";
echo -e "EXE TYPE : $(if [ "$OPT_STATIC" = 1 ]; then echo STATIC; else echo SHARED;fi)";
echo -e "VERBOSE : $(if [ "$OPT_VERBOSE" = 1 ]; then echo YES; else echo NO;fi)";
echo -e "BUILD TYPE : $(if [ "$OPT_DEBUG" = 1 ]; then echo DEBUG; else echo RELEASE;fi)";
echo -e "COMPILER : $COMPILER";
echo -e "\n$0 --help\nto show more options";
sleep 2;
echo -e "\nPlease wait... \c"
}
case "$OPT_TARGET_ARCH" in
arm | arm64 | x86 | x86_64 | all)
;;
*)
echo "unknown arch $OPT_TARGET_ARCH"; exit 1
;;
esac
if [ "$OPT_HELP" = "true" ]; then
HELP; exit 1;
fi
if [ "$OPT_QUIET" = 0 ]; then
info; build;
else
info; build &> /dev/null;
fi
if [ "$?" = 0 ]; then
echo "done";
else
echo "someting went wrong!";
fi