buildMobileVLCKit.sh 22.5 KB
Newer Older
1 2
#!/bin/sh
# Copyright (C) Pierre d'Herbemont, 2010
Felix Paul Kühne's avatar
Felix Paul Kühne committed
3
# Copyright (C) Felix Paul Kühne, 2012-2017
4 5 6

set -e

7
BUILD_DEVICE=yes
8
BUILD_SIMULATOR=yes
9
BUILD_STATIC_FRAMEWORK=no
10
SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
11
SDK_MIN=7.0
12
VERBOSE=no
13
DEBUG=no
14 15 16
CONFIGURATION="Release"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
17
SCARY=yes
Felix Paul Kühne's avatar
Felix Paul Kühne committed
18
TVOS=no
19
BITCODE=no
20 21 22
OSVERSIONMINCFLAG=miphoneos-version-min
OSVERSIONMINLDFLAG=ios_version_min
ROOT_DIR=empty
23

Felix Paul Kühne's avatar
Felix Paul Kühne committed
24
TESTEDHASH=bb538b4e
25

26 27 28
CORE_COUNT=`sysctl -n machdep.cpu.core_count`
let MAKE_JOBS=$CORE_COUNT+1

29 30 31 32 33 34 35 36 37
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
38
   -f       Build framework for device and simulator
39 40 41
   -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
42
   -t       Build for tvOS
43
   -w       Build a limited stack of non-scary libraries only
Felix Paul Kühne's avatar
Felix Paul Kühne committed
44
   -y       Build universal static libraries
45
   -b       Enable bitcode
46 47 48
EOF
}

49
while getopts "hvwsfbdntlk:" OPTION
50 51 52 53 54 55 56 57
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         v)
             VERBOSE=yes
58
             MAKE_JOBS=1
59 60
             ;;
         s)
61 62
             BUILD_DEVICE=no
             BUILD_SIMULATOR=yes
63
             BUILD_STATIC_FRAMEWORK=no
64 65
             ;;
         f)
66 67
             BUILD_DEVICE=yes
             BUILD_SIMULATOR=yes
68
             BUILD_STATIC_FRAMEWORK=yes
69 70
             ;;
         d)  CONFIGURATION="Debug"
71
             DEBUG=yes
72
             ;;
73 74
         w)  SCARY="no"
             ;;
75 76 77 78 79 80 81 82 83
         n)
             NONETWORK=yes
             ;;
         l)
             SKIPLIBVLCCOMPILATION=yes
             ;;
         k)
             SDK=$OPTARG
             ;;
84 85 86
         b)
             BITCODE=yes
             ;;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
87 88
         t)
             TVOS=yes
89
             BITCODE=yes
90
             SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
91
             SDK_MIN=9.0
92 93
             OSVERSIONMINCFLAG=mtvos-version-min
             OSVERSIONMINLDFLAG=tvos_version_min
Felix Paul Kühne's avatar
Felix Paul Kühne committed
94
             ;;
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
         ?)
             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

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
spushd()
{
     pushd "$1" 2>&1> /dev/null
}

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

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

buildxcodeproj()
{
    local target="$2"
    local PLATFORM="$3"

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

    local architectures=""
    if [ "$TVOS" != "yes" ]; then
        if [ "$PLATFORM" = "iphonesimulator" ]; then
            architectures="i386 x86_64"
        else
            architectures="armv7 armv7s arm64"
        fi
    else
        if [ "$PLATFORM" = "appletvsimulator" ]; then
            architectures="x86_64"
        else
            architectures="arm64"
        fi
    fi

152 153 154 155 156
    local bitcodeflag=""
    if [ "$BITCODE" = "yes" ]; then
        bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
    fi

157 158 159 160 161 162 163 164 165 166 167
    local defs="$GCC_PREPROCESSOR_DEFINITIONS"
    if [ "$SCARY" = "no" ]; then
        defs="$defs NOSCARYCODECS"
    fi
    xcodebuild -project "$1.xcodeproj" \
               -target "$target" \
               -sdk $PLATFORM$SDK \
               -configuration ${CONFIGURATION} \
               ARCHS="${architectures}" \
               IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
               GCC_PREPROCESSOR_DEFINITIONS="$defs" \
168
               ${bitcodeflag} \
169 170 171
               > ${out}
}

172 173
# Get root dir
spushd .
174
ROOT_DIR=`pwd`
175 176 177 178
spopd

info "Preparing build dirs"

179 180 181
mkdir -p libvlc

spushd libvlc
182

183
echo `pwd`
184 185 186

if [ "$NONETWORK" != "yes" ]; then
if ! [ -e vlc ]; then
187
git clone git://git.videolan.org/vlc.git vlc
188
info "Applying patches to vlc.git"
189
cd vlc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
190 191
git checkout -B localBranch ${TESTEDHASH}
git branch --set-upstream-to=origin/master localBranch
192
git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
193 194 195 196 197 198 199 200
if [ $? -ne 0 ]; then
git am --abort
info "Applying the patches failed, aborting git-am"
exit 1
fi
cd ..
else
cd vlc
201
git pull --rebase
Rafaël Carré's avatar
Rafaël Carré committed
202
git reset --hard ${TESTEDHASH}
203
git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
204 205 206 207 208 209 210 211 212 213
cd ..
fi
fi

spopd

#
# Build time
#

214 215 216 217
out="/dev/null"
if [ "$VERBOSE" = "yes" ]; then
   out="/dev/stdout"
fi
218

219 220 221 222 223 224 225 226
if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
    info "Building tools"
    spushd ${ROOT_DIR}/libvlc/vlc/extras/tools
    ./bootstrap
    make
    make .gas
    spopd #libvlc/vlc/extras/tools
fi
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
buildLibVLC() {
    VERBOSE="$1"
    DEBUG="$2"
    SCARY="$3"
    BITCODE="$4"
    ARCH="$5"
    TVOS="$6"
    SDK_VERSION="$7"
    PLATFORM="$8"
    OSSTYLE=iPhone
    VLCROOT=${ROOT_DIR}/libvlc/vlc

    if [ "$DEBUG" = "yes" ]; then
        OPTIM="-O0 -g"
    else
        OPTIM="-O3 -g"
244
    fi
245 246 247

    if [ "$TVOS" = "yes" ]; then
        OSSTYLE=AppleTV
248
    fi
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

    if [ "$ARCH" = "aarch64" ]; then
        ACTUAL_ARCH="arm64"
    else
        ACTUAL_ARCH="$ARCH"
    fi

    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
264
    fi
265 266 267 268 269 270

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

    # clean the environment
Thomas Guillem's avatar
Thomas Guillem committed
271
    export PATH="${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${PATH}"
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    export CFLAGS=""
    export CPPFLAGS=""
    export CXXFLAGS=""
    export OBJCFLAGS=""
    export LDFLAGS=""

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

    CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
    OBJCFLAGS="${OPTIM}"

    if [ "$PLATFORM" = "OS" ]; then
    if [ "$ARCH" != "aarch64" ]; then
    CFLAGS+=" -mcpu=cortex-a8 -${OSVERSIONMINCFLAG}=${SDK_MIN}"
    else
    CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
    fi
    else
    CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
    fi

295
    if [ "$BITCODE" = "yes" ]; then
296
    CFLAGS+=" -fembed-bitcode"
297
    fi
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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
    export CFLAGS="${CFLAGS}"
    export CXXFLAGS="${CFLAGS}"
    export CPPFLAGS="${CFLAGS}"
    export OBJCFLAGS="${OBJCFLAGS}"

    if [ "$PLATFORM" = "Simulator" ]; then
        # Use the new ABI on simulator, else we can't build
        export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
    fi

    export LDFLAGS="-isysroot ${SDKROOT} -L${SDKROOT}/usr/lib -arch ${ACTUAL_ARCH}"

    if [ "$PLATFORM" = "OS" ]; then
        EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
        EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
    if [ "$ARCH" != "aarch64" ]; then
        EXTRA_CFLAGS+=" -mcpu=cortex-a8"
        EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
        EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
        export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
    else
        EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
        EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
        export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
    fi
    else
        EXTRA_CFLAGS="-arch ${ARCH}"
        EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
        EXTRA_LDFLAGS=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
        export LDFLAGS="${LDFLAGS} -v -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
    fi

    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
        TVOSOPTIONS="--disable-libarchive"
    else
        TVOSOPTIONS=""
    fi

Thomas Guillem's avatar
Thomas Guillem committed
355 356 357 358 359
    if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
        BUILD=""
    else
        BUILD="--build=x86_64-apple-darwin14"
    fi
360 361 362 363 364 365 366 367 368 369 370 371 372

    # 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

Thomas Guillem's avatar
Thomas Guillem committed
373
    ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
        --disable-disc --disable-sout \
        --disable-sdl \
        --disable-SDL_image \
        --disable-iconv \
        --enable-zvbi \
        --disable-kate \
        --disable-caca \
        --disable-gettext \
        --disable-mpcdec \
        --disable-upnp \
        --disable-gme \
        --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-protobuf \
        --disable-aribb24 \
        --disable-aribb25 \
        --enable-vpx \
        --enable-libdsm \
        ${TVOSOPTIONS} \
        --enable-taglib > ${out}

    echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
    echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
    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"
    else
        DEBUGFLAG="--disable-debug"
    fi

    if [ "$SCARY" = "yes" ]; then
        SCARYFLAG="--enable-dvbpsi --enable-avcodec --disable-vpx"
    else
        SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
439
    fi
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 482 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 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
    if [ "$TVOS" = "yes" ]; then
        TVOSOPTIONS="--disable-neon"
    else
        TVOSOPTIONS="--enable-neon"
    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} \
        ${TVOSOPTIONS} \
        --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 \
        --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
    dummy
    invert
    sepia
    wave
    hqdn3d
    headphone_channel_mixer
    gaussianblur
    gradfun
    extract
    colorthres
    antiflicker
    anaglyph
    remap
    oldmovie
    vhs
    demuxdump
    fingerprinter
    output_udp
    output_http
    output_livehttp
    libmux
    stream_out
    "

    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"

    if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
        if [ "$TVOS" = "yes" ]; then
            export BUILDFORTVOS="yes"
            info "Building libvlc for tvOS"
        else
            info "Building libvlc for iOS"
        fi
        export BUILDFORIOS="yes"

Thomas Guillem's avatar
Thomas Guillem committed
641 642 643 644 645 646 647 648 649
        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
650 651
        unset AS
        unset CCAS
652 653 654 655 656 657 658 659 660

        if [ "$TVOS" = "yes" ]; then
            if [ "$PLATFORM" = "iphonesimulator" ]; then
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
            else
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
            fi
        else
            if [ "$PLATFORM" = "iphonesimulator" ]; then
661 662
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "i386" $TVOS $SDK_VERSION "Simulator"
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
663
            else
664 665 666
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7" $TVOS $SDK_VERSION "OS"
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7s" $TVOS $SDK_VERSION "OS"
                buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
667 668 669
            fi
        fi
    fi
670 671
}

672
if [ "$BUILD_DEVICE" != "no" ]; then
673 674
    buildMobileKit iphoneos
fi
675
if [ "$BUILD_SIMULATOR" != "no" ]; then
676 677
    buildMobileKit iphonesimulator
fi
678 679 680 681 682 683 684 685

DEVICEARCHS=""
SIMULATORARCHS=""

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

    info "...$FILEPATH$FILE"

    for i in $DEVICEARCHS
    do
693
        files="install-"$OSSTYLE"OS/$i/lib/$FILEPATH$FILE $files"
694 695 696 697
    done

    for i in $SIMULATORARCHS
    do
698
        files="install-"$OSSTYLE"Simulator/$i/lib/$FILEPATH$FILE $files"
699 700 701
    done

    if [ "$PLUGIN" != "no" ]; then
702
        lipo $files -create -output install-$OSSTYLE/plugins/$FILE
703
    else
704
        lipo $files -create -output install-$OSSTYLE/core/$FILE
705 706 707 708 709
    fi
}

doContribLipo() {
    LIBNAME="$1"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
710
    OSSTYLE="$2"
711 712 713 714 715 716 717
    files=""

    info "...$LIBNAME"

    for i in $DEVICEARCHS
    do
        if [ "$i" != "arm64" ]; then
718
            files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
719
        else
720
            files="contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib/$LIBNAME $files"
721 722 723 724 725
        fi
    done

    for i in $SIMULATORARCHS
    do
726
        files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
727 728
    done

729
    lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
730 731 732 733 734 735 736
}

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
737 738 739 740 741 742
build_universal_static_lib() {
	PROJECT_DIR=`pwd`
	OSSTYLE="$1"
	info "building universal static libs for OS style $OSSTYLE"

	# remove old module list
743 744 745 746
	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
Felix Paul Kühne's avatar
Felix Paul Kühne committed
747

748 749 750 751 752 753
	spushd libvlc/vlc
	rm -rf install-$OSSTYLE
	mkdir install-$OSSTYLE
	mkdir install-$OSSTYLE/core
	mkdir install-$OSSTYLE/contrib
	mkdir install-$OSSTYLE/plugins
Felix Paul Kühne's avatar
Felix Paul Kühne committed
754 755
	spopd # vlc

756
	spushd libvlc/vlc/install-"$OSSTYLE"OS
Felix Paul Kühne's avatar
Felix Paul Kühne committed
757 758 759 760
	for i in `ls .`
	do
		DEVICEARCHS="$DEVICEARCHS $i"
	done
761
	spopd # vlc-install-"$OSSTYLE"OS
Felix Paul Kühne's avatar
Felix Paul Kühne committed
762

763
	spushd libvlc/vlc/install-"$OSSTYLE"Simulator
Felix Paul Kühne's avatar
Felix Paul Kühne committed
764 765 766 767
	for i in `ls .`
	do
		SIMULATORARCHS="$SIMULATORARCHS $i"
	done
768
	spopd # vlc-install-"$OSSTYLE"Simulator
Felix Paul Kühne's avatar
Felix Paul Kühne committed
769 770 771

	# arm64 got the lowest number of modules
	VLCMODULES=""
772
	spushd libvlc/vlc/install-"$OSSTYLE"OS/arm64/lib/vlc/plugins
Felix Paul Kühne's avatar
Felix Paul Kühne committed
773 774 775 776
	for i in `ls *.a`
	do
		VLCMODULES="$i $VLCMODULES"
	done
777
	spopd # vlc/install-"$OSSTYLE"OS/arm64/lib/vlc/plugins
Felix Paul Kühne's avatar
Felix Paul Kühne committed
778 779 780 781

	if [ "$OSSTYLE" != "AppleTV" ]; then
		# collect ARMv7/s specific neon modules
		VLCNEONMODULES=""
782
		spushd libvlc/vlc/install-"$OSSTYLE"OS/armv7/lib/vlc/plugins
Felix Paul Kühne's avatar
Felix Paul Kühne committed
783 784 785 786
		for i in `ls *.a | grep neon`
		do
			VLCNEONMODULES="$i $VLCNEONMODULES"
		done
787
		spopd # vlc/install-"$OSSTYLE"OS/armv7/lib/vlc/plugins
Felix Paul Kühne's avatar
Felix Paul Kühne committed
788 789
	fi

790
	spushd libvlc/vlc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
791 792 793 794 795 796 797 798 799 800 801 802

	# lipo all the vlc libraries and its plugins
	doVLCLipo "" "libvlc.a" "no" $OSSTYLE
	doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
	doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
	for i in $VLCMODULES
	do
		doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
	done

	# lipo contrib libraries
	CONTRIBLIBS=""
803
	spushd contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib
Felix Paul Kühne's avatar
Felix Paul Kühne committed
804 805 806 807
	for i in `ls *.a`
	do
		CONTRIBLIBS="$i $CONTRIBLIBS"
	done
808
	spopd # contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib
Felix Paul Kühne's avatar
Felix Paul Kühne committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
	for i in $CONTRIBLIBS
	do
		doContribLipo $i $OSSTYLE
	done

	if [ "$OSSTYLE" != "AppleTV" ]; then
		# lipo the remaining NEON plugins
		DEVICEARCHS="armv7 armv7s"
		SIMULATORARCHS=""
		for i in $VLCNEONMODULES
		do
			doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
		done
	fi

	# create module list
	info "creating module list"
826 827
	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
Felix Paul Kühne's avatar
Felix Paul Kühne committed
828 829 830 831 832 833 834 835 836 837

	# 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
838
		LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/contrib/$file "
Felix Paul Kühne's avatar
Felix Paul Kühne committed
839 840 841 842
	done

	for file in $VLCMODULES
	do
843
		symbols=$(nm -g -arch arm64 install-$OSSTYLE/plugins/$file)
Felix Paul Kühne's avatar
Felix Paul Kühne committed
844 845 846
		entryname=$(get_symbol "$symbols" _)
		DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
		BUILTINS+=" $entryname,\n"
847
		LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
Felix Paul Kühne's avatar
Felix Paul Kühne committed
848 849 850 851 852 853 854 855
		info "...$entryname"
	done;

	if [ "$OSSTYLE" != "AppleTV" ]; then
		BUILTINS+="#ifdef __arm__\n"
		DEFINITIONS+="#ifdef __arm__\n"
		for file in $VLCNEONMODULES
		do
856
			symbols=$(nm -g -arch armv7 install-$OSSTYLE/plugins/$file)
Felix Paul Kühne's avatar
Felix Paul Kühne committed
857 858 859
			entryname=$(get_symbol "$symbols" _)
			DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
			BUILTINS+=" $entryname,\n"
860
			LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
Felix Paul Kühne's avatar
Felix Paul Kühne committed
861 862 863 864 865 866 867 868
			info "...$entryname"
		done;
		BUILTINS+="#endif\n"
		DEFINITIONS+="#endif\n"
	fi

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

869 870
	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
Felix Paul Kühne's avatar
Felix Paul Kühne committed
871 872 873

	spopd # vlc
}
874

Felix Paul Kühne's avatar
Felix Paul Kühne committed
875 876 877 878 879
if [ "$TVOS" != "yes" ]; then
    build_universal_static_lib "iPhone"
else
    build_universal_static_lib "AppleTV"
fi
880 881 882

info "all done"

883
if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
884
if [ "$TVOS" != "yes" ]; then
885 886 887 888
    info "Building static MobileVLCKit.framework"

    buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
    buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
889 890 891 892 893

    # Assumes both platforms were built currently
    spushd build
    rm -rf MobileVLCKit.framework && \
    mkdir MobileVLCKit.framework && \
894 895
    lipo -create ${CONFIGURATION}-iphoneos/libMobileVLCKit.a \
                 ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a \
896 897
              -o MobileVLCKit.framework/MobileVLCKit && \
    chmod a+x MobileVLCKit.framework/MobileVLCKit && \
898
    cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
899 900
    spopd # build

901
    info "Build of static MobileVLCKit.framework completed"
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
else
    info "Building static TVVLCKit.framework"

    buildxcodeproj MobileVLCKit "TVVLCKit" appletvos
    buildxcodeproj MobileVLCKit "TVVLCKit" appletvsimulator

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

    info "Build of static TVVLCKit.framework completed"
fi
921
fi