contrib: add option to turn off (L)GPL version 3
[vlc.git] / 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-gnuv3  configure to not build version 3 (L)GPL code"
35         echo "  --disable-optim  disable optimization in libraries"
36 }
37
38 BUILD=
39 HOST=
40 PREFIX=
41 PKGS_ENABLE=
42 PKGS_DISABLE=
43 BUILD_ENCODERS="1"
44 BUILD_NETWORK="1"
45 BUILD_DISCS="1"
46 GPL="1"
47 GNUV3="1"
48 WITH_OPTIMIZATION="1"
49
50 if test ! -f "../../contrib/src/main.mak"
51 then
52         echo "$0 must be run from a subdirectory"
53         exit 1
54 fi
55
56 while test -n "$1"
57 do
58         case "$1" in
59                 --build=*)
60                         BUILD="${1#--build=}"
61                         ;;
62                 --help|-h)
63                         usage
64                         exit 0
65                         ;;
66                 --host=*)
67                         HOST="${1#--host=}"
68                         ;;
69                 --prefix=*)
70                         PREFIX="${1#--prefix=}"
71                         ;;
72                 --disable-disc)
73                         BUILD_DISCS=
74                         ;;
75                 --disable-net)
76                         BUILD_NETWORK=
77                         ;;
78                 --disable-sout)
79                         BUILD_ENCODERS=
80                         ;;
81                 --disable-optim)
82                         WITH_OPTIMIZATION=
83                         ;;
84                 --enable-small)
85                         ENABLE_SMALL=1
86                         ;;
87                 --disable-gpl)
88                         GPL=
89                         ;;
90                 --disable-gnuv3)
91                         GNUV3=
92                         ;;
93                 --disable-*)
94                         PKGS_DISABLE="${PKGS_DISABLE} ${1#--disable-}"
95                         ;;
96                 --enable-*)
97                         PKGS_ENABLE="${PKGS_ENABLE} ${1#--enable-}"
98                         ;;
99                 *)
100                         echo "Unrecognized options $1"
101                         usage
102                         exit 1
103                         ;;
104         esac
105         shift
106 done
107
108 if test -z "$BUILD"
109 then
110         echo -n "Guessing build system... "
111         BUILD="`${CC:-cc} -dumpmachine`"
112         if test -z "$BUILD"; then
113                 echo "FAIL!"
114                 exit 1
115         fi
116         echo "$BUILD"
117 fi
118
119 if test -z "$HOST"
120 then
121         echo -n "Guessing host system...  "
122         HOST="$BUILD"
123         echo "$HOST"
124 fi
125
126 if test "$PREFIX"
127 then
128         # strip trailing slash
129         PREFIX="${PREFIX%/}"
130 fi
131
132 #
133 # Prepare files
134 #
135 echo "Creating configuration file... config.mak"
136 exec 3>config.mak || exit $?
137 cat >&3 << EOF
138 # This file was automatically generated.
139 # Any change will be overwritten if ../bootstrap is run again.
140 BUILD := $BUILD
141 HOST := $HOST
142 PKGS_DISABLE := $PKGS_DISABLE
143 PKGS_ENABLE := $PKGS_ENABLE
144 EOF
145
146 add_make()
147 {
148         while test -n "$1"
149         do
150                 echo "$1" >&3
151                 shift
152         done
153 }
154
155 add_make_enabled()
156 {
157         while test -n "$1"
158         do
159                 add_make "$1 := 1"
160                 shift
161         done
162 }
163
164 check_ios_sdk()
165 {
166     if test "$VLCSDKROOT"
167     then
168             SDKROOT="$VLCSDKROOT"
169     else
170                 if test -z "$SDKROOT"
171                 then
172                    SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
173                    echo "SDKROOT not specified, assuming $SDKROOT"
174                 else
175                    SDKROOT="$SDKROOT"
176                 fi
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 "IOS_SDK=${SDKROOT}"
185 }
186
187 check_macosx_sdk()
188 {
189    if [ -z "${OSX_VERSION}" ]
190    then
191       OSX_VERSION=`xcrun --show-sdk-version`
192       echo "OSX_VERSION not specified, assuming $OSX_VERSION"
193    fi
194    if test -z "$SDKROOT"
195    then
196       SDKROOT=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
197       echo "SDKROOT not specified, assuming $SDKROOT"
198    fi
199
200    if [ ! -d "${SDKROOT}" ]
201    then
202       SDKROOT_NOT_FOUND=`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX_VERSION.sdk
203       SDKROOT=`xcode-select -print-path`/SDKs/MacOSX$OSX_VERSION.sdk
204       echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
205    fi
206    if [ ! -d "${SDKROOT}" ]
207    then
208       SDKROOT_NOT_FOUND="$SDKROOT"
209       SDKROOT=`xcrun --show-sdk-path`
210       echo "SDKROOT not found at $SDKROOT_NOT_FOUND, trying $SDKROOT"
211    fi
212
213    if [ ! -d "${SDKROOT}" ]
214    then
215       echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
216       exit 1
217    fi
218
219    add_make "MACOSX_SDK=${SDKROOT}"
220    add_make "OSX_VERSION ?= ${OSX_VERSION}"
221 }
222
223 check_android_sdk()
224 {
225         [ -z "${ANDROID_NDK}" ] && echo "You must set ANDROID_NDK environment variable" && exit 1
226         add_make "ANDROID_NDK := ${ANDROID_NDK}"
227         [ -z "${ANDROID_ABI}" ] && echo "You must set ANDROID_ABI environment variable" && exit 1
228         add_make "ANDROID_ABI := ${ANDROID_ABI}"
229         [ -z "${ANDROID_API}" ] && echo "You should set ANDROID_API environment variable (using default android-9)" && ANDROID_API := android-9
230         add_make "ANDROID_API := ${ANDROID_API}"
231         [ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_NEON"
232         [ ${ANDROID_ABI} = "armeabi-v7a" ] && add_make_enabled "HAVE_ARMV7A"
233         [ ${ANDROID_ABI} = "arm64-v8a" ] && add_make_enabled "HAVE_NEON"
234         [ ${ANDROID_ABI} = "arm64-v8a" ] && add_make_enabled "HAVE_ARMV8A"
235         [ ${ANDROID_ABI} = "armeabi" -a -z "${NO_ARMV6}" ] && add_make_enabled "HAVE_ARMV6"
236 }
237
238 check_tizen_sdk()
239 {
240         [ -z "${TIZEN_SDK}" ] && echo "You must set TIZEN_SDK environment variable" && exit 1
241         add_make "TIZEN_SDK := ${TIZEN_SDK}"
242         [ -z "${TIZEN_ABI}" ] && echo "You must set TIZEN_ABI environment variable" && exit 1
243         add_make "TIZEN_ABI := ${TIZEN_ABI}"
244         [ ${TIZEN_ABI} = "armv7l" ] && add_make_enabled "HAVE_NEON"
245         [ ${TIZEN_ABI} = "armv7l" ] && add_make_enabled "HAVE_ARMV7A"
246 }
247
248 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
249 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
250 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
251 test -z "$BUILD_NETWORK" || add_make_enabled "BUILD_NETWORK"
252 test -z "$ENABLE_SMALL" || add_make_enabled "ENABLE_SMALL"
253 test -z "$GPL" || add_make_enabled "GPL"
254 test -z "$GNUV3" || add_make_enabled "GNUV3"
255 test -z "$WITH_OPTIMIZATION" || add_make_enabled "WITH_OPTIMIZATION"
256 test "`uname -o`" != "Msys" || add_make "CMAKE_GENERATOR := -G \"MSYS Makefiles\""
257
258 #
259 # Checks
260 #
261 OS="${HOST#*-}" # strip architecture
262 case "${OS}" in
263         *-darwin*)
264                 if test -z "$BUILDFORIOS"
265                 then
266                         check_macosx_sdk
267                         add_make_enabled "HAVE_MACOSX" "HAVE_DARWIN_OS" "HAVE_BSD"
268                 else
269                         check_ios_sdk
270                         add_make_enabled "HAVE_IOS" "HAVE_DARWIN_OS" "HAVE_BSD" "HAVE_FPU"
271
272                         case "${HOST}" in
273                                 *arm*)
274                                 add_make_enabled "HAVE_NEON" "HAVE_ARMV7A"
275                                 ;;
276                         esac;
277                 fi
278                 if test "$BUILDFORTVOS"
279                 then
280                         add_make_enabled "HAVE_TVOS"
281                 fi
282                 ;;
283         *bsd*)
284                 add_make_enabled "HAVE_BSD"
285                 ;;
286         *android*)
287                 check_android_sdk
288                 add_make_enabled "HAVE_LINUX" "HAVE_ANDROID"
289                 case "${HOST}" in
290                         *arm*)
291                         add_make "PLATFORM_SHORT_ARCH := arm"
292                         ;;
293                         *arm64*|*aarch64*)
294                         add_make "PLATFORM_SHORT_ARCH := arm64"
295                         ;;
296                         *i686*)
297                         add_make "PLATFORM_SHORT_ARCH := x86"
298                         ;;
299                         *x86_64*)
300                         add_make "PLATFORM_SHORT_ARCH := x86_64"
301                         ;;
302                         *mipsel*)
303                         add_make "PLATFORM_SHORT_ARCH := mips"
304                         ;;
305                 esac
306                 ;;
307         *linux*)
308                 if [ "`${CC} -v 2>&1 | grep tizen`" ]; then
309                         check_tizen_sdk
310                         add_make_enabled "HAVE_TIZEN"
311                         case "${HOST}" in
312                                 *arm*)
313                                 add_make "PLATFORM_SHORT_ARCH := arm"
314                                 ;;
315                                 *i386*)
316                                 add_make "PLATFORM_SHORT_ARCH := x86"
317                                 ;;
318                         esac
319                 fi
320
321                 add_make_enabled "HAVE_LINUX"
322                 ;;
323         *mingw*)
324                 add_make_enabled "HAVE_WIN32"
325                 case "${HOST}" in
326                         *winphone*|*windowsphone*)
327                         add_make_enabled "HAVE_WINDOWSPHONE"
328                         ;;
329                 esac
330                 case "${HOST}" in
331                         *winphone*|*windowsphone*|*winrt*|*uwp*)
332                         add_make_enabled "HAVE_WINSTORE"
333                         ;;
334                 esac
335                 case "${HOST}" in
336                         amd64*|x86_64*)
337                         add_make_enabled "HAVE_WIN64"
338                         ;;
339                 esac
340         case "${HOST}" in
341             armv7*)
342                 add_make_enabled "HAVE_ARMV7A"
343                 ;;
344         esac
345                 ;;
346         *solaris*)
347                 add_make_enabled "HAVE_SOLARIS"
348                 ;;
349 esac
350
351 #
352 # Results output
353 #
354 test -e Makefile && unlink Makefile
355 ln -sf ../../contrib/src/main.mak Makefile || exit $?
356 echo "Bootstrap completed."
357 make help
358 mkdir -p ../../contrib/tarballs || exit $?