compile.sh 7.77 KB
Newer Older
Rémi Duraffort's avatar
Rémi Duraffort committed
1 2
#! /bin/sh

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
3 4
# Read the Android Wiki http://wiki.videolan.org/AndroidCompile
# Setup all that stuff correctly.
5
# Get the latest Android SDK Platform or modify numbers in configure.sh and libvlc/default.properties.
Rafaël Carré's avatar
Rafaël Carré committed
6

7 8
set -e

9
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
10 11
   echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting."
   echo "They must point to your NDK and SDK directories.\n"
Rafaël Carré's avatar
Rafaël Carré committed
12 13
   exit 1
fi
14 15

if [ -z "$ANDROID_ABI" ]; then
Thomas Guillem's avatar
Thomas Guillem committed
16
   echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, arm64-v8a, x86, x86_64 or mips."
17 18 19
   exit 1
fi

20 21 22 23 24 25 26
if [ -z "$NO_FPU" ];then
    NO_FPU=0
fi
if [ -z "$NO_ARMV6" ];then
    NO_ARMV6=0
fi

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
BUILD=0
FETCH=0
RELEASE=0
JNI=0

for i in ${@}; do
    case "$i" in
        --fetch)
        FETCH=1
        ;;
        --build)
        BUILD=1
        ;;
        release|--release)
        RELEASE=1
        ;;
        jni|--jni)
        JNI=1
        ;;
        *)
        ;;
    esac
done

if [ "$BUILD" = 0 -a "$FETCH" = 0 ];then
    BUILD=1
    FETCH=1
fi

56 57 58 59 60
HAVE_ARM=0
HAVE_X86=0
HAVE_MIPS=0
HAVE_64=0

Edward Wang's avatar
Edward Wang committed
61 62
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
63
    TARGET_TUPLE="i686-linux-android"
Edward Wang's avatar
Edward Wang committed
64 65 66
    PATH_HOST="x86"
    HAVE_X86=1
    PLATFORM_SHORT_ARCH="x86"
Thomas Guillem's avatar
Thomas Guillem committed
67 68 69 70 71 72
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
    TARGET_TUPLE="x86_64-linux-android"
    PATH_HOST="x86_64"
    HAVE_X86=1
    HAVE_64=1
    PLATFORM_SHORT_ARCH="x86_64"
Edward Wang's avatar
Edward Wang committed
73 74 75 76 77
elif [ ${ANDROID_ABI} = "mips" ] ; then
    TARGET_TUPLE="mipsel-linux-android"
    PATH_HOST=$TARGET_TUPLE
    HAVE_MIPS=1
    PLATFORM_SHORT_ARCH="mips"
Thomas Guillem's avatar
Thomas Guillem committed
78 79 80 81 82 83
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
    TARGET_TUPLE="aarch64-linux-android"
    PATH_HOST=$TARGET_TUPLE
    HAVE_ARM=1
    HAVE_64=1
    PLATFORM_SHORT_ARCH="arm64"
Edward Wang's avatar
Edward Wang committed
84 85 86 87 88 89
else
    TARGET_TUPLE="arm-linux-androideabi"
    PATH_HOST=$TARGET_TUPLE
    HAVE_ARM=1
    PLATFORM_SHORT_ARCH="arm"
fi
90

91 92 93 94 95 96
# try to detect NDK version
REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
case "$REL" in
    10*)
        if [ "${HAVE_64}" = 1 ];then
            GCCVER=4.9
97
            ANDROID_API=android-21
98 99 100 101 102 103
        else
            GCCVER=4.8
            ANDROID_API=android-9
        fi
        CXXSTL="/"${GCCVER}
    ;;
104
    *)
105
        echo "You need the NDKv10 or later"
106 107 108 109 110 111 112 113
        exit 1
    ;;
esac

export GCCVER
export CXXSTL
export ANDROID_API

114 115 116 117 118 119 120 121 122 123
# XXX : important!
[ "$HAVE_ARM" = 1 ] && cat << EOF
For an ARMv6 device without FPU:
$ export NO_FPU=1
For an ARMv5 device:
$ export NO_ARMV6=1

If you plan to use a release build, run 'compile.sh release'
EOF

Edward Wang's avatar
Edward Wang committed
124 125 126 127 128
export TARGET_TUPLE
export PATH_HOST
export HAVE_ARM
export HAVE_X86
export HAVE_MIPS
129
export HAVE_64
Edward Wang's avatar
Edward Wang committed
130 131
export PLATFORM_SHORT_ARCH

132 133
# Add the NDK toolchain to the PATH, needed both for contribs and for building
# stub libraries
134
NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
135
export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
136

137 138
ANDROID_PATH="`pwd`"

139
# Fetch VLC source
140
if [ "$FETCH" = 1 ]
141 142
then
    # 1/ libvlc, libvlccore and its plugins
Thomas Guillem's avatar
Thomas Guillem committed
143
    TESTED_HASH=18e445a
144 145
    if [ ! -d "vlc" ]; then
        echo "VLC source not found, cloning"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
146
        git clone git://git.videolan.org/vlc.git vlc
147 148 149 150 151 152 153
        cd vlc
        git checkout -B android ${TESTED_HASH}
    else
        echo "VLC source found"
        cd vlc
        if ! git cat-file -e ${TESTED_HASH}; then
            cat << EOF
154 155 156 157 158
***
*** Error: Your vlc checkout does not contain the latest tested commit ***
***

Please update your source with something like:
Rémi Duraffort's avatar
Rémi Duraffort committed
159 160

cd vlc
161 162 163 164 165 166 167
git reset --hard origin
git pull origin master
git checkout -B android ${TESTED_HASH}

*** : This will delete any changes you made to the current branch ***

EOF
168 169
            exit 1
        fi
170
    fi
171 172 173 174
else
    cd vlc
fi

175
if [ "$BUILD" = 0 ]
176 177 178
then
    echo "Not building anything, please run $0 --build"
    exit 0
179
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
180

181
# Setup CFLAGS
182
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
183
    EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
184 185
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
elif [ ${ANDROID_ABI} = "armeabi" ] ; then
Edward Wang's avatar
Edward Wang committed
186 187
    if [ -n "${NO_ARMV6}" ]; then
        EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
188
    else
Edward Wang's avatar
Edward Wang committed
189 190 191 192 193
        if [ -n "${NO_FPU}" ]; then
            EXTRA_CFLAGS="-march=armv6j -mtune=arm1136j-s -msoft-float"
        else
            EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp"
        fi
194
    fi
Thomas Guillem's avatar
Thomas Guillem committed
195 196
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
    EXTRA_CFLAGS=""
Edward Wang's avatar
Edward Wang committed
197
elif [ ${ANDROID_ABI} = "x86" ] ; then
198
    EXTRA_CFLAGS="-march=pentium -m32"
Thomas Guillem's avatar
Thomas Guillem committed
199 200
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
    EXTRA_CFLAGS=""
Edward Wang's avatar
Edward Wang committed
201
elif [ ${ANDROID_ABI} = "mips" ] ; then
Edward Wang's avatar
Edward Wang committed
202
    EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
Edward Wang's avatar
Edward Wang committed
203 204 205
    # All MIPS Linux kernels since 2.4.4 will trap any unimplemented FPU
    # instruction and emulate it, so we select -mhard-float.
    # See http://www.linux-mips.org/wiki/Floating_point#The_Linux_kernel_and_floating_point
206 207 208
else
    echo "Unknown ABI. Die, die, die!"
    exit 2
209 210
fi

Rafaël Carré's avatar
Rafaël Carré committed
211 212
EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"

Rafaël Carré's avatar
Rafaël Carré committed
213 214 215
EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include"
EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include"

216
# Setup LDFLAGS
217
EXTRA_LDFLAGS="-L${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI} -lgnustl_static"
218

219
# Make in //
220 221 222 223 224 225 226 227
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
228 229
fi

230 231 232
############
# Make VLC #
############
233 234 235 236 237 238 239
echo "Configuring"
${ANDROID_PATH}/compile-libvlc.sh $*

####################################
# VLC android UI and specific code
####################################
echo "Building VLC for Android"
240
cd ../
Rémi Duraffort's avatar
Rémi Duraffort committed
241

242
if [ "$JNI" = 1 ]; then
243
    CLEAN="jniclean"
244
    TARGET="libvlc/obj/local/${ANDROID_ABI}/libvlcjni.so"
245 246
else
    CLEAN="distclean"
Rafaël Carré's avatar
Rafaël Carré committed
247
    TARGET=
248
fi
Rafaël Carré's avatar
Rafaël Carré committed
249

250
export ANDROID_SYS_HEADERS=${PWD}/android-headers
Rafaël Carré's avatar
Rafaël Carré committed
251 252

export ANDROID_LIBS=${PWD}/android-libs
253
export VLC_BUILD_DIR=vlc/build-android-${TARGET_TUPLE}
Rafaël Carré's avatar
Rafaël Carré committed
254

255
make $CLEAN
Rafaël Carré's avatar
Rafaël Carré committed
256
make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
257

258 259 260
#
# Exporting a environment script with all the necessary variables
#
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
echo "Generating environment script."
cat <<EOF
This is a script that will export many of the variables used in this
script. It will allow you to compile parts of the build without having
to rebuild the entire build (e.g. recompile only the Java part).

To use it, include the script into your shell, like this:
    source env.sh

Now, you can use this command to build the Java portion:
    make -e

The file will be automatically regenerated by compile.sh, so if you change
your NDK/SDK locations or any build configurations, just re-run this
script (sh compile.sh) and it will automatically update the file.

EOF

echo "# This file was automatically generated by compile.sh" > env.sh
echo "# Re-run 'sh compile.sh' to update this file." >> env.sh

# The essentials
cat <<EssentialsA >> env.sh
284
export ANDROID_API=$ANDROID_API
285 286 287 288 289
export ANDROID_ABI=$ANDROID_ABI
export ANDROID_SDK=$ANDROID_SDK
export ANDROID_NDK=$ANDROID_NDK
export GCCVER=$GCCVER
export CXXSTL=$CXXSTL
290
export ANDROID_SYS_HEADERS=$ANDROID_SYS_HEADERS
291
export ANDROID_LIBS=$ANDROID_LIBS
Edward Wang's avatar
Edward Wang committed
292
export VLC_BUILD_DIR=$VLC_BUILD_DIR
293
export TARGET_TUPLE=$TARGET_TUPLE
294
export PATH_HOST=$PATH_HOST
295
export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
Thomas Guillem's avatar
Thomas Guillem committed
296
export RELEASE=$RELEASE
297 298 299 300 301 302
EssentialsA

# PATH
echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh

# CPU flags
303 304 305
echo "export HAVE_ARM=${HAVE_ARM}" >> env.sh
echo "export HAVE_X86=${HAVE_X86}" >> env.sh
echo "export HAVE_MIPS=${HAVE_MIPS}" >> env.sh
306

307 308 309
echo "export NO_ARMV6=${NO_ARMV6}" >> env.sh
echo "export NO_FPU=${NO_FPU}" >> env.sh
echo "export HAVE_64=${HAVE_64}" >> env.sh