aboutsummaryrefslogtreecommitdiff
path: root/tools/depends/configure.ac
blob: 232f741e4bd654faf392801197578ee25f784d10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
AC_PREREQ(2.59)
AC_INIT([xbmc-depends], [2.00], [http://trac.xbmc.org])
:${CFLAGS=""}
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_FILES([target/config.site native/config.site.native Makefile.include target/Toolchain.cmake
                 target/config-binaddons.site target/Toolchain_binaddons.cmake])
AC_CANONICAL_HOST

m4_include([m4/xbmc_arch.m4])
m4_include([m4/ax_cxx_compile_stdcxx_11.m4])

# check for not same cpu value
AC_DEFUN([MC_CHECK_NOT_CPU],
[
  AC_MSG_CHECKING([for $2])
  case $1 in
    $2*)
      AC_MSG_ERROR(error in configure of --with-cpu=$1)
      ;;
    *)
      AC_MSG_RESULT([$1 is not $2])
  esac
])

AC_ARG_ENABLE([debug],
  [AS_HELP_STRING([--enable-debug],
  [enable debugging information (default is yes)])],
  [use_debug=$enableval],
  [use_debug=yes])

AC_ARG_ENABLE([ccache],
  [AS_HELP_STRING([--disable-ccache],
  [disable ccache])],
  [use_ccache=no],
  [use_ccache=yes])

AC_ARG_WITH([toolchain],
  [AS_HELP_STRING([--with-toolchain],
  [specify path to toolchain. Required for android. Defaults to xcode root for darwin, /usr for linux])],
  [use_toolchain=$withval])

AC_ARG_WITH([platform],
  [AS_HELP_STRING([--with-platform],
  [target platform [auto]])],
  [use_platform=$withval],
  [use_platform=auto])

AC_ARG_WITH([firmware],
  [AS_HELP_STRING([--with-firmware],
  [platform specific firmware []])],
  [use_firmware=$withval])

AC_ARG_WITH([tarballs],
  [AS_HELP_STRING([--with-tarballs],
  [path where tarballs will be saved [prefix/xbmc-tarballs]])],
  [use_tarballs=$withval])

AC_ARG_WITH([cpu],
  [AS_HELP_STRING([--with-cpu],
  [optional. specify target cpu. guessed if not specified])],
  [use_cpu=$withval],
  [use_cpu=auto])

AC_ARG_WITH([ndk-path],
  [AS_HELP_STRING([--with-ndk-path],
  [specify path to ndk (required for android only)])],
  [use_ndk_path=$withval])

AC_ARG_WITH([sdk-path],
  [AS_HELP_STRING([--with-sdk-path],
  [specify path to sdk (required for android only)])],
  [use_sdk_path=$withval])

AC_ARG_WITH([sdk],
  [AS_HELP_STRING([--with-sdk],
  [specify sdk platform version (optional for android). default is android-24])],
  [use_sdk=$withval])

AC_ARG_WITH([ndk-api],
  [AS_HELP_STRING([--with-ndk-api],
  [specify ndk level (optional for android). default is 21])],
  [use_ndk_api=$withval])

AC_ARG_ENABLE([gplv3],
  [AS_HELP_STRING([--enable-gplv3],
  [enable gplv3 components. default is yes])],
  [use_gplv3=$enableval],
  [use_gplv3=yes])

AC_ARG_ENABLE([wayland],
  [AS_HELP_STRING([--enable-wayland],
  [build libraries needed for Wayland. default is no])],
  [enable_wayland=$enableval],
  [enable_wayland=no])

AC_ARG_WITH([rendersystem],
  [AS_HELP_STRING([--with-rendersystem],
  [render system to use])],
  [app_rendersystem=$withval])

AC_ARG_WITH([target-cflags],
  [AS_HELP_STRING([--with-target-cflags],
  [C compiler flags (target)])],
  [target_cflags=$withval])

AC_ARG_WITH([target-cxxflags],
  [AS_HELP_STRING([--with-target-cxxflags],
  [C++ compiler flags (target)])],
  [target_cxxflags=$withval],
  [target_cxxflags=$target_cflags])

AC_ARG_WITH([target-ldflags],
  [AS_HELP_STRING([--with-target-ldflags],
  [linker flags. Use e.g. for -l<lib> (target)])],
  [target_ldflags=$withval])

AC_ARG_WITH([ffmpeg-options],
  [AS_HELP_STRING([--with-ffmpeg-options],
  [FFmpeg configure options, e.g. --enable-vaapi (target)])],
  [ffmpeg_options=$withval],
  [ffmpeg_options=default])


OLD_PATH="${PATH}"
if test -n "$use_toolchain"; then
  PATH="${use_toolchain}/bin:${use_toolchain}/usr/bin:$PATH"
  case $host in
    arm*-*linux-android*|aarch64*-*linux-android*)
      COMPILER_LIST="clang++ gcc g++"
    ;;
    *)
      COMPILER_LIST=""
    ;;
  esac
fi
AC_PROG_CXX([$COMPILER_LIST])
AX_CXX_COMPILE_STDCXX_11([noext],[mandatory])
c11_flags=$(echo "$CFLAGS" | sed 's/-O@<:@123@:>@//g;s/-g //g;s/ //g')
cxx11_flags=$(echo "$CXXFLAGS" | sed 's/-O@<:@123@:>@//g;s/-g //g;s/ //g')
PATH="${OLD_PATH}"

if test "$use_ccache" = "yes"; then
  AC_CHECK_PROG(HAVE_CCACHE,ccache,"yes","no",)
  if test "x$HAVE_CCACHE" = "xno" ; then
    use_ccache=no
  fi
fi

AC_PATH_PROG(CURL,curl,"no")
if test "x$CURL" = "xno" ; then
  AC_MSG_ERROR("Missing program: curl")
fi

AC_PATH_PROG(TAR,tar,"no")
if test "x$TAR" = "xno" ; then
  AC_MSG_ERROR("Missing program: tar")
fi

if test "$use_debug" = "yes"; then
  build_type="debug"
else
  build_type="release"
fi

use_host=$host_alias

cross_compiling="yes"
if test "x$host" = "x$build"; then
  use_host=$build_cpu-$build_os
  cross_compiling="no"
fi

deps_dir=$use_host-$build_type
tool_dir=$build_cpu-$build_os-native
cross_compiling="yes"

platform_cc=gcc
platform_cxx=g++

case $build in
  arm*-*-linux-gnu*|arm*-*-linux-uclibc*)
    build_os="linux"
  ;;
  *i686*-linux-gnu*|i*86*-*-linux-uclibc*)
    build_os="linux"
  ;;
  x86_64*-linux-gnu*|x86_64-*-linux-uclibc*)
    build_os="linux"
  ;;
  *darwin*)
    build_os="osx"
  ;;
  *)
    AC_MSG_ERROR(unsupported native build platform: $build)
esac


case $host in
  arm*-*linux-android*)
    if test "x$use_cpu" = "xauto"; then
      use_cpu="armeabi-v7a"
    fi
    platform_cc=clang
    platform_cxx=clang++
    use_sdk="${use_sdk:-android-24}"
    use_ndk_api="${use_ndk_api:-21}"
    deps_dir="$use_host-$use_ndk_api-$build_type"
    platform_cflags="-DANDROID -D__ANDROID_API__=$use_ndk_api -fexceptions -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fPIC -DPIC -D_GLIBCXX_USE_C99_MATH_TR1"
    optimize_flags="-Os"
    if test "x$use_cpu" = "xarmeabi-v7a"; then
      platform_cflags+=" -march=armv7-a -mtune=cortex-a9 -mfloat-abi=softfp -mfpu=neon"
    fi
    platform_ldflags="-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--exclude-libs,libunwind.a -L$prefix/$deps_dir/lib/android-$use_ndk_api"
    platform_cxxflags="$platform_cflags -frtti"
    platform_includes="-I$prefix/$deps_dir/include/android-$use_ndk_api"
    platform_os="android"
    #android builds are always cross
    cross_compiling="yes"
  ;;
  aarch64*-*linux-android*)
    if test "x$use_cpu" = "xauto"; then
      use_cpu="arm64-v8a"
    fi
    platform_cc=clang
    platform_cxx=clang++
    use_sdk="${use_sdk:-android-24}"
    use_ndk_api="${use_ndk_api:-21}"
    deps_dir="$use_host-$use_ndk_api-$build_type"
    platform_cflags="-DANDROID -D__ANDROID_API__=$use_ndk_api -fexceptions -funwind-tables -fstack-protector-strong -no-canonical-prefixes  -fPIC -DPIC -D_GLIBCXX_USE_C99_MATH_TR1"
    optimize_flags="-Os"
    if test "x$use_cpu" = "xarm64-v8a"; then
      platform_cflags+=" -march=armv8-a -mtune=cortex-a53"
    fi
    platform_ldflags="-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -L$prefix/$deps_dir/lib/android-$use_ndk_api"
    platform_cxxflags="$platform_cflags -frtti"
    platform_includes="-I$prefix/$deps_dir/include/android-$use_ndk_api"
    platform_os="android"
    #android builds are always cross
    cross_compiling="yes"
  ;;
  i*86*-linux-android*)
    if test "x$use_cpu" = "xauto"; then
      use_cpu=$host_cpu
    fi
    platform_cc=clang
    platform_cxx=clang++
    use_sdk="${use_sdk:-android-24}"
    use_ndk_api="${use_ndk_api:-21}"
    deps_dir="$use_host-$use_ndk_api-$build_type"
    platform_cflags="-DANDROID -D__ANDROID_API__=$use_ndk_api -fexceptions -funwind-tables -fstack-protector-strong -no-canonical-prefixes  -fPIC -DPIC -D_GLIBCXX_USE_C99_MATH_TR1"
    optimize_flags="-Os"
    platform_ldflags="-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -L$prefix/$deps_dir/lib/android-$use_ndk_api"
    platform_cxxflags="$platform_cflags -frtti"
    platform_includes="-I$prefix/$deps_dir/include/android-$use_ndk_api"
    platform_os="android"
    #android builds are always cross
    cross_compiling="yes"
  ;;
  arm*-*-linux-gnu*|arm*-*-linux-uclibc*)
    if test "$use_platform" = "auto"; then
      if test "x$use_cpu" = "xauto"; then
        use_cpu=$host_cpu
      fi
      use_toolchain="${use_toolchain:-/usr}"
      platform_cflags="-fPIC -DPIC"
      optimize_flags="-Os"
      platform_ldflags="-Wl,-rpath-link=$prefix/$deps_dir/lib"
      platform_cxxflags="$platform_cflags"
      platform_os="linux"
    fi
  ;;
  aarch64*-*-linux-gnu*|aarch*-*-linux-be*)
    if test "$use_platform" = "auto"; then
      if test "x$use_cpu" = "xauto"; then
        use_cpu=$host_cpu
      fi
      use_toolchain="${use_toolchain:-/usr}"
      platform_cflags="-fPIC -DPIC"
      optimize_flags="-Os"
      platform_ldflags="-Wl,-rpath-link=$prefix/$deps_dir/lib"
      platform_cxxflags="$platform_cflags"
      platform_os="linux"
    fi
  ;;
  *i686*-linux-gnu*|i*86*-*-linux-uclibc*)
    use_cpu=$host_cpu
    use_toolchain="${use_toolchain:-/usr}"
    platform_cflags="-fPIC -DPIC"
    optimize_flags="-O2"
    platform_cxxflags="$platform_cflags"
    platform_os="linux"
    ffmpeg_options_default="--enable-vaapi --enable-vdpau --cpu=$use_cpu"
  ;;
  x86_64*-linux-gnu*|x86_64-*-linux-uclibc*)
    use_cpu=$host_cpu
    use_toolchain="${use_toolchain:-/usr}"
    platform_cflags="-fPIC -DPIC"
    optimize_flags="-O2"
    platform_cxxflags="$platform_cflags"
    platform_os="linux"
    ffmpeg_options_default="--enable-vaapi --enable-vdpau --cpu=$use_cpu"
  ;;
  *darwin*)
    if test "x$prefix" = "xNONE"; then
      prefix=/Users/Shared/xbmc-depends
    fi

    native_platform_min_version=-mmacosx-version-min=`sw_vers | grep ProductVersion | sed -E "s/.*:.*(10\..*)\.?.*/\1/"`
    use_xcodepath=`xcode-select -print-path`
    use_xcodebuild=$use_xcodepath/usr/bin/xcodebuild
    use_xcode=[`$use_xcodebuild -version | grep Xcode | awk '{ print $2}'`]
    AC_MSG_RESULT(found xcodebuild at $use_xcodebuild)
    use_build_toolchain=$use_xcodepath

    # darwin builds are always cross
    cross_compiling="yes"

    platform_cflags="-std=gnu99 -no_compact_linkedit -no-cpp-precomp"
    platform_ldflags="-Wl,-search_paths_first -no_compact_linkedit"
    platform_cxxflags="-no_compact_linkedit -no-cpp-precomp"

    case $use_xcode in
      3.*.*)
        platform_cc=gcc-4.2
        platform_cxx=g++-4.2
        ;;
      4.* | 4.*.*)
        platform_cc=llvm-gcc-4.2
        platform_cxx=llvm-g++-4.2
        ;;
      *)
        platform_cc=clang
        platform_cxx=clang++
        platform_cflags="-fheinous-gnu-extensions -no-cpp-precomp"
        platform_ldflags="-Wl,-search_paths_first"
        platform_cxxflags="-no-cpp-precomp"
        ;;
    esac
    case $host in
      *86*-apple-darwin)
        MC_CHECK_NOT_CPU([$use_cpu], "arm")

        # setup which cpu to use
        case $host in
          x86_64-apple-darwin*)
            if test "x$use_cpu" = "xauto"; then
              use_cpu=x86_64
            fi
          ;;
          i*86-apple-darwin*)
            if test "x$use_cpu" = "xauto"; then
              use_cpu=i386
            fi
            platform_ldflags+=" -read_only_relocs suppress"
         ;;
          *)
            AC_MSG_ERROR(error in configure of --with-arch=$use_cpu)
        esac

        # setup which sdk to use
        found_sdk_version=[`$use_xcodebuild -showsdks | sed -E -n 's/.*macosx([0-9]+)\.([0-9]+)/\1.\2/p' | sort  -n -t. -k1,1 -k2,2 | tail -n 1`]
        use_sdk="${use_sdk:-$found_sdk_version}"

        # now that we know which sdk, error check sdk_name
        case $use_sdk in
          10.5);;
          10.6);;
          10.7);;
          10.8);;
          10.9);;
          10.10);;
          10.11);;
          10.12);;
          10.13);;
          *)
            AC_MSG_ERROR(error in configure of --with-sdk=$use_sdk)
        esac
        sdk_name=macosx$use_sdk
        platform_min_version="macosx-version-min=10.8"

        use_sdk_path=[`$use_xcodebuild -version -sdk $sdk_name Path`]
        platform_os="osx"

        # find the matching toolchain
        case $use_xcode in
          5.* | 5.*.* )
            use_toolchain="${use_xcodepath}/Toolchains/XcodeDefault.xctoolchain"
            ;;
          *)
            use_toolchain="${use_toolchain:-$use_xcodepath}"
            ;;
        esac
      ;;

      arm-apple-darwin*)
        MC_CHECK_NOT_CPU([$use_cpu], "*86")

        # setup which sdk to use
        if test "$use_platform" = "tvos"; then
          # setup which cpu to use
          if test "x$use_cpu" = "xauto"; then
            use_cpu=arm64
          fi

          target_platform=appletvos

          found_sdk_version=[`$use_xcodebuild -showsdks | grep $target_platform | sort | tail -n 1 | awk '{ print $2}'`]
          use_sdk="${use_sdk:-$found_sdk_version}"
	  platform_cflags+=" -fembed-bitcode"
	  platform_cxxflags+=" -fembed-bitcode"
          sdk_name=$target_platform$use_sdk
          platform_min_version="$target_platform-version-min=9.0"
        else
          # setup which cpu to use
          if test "x$use_cpu" = "xauto"; then
            use_cpu=armv7
          fi

          target_platform=iphoneos

          found_sdk_version=[`$use_xcodebuild -showsdks | grep $target_platform | sort | tail -n 1 | awk '{ print $2}'`]
          use_sdk="${use_sdk:-$found_sdk_version}"
          sdk_name=$target_platform$use_sdk
          platform_min_version="$target_platform-version-min=6.0"
        fi
	case $use_sdk in
          4.*);;
          5.*);;
          6.*);;
          7.*);;
          8.*);;
          9.*);;
          10.*);;
          11.*);;
            *)
              AC_MSG_ERROR(error in configure of --with-sdk=$use_sdk)
            ;;
        esac

        # find the matching toolchain
        case $use_xcode in
          3.*.* | 4.* | 4.*.*)
            use_toolchain="${use_toolchain:-`$use_xcodebuild -version -sdk $sdk_name PlatformPath`/Developer}"
            ;;
          *)
            use_toolchain="${use_xcodepath}/Toolchains/XcodeDefault.xctoolchain"
            ;;
        esac

        platform_os="ios"

        if [ ! test "x$use_cpu" = "xarm64" ]; then
          platform_cflags+=" -mcpu=cortex-a8 -mfpu=neon"
          platform_ldflags+=" -Wl,-segalign,4000"
        fi
        platform_cflags+=" -ftree-vectorize -pipe -Wno-trigraphs -fpascal-strings"
        platform_cflags+=" -Wreturn-type -Wunused-variable -fmessage-length=0 -gdwarf-2"
        platform_cflags+=" -Wno-error=implicit-function-declaration"
        optimize_flags="-O3"
        platform_ldflags+=" -L$use_sdk_path/usr/lib/system"
        platform_cxxflags+=" $cpu_flags"
        use_sdk_path=[`$use_xcodebuild -version -sdk $sdk_name | grep ^Path | awk '{ print $2}'`]
      ;;
    esac
    platform_cflags+=" -arch $use_cpu -m$platform_min_version"
    platform_ldflags+=" -arch $use_cpu -m$platform_min_version -isysroot $use_sdk_path -stdlib=libc++"
    platform_cxxflags+=" -arch $use_cpu -m$platform_min_version -std=c++11 -stdlib=libc++"
    platform_includes="-isysroot $use_sdk_path"
    deps_dir="${sdk_name}_${use_cpu}-target-${build_type}"
    AC_CHECK_LIB([z], [main], has_zlib=1, AC_MSG_WARN("No zlib support in toolchain. Will build libz."); has_zlib=0)
  ;;
  *)
    AC_MSG_ERROR(unsupported host ($use_host))
esac

case $use_platform in
  raspberry-pi)
     target_platform=raspberry-pi
     use_neon=no
     use_cpu=arm1176jzf-s
     ffmpeg_options_default="--cpu=arm1176jzf-s"
     platform_cflags="-mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp"
     platform_cxxflags="-mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp"
     optimize_flags="-Os"
     platform_ldflags=""
     ;;
  raspberry-pi2)
     target_platform=raspberry-pi
     use_neon=yes
     use_cpu=cortex-a7
     ffmpeg_options_default="--cpu=cortex-a7"
     platform_cflags="-fPIC -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4"
     platform_cxxflags="-fPIC -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4"
     optimize_flags="-Os"
     platform_ldflags="-lpthread"
     ;;
esac

if test "$target_platform" = "raspberry-pi" ; then
  if test -d "${use_firmware}/opt/vc/include"; then
    :
  else
    AC_MSG_ERROR([Raspberry Pi firmware not found])
  fi
  use_arch="arm"
  use_hardcoded_tables="yes"
  ARCH="arm"
  platform_os="linux"
  cross_compiling="yes"
  use_host="arm-linux-gnueabihf"
  deps_dir="$use_platform-$build_type"
  platform_cflags+=" -pipe -mabi=aapcs-linux -Wno-psabi \
   -Wa,-mno-warn-deprecated -Wno-deprecated-declarations \
   -isystem${use_firmware}/opt/vc/include \
   -isystem${use_firmware}/opt/vc/include/interface/vcos/pthreads \
   -isystem${use_firmware}/opt/vc/include/interface/vmcs_host/linux"
  platform_cxxflags+=" -pipe -mabi=aapcs-linux -Wno-psabi \
   -Wa,-mno-warn-deprecated -Wno-deprecated-declarations \
   -isystem${use_firmware}/opt/vc/include \
   -isystem${use_firmware}/opt/vc/include/interface/vcos/pthreads \
   -isystem${use_firmware}/opt/vc/include/interface/vmcs_host/linux"
  platform_ldflags+=" -L${use_firmware}/opt/vc/lib -lEGL -lGLESv2 -lbcm_host -lvcos \
   -lvchiq_arm"
fi

XBMC_SETUP_ARCH_DEFINES()


if test -n $use_build_toolchain; then
  PATH_FOR_HOST=$use_toolchain:$use_toolchain/usr/bin:$use_toolchain/bin:$PATH
else
  PATH_FOR_HOST=$PATH
fi
if test -n $use_build_toolchain; then
  PATH_FOR_BUILD=$use_build_toolchain:$use_build_toolchain/usr/bin:$use_toolchain/bin:$PATH
else
  PATH_FOR_BUILD=$PATH
fi

AC_PATH_TOOL([RANLIB], [ranlib],, $PATH_FOR_HOST)
AC_PATH_TOOL([LD], [ld],, $PATH_FOR_HOST)
AC_PATH_TOOL([AR], [ar],, $PATH_FOR_HOST)
AC_PATH_TOOL([READELF], [readelf],, $PATH_FOR_HOST)
AC_PATH_TOOL([STRIP], [strip],, $PATH_FOR_HOST)
AC_PATH_TOOL([AS], [as],, $PATH_FOR_HOST)
AC_PATH_TOOL([NM], [nm],, $PATH_FOR_HOST)
AC_PATH_TOOL([OBJDUMP], [objdump],, $PATH_FOR_HOST)
AC_PATH_TOOL([CC],[$platform_cc],,$PATH_FOR_HOST)
AC_PATH_TOOL([CXX],[$platform_cxx],,$PATH_FOR_HOST)
AC_PROG_CPP

AC_PATH_PROG([RANLIB_FOR_BUILD], [ranlib], ranlib, $PATH_FOR_BUILD)
AC_PATH_PROG([LD_FOR_BUILD], [ld], ld, $PATH_FOR_BUILD)
AC_PATH_PROG([AR_FOR_BUILD], [ar], ar, $PATH_FOR_BUILD)
AC_PATH_PROG([READELF_FOR_BUILD], [readelf], readelf, $PATH_FOR_BUILD)
AC_PATH_PROG([STRIP_FOR_BUILD], [strip], strip, $PATH_FOR_BUILD)
AC_PATH_PROG([AS_FOR_BUILD], [as], as, $PATH_FOR_BUILD)
AC_PATH_PROG([NM_FOR_BUILD], [nm], nm, $PATH_FOR_BUILD)
AC_PATH_PROG([OBJDUMP_FOR_BUILD], [objdump], objdump, $PATH_FOR_BUILD)
AC_PATH_PROG([CC_FOR_BUILD],[gcc llvm-gcc $platform_cc], gcc, $PATH_FOR_BUILD)
AC_PATH_PROG([CXX_FOR_BUILD],[g++ llvm-g++ $platform_cxx], g++, $PATH_FOR_BUILD)

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)
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)
AC_CHECK_LIB([crystax],   [main], has_libcrystax=1, has_libcrystax=0)

if test "$link_iconv" = "none required"; then
  link_iconv=
fi

if test "x$prefix" = "xNONE"; then
  AC_MSG_ERROR([No prefix path defined. Use for ex: --prefix=/opt/xbmc-depends]);
fi

if test "$use_ccache" = "yes"; then
  AC_PATH_TOOL([CCACHE], [ccache],, $PATH_FOR_HOST)
fi

if test -z $use_tarballs; then
  use_tarballs=$prefix/xbmc-tarballs
fi

if test "$platform_os" != "linux"; then
  if test "x$enable_wayland" != "xno"; then
    AC_MSG_ERROR([Wayland is only supported on the Linux platform])
  fi
fi

if test -n "$app_rendersystem"; then
  if test "$app_rendersystem" != "gl" && test "$app_rendersystem" != "gles"; then
    AC_MSG_ERROR(Rendersystem must be gl or gles)
  fi
fi

if test "$platform_os" == "android"; then
  if test -z $use_ndk_path; then
    AC_MSG_ERROR("NDK path is required for android")
  fi

  if ([! test -f "$use_ndk_path/source.properties"] && [! test -f "$use_ndk_path/RELEASE.TXT"]) ; then
    AC_MSG_ERROR("$use_ndk_path is not an NDK directory")
  fi

  if test -z $use_sdk_path; then
    AC_MSG_ERROR("SDK path is required for android")
  fi

  if [ ! test -f $use_sdk_path/tools/android ]; then
    AC_MSG_ERROR(verify sdk path)
  fi

  if [ ! test -f $use_ndk_path/sources/android/native_app_glue/android_native_app_glue.h ]; then
    AC_MSG_ERROR(verify ndk path)
  fi

  #not all sort versions support -V - probe it...
  SORT_PARAMS=""
  sort -V /dev/null > /dev/null 2>&1 && SORT_PARAMS="-V"
  build_tools_path=$use_sdk_path/tools:$use_sdk_path/platform-tools:$use_sdk_path/build-tools/`ls $use_sdk_path/build-tools | sort $SORT_PARAMS | tail -n 1`

  AC_PATH_PROG(AAPT,aapt,"no",$build_tools_path)
  if test "x$AAPT" = "xno" ; then
    AC_MSG_ERROR("Missing program: aapt")
  fi

  AC_PATH_PROG(DX,dx,"no",$build_tools_path)
  if test "x$DX" = "xno" ; then
    AC_MSG_ERROR("Missing program: dx")
  fi

  AC_PATH_PROG(ZIPALIGN,zipalign,"no",$build_tools_path)
  if test "x$ZIPALIGN" = "xno" ; then
    AC_MSG_ERROR("Missing program: zipalign")
  fi
fi

# darwin needs unzip/zip in Codesign.command
if test "$platform_os" = "android" || test "$platform_os" = "osx" || test "$platform_os" = "ios"; then
  AC_CHECK_PROG(HAVE_UNZIP,unzip,"yes","no",)
  if test "x$HAVE_UNZIP" = "xno"; then
    AC_MSG_ERROR("Missing program: unzip")
  fi
fi
if test "$platform_os" = "osx" || test "$platform_os" = "ios"; then
  AC_CHECK_PROG(HAVE_ZIP,zip,"yes","no",)
  if test "x$HAVE_ZIP" = "xno"; then
    AC_MSG_ERROR("Missing program: zip")
  fi
fi

# Some dumb checks to see if paths might be correct.
if [ ! `mkdir -p $prefix/$deps_dir/include` ]; then
  AC_MSG_ERROR(unable to create $prefix/$deps_dir/include. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$deps_dir/lib` ]; then
  AC_MSG_ERROR(unable to create $prefix/$deps_dir/lib. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$deps_dir/share` ]; then
  AC_MSG_ERROR(unable to create $prefix/$deps_dir/share. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$tool_dir/include` ]; then
  AC_MSG_ERROR(unable to create $prefix/$tool_dir/include. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$tool_dir/lib` ]; then
  AC_MSG_ERROR(unable to create $prefix/$tool_dir/lib. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$tool_dir/share` ]; then
  AC_MSG_ERROR(unable to create $prefix/$tool_dir/share. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $prefix/$tool_dir/bin` ]; then
  AC_MSG_ERROR(unable to create $prefix/$tool_dir/share. verify that the path and permissions are correct.)
fi

if [ ! `mkdir -p $use_tarballs` ]; then
  AC_MSG_ERROR(unable to create tarballs dir. verify that the path and permissions are correct.)
fi

if test "$platform_os" == "android"; then
  echo

  if [ ! `mkdir -p $prefix/$deps_dir/include/$use_sdk` ]; then
    AC_MSG_ERROR(unable to create $prefix/$deps_dir/include/$use_sdk. verify that the path and permissions are correct.)
  fi

  if [ ! `mkdir -p $prefix/$deps_dir/lib/$use_sdk` ]; then
    AC_MSG_ERROR(unable to create $prefix/$deps_dir/lib/$use_sdk. verify that the path and permissions are correct.)
  fi
fi

# remove unwanted optimization flags
tmp_cflags=$(echo $c11_flags $platform_cflags | sed 's/-O@<:@123@:>@//g;s/-g //g;s/ \{2,\}//g')
tmp_cxxflags=$(echo $cxx11_flags $platform_cxxflags | sed 's/-O@<:@123@:>@//g;s/-g //g;s/ \{2,\}//g')

release_cflags="-DNDEBUG=1"

# newer xcode version accept -Og flag, but debugging doesn't work with it
if test "$platform_os" = "osx" || test "$platform_os" = "ios"; then
  debug_cflags="-g -D_DEBUG"
else
  CFLAGS="$tmp_cflags -Og -g -D_DEBUG"
  AC_COMPILE_IFELSE(
    [AC_LANG_SOURCE([int foo;])],
    [debug_cflags="-Og -g -D_DEBUG"],
    [debug_cflags="-g -D_DEBUG"])
fi

# add user supplied flags to the end, so they override our defaults
platform_cflags_release="$tmp_cflags $relase_cflags $optimize_flags $target_cflags"
platform_cxxflags_release="$tmp_cxxflags $relase_cflags $optimize_flags $target_cxxflags"
platform_cflags_debug="$tmp_cflags $debug_cflags $target_cflags"
platform_cxxflags_debug="$tmp_cxxflags $debug_cflags $target_cxxflags"
platform_ldflags+=" $target_ldflags $LIBS"

if test "$use_debug" = "yes"; then
  platform_cflags="$platform_cflags_debug"
  platform_cxxflags="$platform_cxxflags_debug"
else
  platform_cflags="$platform_cflags_release"
  platform_cxxflags="$platform_cxxflags_release"
fi

if test "$ffmpeg_options" == "default"; then
  ffmpeg_options="$ffmpeg_options_default"
fi

if test "$platform_os" == "android"; then
echo -e
  AC_SUBST(use_sdk_path)
  AC_SUBST(use_ndk_path)
  AC_SUBST(use_sdk)
  AC_SUBST(use_ndk_api)
  AC_SUBST(build_tools_path)
fi

AC_SUBST(use_debug)
AC_SUBST(use_host)
AC_SUBST(deps_dir)
AC_SUBST(tool_dir)
AC_SUBST(use_cpu)
AC_SUBST(use_toolchain)
AC_SUBST(use_build_toolchain)
AC_SUBST(use_tarballs)
AC_SUBST(target_platform)
AC_SUBST(use_firmware)
AC_SUBST(cross_compiling)
AC_SUBST(platform_cflags)
AC_SUBST(platform_cxxflags)
AC_SUBST(platform_cflags_release)
AC_SUBST(platform_cxxflags_release)
AC_SUBST(platform_cflags_debug)
AC_SUBST(platform_cxxflags_debug)
AC_SUBST(platform_ldflags)
AC_SUBST(platform_includes)
AC_SUBST(platform_os)
AC_SUBST(build_os)
AC_SUBST(has_zlib)
AC_SUBST(link_iconv)
AC_SUBST(need_libiconv)
AC_SUBST(use_gplv3)
AC_SUBST(enable_wayland)
AC_SUBST(has_libcrystax)
AC_SUBST(use_xcode)
AC_SUBST(use_ccache)
AC_SUBST(native_platform_min_version)
AC_SUBST(app_rendersystem)
AC_SUBST(ffmpeg_options)

AC_OUTPUT
echo -e "ccache:\t $use_ccache"
echo -e "toolchain:\t $use_toolchain"
echo -e "cpu:\t\t $use_cpu"
echo -e "host:\t\t $use_host"
if test "$platform_os" == "android"; then
  echo -e "sdk-platform:\t $use_sdk"
  echo -e "build-tools:\t $build_tools_path"
fi

if test "$platform_os" == "ios"; then
  if test "$use_platform" = "tvos"; then
    simulator_sdk_path=[`$use_xcodebuild -version -sdk appletvsimulator$use_sdk  | grep ^Path | awk '{ print $2}'`]
  else
    simulator_sdk_path=[`$use_xcodebuild -version -sdk iphonesimulator$use_sdk  | grep ^Path | awk '{ print $2}'`]
  fi
  cp -vf $simulator_sdk_path/usr/include/crt_externs.h $prefix/$deps_dir/include
fi
echo -e "use simulator:\t $use_simulator"

if test "x$has_localeconv" == "xno" && test "$platform_os" == "android"; then
  cp -vf target/android-libc-replacements/locale.h $prefix/$deps_dir/include/
fi

cp -vf target/config.site $prefix/$deps_dir/share
cp -vf target/config-binaddons.site $prefix/$tool_dir/share
cp -vf target/Toolchain.cmake $prefix/$deps_dir/share
cp -vf target/Toolchain_binaddons.cmake $prefix/$deps_dir/share
cp -vf native/config.site.native $prefix/$tool_dir/share/config.site


echo -e "\n\n#------- configuration -------#"
echo -e "build type:\t $build_type"
echo -e "toolchain:\t $use_toolchain"
echo -e "cpu:\t\t $use_cpu"
echo -e "host:\t\t $use_host"
echo -e "cflags:\t\t $platform_cflags"
echo -e "cxxflags:\t $platform_cxxflags"
echo -e "ldflags:\t $platform_ldflags"
echo -e "ffmpeg options:\t $ffmpeg_options"
echo -e "prefix:\t\t  $prefix"
echo -e "depends:\t $prefix/$deps_dir"
if test "$platform_os" == "android"; then
  echo -e "sdk-platform:\t $use_sdk"
  echo -e "build-tools:\t $build_tools_path"
fi