-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild_strace_for_android.sh
More file actions
executable file
·176 lines (144 loc) · 4.18 KB
/
build_strace_for_android.sh
File metadata and controls
executable file
·176 lines (144 loc) · 4.18 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# build strace for android
# g0, 2018
PROJECT='strace'
COLORS=1
DEFAULT_ARCH='arm'
DEFAULT_SDKV='23'
ROOT=`pwd`
BINARIES='binaries'
STATUS=0
[ "$COLORS" -eq "1" ] && ESC8='\033['
[ "$COLORS" -eq "1" ] && GREEN=${ESC8}"01;32m"
[ "$COLORS" -eq "1" ] && RED=${ESC8}"31;01m"
[ "$COLORS" -eq "1" ] && RESET=${ESC8}"00m"
_say(){
printf "${GREEN}%s${RESET}\n" "${1}"
}
_die(){
printf "${RED}%s${RESET}\n" "${1}"
STATUS=$((STATUS+1))
exit $STATUS
}
_not_in_archs(){
archs=(arm arm64 mips mips64 x86 x86_64)
for arch in ${archs[*]}
do
[ "$arch" = "$1" ] && return 1
done
echo "$1 is not a supported arch."
return 0
}
if [ "$1" = "-h" ]
then
echo -e "\t $0 arch api_version rmbuild verbose stip"
echo -e "\t example: $0 arm64 24 rmbuild"
echo -e "\t add rmbuild to reset config"
echo -e "\t with no arguments, it will attempt to build socat for the android seen over adb"
echo ""
exit 0
fi
sed --help |grep -q GNU > /dev/null 2>&1
[ ! $? -eq "0" ] && _die "GNU sed was not found. Giving up."
ndk-which gcc > /dev/null 2>&1
[ ! $? -eq "0" ] && _die "this NDK, if any, does not do gcc. Giving up."
SDKV=$(adb shell getprop ro.build.version.sdk 2>/dev/null)
[ -z "$SDKV" ] && SDKV=$DEFAULT_SDKV
ARCH=$(adb shell getprop ro.product.cpu.abi 2>/dev/null)
[ -z "$ARCH" ] && ARCH=$DEFAULT_ARCH
[[ "$ARCH" = *"-"* ]] && ARCH=$(echo "$ARCH" |awk -F '-' '{print $1}')
if _not_in_archs $ARCH; then
ARCH=$DEFAULT_ARCH
fi
# ARCH='arm64'
# SDKV='26'
# OP3='rmbuild'
# OP4='verbose'
# OP5='strip'
# OP6='clean'
[ $# -ge 1 ] && ARCH=$1
[ $# -ge 2 ] && SDKV=$2
[ $# -ge 3 ] && OP3=$3
[ $# -ge 4 ] && OP4=$4
[ $# -ge 5 ] && OP5=$5
if [ "$OP3" = 'rmbuild' ]
then
_say "deleting untracked git files"
git ls-files --others --exclude-standard |xargs rm
fi
_say "Building $PROJECT for Architecture:$ARCH, Android SDK API version:$SDKV"
BUILD="${ROOT}/builds/${ARCH}_${SDKV}"
mkdir -p $BUILD
HOST='arm-linux-androideabi'
TCDIR="${BUILD}/toolchain_${ARCH}${SDKV}"
SYSROOT="${BUILD}/toolchain_${ARCH}${SDKV}/sysroot"
[[ "$ARCH" = 'arm' ]] && HOST='arm-linux-androideabi'
[[ "$ARCH" = 'arm64' ]] && HOST='aarch64-linux-android'
[[ "$ARCH" = 'x86' ]] && HOST='i686-linux-android'
[[ "$ARCH" = 'x86_64' ]] && HOST='x86_64-linux-android'
[[ "$ARCH" = 'mips' ]] && HOST='mipsel-linux-android'
[[ "$ARCH" = 'mips64' ]] && HOST='mips64el-linux-android'
CC="$TCDIR/bin/$HOST-clang --sysroot=$SYSROOT"
LD="$TCDIR/bin/$HOST-ld"
AR="$TCDIR/bin/$HOST-ar"
RANLIB="$TCDIR/bin/$HOST-ranlib"
STRIP="$TCDIR/bin/$HOST-strip"
CFLAGS="-fPIE -fPIC"
[[ "$OP4" = 'verbose' ]] && CFLAGS="$CFLAGS -v"
LDFLAGS="-fPIE -pie"
[[ "$OP4" = 'verbose' ]] && LDFLAGS="$LDFLAGS -v"
_say "HOST: $HOST"
_say "CC: $CC"
_say "CFLAGS: $CFLAGS"
_say "LD: $LD"
_say "LDFLAGS: $LDFLAGS"
_say "AR: $AR"
_say "RANLIB: $RANLIB"
export CFLAGS="$CFLAGS"
export CC="$CC"
export RANLIB="$RANLIB"
export AR="$AR"
export LDFLAGS="$LDFLAGS"
export LD="$LD"
export PATH="$TCDIR/bin:$PATH"
rm -rf $TCDIR
V=''
[[ "$OP4" = 'verbose' ]] && V="-v"
make_standalone_toolchain.py $V --arch $ARCH --api $SDKV --install-dir $TCDIR --force
cd ${ROOT}
${ROOT}/configure \
--host=$HOST \
|| _die "configure failed"
# --enable-arm-oabi
# --srcdir=$ROOT
_handle_bin(){
if [ -e "${ROOT}/${1}" ]
then
mkdir -p ${ROOT}/$BINARIES/${ARCH}/${SDKV}
cp ${ROOT}/${1} ${ROOT}/$BINARIES/${ARCH}/${SDKV}/${1}
[[ "$OP5" = 'strip' ]] && $STRIP ${ROOT}/$BINARIES/${ARCH}/${SDKV}/${1}
_say "Build finished, ${1} has been generated successfuly in ${ROOT}/$BINARIES/$ARCH/$SDKV/${1}"
else
STATUS=$((STATUS+1))
printf "${RED}%s${RESET}\n" "${1} was not made"
fi
}
MAKE="$TCDIR/bin/make"
J=$(sysctl -n hw.physicalcpu)
J=$((J-1))
[ "$J" -ge 2 -a "$J" -le 16 ] && MAKE="$MAKE -j${J}"
_say "$MAKE"
$MAKE || _die "make failed"
_say "Build finished, $PROJECT has been generated successfuly in $ROOT/$PROJECT"
_handle_bin "$PROJECT"
if [ "$OP3" = 'rmbuild' -a -d "$BUILD" ]
then
_say "git add ./binaries{,-oabi}/*"
git add ./binaries/*
git add ./binaries-oabi/*
rm -r ${BUILD}
[ ! -d "$BUILD" ] && _say "deleted $BUILD"
_say "deleting untracked git files."
git ls-files --others --exclude-standard |xargs rm
fi
exit $STATUS