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