]> git.sesse.net Git - vlc/blob - contrib/bootstrap
Contrib: allow building contribs with no optimization
[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-net    configure to not build networking packages"
31         echo "  --disable-sout   configure to not build stream output packages"
32         echo "  --enable-small   optimize libraries for size with slight speed decrease [DANGEROUS]"
33         echo "  --disable-gpl    configure to not build viral GPL code"
34         echo "  --disable-optim  disable optimization in libraries"
35 }
36
37 BUILD=
38 HOST=
39 PREFIX=
40 PKGS_ENABLE=
41 PKGS_DISABLE=
42 BUILD_ENCODERS="1"
43 BUILD_NETWORK="1"
44 BUILD_DISCS="1"
45 GPL="1"
46 WITH_OPTIMIZATION="1"
47
48 if test ! -f "../../contrib/src/main.mak"
49 then
50         echo "$0 must be run from a subdirectory"
51         exit 1
52 fi
53
54 while test -n "$1"
55 do
56         case "$1" in
57                 --build=*)
58                         BUILD="${1#--build=}"
59                         ;;
60                 --help|-h)
61                         usage
62                         exit 0
63                         ;;
64                 --host=*)
65                         HOST="${1#--host=}"
66                         ;;
67                 --prefix=*)
68                         PREFIX="${1#--prefix=}"
69                         ;;
70                 --disable-disc)
71                         BUILD_DISCS=
72                         ;;
73                 --disable-net)
74                         BUILD_NETWORK=
75                         ;;
76                 --disable-sout)
77                         BUILD_ENCODERS=
78                         ;;
79                 --disable-optim)
80                         WITH_OPTIMIZATION=
81                         ;;
82                 --enable-small)
83                         ENABLE_SMALL=1
84                         ;;
85                 --disable-gpl)
86                         GPL=
87                         ;;
88                 --disable-*)
89                         PKGS_DISABLE="${PKGS_DISABLE} ${1#--disable-}"
90                         ;;
91                 --enable-*)
92                         PKGS_ENABLE="${PKGS_ENABLE} ${1#--enable-}"
93                         ;;
94                 *)
95                         echo "Unrecognized options $1"
96                         usage
97                         exit 1
98                         ;;
99         esac
100         shift
101 done
102
103 if test -z "$BUILD"
104 then
105         echo -n "Guessing build system... "
106         BUILD="`${CC:-cc} -dumpmachine`"
107         if test -z "$BUILD"; then
108                 echo "FAIL!"
109                 exit 1
110         fi
111         echo "$BUILD"
112 fi
113
114 if test -z "$HOST"
115 then
116         echo -n "Guessing host system...  "
117         HOST="$BUILD"
118         echo "$HOST"
119 fi
120
121 if test "$PREFIX"
122 then
123         # strip trailing slash
124         PREFIX="${PREFIX%/}"
125 fi
126
127 #
128 # Prepare files
129 #
130 echo "Creating configuration file... config.mak"
131 exec 3>config.mak || exit $?
132 cat >&3 << EOF
133 # This file was automatically generated.
134 # Any change will be overwritten if ../bootstrap is run again.
135 BUILD := $BUILD
136 HOST := $HOST
137 PKGS_DISABLE := $PKGS_DISABLE
138 PKGS_ENABLE := $PKGS_ENABLE
139 EOF
140
141 add_make()
142 {
143         while test -n "$1"
144         do
145                 echo "$1" >&3
146                 shift
147         done
148 }
149
150 add_make_enabled()
151 {
152         while test -n "$1"
153         do
154                 add_make "$1 := 1"
155                 shift
156         done
157 }
158
159 check_ios_sdk()
160 {
161    if test -z "$SDKROOT"
162    then
163       SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
164       echo "SDKROOT not specified, assuming $SDKROOT"
165    else
166       SDKROOT="$SDKROOT"
167       fi
168
169    if [ ! -d "${SDKROOT}" ]
170    then
171       echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
172       exit 1
173    fi
174    add_make "IOS_SDK=${SDKROOT}"
175 }
176
177 check_macosx_sdk()
178 {
179    if [ -z "${OSX_VERSION}" ]
180    then
181       OSX_VERSION=`xcrun --show-sdk-version`
182       echo "OSX_VERSION not specified, assuming $OSX_VERSION"
183    fi
184    if test -z "$SDKROOT"
185    then
186       SDKROOT=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
187       echo "SDKROOT not specified, assuming $SDKROOT"
188    fi
189
190    if [ ! -d "${SDKROOT}" ]
191    then
192       SDKROOT_NOT_FOUND=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
193       SDKROOT=`xcode-select -print-path`/SDKs/MacOSX$OSX_VERSION.sdk
194       echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
195    fi
196    if [ ! -d "${SDKROOT}" ]
197    then
198       SDKROOT_NOT_FOUND="$SDKROOT"
199       SDKROOT=`xcrun --show-sdk-path`
200       echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
201    fi
202
203    if [ ! -d "${SDKROOT}" ]
204    then
205       echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
206       exit 1
207    fi
208
209    add_make "MACOSX_SDK=${SDKROOT}"
210    add_make "OSX_VERSION ?= ${OSX_VERSION}"
211 }
212
213 check_android_sdk()
214 {
215         [ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
216         add_make "ANDROID_NDK := ${ANDROID_NDK}"
217         [ -z "${ANDROID_ABI}" ] && echo "You must set ANDROID_ABI environment variable" && exit 1
218         add_make "ANDROID_ABI := ${ANDROID_ABI}"
219         [ -z "${ANDROID_API}" ] && echo "You should set ANDROID_API environment variable (using default android-9)" && ANDROID_API := android-9
220         add_make "ANDROID_API := ${ANDROID_API}"
221         [ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_NEON"
222         [ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_ARMV7A"
223         [ ${ANDROID_ABI} = "arm64-v8a" ] && add_make_enabled "HAVE_NEON"
224         [ ${ANDROID_ABI} = "arm64-v8a" ] && add_make_enabled "HAVE_ARMV8A"
225         [ ${ANDROID_ABI} = "armeabi" -a -z "${NO_ARMV6}" ] && add_make_enabled "HAVE_ARMV6"
226 }
227
228 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
229 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
230 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
231 test -z "$BUILD_NETWORK" || add_make_enabled "BUILD_NETWORK"
232 test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
233 test -z "$GPL" || add_make_enabled "GPL"
234 test -z "$WITH_OPTIMIZATION" || add_make_enabled "WITH_OPTIMIZATION"
235
236 #
237 # Checks
238 #
239 OS="${HOST#*-}" # strip architecture
240 case "${OS}" in
241         apple-darwin*)
242                 if test -z "$BUILDFORIOS"
243                 then
244                         check_macosx_sdk
245                         add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
246                 else
247                         check_ios_sdk
248                         add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD" "HAVE_FPU"
249
250                         case "${HOST}" in
251                                 *arm*)
252                                 add_make_enabled "HAVE_NEON" "HAVE_ARMV7A"
253                                 ;;
254                         esac;
255                 fi
256                 ;;
257         *bsd*)
258                 add_make_enabled "HAVE_BSD"
259                 ;;
260         *android*)
261                 check_android_sdk
262                 add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
263                 case "${HOST}" in
264                         *arm*)
265                         add_make "PLATFORM_SHORT_ARCH := arm"
266                         ;;
267                         *arm64*|*aarch64*)
268                         add_make "PLATFORM_SHORT_ARCH := arm64"
269                         ;;
270                         *i686*)
271                         add_make "PLATFORM_SHORT_ARCH := x86"
272                         ;;
273                         *x86_64*)
274                         add_make "PLATFORM_SHORT_ARCH := x86_64"
275                         ;;
276                         *mipsel*)
277                         add_make "PLATFORM_SHORT_ARCH := mips"
278                         ;;
279                 esac
280                 ;;
281         *linux*)
282                 add_make_enabled "HAVE_LINUX"
283                 ;;
284         *mingw*)
285                 add_make_enabled "HAVE_WIN32"
286                 ;;
287         *solaris*)
288                 add_make_enabled "HAVE_SOLARIS"
289                 ;;
290 esac
291
292 #
293 # Results output
294 #
295 test -e Makefile && unlink Makefile
296 ln -sf ../../contrib/src/main.mak Makefile || exit $?
297 cat << EOF
298 Bootstrap completed.
299
300 Run "make" to start compilation.
301
302 Other targets:
303  * make install      same as "make"
304  * make prebuilt     fetch and install prebuilt binaries
305  * make list         list packages
306  * make fetch        fetch required source tarballs
307  * make fetch-all    fetch all source tarballs
308  * make distclean    clean everything and undo bootstrap
309  * make mostlyclean  clean everything except source tarballs
310  * make clean        clean everything
311  * make package      prepare prebuilt packages
312 EOF
313
314 mkdir -p ../../contrib/tarballs || exit $?