bootstrap 15 KB
Newer Older
1 2 3 4
#!/bin/sh
# ***************************************************************************
# bootstrap : Set up config.mak
# ***************************************************************************
Felix Kühne's avatar
Felix Kühne committed
5
# Copyright (C) 2003-2009 the VideoLAN team
6
# $Id$
7 8
#
# Authors: Christophe Massiot <massiot@via.ecp.fr>
9
#          Derk-Jan Hartman <hartman at videolan dot org>
Felix Kühne's avatar
Felix Kühne committed
10
#          Felix Paul Kühne <fkuehne at videolan dot org>
11 12 13 14 15 16 17 18 19 20 21 22 23
#
# 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
Antoine Cellerier's avatar
Antoine Cellerier committed
24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 26
# ***************************************************************************

27 28 29 30 31 32
cat >&2 << EOF
WARNING: This method of building third party libraries has been deprecated,
         and is not supported anymore.

Building from the /contrib folder is recommended instead of /extras/contrib.
EOF
33

34 35 36
LANG=C
export LANG
set -e
37
set +x
38

Pierre's avatar
Pierre committed
39 40 41
usage()
{
cat << EOF
42
usage: $0 [-t target] [-d distro] [-b buildir] [-i installdir]
Pierre's avatar
Pierre committed
43 44

OPTIONS:
45 46 47 48 49
   -t target     Force target to "target"
   -d distro     Force distro to "distro"
   -b buildir    Set build dir to "builddir"
   -i installdir Install to "installdir"
   -h            Show some help
Pierre's avatar
Pierre committed
50 51 52
EOF
}

53 54 55 56 57
add_makefile_cfg()
{
    echo $1 >> "${config_mak}"
}

58 59 60 61 62
add_enabled_makefile_cfg()
{
    echo "$1=1" >> "${config_mak}"
}

63 64 65 66 67 68 69 70 71 72 73
error()
{
    echo "[contrib] ERROR: $1"
}

info()
{
    echo "[contrib] $1"
}

DISTRO=
74 75 76 77 78 79 80

hint_distro()
{
    # Give a hint about the auto detected distro
    if test -z "${DISTRO}"; then DISTRO="$1"; fi
}

81 82
BUILDDIR=.

83
while getopts "ht:d:b:i:" OPTION
Pierre's avatar
Pierre committed
84 85 86 87 88 89 90 91 92 93 94 95
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         t)
             TARGET=$OPTARG
             ;;
         d)
             DISTRO=$OPTARG
             ;;
96 97 98 99 100 101
         b)
             BUILDDIR=$OPTARG
             ;;
         i)
             PREFIX=$OPTARG
             ;;
Pierre's avatar
Pierre committed
102 103
         ?)
             usage
104
             exit 1
Pierre's avatar
Pierre committed
105 106 107
             ;;
     esac
done
108 109 110
shift $(($OPTIND - 1))

if [ "x$1" != "x" ]; then
111 112 113 114
    error "Fallback to old command line switch, use the -t option now"
    TARGET="$1"
fi
if [ "x$2" != "x" ]; then
115 116 117
    usage
    exit 1
fi
Pierre's avatar
Pierre committed
118

119
BUILD=`gcc -dumpmachine`
120

Pierre's avatar
Pierre committed
121
if test "x$TARGET" = "x"; then
122
    TARGET="$BUILD"
123 124 125 126 127 128
    info "No target specified, using '$TARGET'"
fi

if test "x$PREFIX" = "x"; then
    PREFIX="`pwd`/hosts/$TARGET"
    info "No install dir specified, using '$PREFIX'"
129 130
fi

131 132 133
# Make sure prefix is absolute and existing
mkdir -p "${PREFIX}"
PREFIX=`cd "${PREFIX}" && pwd`
134
mkdir -p "${PREFIX}/share/aclocal" # aclocal needs this dir to exist
135 136 137 138 139 140 141 142 143 144 145 146 147

#
# Set up build dir
#

mkdir -p "${BUILDDIR}"

# Install build dir makefile
ln -sf "`pwd`/contrib.mak" "${BUILDDIR}/Makefile"

# Create the 'build-src' folder to build from source
mkdir -p "${BUILDDIR}/build-src"
ln -sf "`pwd`/src/contrib-src.mak" "${BUILDDIR}/build-src/Makefile"
148 149
ln -sf "`pwd`/src/packages.mak" "${BUILDDIR}/build-src/"
ln -sf "`pwd`/src/Patches" "${BUILDDIR}/build-src/"
150 151

# Create config.mak
152 153
config_mak="${BUILDDIR}/config.mak"
rm -f "${config_mak}"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
154
{
155 156
    echo "# Automatically generated by bootstrap."
    echo "# Make changes if you know what you're doing."
157
} > "${config_mak}"
158

159
if test "$TARGET" != "$BUILD"; then
160 161 162 163 164 165
    test -z "$CC"    && CC="${TARGET}-gcc"
    test -z "$CXX"   && CXX="${TARGET}-g++"
    test -z "$LD"    && LD="${TARGET}-ld"
    test -z "$RANLIB"&& RANLIB="${TARGET}-ranlib"
    test -z "$AR"    && AR="${TARGET}-ar"
    test -z "$STRIP" && STRIP="${TARGET}-strip"
166 167
fi

168
case $TARGET in
169
    *powerpc*|*ppc*)
170
         ARCH="ppc"
171
     ;;
172
    *86_64*)
173
          ARCH="x86_64"
174
     ;;
175
    *86*)
176
          ARCH="i386"
177
     ;;
178 179 180
    arm*eabi)
          ARCH="armel"
     ;;
Pierre's avatar
Pierre committed
181 182 183
    arm*)
          ARCH="arm"
     ;;
184
esac
185
add_makefile_cfg "ARCH = $ARCH"
186

187
# Check the HAVE_{OS}
188
case $TARGET in
189
    *darwin*)
190 191
        add_enabled_makefile_cfg "HAVE_DARWIN_OS"
        add_enabled_makefile_cfg "HAVE_BSD"
192 193
    ;;
    *linux*)
194
        add_enabled_makefile_cfg "HAVE_LINUX"
195 196
    ;;
    *bsd*)
197
        add_enabled_makefile_cfg "HAVE_BSD"
198 199
    ;;
    *wince*)
200
        add_enabled_makefile_cfg "HAVE_WINCE"
201
    ;;
Pankaj Yadav's avatar
Pankaj Yadav committed
202 203 204
    *symbian*)
        add_enabled_makefile_cfg "HAVE_SYMBIAN"
    ;;
205 206
esac

207
# Figure out the correct distro to use
208 209 210 211
case $TARGET in
    ppc-darwin|*-apple-darwin8)
        error "Your version of Mac OS X is too old!"
        error "Compiling and running VLC requires 10.5.x or later"
212
        exit 1
213
    ;;
214
    powerpc-apple-darwin9)
215
        hint_distro macosx32
216
        HAVE_DARWIN_32=1
217

218
        CFLAGS_TUNING=" -arch ppc -mtune=G4"
219
        EXTRA_LDFLAGS=" -arch ppc"
220
    ;;
221
    i686-apple-darwin*)
222
        hint_distro macosx32
223 224
        HAVE_DARWIN_32=1

225
        CFLAGS_TUNING=" -march=prescott -mtune=generic -arch i386 -m32"
226
        EXTRA_LDFLAGS=" -arch i386"
227
    ;;
228
    x86_64-apple-darwin*)
229
        hint_distro macosx64
230
        HAVE_DARWIN_64=1
231

232
        CFLAGS_TUNING=" -march=core2 -mtune=core2 -m64 -arch x86_64"
233
        EXTRA_LDFLAGS=" -arch x86_64"
234
    ;;
235
    *mingw32ce)
236
        EXTRA_CPPFLAGS=" -D_WIN32_WCE=0x0500"
237
        hint_distro wince
238
    ;;
239
    *64-*mingw*)
240
        add_enabled_makefile_cfg "HAVE_WIN32"
241
        EXTRA_CFLAGS="-O3"
242
        hint_distro win64
243
    ;;
244
    *mingw32*)
245
        EXTRA_CFLAGS=" -O3 -march=i686 -mtune=generic"
246
        hint_distro win32
247
    ;;
248
    i686-pc-cygwin)
249
        add_enabled_makefile_cfg "HAVE_CYGWIN"
250 251
        CC="gcc -mno-cygwin -isystem /usr/include/mingw"
        CXX="g++ -mno-cygwin -isystem /usr/include/mingw"
252
        TARGET=`$CC -dumpmachine`
253 254 255
        EXTRA_CFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
        EXTRA_CPPFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
        EXTRA_LDFLAGS=" -mno-cygwin"
256
        hint_distro win32
257
    ;;
258
    arm-wince-pe)
259
        EXTRA_CPPFLAGS=" -D_WIN32_WCE"
260
        hint_distro wince
261
    ;;
262
    armeb-linux-uclibc)
263 264
        add_enabled_makefile_cfg "HAVE_UCLIBC"
        add_enabled_makefile_cfg "HAVE_BIGENDIAN"
265 266
        EXTRA_CFLAGS="-Os -march=armv5 -msoft-float"
    ;;
267 268
    arm-none-linux-gnueabi)
        if test -f /etc/maemo_version; then
269
            hint_distro maemo5
270
            EXTRA_CFLAGS=" -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a"
271 272
            EXTRA_CFLAGS="$EXTRA_CFLAGS -mfpu=neon -mfloat-abi=softfp"
            EXTRA_CFLAGS="$EXTRA_CFLAGS -O3 -fno-tree-vectorize"
273 274
        fi
    ;;
275 276 277 278
    *86_64*linux*)
        EXTRA_CFLAGS=" -fPIC"
        EXTRA_CPPFLAGS=" -fPIC"
        EXTRA_LDFLAGS=" -L/usr/lib64"
279 280 281
        add_makefile_cfg "LIBRARY_PATH = /usr/lib64"
        add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib64/pkgconfig"
        add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib64/pkgconfig"
282
    ;;
283 284
esac

Pierre's avatar
Pierre committed
285 286 287 288
#
# Fix up the Distro
#

289
if test -z "${DISTRO}" -a "$TARGET" = "$BUILD"; then
290 291
    if test -d "/usr/lib/pkgconfig"; then
        if test -z "$PKG_CONFIG_PATH"; then
292
            add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib/pkgconfig"
293
        fi
294
        if test -z "$PKG_CONFIG_LIBDIR"; then
295
            add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig"
296 297
        fi
    fi
298
    # Try to match distribution
299
    if test -f /etc/maemo_version; then
300
        hint_distro maemo5
301
    fi
302 303
fi

304
# Default Unix-like systems
305
hint_distro unix
306

307 308 309
distro_mak="${BUILDDIR}/distro.mak"
distro_file="`pwd`/src/Distributions/${DISTRO}.mak"
ln -sf "${distro_file}" "${distro_mak}"
310

Pierre's avatar
Pierre committed
311 312 313 314 315 316 317 318 319 320 321 322 323
#
# Distro specific settings
#

case "$DISTRO" in
  ios)
    if test -z "$IOS_SDK_ROOT"; then
        error "The bootstrap script requires the IOS_SDK_ROOT environment "
        error "variable to be set when building for iOS"
        exit 1
    fi
    add_makefile_cfg "IOS_SDK_ROOT = ${IOS_SDK_ROOT}"
    ;;
324
  macosx*)
325
    SDK_TARGET=10.6
326
    HAVE_MACOSX_DARWIN_9=1
327 328
    EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -D\${ENVP} -isysroot \${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
329 330
    CC="/usr/bin/clang"
    CXX="/usr/bin/clang++"
331 332 333 334
    LD="ld"
    RANLIB="ranlib"
    AR=
    STRIP="strip"
335 336 337 338
    add_makefile_cfg "PATH = /bin:/usr/bin:/usr/local/bin"
    add_makefile_cfg "SDK_TARGET = ${SDK_TARGET}"
    add_makefile_cfg "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}"
    add_makefile_cfg "MACOSX_SDK = /Developer/SDKs/MacOSX${SDK_TARGET}.sdk"
339
    add_enabled_makefile_cfg "HAVE_MACOSX"
340

341 342
    case $TARGET in
    x86_64*|i686*) add_enabled_makefile_cfg "HAVE_MACOSX_ON_INTEL" ;;
343 344
    esac
    case $TARGET in
345 346 347 348
    *darwin10)     add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_10" ;;
    *darwin9)      add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9" ;;
    esac

349 350 351 352 353
    if ! test -e /Developer/SDKs; then
        error "Your Developer Tools' SDKs were not found.\nYou need to add extra symbolic links to /Developer to achieve correctly\nbuilt contribs.\nHave a look at the OSX-Compile-HOWTO for details." >&2
        exit 1
    fi
    ;;
354 355 356
  win*)
    add_makefile_cfg "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig"
    ;;
357 358 359 360 361 362 363 364
  android)
    if test -z "$ANDROID_NDK"; then
        error "The bootstrap script requires the ANDROID_NDK environment variable "
        error "to be set when building for Android"
        exit 1
    fi
    # The given host (arm-eabi) is not the real one (arm-linux-androideabi)
    ln -sfn $TARGET hosts/arm-linux-androideabi
365 366
    CC="arm-linux-androideabi-gcc --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
    CXX="arm-linux-androideabi-g++ --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
367 368 369 370 371 372 373 374
    NM=arm-linux-androideabi-nm
    AR=arm-linux-androideabi-ar
    LD=arm-linux-androideabi-ld
    RANLIB=arm-linux-androideabi-ranlib
    STRIP=arm-linux-androideabi-strip
    # Add the PATH to the NDK
    add_makefile_cfg "ANDROID_NDK = ${ANDROID_NDK}"
    add_makefile_cfg "PATH = ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:${PATH}"
375

376
    add_enabled_makefile_cfg "HAVE_LINUX"
377 378
    if test -z "$NO_NEON"; then
        add_enabled_makefile_cfg "HAVE_NEON"
379 380 381
        ARM_EABI=armeabi-v7a
    else
        ARM_EABI=armeabi
382
    fi
383 384 385 386
    # make sure android toolchain can build C++
    EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -D__STDC_VERSION__=199901L"
    EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include"
    EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/$ARM_EABI/include"
Pierre's avatar
Pierre committed
387 388
esac

389
# Save passed flags
390 391 392 393
EXTRA_CFLAGS="$EXTRA_CFLAGS $CFLAGS"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS $CPPFLAGS"
EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CXXFLAGS"
394

395
uppercase_distro=`echo "$DISTRO" | tr '[:lower:]' '[:upper:]'`
396
add_enabled_makefile_cfg "HAVE_${uppercase_distro}"
397 398
add_makefile_cfg "BUILD = $BUILD"
add_makefile_cfg "HOST = $TARGET"
399 400 401
add_makefile_cfg "SRCDIR = `pwd`"
add_makefile_cfg "PREFIX = ${PREFIX}"
add_makefile_cfg "VLCROOTDIR = `pwd`/../.."
402

403
ln -sfn hosts/$TARGET build
404

405 406 407 408 409 410 411 412 413 414
add_makefile_cfg "CC = ${CC}"
add_makefile_cfg "CXX = ${CXX}"
add_makefile_cfg "LD = ${LD}"
add_makefile_cfg "RANLIB = ${RANLIB}"
add_makefile_cfg "AR = ${AR}"
add_makefile_cfg "STRIP = ${STRIP}"
add_makefile_cfg "EXTRA_CFLAGS = ${CFLAGS_TUNING} ${EXTRA_CFLAGS}"
add_makefile_cfg "EXTRA_CPPFLAGS = ${EXTRA_CPPFLAGS} -isystem \$(PREFIX)/include"
add_makefile_cfg "EXTRA_LDFLAGS = ${EXTRA_LDFLAGS}"
add_makefile_cfg "EXTRA_PATH = ${EXTRA_PATH}"
415

416
#CMAKE
417 418 419 420 421
toolchain_cmake="${BUILDDIR}/toolchain.cmake"
rm -f ${BUILDDIR}/toolchain.cmake
if test ${DISTRO} = "win32"; then
    echo "SET(CMAKE_SYSTEM_NAME Windows)" >> "${toolchain_cmake}"
    echo "SET(CMAKE_RC_COMPILER ${TARGET}-windres)" >> "${toolchain_cmake}"
422
fi
423 424 425 426 427 428 429 430 431 432 433 434
case "$DISTRO" in macosx*)
    echo "SET(CMAKE_SYSTEM_NAME Darwin)" >> "${toolchain_cmake}"
    echo "set(CMAKE_C_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
    echo "set(CMAKE_CXX_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
    echo "set(CMAKE_LD_FLAGS ${EXTRA_LDFLAGS})" >> "${toolchain_cmake}"
esac
echo "SET(CMAKE_C_COMPILER ${CC})" >> "${toolchain_cmake}"
echo "SET(CMAKE_CXX_COMPILER ${CXX})" >> "${toolchain_cmake}"
echo "SET(CMAKE_FIND_ROOT_PATH  `pwd` )" >> "${toolchain_cmake}"
echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> "${toolchain_cmake}"
echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> "${toolchain_cmake}"
echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> "${toolchain_cmake}"
435

436
if wget --version >/dev/null 2>&1; then
437
    add_makefile_cfg "WGET = \"`which wget`\" -c --passive"
438
elif test -z `curl --version >/dev/null 2>&1`; then
439
    add_makefile_cfg "WGET = \"`which curl`\" -L -O"
440
else
441
    error "You need at least wget or curl to fetch the packages."
442
    exit 1
443 444
fi

445
if svn --version >/dev/null 2>&1; then
446
    add_makefile_cfg "SVN = \"`which svn`\""
447
else
448
    error "You do not have a subversion client in your PATH."
449
fi
450

451
if git --version>/dev/null 2>&1; then
452
    add_makefile_cfg "GIT = \"`which git`\""
453
else
454
    error "You do not have a Git client in your PATH."
455
fi
456 457

if test -z "$CONTRIBS_RELEASE"; then
458 459 460 461 462 463
    add_makefile_cfg "EXTRA_CFLAGS += -DNDEBUG"
    info "*****************************************************************"
    info "* If you need contribs with all debug information, run this     *"
    info "* line and compile the libraries on your own.                   *"
    info "* CONTRIBS_RELEASE=no ./bootstrap                               *"
    info "*****************************************************************"
464
fi
465

466 467
if test $HAVE_MACOSX_DARWIN_9; then
    add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9"
468 469
    if ! /usr/bin/gcc --version>/dev/null 2>&1; then
        error "You do not have GCC installed in /usr/bin, compilation WILL FAIL."
470
    fi
471
fi
Felix Kühne's avatar
Felix Kühne committed
472

473
if test "$DISTRO" = "macosx32"; then
474
    info "*****************************************************************"
475
    info "* VLC will be compiled in 32bit mode using the 10.5 & later SDK.*"
476
    info "*                                                               *"
477
    info "* Re-run with the -t x86_64-apple-darwin* argument to turn on   *"
478 479
    info "* 64bit compilation for Intel-based Macs, whereas * is either   *"
    info "* 9 or 10 depending on your Darwin version.                     *"
480
    info "* There is no PPC64 support.                                    *"
481
    info "*****************************************************************"
482 483
fi

484
if test "$DISTRO" = "macosx64"; then
485 486
    info
    info "*****************************************************************"
487
    info "* VLC will be compiled in 64bit mode using the 10.5 & later SDK.*"
488
    info "*****************************************************************"
Felix Kühne's avatar
Felix Kühne committed
489
fi
Rafaël Carré's avatar
Rafaël Carré committed
490 491 492 493 494

case `uname` in
    Linux)
        CPUS=`grep -c ^processor /proc/cpuinfo`
     ;;
495 496 497
#    Darwin)
#        CPUS=`sysctl hw.ncpu|cut -d: -f2`
#    ;;
Rafaël Carré's avatar
Rafaël Carré committed
498 499 500 501
    *)
        CPUS=1  # default
     ;;
esac
502
add_makefile_cfg "MAKEFLAGS += -j$CPUS"
Rafaël Carré's avatar
Rafaël Carré committed
503

504
info "Using $CPUS processor(s)"