bootstrap 6.89 KB
Newer Older
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#! /bin/sh
# Copyright (C) 2003-2011 the VideoLAN team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.

#
# Command line handling
#
usage()
{
	echo "Usage: $0 [--build=BUILD] [--host=HOST] [--prefix=PREFIX]"
	echo "  --build=BUILD    configure for building on BUILD"
	echo "  --host=HOST      cross-compile to build to run on HOST"
	echo "  --prefix=PREFIX  install files in PREFIX"
27 28
	echo "  --disable-FOO    configure to not build package FOO"
	echo "  --enable-FOO     configure to build package FOO"
29
	echo "  --disable-disc   configure to not build optical discs packages"
30
	echo "  --disable-net    configure to not build networking packages"
31
	echo "  --disable-sout   configure to not build stream output packages"
32
	echo "  --enable-small   optimize libraries for size with slight speed decrease [DANGEROUS]"
33
	echo "  --disable-gpl    configure to not build viral GPL code"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
34 35 36 37 38
}

BUILD=
HOST=
PREFIX=
39 40
PKGS_ENABLE=
PKGS_DISABLE=
41
BUILD_ENCODERS="1"
42
BUILD_NETWORK="1"
43
BUILD_DISCS="1"
44
GPL="1"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
45

46
if test ! -f "../../contrib/src/main.mak"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
then
	echo "$0 must be run from a subdirectory"
	exit 1
fi

while test -n "$1"
do
	case "$1" in
		--build=*)
			BUILD="${1#--build=}"
			;;
		--help|-h)
			usage
			exit 0
			;;
		--host=*)
			HOST="${1#--host=}"
			;;
		--prefix=*)
			PREFIX="${1#--prefix=}"
			;;
68 69 70
		--disable-disc)
			BUILD_DISCS=
			;;
71 72 73
		--disable-net)
			BUILD_NETWORK=
			;;
74 75 76
		--disable-sout)
			BUILD_ENCODERS=
			;;
77 78 79
		--enable-small)
			ENABLE_SMALL=1
			;;
80 81 82
		--disable-gpl)
			GPL=
			;;
83 84 85 86 87 88
		--disable-*)
			PKGS_DISABLE="${PKGS_DISABLE} ${1#--disable-}"
			;;
		--enable-*)
			PKGS_ENABLE="${PKGS_ENABLE} ${1#--enable-}"
			;;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
89 90 91 92 93 94 95 96 97 98 99 100
		*)
			echo "Unrecognized options $1"
			usage
			exit 1
			;;
	esac
	shift
done

if test -z "$BUILD"
then
	echo -n "Guessing build system... "
101
	BUILD="`${CC:-cc} -dumpmachine`"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
	if test -z "$BUILD"; then
		echo "FAIL!"
		exit 1
	fi
	echo "$BUILD"
fi

if test -z "$HOST"
then
	echo -n "Guessing host system...  "
	HOST="$BUILD"
	echo "$HOST"
fi

if test "$PREFIX"
then
	# strip trailing slash
	PREFIX="${PREFIX%/}"
fi

#
# Prepare files
#
echo "Creating configuration file... config.mak"
126
exec 3>config.mak || exit $?
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
127 128 129 130 131
cat >&3 << EOF
# This file was automatically generated.
# Any change will be overwritten if ../bootstrap is run again.
BUILD := $BUILD
HOST := $HOST
132 133
PKGS_DISABLE := $PKGS_DISABLE
PKGS_ENABLE := $PKGS_ENABLE
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
EOF

add_make()
{
	while test -n "$1"
	do
		echo "$1" >&3
		shift
	done
}

add_make_enabled()
{
	while test -n "$1"
	do
		add_make "$1 := 1"
		shift
	done
}

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
check_ios_sdk()
{
   if test -z "$SDKROOT"
   then
      SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
      echo "SDKROOT not specified, assuming $SDKROOT"
   else
      SDKROOT="$SDKROOT"
      fi

   if [ ! -d "${SDKROOT}" ]
   then
      echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
      exit 1
   fi
   add_make "IOS_SDK=${SDKROOT}"
}

172 173
check_macosx_sdk()
{
174 175 176 177 178
   if [ -z "${OSX_VERSION}" ]
   then
      OSX_VERSION=`xcrun --show-sdk-version`
      echo "OSX_VERSION not specified, assuming $OSX_VERSION"
   fi
179
   if test -z "$SDKROOT"
180
   then
181 182
      SDKROOT=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
      echo "SDKROOT not specified, assuming $SDKROOT"
183
   fi
184

185 186 187 188 189 190
   if [ ! -d "${SDKROOT}" ]
   then
      SDKROOT_NOT_FOUND=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
      SDKROOT=`xcode-select -print-path`/SDKs/MacOSX$OSX_VERSION.sdk
      echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
   fi
191 192 193 194 195 196
   if [ ! -d "${SDKROOT}" ]
   then
      SDKROOT_NOT_FOUND="$SDKROOT"
      SDKROOT=`xcrun --show-sdk-path`
      echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
   fi
197

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

204
   add_make "MACOSX_SDK=${SDKROOT}"
205 206 207
   add_make "OSX_VERSION ?= ${OSX_VERSION}"
}

208 209 210 211
check_android_sdk()
{
	[ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
	add_make "ANDROID_NDK := ${ANDROID_NDK}"
212 213
	[ -z "${ANDROID_ABI}" ] && echo "You must set ANDROID_ABI environment variable" && exit 1
	add_make "ANDROID_ABI := ${ANDROID_ABI}"
214
	[ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_NEON"
215
	[ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_ARMV7A"
216
	[ ${ANDROID_ABI} = "armeabi" -a -z "${NO_ARMV6}" ] && add_make_enabled "HAVE_ARMV6"
217 218
}

219
test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
220 221
test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
222
test -z "$BUILD_NETWORK" || add_make_enabled "BUILD_NETWORK"
223
test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
224
test -z "$GPL" || add_make_enabled "GPL"
225

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
226 227 228
#
# Checks
#
229 230
OS="${HOST#*-}" # strip architecture
case "${OS}" in
231 232 233 234 235 236
	apple-darwin*)
		if test -z "$BUILDFORIOS"
		then
			check_macosx_sdk
			add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
		else
237
			check_ios_sdk
238
			add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD" "HAVE_NEON" "HAVE_ARMV7A"
239
		fi
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
240 241 242 243
		;;
	*bsd*)
		add_make_enabled "HAVE_BSD"
		;;
244
	*android*)
245 246
		check_android_sdk
		add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
247 248 249 250 251 252 253 254 255 256 257
		case "${HOST}" in
			*arm*)
			add_make "PLATFORM_SHORT_ARCH := arm"
			;;
			*i686*)
			add_make "PLATFORM_SHORT_ARCH := x86"
			;;
			*mipsel*)
			add_make "PLATFORM_SHORT_ARCH := mips"
			;;
		esac
258
		;;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
259 260 261
	*linux*)
		add_make_enabled "HAVE_LINUX"
		;;
262 263 264
	*mingw*)
		add_make_enabled "HAVE_WIN32"
		;;
265 266 267
	*solaris*)
		add_make_enabled "HAVE_SOLARIS"
		;;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
268 269 270 271 272 273
esac

#
# Results output
#
test -e Makefile && unlink Makefile
274
ln -sf ../../contrib/src/main.mak Makefile || exit $?
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
275 276 277 278 279 280 281
cat << EOF
Bootstrap completed.

Run "make" to start compilation.

Other targets:
 * make install      same as "make"
282 283
 * make prebuilt     fetch and install prebuilt binaries
 * make list         list packages
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
284 285 286 287
 * make fetch        fetch required source tarballs
 * make fetch-all    fetch all source tarballs
 * make distclean    clean everything and undo bootstrap
 * make mostlyclean  clean everything except source tarballs
288
 * make clean        clean everything
289
 * make package      prepare prebuilt packages
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
290
EOF
291

292
mkdir -p ../../contrib/tarballs || exit $?