]> git.sesse.net Git - vlc/blob - extras/contrib/bootstrap
ed73e5a572c91407930b0cf11ff4521505214dd4
[vlc] / extras / contrib / bootstrap
1 #!/bin/sh
2 # ***************************************************************************
3 # bootstrap : Set up config.mak
4 # ***************************************************************************
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>
10 #          Felix Paul Kühne <fkuehne at videolan dot org>
11 #
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.
16 #
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.
21 #
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 # ***************************************************************************
26
27 echo "WARNING: This method to build 3rd party libraries has been deprecated.
28 Please use the /contrib folder instead of /extras/contrib.
29 "
30
31 LANG=C
32 export LANG
33 set -e
34 set +x
35
36 usage()
37 {
38 cat << EOF
39 usage: $0 [-t target] [-d distro] [-b buildir] [-i installdir]
40
41 OPTIONS:
42    -t target     Force target to "target"
43    -d distro     Force distro to "distro"
44    -b buildir    Set build dir to "builddir"
45    -i installdir Install to "installdir"
46    -h            Show some help
47 EOF
48 }
49
50 add_makefile_cfg()
51 {
52     echo $1 >> "${config_mak}"
53 }
54
55 add_enabled_makefile_cfg()
56 {
57     echo "$1=1" >> "${config_mak}"
58 }
59
60 error()
61 {
62     echo "[contrib] ERROR: $1"
63 }
64
65 info()
66 {
67     echo "[contrib] $1"
68 }
69
70 DISTRO=
71
72 hint_distro()
73 {
74     # Give a hint about the auto detected distro
75     if test -z "${DISTRO}"; then DISTRO="$1"; fi
76 }
77
78 BUILDDIR=.
79
80 while getopts "ht:d:b:i:" OPTION
81 do
82      case $OPTION in
83          h)
84              usage
85              exit 1
86              ;;
87          t)
88              TARGET=$OPTARG
89              ;;
90          d)
91              DISTRO=$OPTARG
92              ;;
93          b)
94              BUILDDIR=$OPTARG
95              ;;
96          i)
97              PREFIX=$OPTARG
98              ;;
99          ?)
100              usage
101              exit 1
102              ;;
103      esac
104 done
105 shift $(($OPTIND - 1))
106
107 if [ "x$1" != "x" ]; then
108     error "Fallback to old command line switch, use the -t option now"
109     TARGET="$1"
110 fi
111 if [ "x$2" != "x" ]; then
112     usage
113     exit 1
114 fi
115
116 BUILD=`gcc -dumpmachine`
117
118 if test "x$TARGET" = "x"; then
119     TARGET="$BUILD"
120     info "No target specified, using '$TARGET'"
121 fi
122
123 if test "x$PREFIX" = "x"; then
124     PREFIX="`pwd`/hosts/$TARGET"
125     info "No install dir specified, using '$PREFIX'"
126 fi
127
128 # Make sure prefix is absolute and existing
129 mkdir -p "${PREFIX}"
130 PREFIX=`cd "${PREFIX}" && pwd`
131 mkdir -p "${PREFIX}/share/aclocal" # aclocal needs this dir to exist
132
133 #
134 # Set up build dir
135 #
136
137 mkdir -p "${BUILDDIR}"
138
139 # Install build dir makefile
140 ln -sf "`pwd`/contrib.mak" "${BUILDDIR}/Makefile"
141
142 # Create the 'build-src' folder to build from source
143 mkdir -p "${BUILDDIR}/build-src"
144 ln -sf "`pwd`/src/contrib-src.mak" "${BUILDDIR}/build-src/Makefile"
145 ln -sf "`pwd`/src/packages.mak" "${BUILDDIR}/build-src/"
146 ln -sf "`pwd`/src/Patches" "${BUILDDIR}/build-src/"
147
148 # Create config.mak
149 config_mak="${BUILDDIR}/config.mak"
150 rm -f "${config_mak}"
151 {
152     echo "# Automatically generated by bootstrap."
153     echo "# Make changes if you know what you're doing."
154 } > "${config_mak}"
155
156 if test "$TARGET" != "$BUILD"; then
157     test -z "$CC"    && CC="${TARGET}-gcc"
158     test -z "$CXX"   && CXX="${TARGET}-g++"
159     test -z "$LD"    && LD="${TARGET}-ld"
160     test -z "$RANLIB"&& RANLIB="${TARGET}-ranlib"
161     test -z "$AR"    && AR="${TARGET}-ar"
162     test -z "$STRIP" && STRIP="${TARGET}-strip"
163 fi
164
165 case $TARGET in
166     *powerpc*|*ppc*)
167          ARCH="ppc"
168      ;;
169     *86_64*)
170           ARCH="x86_64"
171      ;;
172     *86*)
173           ARCH="i386"
174      ;;
175     arm*eabi)
176           ARCH="armel"
177      ;;
178     arm*)
179           ARCH="arm"
180      ;;
181 esac
182 add_makefile_cfg "ARCH = $ARCH"
183
184 # Check the HAVE_{OS}
185 case $TARGET in
186     *darwin*)
187         add_enabled_makefile_cfg "HAVE_DARWIN_OS"
188         add_enabled_makefile_cfg "HAVE_BSD"
189     ;;
190     *linux*)
191         add_enabled_makefile_cfg "HAVE_LINUX"
192     ;;
193     *bsd*)
194         add_enabled_makefile_cfg "HAVE_BSD"
195     ;;
196     *wince*)
197         add_enabled_makefile_cfg "HAVE_WINCE"
198     ;;
199     *symbian*)
200         add_enabled_makefile_cfg "HAVE_SYMBIAN"
201     ;;
202 esac
203
204 # Figure out the correct distro to use
205 case $TARGET in
206     ppc-darwin|*-apple-darwin8)
207         error "Your version of Mac OS X is too old!"
208         error "Compiling and running VLC requires 10.5.x or later"
209         exit 1
210     ;;
211     powerpc-apple-darwin9)
212         hint_distro macosx32
213         HAVE_DARWIN_32=1
214
215         CFLAGS_TUNING=" -arch ppc -mtune=G4"
216         EXTRA_LDFLAGS=" -arch ppc"
217     ;;
218     i686-apple-darwin*)
219         hint_distro macosx32
220         HAVE_DARWIN_32=1
221
222         CFLAGS_TUNING=" -march=prescott -mtune=generic -arch i386 -m32"
223         EXTRA_LDFLAGS=" -arch i386"
224     ;;
225     x86_64-apple-darwin*)
226         hint_distro macosx64
227         HAVE_DARWIN_64=1
228
229         CFLAGS_TUNING=" -march=core2 -mtune=core2 -m64 -arch x86_64"
230         EXTRA_LDFLAGS=" -arch x86_64"
231     ;;
232     *mingw32ce)
233         EXTRA_CPPFLAGS=" -D_WIN32_WCE=0x0500"
234         hint_distro wince
235     ;;
236     *64-*mingw*)
237         add_enabled_makefile_cfg "HAVE_WIN32"
238         EXTRA_CFLAGS="-O3"
239         hint_distro win64
240     ;;
241     *mingw32*)
242         EXTRA_CFLAGS=" -O3 -march=i686 -mtune=generic"
243         hint_distro win32
244     ;;
245     i686-pc-cygwin)
246         add_enabled_makefile_cfg "HAVE_CYGWIN"
247         CC="gcc -mno-cygwin -isystem /usr/include/mingw"
248         CXX="g++ -mno-cygwin -isystem /usr/include/mingw"
249         TARGET=`$CC -dumpmachine`
250         EXTRA_CFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
251         EXTRA_CPPFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
252         EXTRA_LDFLAGS=" -mno-cygwin"
253         hint_distro win32
254     ;;
255     arm-wince-pe)
256         EXTRA_CPPFLAGS=" -D_WIN32_WCE"
257         hint_distro wince
258     ;;
259     armeb-linux-uclibc)
260         add_enabled_makefile_cfg "HAVE_UCLIBC"
261         add_enabled_makefile_cfg "HAVE_BIGENDIAN"
262         EXTRA_CFLAGS="-Os -march=armv5 -msoft-float"
263     ;;
264     arm-none-linux-gnueabi)
265         if test -f /etc/maemo_version; then
266             hint_distro maemo5
267             EXTRA_CFLAGS=" -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a"
268             EXTRA_CFLAGS="$EXTRA_CFLAGS -mfpu=neon -mfloat-abi=softfp"
269             EXTRA_CFLAGS="$EXTRA_CFLAGS -O3 -fno-tree-vectorize"
270         fi
271     ;;
272     *86_64*linux*)
273         EXTRA_CFLAGS=" -fPIC"
274         EXTRA_CPPFLAGS=" -fPIC"
275         EXTRA_LDFLAGS=" -L/usr/lib64"
276         add_makefile_cfg "LIBRARY_PATH = /usr/lib64"
277         add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib64/pkgconfig"
278         add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib64/pkgconfig"
279     ;;
280 esac
281
282 #
283 # Fix up the Distro
284 #
285
286 if test -z "${DISTRO}" -a "$TARGET" = "$BUILD"; then
287     if test -d "/usr/lib/pkgconfig"; then
288         if test -z "$PKG_CONFIG_PATH"; then
289             add_makefile_cfg "PKG_CONFIG_PATH = /usr/lib/pkgconfig"
290         fi
291         if test -z "$PKG_CONFIG_LIBDIR"; then
292             add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig"
293         fi
294     fi
295     # Try to match distribution
296     if test -f /etc/fedora-release; then
297         hint_distro fedora
298     elif test -f /etc/maemo_version; then
299         hint_distro maemo5
300     elif test -f /etc/debian_version; then
301         # NOTE: check for Debian *after* its derivatives
302         hint_distro debian
303     fi
304 fi
305
306 # Default Unix-like systems
307 hint_distro unix
308
309 distro_mak="${BUILDDIR}/distro.mak"
310 distro_file="`pwd`/src/Distributions/${DISTRO}.mak"
311 ln -sf "${distro_file}" "${distro_mak}"
312
313 #
314 # Distro specific settings
315 #
316
317 case "$DISTRO" in
318   ios)
319     if test -z "$IOS_SDK_ROOT"; then
320         error "The bootstrap script requires the IOS_SDK_ROOT environment "
321         error "variable to be set when building for iOS"
322         exit 1
323     fi
324     add_makefile_cfg "IOS_SDK_ROOT = ${IOS_SDK_ROOT}"
325     ;;
326   macosx*)
327     SDK_TARGET=10.6
328     HAVE_MACOSX_DARWIN_9=1
329     EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
330     EXTRA_CFLAGS="${EXTRA_CFLAGS} -D\${ENVP} -isysroot \${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
331     CC="/usr/bin/clang"
332     CXX="/usr/bin/clang++"
333     LD="ld"
334     RANLIB="ranlib"
335     AR=
336     STRIP="strip"
337     add_makefile_cfg "PATH = /bin:/usr/bin:/usr/local/bin"
338     add_makefile_cfg "SDK_TARGET = ${SDK_TARGET}"
339     add_makefile_cfg "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}"
340     add_makefile_cfg "MACOSX_SDK = /Developer/SDKs/MacOSX${SDK_TARGET}.sdk"
341     add_enabled_makefile_cfg "HAVE_MACOSX"
342
343     case $TARGET in
344     x86_64*|i686*) add_enabled_makefile_cfg "HAVE_MACOSX_ON_INTEL" ;;
345     esac
346     case $TARGET in
347     *darwin10)     add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_10" ;;
348     *darwin9)      add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9" ;;
349     esac
350
351     if ! test -e /Developer/SDKs; then
352         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         exit 1
354     fi
355     ;;
356   win*)
357     add_makefile_cfg "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig"
358     ;;
359   android)
360     if test -z "$ANDROID_NDK"; then
361         error "The bootstrap script requires the ANDROID_NDK environment variable "
362         error "to be set when building for Android"
363         exit 1
364     fi
365     # The given host (arm-eabi) is not the real one (arm-linux-androideabi)
366     ln -sfn $TARGET hosts/arm-linux-androideabi
367     CC="arm-linux-androideabi-gcc --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
368     CXX="arm-linux-androideabi-g++ --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
369     NM=arm-linux-androideabi-nm
370     AR=arm-linux-androideabi-ar
371     LD=arm-linux-androideabi-ld
372     RANLIB=arm-linux-androideabi-ranlib
373     STRIP=arm-linux-androideabi-strip
374     # Add the PATH to the NDK
375     add_makefile_cfg "ANDROID_NDK = ${ANDROID_NDK}"
376     add_makefile_cfg "PATH = ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:${PATH}"
377
378     add_enabled_makefile_cfg "HAVE_LINUX"
379     if test -z "$NO_NEON"; then
380         add_enabled_makefile_cfg "HAVE_NEON"
381         ARM_EABI=armeabi-v7a
382     else
383         ARM_EABI=armeabi
384     fi
385     # make sure android toolchain can build C++
386     EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -D__STDC_VERSION__=199901L"
387     EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include"
388     EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/$ARM_EABI/include"
389 esac
390
391 # Save passed flags
392 EXTRA_CFLAGS="$EXTRA_CFLAGS $CFLAGS"
393 EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
394 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS $CPPFLAGS"
395 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CXXFLAGS"
396
397 uppercase_distro=`echo "$DISTRO" | tr '[:lower:]' '[:upper:]'`
398 add_enabled_makefile_cfg "HAVE_${uppercase_distro}"
399 add_makefile_cfg "BUILD = $BUILD"
400 add_makefile_cfg "HOST = $TARGET"
401 add_makefile_cfg "SRCDIR = `pwd`"
402 add_makefile_cfg "PREFIX = ${PREFIX}"
403 add_makefile_cfg "VLCROOTDIR = `pwd`/../.."
404
405 ln -sfn hosts/$TARGET build
406
407 add_makefile_cfg "CC = ${CC}"
408 add_makefile_cfg "CXX = ${CXX}"
409 add_makefile_cfg "LD = ${LD}"
410 add_makefile_cfg "RANLIB = ${RANLIB}"
411 add_makefile_cfg "AR = ${AR}"
412 add_makefile_cfg "STRIP = ${STRIP}"
413 add_makefile_cfg "EXTRA_CFLAGS = ${CFLAGS_TUNING} ${EXTRA_CFLAGS}"
414 add_makefile_cfg "EXTRA_CPPFLAGS = ${EXTRA_CPPFLAGS} -isystem \$(PREFIX)/include"
415 add_makefile_cfg "EXTRA_LDFLAGS = ${EXTRA_LDFLAGS}"
416 add_makefile_cfg "EXTRA_PATH = ${EXTRA_PATH}"
417
418 #CMAKE
419 toolchain_cmake="${BUILDDIR}/toolchain.cmake"
420 rm -f ${BUILDDIR}/toolchain.cmake
421 if test ${DISTRO} = "win32"; then
422     echo "SET(CMAKE_SYSTEM_NAME Windows)" >> "${toolchain_cmake}"
423     echo "SET(CMAKE_RC_COMPILER ${TARGET}-windres)" >> "${toolchain_cmake}"
424 fi
425 case "$DISTRO" in macosx*)
426     echo "SET(CMAKE_SYSTEM_NAME Darwin)" >> "${toolchain_cmake}"
427     echo "set(CMAKE_C_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
428     echo "set(CMAKE_CXX_FLAGS ${CFLAGS_TUNING} ${EXTRA_CFLAGS})" >> "${toolchain_cmake}"
429     echo "set(CMAKE_LD_FLAGS ${EXTRA_LDFLAGS})" >> "${toolchain_cmake}"
430 esac
431 echo "SET(CMAKE_C_COMPILER ${CC})" >> "${toolchain_cmake}"
432 echo "SET(CMAKE_CXX_COMPILER ${CXX})" >> "${toolchain_cmake}"
433 echo "SET(CMAKE_FIND_ROOT_PATH  `pwd` )" >> "${toolchain_cmake}"
434 echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> "${toolchain_cmake}"
435 echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> "${toolchain_cmake}"
436 echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> "${toolchain_cmake}"
437
438 if wget --version >/dev/null 2>&1; then
439     add_makefile_cfg "WGET = \"`which wget`\" -c --passive"
440 elif test -z `curl --version >/dev/null 2>&1`; then
441     add_makefile_cfg "WGET = \"`which curl`\" -L -O"
442 else
443     error "You need at least wget or curl to fetch the packages."
444     exit 1
445 fi
446
447 if svn --version >/dev/null 2>&1; then
448     add_makefile_cfg "SVN = \"`which svn`\""
449 else
450     error "You do not have a subversion client in your PATH."
451 fi
452
453 if git --version>/dev/null 2>&1; then
454     add_makefile_cfg "GIT = \"`which git`\""
455 else
456     error "You do not have a Git client in your PATH."
457 fi
458
459 if test -z "$CONTRIBS_RELEASE"; then
460     add_makefile_cfg "EXTRA_CFLAGS += -DNDEBUG"
461     info "*****************************************************************"
462     info "* If you need contribs with all debug information, run this     *"
463     info "* line and compile the libraries on your own.                   *"
464     info "* CONTRIBS_RELEASE=no ./bootstrap                               *"
465     info "*****************************************************************"
466 fi
467
468 if test $HAVE_MACOSX_DARWIN_9; then
469     add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9"
470     if ! /usr/bin/gcc --version>/dev/null 2>&1; then
471         error "You do not have GCC installed in /usr/bin, compilation WILL FAIL."
472     fi
473 fi
474
475 if test "$DISTRO" = "macosx32"; then
476     info "*****************************************************************"
477     info "* VLC will be compiled in 32bit mode using the 10.5 & later SDK.*"
478     info "*                                                               *"
479     info "* Re-run with the -t x86_64-apple-darwin* argument to turn on   *"
480     info "* 64bit compilation for Intel-based Macs, whereas * is either   *"
481     info "* 9 or 10 depending on your Darwin version.                     *"
482     info "* There is no PPC64 support.                                    *"
483     info "*****************************************************************"
484 fi
485
486 if test "$DISTRO" = "macosx64"; then
487     info
488     info "*****************************************************************"
489     info "* VLC will be compiled in 64bit mode using the 10.5 & later SDK.*"
490     info "*****************************************************************"
491 fi
492
493 case `uname` in
494     Linux)
495         CPUS=`grep -c ^processor /proc/cpuinfo`
496      ;;
497 #    Darwin)
498 #        CPUS=`sysctl hw.ncpu|cut -d: -f2`
499 #    ;;
500     *)
501         CPUS=1  # default
502      ;;
503 esac
504 add_makefile_cfg "MAKEFLAGS += -j$CPUS"
505
506 info "Using $CPUS processor(s)"