]> git.sesse.net Git - vlc/blob - contrib/bootstrap
contrib/bootstrap: fixed check for iOS
[vlc] / contrib / bootstrap
1 #! /bin/sh
2 # Copyright (C) 2003-2011 the VideoLAN team
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17
18 #
19 # Command line handling
20 #
21 usage()
22 {
23         echo "Usage: $0 [--build=BUILD] [--host=HOST] [--prefix=PREFIX]"
24         echo "  --build=BUILD    configure for building on BUILD"
25         echo "  --host=HOST      cross-compile to build to run on HOST"
26         echo "  --prefix=PREFIX  install files in PREFIX"
27         echo "  --disable-FOO    configure to not build package FOO"
28         echo "  --enable-FOO     configure to build package FOO"
29         echo "  --disable-disc   configure to not build optical discs packages"
30         echo "  --disable-sout   configure to not build stream output packages"
31         echo "  --enable-small   optimize libraries for size with slight speed decrease [DANGEROUS]"
32 }
33
34 BUILD=
35 HOST=
36 PREFIX=
37 PKGS_ENABLE=
38 PKGS_DISABLE=
39 BUILD_ENCODERS="1"
40 BUILD_DISCS="1"
41
42 if test ! -f "../../contrib/src/main.mak"
43 then
44         echo "$0 must be run from a subdirectory"
45         exit 1
46 fi
47
48 while test -n "$1"
49 do
50         case "$1" in
51                 --build=*)
52                         BUILD="${1#--build=}"
53                         ;;
54                 --help|-h)
55                         usage
56                         exit 0
57                         ;;
58                 --host=*)
59                         HOST="${1#--host=}"
60                         ;;
61                 --prefix=*)
62                         PREFIX="${1#--prefix=}"
63                         ;;
64                 --disable-disc)
65                         BUILD_DISCS=
66                         ;;
67                 --disable-sout)
68                         BUILD_ENCODERS=
69                         ;;
70                 --enable-small)
71                         ENABLE_SMALL=1
72                         ;;
73                 --disable-*)
74                         PKGS_DISABLE="${PKGS_DISABLE} ${1#--disable-}"
75                         ;;
76                 --enable-*)
77                         PKGS_ENABLE="${PKGS_ENABLE} ${1#--enable-}"
78                         ;;
79                 *)
80                         echo "Unrecognized options $1"
81                         usage
82                         exit 1
83                         ;;
84         esac
85         shift
86 done
87
88 if test -z "$BUILD"
89 then
90         echo -n "Guessing build system... "
91         BUILD="`cc -dumpmachine`"
92         if test -z "$BUILD"; then
93                 echo "FAIL!"
94                 exit 1
95         fi
96         echo "$BUILD"
97 fi
98
99 if test -z "$HOST"
100 then
101         echo -n "Guessing host system...  "
102         HOST="$BUILD"
103         echo "$HOST"
104 fi
105
106 if test "$PREFIX"
107 then
108         # strip trailing slash
109         PREFIX="${PREFIX%/}"
110 fi
111
112 #
113 # Prepare files
114 #
115 echo "Creating configuration file... config.mak"
116 exec 3>config.mak
117 cat >&3 << EOF
118 # This file was automatically generated.
119 # Any change will be overwritten if ../bootstrap is run again.
120 BUILD := $BUILD
121 HOST := $HOST
122 PKGS_DISABLE := $PKGS_DISABLE
123 PKGS_ENABLE := $PKGS_ENABLE
124 EOF
125
126 add_make()
127 {
128         while test -n "$1"
129         do
130                 echo "$1" >&3
131                 shift
132         done
133 }
134
135 add_make_enabled()
136 {
137         while test -n "$1"
138         do
139                 add_make "$1 := 1"
140                 shift
141         done
142 }
143
144 check_macosx_sdk()
145 {
146    [ -z "${OSX_VERSION}" ] && echo "OSX_VERSION not specified, assuming 10.5" && OSX_VERSION=10.5
147    SDK="/Developer/SDKs/MacOSX${OSX_VERSION}.sdk"
148    if [ ! -d "${SDK}" ]
149    then
150            echo "
151 *** ${SDK} does not exist, please install required SDK, or use export OSX_VERSION=10.6 ***
152 "
153            exit 1
154    fi
155    add_make "OSX_VERSION ?= ${OSX_VERSION}"
156 }
157
158 check_ios_sdk()
159 {
160         if test -z "$SDKROOT"
161         then
162                 SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
163                 echo "SDKROOT not specified, assuming $SDKROOT"
164         else
165                 SDKROOT="$SDKROOT"
166         fi
167
168         if [ ! -d "${SDKROOT}" ]
169         then
170                 echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
171                 exit 1
172         fi
173         add_make "SDKROOT=${SDKROOT}"
174 }
175
176 check_android_sdk()
177 {
178         [ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
179         add_make "ANDROID_NDK := ${ANDROID_NDK}"
180         test -z "${NO_NEON}" && add_make_enabled "HAVE_NEON"
181 }
182
183 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
184 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
185 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
186 test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
187
188 #
189 # Checks
190 #
191 OS="${HOST#*-}" # strip architecture
192 case "${OS}" in
193         apple-darwin*)
194                 if test -z "$BUILDFORIOS"
195                 then
196                         check_macosx_sdk
197                         add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
198                 else
199                         check_ios_sdk
200                         add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD"
201                 fi
202                 ;;
203         *bsd*)
204                 add_make_enabled "HAVE_BSD"
205                 ;;
206         linux-androideabi)
207                 check_android_sdk
208                 add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
209                 add_make "PATH = ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:${PATH}"
210                 ;;
211         *linux*)
212                 add_make_enabled "HAVE_LINUX"
213                 ;;
214         *wince*)
215                 add_make_enabled "HAVE_WINCE"
216                 ;;
217         *mingw*)
218                 add_make_enabled "HAVE_WIN32"
219                 ;;
220 esac
221
222 #
223 # Results output
224 #
225 test -e Makefile && unlink Makefile
226 ln -sf ../../contrib/src/main.mak Makefile
227 cat << EOF
228 Bootstrap completed.
229
230 Run "make" to start compilation.
231
232 Other targets:
233  * make install      same as "make"
234  * make prebuilt     fetch and install prebuilt binaries
235  * make list         list packages
236  * make fetch        fetch required source tarballs
237  * make fetch-all    fetch all source tarballs
238  * make distclean    clean everything and undo bootstrap
239  * make mostlyclean  clean everything except source tarballs
240  * make clean        clean everything
241  * make package      prepare prebuilt packages
242 EOF
243
244 mkdir -p ../../contrib/tarballs