compile-libvlc.sh 12.1 KB
Newer Older
1 2
#!/bin/sh

3 4 5 6 7 8 9 10 11 12 13
#############
# FUNCTIONS #
#############

checkfail()
{
    if [ ! $? -eq 0 ];then
        echo "$1"
        exit 1
    fi
}
14

Thomas Guillem's avatar
Thomas Guillem committed
15 16 17 18
#############
# ARGUMENTS #
#############

19
RELEASE=0
Thomas Guillem's avatar
Thomas Guillem committed
20
ASAN=0
21 22 23 24 25 26 27 28 29 30 31
while [ $# -gt 0 ]; do
    case $1 in
        help|--help)
            echo "Use -a to set the ARCH"
            echo "Use --release to build in release mode"
            exit 1
            ;;
        a|-a)
            ANDROID_ABI=$2
            shift
            ;;
Thomas Guillem's avatar
Thomas Guillem committed
32 33 34
        -c)
            CHROME_OS=1
            ;;
Thomas Guillem's avatar
Thomas Guillem committed
35 36 37
        --asan)
            ASAN=1
            ;;
38 39 40 41 42 43 44
        release|--release)
            RELEASE=1
            ;;
    esac
    shift
done

45 46 47 48 49 50
if [ -z "$ANDROID_NDK" ]; then
    echo "Please set the ANDROID_NDK environment variable with its path."
    exit 1
fi

if [ -z "$ANDROID_ABI" ]; then
51 52
    echo "Please pass the ANDROID ABI to the correct architecture, using
                compile-libvlc.sh -a ARCH
53 54
    ARM:     (armeabi-v7a|arm)
    ARM64:   (arm64-v8a|arm64)
55
    X86:     x86, x86_64"
56 57 58
    exit 1
fi

59 60 61 62 63 64 65 66 67 68 69
###########################
# VLC BOOTSTRAP ARGUMENTS #
###########################

VLC_BOOTSTRAP_ARGS="\
    --disable-disc \
    --enable-dvdread \
    --enable-dvdnav \
    --disable-dca \
    --disable-goom \
    --disable-chromaprint \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
70
    --enable-lua \
71 72 73 74 75 76 77 78 79
    --disable-schroedinger \
    --disable-sdl \
    --disable-SDL_image \
    --disable-fontconfig \
    --enable-zvbi \
    --disable-kate \
    --disable-caca \
    --disable-gettext \
    --disable-mpcdec \
Thomas Guillem's avatar
Thomas Guillem committed
80
    --enable-upnp \
81 82 83 84 85 86
    --disable-gme \
    --disable-tremor \
    --enable-vorbis \
    --disable-sidplay2 \
    --disable-samplerate \
    --disable-faad2 \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
87
    --enable-harfbuzz \
88 89 90
    --enable-iconv \
    --disable-aribb24 \
    --disable-aribb25 \
91
    --enable-mpg123 \
92
    --enable-libdsm \
Thomas Guillem's avatar
Thomas Guillem committed
93
    --enable-libarchive \
Thomas Guillem's avatar
Thomas Guillem committed
94
    --disable-libmpeg2 \
Thomas Guillem's avatar
Thomas Guillem committed
95
    --enable-soxr \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
96
    --enable-nfs \
97
    --enable-microdns \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
98
    --enable-fluidlite \
Thomas Guillem's avatar
Thomas Guillem committed
99
    --disable-mad \
Geoffrey Métais's avatar
Geoffrey Métais committed
100 101 102
    --disable-vncclient \
    --disable-vnc \
    --enable-jpeg \
103
    --enable-libplacebo \
104
    --enable-ad-clauses \
105
    --disable-srt \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
106
    --enable-vpx \
Geoffrey Métais's avatar
Geoffrey Métais committed
107
    --disable-x265 \
108
    --disable-medialibrary \
109 110 111 112 113 114 115 116 117 118 119 120 121 122
"

###########################
# VLC CONFIGURE ARGUMENTS #
###########################

VLC_CONFIGURE_ARGS="\
    --disable-nls \
    --enable-live555 --enable-realrtsp \
    --enable-avformat \
    --enable-swscale \
    --enable-avcodec \
    --enable-opus \
    --enable-opensles \
123
    --enable-matroska \
124 125 126 127 128 129
    --enable-taglib \
    --enable-dvbpsi \
    --disable-vlc --disable-shared \
    --disable-update-check \
    --disable-vlm \
    --disable-dbus \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
130
    --enable-lua \
131 132 133 134 135 136 137 138 139
    --disable-vcd \
    --disable-v4l2 \
    --enable-dvdread \
    --enable-dvdnav \
    --disable-bluray \
    --disable-linsys \
    --disable-decklink \
    --disable-libva \
    --disable-dv1394 \
140
    --enable-mod \
141 142 143
    --disable-sid \
    --disable-gme \
    --disable-tremor \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
144 145
    --disable-mad \
    --enable-mpg123 \
146 147 148 149
    --disable-dca \
    --disable-sdl-image \
    --enable-zvbi \
    --disable-fluidsynth \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
150
    --enable-fluidlite \
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    --disable-jack \
    --disable-pulse \
    --disable-alsa \
    --disable-samplerate \
    --disable-xcb \
    --disable-qt \
    --disable-skins2 \
    --disable-mtp \
    --disable-notify \
    --enable-libass \
    --disable-svg \
    --disable-udev \
    --enable-libxml2 \
    --disable-caca \
    --enable-gles2 \
    --disable-goom \
    --disable-projectm \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
168
    --enable-sout \
169 170
    --enable-vorbis \
    --disable-faad \
171
    --disable-schroedinger \
Geoffrey Métais's avatar
Geoffrey Métais committed
172 173
    --disable-vnc \
    --enable-jpeg \
174 175
"

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
########################
# VLC MODULE BLACKLIST #
########################

VLC_MODULE_BLACKLIST="
    addons.*
    stats
    access_(bd|shm|imem)
    oldrc
    real
    hotkeys
    gestures
    sap
    dynamicoverlay
    rss
    ball
    audiobargraph_[av]
    clone
    mosaic
    osdmenu
    puzzle
    mediadirs
    t140
    ripple
    motion
    sharpen
    grain
    posterize
    mirror
    wall
    scene
    blendbench
    psychedelic
    alphamask
    netsync
    audioscrobbler
    motiondetect
    motionblur
    export
    smf
    podcast
    bluescreen
    erase
    stream_filter_record
    speex_resampler
    remoteosd
    magnify
    gradient
    dtstofloat32
    logger
    visual
    fb
    aout_file
    yuv
    .dummy
"

233 234
SRC_DIR=$PWD

235
. ./build-common
236

237 238 239
###########################
# Build buildsystem tools #
###########################
240

241 242 243 244 245 246 247 248 249 250
export PATH="`pwd`/vlc/extras/tools/build/bin:$PATH"
echo "Building tools"
cd vlc/extras/tools
./bootstrap
checkfail "buildsystem tools: bootstrap failed"
make $MAKEFLAGS
checkfail "buildsystem tools: make failed"
make $MAKEFLAGS .gas || make $MAKEFLAGS .buildgas
checkfail "buildsystem tools: make failed"
cd ../../..
Thomas Guillem's avatar
Thomas Guillem committed
251

252 253
VLC_SRC_DIR="$SRC_DIR/vlc"
VLC_CONTRIB="$VLC_SRC_DIR/contrib/$TARGET_TUPLE"
254

255 256
cd vlc

257 258 259 260
#############
# BOOTSTRAP #
#############

261
if [ ! -f configure ]; then
262 263
    echo "Bootstraping"
    ./bootstrap
264
    checkfail "vlc: bootstrap failed"
265 266
fi

267 268 269
############
# Contribs #
############
Thomas Guillem's avatar
Thomas Guillem committed
270

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
echo "Building the contribs"
mkdir -p contrib/contrib-android-${TARGET_TUPLE}

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

cd contrib/contrib-android-${TARGET_TUPLE}
288

289
export USE_FFMPEG=1
290
ANDROID_ABI=${ANDROID_ABI} ANDROID_API=${ANDROID_API} \
291
    ../bootstrap --host=${TARGET_TUPLE} ${VLC_BOOTSTRAP_ARGS}
292
checkfail "contribs: bootstrap failed"
293 294 295 296 297

# 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
[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak

Thomas Guillem's avatar
Thomas Guillem committed
298 299
echo "EXTRA_CFLAGS=${EXTRA_CFLAGS}" >> config.mak
echo "EXTRA_CXXFLAGS=${EXTRA_CXXFLAGS}" >> config.mak
300
echo "EXTRA_LDFLAGS=${EXTRA_LDFLAGS}" >> config.mak
301 302 303 304 305
echo "CC=${NDK_TOOLCHAIN_PATH}/clang" >> config.mak
echo "CXX=${NDK_TOOLCHAIN_PATH}/clang++" >> config.mak
echo "AR=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-ar" >> config.mak
echo "RANLIB=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-ranlib" >> config.mak
echo "LD=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-ld" >> config.mak
306

307 308 309
# fix modplug endianess check (narrowing error)
export ac_cv_c_bigendian=no

310
make $MAKEFLAGS fetch
311
checkfail "contribs: make fetch failed"
312 313

# gettext
314
which autopoint >/dev/null || make $MAKEFLAGS .gettext
315 316
#export the PATH
# Make
317
make $MAKEFLAGS
318
checkfail "contribs: make failed"
319

320
cd ../../
321

322 323 324
###################
# BUILD DIRECTORY #
###################
Thomas Guillem's avatar
Thomas Guillem committed
325

Thomas Guillem's avatar
Thomas Guillem committed
326 327 328 329 330
if [ "${CHROME_OS}" = "1" ];then
    VLC_BUILD_DIR=build-chrome-${TARGET_TUPLE}
else
    VLC_BUILD_DIR=build-android-${TARGET_TUPLE}
fi
Thomas Guillem's avatar
Thomas Guillem committed
331 332 333
if [ "${ASAN}" = 1 ];then
    VLC_BUILD_DIR=${VLC_BUILD_DIR}-asan
fi
334
VLC_BUILD_DIR=`realpath ${VLC_BUILD_DIR}`
335
mkdir -p $VLC_BUILD_DIR && cd $VLC_BUILD_DIR
336 337 338 339 340

#############
# CONFIGURE #
#############

341 342 343 344
if [ "${CHROME_OS}" = "1" ];then
    # chrome OS doesn't have eventfd
    export ac_cv_func_eventfd=no
    export ac_cv_header_sys_eventfd_h=no
345
    export ac_cv_func_pipe2=no
346 347
fi

348 349
if [ ${ANDROID_API} -lt "26" ]; then
    # android APIs < 26 have empty sys/shm.h headers that triggers shm detection but it
350 351
    # doesn't have any shm functions and/or symbols. */
    export ac_cv_header_sys_shm_h=no
352 353 354
fi

if [ ${ANDROID_API} -lt "21" ] ; then
355
    # force uselocale using libandroid_support since it's present in libc++
Thomas Guillem's avatar
Thomas Guillem committed
356
    export ac_cv_func_uselocale=yes
Thomas Guillem's avatar
Thomas Guillem committed
357

358
    # -l order is important here
Thomas Guillem's avatar
Thomas Guillem committed
359
    VLC_LDFLAGS="${VLC_LDFLAGS} -L${NDK_LIB_DIR} -landroid_support"
360 361 362 363
    if [ "${ANDROID_ABI}" = "armeabi-v7a" ]; then
        VLC_LDFLAGS="${VLC_LDFLAGS} -lunwind"
    fi
    VLC_LDFLAGS="${VLC_LDFLAGS} -latomic -lgcc"
364
fi
Thomas Guillem's avatar
Thomas Guillem committed
365

366 367 368 369 370
# always use fixups for search.h and tdestroy
export ac_cv_header_search_h=no
export ac_cv_func_tdestroy=no
export ac_cv_func_tfind=no

371
if [ ! -e ./config.h -o "$RELEASE" = 1 ]; then
372
CFLAGS="${VLC_CFLAGS} ${EXTRA_CFLAGS}" \
Thomas Guillem's avatar
Thomas Guillem committed
373 374 375 376 377 378 379 380
CXXFLAGS="${VLC_CXXFLAGS} ${EXTRA_CFLAGS} ${EXTRA_CXXFLAGS}" \
CC="${CROSS_TOOLS}clang" \
CXX="${CROSS_TOOLS}clang++" \
NM="${CROSS_TOOLS}nm" \
STRIP="${CROSS_TOOLS}strip" \
RANLIB="${CROSS_TOOLS}ranlib" \
AR="${CROSS_TOOLS}ar" \
PKG_CONFIG_LIBDIR=$VLC_SRC_DIR/contrib/$TARGET_TUPLE/lib/pkgconfig \
381
PKG_CONFIG_PATH=$VLC_SRC_DIR/contrib/$TARGET_TUPLE/lib/pkgconfig \
382
PATH=../contrib/bin:$PATH \
383
sh ../configure --host=$TARGET_TUPLE --build=x86_64-unknown-linux \
Thomas Guillem's avatar
Thomas Guillem committed
384
    --with-contrib=${VLC_SRC_DIR}/contrib/${TARGET_TUPLE} \
385
    --prefix=${VLC_BUILD_DIR}/install/ \
Thomas Guillem's avatar
Thomas Guillem committed
386
    ${EXTRA_PARAMS} ${VLC_CONFIGURE_ARGS} ${OPTS}
387
checkfail "vlc: configure failed"
Thomas Guillem's avatar
Thomas Guillem committed
388
fi
389

390 391 392 393 394 395
############
# BUILDING #
############

echo "Building"
make $MAKEFLAGS
396
checkfail "vlc: make failed"
397 398
make install
checkfail "vlc: make install failed"
399

400
cd $SRC_DIR
401

Thomas Guillem's avatar
Thomas Guillem committed
402
echo ok
403

404

405 406 407
##################
# libVLC modules #
##################
Thomas Guillem's avatar
Thomas Guillem committed
408

409
REDEFINED_VLC_MODULES_DIR=${VLC_BUILD_DIR}/install/lib/vlc/plugins
410 411
rm -rf ${REDEFINED_VLC_MODULES_DIR}
mkdir -p ${REDEFINED_VLC_MODULES_DIR}
412

413
echo "Generating static module list"
414 415 416 417 418 419 420 421 422 423
blacklist_regexp=
for i in ${VLC_MODULE_BLACKLIST}
do
    if [ -z "${blacklist_regexp}" ]
    then
        blacklist_regexp="${i}"
    else
        blacklist_regexp="${blacklist_regexp}|${i}"
    fi
done
424

425 426 427 428 429 430 431 432 433 434
find_modules()
{
    echo "`find $1 -name 'lib*plugin.a' | grep -vE "lib(${blacklist_regexp})_plugin.a" | tr '\n' ' '`"
}

get_symbol()
{
    echo "$1" | grep vlc_entry_$2|cut -d" " -f 3
}

435
VLC_MODULES=$(find_modules ${VLC_BUILD_DIR}/modules)
436 437 438
DEFINITION="";
BUILTINS="const void *vlc_static_modules[] = {\n";
for file in $VLC_MODULES; do
439
    outfile=${REDEFINED_VLC_MODULES_DIR}/`basename $file`
440
    name=`echo $file | sed 's/.*\.libs\/lib//' | sed 's/_plugin\.a//'`;
Thomas Guillem's avatar
Thomas Guillem committed
441
    symbols=$("${CROSS_TOOLS}nm" -g $file)
442

443
    # assure that all modules have differents symbol names
444 445 446
    entry=$(get_symbol "$symbols" _)
    copyright=$(get_symbol "$symbols" copyright)
    license=$(get_symbol "$symbols" license)
447
    cat <<EOF > ${REDEFINED_VLC_MODULES_DIR}/syms
448 449 450 451
AccessOpen AccessOpen__$name
AccessClose AccessClose__$name
StreamOpen StreamOpen__$name
StreamClose StreamClose__$name
452 453
OpenDemux OpenDemux__$name
CloseDemux CloseDemux__$name
454 455 456 457 458 459
DemuxOpen DemuxOpen__$name
DemuxClose DemuxClose__$name
OpenFilter OpenFilter__$name
CloseFilter CloseFilter__$name
Open Open__$name
Close Close__$name
460 461 462 463
$entry vlc_entry__$name
$copyright vlc_entry_copyright__$name
$license vlc_entry_license__$name
EOF
Thomas Guillem's avatar
Thomas Guillem committed
464
    ${CROSS_TOOLS}objcopy --redefine-syms ${REDEFINED_VLC_MODULES_DIR}/syms $file $outfile
465 466 467 468 469
    checkfail "objcopy failed"

    DEFINITION=$DEFINITION"int vlc_entry__$name (int (*)(void *, void *, int, ...), void *);\n";
    BUILTINS="$BUILTINS vlc_entry__$name,\n";
done;
470
BUILTINS="$BUILTINS NULL\n};\n"; \
471 472 473 474 475 476 477 478 479 480 481
printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > libvlc/jni/libvlcjni-modules.c

DEFINITION=""
BUILTINS="const void *libvlc_functions[] = {\n";
for func in `cat vlc/lib/libvlc.sym`
do
    DEFINITION=$DEFINITION"int $func(void);\n";
    BUILTINS="$BUILTINS $func,\n";
done
BUILTINS="$BUILTINS NULL\n};\n"; \
printf "/* Autogenerated from the list of modules */\n#include <unistd.h>\n$DEFINITION\n$BUILTINS\n" > libvlc/jni/libvlcjni-symbols.c
482

483
rm ${REDEFINED_VLC_MODULES_DIR}/syms
484

485 486 487
############################################
# NDK-Build for libvlc.so and libvlcjni.so #
############################################
488

489
VLC_MODULES=$(find_modules ${REDEFINED_VLC_MODULES_DIR})
490
VLC_CONTRIB_LDFLAGS=`for i in $(/bin/ls $VLC_CONTRIB/lib/pkgconfig/*.pc); do PKG_CONFIG_PATH="$VLC_CONTRIB/lib/pkgconfig/" pkg-config --libs $i; done |xargs`
491 492 493 494 495 496
echo -e "ndk-build vlc"

$ANDROID_NDK/ndk-build$OSCMD -C libvlc \
    APP_STL="c++_shared" \
    APP_CPPFLAGS="-frtti -fexceptions" \
    VLC_SRC_DIR="$VLC_SRC_DIR" \
497
    VLC_BUILD_DIR="$VLC_BUILD_DIR" \
498 499 500
    VLC_CONTRIB="$VLC_CONTRIB" \
    VLC_CONTRIB_LDFLAGS="$VLC_CONTRIB_LDFLAGS" \
    VLC_MODULES="$VLC_MODULES" \
501
    VLC_LDFLAGS="$VLC_LDFLAGS" \
502 503 504 505 506 507
    APP_BUILD_SCRIPT=jni/Android.mk \
    APP_PLATFORM=android-${ANDROID_API} \
    APP_ABI=${ANDROID_ABI} \
    NDK_PROJECT_PATH=jni \
    NDK_TOOLCHAIN_VERSION=clang \
    NDK_DEBUG=${NDK_DEBUG}
508

509
checkfail "ndk-build libvlc failed"
510

511
cd ${SRC_DIR}
Thomas Guillem's avatar
Thomas Guillem committed
512
OUT_DBG_DIR=.dbg/${ANDROID_ABI}
513
echo "Dumping dbg symbols info ${OUT_DBG_DIR}"
514 515

mkdir -p $OUT_DBG_DIR
Thomas Guillem's avatar
Thomas Guillem committed
516
cp -a libvlc/jni/obj/local/${ANDROID_ABI}/*.so ${OUT_DBG_DIR}