forked from videolan/vlc-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-common
executable file
·186 lines (159 loc) · 5.15 KB
/
build-common
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
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
# Make in //
if [ -z "$MAKEFLAGS" ]; then
UNAMES=$(uname -s)
MAKEFLAGS=
if which nproc >/dev/null; then
MAKEFLAGS=-j`nproc`
elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null; then
MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
fi
fi
echo "MAKEFLAGS: ${MAKEFLAGS}"
#########
# FLAGS #
#########
if [ "${ANDROID_ABI}" = "arm" ] ; then
ANDROID_ABI="armeabi-v7a"
elif [ "${ANDROID_ABI}" = "arm64" ] ; then
ANDROID_ABI="arm64-v8a"
fi
# Set up ABI variables
if [ "${ANDROID_ABI}" = "x86" ] ; then
TARGET_TUPLE="i686-linux-android"
PLATFORM_SHORT_ARCH="x86"
elif [ "${ANDROID_ABI}" = "x86_64" ] ; then
TARGET_TUPLE="x86_64-linux-android"
PLATFORM_SHORT_ARCH="x86_64"
HAVE_64=1
elif [ "${ANDROID_ABI}" = "arm64-v8a" ] ; then
TARGET_TUPLE="aarch64-linux-android"
HAVE_ARM=1
HAVE_64=1
PLATFORM_SHORT_ARCH="arm64"
elif [ "${ANDROID_ABI}" = "armeabi-v7a" ] ; then
TARGET_TUPLE="arm-linux-androideabi"
HAVE_ARM=1
PLATFORM_SHORT_ARCH="arm"
else
echo "Unknown ABI: '${ANDROID_ABI}'. Die, die, die!"
exit 2
fi
# try to detect NDK version
REL=$(grep -o '^Pkg.Revision.*[0-9]*.*' $ANDROID_NDK/source.properties |cut -d " " -f 3 | cut -d "." -f 1)
if [ "$REL" -eq 18 ]; then
if [ "${HAVE_64}" = 1 ]; then
ANDROID_API=21
else
ANDROID_API=17
fi
else
echo "NDK v18 needed, cf. https://developer.android.com/ndk/downloads/"
exit 1
fi
NDK_FORCE_ARG=
NDK_TOOLCHAIN_DIR=${PWD}/toolchains/${PLATFORM_SHORT_ARCH}
NDK_TOOLCHAIN_PROPS=${NDK_TOOLCHAIN_DIR}/source.properties
NDK_TOOLCHAIN_PATH=${NDK_TOOLCHAIN_DIR}/bin
if [ "`cat \"${NDK_TOOLCHAIN_PROPS}\" 2>/dev/null`" != "`cat \"${ANDROID_NDK}/source.properties\"`" ];then
echo "NDK changed, making new toolchain"
NDK_FORCE_ARG="--force"
fi
$ANDROID_NDK/build/tools/make_standalone_toolchain.py \
--arch ${PLATFORM_SHORT_ARCH} \
--api ${ANDROID_API} \
--stl libc++ \
${NDK_FORCE_ARG} \
--install-dir ${NDK_TOOLCHAIN_DIR} 2> /dev/null
if [ ! -d ${NDK_TOOLCHAIN_PATH} ];
then
echo "make_standalone_toolchain.py failed"
exit 1
fi
if [ ! -z "${NDK_FORCE_ARG}" ];then
# Don't mess up nl_langinfo() detection since this symbol is not present for 64
# bits
if [ "${HAVE_64}" = 1 ];then
rm ${NDK_TOOLCHAIN_DIR}/sysroot/usr/local/include/langinfo.h
fi
fi
if [ ! -z "${NDK_FORCE_ARG}" ];then
cp "$ANDROID_NDK/source.properties" "${NDK_TOOLCHAIN_PROPS}"
fi
# Add the NDK toolchain to the PATH, needed both for contribs and for building
# stub libraries
CROSS_TOOLS=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-
export PATH="${NDK_TOOLCHAIN_PATH}:${PATH}"
ON_WINDOWS=0
if [ ! -z "$MSYSTEM_PREFIX" ] ; then
# The make.exe and awk.exe from the toolchain don't work in msys
export PATH="$MSYSTEM_PREFIX/bin:/usr/bin:${NDK_TOOLCHAIN_PATH}:${PATH}"
ON_WINDOWS=1
fi
##########
# CFLAGS #
##########
VLC_CFLAGS="-std=gnu11"
VLC_CXXFLAGS="-std=gnu++11"
if [ "$NO_OPTIM" = "1" ];
then
VLC_CFLAGS="${VLC_CFLAGS} -g -O0"
VLC_CXXFLAGS="${VLC_CXXFLAGS} -g -O0"
else
VLC_CFLAGS="${VLC_CFLAGS} -g -O2"
VLC_CXXFLAGS="${VLC_CXXFLAGS} -g -O2"
fi
VLC_CFLAGS="${VLC_CFLAGS} -fstrict-aliasing -funsafe-math-optimizations"
VLC_CXXFLAGS="${VLC_CXXFLAGS} -fstrict-aliasing -funsafe-math-optimizations"
# Setup CFLAGS per ABI
if [ "${ANDROID_ABI}" = "armeabi-v7a" ] ; then
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mcpu=cortex-a8"
EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
elif [ "${ANDROID_ABI}" = "x86" ] ; then
EXTRA_CFLAGS="-mtune=atom -msse3 -mfpmath=sse -m32"
fi
EXTRA_CFLAGS="${EXTRA_CFLAGS} -MMD -MP -fpic -ffunction-sections -funwind-tables \
-fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument \
-no-canonical-prefixes -fno-integrated-as"
EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -fexceptions -frtti"
EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -D__STDC_FORMAT_MACROS=1 -D__STDC_CONSTANT_MACROS=1 -D__STDC_LIMIT_MACROS=1"
#################
# Setup LDFLAGS #
#################
EXTRA_LDFLAGS="${VLC_LDFLAGS}"
if [ ${ANDROID_ABI} = "armeabi-v7a" ]; then
EXTRA_PARAMS=" --enable-neon"
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -Wl,--fix-cortex-a8"
fi
NDK_LIB_DIR="${NDK_TOOLCHAIN_DIR}/${TARGET_TUPLE}/lib"
if [ "${PLATFORM_SHORT_ARCH}" = "x86_64" ];then
NDK_LIB_DIR="${NDK_LIB_DIR}64"
elif [ "${PLATFORM_SHORT_ARCH}" = "arm" ]; then
NDK_LIB_DIR="${NDK_LIB_DIR}/armv7-a"
fi
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -L${NDK_LIB_DIR} -lc++abi"
VLC_LDFLAGS="${EXTRA_LDFLAGS}"
# Release or not?
if [ "$RELEASE" = 1 ]; then
OPTS=""
EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
NDK_DEBUG=0
else
OPTS="--enable-debug"
NDK_DEBUG=1
fi
if [ "${ASAN}" = 1 ];then
VLC_CFLAGS="${VLC_CFLAGS} -O0 -fno-omit-frame-pointer -fsanitize=address"
VLC_CXXFLAGS="${VLC_CXXFLAGS} -O0 -fno-omit-frame-pointer -fsanitize=address"
VLC_LDFLAGS="${VLC_LDFLAGS} -ldl -fsanitize=address"
fi
###############
# DISPLAY ABI #
###############
echo "ABI: $ANDROID_ABI"
echo "API: $ANDROID_API"
echo "PATH: $PATH"
echo "EXTRA_CFLAGS: ${EXTRA_CFLAGS}"
echo "VLC_CFLAGS: ${VLC_CFLAGS}"
echo "VLC_CXXFLAGS: ${VLC_CXXFLAGS}"
echo ok