]> git.sesse.net Git - vlc/blob - contrib/bootstrap
contrib: move some android complexity outside of vlc.git
[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.6" && OSX_VERSION=10.6
147    if test -z "$SDKROOT"
148    then
149       SDKROOT=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
150       echo "SDKROOT not specified, assuming $SDKROOT"
151    fi
152
153    if [ ! -d "${SDKROOT}" ]
154    then
155       SDKROOT_NOT_FOUND=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
156       SDKROOT=`xcode-select -print-path`/SDKs/MacOSX$OSX_VERSION.sdk
157       echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
158    fi
159
160    if [ ! -d "${SDKROOT}" ]
161    then
162       echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
163       exit 1
164    fi
165
166    add_make "OSX_VERSION ?= ${OSX_VERSION}"
167 }
168
169 check_ios_sdk()
170 {
171         if test -z "$SDKROOT"
172         then
173                 SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
174                 echo "SDKROOT not specified, assuming $SDKROOT"
175         else
176                 SDKROOT="$SDKROOT"
177         fi
178
179         if [ ! -d "${SDKROOT}" ]
180         then
181                 echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
182                 exit 1
183         fi
184         add_make "SDKROOT=${SDKROOT}"
185 }
186
187 check_android_sdk()
188 {
189         [ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
190         add_make "ANDROID_NDK := ${ANDROID_NDK}"
191         [ -z "${ANDROID_ABI}" ] && echo "You must set ANDROID_ABI environment variable" && exit 1
192         add_make "ANDROID_ABI := ${ANDROID_ABI}"
193         test -z "${NO_NEON}" && add_make_enabled "HAVE_NEON"
194 }
195
196 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
197 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
198 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
199 test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
200
201 #
202 # Checks
203 #
204 OS="${HOST#*-}" # strip architecture
205 case "${OS}" in
206         apple-darwin*)
207                 if test -z "$BUILDFORIOS"
208                 then
209                         check_macosx_sdk
210                         add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
211                 else
212                         check_ios_sdk
213                         add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD" "HAVE_NEON"
214                 fi
215                 ;;
216         *bsd*)
217                 add_make_enabled "HAVE_BSD"
218                 ;;
219         *android*)
220                 check_android_sdk
221                 add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
222                 case "${HOST}" in
223                         *arm*)
224                         add_make "PLATFORM_SHORT_ARCH := arm"
225                         ;;
226                         *i686*)
227                         add_make "PLATFORM_SHORT_ARCH := x86"
228                         ;;
229                         *mipsel*)
230                         add_make "PLATFORM_SHORT_ARCH := mips"
231                         ;;
232                 esac
233                 ;;
234         *linux*)
235                 add_make_enabled "HAVE_LINUX"
236                 ;;
237         *wince*)
238                 add_make_enabled "HAVE_WINCE"
239                 ;;
240         *mingw*)
241                 add_make_enabled "HAVE_WIN32"
242                 ;;
243 esac
244
245 #
246 # Results output
247 #
248 test -e Makefile && unlink Makefile
249 ln -sf ../../contrib/src/main.mak Makefile
250 cat << EOF
251 Bootstrap completed.
252
253 Run "make" to start compilation.
254
255 Other targets:
256  * make install      same as "make"
257  * make prebuilt     fetch and install prebuilt binaries
258  * make list         list packages
259  * make fetch        fetch required source tarballs
260  * make fetch-all    fetch all source tarballs
261  * make distclean    clean everything and undo bootstrap
262  * make mostlyclean  clean everything except source tarballs
263  * make clean        clean everything
264  * make package      prepare prebuilt packages
265 EOF
266
267 mkdir -p ../../contrib/tarballs