bootstrap 6.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#! /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]"
24 25 26
	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
	echo "  --no-checksums      don't verify checksums (allows to replace tarballs)"
28
	echo "  --disable-downloads don't download packages from the internet"
29
	echo "  --enable-debug      build with debug symbol and extra checks (disabled by default)"
30 31
	echo "  --disable-FOO       configure to not build package FOO"
	echo "  --enable-FOO        configure to build package FOO"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
}

BUILD=
HOST=
PREFIX=
PKGS_ENABLE=
PKGS_DISABLE=

if test ! -f "../../contrib/src/main.mak"
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
			;;
56 57 58
		--no-checksums)
			DISABLE_CONTRIB_CHECKSUMS="TRUE"
			;;
59 60 61
		--disable-downloads)
			DISABLE_CONTRIB_DOWNLOADS="TRUE"
			;;
62 63 64
		--enable-debug)
			ENABLE_DEBUG=1
			;;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
		--host=*)
			HOST="${1#--host=}"
			;;
		--prefix=*)
			PREFIX="${1#--prefix=}"
			;;
		--disable-*)
			PKGS_DISABLE="${PKGS_DISABLE} ${1#--disable-}"
			;;
		--enable-*)
			PKGS_ENABLE="${PKGS_ENABLE} ${1#--enable-}"
			;;
		*)
			echo "Unrecognized options $1"
			usage
			exit 1
			;;
	esac
	shift
done

if test -z "$BUILD"
then
	echo -n "Guessing build system... "
	BUILD="`${CC:-cc} -dumpmachine`"
	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"
exec 3>config.mak || exit $?
cat >&3 << EOF
# This file was automatically generated.
# Any change will be overwritten if ../bootstrap is run again.
BUILD := $BUILD
HOST := $HOST
120
CROSS_COMPILE ?= $HOST-
121 122
PKGS_DISABLE := $PKGS_DISABLE
PKGS_ENABLE := $PKGS_ENABLE
123
DISABLE_CONTRIB_DOWNLOADS := $DISABLE_CONTRIB_DOWNLOADS
124
DISABLE_CONTRIB_CHECKSUMS := $DISABLE_CONTRIB_CHECKSUMS
125
ENABLE_DEBUG := $ENABLE_DEBUG
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
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
}

check_ios_sdk()
{
   if test -z "$SDKROOT"
   then
Edric Milaret's avatar
Edric Milaret committed
150
      SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk
151 152 153
      echo "SDKROOT not specified, assuming $SDKROOT"
   else
      SDKROOT="$SDKROOT"
Edric Milaret's avatar
Edric Milaret committed
154
   fi
155 156 157 158 159 160 161

   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}"
Edric Milaret's avatar
Edric Milaret committed
162
   add_make "IOS_TARGET_PLATFORM=${IOS_TARGET_PLATFORM}"
163 164 165 166 167 168 169 170 171 172 173 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
}

check_macosx_sdk()
{
   if [ -z "${OSX_VERSION}" ]
   then
      OSX_VERSION=`xcrun --show-sdk-version`
      echo "OSX_VERSION not specified, assuming $OSX_VERSION"
   fi
   if test -z "$SDKROOT"
   then
      SDKROOT=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
      echo "SDKROOT not specified, assuming $SDKROOT"
   fi

   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
   if [ ! -d "${SDKROOT}" ]
   then
      SDKROOT_NOT_FOUND="$SDKROOT"
      SDKROOT=`xcrun --show-sdk-path`
      echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
   fi

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

   add_make "MACOSX_SDK=${SDKROOT}"
   add_make "OSX_VERSION ?= ${OSX_VERSION}"
}

check_android_sdk()
{
	[ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
	add_make "ANDROID_NDK := ${ANDROID_NDK}"
	[ -z "${ANDROID_ABI}" ] && echo "You must set ANDROID_ABI environment variable" && exit 1
	add_make "ANDROID_ABI := ${ANDROID_ABI}"
207 208
	[ -z "${ANDROID_API}" ] && echo "You should set ANDROID_API environment variable (using default android-9)" && ANDROID_API := android-9
	add_make "ANDROID_API := ${ANDROID_API}"
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
	[ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_NEON"
	[ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_ARMV7A"
	[ ${ANDROID_ABI} = "armeabi" -a -z "${NO_ARMV6}" ] && add_make_enabled "HAVE_ARMV6"
}

test -z "$PREFIX" || add_make "PREFIX := $PREFIX"

#
# Checks
#
OS="${HOST#*-}" # strip architecture
case "${OS}" in
	apple-darwin*)
		if test -z "$BUILDFORIOS"
		then
			check_macosx_sdk
			add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
		else
			check_ios_sdk
			add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD" "HAVE_NEON" "HAVE_ARMV7A"
		fi
		;;
	*bsd*)
		add_make_enabled "HAVE_BSD"
		;;
	*android*)
		check_android_sdk
		add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
		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
		;;
	*linux*)
		add_make_enabled "HAVE_LINUX"
		;;
	*wince*)
		add_make_enabled "HAVE_WINCE"
		;;
	*mingw*)
		add_make_enabled "HAVE_WIN32"
		;;
	*solaris*)
		add_make_enabled "HAVE_SOLARIS"
		;;
esac

#
# Results output
#
test -e Makefile && unlink Makefile
ln -sf ../../contrib/src/main.mak Makefile || exit $?
cat << EOF
Bootstrap completed.

Run "make" to start compilation.

Other targets:
 * make install      same as "make"
 * make prebuilt     fetch and install prebuilt binaries
 * make list         list packages
 * 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
 * make clean        clean everything
 * make package      prepare prebuilt packages
EOF

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