compileAndBuildVLCKit.sh 31.3 KB
Newer Older
1 2
#!/bin/sh
# Copyright (C) Pierre d'Herbemont, 2010
3
# Copyright (C) Felix Paul Kühne, 2012-2019
4 5 6

set -e

7
BUILD_DEVICE=yes
8
BUILD_SIMULATOR=yes
9
BUILD_STATIC_FRAMEWORK=no
10
BUILD_DYNAMIC_FRAMEWORK=no
11
SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
12
SDK_MIN=8.0
13
VERBOSE=no
14
DEBUG=no
15 16 17
CONFIGURATION="Release"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
18
SCARY=yes
Felix Paul Kühne's avatar
Felix Paul Kühne committed
19
TVOS=no
20
MACOS=no
21
IOS=yes
22
BITCODE=no
23 24
OSVERSIONMINCFLAG=iphoneos
OSVERSIONMINLDFLAG=ios
25
ROOT_DIR=empty
26
FARCH="all"
27

28
TESTEDHASH="563b25c5c1" # libvlc hash that this version of VLCKit is build on
29

30 31 32 33
if [ -z "$MAKE_JOBS" ]; then
    CORE_COUNT=`sysctl -n machdep.cpu.core_count`
    let MAKE_JOBS=$CORE_COUNT+1
fi
34

35 36 37 38 39 40 41 42 43
usage()
{
cat << EOF
usage: $0 [-s] [-v] [-k sdk]

OPTIONS
   -k       Specify which sdk to use (see 'xcodebuild -showsdks', current: ${SDK})
   -v       Be more verbose
   -s       Build for simulator
44
   -f       Build framework for device and simulator
45 46 47
   -d       Enable Debug
   -n       Skip script steps requiring network interaction
   -l       Skip libvlc compilation
Felix Paul Kühne's avatar
Felix Paul Kühne committed
48
   -t       Build for tvOS
49
   -x       Build for macOS / Mac OS X
50
   -w       Build a limited stack of non-scary libraries only
Felix Paul Kühne's avatar
Felix Paul Kühne committed
51
   -y       Build universal static libraries
52
   -b       Enable bitcode
53
   -a       Build framework for specific arch (all|i386|x86_64|armv7|armv7s|aarch64)
54
   -e       External VLC source path
55 56 57
EOF
}

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
get_actual_arch() {
    if [ "$1" = "aarch64" ]; then
        echo "arm64"
    else
        echo "$1"
    fi
}

get_arch() {
    if [ "$1" = "arm64" ]; then
        echo "aarch64"
    else
        echo "$1"
    fi
}

74 75 76 77 78 79 80 81
is_simulator_arch() {
    if [ "$1" = "i386" -o "$1" = "x86_64" ];then
        return 0
    else
        return 1
    fi
}

82 83 84 85 86 87 88 89 90 91 92 93 94 95
spushd()
{
     pushd "$1" 2>&1> /dev/null
}

spopd()
{
     popd 2>&1> /dev/null
}

info()
{
     local green="\033[1;32m"
     local normal="\033[0m"
96
     echo "[${green}info${normal}] $1"
97 98
}

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
cleantheenvironment()
{
    export AS=""
    export CCAS=""
    export ASCPP=""
    export CC=""
    export CFLAGS=""
    export CPPFLAGS=""
    export CXX=""
    export CXXFLAGS=""
    export CXXCPPFLAGS=""
    export OBJC=""
    export OBJCFLAGS=""
    export LD=""
    export LDFLAGS=""
    export STRIP=""
115
    export PKG_CONFIG_PATH=""
116 117
}

118 119
buildxcodeproj()
{
120 121
    cleantheenvironment

122 123 124 125 126 127
    local target="$2"
    local PLATFORM="$3"

    info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"

    local architectures=""
128
    if [ "$FARCH" = "all" ];then
129
        if [ "$TVOS" = "yes" ]; then
130 131 132 133 134
            if [ "$PLATFORM" = "appletvsimulator" ]; then
                architectures="x86_64"
            else
                architectures="arm64"
            fi
135
        fi
136 137 138 139 140 141 142
        if [ "$IOS" = "yes" ]; then
            if [ "$PLATFORM" = "iphonesimulator" ]; then
                architectures="i386 x86_64"
            else
                architectures="armv7 armv7s arm64"
            fi
        fi
143
    else
144
        architectures=`get_actual_arch $FARCH`
145 146
    fi

147 148 149 150 151
    local bitcodeflag=""
    if [ "$BITCODE" = "yes" ]; then
        bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
    fi

152 153 154 155
    local defs="$GCC_PREPROCESSOR_DEFINITIONS"
    if [ "$SCARY" = "no" ]; then
        defs="$defs NOSCARYCODECS"
    fi
156

157 158 159 160 161 162 163
    xcodebuild -project "$1.xcodeproj" \
               -target "$target" \
               -sdk $PLATFORM$SDK \
               -configuration ${CONFIGURATION} \
               ARCHS="${architectures}" \
               IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
               GCC_PREPROCESSOR_DEFINITIONS="$defs" \
164
               ${bitcodeflag} \
165 166 167 168
               > ${out}
}

buildLibVLC() {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
169 170
    ARCH="$1"
    PLATFORM="$2"
171 172 173 174 175
    OSSTYLE=iPhone

    if [ "$DEBUG" = "yes" ]; then
        OPTIM="-O0 -g"
    else
176
        OPTIM="-O3 -g"
177
    fi
178 179 180

    if [ "$TVOS" = "yes" ]; then
        OSSTYLE=AppleTV
181
    fi
182 183 184 185
    if [ "$MACOS" = "yes" ]; then
        OSSTYLE=MacOSX
        PLATFORM=
    fi
186

187
    ACTUAL_ARCH=`get_actual_arch $ARCH`
188 189 190 191 192 193 194 195 196

    info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"

    SDKROOT=`xcode-select -print-path`/Platforms/${OSSTYLE}${PLATFORM}.platform/Developer/SDKs/${OSSTYLE}${PLATFORM}${SDK_VERSION}.sdk

    if [ ! -d "${SDKROOT}" ]
    then
        echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
        exit 1
197
    fi
198 199 200 201 202

    BUILDDIR="${VLCROOT}/build-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
    PREFIX="${VLCROOT}/install-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
    TARGET="${ARCH}-apple-darwin14"

203
    # partially clean the environment
204 205 206 207 208
    export CFLAGS=""
    export CPPFLAGS=""
    export CXXFLAGS=""
    export OBJCFLAGS=""
    export LDFLAGS=""
209 210
    export EXTRA_LDFLAGS=""
    export EXTRA_CFLAGS=""
211 212 213 214 215 216

    export PLATFORM=$PLATFORM
    export SDK_VERSION=$SDK_VERSION
    export VLCSDKROOT=$SDKROOT

    OBJCFLAGS="${OPTIM}"
217 218 219 220
    CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
    EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
    LDFLAGS="-arch ${ACTUAL_ARCH}"
    EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
221

222 223 224 225 226 227 228 229 230 231 232
    SDKNAME_CFLAGS=${OSVERSIONMINCFLAG}
    SDKNAME_LDFLAGS=${OSVERSIONMINLDFLAG}

    if [ "$PLATFORM" = "Simulator" ]; then
        SDKNAME_LDFLAGS+="_simulator"
    fi

    CFLAGS+=" -m${SDKNAME_CFLAGS}-version-min=${SDK_MIN}"
    EXTRA_CFLAGS+=" -m${SDKNAME_CFLAGS}-version-min=${SDK_MIN}"
    LDFLAGS+=" -Wl,-${SDKNAME_LDFLAGS}_version_min,${SDK_MIN}"
    EXTRA_LDFLAGS+=" -Wl,-${SDKNAME_LDFLAGS}_version_min,${SDK_MIN}"
233 234 235 236 237 238 239 240

    if [ "$PLATFORM" = "OS" ]; then
        if [ "$ARCH" != "aarch64" ]; then
            CFLAGS+=" -mcpu=cortex-a8"
            EXTRA_CFLAGS+=" -mcpu=cortex-a8"
        fi
    else # Simulator platform
        LDFLAGS+=" -v"
241 242 243

        # Use the new ABI on simulator, else we can't build
        OBJCFLAGS+=" -fobjc-abi-version=2 -fobjc-legacy-dispatch"
244 245
    fi

246
    if [ "$BITCODE" = "yes" ]; then
247
        CFLAGS+=" -fembed-bitcode"
248
    fi
249

250 251 252 253
    export CFLAGS="${CFLAGS}"
    export CXXFLAGS="${CFLAGS}"
    export CPPFLAGS="${CFLAGS}"
    export OBJCFLAGS="${OBJCFLAGS}"
254
    export LDFLAGS="${LDFLAGS}"
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274

    spushd ${VLCROOT}/contrib

    info "Compiling third-party libraries"

    mkdir -p "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
    cd "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"

    if [ "$PLATFORM" = "OS" ]; then
        export AS="gas-preprocessor.pl ${CC}"
        export ASCPP="gas-preprocessor.pl ${CC}"
        export CCAS="gas-preprocessor.pl ${CC}"
        if [ "$ARCH" = "aarch64" ]; then
            export GASPP_FIX_XCODE5=1
        fi
    else
        export ASCPP="xcrun as"
    fi

    if [ "$TVOS" = "yes" ]; then
275
        CUSTOMOSOPTIONS="--disable-libarchive"
276 277 278 279 280 281
    fi
    if [ "$MACOS" = "yes" ]; then
        CUSTOMOSOPTIONS="--disable-fontconfig --disable-bghudappkit --disable-twolame --disable-microdns --disable-SDL --disable-SDL_image --disable-cddb --disable-bluray"
    fi
    if [ "$IOS" = "yes" ]; then
        CUSTOMOSOPTIONS=""
282 283
    fi

284 285 286 287 288
    if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
        BUILD=""
    else
        BUILD="--build=x86_64-apple-darwin14"
    fi
289

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    if [ "$MACOS" = "yes" ]; then
        # The following symbols do not exist on the minimal macOS version (10.7), so they are disabled
        # here. This allows compilation also with newer macOS SDKs.
        # Added symbols in 10.13
        export ac_cv_func_open_wmemstream=no
        export ac_cv_func_fmemopen=no
        export ac_cv_func_open_memstream=no
        export ac_cv_func_futimens=no
        export ac_cv_func_utimensat=no

        # Added symbols between 10.11 and 10.12
        export ac_cv_func_basename_r=no
        export ac_cv_func_clock_getres=no
        export ac_cv_func_clock_gettime=no
        export ac_cv_func_clock_settime=no
        export ac_cv_func_dirname_r=no
        export ac_cv_func_getentropy=no
        export ac_cv_func_mkostemp=no
        export ac_cv_func_mkostemps=no

        # Added symbols between 10.7 and 10.11
        export ac_cv_func_ffsll=no
        export ac_cv_func_flsll=no
        export ac_cv_func_fdopendir=no
        export ac_cv_func_openat=no
        export ac_cv_func_fstatat=no
        export ac_cv_func_readlinkat=no
    else
        # The following symbols do not exist on the minimal iOS version (7.0), so they are disabled
        # here. This allows compilation also with newer iOS SDKs
        # Added symbols between 7.x and 10.x
        export ac_cv_func_basename_r=no
        export ac_cv_func_clock_getres=no
        export ac_cv_func_clock_gettime=no
        export ac_cv_func_clock_settime=no
        export ac_cv_func_dirname_r=no
        export ac_cv_func_getentropy=no
        export ac_cv_func_mkostemp=no
        export ac_cv_func_mkostemps=no
        export ac_cv_func_open_memstream=no
        export ac_cv_func_futimens=no
    fi
332

333
    export USE_FFMPEG=1
334
    ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
335
        --enable-ad-clauses \
336
        --disable-disc \
337 338 339 340 341 342 343 344 345 346
        --disable-sdl \
        --disable-SDL_image \
        --disable-iconv \
        --enable-zvbi \
        --disable-kate \
        --disable-caca \
        --disable-gettext \
        --disable-mpcdec \
        --disable-upnp \
        --disable-gme \
347
        --disable-srt \
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
        --disable-tremor \
        --enable-vorbis \
        --disable-sidplay2 \
        --disable-samplerate \
        --disable-goom \
        --disable-vncserver \
        --disable-orc \
        --disable-schroedinger \
        --disable-libmpeg2 \
        --disable-chromaprint \
        --disable-mad \
        --enable-fribidi \
        --enable-libxml2 \
        --enable-freetype2 \
        --enable-ass \
        --disable-fontconfig \
        --disable-gpg-error \
        --disable-vncclient \
        --disable-gnutls \
        --disable-lua \
        --disable-luac \
        --disable-aribb24 \
        --disable-aribb25 \
        --enable-vpx \
        --enable-libdsm \
Thomas Guillem's avatar
Thomas Guillem committed
373
        --enable-libplacebo \
374 375 376 377
        --disable-sparkle \
        --disable-growl \
        --disable-breakpad \
        --disable-ncurses \
378
        --disable-asdcplib \
Thomas Guillem's avatar
Thomas Guillem committed
379
        --enable-soxr \
380
        ${CUSTOMOSOPTIONS} \
381 382 383 384
        --enable-taglib > ${out}

    echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
    echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
385 386 387 388 389 390 391
    echo "CC=${CC}" >> config.mak
    echo "CXX=${CXX}" >> config.mak
    echo "OBJC=${OBJC}" >> config.mak
    echo "LD=${LD}" >> config.mak
    echo "AR=${AR}" >> config.mak
    echo "RANLIB=${RANLIB}" >> config.mak
    echo "STRIP=${STRIP}" >> config.mak
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
    make fetch -j$MAKE_JOBS
    make -j$MAKE_JOBS > ${out}

    spopd # ${VLCROOT}/contrib

    if ! [ -e ${VLCROOT}/configure ]; then
        info "Bootstraping vlc"
        ${VLCROOT}/bootstrap  > ${out}
    fi

    mkdir -p ${BUILDDIR}
    spushd ${BUILDDIR}

    if [ "$DEBUG" = "yes" ]; then
        DEBUGFLAG="--enable-debug"
407 408
    else
        export CFLAGS="${CFLAGS} -DNDEBUG"
409 410 411
    fi

    if [ "$SCARY" = "yes" ]; then
Thomas Guillem's avatar
Thomas Guillem committed
412
        SCARYFLAG="--enable-dvbpsi --enable-avcodec"
413 414
    else
        SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
415
    fi
416

417 418
    if [ "$TVOS" != "yes" -a \( "$ARCH" = "armv7" -o "$ARCH" = "armv7s" \) ];then
        export ac_cv_arm_neon=yes
419
    else
420
        export ac_cv_arm_neon=no
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
    fi

    # Available but not authorized
    export ac_cv_func_daemon=no
    export ac_cv_func_fork=no

    if [ "${VLCROOT}/configure" -nt config.log -o \
         "${THIS_SCRIPT_PATH}" -nt config.log ]; then
         info "Configuring vlc"

    ${VLCROOT}/configure \
        --prefix="${PREFIX}" \
        --host="${TARGET}" \
        --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
        --enable-static \
        ${DEBUGFLAG} \
        ${SCARYFLAG} \
        --disable-macosx \
        --disable-macosx-qtkit \
        --disable-macosx-avfoundation \
        --disable-shared \
        --enable-opus \
        --disable-faad \
        --disable-lua \
        --disable-a52 \
        --enable-fribidi \
        --disable-qt --disable-skins2 \
        --disable-vcd \
        --disable-vlc \
        --disable-vlm \
        --disable-httpd \
        --disable-nls \
        --disable-sse \
        --disable-notify \
        --enable-live555 \
        --enable-realrtsp \
        --enable-swscale \
        --disable-projectm \
        --enable-libass \
        --enable-libxml2 \
        --disable-goom \
        --disable-dvdread \
        --disable-dvdnav \
        --disable-bluray \
        --disable-linsys \
        --disable-libva \
        --disable-gme \
        --disable-tremor \
        --enable-vorbis \
        --disable-fluidsynth \
        --disable-jack \
        --disable-pulse \
        --disable-mtp \
        --enable-ogg \
        --enable-speex \
        --enable-theora \
        --enable-flac \
        --disable-screen \
        --enable-freetype \
        --enable-taglib \
        --disable-mmx \
482
        --disable-sparkle \
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
        --disable-addonmanagermodules \
        --disable-mad > ${out}
    fi

    info "Building libvlc"
    make -j$MAKE_JOBS > ${out}

    info "Installing libvlc"
    make install > ${out}

    find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
    rm -rf "${PREFIX}/contribs"
    cp -R "${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" "${PREFIX}/contribs"

    info "Removing unneeded modules"
    blacklist="
    stats
    access_bd
    shm
    access_imem
    oldrc
    real
    hotkeys
    gestures
    dynamicoverlay
    rss
    ball
    marq
    magnify
    audiobargraph_
    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
    logger
    visual
    fb
    aout_file
    invert
    sepia
    wave
    hqdn3d
    headphone_channel_mixer
    gaussianblur
    gradfun
    extract
    colorthres
    antiflicker
    anaglyph
    remap
    oldmovie
    vhs
    demuxdump
    fingerprinter
    output_udp
    output_livehttp
    "

    if [ "$SCARY" = "no" ]; then
    blacklist="${blacklist}
    dts
    dvbsub
    svcd
    hevc
    packetizer_mlp
    a52
    vc1
    uleaddvaudio
    librar
    libvoc
    avio
    chorus_flanger
    smooth
    cvdsub
    libmod
    libdash
    libmpgv
    dolby_surround
    mpegaudio"
    fi

    echo ${blacklist}

    for i in ${blacklist}
    do
        find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
    done

    spopd
}

buildMobileKit() {
    PLATFORM="$1"

604 605
    cleantheenvironment

606 607
    if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
        if [ "$TVOS" = "yes" ]; then
608 609 610 611 612
            # this variable is read by libvlc's contrib build script
            # to create the required build environment
            # for historical raisons, tvOS is a special flavor of iOS
            # so we need to export both variables
            export BUILDFORIOS="yes"
613
            export BUILDFORTVOS="yes"
614
            info "Building libvlc for tvOS"
615 616 617 618 619 620 621 622 623 624 625
        fi
        if [ "$MACOS" = "yes" ]; then
            # macOS is the default build environment for libvlc's contrib
            # build scripts, so we don't need to export anything
            info "Building libvlc for macOS"
        fi
        if [ "$IOS" = "yes" ]; then
            # this variable is read by libvlc's contrib build script
            # to create the required build environment
            export BUILDFORIOS="yes"
            info "Building libvlc for iOS"
626 627
        fi

Thomas Guillem's avatar
Thomas Guillem committed
628 629 630 631 632 633 634 635 636
        export AR=`xcrun -f ar`
        export RANLIB=`xcrun -f ranlib`
        export CC=`xcrun -f clang`
        export OBJC=`xcrun -f clang`
        export CXX=`xcrun -f clang++`
        export LD=`xcrun -f ld`
        export STRIP=`xcrun -f strip`
        export CPPFLAGS=-E
        export CXXCPPFLAGS=-E
637 638
        unset AS
        unset CCAS
639

640 641 642
        if [ "$FARCH" = "all" ];then
            if [ "$TVOS" = "yes" ]; then
                if [ "$PLATFORM" = "iphonesimulator" ]; then
643
                    buildLibVLC "x86_64" "Simulator"
644
                else
645
                    buildLibVLC "aarch64" "OS"
646
                fi
647 648
            fi
            if [ "$MACOS" = "yes" ]; then
649
                buildLibVLC "x86_64" "OS"
650 651 652
            fi
            if [ "$IOS" = "yes" ]; then
                if [ "$PLATFORM" = "iphonesimulator" ]; then
653 654
                    buildLibVLC "i386" "Simulator"
                    buildLibVLC "x86_64" "Simulator"
655
                else
656 657 658
                    buildLibVLC "armv7" "OS"
                    buildLibVLC "armv7s" "OS"
                    buildLibVLC "aarch64" "OS"
659
                fi
660 661
            fi
        else
662 663 664 665 666 667 668
            if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
              -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
                echo "*** Framework ARCH: ${FARCH} is invalid ***"
                exit 1
            fi

            local buildPlatform=""
669
            if [ "$PLATFORM" = "iphonesimulator" ]; then
670 671 672
                if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
                    buildPlatform="Simulator"
                fi
673
            else
674 675 676 677 678
                if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
                    buildPlatform="OS"
                fi
            fi
            if [ ! -z "$buildPlatform" ];then
679
                buildLibVLC $FARCH $buildPlatform
680 681 682
            fi
        fi
    fi
683 684
}

685 686 687 688
doVLCLipo() {
    FILEPATH="$1"
    FILE="$2"
    PLUGIN="$3"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
689
    OSSTYLE="$4"
690 691 692 693 694 695
    files=""

    info "...$FILEPATH$FILE"

    for i in $DEVICEARCHS
    do
696 697
        actual_arch=`get_actual_arch $i`
        files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
698 699 700 701
    done

    for i in $SIMULATORARCHS
    do
702 703
        actual_arch=`get_actual_arch $i`
        files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
704 705 706
    done

    if [ "$PLUGIN" != "no" ]; then
707
        lipo $files -create -output install-$OSSTYLE/plugins/$FILE
708
    else
709
        lipo $files -create -output install-$OSSTYLE/core/$FILE
710 711 712 713 714
    fi
}

doContribLipo() {
    LIBNAME="$1"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
715
    OSSTYLE="$2"
716 717 718 719
    files=""

    info "...$LIBNAME"

720
    for i in $DEVICEARCHS $SIMULATORARCHS
721
    do
722
        files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
723 724
    done

725
    lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
726 727 728 729 730 731 732
}

get_symbol()
{
    echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
733
build_universal_static_lib() {
Thomas Guillem's avatar
Thomas Guillem committed
734 735 736 737 738 739 740 741 742 743
    PROJECT_DIR=`pwd`
    OSSTYLE="$1"
    info "building universal static libs for OS style $OSSTYLE"

    # remove old module list
    rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
    rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
    touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
    touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig

744
    if [ "$OSSTYLE" != "MacOSX" ]; then
745
        spushd ${VLCROOT}
746 747 748 749 750 751 752
        rm -rf install-$OSSTYLE
        mkdir install-$OSSTYLE
        mkdir install-$OSSTYLE/core
        mkdir install-$OSSTYLE/contrib
        mkdir install-$OSSTYLE/plugins
        spopd # vlc
    else
753
        spushd ${VLCROOT}/install-$OSSTYLE
754 755 756 757 758 759 760 761
        rm -rf core
        rm -rf contrib
        rm -rf plugins
        ln -s x86_64/lib core
        ln -s x86_64/contribs/lib contrib
        ln -s x86_64/lib/vlc/plugins plugins
        spopd # vlc
    fi
Thomas Guillem's avatar
Thomas Guillem committed
762

763 764 765 766 767
    VLCMODULES=""
    VLCNEONMODULES=""
    SIMULATORARCHS=""
    CONTRIBLIBS=""
    DEVICEARCHS=""
Thomas Guillem's avatar
Thomas Guillem committed
768 769

    # arm64 got the lowest number of modules
770 771 772
    arch="aarch64"
    if [ "$FARCH" != "all" ];then
        arch="$FARCH"
773 774
    elif [ "$BUILD_SIMULATOR" = "yes" ]; then
        arch="x86_64"
775
    fi
776

777
    actual_arch=`get_actual_arch $arch`
Thomas Guillem's avatar
Thomas Guillem committed
778

779 780
    if [ -d ${VLCROOT}/install-"$OSSTYLE"OS ];then
        spushd ${VLCROOT}/install-"$OSSTYLE"OS
781 782 783 784 785 786 787 788
        for i in `ls .`
        do
            local iarch="`get_arch $i`"
            if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
                DEVICEARCHS="$DEVICEARCHS $iarch"
            fi
        done

789 790 791 792 793 794 795 796 797
        if (! is_simulator_arch $arch);then
            echo "IPHONE OS: $arch"
            spushd $actual_arch/lib/vlc/plugins
            for i in `ls *.a`
            do
                VLCMODULES="$i $VLCMODULES"
            done
            spopd # $actual_arch/lib/vlc/plugins
        fi
798 799 800 801

        if [ "$OSSTYLE" != "AppleTV" -a \
            \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
            # collect ARMv7/s specific neon modules
802 803 804 805 806
            if [ "$FARCH" = "all" ];then
                spushd armv7/lib/vlc/plugins
            else
                spushd $FARCH/lib/vlc/plugins
            fi
807 808 809 810 811 812 813 814 815
            for i in `ls *.a | grep neon`
            do
                VLCNEONMODULES="$i $VLCNEONMODULES"
            done
            spopd # armv7/lib/vlc/plugins
        fi
        spopd # vlc-install-"$OSSTYLE"OS
    fi

816 817
    if [ -d ${VLCROOT}/install-"$OSSTYLE"Simulator ];then
        spushd ${VLCROOT}/install-"$OSSTYLE"Simulator
818
            for i in `ls .`
819
            do
820 821 822 823
                local iarch="`get_arch $i`"
                if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
                    SIMULATORARCHS="$SIMULATORARCHS $iarch"
                fi
824
            done
825 826 827 828 829 830 831 832 833

            if (is_simulator_arch $arch);then
                echo "SIMU OS: $arch"
                spushd $arch/lib/vlc/plugins
                    for i in `ls *.a`
                    do
                        VLCMODULES="$i $VLCMODULES"
                    done
                spopd # $iarch/lib/vlc/plugins
834 835
            fi
        spopd # vlc-install-"$OSSTYLE"Simulator
Thomas Guillem's avatar
Thomas Guillem committed
836 837
    fi

838
    if [ "$OSSTYLE" = "MacOSX" ]; then
839 840
        if [ -d ${VLCROOT}/install-"$OSSTYLE" ];then
            spushd ${VLCROOT}/install-"$OSSTYLE"
841 842 843 844 845 846 847 848
                echo `pwd`
                echo "macOS: $arch"
                spushd $arch/lib/vlc/plugins
                    for i in `ls *.a`
                    do
                        VLCMODULES="$i $VLCMODULES"
                    done
                spopd # $actual_arch/lib/vlc/plugins
849 850 851
            spopd # vlc-install-"$OSSTYLE"
        fi
    fi
Thomas Guillem's avatar
Thomas Guillem committed
852

853
    spushd ${VLCROOT}
854 855

    # collect contrib libraries
856
    spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
Thomas Guillem's avatar
Thomas Guillem committed
857 858 859 860
    for i in `ls *.a`
    do
        CONTRIBLIBS="$i $CONTRIBLIBS"
    done
861 862
    spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib

863 864 865 866 867 868
    # lipo all the vlc libraries and its plugins
    if [ "$OSSTYLE" != "MacOSX" ]; then
        doVLCLipo "" "libvlc.a" "no" $OSSTYLE
        doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
        doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
        for i in $VLCMODULES
Thomas Guillem's avatar
Thomas Guillem committed
869 870 871
        do
            doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
        done
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893

        # lipo contrib libraries
        for i in $CONTRIBLIBS
        do
            doContribLipo $i $OSSTYLE
        done

        if [ "$OSSTYLE" != "AppleTV" ]; then
            # lipo the remaining NEON plugins
            DEVICEARCHS=""
            for i in armv7 armv7s; do
                local iarch="`get_arch $i`"
                if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
                    DEVICEARCHS="$DEVICEARCHS $iarch"
                fi
            done
            SIMULATORARCHS=""
            for i in $VLCNEONMODULES
            do
                doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
            done
        fi
Thomas Guillem's avatar
Thomas Guillem committed
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
    fi

    # create module list
    info "creating module list"
    echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
    echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig

    # arm64 got the lowest number of modules
    BUILTINS="const void *vlc_static_modules[] = {\n"; \

    LDFLAGS=""
    DEFINITIONS=""

    # add contrib libraries to LDFLAGS
    for file in $CONTRIBLIBS
    do
910
        LDFLAGS+="${VLCROOT}/install-$OSSTYLE/contrib/$file "
Thomas Guillem's avatar
Thomas Guillem committed
911 912 913 914
    done

    for file in $VLCMODULES
    do
915
        symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
Thomas Guillem's avatar
Thomas Guillem committed
916 917 918
        entryname=$(get_symbol "$symbols" _)
        DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
        BUILTINS+=" $entryname,\n"
919
        LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
Thomas Guillem's avatar
Thomas Guillem committed
920 921 922
        info "...$entryname"
    done;

923 924
    # we only have ARM NEON modules for 32bit so this is limited to iOS
    if [ "$OSSTYLE" = "iPhone" ]; then
Thomas Guillem's avatar
Thomas Guillem committed
925 926 927 928
        BUILTINS+="#ifdef __arm__\n"
        DEFINITIONS+="#ifdef __arm__\n"
        for file in $VLCNEONMODULES
        do
929
            symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
Thomas Guillem's avatar
Thomas Guillem committed
930 931 932
            entryname=$(get_symbol "$symbols" _)
            DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
            BUILTINS+=" $entryname,\n"
933
            LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
Thomas Guillem's avatar
Thomas Guillem committed
934 935 936 937 938 939 940 941
            info "...$entryname"
        done;
        BUILTINS+="#endif\n"
        DEFINITIONS+="#endif\n"
    fi

    BUILTINS="$BUILTINS NULL\n};\n"

942 943
    echo "$DEFINITIONS\n$BUILTINS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
    echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
Thomas Guillem's avatar
Thomas Guillem committed
944 945

    spopd # vlc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
946
}
947

948
while getopts "hvwsfbdxntlk:a:e:" OPTION
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         v)
             VERBOSE=yes
             ;;
         s)
             BUILD_DEVICE=no
             BUILD_SIMULATOR=yes
             BUILD_STATIC_FRAMEWORK=no
             ;;
         f)
             BUILD_DEVICE=yes
             BUILD_SIMULATOR=yes
             BUILD_STATIC_FRAMEWORK=yes
             ;;
         d)  CONFIGURATION="Debug"
             DEBUG=yes
             ;;
         w)  SCARY="no"
             ;;
         n)
             NONETWORK=yes
             ;;
         l)
             SKIPLIBVLCCOMPILATION=yes
             ;;
         k)
             SDK=$OPTARG
             ;;
         a)
             BUILD_DEVICE=yes
             BUILD_SIMULATOR=yes
             BUILD_STATIC_FRAMEWORK=yes
             FARCH=$OPTARG
             ;;
         b)
             BITCODE=yes
             ;;
         t)
             TVOS=yes
             IOS=no
             BITCODE=yes
             SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
996
             SDK_MIN=10.2
997 998
             OSVERSIONMINCFLAG=tvos
             OSVERSIONMINLDFLAG=tvos
999 1000 1001 1002 1003 1004 1005
             ;;
         x)
             MACOS=yes
             IOS=no
             BITCODE=no
             SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
             SDK_MIN=10.9
1006 1007
             OSVERSIONMINCFLAG=macosx
             OSVERSIONMINLDFLAG=macosx
1008 1009 1010 1011 1012
             BUILD_DEVICE=yes
             FARCH=x86_64
             BUILD_DYNAMIC_FRAMEWORK=yes
             BUILD_STATIC_FRAMEWORK=no
             ;;
1013 1014 1015
         e)
             VLCROOT=$OPTARG
             ;;
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
         ?)
             usage
             exit 1
             ;;
     esac
done
shift $(($OPTIND - 1))

out="/dev/null"
if [ "$VERBOSE" = "yes" ]; then
   out="/dev/stdout"
fi

if [ "x$1" != "x" ]; then
    usage
    exit 1
fi

# Get root dir
spushd .
ROOT_DIR=`pwd`
spopd

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
if [ "$VLCROOT" = "" ]; then
    VLCROOT=${ROOT_DIR}/libvlc/vlc
    info "Preparing build dirs"

    mkdir -p libvlc
    spushd libvlc

    if [ "$NONETWORK" != "yes" ]; then
        if ! [ -e vlc ]; then
            git clone https://git.videolan.org/git/vlc/vlc-3.0.git vlc
            info "Applying patches to vlc.git"
            cd vlc
            git checkout -B localBranch ${TESTEDHASH}
            git branch --set-upstream-to=origin/master localBranch
            git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
            if [ $? -ne 0 ]; then
                git am --abort
                info "Applying the patches failed, aborting git-am"
                exit 1
            fi
            cd ..
        else
            cd vlc
1062
            git fetch --all
1063
            git reset --hard ${TESTEDHASH}
1064 1065
            git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
            cd ..
1066 1067
        fi
    fi
1068 1069

    spopd
1070 1071
fi

1072 1073 1074 1075 1076 1077 1078
# get python installation
python3Path=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
if [ ! -d "$python3Path" ]; then
    python3Path=""
fi

export PATH="$python3Path:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:${VLC_PATH}:/usr/bin:/bin:/usr/sbin:/sbin"
1079 1080

echo `pwd`
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

#
# Build time
#

out="/dev/null"
if [ "$VERBOSE" = "yes" ]; then
   out="/dev/stdout"
fi

if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
    info "Building tools"
1093
    spushd ${VLCROOT}/extras/tools
1094 1095 1096
    ./bootstrap
    make
    make .gas
1097
    spopd #${VLCROOT}/extras/tools
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
fi

if [ "$BUILD_DEVICE" != "no" ]; then
    buildMobileKit iphoneos
fi
if [ "$BUILD_SIMULATOR" != "no" ]; then
    buildMobileKit iphonesimulator
fi

DEVICEARCHS=""
SIMULATORARCHS=""

1110
if [ "$TVOS" = "yes" ]; then
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1111
    build_universal_static_lib "AppleTV"
1112 1113 1114 1115 1116 1117
fi
if [ "$MACOS" = "yes" ]; then
    build_universal_static_lib "MacOSX"
fi
if [ "$IOS" = "yes" ]; then
    build_universal_static_lib "iPhone"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1118
fi
1119 1120 1121

info "all done"

1122
if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
1123
if [ "$TVOS" = "yes" ]; then
1124 1125
    info "Building static TVVLCKit.framework"

1126
    lipo_libs=""
1127
    platform=""
Soomin Lee's avatar
Soomin Lee committed
1128
    if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
1129 1130
        platform="appletvos"
        buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
1131 1132
        lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
    fi
Soomin Lee's avatar
Soomin Lee committed
1133
    if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
1134 1135
        platform="appletvsimulator"
        buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
1136 1137
        lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
    fi
1138 1139 1140 1141 1142

    # Assumes both platforms were built currently
    spushd build
    rm -rf TVVLCKit.framework && \
    mkdir TVVLCKit.framework && \
1143
    lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
1144
    chmod a+x TVVLCKit.framework/TVVLCKit && \
1145
    cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
1146 1147 1148 1149
    spopd # build

    info "Build of static TVVLCKit.framework completed"
fi
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
if [ "$IOS" = "yes" ]; then
    info "Building static MobileVLCKit.framework"

    lipo_libs=""
    platform=""
    if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
        platform="iphoneos"
        buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
        lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
    fi
    if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
        platform="iphonesimulator"
        buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
        lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
    fi

    # Assumes both platforms were built currently
    spushd build
    rm -rf MobileVLCKit.framework && \
    mkdir MobileVLCKit.framework && \
    lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
    chmod a+x MobileVLCKit.framework/MobileVLCKit && \
    cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
    spopd # build

    info "Build of static MobileVLCKit.framework completed"
fi
1177
fi
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
if [ "$MACOS" = "yes" ]; then
    info "Building VLCKit.framework"

    buildxcodeproj VLCKit "VLCKit" "macosx"

    # remove intermediate build result we don't need to keep
    spushd build
    rm ${CONFIGURATION}/libStaticLibVLC.a
    spopd # build

    info "Build of VLCKit.framework completed"
fi
fi