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