435654ff8e5c47166c9efe45f6cabd3de4ded38b
[vuplus_xbmc] / tools / depends / configure.in
1 AC_PREREQ(2.59)
2 AC_INIT([xbmc-depends], [2.00], [http://trac.xbmc.org])
3 :${CFLAGS=""}
4 AC_CONFIG_AUX_DIR([build-aux])
5 AC_CONFIG_FILES([target/config.site native/config.site.native Makefile.include target/Toolchain.cmake])
6 AC_CANONICAL_HOST
7 m4_include([../../m4/xbmc_arch.m4])
8
9 AC_ARG_WITH([toolchain],
10   [AS_HELP_STRING([--with-toolchain],
11   [specify path to toolchain. Required for android. Defaults to xcode root for darwin, /usr for linux])],
12   [use_toolchain=$withval])
13
14 AC_ARG_WITH([tarballs],
15   [AS_HELP_STRING([--with-tarballs],
16   [path where tarballs will be saved [prefix/xbmc-tarballs]])],
17   [use_tarballs=$withval])
18
19 AC_ARG_WITH([cpu],
20   [AS_HELP_STRING([--with-cpu],
21   [optional. specify target cpu. guessed if not specified])],
22   [use_cpu=$withval],use_cpu=auto)
23
24 AC_ARG_WITH([ndk],
25   [AS_HELP_STRING([--with-ndk],
26   [specify path to ndk (required for android only)])],
27   [use_ndk=$withval])
28
29 AC_ARG_WITH([sdk-path],
30   [AS_HELP_STRING([--with-sdk-path],
31   [specify path to sdk (required for android only)])],
32   [use_sdk_path=$withval])
33
34 AC_ARG_WITH([sdk],
35   [AS_HELP_STRING([--with-sdk],
36   [spcify sdk platform version (optional for android). default is android-14])],
37   [use_sdk=$withval])
38
39 AC_ARG_ENABLE([gplv3],
40   [AS_HELP_STRING([--enable-gplv3],
41   [enable gplv3 components. default off for android, on everywhere else])],
42   [use_gplv3=1], [use_gplv3=auto])
43
44
45 AC_CHECK_PROG(HAVE_UNZIP,unzip,"yes","no",)
46 if test "x$HAVE_UNZIP" = "xno" ; then
47   AC_MSG_ERROR("Missing program: unzip")
48 fi
49
50 AC_CHECK_PROG(HAVE_ZIP,zip,"yes","no",)
51 if test "x$HAVE_ZIP" = "xno" ; then
52   AC_MSG_ERROR("Missing program: zip")
53 fi
54
55 AC_PATH_PROG(CURL,curl,"no")
56 if test "x$CURL" = "xno" ; then
57   AC_MSG_ERROR("Missing program: curl")
58 fi
59
60 AC_PATH_PROG(TAR,tar,"no")
61 if test "x$TAR" = "xno" ; then
62   AC_MSG_ERROR("Missing program: tar")
63 fi
64
65 use_host=$host_alias
66
67 if test "x$host" = "x$build"; then
68 use_host=$build_cpu-$build_os
69 fi
70
71 deps_dir=$use_host
72 tool_dir=$build_cpu-$build_os-native
73 cross_compiling="yes"
74
75 if test "x$host" = "x$build"; then
76   cross_compiling="no"
77 fi
78
79 passed_cflags="$CFLAGS"
80 passed_ldflags="$LDFLAGS"
81 passed_cxxflags="$CXXFLAGS"
82 platform_cc=gcc
83 platform_cxx=g++
84 case $host in
85   arm*-*linux-android*)
86     if test "x$use_cpu" = "xauto"; then
87       use_cpu="armeabi-v7a"
88     fi
89     use_sdk="${use_sdk:-android-14}"
90     deps_dir="$use_host-$use_sdk"
91     platform_cflags="-DANDROID -Os -fexceptions"
92     if test "x$use_cpu" = "xarmeabi-v7a"; then
93       platform_cflags+=" -march=armv7-a -mtune=cortex-a9 -mfloat-abi=softfp -mfpu=neon"
94     fi
95     platform_ldflags="-L$prefix/$deps_dir/lib/$use_sdk"
96     platform_cxxflags="$platform_cflags -frtti"
97     platform_includes="-I$prefix/$deps_dir/include/$use_sdk"
98     platform_os="android"
99     if test "x$use_gplv3" = "xauto"; then
100       use_gplv3=0
101     fi
102     #android builds are always cross
103     cross_compiling="yes"
104   ;;     
105   i*86*-linux-android*)
106     if test "x$use_cpu" = "xauto"; then
107       use_cpu=$host_cpu
108     fi
109     use_sdk="${use_sdk:-android-14}"
110     deps_dir="$use_host-$use_sdk"
111     platform_cflags="-DANDROID -Os -fexceptions"
112     platform_ldflags="-L$prefix/$deps_dir/lib/$use_sdk"
113     platform_cxxflags="$platform_cflags -frtti"
114     platform_includes="-I$prefix/$deps_dir/include/$use_sdk"
115     platform_os="android"
116     if test "x$use_gplv3" = "xauto"; then
117       use_gplv3=0
118     fi
119     #android builds are always cross
120     cross_compiling="yes"
121   ;;
122   arm*-*-linux-gnu*)
123     if test "x$use_cpu" = "xauto"; then
124       use_cpu=$host_cpu
125     fi
126     use_toolchain="${use_toolchain:-/usr}"
127     platform_cflags="-Os -fPIC -DPIC"
128     platform_ldflags="-Wl,-rpath-link=$prefix/$deps_dir/lib"
129     platform_cxxflags="$platform_cflags"
130     platform_os="linux"
131   ;;
132   *i686*-linux-gnu*)
133     use_cpu=$host_cpu
134     use_toolchain="${use_toolchain:-/usr}"
135     platform_os="linux"
136   ;;
137   x86_64*-linux-gnu*)
138     use_cpu=$host_cpu
139     use_toolchain="${use_toolchain:-/usr}"
140     platform_cflags="-fPIC -DPIC"
141     platform_cxxflags="$platform_cflags"
142     platform_os="linux"
143   ;;
144   *darwin*)
145     if test "x$prefix" = "xNONE"; then
146       prefix=/Users/Shared/xbmc-depends
147     fi
148     use_tarballs="${use_tarballs:-$prefix/tarballs}"
149     use_xcodepath=`xcode-select -print-path`
150     use_xcodebuild=$use_xcodepath/usr/bin/xcodebuild
151     use_xcode=[`$use_xcodebuild -version | grep Xcode | awk '{ print $2}'`]
152     AC_MSG_RESULT(found xcodebuild at $use_xcodebuild)
153     use_build_toolchain=$use_xcodepath
154
155     #darwin builds are always cross
156     cross_compiling="yes"
157
158     platform_cflags="-std=gnu99 -no_compact_linkedit -no-cpp-precomp"
159     platform_ldflags="-Wl,-search_paths_first -no_compact_linkedit"
160     platform_cxxflags="-no_compact_linkedit -no-cpp-precomp"
161
162     case $use_xcode in
163       3.*.*)
164         platform_cc=gcc-4.2
165         platform_cxx=g++-4.2
166         ;;
167       4.*.*)
168         platform_cc=llvm-gcc-4.2
169         platform_cxx=llvm-g++-4.2
170         ;; 
171       *)
172         platform_cc=clang
173         platform_cxx=clang++
174         platform_cflags="-fheinous-gnu-extensions -no-cpp-precomp -no-integrated-as"
175         platform_ldflags="-Wl,-search_paths_first"
176         platform_cxxflags="-no-cpp-precomp"
177         ;;
178     esac
179     case $host in
180       *86*-apple-darwin)
181         found_sdk_version=[`$use_xcodebuild -showsdks | grep macosx | sort |  tail -n 1 | grep -oE 'macosx[0-9.0-9]+' | cut -c 7-$NF`]
182         case $use_xcode in
183           5.* | 5.*.* )
184             use_toolchain="${use_xcodepath}/Toolchains/XcodeDefault.xctoolchain"
185             ;;
186           *)
187             use_toolchain="${use_toolchain:-$use_xcodepath}"
188             ;;
189         esac
190         use_sdk="${use_sdk:-$found_sdk_version}"
191         if test "$use_cpu" = "armv7"; then
192           AC_MSG_ERROR(error in configure of --with-arch=$use_cpu)
193         fi
194         case $use_sdk in
195           10.5);;
196           10.6);;
197           10.7);;
198           10.8);;
199           10.9);;
200           *)
201             AC_MSG_ERROR(error in configure of --with-sdk=$use_sdk)
202         esac
203         sdk_name=macosx$use_sdk
204         use_sdk_path=[`$use_xcodebuild -version -sdk $sdk_name Path`]
205
206         case $host in
207           x86_64-apple-darwin*)
208             if test "x$use_cpu" = "xauto"; then
209               use_cpu=x86_64
210             fi
211           ;;
212           i*86-apple-darwin*)
213             if test "x$use_cpu" = "xauto"; then
214               use_cpu=i386
215             fi
216           ;;
217           *)
218             AC_MSG_ERROR(error in configure of --with-arch=$use_cpu)
219         esac
220         platform_os="osx"
221         platform_min_version=macosx-version-min=10.6
222       ;;
223
224       arm-apple-darwin*)
225         if test "x$use_cpu" = "xauto"; then
226           use_cpu=armv7
227         fi
228         if test "$use_cpu" != "armv7"; then
229           AC_MSG_ERROR(error in configure of --with-arch=$use_cpu)
230         fi
231         platform_min_version="iphoneos-version-min=4.2"
232         found_sdk_version=[`$use_xcodebuild -showsdks | grep iphoneos | sort | tail -n 1 | awk '{ print $2}'`]
233         use_sdk="${use_sdk:-$found_sdk_version}"
234         sdk_name=iphoneos$use_sdk
235         case $use_xcode in
236           5.* | 5.*.* )
237             use_toolchain="${use_xcodepath}/Toolchains/XcodeDefault.xctoolchain"
238             ;;
239           *)
240             use_toolchain="${use_toolchain:-`$use_xcodebuild -version -sdk $sdk_name PlatformPath`/Developer}"
241             ;;
242         esac
243         
244         case $use_sdk in
245           4.*);;
246           5.*);;
247           6.*);;
248           7.*);;
249             *)
250               AC_MSG_ERROR(error in configure of --with-sdk=$use_sdk)
251             ;;
252         esac
253         use_sdk_path=[`$use_xcodebuild -version -sdk $sdk_name | grep ^Path | awk '{ print $2}'`]
254         platform_os="ios"
255         tmp_flags="-mcpu=cortex-a8 -mfpu=neon -ftree-vectorize -mfloat-abi=softfp -pipe -Wno-trigraphs -fpascal-strings -O3 -Wreturn-type -Wunused-variable -fmessage-length=0 -gdwarf-2"
256         platform_cflags+=" $tmp_flags"
257         platform_ldflags+=" -L$use_sdk_path/usr/lib/system"
258         platform_cxxflags+=" $tmp_flags"
259       ;;
260     esac
261     platform_cflags+=" -arch $use_cpu -m$platform_min_version"
262     platform_ldflags+=" -arch $use_cpu -m$platform_min_version -isysroot $use_sdk_path"
263     platform_cxxflags+=" -arch $use_cpu -m$platform_min_version"
264     platform_includes="-isysroot $use_sdk_path"
265     deps_dir=$sdk_name"_"$use_cpu-target
266     tool_dir=buildtools-native;
267   ;;
268   *)
269     AC_MSG_ERROR(unsupported host ($use_host))
270 esac
271
272 XBMC_SETUP_ARCH_DEFINES()
273
274 platform_cflags+=" $passed_cflags"
275 platform_ldflags+=" $passed_ldflags $LIBS"
276 platform_cxxflags+=" $passed_cxxflags"
277
278 if test -n $use_build_toolchain; then
279   PATH_FOR_HOST=$use_toolchain:$use_toolchain/usr/bin:$use_toolchain/bin:$PATH
280 else
281   PATH_FOR_HOST=$PATH
282 fi
283 if test -n $use_build_toolchain; then
284   PATH_FOR_BUILD=$use_build_toolchain:$use_build_toolchain/usr/bin:$use_toolchain/bin:$PATH
285 else
286   PATH_FOR_BUILD=$PATH
287 fi
288
289 AC_PATH_TOOL([RANLIB], [ranlib],, $PATH_FOR_HOST)
290 AC_PATH_TOOL([LD], [ld],, $PATH_FOR_HOST)
291 AC_PATH_TOOL([AR], [ar],, $PATH_FOR_HOST)
292 AC_PATH_TOOL([READELF], [readelf],, $PATH_FOR_HOST)
293 AC_PATH_TOOL([STRIP], [strip],, $PATH_FOR_HOST)
294 AC_PATH_TOOL([AS], [as],, $PATH_FOR_HOST)
295 AC_PATH_TOOL([NM], [nm],, $PATH_FOR_HOST)
296 AC_PATH_TOOL([OBJDUMP], [objdump],, $PATH_FOR_HOST)
297 AC_PATH_TOOL([CC],[$platform_cc],,$PATH_FOR_HOST)
298 AC_PATH_TOOL([CXX],[$platform_cxx],,$PATH_FOR_HOST)
299 AC_PROG_CPP
300
301 AC_PATH_PROG([RANLIB_FOR_BUILD], [ranlib], ranlib, $PATH_FOR_BUILD)
302 AC_PATH_PROG([LD_FOR_BUILD], [ld], ld, $PATH_FOR_BUILD)
303 AC_PATH_PROG([AR_FOR_BUILD], [ar], ar, $PATH_FOR_BUILD)
304 AC_PATH_PROG([READELF_FOR_BUILD], [readelf], readelf, $PATH_FOR_BUILD)
305 AC_PATH_PROG([STRIP_FOR_BUILD], [strip], strip, $PATH_FOR_BUILD)
306 AC_PATH_PROG([AS_FOR_BUILD], [as], as, $PATH_FOR_BUILD)
307 AC_PATH_PROG([NM_FOR_BUILD], [nm], nm, $PATH_FOR_BUILD)
308 AC_PATH_PROG([OBJDUMP_FOR_BUILD], [objdump], objdump, $PATH_FOR_BUILD)
309 AC_PATH_PROG([CC_FOR_BUILD],[gcc llvm-gcc $platform_cc], gcc, $PATH_FOR_BUILD)
310 AC_PATH_PROG([CXX_FOR_BUILD],[g++ llvm-g++ $platform_cxx], g++, $PATH_FOR_BUILD)
311
312 AC_CHECK_LIB([z],   [main], has_zlib=1, AC_MSG_WARN("No zlib support in toolchain. Will build libz."); has_zlib=0)
313 AC_SEARCH_LIBS([iconv_open],iconv, link_iconv=$ac_cv_search_iconv_open, link_iconv=-liconv; AC_MSG_WARN("No iconv support in toolchain. Will build libiconv."); need_libiconv=1)
314 AC_TRY_LINK([#include <locale.h>],[struct lconv* test=localeconv();], has_localeconv=yes, AC_MSG_WARN("No localeconv support in toolchain. Using replacement."); has_localeconv=no)
315 AC_CHECK_LIB([crystax],   [main], has_libcrystax=1, has_libcrystax=0)
316
317 if test "x$use_gplv3" = "xauto"; then
318   use_gplv3=1
319 fi
320
321 if test "$link_iconv" = "none required"; then
322   link_iconv=
323 fi
324
325 if test "x$prefix" = "xNONE"; then
326   AC_MSG_ERROR([No prefix path defined. Use for ex: --prefix=/opt/xbmc-depends]);
327 fi
328
329 if test -z $use_tarballs; then
330   use_tarballs=$prefix/xbmc-tarballs
331 fi
332
333 if test "$platform_os" == "android"; then
334   if test -z $use_ndk; then
335     AC_MSG_ERROR("NDK path is required for android")
336   fi
337
338   if test -z $use_sdk_path; then
339     AC_MSG_ERROR("SDK path is required for android")
340   fi
341
342   if [ ! test -f $use_sdk_path/tools/zipalign ]; then
343     AC_MSG_ERROR(verify sdk path)
344   fi
345
346   if [ ! test -f $use_ndk/sources/android/native_app_glue/android_native_app_glue.h ]; then
347     AC_MSG_ERROR(verify ndk path)
348   fi
349 fi
350
351 # Some dumb checks to see if paths might be correct.
352 if [ ! `mkdir -p $prefix/$deps_dir/include` ]; then
353   AC_MSG_ERROR(unable to create $prefix/$deps_dir/include. verify that the path and permissions are correct.)
354 fi
355
356 if [ ! `mkdir -p $prefix/$deps_dir/lib` ]; then
357   AC_MSG_ERROR(unable to create $prefix/$deps_dir/lib. verify that the path and permissions are correct.)
358 fi
359
360 if [ ! `mkdir -p $prefix/$deps_dir/share` ]; then
361   AC_MSG_ERROR(unable to create $prefix/$deps_dir/share. verify that the path and permissions are correct.)
362 fi
363
364 if [ ! `mkdir -p $prefix/$tool_dir/include` ]; then
365   AC_MSG_ERROR(unable to create $prefix/$tool_dir/include. verify that the path and permissions are correct.)
366 fi
367
368 if [ ! `mkdir -p $prefix/$tool_dir/lib` ]; then
369   AC_MSG_ERROR(unable to create $prefix/$tool_dir/lib. verify that the path and permissions are correct.)
370 fi
371
372 if [ ! `mkdir -p $prefix/$tool_dir/share` ]; then
373   AC_MSG_ERROR(unable to create $prefix/$tool_dir/share. verify that the path and permissions are correct.)
374 fi
375
376 if [ ! `mkdir -p $prefix/$tool_dir/bin` ]; then
377   AC_MSG_ERROR(unable to create $prefix/$tool_dir/share. verify that the path and permissions are correct.)
378 fi
379
380 if [ ! `mkdir -p $use_tarballs` ]; then
381   AC_MSG_ERROR(unable to create tarballs dir. verify that the path and permissions are correct.)
382 fi
383
384 if test "$platform_os" == "android"; then
385   echo
386
387   if [ ! `mkdir -p $prefix/$deps_dir/include/$use_sdk` ]; then
388     AC_MSG_ERROR(unable to create $prefix/$deps_dir/include/$use_sdk. verify that the path and permissions are correct.)
389   fi
390
391   if [ ! `mkdir -p $prefix/$deps_dir/lib/$use_sdk` ]; then
392     AC_MSG_ERROR(unable to create $prefix/$deps_dir/lib/$use_sdk. verify that the path and permissions are correct.)
393   fi
394 fi
395
396 if test "$platform_os" == "android"; then
397 echo -e
398   AC_SUBST(use_sdk_path)
399   AC_SUBST(use_ndk)
400   AC_SUBST(use_sdk)
401 fi
402
403 AC_SUBST(use_host)
404 AC_SUBST(deps_dir)
405 AC_SUBST(tool_dir)
406 AC_SUBST(use_cpu)
407 AC_SUBST(use_toolchain)
408 AC_SUBST(use_build_toolchain)
409 AC_SUBST(use_tarballs)
410 AC_SUBST(cross_compiling)
411 AC_SUBST(platform_cflags)
412 AC_SUBST(platform_cxxflags)
413 AC_SUBST(platform_ldflags)
414 AC_SUBST(platform_includes)
415 AC_SUBST(platform_os)
416 AC_SUBST(has_zlib)
417 AC_SUBST(link_iconv)
418 AC_SUBST(need_libiconv)
419 AC_SUBST(use_gplv3)
420 AC_SUBST(has_libcrystax)
421 AC_SUBST(use_xcode)
422
423 AC_OUTPUT
424 echo -e "toolchain:\t $use_toolchain"
425 echo -e "cpu:\t\t $use_cpu"
426 echo -e "host:\t\t $use_host"
427 if test "$platform_os" == "android"; then
428   echo -e "sdk-platform:\t $use_sdk"
429 fi
430
431 if test "$platform_os" == "ios"; then
432   simulator_sdk_path=[`$use_xcodebuild -version -sdk iphonesimulator$use_sdk | grep ^Path | awk '{ print $2}'`]
433   cp -vf $simulator_sdk_path/usr/include/crt_externs.h $prefix/$deps_dir/include
434 fi
435
436 if test "x$has_localeconv" == "xno" && test "$platform_os" == "android"; then
437   cp -vf target/android-libc-replacements/locale.h $prefix/$deps_dir/include/
438 fi
439
440 cp -vf target/config.site $prefix/$deps_dir/share
441 cp -vf target/Toolchain.cmake $prefix/$deps_dir/share
442 cp -vf native/config.site.native $prefix/$tool_dir/share/config.site