2 # ***************************************************************************
3 # bootstrap : Set up config.mak
4 # ***************************************************************************
5 # Copyright (C) 2003-2009 the VideoLAN team
8 # Authors: Christophe Massiot <massiot@via.ecp.fr>
9 # Derk-Jan Hartman <hartman at videolan dot org>
10 # Felix Paul Kühne <fkuehne at videolan dot org>
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 # ***************************************************************************
35 usage: $0 [-t target] [-d distro] [-b buildir] [-i installdir]
38 -t target Force target to "target"
39 -d distro Force distro to "distro"
40 -b buildir Set build dir to "builddir"
41 -i installdir Install to "installdir"
48 echo $1 >> "${config_mak}"
51 add_enabled_makefile_cfg()
53 echo "$1=1" >> "${config_mak}"
58 echo "[contrib] ERROR: $1"
70 # Give a hint about the auto detected distro
71 if test -z "${DISTRO}"; then DISTRO="$1"; fi
76 while getopts "ht:d:b:i:" OPTION
101 shift $(($OPTIND - 1))
103 if [ "x$1" != "x" ]; then
104 error "Fallback to old command line switch, use the -t option now"
107 if [ "x$2" != "x" ]; then
112 BUILD=`gcc -dumpmachine`
114 if test "x$TARGET" = "x"; then
116 info "No target specified, using '$TARGET'"
119 if test "x$PREFIX" = "x"; then
120 PREFIX="`pwd`/hosts/$TARGET"
121 info "No install dir specified, using '$PREFIX'"
124 # Make sure prefix is absolute and existing
126 PREFIX=`cd "${PREFIX}" && pwd`
127 mkdir -p "${PREFIX}/share/aclocal" # aclocal needs this dir to exist
133 mkdir -p "${BUILDDIR}"
135 # Install build dir makefile
136 ln -sf "`pwd`/contrib.mak" "${BUILDDIR}/Makefile"
138 # Create the 'build-src' folder to build from source
139 mkdir -p "${BUILDDIR}/build-src"
140 ln -sf "`pwd`/src/contrib-src.mak" "${BUILDDIR}/build-src/Makefile"
141 ln -sf "`pwd`/src/packages.mak" "${BUILDDIR}/build-src/"
142 ln -sf "`pwd`/src/Patches" "${BUILDDIR}/build-src/"
145 config_mak="${BUILDDIR}/config.mak"
146 rm -f "${config_mak}"
148 echo "# Automatically generated by bootstrap."
149 echo "# Make changes if you know what you're doing."
152 if test "$TARGET" != "$BUILD"; then
153 test -z "$CC" && CC="${TARGET}-gcc"
154 test -z "$CXX" && CXX="${TARGET}-g++"
155 test -z "$LD" && LD="${TARGET}-ld"
156 test -z "$RANLIB"&& RANLIB="${TARGET}-ranlib"
157 test -z "$AR" && AR="${TARGET}-ar"
158 test -z "$STRIP" && STRIP="${TARGET}-strip"
178 add_makefile_cfg "ARCH = $ARCH"
180 # Check the HAVE_{OS}
183 add_enabled_makefile_cfg "HAVE_DARWIN_OS"
184 add_enabled_makefile_cfg "HAVE_BSD"
187 add_enabled_makefile_cfg "HAVE_LINUX"
190 add_enabled_makefile_cfg "HAVE_BSD"
193 add_enabled_makefile_cfg "HAVE_WINCE"
196 add_enabled_makefile_cfg "HAVE_SYMBIAN"
200 # Figure out the correct distro to use
202 ppc-darwin|*-apple-darwin8)
203 error "Your version of Mac OS X is too old!"
204 error "Compiling and running VLC requires 10.5.x or later"
207 powerpc-apple-darwin9)
211 CFLAGS_TUNING=" -arch ppc -mtune=G4"
212 EXTRA_LDFLAGS=" -arch ppc"
218 CFLAGS_TUNING=" -march=prescott -mtune=generic -arch i386 -m32"
219 EXTRA_LDFLAGS=" -arch i386"
221 x86_64-apple-darwin*)
225 CFLAGS_TUNING=" -march=core2 -mtune=core2 -m64 -arch x86_64"
226 EXTRA_LDFLAGS=" -arch x86_64"
229 EXTRA_CPPFLAGS=" -D_WIN32_WCE=0x0500"
233 add_enabled_makefile_cfg "HAVE_WIN32"
238 EXTRA_CFLAGS=" -O3 -march=i686 -mtune=generic"
242 add_enabled_makefile_cfg "HAVE_CYGWIN"
243 CC="gcc -mno-cygwin -isystem /usr/include/mingw"
244 CXX="g++ -mno-cygwin -isystem /usr/include/mingw"
245 TARGET=`$CC -dumpmachine`
246 EXTRA_CFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
247 EXTRA_CPPFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
248 EXTRA_LDFLAGS=" -mno-cygwin"
252 EXTRA_CPPFLAGS=" -D_WIN32_WCE"
256 add_enabled_makefile_cfg "HAVE_UCLIBC"
257 add_enabled_makefile_cfg "HAVE_BIGENDIAN"
258 EXTRA_CFLAGS="-Os -march=armv5 -msoft-float"
260 arm-none-linux-gnueabi)
261 if test -f /etc/maemo_version; then
263 EXTRA_CFLAGS=" -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a"
264 EXTRA_CFLAGS="$EXTRA_CFLAGS -mfpu=neon -mfloat-abi=softfp"
265 EXTRA_CFLAGS="$EXTRA_CFLAGS -O3 -fno-tree-vectorize"
269 EXTRA_CFLAGS=" -fPIC"
270 EXTRA_CPPFLAGS=" -fPIC"
271 EXTRA_LDFLAGS=" -L/usr/lib64"
272 add_makefile_cfg "LIBRARY_PATH = /usr/lib64"
273 add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib64/pkgconfig"
274 add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib64/pkgconfig"
282 if test -z "${DISTRO}" -a "$TARGET" = "$BUILD"; then
283 if test -d "/usr/lib/pkgconfig"; then
284 if test -z "$PKG_CONFIG_PATH"; then
285 add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib/pkgconfig"
287 if test -z "$PKG_CONFIG_LIBDIR"; then
288 add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig"
291 # Try to match distribution
292 if test -f /etc/fedora-release; then
294 elif test -f /etc/maemo_version; then
296 elif test -f /etc/debian_version; then
297 # NOTE: check for Debian *after* its derivatives
302 # Default Unix-like systems
305 distro_mak="${BUILDDIR}/distro.mak"
306 distro_file="`pwd`/src/Distributions/${DISTRO}.mak"
307 ln -sf "${distro_file}" "${distro_mak}"
310 # Distro specific settings
315 if test -z "$IOS_SDK_ROOT"; then
316 error "The bootstrap script requires the IOS_SDK_ROOT environment "
317 error "variable to be set when building for iOS"
320 add_makefile_cfg "IOS_SDK_ROOT = ${IOS_SDK_ROOT}"
324 HAVE_MACOSX_DARWIN_9=1
325 EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
326 EXTRA_CFLAGS="${EXTRA_CFLAGS} -D\${ENVP} -isysroot \${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
328 CXX="/usr/bin/clang++"
333 add_makefile_cfg "PATH = /bin:/usr/bin:/usr/local/bin"
334 add_makefile_cfg "SDK_TARGET = ${SDK_TARGET}"
335 add_makefile_cfg "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}"
336 add_makefile_cfg "MACOSX_SDK = /Developer/SDKs/MacOSX${SDK_TARGET}.sdk"
337 add_enabled_makefile_cfg "HAVE_MACOSX"
340 x86_64*|i686*) add_enabled_makefile_cfg "HAVE_MACOSX_ON_INTEL" ;;
343 *darwin10) add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_10" ;;
344 *darwin9) add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9" ;;
347 if ! test -e /Developer/SDKs; then
348 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
353 add_makefile_cfg "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig"
356 if test -z "$ANDROID_NDK"; then
357 error "The bootstrap script requires the ANDROID_NDK environment variable "
358 error "to be set when building for Android"
361 # The given host (arm-eabi) is not the real one (arm-linux-androideabi)
362 ln -sfn $TARGET hosts/arm-linux-androideabi
363 CC="arm-linux-androideabi-gcc --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
364 CXX="arm-linux-androideabi-g++ --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
365 NM=arm-linux-androideabi-nm
366 AR=arm-linux-androideabi-ar
367 LD=arm-linux-androideabi-ld
368 RANLIB=arm-linux-androideabi-ranlib
369 STRIP=arm-linux-androideabi-strip
370 # Add the PATH to the NDK
371 add_makefile_cfg "ANDROID_NDK = ${ANDROID_NDK}"
372 add_makefile_cfg "PATH = ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:${PATH}"
374 add_enabled_makefile_cfg "HAVE_LINUX"
375 if test -z "$NO_NEON"; then
376 add_enabled_makefile_cfg "HAVE_NEON"
381 # make sure android toolchain can build C++
382 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -D__STDC_VERSION__=199901L"
383 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include"
384 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/$ARM_EABI/include"
388 EXTRA_CFLAGS="$EXTRA_CFLAGS $CFLAGS"
389 EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
390 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS $CPPFLAGS"
391 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CXXFLAGS"
393 uppercase_distro=`echo "$DISTRO" | tr '[:lower:]' '[:upper:]'`
394 add_enabled_makefile_cfg "HAVE_${uppercase_distro}"
395 add_makefile_cfg "BUILD = $BUILD"
396 add_makefile_cfg "HOST = $TARGET"
397 add_makefile_cfg "SRCDIR = `pwd`"
398 add_makefile_cfg "PREFIX = ${PREFIX}"
399 add_makefile_cfg "VLCROOTDIR = `pwd`/../.."
401 ln -sfn hosts/$TARGET build
403 add_makefile_cfg "CC = ${CC}"
404 add_makefile_cfg "CXX = ${CXX}"
405 add_makefile_cfg "LD = ${LD}"
406 add_makefile_cfg "RANLIB = ${RANLIB}"
407 add_makefile_cfg "AR = ${AR}"
408 add_makefile_cfg "STRIP = ${STRIP}"
409 add_makefile_cfg "EXTRA_CFLAGS = ${CFLAGS_TUNING} ${EXTRA_CFLAGS}"
410 add_makefile_cfg "EXTRA_CPPFLAGS = ${EXTRA_CPPFLAGS} -isystem \$(PREFIX)/include"
411 add_makefile_cfg "EXTRA_LDFLAGS = ${EXTRA_LDFLAGS}"
412 add_makefile_cfg "EXTRA_PATH = ${EXTRA_PATH}"
415 toolchain_cmake="${BUILDDIR}/toolchain.cmake"
416 rm -f ${BUILDDIR}/toolchain.cmake
417 if test ${DISTRO} = "win32"; then
418 echo "SET(CMAKE_SYSTEM_NAME Windows)" >> "${toolchain_cmake}"
419 echo "SET(CMAKE_RC_COMPILER ${TARGET}-windres)" >> "${toolchain_cmake}"
421 case "$DISTRO" in macosx*)
422 echo "SET(CMAKE_SYSTEM_NAME Darwin)" >> "${toolchain_cmake}"
423 echo "set(CMAKE_C_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
424 echo "set(CMAKE_CXX_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
425 echo "set(CMAKE_LD_FLAGS ${EXTRA_LDFLAGS})" >> "${toolchain_cmake}"
427 echo "SET(CMAKE_C_COMPILER ${CC})" >> "${toolchain_cmake}"
428 echo "SET(CMAKE_CXX_COMPILER ${CXX})" >> "${toolchain_cmake}"
429 echo "SET(CMAKE_FIND_ROOT_PATH `pwd` )" >> "${toolchain_cmake}"
430 echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> "${toolchain_cmake}"
431 echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> "${toolchain_cmake}"
432 echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> "${toolchain_cmake}"
434 if wget --version >/dev/null 2>&1; then
435 add_makefile_cfg "WGET = \"`which wget`\" -c --passive"
436 elif test -z `curl --version >/dev/null 2>&1`; then
437 add_makefile_cfg "WGET = \"`which curl`\" -L -O"
439 error "You need at least wget or curl to fetch the packages."
443 if svn --version >/dev/null 2>&1; then
444 add_makefile_cfg "SVN = \"`which svn`\""
446 error "You do not have a subversion client in your PATH."
449 if git --version>/dev/null 2>&1; then
450 add_makefile_cfg "GIT = \"`which git`\""
452 error "You do not have a Git client in your PATH."
455 if test -z "$CONTRIBS_RELEASE"; then
456 add_makefile_cfg "EXTRA_CFLAGS += -DNDEBUG"
457 info "*****************************************************************"
458 info "* If you need contribs with all debug information, run this *"
459 info "* line and compile the libraries on your own. *"
460 info "* CONTRIBS_RELEASE=no ./bootstrap *"
461 info "*****************************************************************"
464 if test $HAVE_MACOSX_DARWIN_9; then
465 add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9"
466 if ! /usr/bin/gcc --version>/dev/null 2>&1; then
467 error "You do not have GCC installed in /usr/bin, compilation WILL FAIL."
471 if test "$DISTRO" = "macosx32"; then
472 info "*****************************************************************"
473 info "* VLC will be compiled in 32bit mode using the 10.5 & later SDK.*"
475 info "* Re-run with the -t x86_64-apple-darwin* argument to turn on *"
476 info "* 64bit compilation for Intel-based Macs, whereas * is either *"
477 info "* 9 or 10 depending on your Darwin version. *"
478 info "* There is no PPC64 support. *"
479 info "*****************************************************************"
482 if test "$DISTRO" = "macosx64"; then
484 info "*****************************************************************"
485 info "* VLC will be compiled in 64bit mode using the 10.5 & later SDK.*"
486 info "*****************************************************************"
491 CPUS=`grep -c ^processor /proc/cpuinfo`
494 # CPUS=`sysctl hw.ncpu|cut -d: -f2`
500 add_makefile_cfg "MAKEFLAGS += -j$CPUS"
502 info "Using $CPUS processor(s)"