26e9e475d8d508b231a4a7091c3692dd819f7b12
[vlc.git] / extras / contrib / bootstrap
1 #!/bin/sh
2 # ***************************************************************************
3 # bootstrap : Set up config.mak
4 # ***************************************************************************
5 # Copyright (C) 2003-2007 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 K├╝hne <fkuehne@users.sourceforge.net>
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 if test "$#" -gt "1"; then
28   echo "Usage: $0 <host>" >&2
29   echo "  Prepare config.mak file." >&2
30   exit 1
31 fi
32
33 LANG=C
34 export LANG
35 set -e
36 set -x
37
38 BUILD=`gcc -dumpmachine`
39 if test "$#" = "1"; then
40   HOST="$1"
41 else
42   HOST="$BUILD"
43 fi
44
45 rm -f config.mak
46 {
47         echo "# Automatically generated by bootstrap."
48         echo "# Make changes if you know what you're doing."
49 } > config.mak
50
51 rm -f distro.mak
52 {
53     echo "# Automatically generated by bootstrap"
54     echo "# Make changes if you know what you're doing."
55 } > distro.mak
56
57 if test "$HOST" != "$BUILD"; then
58     CC="${HOST}-gcc"
59     CXX="${HOST}-g++"
60     LD="${HOST}-ld"
61     RANLIB="${HOST}-ranlib"
62     AR="${HOST}-ar"
63 fi
64
65 case $HOST in
66     ppc-darwin)
67 # Mac OS X < 10.4
68             echo "Your version of Mac OS X is too old!" >&2
69             echo "Compiling VLC requires 10.4.x or later" >&2
70             exit 1
71         ;;
72     powerpc-apple-darwin8)
73 # Mac OS X 10.4
74 # Makefile cross compiling is only supported with gcc-4.0
75 # ENVP defines the oldest environment on which the program will be able to run
76 # SDK 10.2.8 requires gcc-3.3 (so we cannot use that SDK)
77             SDK_TARGET=10.3
78             echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
79             echo "HAVE_DARWIN_OS = 1" >> config.mak
80             echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
81             echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.3.9.sdk" >> config.mak
82             CFLAGS_TUNING=" -arch ppc -mtune=G4"
83             EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK}"
84             EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
85             echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
86         cat src/Distributions/darwin.mak >> distro.mak
87         ;;
88     powerpc-apple-darwin9)
89             SDK_TARGET=10.3
90             echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
91             echo "HAVE_DARWIN_OS = 1" >> config.mak
92 #           echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
93 #           echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.3.9.sdk" >> config.mak
94             CFLAGS_TUNING=" -arch ppc -mtune=G4"
95 #           EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK}"
96 #           EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
97             echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
98         cat src/Distributions/darwin.mak >> distro.mak
99         ;;
100     i686-apple-darwin8)
101             SDK_TARGET=10.4
102             echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
103             echo "HAVE_DARWIN_OS = 1" >> config.mak
104             echo "HAVE_DARWIN_OS_ON_INTEL = 1" >> config.mak
105             echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
106             echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
107             CFLAGS_TUNING=" -march=pentium-m -mtune=prescott"
108             EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK}"
109             EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
110             echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
111         cat src/Distributions/darwin.mak >> distro.mak
112         ;;
113     i686-apple-darwin9)
114             SDK_TARGET=10.4
115             echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
116             echo "HAVE_DARWIN_OS = 1" >> config.mak
117             echo "HAVE_DARWIN_OS_ON_INTEL = 1" >> config.mak
118 #           echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
119 #           echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
120             CFLAGS_TUNING=" -march=pentium-m -mtune=prescott"
121 #           EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK}"
122 #           EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
123             echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
124         cat src/Distributions/darwin.mak >> distro.mak
125         ;;
126     i586-pc-beos)
127             echo "HAVE_BEOS = 1" >> config.mak
128             if test -f /boot/beos/system/lib/libbind.so; then
129                 EXTRA_LDFLAGS=" -lbind -lsocket"
130             else
131                 EXTRA_LDFLAGS=" -lnet"
132             fi
133             if test "$HOST" = "$BUILD"; then
134 #               Compiling on BeOS
135                 PATH=".:/boot/home/config/bin:/bin:/boot/apps"
136                 PATH="${PATH}:/boot/preferences:/boot/beos/apps"
137                 PATH="${PATH}:/boot/beos/preferences"
138                 PATH="${PATH}:/boot/develop/tools/gnupro/bin"
139                 echo "PATH = ${PATH}" >> config.mak
140                 LIBRARY_PATH="${LIBRARY_PATH}:%A/lib:/boot/home/config/lib"
141                 LIBRARY_PATH="${LIBRARY_PATH}:/boot/beos/system/lib"
142                 echo "LIBRARY_PATH = ${LIBRARY_PATH}" >> config.mak
143             else
144 #               Cross compiling from Linux
145                 PATH="/opt/beos-tools/bin:/opt/cross-tools/bin"
146                 PATH="${PATH}:/usr/bin:/bin"
147                 echo "PATH = ${PATH}" >> config.mak
148             fi
149             cat src/Distributions/beos.mak >> distro.mak
150         ;;
151     *mingw32*)
152             echo "HAVE_WIN32 = 1" >> config.mak
153             echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
154             cat src/Distributions/win32.mak >> distro.mak
155         ;;
156     i686-pc-cygwin)
157             echo "HAVE_WIN32 = 1" >> config.mak
158             echo "HAVE_CYGWIN = 1" >> config.mak
159             CC="gcc -mno-cygwin -isystem /usr/include/mingw"
160             CXX="g++ -mno-cygwin -isystem /usr/include/mingw"
161             HOST=`$CC -dumpmachine`
162             EXTRA_CFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
163             EXTRA_CPPFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
164             EXTRA_LDFLAGS=" -mno-cygwin"
165             echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
166             cat src/Distributions/win32.mak >> distro.mak
167         ;;
168     arm-wince-pe)
169             echo "HAVE_WINCE = 1" >> config.mak
170             echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
171             EXTRA_CPPFLAGS=" -D_WIN32_WCE"
172             cat src/Distributions/wince.mak >> distro.mak
173         ;;
174     *)
175             if test "$HOST" = "$BUILD"; then
176                 if test -d "/usr/lib/pkgconfig"; then
177                     if test -z "$PKG_CONFIG_PATH"; then
178                         echo "PKG_CONFIG_PATH = /usr/lib/pkgconfig" >> config.mak
179                     fi
180                     if test -z "$PKG_CONFIG_LIBDIR"; then
181                         echo "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig" >> config.mak
182                     fi
183                 fi
184             fi
185             # Try to match distribution
186             if test -f /etc/fedora-release; then
187                 cat src/Distributions/fedora.mak >> distro.mak
188             else
189                 # Default Unix-like systems
190                 cat src/Distributions/unix.mak >> distro.mak
191             fi
192         ;;
193 esac
194
195 echo "BUILD = $BUILD" >> config.mak
196 echo "HOST = $HOST" >> config.mak
197
198 echo "PREFIX = `pwd`" >> config.mak
199
200 echo "CC = ${CC}" >> config.mak
201 echo "CXX = ${CXX}" >> config.mak
202 echo "LD = ${LD}" >> config.mak
203 echo "RANLIB = ${RANLIB}" >> config.mak
204 echo "AR = ${AR}" >> config.mak
205 echo "EXTRA_CFLAGS = ${CFLAGS_TUNING} ${EXTRA_CFLAGS}" >> config.mak
206 echo "EXTRA_CPPFLAGS = ${EXTRA_CPPFLAGS} -isystem \$(PREFIX)/include" >> config.mak
207 echo "EXTRA_LDFLAGS = ${EXTRA_LDFLAGS}" >> config.mak
208 echo "EXTRA_PATH = ${EXTRA_PATH}" >> config.mak
209
210 if which curl >/dev/null; then
211         echo "WGET = curl -O" >> config.mak
212 elif wget --version >/dev/null 2>&1; then
213         echo "WGET = wget" >> config.mak
214 else
215         echo "You need at least wget or curl to fetch the packages." >&2
216         exit 1
217 fi
218
219 if test -f /sw/bin/svn; then
220         echo "SVN = /sw/bin/svn" >> config.mak
221 elif test -f /usr/local/bin/svn; then
222         echo "SVN = /usr/local/bin/svn" >> config.mak
223 elif test -f /usr/bin/svn; then
224         echo "SVN = /usr/bin/svn" >> config.mak
225 elif test -f /opt/local/bin/svn; then
226         echo "SVN = /opt/local/bin/svn" >> config.mak
227 elif svn help >/dev/null 2>&1; then
228         echo "SVN = svn" >> config.mak
229 else
230         echo "You do not have a subversion client installed." >&2
231 fi