compile.sh 5.62 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
16
   echo "Please set ANDROID_ABI to your architecture."
17 18 19
   exit 1
fi

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

49 50
HAVE_64=0

Edward Wang's avatar
Edward Wang committed
51 52
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
53
    TARGET_TUPLE="i686-linux-android"
Edward Wang's avatar
Edward Wang committed
54 55
    PATH_HOST="x86"
    PLATFORM_SHORT_ARCH="x86"
Thomas Guillem's avatar
Thomas Guillem committed
56 57 58 59 60
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
    TARGET_TUPLE="x86_64-linux-android"
    PATH_HOST="x86_64"
    HAVE_64=1
    PLATFORM_SHORT_ARCH="x86_64"
Edward Wang's avatar
Edward Wang committed
61 62 63 64
elif [ ${ANDROID_ABI} = "mips" ] ; then
    TARGET_TUPLE="mipsel-linux-android"
    PATH_HOST=$TARGET_TUPLE
    PLATFORM_SHORT_ARCH="mips"
Thomas Guillem's avatar
Thomas Guillem committed
65 66 67 68 69
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
    TARGET_TUPLE="aarch64-linux-android"
    PATH_HOST=$TARGET_TUPLE
    HAVE_64=1
    PLATFORM_SHORT_ARCH="arm64"
Edward Wang's avatar
Edward Wang committed
70 71 72 73 74
else
    TARGET_TUPLE="arm-linux-androideabi"
    PATH_HOST=$TARGET_TUPLE
    PLATFORM_SHORT_ARCH="arm"
fi
75

76 77 78 79 80 81
# 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
82
            ANDROID_API=android-21
83 84 85 86 87
        else
            GCCVER=4.8
            ANDROID_API=android-9
        fi
    ;;
88
    *)
89
        echo "You need the NDKv10 or later"
90 91 92 93
        exit 1
    ;;
esac

94 95
export GCCVER            # Android.mk
export ANDROID_API       # Android.mk for -21
96

97 98 99 100
SYSROOT=$ANDROID_NDK/platforms/$ANDROID_API/arch-$PLATFORM_SHORT_ARCH
export SYSROOT           # Makefile for android-libs
export TARGET_TUPLE      # Makefile for android-libs
export HAVE_64           # Makefile for libiomx.so.*
Edward Wang's avatar
Edward Wang committed
101

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

107 108
ANDROID_PATH="`pwd`"

109
# Fetch VLC source
110
if [ "$FETCH" = 1 ]
111 112
then
    # 1/ libvlc, libvlccore and its plugins
Thomas Guillem's avatar
Thomas Guillem committed
113
    TESTED_HASH=18e445a
114 115
    if [ ! -d "vlc" ]; then
        echo "VLC source not found, cloning"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
116
        git clone git://git.videolan.org/vlc.git vlc
117 118 119 120 121 122 123
        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
124 125 126 127 128
***
*** 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
129 130

cd vlc
131 132 133 134 135 136 137
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
138 139
            exit 1
        fi
140
    fi
141 142 143 144
else
    cd vlc
fi

145
if [ "$BUILD" = 0 ]
146 147 148
then
    echo "Not building anything, please run $0 --build"
    exit 0
149
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
150

151
# Make in //
152 153 154 155 156 157 158 159
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
160 161
fi

162 163 164
############
# Make VLC #
############
165 166 167 168 169 170 171
echo "Configuring"
${ANDROID_PATH}/compile-libvlc.sh $*

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

174
if [ "$JNI" = 1 ]; then
175
    CLEAN="jniclean"
176
    TARGET="libvlc/obj/local/${ANDROID_ABI}/libvlcjni.so"
177 178
else
    CLEAN="distclean"
Rafaël Carré's avatar
Rafaël Carré committed
179
    TARGET=
180
fi
Rafaël Carré's avatar
Rafaël Carré committed
181

182
export ANDROID_SYS_HEADERS=${PWD}/android-headers
Rafaël Carré's avatar
Rafaël Carré committed
183 184

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

187
make $CLEAN
188
make -j1 TARGET_TUPLE=$TARGET_TUPLE SYSROOT=$SYSROOT GCCVER=$GCCVER RELEASE=$RELEASE $TARGET
189

190 191 192
#
# Exporting a environment script with all the necessary variables
#
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
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
216
export ANDROID_API=$ANDROID_API
217 218 219 220
export ANDROID_ABI=$ANDROID_ABI
export ANDROID_SDK=$ANDROID_SDK
export ANDROID_NDK=$ANDROID_NDK
export GCCVER=$GCCVER
221
export ANDROID_SYS_HEADERS=$ANDROID_SYS_HEADERS
222
export ANDROID_LIBS=$ANDROID_LIBS
Edward Wang's avatar
Edward Wang committed
223
export VLC_BUILD_DIR=$VLC_BUILD_DIR
224
export TARGET_TUPLE=$TARGET_TUPLE
Thomas Guillem's avatar
Thomas Guillem committed
225
export RELEASE=$RELEASE
226 227 228 229 230 231
EssentialsA

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

# CPU flags
232
echo "export HAVE_64=${HAVE_64}" >> env.sh