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

set -e

7
BUILD_DEVICE=yes
8
BUILD_SIMULATOR=yes
9
BUILD_STATIC_FRAMEWORK=no
10
SDK=`xcrun --sdk iphoneos --show-sdk-version`
11
SDK_MIN=7.0
12 13 14 15
VERBOSE=no
CONFIGURATION="Release"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
16
SCARY=yes
Felix Paul Kühne's avatar
Felix Paul Kühne committed
17
TVOS=no
18
BITCODE=no
19

Felix Paul Kühne's avatar
Felix Paul Kühne committed
20
TESTEDHASH=41d21a66
21 22 23 24 25 26 27 28 29 30

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

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"
62 63 64
    local PLATFORM="$3"

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

66
    local architectures=""
67 68 69 70 71 72
    if [ "$TVOS" != "yes" ]; then
        if [ "$PLATFORM" = "iphonesimulator" ]; then
            architectures="i386 x86_64"
        else
            architectures="armv7 armv7s arm64"
        fi
73
    else
74 75 76 77 78
        if [ "$PLATFORM" = "appletvsimulator" ]; then
            architectures="x86_64"
        else
            architectures="arm64"
        fi
79
    fi
80

81 82 83 84
    local defs="$GCC_PREPROCESSOR_DEFINITIONS"
    if [ "$SCARY" = "no" ]; then
        defs="$defs NOSCARYCODECS"
    fi
85 86 87
    xcodebuild -project "$1.xcodeproj" \
               -target "$target" \
               -sdk $PLATFORM$SDK \
88
               -configuration ${CONFIGURATION} \
89
               ARCHS="${architectures}" \
90 91 92
               IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
               GCC_PREPROCESSOR_DEFINITIONS="$defs" \
               > ${out}
93 94
}

95
while getopts "hvwsfbdntlk:" OPTION
96 97 98 99 100 101 102 103 104 105
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         v)
             VERBOSE=yes
             ;;
         s)
106 107
             BUILD_DEVICE=no
             BUILD_SIMULATOR=yes
108
             BUILD_STATIC_FRAMEWORK=no
109 110
             ;;
         f)
111 112
             BUILD_DEVICE=yes
             BUILD_SIMULATOR=yes
113
             BUILD_STATIC_FRAMEWORK=yes
114 115 116
             ;;
         d)  CONFIGURATION="Debug"
             ;;
117 118
         w)  SCARY="no"
             ;;
119 120 121 122 123 124 125 126 127
         n)
             NONETWORK=yes
             ;;
         l)
             SKIPLIBVLCCOMPILATION=yes
             ;;
         k)
             SDK=$OPTARG
             ;;
128 129 130
         b)
             BITCODE=yes
             ;;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
131 132
         t)
             TVOS=yes
133
             BITCODE=yes
Felix Paul Kühne's avatar
Felix Paul Kühne committed
134
             SDK=`xcrun --sdk appletvos --show-sdk-version`
135
             SDK_MIN=9.0
Felix Paul Kühne's avatar
Felix Paul Kühne committed
136
             ;;
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
         ?)
             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 .
aspen_root_dir=`pwd`
spopd

info "Preparing build dirs"

mkdir -p MobileVLCKit/ImportedSources

spushd MobileVLCKit/ImportedSources

if [ "$NONETWORK" != "yes" ]; then
if ! [ -e vlc ]; then
168
git clone git://git.videolan.org/vlc.git vlc
169
info "Applying patches to vlc.git"
170
cd vlc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
171 172
git checkout -B localBranch ${TESTEDHASH}
git branch --set-upstream-to=origin/master localBranch
173 174 175 176 177 178 179 180 181
git am ../../patches/*.patch
if [ $? -ne 0 ]; then
git am --abort
info "Applying the patches failed, aborting git-am"
exit 1
fi
cd ..
else
cd vlc
182
git pull --rebase
Rafaël Carré's avatar
Rafaël Carré committed
183
git reset --hard ${TESTEDHASH}
184
git am ../../patches/*.patch
185 186 187 188 189 190 191 192 193 194
cd ..
fi
fi

spopd

#
# Build time
#

195 196
buildMobileKit() {
    PLATFORM="$1"
197

198
    spushd MobileVLCKit/ImportedSources
199

200 201 202 203 204 205 206
    if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
    spushd vlc/extras/package/ios
    info "Building vlc"
    args=""
    if [ "$VERBOSE" = "yes" ]; then
        args="${args} -v"
    fi
207 208 209
    if [ "$CONFIGURATION" = "Debug" ]; then
        args="${args} -d"
    fi
210 211 212
    if [ "$SCARY" = "no" ]; then
        args="${args} -w"
    fi
213 214 215
    if [ "$BITCODE" = "yes" ]; then
        args="${args} -b"
    fi
Felix Paul Kühne's avatar
Felix Paul Kühne committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    if [ "$TVOS" = "no" ]; then
		if [ "$PLATFORM" = "iphonesimulator" ]; then
			args="${args} -s"
			./build.sh -a i386 ${args} -k "${SDK}" && ./build.sh -a x86_64 ${args} -k "${SDK}"
		else
			./build.sh -a armv7 ${args} -k "${SDK}" && ./build.sh -a armv7s ${args} -k "${SDK}" && ./build.sh -a aarch64 ${args} -k "${SDK}"
		fi
	else
		if [ "$PLATFORM" = "iphonesimulator" ]; then
			args="${args} -s"
			./build.sh -a x86_64 -t ${args} -k "${SDK}"
		else
			./build.sh -a aarch64 -t ${args} -k "${SDK}"
		fi
	fi
231

232 233
    spopd
    fi
234

235 236 237
    spopd # MobileVLCKit/ImportedSources
}

238
if [ "$BUILD_DEVICE" != "no" ]; then
239 240
    buildMobileKit iphoneos
fi
241
if [ "$BUILD_SIMULATOR" != "no" ]; then
242 243
    buildMobileKit iphonesimulator
fi
244 245 246 247 248 249 250 251

DEVICEARCHS=""
SIMULATORARCHS=""

doVLCLipo() {
    FILEPATH="$1"
    FILE="$2"
    PLUGIN="$3"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
252
    OSSTYLE="$4"
253 254 255 256 257 258
    files=""

    info "...$FILEPATH$FILE"

    for i in $DEVICEARCHS
    do
Felix Paul Kühne's avatar
Felix Paul Kühne committed
259
        files="install-ios-"$OSSTYLE"OS/$i/lib/$FILEPATH$FILE $files"
260 261 262 263
    done

    for i in $SIMULATORARCHS
    do
Felix Paul Kühne's avatar
Felix Paul Kühne committed
264
        files="install-ios-"$OSSTYLE"Simulator/$i/lib/$FILEPATH$FILE $files"
265 266 267
    done

    if [ "$PLUGIN" != "no" ]; then
Felix Paul Kühne's avatar
Felix Paul Kühne committed
268
        lipo $files -create -output install-ios-$OSSTYLE/plugins/$FILE
269
    else
Felix Paul Kühne's avatar
Felix Paul Kühne committed
270
        lipo $files -create -output install-ios-$OSSTYLE/core/$FILE
271 272 273 274 275
    fi
}

doContribLipo() {
    LIBNAME="$1"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
276
    OSSTYLE="$2"
277 278 279 280 281 282 283
    files=""

    info "...$LIBNAME"

    for i in $DEVICEARCHS
    do
        if [ "$i" != "arm64" ]; then
284
            files="contrib/$OSSTYLE-$i-apple-darwin15-$i/lib/$LIBNAME $files"
285
        else
286
            files="contrib/$OSSTYLE-aarch64-apple-darwin15-aarch64/lib/$LIBNAME $files"
287 288 289 290 291
        fi
    done

    for i in $SIMULATORARCHS
    do
292
        files="contrib/$OSSTYLE-$i-apple-darwin15-$i/lib/$LIBNAME $files"
293 294
    done

Felix Paul Kühne's avatar
Felix Paul Kühne committed
295
    lipo $files -create -output install-ios-$OSSTYLE/contrib/$LIBNAME
296 297 298 299 300 301 302
}

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
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 355 356 357 358 359 360 361 362 363 364 365 366 367 368
build_universal_static_lib() {
	PROJECT_DIR=`pwd`
	OSSTYLE="$1"
	info "building universal static libs for OS style $OSSTYLE"

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

	spushd MobileVLCKit/ImportedSources/vlc
	rm -rf install-ios-$OSSTYLE
	mkdir install-ios-$OSSTYLE
	mkdir install-ios-$OSSTYLE/core
	mkdir install-ios-$OSSTYLE/contrib
	mkdir install-ios-$OSSTYLE/plugins
	spopd # vlc

	spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS
	for i in `ls .`
	do
		DEVICEARCHS="$DEVICEARCHS $i"
	done
	spopd # vlc-install-ios-"$OSSTYLE"OS

	spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"Simulator
	for i in `ls .`
	do
		SIMULATORARCHS="$SIMULATORARCHS $i"
	done
	spopd # vlc-install-ios-"$OSSTYLE"Simulator

	# arm64 got the lowest number of modules
	VLCMODULES=""
	spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins
	for i in `ls *.a`
	do
		VLCMODULES="$i $VLCMODULES"
	done
	spopd # vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins

	if [ "$OSSTYLE" != "AppleTV" ]; then
		# collect ARMv7/s specific neon modules
		VLCNEONMODULES=""
		spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
		for i in `ls *.a | grep neon`
		do
			VLCNEONMODULES="$i $VLCNEONMODULES"
		done
		spopd # vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
	fi

	spushd MobileVLCKit/ImportedSources/vlc

	# 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=""
369
	spushd contrib/$OSSTYLE-aarch64-apple-darwin15-aarch64/lib
Felix Paul Kühne's avatar
Felix Paul Kühne committed
370 371 372 373
	for i in `ls *.a`
	do
		CONTRIBLIBS="$i $CONTRIBLIBS"
	done
374
	spopd # contrib/$OSSTYLE-aarch64-apple-darwin15-aarch64/lib
Felix Paul Kühne's avatar
Felix Paul Kühne committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
	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"
392 393
	echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
	echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
Felix Paul Kühne's avatar
Felix Paul Kühne committed
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

	# 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
		LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/contrib/$file "
	done

	for file in $VLCMODULES
	do
		symbols=$(nm -g -arch arm64 install-ios-$OSSTYLE/plugins/$file)
		entryname=$(get_symbol "$symbols" _)
		DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
		BUILTINS+=" $entryname,\n"
		LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
		info "...$entryname"
	done;

	if [ "$OSSTYLE" != "AppleTV" ]; then
		BUILTINS+="#ifdef __arm__\n"
		DEFINITIONS+="#ifdef __arm__\n"
		for file in $VLCNEONMODULES
		do
			symbols=$(nm -g -arch armv7 install-ios-$OSSTYLE/plugins/$file)
			entryname=$(get_symbol "$symbols" _)
			DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
			BUILTINS+=" $entryname,\n"
			LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
			info "...$entryname"
		done;
		BUILTINS+="#endif\n"
		DEFINITIONS+="#endif\n"
	fi

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

435 436
	echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
	echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
Felix Paul Kühne's avatar
Felix Paul Kühne committed
437 438 439

	spopd # vlc
}
440

Felix Paul Kühne's avatar
Felix Paul Kühne committed
441 442 443 444 445
if [ "$TVOS" != "yes" ]; then
    build_universal_static_lib "iPhone"
else
    build_universal_static_lib "AppleTV"
fi
446 447 448

info "all done"

449
if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
450
if [ "$TVOS" != "yes" ]; then
451 452 453 454
    info "Building static MobileVLCKit.framework"

    buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
    buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
455 456 457 458 459

    # Assumes both platforms were built currently
    spushd build
    rm -rf MobileVLCKit.framework && \
    mkdir MobileVLCKit.framework && \
460 461
    lipo -create ${CONFIGURATION}-iphoneos/libMobileVLCKit.a \
                 ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a \
462 463
              -o MobileVLCKit.framework/MobileVLCKit && \
    chmod a+x MobileVLCKit.framework/MobileVLCKit && \
464
    cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
465 466
    spopd # build

467
    info "Build of static MobileVLCKit.framework completed"
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
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
487
fi