]> git.sesse.net Git - vlc/blob - extras/contrib/bootstrap
Compat: relicense strcasestr to LGPL
[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 LANG=C
28 export LANG
29 set -e
30 set +x
31
32 usage()
33 {
34 cat << EOF
35 usage: $0 [-t target] [-d distro] [-b buildir] [-i installdir]
36
37 OPTIONS:
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"
42    -h            Show some help
43 EOF
44 }
45
46 add_makefile_cfg()
47 {
48     echo $1 >> "${config_mak}"
49 }
50
51 add_enabled_makefile_cfg()
52 {
53     echo "$1=1" >> "${config_mak}"
54 }
55
56 error()
57 {
58     echo "[contrib] ERROR: $1"
59 }
60
61 info()
62 {
63     echo "[contrib] $1"
64 }
65
66 DISTRO=
67
68 hint_distro()
69 {
70     # Give a hint about the auto detected distro
71     if test -z "${DISTRO}"; then DISTRO="$1"; fi
72 }
73
74 BUILDDIR=.
75
76 while getopts "ht:d:b:i:" OPTION
77 do
78      case $OPTION in
79          h)
80              usage
81              exit 1
82              ;;
83          t)
84              TARGET=$OPTARG
85              ;;
86          d)
87              DISTRO=$OPTARG
88              ;;
89          b)
90              BUILDDIR=$OPTARG
91              ;;
92          i)
93              PREFIX=$OPTARG
94              ;;
95          ?)
96              usage
97              exit 1
98              ;;
99      esac
100 done
101 shift $(($OPTIND - 1))
102
103 if [ "x$1" != "x" ]; then
104     error "Fallback to old command line switch, use the -t option now"
105     TARGET="$1"
106 fi
107 if [ "x$2" != "x" ]; then
108     usage
109     exit 1
110 fi
111
112 BUILD=`gcc -dumpmachine`
113
114 if test "x$TARGET" = "x"; then
115     TARGET="$BUILD"
116     info "No target specified, using '$TARGET'"
117 fi
118
119 if test "x$PREFIX" = "x"; then
120     PREFIX="`pwd`/hosts/$TARGET"
121     info "No install dir specified, using '$PREFIX'"
122 fi
123
124 # Make sure prefix is absolute and existing
125 mkdir -p "${PREFIX}"
126 PREFIX=`cd "${PREFIX}" && pwd`
127 mkdir -p "${PREFIX}/share/aclocal" # aclocal needs this dir to exist
128
129 #
130 # Set up build dir
131 #
132
133 mkdir -p "${BUILDDIR}"
134
135 # Install build dir makefile
136 ln -sf "`pwd`/contrib.mak" "${BUILDDIR}/Makefile"
137
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/"
143
144 # Create config.mak
145 config_mak="${BUILDDIR}/config.mak"
146 rm -f "${config_mak}"
147 {
148     echo "# Automatically generated by bootstrap."
149     echo "# Make changes if you know what you're doing."
150 } > "${config_mak}"
151
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"
159 fi
160
161 case $TARGET in
162     *powerpc*|*ppc*)
163          ARCH="ppc"
164      ;;
165     *86_64*)
166           ARCH="x86_64"
167      ;;
168     *86*)
169           ARCH="i386"
170      ;;
171     arm*eabi)
172           ARCH="armel"
173      ;;
174     arm*)
175           ARCH="arm"
176      ;;
177 esac
178 add_makefile_cfg "ARCH = $ARCH"
179
180 # Check the HAVE_{OS}
181 case $TARGET in
182     *darwin*)
183         add_enabled_makefile_cfg "HAVE_DARWIN_OS"
184         add_enabled_makefile_cfg "HAVE_BSD"
185     ;;
186     *linux*)
187         add_enabled_makefile_cfg "HAVE_LINUX"
188     ;;
189     *bsd*)
190         add_enabled_makefile_cfg "HAVE_BSD"
191     ;;
192     *wince*)
193         add_enabled_makefile_cfg "HAVE_WINCE"
194     ;;
195     *symbian*)
196         add_enabled_makefile_cfg "HAVE_SYMBIAN"
197     ;;
198 esac
199
200 # Figure out the correct distro to use
201 case $TARGET in
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"
205         exit 1
206     ;;
207     powerpc-apple-darwin9)
208         hint_distro macosx32
209         HAVE_DARWIN_32=1
210
211         CFLAGS_TUNING=" -arch ppc -mtune=G4"
212         EXTRA_LDFLAGS=" -arch ppc"
213     ;;
214     i686-apple-darwin*)
215         hint_distro macosx32
216         HAVE_DARWIN_32=1
217
218         CFLAGS_TUNING=" -march=prescott -mtune=generic -arch i386 -m32"
219         EXTRA_LDFLAGS=" -arch i386"
220     ;;
221     x86_64-apple-darwin*)
222         hint_distro macosx64
223         HAVE_DARWIN_64=1
224
225         CFLAGS_TUNING=" -march=core2 -mtune=core2 -m64 -arch x86_64"
226         EXTRA_LDFLAGS=" -arch x86_64"
227     ;;
228     *mingw32ce)
229         EXTRA_CPPFLAGS=" -D_WIN32_WCE=0x0500"
230         hint_distro wince
231     ;;
232     *64-*mingw*)
233         add_enabled_makefile_cfg "HAVE_WIN32"
234         EXTRA_CFLAGS="-O3"
235         hint_distro win64
236     ;;
237     *mingw32*)
238         EXTRA_CFLAGS=" -O3 -march=i686 -mtune=generic"
239         hint_distro win32
240     ;;
241     i686-pc-cygwin)
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"
249         hint_distro win32
250     ;;
251     arm-wince-pe)
252         EXTRA_CPPFLAGS=" -D_WIN32_WCE"
253         hint_distro wince
254     ;;
255     armeb-linux-uclibc)
256         add_enabled_makefile_cfg "HAVE_UCLIBC"
257         add_enabled_makefile_cfg "HAVE_BIGENDIAN"
258         EXTRA_CFLAGS="-Os -march=armv5 -msoft-float"
259     ;;
260     arm-none-linux-gnueabi)
261         if test -f /etc/maemo_version; then
262             hint_distro maemo5
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"
266         fi
267     ;;
268     *86_64*linux*)
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"
275     ;;
276 esac
277
278 #
279 # Fix up the Distro
280 #
281
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"
286         fi
287         if test -z "$PKG_CONFIG_LIBDIR"; then
288             add_makefile_cfg "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig"
289         fi
290     fi
291     # Try to match distribution
292     if test -f /etc/fedora-release; then
293         hint_distro fedora
294     elif test -f /etc/maemo_version; then
295         hint_distro maemo5
296     elif test -f /etc/debian_version; then
297         # NOTE: check for Debian *after* its derivatives
298         hint_distro debian
299     fi
300 fi
301
302 # Default Unix-like systems
303 hint_distro unix
304
305 distro_mak="${BUILDDIR}/distro.mak"
306 distro_file="`pwd`/src/Distributions/${DISTRO}.mak"
307 ln -sf "${distro_file}" "${distro_mak}"
308
309 #
310 # Distro specific settings
311 #
312
313 case "$DISTRO" in
314   ios)
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"
318         exit 1
319     fi
320     add_makefile_cfg "IOS_SDK_ROOT = ${IOS_SDK_ROOT}"
321     ;;
322   macosx*)
323     SDK_TARGET=10.5
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}"
327     CC="/usr/bin/gcc"
328     CXX="/usr/bin/g++"
329     LD="ld"
330     RANLIB="ranlib"
331     AR=
332     STRIP="strip"
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"
338
339     case $TARGET in
340     x86_64*|i686*) add_enabled_makefile_cfg "HAVE_MACOSX_ON_INTEL" ;;
341     esac
342     case $TARGET in
343     *darwin10)     add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_10" ;;
344     *darwin9)      add_enabled_makefile_cfg "HAVE_MACOSX_DARWIN_9" ;;
345     esac
346
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
349         exit 1
350     fi
351     ;;
352   win*)
353     add_makefile_cfg "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig"
354     ;;
355   android)
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"
359         exit 1
360     fi
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}"
373
374     add_enabled_makefile_cfg "HAVE_LINUX"
375     if test -z "$NO_NEON"; then
376         add_enabled_makefile_cfg "HAVE_NEON"
377         ARM_EABI=armeabi-v7a
378     else
379         ARM_EABI=armeabi
380     fi
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"
385 esac
386
387 # Save passed flags
388 EXTRA_CFLAGS="$EXTRA_CFLAGS $CFLAGS"
389 EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
390 EXTRA_CPPFLAGS="$EXTRA_CPPFLAGS $CPPFLAGS"
391 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CXXFLAGS"
392
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`/../.."
400
401 ln -sfn hosts/$TARGET build
402
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}"
413
414 #CMAKE
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}"
420 fi
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}"
426 esac
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}"
433
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"
438 else
439     error "You need at least wget or curl to fetch the packages."
440     exit 1
441 fi
442
443 if svn --version >/dev/null 2>&1; then
444     add_makefile_cfg "SVN = \"`which svn`\""
445 else
446     error "You do not have a subversion client in your PATH."
447 fi
448
449 if git --version>/dev/null 2>&1; then
450     add_makefile_cfg "GIT = \"`which git`\""
451 else
452     error "You do not have a Git client in your PATH."
453 fi
454
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 "*****************************************************************"
462 fi
463
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."
468     fi
469 fi
470
471 if test "$DISTRO" = "macosx32"; then
472     info "*****************************************************************"
473     info "* VLC will be compiled in 32bit mode using the 10.5 & later SDK.*"
474     info "*                                                               *"
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 "*****************************************************************"
480 fi
481
482 if test "$DISTRO" = "macosx64"; then
483     info
484     info "*****************************************************************"
485     info "* VLC will be compiled in 64bit mode using the 10.5 & later SDK.*"
486     info "*****************************************************************"
487 fi
488
489 case `uname` in
490     Linux)
491         CPUS=`grep -c ^processor /proc/cpuinfo`
492      ;;
493 #    Darwin)
494 #        CPUS=`sysctl hw.ncpu|cut -d: -f2`
495 #    ;;
496     *)
497         CPUS=1  # default
498      ;;
499 esac
500 add_makefile_cfg "MAKEFLAGS += -j$CPUS"
501
502 info "Using $CPUS processor(s)"