Skip to content

Commit c7b5bfc

Browse files
committed
fix script
1 parent c6db78a commit c7b5bfc

File tree

1 file changed

+95
-82
lines changed

1 file changed

+95
-82
lines changed

build.sh

Lines changed: 95 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
#!/data/data/com.termux/files/usr/bin/bash
22
# File : build.sh
33
# Author : rendiix <vanzdobz@gmail.com>
4-
# Create date: 4-Jul-2019 09:51
4+
# Create date: 22-Jan-2020 19:04
55

66
if [[ $(which ndk-build) != "" ]]; then
7-
NDK=$(which ndk-build)
8-
else
9-
echo -e "$1: Could not find Android NDK directory !\nMake sure you have installed android NDK!"
10-
exit 1
11-
fi
12-
13-
function build() {
14-
JOBS=$(grep -c ^processor /proc/cpuinfo)
15-
if [ "$OPT_DEBUG" = "true" ]; then
16-
DEBUGFLAGS="NDK_DEBUG=1 APP_OPTIM=debug"
17-
fi
18-
TOOLCHAINS=${COMPILER} BUILD=${OPT_TARGET_ARCH} STATIC=${OPT_STATIC} $NDK ${DEBUGFLAGS} V=${OPT_VERBOSE} -j${JOBS}
19-
20-
if [ "$?" = 0 ]; then
21-
find libs -mindepth 1 -maxdepth 1 -type d | while read -r meki
22-
do
23-
DIR_ABI=$(basename "$meki")
24-
if [ ! -d "bin" ]; then
25-
mkdir bin
26-
fi
27-
if [ "$OPT_NO_COPY" = "0" ]; then
28-
for binary in "make_ext4fs" "img2simg" "simg2img" "sefcontext_decompile"; do
29-
cp -f "libs/${DIR_ABI}/${binary}" "bin/${binary}_android_${DIR_ABI}"
30-
done
31-
rm -rf libs
32-
fi
33-
done
7+
NDK=$(which ndk-build);
8+
else
9+
echo -e "$1: Could not find Android NDK directory !\nMake sure you have installed android NDK!"; exit 1;
3410
fi
35-
rm -rf obj
11+
12+
build ()
13+
{
14+
JOBS=$(grep -c ^processor /proc/cpuinfo);
15+
if [ "$OPT_DEBUG" = "true" ]; then
16+
DEBUGFLAGS="NDK_DEBUG=1 APP_OPTIM=debug";
17+
fi;
18+
TOOLCHAINS=${COMPILER} BUILD=${OPT_TARGET_ARCH} STATIC=${OPT_STATIC} $NDK ${DEBUGFLAGS} V=${OPT_VERBOSE} -j${JOBS};
19+
if [ "$?" = 0 ]; then
20+
find libs -mindepth 1 -maxdepth 1 -type d | while read -r meki; do
21+
DIR_ABI=$(basename "$meki");
22+
if [ ! -d "prebuilt_binary" ]; then
23+
mkdir prebuilt_binary;
24+
fi;
25+
if [ "$OPT_NO_COPY" = "0" ]; then
26+
for binary in "make_ext4fs" "img2simg" "simg2img" "sefcontext_decompile";
27+
do
28+
cp -f "libs/${DIR_ABI}/${binary}" "prebuilt_binary/${binary}_android_${DIR_ABI}";
29+
done;
30+
fi;
31+
done;
32+
fi;
33+
rm -rf libs;
34+
rm -rf obj
3635
}
3736

38-
function HELP() {
39-
echo -e "Usage $0 <options>
37+
HELP ()
38+
{
39+
echo -e "Usage $0 <options>
4040
4141
Options:
4242
-t, --target <arm|arm64|x86|x86_64>
@@ -51,13 +51,10 @@ Options:
5151
-q, --quiet build with silent stdout"
5252
}
5353

54-
OPTS=`busybox getopt -o t:c:vsndhq \
55-
--long target:,compiler:verbose,static,no-copy,debug,quiet,help \
56-
-n "$0" -- "$@"`
54+
OPTS=`busybox getopt -o t:c:vsndhq --long target:,compiler:verbose,static,no-copy,debug,quiet,help -n "$0" -- "$@"`
5755

5856
if [ "$?" -ne "0" ]; then
59-
HELP
60-
exit 1
57+
HELP; exit 1;
6158
fi
6259
eval set -- "$OPTS"
6360

@@ -71,66 +68,82 @@ OPT_NO_COPY="0"
7168
COMPILER=clang
7269

7370
if [ -z "$1" ]; then
74-
echo -e "No options was given, building with default options.
71+
echo -e "No options was given, building with default options.
7572
To see more options:
76-
$0 --help\n"
77-
fi
73+
$0 --help\n";
74+
fi
7875

7976
while true; do
80-
case "$1" in
81-
-t | --target ) OPT_TARGET_ARCH="$2"; shift;;
82-
-c | --compiler )
83-
if [[ "$2" -ne "clang" || "$2" -ne "gcc" ]]; then
84-
echo "$2 is not valid compiler, use gcc or clang"
85-
HELP
86-
exit 1
87-
fi
88-
COMPILER="$2"; shift;;
89-
-h | --help ) OPT_HELP=true;;
90-
-d | --debug ) OPT_DEBUG=true;;
91-
-v | --verbose ) OPT_VERBOSE=1;;
92-
-n | --no-copy ) OPT_NO_COPY=1;;
93-
-s | --static ) OPT_STATIC=1;;
94-
-q | --quiet ) OPT_QUIET=1;;
95-
-- ) shift; break ;;
96-
*) break ;;
97-
esac
98-
shift
77+
case "$1" in
78+
-t | --target)
79+
OPT_TARGET_ARCH="$2"; shift
80+
;;
81+
-c | --compiler)
82+
if [[ "$2" -ne "clang" || "$2" -ne "gcc" ]]; then
83+
echo "$2 is not valid compiler, use gcc or clang"; HELP; exit 1;
84+
fi; COMPILER="$2"; shift
85+
;;
86+
-h | --help)
87+
OPT_HELP=true
88+
;;
89+
-d | --debug)
90+
OPT_DEBUG=true
91+
;;
92+
-v | --verbose)
93+
OPT_VERBOSE=1
94+
;;
95+
-n | --no-copy)
96+
OPT_NO_COPY=1
97+
;;
98+
-s | --static)
99+
OPT_STATIC=1
100+
;;
101+
-q | --quiet)
102+
OPT_QUIET=1
103+
;;
104+
--)
105+
shift; break
106+
;;
107+
*)
108+
break
109+
;;
110+
esac; shift;
99111
done
100112

101-
function info() {
102-
echo -e "\nBuild start with cofiguration:\n"
103-
echo -e "BUILD TARGET ARCH: $OPT_TARGET_ARCH"
104-
echo -e "EXE TYPE : $(if [ "$OPT_STATIC" = 1 ]; then echo STATIC; else echo SHARED;fi)"
105-
echo -e "VERBOSE : $(if [ "$OPT_VERBOSE" = 1 ]; then echo YES; else echo NO;fi)"
106-
echo -e "BUILD TYPE : $(if [ "$OPT_DEBUG" = 1 ]; then echo DEBUG; else echo RELEASE;fi)"
107-
echo -e "COMPILER : $COMPILER"
108-
echo -e "\n$0 --help\nto show more options"
109-
sleep 2
110-
echo -e "\nPlease wait... \c"
111-
}
113+
info ()
114+
{
115+
echo -e "\nBuild start with cofiguration:\n";
116+
echo -e "BUILD TARGET ARCH: $OPT_TARGET_ARCH";
117+
echo -e "EXE TYPE : $(if [ "$OPT_STATIC" = 1 ]; then echo STATIC; else echo SHARED;fi)";
118+
echo -e "VERBOSE : $(if [ "$OPT_VERBOSE" = 1 ]; then echo YES; else echo NO;fi)";
119+
echo -e "BUILD TYPE : $(if [ "$OPT_DEBUG" = 1 ]; then echo DEBUG; else echo RELEASE;fi)";
120+
echo -e "COMPILER : $COMPILER";
121+
echo -e "\n$0 --help\nto show more options";
122+
sleep 2;
123+
echo -e "\nPlease wait... \c"
124+
}
112125

113-
case "$OPT_TARGET_ARCH" in
114-
arm|arm64|x86|x86_64|all);;
126+
case "$OPT_TARGET_ARCH" in
127+
arm | arm64 | x86 | x86_64 | all)
128+
129+
;;
115130
*)
116-
echo "unknown arch $OPT_TARGET_ARCH";
117-
exit 1 ;;
118-
esac
131+
echo "unknown arch $OPT_TARGET_ARCH"; exit 1
132+
;;
133+
esac
119134

120135
if [ "$OPT_HELP" = "true" ]; then
121-
HELP;
122-
exit 1
136+
HELP; exit 1;
123137
fi
124138

125139
if [ "$OPT_QUIET" = 0 ]; then
126-
info
127-
build
140+
info; build;
128141
else
129-
info
130-
build &>/dev/null
142+
info; build &> /dev/null;
131143
fi
132144
if [ "$?" = 0 ]; then
133-
echo "done"
145+
echo "done";
134146
else
135-
echo "someting went wrong!"
147+
echo "someting went wrong!";
136148
fi
149+

0 commit comments

Comments
 (0)