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