compile.sh 11.7 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 5
# Read the Android Wiki http://wiki.videolan.org/AndroidCompile
# Setup all that stuff correctly.
# Get the latest Android SDK Platform or modify numbers in configure.sh and vlc-android/default.properties.
Rafaël Carré's avatar
Rafaël Carré committed
6

7 8
set -e

9

10
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
11 12
   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
13 14
   exit 1
fi
15 16

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

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
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

Edward Wang's avatar
Edward Wang committed
50 51
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
52
    TARGET_TUPLE="i686-linux-android"
Edward Wang's avatar
Edward Wang committed
53 54 55
    PATH_HOST="x86"
    HAVE_X86=1
    PLATFORM_SHORT_ARCH="x86"
Thomas Guillem's avatar
Thomas Guillem committed
56 57 58 59 60 61
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
62 63 64 65 66
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
67 68 69 70 71 72
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
73 74 75 76 77 78
else
    TARGET_TUPLE="arm-linux-androideabi"
    PATH_HOST=$TARGET_TUPLE
    HAVE_ARM=1
    PLATFORM_SHORT_ARCH="arm"
fi
79

80 81 82 83 84 85
# 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
86
            ANDROID_API=android-21
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
        else
            GCCVER=4.8
            ANDROID_API=android-9
        fi
        CXXSTL="/"${GCCVER}
    ;;
    9*)
        if [ "${HAVE_64}" = 1 ];then
            echo "You need the NDKv10 or later for 64 bits build"
            exit 1
        fi
        GCCVER=4.8
        ANDROID_API=android-9
        CXXSTL="/"${GCCVER}
    ;;
    7|8|*)
        echo "You need the NDKv9 or later"
        exit 1
    ;;
esac

export GCCVER
export CXXSTL
export ANDROID_API

112 113 114 115 116 117 118 119 120 121
# 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
122 123 124 125 126
export TARGET_TUPLE
export PATH_HOST
export HAVE_ARM
export HAVE_X86
export HAVE_MIPS
127
export HAVE_64
Edward Wang's avatar
Edward Wang committed
128 129
export PLATFORM_SHORT_ARCH

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

135 136
ANDROID_PATH="`pwd`"

137
# Fetch VLC source
138 139 140
if [ ! -z "$FETCH" ]
then
    # 1/ libvlc, libvlccore and its plugins
Thomas Guillem's avatar
Thomas Guillem committed
141
    TESTED_HASH=6e2f490
142 143
    if [ ! -d "vlc" ]; then
        echo "VLC source not found, cloning"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
144
        git clone git://git.videolan.org/vlc.git vlc
145 146 147 148 149 150 151
        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
152 153 154 155 156
***
*** 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
157 158

cd vlc
159 160 161 162 163 164 165
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
166 167
            exit 1
        fi
168
    fi
169 170 171 172 173 174 175 176
else
    cd vlc
fi

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

179
# Setup CFLAGS
180
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
181
    EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
182 183
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
elif [ ${ANDROID_ABI} = "armeabi" ] ; then
Edward Wang's avatar
Edward Wang committed
184 185
    if [ -n "${NO_ARMV6}" ]; then
        EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
186
    else
Edward Wang's avatar
Edward Wang committed
187 188 189 190 191
        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
192
    fi
Thomas Guillem's avatar
Thomas Guillem committed
193 194
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
    EXTRA_CFLAGS=""
Edward Wang's avatar
Edward Wang committed
195
elif [ ${ANDROID_ABI} = "x86" ] ; then
196
    EXTRA_CFLAGS="-march=pentium -m32"
Thomas Guillem's avatar
Thomas Guillem committed
197 198
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
    EXTRA_CFLAGS=""
Edward Wang's avatar
Edward Wang committed
199
elif [ ${ANDROID_ABI} = "mips" ] ; then
Edward Wang's avatar
Edward Wang committed
200
    EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
Edward Wang's avatar
Edward Wang committed
201 202 203
    # 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
204 205 206
else
    echo "Unknown ABI. Die, die, die!"
    exit 2
207 208
fi

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

Rafaël Carré's avatar
Rafaël Carré committed
211 212 213
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"

214 215 216
# Setup LDFLAGS
EXTRA_LDFLAGS="-l${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/libgnustl_static.a"

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

228
# Build buildsystem tools
229 230 231 232 233 234 235
export PATH=`pwd`/extras/tools/build/bin:$PATH
echo "Building tools"
cd extras/tools
./bootstrap
make $MAKEFLAGS
cd ../..

236 237 238
############
# Contribs #
############
239
echo "Building the contribs"
240
mkdir -p contrib/contrib-android-${TARGET_TUPLE}
241 242 243 244 245 246 247 248 249 250 251 252 253 254

gen_pc_file() {
    echo "Generating $1 pkg-config file"
    echo "Name: $1
Description: $1
Version: $2
Libs: -l$1
Cflags:" > contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
}

mkdir -p contrib/${TARGET_TUPLE}/lib/pkgconfig
gen_pc_file EGL 1.1
gen_pc_file GLESv2 2

255
cd contrib/contrib-android-${TARGET_TUPLE}
256
../bootstrap --host=${TARGET_TUPLE} --disable-disc --disable-sout \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
257
    --enable-dvdread \
258
    --enable-dvdnav \
259
    --disable-dca \
Rafaël Carré's avatar
Rafaël Carré committed
260
    --disable-goom \
Rafaël Carré's avatar
Rafaël Carré committed
261
    --disable-chromaprint \
Rafaël Carré's avatar
Rafaël Carré committed
262 263
    --disable-lua \
    --disable-schroedinger \
264 265 266 267 268 269 270 271 272 273 274
    --disable-sdl \
    --disable-SDL_image \
    --disable-fontconfig \
    --disable-zvbi \
    --disable-kate \
    --disable-caca \
    --disable-gettext \
    --disable-mpcdec \
    --disable-upnp \
    --disable-gme \
    --disable-tremor \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
275
    --enable-vorbis \
276 277 278
    --disable-sidplay2 \
    --disable-samplerate \
    --disable-faad2 \
279
    --disable-harfbuzz \
Felix Abecassis's avatar
Felix Abecassis committed
280 281
    --enable-iconv \
    --disable-aribb24
282 283 284

# TODO: mpeg2, theora

Rafaël Carré's avatar
Rafaël Carré committed
285 286
# Some libraries have arm assembly which won't build in thumb mode
# We append -marm to the CFLAGS of these libs to disable thumb mode
Rafaël Carré's avatar
Rafaël Carré committed
287
[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
Rafaël Carré's avatar
Rafaël Carré committed
288

289
# Release or not?
290
if [ "$RELEASE" = 1 ]; then
291
    OPTS=""
292
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
293 294 295 296
else
    OPTS="--enable-debug"
fi

297
echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
298
echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
299
export VLC_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
300
export VLC_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}"
301

Rafaël Carré's avatar
Rafaël Carré committed
302
make fetch
303
# We already have zlib available
304
[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
305
which autopoint >/dev/null || make $MAKEFLAGS .gettext
306
export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
307
make $MAKEFLAGS
Rémi Duraffort's avatar
Rémi Duraffort committed
308

309 310 311 312
############
# Make VLC #
############
cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
Rémi Duraffort's avatar
Rémi Duraffort committed
313

314
if [ "$JNI" = 1 ]; then
315
    CLEAN="jniclean"
316
    TARGET="vlc-android/obj/local/${ANDROID_ABI}/libvlcjni.so"
317 318
else
    CLEAN="distclean"
319
    if [ ! -f config.h ]; then
320 321 322 323 324
        echo "Bootstraping"
        ../bootstrap
        echo "Configuring"
        ${ANDROID_PATH}/configure.sh $OPTS
    fi
Rafaël Carré's avatar
Rafaël Carré committed
325
    TARGET=
326
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
327

328 329 330
# ANDROID NDK FIXUP (BLAME GOOGLE)
config_undef ()
{
Thomas Guillem's avatar
Thomas Guillem committed
331
    previous_change=`stat -c "%y" config.h`
332
    sed -i 's,#define '$1' 1,/\* #undef '$1' \*/,' config.h
Thomas Guillem's avatar
Thomas Guillem committed
333 334
    # don't change modified date in order to don't trigger a full build
    touch -d "$previous_change" config.h
335 336
}

Thomas Guillem's avatar
Thomas Guillem committed
337 338 339 340 341 342
# if config dependencies change, ./config.status --recheck
# is run and overwrite previously hacked config.h. So call make Makefile here
# and hack config.h after.

make $MAKEFLAGS Makefile

343 344 345 346 347 348 349 350 351 352
if [ ${ANDROID_ABI} = "x86" -a ${ANDROID_API} != "android-21" ] ; then
    # NDK x86 libm.so has nanf symbol but no nanf definition, we don't known if
    # intel devices has nanf. Assume they don't have it.
    config_undef HAVE_NANF
fi
if [ ${ANDROID_API} = "android-21" ] ; then
    # android-21 has empty sys/shm.h headers that triggers shm detection but it
    # doesn't have any shm functions and/or symbols. */
    config_undef HAVE_SYS_SHM_H
fi
Thomas Guillem's avatar
Thomas Guillem committed
353
# END OF ANDROID NDK FIXUP
354

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
355
echo "Building"
356
make $MAKEFLAGS
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
357

358 359 360 361
####################################
# VLC android UI and specific code
####################################
echo "Building VLC for Android"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
362
cd ../../
Rafaël Carré's avatar
Rafaël Carré committed
363

364
export ANDROID_SYS_HEADERS_GINGERBREAD=${PWD}/android-headers-gingerbread
365
export ANDROID_SYS_HEADERS_HC=${PWD}/android-headers-hc
366
export ANDROID_SYS_HEADERS_ICS=${PWD}/android-headers-ics
367 368 369
export ANDROID_SYS_HEADERS_JB=${PWD}/android-headers-jb
export ANDROID_SYS_HEADERS_JBMR2=${PWD}/android-headers-jbmr2
export ANDROID_SYS_HEADERS_KK=${PWD}/android-headers-kk
Rafaël Carré's avatar
Rafaël Carré committed
370 371

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

374
make $CLEAN
Rafaël Carré's avatar
Rafaël Carré committed
375
make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
376

377 378 379
#
# Exporting a environment script with all the necessary variables
#
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
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
403
export ANDROID_API=$ANDROID_API
404 405 406 407 408 409 410 411
export ANDROID_ABI=$ANDROID_ABI
export ANDROID_SDK=$ANDROID_SDK
export ANDROID_NDK=$ANDROID_NDK
export GCCVER=$GCCVER
export CXXSTL=$CXXSTL
export ANDROID_SYS_HEADERS_GINGERBREAD=$ANDROID_SYS_HEADERS_GINGERBREAD
export ANDROID_SYS_HEADERS_HC=$ANDROID_SYS_HEADERS_HC
export ANDROID_SYS_HEADERS_ICS=$ANDROID_SYS_HEADERS_ICS
412 413 414
export ANDROID_SYS_HEADERS_JB=$ANDROID_SYS_HEADERS_JB
export ANDROID_SYS_HEADERS_JBMR2=$ANDROID_SYS_HEADERS_JBMR2
export ANDROID_SYS_HEADERS_KK=$ANDROID_SYS_HEADERS_KK
415
export ANDROID_LIBS=$ANDROID_LIBS
Edward Wang's avatar
Edward Wang committed
416
export VLC_BUILD_DIR=$VLC_BUILD_DIR
417
export TARGET_TUPLE=$TARGET_TUPLE
418
export PATH_HOST=$PATH_HOST
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
EssentialsA

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

# CPU flags
if [ -n "${HAVE_ARM}" ]; then
    echo "export HAVE_ARM=1" >> env.sh
elif [ -n "${HAVE_X86}" ]; then
    echo "export HAVE_X86=1" >> env.sh
elif [ -n "${HAVE_MIPS}" ]; then
    echo "export HAVE_MIPS=1" >> env.sh
fi

if [ -n "${NO_ARMV6}" ]; then
    echo "export NO_ARMV6=1" >> env.sh
fi
if [ -n "${NO_FPU}" ]; then
    echo "export NO_FPU=1" >> env.sh
fi
Thomas Guillem's avatar
Thomas Guillem committed
440 441 442
if [ -n "${HAVE_64}" ]; then
    echo "export HAVE_64=1" >> env.sh
fi