contribs : propose to build whole contribs with -DNDEBUG to disable
[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" -o "$1" = "-h" -o "$1" = "--help" ; 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 "$#" -ge "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     STRIP="${HOST}-strip"
71 fi
72
73 # Check the HAVE_{OS}
74 case $HOST in
75     *darwin*)
76         echo "HAVE_DARWIN_OS = 1" >> config.mak
77         echo "HAVE_BSD = 1" >> config.mak
78     ;;
79     *linux*)
80         echo "HAVE_LINUX = 1" >> config.mak
81     ;;
82     *bsd*)
83         echo "HAVE_BSD = 1" >> config.mak
84     ;;
85     *wince*)
86         echo "HAVE_WINCE = 1" >> config.mak
87     ;;
88     *beos*)
89         echo "HAVE_BEOS = 1" >> config.mak
90     ;;
91 esac
92
93 case $HOST in
94     ppc-darwin)
95 # Mac OS X < 10.4
96         echo "Your version of Mac OS X is too old!" >&2
97         echo "Compiling VLC requires 10.4.x or later" >&2
98         exit 1
99     ;;
100     powerpc-apple-darwin8)
101 # Mac OS X 10.4 or 10.5 with Xcode 2.5
102 # Makefile cross compiling is only supported with gcc-4.0
103 # ENVP defines the oldest environment on which the program will be able to run
104         SDK_TARGET=10.4
105         echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
106         echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
107         echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
108         CFLAGS_TUNING=" -arch ppc -mtune=G4"
109         EXTRA_CFLAGS=" -D\${ENVP} -mmacosx-version-min=\${SDK_TARGET}"
110         CC="gcc -isysroot \${MACOSX_SDK}"
111         CXX="g++ -isysroot \${MACOSX_SDK}"
112         LD="ld -arch ppc -syslibroot \${MACOSX_SDK}"
113         echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
114         cat src/Distributions/darwin.mak >> distro.mak
115     ;;
116     i686-apple-darwin8)
117         SDK_TARGET=10.4
118         echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
119         echo "HAVE_DARWIN_OS_ON_INTEL = 1" >> config.mak
120         echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
121         echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
122         CFLAGS_TUNING=" -march=pentium-m -mtune=prescott"
123         EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
124         EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
125         echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
126         cat src/Distributions/darwin.mak >> distro.mak
127     ;;
128     powerpc-apple-darwin9)
129 # Mac OS X 10.5 with Xcode 3, specific rules apply
130         SDK_TARGET=10.4
131         echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
132         echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
133         echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
134         echo "HAVE_DARWIN_9 = 1" >> config.mak
135         CFLAGS_TUNING=" -arch ppc -mtune=G4"
136         EXTRA_CFLAGS=" -D\${ENVP} -mmacosx-version-min=\${SDK_TARGET}"
137         CC="gcc -isysroot \${MACOSX_SDK}"
138         CXX="g++ -isysroot \${MACOSX_SDK}"
139         LD="ld -arch ppc -syslibroot \${MACOSX_SDK}"
140         echo "PATH = /bin:/usr/bin:/usr/local/bin:" >> config.mak
141         cat src/Distributions/darwin.mak >> distro.mak
142         if test -e /Developer/SDKs; then
143             echo "SDKs found. Everything is fine." >&2
144         else
145             echo "ERROR:\nYour 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
146             exit 1
147         fi
148     ;;
149     i686-apple-darwin9)
150         SDK_TARGET=10.4
151         MIN_LD_VERSION_WITH_TEXT_RELOCATION=81
152         echo "SDK_TARGET = ${SDK_TARGET}" >> config.mak
153         echo "HAVE_DARWIN_OS_ON_INTEL = 1" >> config.mak
154         echo "HAVE_DARWIN_9 = 1" >> config.mak
155         if test `ld -v 2> /dev/stdout | sed -E 's/.*ld64-([0-9]+).*/\1/'` -lt ${MIN_LD_VERSION_WITH_TEXT_RELOCATION}; then
156             echo "NO_TEXT_RELOCATION = 1" >> config.mak
157         fi
158         echo "ENVP = MACOSX_DEPLOYMENT_TARGET=${SDK_TARGET}" >> config.mak
159         echo "MACOSX_SDK = /Developer/SDKs/MacOSX10.4u.sdk" >> config.mak
160         CFLAGS_TUNING=" -march=pentium-m -mtune=prescott"
161         EXTRA_CFLAGS=" -D\${ENVP} -isysroot \${MACOSX_SDK} -mmacosx-version-min=\${SDK_TARGET}"
162         EXTRA_LDFLAGS=" -isysroot \${MACOSX_SDK} -Wl,-syslibroot,\${MACOSX_SDK}"
163         echo "PATH = /bin:/usr/bin:/usr/local/bin" >> config.mak
164         cat src/Distributions/darwin.mak >> distro.mak
165         if test -e /Developer/SDKs; then
166             echo "SDKs found. Everything is fine." >&2
167         else
168             echo "ERROR:\nYour 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
169             exit 1
170         fi
171     ;;
172     i586-pc-beos)
173         if test -f /boot/beos/system/lib/libbind.so; then
174             EXTRA_LDFLAGS=" -lbind -lsocket"
175         else
176             EXTRA_LDFLAGS=" -lnet"
177         fi
178         if test "$HOST" = "$BUILD"; then
179 #           Compiling on BeOS
180             PATH=".:/boot/home/config/bin:/bin:/boot/apps"
181             PATH="${PATH}:/boot/preferences:/boot/beos/apps"
182             PATH="${PATH}:/boot/beos/preferences"
183             PATH="${PATH}:/boot/develop/tools/gnupro/bin"
184             echo "PATH = ${PATH}" >> config.mak
185             LIBRARY_PATH="${LIBRARY_PATH}:%A/lib:/boot/home/config/lib"
186             LIBRARY_PATH="${LIBRARY_PATH}:/boot/beos/system/lib"
187             echo "LIBRARY_PATH = ${LIBRARY_PATH}" >> config.mak
188         else
189 #           Cross compiling from Linux
190             PATH="/opt/beos-tools/bin:/opt/cross-tools/bin"
191             PATH="${PATH}:/usr/bin:/bin"
192             echo "PATH = ${PATH}" >> config.mak
193         fi
194         cat src/Distributions/beos.mak >> distro.mak
195     ;;
196     *mingw32*)
197         echo "HAVE_WIN32 = 1" >> config.mak
198         echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
199             EXTRA_CFLAGS="-O3"
200         cat src/Distributions/win32.mak >> distro.mak
201     ;;
202     i686-pc-cygwin)
203         echo "HAVE_WIN32 = 1" >> config.mak
204         echo "HAVE_CYGWIN = 1" >> config.mak
205         CC="gcc -mno-cygwin -isystem /usr/include/mingw"
206         CXX="g++ -mno-cygwin -isystem /usr/include/mingw"
207         HOST=`$CC -dumpmachine`
208         EXTRA_CFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
209         EXTRA_CPPFLAGS=" -mno-cygwin -isystem /usr/include/mingw"
210         EXTRA_LDFLAGS=" -mno-cygwin"
211         echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
212         cat src/Distributions/win32.mak >> distro.mak
213     ;;
214     arm-wince-pe)
215         echo "PKG_CONFIG_PATH = \$(PREFIX)/lib/pkgconfig" >> config.mak
216         EXTRA_CPPFLAGS=" -D_WIN32_WCE"
217         cat src/Distributions/wince.mak >> distro.mak
218     ;;
219     armeb-linux-uclibc)
220         echo "HAVE_UCLIBC = 1" >> config.mak
221         echo "HAVE_BIGENDIAN = 1" >> config.mak
222         EXTRA_CFLAGS="-Os -march=armv5 -msoft-float"
223         if test ! -z "${DISTRO}";  then
224             cat src/Distributions/${DISTRO}.mak >> distro.mak
225         else
226             cat src/Distributions/unix.mak >> distro.mak
227         fi
228     ;;
229     *)
230         if test "$HOST" = "$BUILD"; then
231             if test -d "/usr/lib/pkgconfig"; then
232                 if test -z "$PKG_CONFIG_PATH"; then
233                     echo "PKG_CONFIG_PATH = /usr/lib/pkgconfig" >> config.mak
234                 fi
235                 if test -z "$PKG_CONFIG_LIBDIR"; then
236                     echo "PKG_CONFIG_LIBDIR = /usr/lib/pkgconfig" >> config.mak
237                 fi
238             fi
239             # Try to match distribution
240             if test -f /etc/fedora-release; then
241                 cat src/Distributions/fedora.mak >> distro.mak
242             else
243                 # Default Unix-like systems
244                 cat src/Distributions/unix.mak >> distro.mak
245             fi
246         else # unknown distro
247             if test ! -z "${DISTRO}";  then
248                 cat src/Distributions/${DISTRO}.mak >> distro.mak
249             else
250                 cat src/Distributions/unix.mak >> distro.mak
251             fi
252         fi
253     ;;
254 esac
255
256 echo "BUILD = $BUILD" >> config.mak
257 echo "HOST = $HOST" >> config.mak
258
259 echo "PREFIX = `pwd`" >> config.mak
260
261 echo "CC = ${CC}" >> config.mak
262 echo "CXX = ${CXX}" >> config.mak
263 echo "LD = ${LD}" >> config.mak
264 echo "RANLIB = ${RANLIB}" >> config.mak
265 echo "AR = ${AR}" >> config.mak
266 echo "STRIP = ${STRIP}" >> config.mak
267 echo "EXTRA_CFLAGS = ${CFLAGS_TUNING} ${EXTRA_CFLAGS}" >> config.mak
268 echo "EXTRA_CPPFLAGS = ${EXTRA_CPPFLAGS} -isystem \$(PREFIX)/include" >> config.mak
269 echo "EXTRA_LDFLAGS = ${EXTRA_LDFLAGS}" >> config.mak
270 echo "EXTRA_PATH = ${EXTRA_PATH}" >> config.mak
271
272 if wget --version >/dev/null 2>&1; then
273     echo "WGET = `which wget` -c --passive" >> config.mak
274 elif which curl >/dev/null; then
275     echo "WGET = `which curl` -L -O" >> config.mak
276 else
277     echo "You need at least wget or curl to fetch the packages." >&2
278     exit 1
279 fi
280
281 if svn help >/dev/null 2>&1; then
282     echo "SVN = `which svn`" >> config.mak
283 else
284     echo "You do not have a subversion client in your PATH." >&2
285 fi
286
287 if git help >/dev/null 2>&1; then
288     echo "GIT = `which git`" >> config.mak
289 else
290     echo "You do not have a Git client in your PATH." >&2
291 fi
292
293 if test -z "$CONTRIBS_RELEASE"; then
294     set +x
295     echo
296     echo "***********************************************************"
297     echo "* If you are building contribs for a release build of VLC *"
298     echo "* Please run CONTRIBS_RELEASE=sexy ./bootstrap            *"
299     echo "***********************************************************"
300 else
301     echo "EXTRA_CFLAGS += -DNDEBUG" >> config.mak
302     echo "EXTRA_CPPFLAGS += -DNDEBUG" >> config.mak
303 fi