compile.sh 4.15 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 53
# Set up ABI variables
if [ ${ANDROID_ABI} = "x86" ] ; then
    PATH_HOST="x86"
Thomas Guillem's avatar
Thomas Guillem committed
54 55 56
elif [ ${ANDROID_ABI} = "x86_64" ] ; then
    PATH_HOST="x86_64"
    HAVE_64=1
Edward Wang's avatar
Edward Wang committed
57
elif [ ${ANDROID_ABI} = "mips" ] ; then
58
    PATH_HOST="mipsel-linux-android"
Thomas Guillem's avatar
Thomas Guillem committed
59
elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
60
    PATH_HOST="aarch64-linux-android"
Thomas Guillem's avatar
Thomas Guillem committed
61
    HAVE_64=1
Edward Wang's avatar
Edward Wang committed
62
else
63
    PATH_HOST="arm-linux-androideabi"
Edward Wang's avatar
Edward Wang committed
64
fi
65

66 67 68 69 70 71 72 73 74 75
# 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
        else
            GCCVER=4.8
        fi
    ;;
76
    *)
77
        echo "You need the NDKv10 or later"
78 79 80 81
        exit 1
    ;;
esac

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

87 88
ANDROID_PATH="`pwd`"

89
# Fetch VLC source
90
if [ "$FETCH" = 1 ]
91 92
then
    # 1/ libvlc, libvlccore and its plugins
Thomas Guillem's avatar
Thomas Guillem committed
93
    TESTED_HASH=18e445a
94 95
    if [ ! -d "vlc" ]; then
        echo "VLC source not found, cloning"
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
96
        git clone git://git.videolan.org/vlc.git vlc
97 98 99 100 101 102 103
        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
104 105 106 107 108
***
*** 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
109 110

cd vlc
111 112 113 114 115 116 117
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
118 119
            exit 1
        fi
120
        cd ..
121
    fi
122 123
fi

124
if [ "$BUILD" = 0 ]
125 126 127
then
    echo "Not building anything, please run $0 --build"
    exit 0
128
fi
Rémi Duraffort's avatar
Rémi Duraffort committed
129

130 131 132
############
# Make VLC #
############
133 134 135 136 137 138 139
echo "Configuring"
${ANDROID_PATH}/compile-libvlc.sh $*

####################################
# VLC android UI and specific code
####################################
echo "Building VLC for Android"
Rémi Duraffort's avatar
Rémi Duraffort committed
140

141
if [ "$JNI" = 1 ]; then
142
    CLEAN="jniclean"
143
    TARGET="libvlc/obj/local/${ANDROID_ABI}/libvlcjni.so"
144 145
else
    CLEAN="distclean"
Rafaël Carré's avatar
Rafaël Carré committed
146
    TARGET=
147
fi
Rafaël Carré's avatar
Rafaël Carré committed
148

149
make -j1 RELEASE=$RELEASE $TARGET
150

151 152 153
#
# Exporting a environment script with all the necessary variables
#
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
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_SDK=$ANDROID_SDK
export ANDROID_NDK=$ANDROID_NDK
179
export ANDROID_ABI=$ANDROID_ABI
180 181 182 183
EssentialsA

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