compile.sh 9.6 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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
BUILD=
FETCH=
case "$1" in
    --fetch)
    FETCH=1
    shift
    ;;
    --build)
    BUILD=1
    shift
    ;;
    *)
    FETCH=1
    BUILD=1
    ;;
esac

26
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
27 28
   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
29 30
   exit 1
fi
31 32 33 34 35 36

if [ -z "$ANDROID_ABI" ]; then
   echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, x86 or mips."
   exit 1
fi

Rafaël Carré's avatar
Rafaël Carré committed
37 38 39
# try to detect NDK version
REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
case "$REL" in
Felix Abecassis's avatar
Felix Abecassis committed
40
    9*|10*)
Rafaël Carré's avatar
Rafaël Carré committed
41 42 43
        GCCVER=4.8
        CXXSTL="/"${GCCVER}
    ;;
44
    7|8|*)
45
        echo "You need the NDKv9 or later"
Rafaël Carré's avatar
Rafaël Carré committed
46 47 48 49 50 51
        exit 1
    ;;
esac

export GCCVER
export CXXSTL
Rémi Duraffort's avatar
Rémi Duraffort committed
52

Edward Wang's avatar
Edward Wang committed
53 54
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
55
    TARGET_TUPLE="i686-linux-android"
Edward Wang's avatar
Edward Wang committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69
    PATH_HOST="x86"
    HAVE_X86=1
    PLATFORM_SHORT_ARCH="x86"
elif [ ${ANDROID_ABI} = "mips" ] ; then
    TARGET_TUPLE="mipsel-linux-android"
    PATH_HOST=$TARGET_TUPLE
    HAVE_MIPS=1
    PLATFORM_SHORT_ARCH="mips"
else
    TARGET_TUPLE="arm-linux-androideabi"
    PATH_HOST=$TARGET_TUPLE
    HAVE_ARM=1
    PLATFORM_SHORT_ARCH="arm"
fi
70

71 72 73 74 75 76 77 78 79 80
# 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
81 82 83 84 85 86 87
export TARGET_TUPLE
export PATH_HOST
export HAVE_ARM
export HAVE_X86
export HAVE_MIPS
export PLATFORM_SHORT_ARCH

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

93 94
ANDROID_PATH="`pwd`"

95
# Fetch VLC source
96 97 98
if [ ! -z "$FETCH" ]
then
    # 1/ libvlc, libvlccore and its plugins
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
99
    TESTED_HASH=5636603
100 101
    if [ ! -d "vlc" ]; then
        echo "VLC source not found, cloning"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
102
        git clone git://git.videolan.org/vlc.git vlc
103 104 105 106 107 108 109
        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
110 111 112 113 114
***
*** 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
115 116

cd vlc
117 118 119 120 121 122 123
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
124 125
            exit 1
        fi
126
    fi
127 128 129 130 131 132 133 134
else
    cd vlc
fi

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

137
# Setup CFLAGS
138
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
139
    EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
140 141
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
elif [ ${ANDROID_ABI} = "armeabi" ] ; then
Edward Wang's avatar
Edward Wang committed
142 143
    if [ -n "${NO_ARMV6}" ]; then
        EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
144
    else
Edward Wang's avatar
Edward Wang committed
145 146 147 148 149
        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
150
    fi
Edward Wang's avatar
Edward Wang committed
151
elif [ ${ANDROID_ABI} = "x86" ] ; then
152
    EXTRA_CFLAGS="-march=pentium -m32"
Edward Wang's avatar
Edward Wang committed
153
elif [ ${ANDROID_ABI} = "mips" ] ; then
Edward Wang's avatar
Edward Wang committed
154
    EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
Edward Wang's avatar
Edward Wang committed
155 156 157
    # 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
158 159 160
else
    echo "Unknown ABI. Die, die, die!"
    exit 2
161 162
fi

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

Rafaël Carré's avatar
Rafaël Carré committed
165 166 167
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"

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

171
# Make in //
172
UNAMES=$(uname -s)
173 174 175 176
MAKEFLAGS=
if which nproc >/dev/null
then
MAKEFLAGS=-j`nproc`
177
elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
178 179 180 181
then
MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
fi

182
# Build buildsystem tools
183 184 185 186 187 188 189
export PATH=`pwd`/extras/tools/build/bin:$PATH
echo "Building tools"
cd extras/tools
./bootstrap
make $MAKEFLAGS
cd ../..

190 191 192
############
# Contribs #
############
193
echo "Building the contribs"
194
mkdir -p contrib/contrib-android-${TARGET_TUPLE}
195 196 197 198 199 200 201 202 203 204 205 206 207 208

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

209
cd contrib/contrib-android-${TARGET_TUPLE}
210
../bootstrap --host=${TARGET_TUPLE} --disable-disc --disable-sout \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
211
    --enable-dvdread \
212
    --enable-dvdnav \
213
    --disable-dca \
Rafaël Carré's avatar
Rafaël Carré committed
214
    --disable-goom \
Rafaël Carré's avatar
Rafaël Carré committed
215
    --disable-chromaprint \
Rafaël Carré's avatar
Rafaël Carré committed
216 217
    --disable-lua \
    --disable-schroedinger \
218 219 220 221 222 223 224 225 226 227 228
    --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
229
    --enable-vorbis \
230 231 232
    --disable-sidplay2 \
    --disable-samplerate \
    --disable-faad2 \
233
    --disable-harfbuzz \
Felix Abecassis's avatar
Felix Abecassis committed
234 235
    --enable-iconv \
    --disable-aribb24
236 237 238

# TODO: mpeg2, theora

Rafaël Carré's avatar
Rafaël Carré committed
239 240
# 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
241
[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
Rafaël Carré's avatar
Rafaël Carré committed
242

243
# Release or not?
Rafaël Carré's avatar
Rafaël Carré committed
244
if [ $# -ne 0 ] && [ "$1" = "release" ]; then
245
    OPTS=""
246
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
Rafaël Carré's avatar
Rafaël Carré committed
247
    RELEASE=1
248 249
else
    OPTS="--enable-debug"
Rafaël Carré's avatar
Rafaël Carré committed
250
    RELEASE=0
251 252
fi

253
echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
254
echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
255
export VLC_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
256
export VLC_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}"
257

Rafaël Carré's avatar
Rafaël Carré committed
258
make fetch
259
# We already have zlib available
260
[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
261
which autopoint >/dev/null || make $MAKEFLAGS .gettext
262
export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
263
make $MAKEFLAGS
Rémi Duraffort's avatar
Rémi Duraffort committed
264

265 266 267 268
############
# Make VLC #
############
cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
Rémi Duraffort's avatar
Rémi Duraffort committed
269

270 271
if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
    CLEAN="jniclean"
Rafaël Carré's avatar
Rafaël Carré committed
272
    TARGET="vlc-android/obj/local/armeabi-v7a/libvlcjni.so"
273 274
else
    CLEAN="distclean"
275
    if [ ! -f config.h ]; then
276 277 278 279 280
        echo "Bootstraping"
        ../bootstrap
        echo "Configuring"
        ${ANDROID_PATH}/configure.sh $OPTS
    fi
Rafaël Carré's avatar
Rafaël Carré committed
281
    TARGET=
282
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
283

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
284
echo "Building"
285
make $MAKEFLAGS
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
286

287 288 289 290
####################################
# VLC android UI and specific code
####################################
echo "Building VLC for Android"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
291
cd ../../
Rafaël Carré's avatar
Rafaël Carré committed
292

293
export ANDROID_SYS_HEADERS_GINGERBREAD=${PWD}/android-headers-gingerbread
294
export ANDROID_SYS_HEADERS_HC=${PWD}/android-headers-hc
295
export ANDROID_SYS_HEADERS_ICS=${PWD}/android-headers-ics
296 297 298
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
299 300

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

303
make $CLEAN
Rafaël Carré's avatar
Rafaël Carré committed
304
make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
305

306 307 308
#
# Exporting a environment script with all the necessary variables
#
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
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
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
340 341 342
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
343
export ANDROID_LIBS=$ANDROID_LIBS
Edward Wang's avatar
Edward Wang committed
344
export VLC_BUILD_DIR=$VLC_BUILD_DIR
345
export TARGET_TUPLE=$TARGET_TUPLE
346
export PATH_HOST=$PATH_HOST
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
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