compile.sh 7.78 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
if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" -o -z "$ANDROID_ABI" ]; then
   echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting."
   echo "They must point to your NDK and SDK directories.\n"
   echo "ANDROID_ABI should match your ABI: armeabi-v7a, armeabi or ..."
Rafaël Carré's avatar
Rafaël Carré committed
13 14
   exit 1
fi
Rafaël Carré's avatar
Rafaël Carré committed
15 16 17 18
# try to detect NDK version
REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
case "$REL" in
    8?)
Rafaël Carré's avatar
Rafaël Carré committed
19 20 21 22 23 24 25 26 27 28 29
        # we don't use 4.4.3 because it doesn't handle threads correctly.
        # TODO : clang?
        if test -d ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.7
        # if gcc 4.7 is present, it's there for all the archs (x86, mips, arm)
        then
            # since r8d
            GCCVER=4.7
        else
            GCCVER=4.6
        fi
        CXXSTL="/"${GCCVER}
Rafaël Carré's avatar
Rafaël Carré committed
30
    ;;
31 32
    7|8|*)
        echo "You need the NDKv8b or later"
Rafaël Carré's avatar
Rafaël Carré committed
33 34 35 36 37 38
        exit 1
    ;;
esac

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

40 41 42 43
# XXX : important!
cat << EOF
For an ARMv6 device without FPU, you need a build without FPU:
$ export NO_FPU=1
Edward Wang's avatar
Edward Wang committed
44 45
For an ARMv5 device or the Android emulator, you need an ARMv5 build:
$ export NO_ARMV6=1
46 47 48

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

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 56 57 58 59 60 61 62 63 64 65 66
    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
67

Edward Wang's avatar
Edward Wang committed
68 69 70 71 72 73 74
export TARGET_TUPLE
export PATH_HOST
export HAVE_ARM
export HAVE_X86
export HAVE_MIPS
export PLATFORM_SHORT_ARCH

75 76
# Add the NDK toolchain to the PATH, needed both for contribs and for building
# stub libraries
77 78
NDK_TOOLCHAIN_PATH=${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/`uname|tr A-Z a-z`-x86/bin
export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
79

Rafaël Carré's avatar
Rafaël Carré committed
80
# 1/ libvlc, libvlccore and its plugins
81
TESTED_HASH=6f621b95b3f
82
if [ ! -d "vlc" ]; then
83
    echo "VLC source not found, cloning"
84
    git clone git://git.videolan.org/vlc.git vlc
Philipp Dreimann's avatar
Philipp Dreimann committed
85
    cd vlc
86
    git checkout -B android ${TESTED_HASH}
87
    echo "Applying the patches"
88
    git am -3 ../patches/*.patch
89 90 91 92 93
    if [ $? -ne 0 ]; then
        git am --abort
        echo "Applying the patches failed, aborting git-am"
        exit 1
    fi
94
else
95
    echo "VLC source found"
96
    cd vlc
97 98 99 100 101 102 103
    if ! git cat-file -e ${TESTED_HASH}; then
        cat << EOF
***
*** 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
104 105

cd vlc
106 107 108
git reset --hard origin
git pull origin master
git checkout -B android ${TESTED_HASH}
Sébastien Toque's avatar
Sébastien Toque committed
109
git am -3 ../patches/*
110 111 112 113 114 115 116

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

EOF
        exit 1
    fi
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
117

118
if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
119
    EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
120 121
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
elif [ ${ANDROID_ABI} = "armeabi" ] ; then
Edward Wang's avatar
Edward Wang committed
122 123
    if [ -n "${NO_ARMV6}" ]; then
        EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
124
    else
Edward Wang's avatar
Edward Wang committed
125 126 127 128 129
        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
130
    fi
Edward Wang's avatar
Edward Wang committed
131 132
elif [ ${ANDROID_ABI} = "x86" ] ; then
    EXTRA_CFLAGS="-march=pentium -ffunction-sections -funwind-tables -frtti -fno-exceptions"
Edward Wang's avatar
Edward Wang committed
133
elif [ ${ANDROID_ABI} = "mips" ] ; then
Edward Wang's avatar
Edward Wang committed
134
    EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
Edward Wang's avatar
Edward Wang committed
135 136 137
    # 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
138 139 140
else
    echo "Unknown ABI. Die, die, die!"
    exit 2
141 142
fi

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

Rafaël Carré's avatar
Rafaël Carré committed
145 146 147
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"

148 149 150 151
echo "Building the contribs"
mkdir -p contrib/android
cd contrib/android
../bootstrap --host=${TARGET_TUPLE} --disable-disc --disable-sout --enable-small \
152
    --disable-dca \
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    --disable-sdl \
    --disable-SDL_image \
    --disable-fontconfig \
    --disable-zvbi \
    --disable-kate \
    --disable-caca \
    --disable-gettext \
    --disable-mpcdec \
    --disable-upnp \
    --disable-gme \
    --disable-tremor \
    --disable-vorbis \
    --disable-sidplay2 \
    --disable-samplerate \
    --disable-faad2 \
168
    --disable-harfbuzz \
169 170 171 172
    --enable-iconv

# TODO: mpeg2, theora

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

177
# Release or not?
Rafaël Carré's avatar
Rafaël Carré committed
178
if [ $# -ne 0 ] && [ "$1" = "release" ]; then
179
    OPTS=""
180 181
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
    RELEASEFLAG="RELEASE=1"
182 183 184 185
else
    OPTS="--enable-debug"
fi

186 187 188 189 190 191
MAKEFLAGS=
if which nproc >/dev/null
then
MAKEFLAGS=-j`nproc`
fi

192
echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
193
export VLC_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
194

Rafaël Carré's avatar
Rafaël Carré committed
195
make fetch
196
make $MAKEFLAGS
Rémi Duraffort's avatar
Rémi Duraffort committed
197 198 199

cd ../.. && mkdir -p android && cd android

200 201
echo "Bootstraping"
../bootstrap
Rémi Duraffort's avatar
Rémi Duraffort committed
202 203

echo "Configuring"
204
../../configure.sh $OPTS
Rémi Duraffort's avatar
Rémi Duraffort committed
205

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
206
echo "Building"
207
make $MAKEFLAGS
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
208

Rafaël Carré's avatar
Rafaël Carré committed
209 210 211

# 2/ VLC android UI and specific code

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
212 213
echo "Building Android"
cd ../../
Rafaël Carré's avatar
Rafaël Carré committed
214

215
export ANDROID_SYS_HEADERS_GINGERBREAD=${PWD}/android-headers-gingerbread
216
export ANDROID_SYS_HEADERS_HC=${PWD}/android-headers-hc
217
export ANDROID_SYS_HEADERS_ICS=${PWD}/android-headers-ics
Rafaël Carré's avatar
Rafaël Carré committed
218 219

export ANDROID_LIBS=${PWD}/android-libs
220
export VLC_BUILD_DIR=vlc/android
Rafaël Carré's avatar
Rafaël Carré committed
221

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
222
make distclean
223
make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL $RELEASEFLAG
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280

# 3/ Environment script
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
export ANDROID_LIBS=$ANDROID_LIBS
export VLC_BUILD_DIR=$PWD/vlc/android
export TARGET_TUPLE=$TARGET_TUPLE
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