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