]> git.sesse.net Git - vlc/blob - contrib/bootstrap
Contribs: add an option to optimize a bit for the size
[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_android_sdk()
159 {
160         [ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
161         add_make "ANDROID_NDK := ${ANDROID_NDK}"
162         test -z "${NO_NEON}" && add_make_enabled "HAVE_NEON"
163 }
164
165 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
166 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
167 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
168 test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
169
170 #
171 # Checks
172 #
173 OS="${HOST#*-}" # strip architecture
174 case "${OS}" in
175         apple-darwin*)
176                 check_macosx_sdk
177                 add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
178                 ;;
179         *darwin*)
180                 add_make_enabled "HAVE_DARWIN_OS" "HAVE_BSD"
181                 ;;
182         *bsd*)
183                 add_make_enabled "HAVE_BSD"
184                 ;;
185         linux-androideabi)
186                 check_android_sdk
187                 add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
188                 add_make "PATH = ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/:${PATH}"
189                 ;;
190         *linux*)
191                 add_make_enabled "HAVE_LINUX"
192                 ;;
193         *wince*)
194                 add_make_enabled "HAVE_WINCE"
195                 ;;
196         *mingw*)
197                 add_make_enabled "HAVE_WIN32"
198                 ;;
199 esac
200
201 #
202 # Results output
203 #
204 test -e Makefile && unlink Makefile
205 ln -sf ../../contrib/src/main.mak Makefile
206 cat << EOF
207 Bootstrap completed.
208
209 Run "make" to start compilation.
210
211 Other targets:
212  * make install      same as "make"
213  * make prebuilt     fetch and install prebuilt binaries
214  * make list         list packages
215  * make fetch        fetch required source tarballs
216  * make fetch-all    fetch all source tarballs
217  * make distclean    clean everything and undo bootstrap
218  * make mostlyclean  clean everything except source tarballs
219  * make clean        clean everything
220  * make package      prepare prebuilt packages
221 EOF
222
223 mkdir -p ../../contrib/tarballs