Add partially accelerated mc_luma
[x262.git] / configure
1 #!/bin/bash
2
3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
4 cat <<EOF
5 Usage: ./configure [options]
6
7 Help:
8   -h, --help               print this message
9
10 Standard options:
11   --prefix=PREFIX          install architecture-independent files in PREFIX
12                            [/usr/local]
13   --exec-prefix=EPREFIX    install architecture-dependent files in EPREFIX
14                            [PREFIX]
15   --bindir=DIR             install binaries in DIR [EPREFIX/bin]
16   --libdir=DIR             install libs in DIR [EPREFIX/lib]
17   --includedir=DIR         install includes in DIR [PREFIX/include]
18   --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS
19   --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS
20   --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS
21   --extra-rcflags=ERCFLAGS add ERCFLAGS to RCFLAGS
22
23 Configuration options:
24   --disable-cli            disable cli
25   --system-libx264         use system libx264 instead of internal
26   --enable-shared          build shared library
27   --enable-static          build static library
28   --disable-opencl         disable OpenCL features
29   --disable-gpl            disable GPL-only features
30   --disable-thread         disable multithreaded encoding
31   --enable-win32thread     use win32threads (windows only)
32   --disable-interlaced     disable interlaced encoding support
33   --disable-mpeg2          disables MPEG-2 encoding support
34   --enable-visualize       enable visualization (X11 only)
35   --bit-depth=BIT_DEPTH    set output bit depth (8-10) [8]
36   --chroma-format=FORMAT   output chroma format (420, 422, 444, all) [all]
37
38 Advanced options:
39   --disable-asm            disable platform-specific assembly optimizations
40   --enable-debug           add -g
41   --enable-gprof           add -pg
42   --enable-strip           add -s
43   --enable-pic             build position-independent code
44
45 Cross-compilation:
46   --host=HOST              build programs to run on HOST
47   --cross-prefix=PREFIX    use PREFIX for compilation tools
48   --sysroot=SYSROOT        root of cross-build tree
49
50 External library support:
51   --disable-avs            disable avisynth support
52   --disable-swscale        disable swscale support
53   --disable-lavf           disable libavformat support
54   --disable-ffms           disable ffmpegsource support
55   --disable-gpac           disable gpac support
56   --disable-lsmash         disable lsmash support
57
58 EOF
59 exit 1
60 fi
61
62 log_check() {
63     echo -n "checking $1... " >> config.log
64 }
65
66 log_ok() {
67     echo "yes" >> config.log
68 }
69
70 log_fail() {
71     echo "no" >> config.log
72 }
73
74 log_msg() {
75     echo "$1" >> config.log
76 }
77
78 intel_cflags() {
79     # Intel Compiler issues an incredibly large number of warnings on any warning level,
80     # suppress them by disabling all warnings rather than having to use #pragmas to disable most of them
81     for arg in $*; do
82         [ $arg = -ffast-math ] && arg=
83         [[ "$arg" = -falign-loops* ]] && arg=
84         [ "$arg" = -fno-tree-vectorize ] && arg=
85         [ "$arg" = -Wshadow ] && arg=
86         [[ "$arg" = -mpreferred-stack-boundary* ]] && arg=
87         [[ "$arg" = -l* ]] && arg=
88         [[ "$arg" = -L* ]] && arg=
89         if [ $compiler = ICL ]; then
90             [ "$arg" = -Wall ] && arg=-W0
91             [ "$arg" = -g ] && arg=-Z7
92             [ "$arg" = -fomit-frame-pointer ] && arg=
93             [ "$arg" = -s ] && arg=
94             [ "$arg" = -fPIC ] && arg=
95         else
96             [ "$arg" = -Wall ] && arg=-w0
97         fi
98
99         [ -n "$arg" ] && echo -n "$arg "
100     done
101 }
102
103 icl_ldflags() {
104     for arg in $*; do
105         arg=${arg/LIBPATH/libpath}
106         [ ${arg#-libpath:} == $arg -a ${arg#-l} != $arg ] && arg=${arg#-l}.lib
107         [ ${arg#-L} != $arg ] && arg=-libpath:${arg#-L}
108         [ $arg = -Wl,--large-address-aware ] && arg=-largeaddressaware
109         [ $arg = -s ] && arg=
110         [ "$arg" = -Wl,-Bsymbolic ] && arg=
111
112         arg=${arg/pthreadGC/pthreadVC}
113         [ "$arg" = avifil32.lib ] && arg=vfw32.lib
114         [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib
115
116         [ -n "$arg" ] && echo -n "$arg "
117     done
118 }
119
120 cc_check() {
121     if [ -z "$3" ]; then
122         if [ -z "$1$2" ]; then
123             log_check "whether $CC works"
124         elif [ -z "$1" ]; then
125             log_check "for $2"
126         else
127             log_check "for $1"
128         fi
129     elif [ -z "$1" ]; then
130         if [ -z "$2" ]; then
131             log_check "whether $CC supports $3"
132         else
133             log_check "whether $CC supports $3 with $2"
134         fi
135     else
136         log_check "for $3 in $1";
137     fi
138     rm -f conftest.c
139     [ -n "$1" ] && echo "#include <$1>" > conftest.c
140     echo "int main () { $3 return 0; }" >> conftest.c
141     if [ $compiler = ICL ]; then
142         cc_cmd="$CC conftest.c $(intel_cflags $CFLAGS $2) -link $(icl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
143     else
144         cc_cmd="$CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
145     fi
146     if $cc_cmd >conftest.log 2>&1; then
147         res=$?
148         log_ok
149     else
150         res=$?
151         log_fail
152         log_msg "Failed commandline was:"
153         log_msg "--------------------------------------------------"
154         log_msg "$cc_cmd"
155         cat conftest.log >> config.log
156         log_msg "--------------------------------------------------"
157         log_msg "Failed program was:"
158         log_msg "--------------------------------------------------"
159         cat conftest.c >> config.log
160         log_msg "--------------------------------------------------"
161     fi
162     return $res
163 }
164
165 cpp_check() {
166     log_check "whether $3 is true"
167     rm -f conftest.c
168     [ -n "$1" ] && echo "#include <$1>" > conftest.c
169     echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
170
171     if $CC conftest.c $CFLAGS $2 -E -o conftest >conftest.log 2>&1; then
172         res=$?
173         log_ok
174     else
175         res=$?
176         log_fail
177         log_msg "--------------------------------------------------"
178         cat conftest.log >> config.log
179         log_msg "--------------------------------------------------"
180         log_msg "Failed program was:"
181         log_msg "--------------------------------------------------"
182         cat conftest.c >> config.log
183         log_msg "--------------------------------------------------"
184     fi
185     return $res
186 }
187
188 as_check() {
189     log_check "whether $AS supports $1"
190     echo "$1" > conftest.asm
191     if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
192         res=$?
193         log_ok
194     else
195         res=$?
196         log_fail
197         log_msg "Failed commandline was:"
198         log_msg "--------------------------------------------------"
199         log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
200         cat conftest.log >> config.log
201         log_msg "--------------------------------------------------"
202         log_msg "Failed program was:"
203         log_msg "--------------------------------------------------"
204         cat conftest.asm >> config.log
205         log_msg "--------------------------------------------------"
206     fi
207     return $res
208 }
209
210 rc_check() {
211     log_check "whether $RC works"
212     echo "$1" > conftest.rc
213     if [ $compiler = ICL ]; then
214         rc_cmd="$RC $RCFLAGS -foconftest.o conftest.rc"
215     else
216         rc_cmd="$RC $RCFLAGS -o conftest.o conftest.rc"
217     fi
218     if $rc_cmd >conftest.log 2>&1; then
219         res=$?
220         log_ok
221     else
222         res=$?
223         log_fail
224         log_msg "Failed commandline was:"
225         log_msg "--------------------------------------------------"
226         log_msg "$rc_cmd"
227         cat conftest.log >> config.log
228         log_msg "--------------------------------------------------"
229         log_msg "Failed program was:"
230         log_msg "--------------------------------------------------"
231         cat conftest.rc >> config.log
232         log_msg "--------------------------------------------------"
233     fi
234     return $res
235 }
236
237 define() {
238     echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
239 }
240
241 die() {
242     log_msg "DIED: $@"
243     echo "$@"
244     exit 1
245 }
246
247 rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest*
248
249 SRCPATH="$(cd $(dirname $0); pwd)"
250 [ "$SRCPATH" = "$(pwd)" ] && SRCPATH=.
251 [ -n "$(echo $SRCPATH | grep ' ')" ] && die "Out of tree builds are impossible with whitespace in source path."
252 [ -e "$SRCPATH/config.h" -o -e "$SRCPATH/x264_config.h" ] && die "Out of tree builds are impossible with config.h/x264_config.h in source dir."
253
254 prefix='/usr/local'
255 exec_prefix='${prefix}'
256 bindir='${exec_prefix}/bin'
257 libdir='${exec_prefix}/lib'
258 includedir='${prefix}/include'
259 DEVNULL='/dev/null'
260
261 cli="yes"
262 cli_libx264="internal"
263 shared="no"
264 static="no"
265 avs="auto"
266 lavf="auto"
267 ffms="auto"
268 gpac="auto"
269 lsmash="auto"
270 mp4="no"
271 gpl="yes"
272 thread="auto"
273 swscale="auto"
274 asm="auto"
275 interlaced="yes"
276 mpeg2="yes"
277 debug="no"
278 gprof="no"
279 strip="no"
280 pic="no"
281 bit_depth="8"
282 chroma_format="all"
283 compiler="GNU"
284 opencl="yes"
285
286 CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
287 LDFLAGS="$LDFLAGS"
288 LDFLAGSCLI="$LDFLAGSCLI"
289 ASFLAGS="$ASFLAGS"
290 RCFLAGS="$RCFLAGS"
291 HAVE_GETOPT_LONG=1
292 cross_prefix=""
293
294 EXE=""
295
296 # list of all preprocessor HAVE values we can define
297 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
298              LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH MPEG2"
299 # parse options
300
301 for opt do
302     optarg="${opt#*=}"
303     case "$opt" in
304         --prefix=*)
305             prefix="$optarg"
306             ;;
307         --exec-prefix=*)
308             exec_prefix="$optarg"
309             ;;
310         --bindir=*)
311             bindir="$optarg"
312             ;;
313         --libdir=*)
314             libdir="$optarg"
315             ;;
316         --includedir=*)
317             includedir="$optarg"
318             ;;
319         --disable-cli)
320             cli="no"
321             ;;
322         --system-libx264)
323             cli_libx264="system"
324             ;;
325         --enable-shared)
326             shared="yes"
327             ;;
328         --enable-static)
329             static="yes"
330             ;;
331         --disable-asm)
332             asm="no"
333             ;;
334         --disable-interlaced)
335             interlaced="no"
336             ;;
337         --disable-mpeg2)
338             mpeg2="no"
339             ;;
340         --disable-avs)
341             avs="no"
342             ;;
343         --disable-lavf)
344             lavf="no"
345             ;;
346         --disable-ffms)
347             ffms="no"
348             ;;
349         --disable-gpac)
350             gpac="no"
351             ;;
352         --disable-lsmash)
353             lsmash="no"
354             ;;
355         --disable-gpl)
356             gpl="no"
357             ;;
358         --extra-asflags=*)
359             ASFLAGS="$ASFLAGS $optarg"
360             ;;
361         --extra-cflags=*)
362             CFLAGS="$CFLAGS $optarg"
363             ;;
364         --extra-ldflags=*)
365             LDFLAGS="$LDFLAGS $optarg"
366             ;;
367         --extra-rcflags=*)
368             RCFLAGS="$RCFLAGS $optarg"
369             ;;
370         --disable-thread)
371             thread="no"
372             ;;
373         --enable-win32thread)
374             thread="win32"
375             ;;
376         --disable-swscale)
377             swscale="no"
378             ;;
379         --enable-debug)
380             debug="yes"
381             ;;
382         --enable-gprof)
383             CFLAGS="$CFLAGS -pg"
384             LDFLAGS="$LDFLAGS -pg"
385             gprof="yes"
386             ;;
387         --enable-strip)
388             strip="yes"
389             ;;
390         --enable-pic)
391             pic="yes"
392             ;;
393         --host=*)
394             host="$optarg"
395             ;;
396         --disable-opencl)
397             opencl="no"
398             ;;
399         --cross-prefix=*)
400             cross_prefix="$optarg"
401             ;;
402         --sysroot=*)
403             CFLAGS="$CFLAGS --sysroot=$optarg"
404             LDFLAGS="$LDFLAGS --sysroot=$optarg"
405             ;;
406         --bit-depth=*)
407             bit_depth="$optarg"
408             if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
409                 echo "Supplied bit depth must be in range [8,10]."
410                 exit 1
411             fi
412             bit_depth=`expr $bit_depth + 0`
413             ;;
414         --chroma-format=*)
415             chroma_format="$optarg"
416             if [ $chroma_format != "420" -a $chroma_format != "422" -a $chroma_format != "444" -a $chroma_format != "all" ]; then
417                 echo "Supplied chroma format must be 420, 422, 444 or all."
418                 exit 1
419             fi
420             ;;
421         *)
422             echo "Unknown option $opt, ignored"
423             ;;
424     esac
425 done
426
427 [ "$cli" = "no" -a "$shared" = "no" -a "$static" = "no" ] && die "Nothing to build. Enable cli, shared or static."
428
429 CC="${CC-${cross_prefix}gcc}"
430 AR="${AR-${cross_prefix}ar}"
431 RANLIB="${RANLIB-${cross_prefix}ranlib}"
432 STRIP="${STRIP-${cross_prefix}strip}"
433 INSTALL="${INSTALL-install}"
434
435 if [ "x$host" = x ]; then
436     host=`${SRCPATH}/config.guess`
437 fi
438 # normalize a triplet into a quadruplet
439 host=`${SRCPATH}/config.sub $host`
440
441 # split $host
442 host_cpu="${host%%-*}"
443 host="${host#*-}"
444 host_vendor="${host%%-*}"
445 host_os="${host#*-}"
446
447 # test for use of Intel Compiler
448 if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
449     if [[ `basename "$CC"` = icl* ]]; then
450         # Windows Intel Compiler creates dependency generation with absolute Windows paths, Cygwin's make does not support Windows paths.
451         [[ $host_os = cygwin* ]] && die "Windows Intel Compiler support requires MSYS"
452         compiler=ICL
453         CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -I\$(SRCPATH)/extras"
454         QPRE="-Q"
455         `$CC 2>&1 | grep -q IA-32` && host_cpu=i486
456         `$CC 2>&1 | grep -q "Intel(R) 64"` && host_cpu=x86_64
457         cpp_check "" "" "_MSC_VER >= 1400" || die "Windows Intel Compiler support requires Visual Studio 2005 or newer"
458     fi
459 else
460     if [[ `basename "$CC"` = icc* ]]; then
461         AR="xiar"
462         compiler=ICC
463         QPRE="-"
464     fi
465 fi
466
467 libm=""
468 case $host_os in
469     beos*)
470         SYS="BEOS"
471         define HAVE_MALLOC_H
472         ;;
473     darwin*)
474         SYS="MACOSX"
475         CFLAGS="$CFLAGS -falign-loops=16"
476         libm="-lm"
477         if [ "$pic" = "no" ]; then
478             cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
479         fi
480         ;;
481     freebsd*)
482         SYS="FREEBSD"
483         libm="-lm"
484         ;;
485     kfreebsd*-gnu)
486         SYS="FREEBSD"
487         define HAVE_MALLOC_H
488         libm="-lm"
489         ;;
490     netbsd*)
491         SYS="NETBSD"
492         libm="-lm"
493         ;;
494     openbsd*)
495         SYS="OPENBSD"
496         libm="-lm"
497         ;;
498     *linux*)
499         SYS="LINUX"
500         define HAVE_MALLOC_H
501         libm="-lm"
502         ;;
503     gnu*)
504         SYS="HURD"
505         define HAVE_MALLOC_H
506         libm="-lm"
507         ;;
508     cygwin*)
509         EXE=".exe"
510         if cc_check "" -mno-cygwin; then
511             CFLAGS="$CFLAGS -mno-cygwin"
512             LDFLAGS="$LDFLAGS -mno-cygwin"
513         fi
514         if cpp_check "" "" "defined(__CYGWIN__)" ; then
515             define HAVE_MALLOC_H
516             SYS="CYGWIN"
517         else
518             SYS="WINDOWS"
519             DEVNULL="NUL"
520             LDFLAGSCLI="$LDFLAGSCLI -lshell32"
521             RC="${RC-${cross_prefix}windres}"
522         fi
523         ;;
524     mingw*)
525         SYS="WINDOWS"
526         EXE=".exe"
527         DEVNULL="NUL"
528         LDFLAGSCLI="$LDFLAGSCLI -lshell32"
529         [ $compiler = ICL ] && RC="${RC-rc}" || RC="${RC-${cross_prefix}windres}"
530         ;;
531     sunos*|solaris*)
532         SYS="SunOS"
533         define HAVE_MALLOC_H
534         libm="-lm"
535         if cc_check "" /usr/lib/64/values-xpg6.o; then
536             LDFLAGS="$LDFLAGS /usr/lib/64/values-xpg6.o"
537         else
538             LDFLAGS="$LDFLAGS /usr/lib/values-xpg6.o"
539         fi
540         if test -x /usr/ucb/install ; then
541             INSTALL=/usr/ucb/install
542         elif test -x /usr/bin/ginstall ; then
543             # OpenSolaris
544             INSTALL=/usr/bin/ginstall
545         elif test -x /usr/gnu/bin/install ; then
546             # OpenSolaris
547             INSTALL=/usr/gnu/bin/install
548         fi
549         HAVE_GETOPT_LONG=0
550         ;;
551     *qnx*)
552         SYS="QNX"
553         define HAVE_MALLOC_H
554         libm="-lm"
555         HAVE_GETOPT_LONG=0
556         CFLAGS="$CFLAGS -I\$(SRCPATH)/extras"
557         ;;
558     *)
559         die "Unknown system $host, edit the configure"
560         ;;
561 esac
562
563 LDFLAGS="$LDFLAGS $libm"
564
565 stack_alignment=16
566 case $host_cpu in
567     i*86)
568         ARCH="X86"
569         AS="yasm"
570         ASFLAGS="$ASFLAGS -O2"
571         if [ $compiler = GNU ]; then
572             if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
573                 CFLAGS="$CFLAGS -march=i686"
574             fi
575             if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
576                 CFLAGS="$CFLAGS -mfpmath=sse -msse"
577             fi
578             CFLAGS="-m32 $CFLAGS"
579             LDFLAGS="-m32 $LDFLAGS"
580         else
581             # icc on linux has various degrees of mod16 stack support
582             if [ $SYS = LINUX ]; then
583                 # < 11 is completely incapable of keeping a mod16 stack
584                 if cpp_check "" "" "__INTEL_COMPILER < 1100" ; then
585                     stack_alignment=4
586                 # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
587                 elif cpp_check "" "" "__INTEL_COMPILER < 1200" ; then
588                     CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
589                 fi
590                 # >= 12 defaults to a mod16 stack
591             fi
592             # icl on windows has no mod16 stack support
593             [ $SYS = WINDOWS ] && stack_alignment=4
594         fi
595         if [ "$SYS" = MACOSX ]; then
596             ASFLAGS="$ASFLAGS -f macho -DPREFIX"
597         elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
598             ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
599             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
600             [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--nxcompat -Wl,--dynamicbase"
601             [ $compiler = GNU ] && RCFLAGS="--target=pe-i386 $RCFLAGS"
602         else
603             ASFLAGS="$ASFLAGS -f elf"
604         fi
605         ;;
606     x86_64)
607         ARCH="X86_64"
608         AS="yasm"
609         [ $compiler = GNU ] && CFLAGS="-m64 $CFLAGS" && LDFLAGS="-m64 $LDFLAGS"
610         if [ "$SYS" = MACOSX ]; then
611             ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
612             if cc_check '' "-arch x86_64"; then
613                 CFLAGS="$CFLAGS -arch x86_64"
614                 LDFLAGS="$LDFLAGS -arch x86_64"
615             fi
616         elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
617             ASFLAGS="$ASFLAGS -f win32 -m amd64"
618             # only the GNU toolchain is inconsistent in prefixing function names with _
619             [ $compiler = GNU ] && cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
620             [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--nxcompat -Wl,--dynamicbase"
621             [ $compiler = GNU ] && RCFLAGS="--target=pe-x86-64 $RCFLAGS"
622         else
623             ASFLAGS="$ASFLAGS -f elf -m amd64"
624         fi
625         ;;
626     powerpc|powerpc64)
627         ARCH="PPC"
628         if [ $asm = auto ] ; then
629             define HAVE_ALTIVEC
630             AS="${AS-${cross_prefix}gcc}"
631             if [ $SYS = MACOSX ] ; then
632                 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
633             else
634                 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
635                 define HAVE_ALTIVEC_H
636             fi
637         fi
638         ;;
639     sparc)
640         ARCH="SPARC"
641         case $(uname -m) in
642             sun4u|sun4v)
643                 if [ $asm = auto ]; then
644                     ARCH="UltraSPARC"
645                     if ! echo $CFLAGS | grep -Eq '\-mcpu' ; then
646                         CFLAGS="$CFLAGS -mcpu=ultrasparc"
647                         LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
648                     fi
649                     AS="${AS-${cross_prefix}as}"
650                     ASFLAGS="$ASFLAGS -xarch=v8plusa"
651                 fi
652                 ;;
653         esac
654         ;;
655     mips|mipsel|mips64|mips64el)
656         ARCH="MIPS"
657         ;;
658     arm*)
659         ARCH="ARM"
660         if [ "$SYS" = MACOSX ] ; then
661             AS="${AS-extras/gas-preprocessor.pl $CC}"
662             ASFLAGS="$ASFLAGS -DPREFIX -DPIC"  # apple's ld doesn't support movw/movt relocations at all
663             # build for armv7 by default
664             if ! echo $CFLAGS | grep -Eq '\-arch' ; then
665                 CFLAGS="$CFLAGS -arch armv7"
666                 LDFLAGS="$LDFLAGS -arch armv7"
667             fi
668         else
669             AS="${AS-${cross_prefix}gcc}"
670         fi
671         ;;
672     s390|s390x)
673         ARCH="S390"
674         ;;
675     hppa*|parisc*)
676         ARCH="PARISC"
677         ;;
678     ia64)
679         ARCH="IA64"
680         ;;
681     alpha*)
682         ARCH="ALPHA"
683         ;;
684     *)
685         ARCH="$(echo $host_cpu | tr a-z A-Z)"
686         ;;
687 esac
688
689 if [ $SYS = WINDOWS ]; then
690     if ! rc_check "0 RCDATA {0}" ; then
691         RC=""
692     fi
693 fi
694
695 log_msg "x264 configure script"
696 if [ -n "$*" ]; then
697     msg="Command line options:"
698     for i in $@; do
699         msg="$msg \"$i\""
700     done
701     log_msg "$msg"
702 fi
703 log_msg ""
704
705 # check requirements
706
707 cc_check || die "No working C compiler found."
708
709 if [ $compiler != ICL ]; then
710     if cc_check '' -std=gnu99 'for( int i = 0; i < 9; i++ );' ; then
711         CFLAGS="$CFLAGS -std=gnu99"
712     elif cc_check '' -std=c99 'for( int i = 0; i < 9; i++ );' ; then
713         CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
714     elif ! cc_check '' '' 'for( int i = 0; i < 9; i++ );' ; then
715         die "C99 compiler is needed for compilation."
716     fi
717 fi
718
719 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" -o $ARCH = "PARISC" -o $ARCH = "MIPS" \) ] ; then
720     pic="yes"
721 fi
722
723 if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
724     if ! as_check "vpmovzxwd ymm0, xmm0" ; then
725         VER=`($AS --version || echo no assembler) 2>/dev/null | head -n 1`
726         echo "Found $VER"
727         echo "Minimum version is yasm-1.2.0"
728         echo "If you really want to compile without asm, configure with --disable-asm."
729         exit 1
730     fi
731     if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
732         VER=`(${cross_prefix}as --version || echo no gnu as) 2>/dev/null | head -n 1`
733         echo "Found $VER"
734         echo "Minimum version is binutils-2.17"
735         echo "Your compiler can't handle inline SSSE3 asm."
736         echo "If you really want to compile without asm, configure with --disable-asm."
737         exit 1
738     fi
739     ASFLAGS="$ASFLAGS -Worphan-labels"
740     define HAVE_MMX
741     if [ $compiler = GNU ] && cc_check '' -mpreferred-stack-boundary=5 ; then
742         CFLAGS="$CFLAGS -mpreferred-stack-boundary=5"
743         stack_alignment=32
744     fi
745 fi
746
747 if [ $asm = auto -a $ARCH = ARM ] ; then
748     # set flags so neon is built by default
749     echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon"
750
751     if  cc_check '' '' '__asm__("rev ip, ip");' ; then      define HAVE_ARMV6
752         cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2
753         cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
754         ASFLAGS="$ASFLAGS $CFLAGS -c"
755     else
756         echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
757         echo "If you really want to run on such a CPU, configure with --disable-asm."
758         exit 1
759     fi
760 fi
761
762 [ $asm = no ] && AS=""
763 [ "x$AS" = x ] && asm="no" || asm="yes"
764
765 define ARCH_$ARCH
766 define SYS_$SYS
767
768 define STACK_ALIGNMENT $stack_alignment
769 ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment"
770
771 # skip endianness check for Intel Compiler, as all supported platforms are little. the -ipo flag will also cause the check to fail
772 if [ $compiler = GNU ]; then
773     echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
774     $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
775     if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
776         define WORDS_BIGENDIAN
777     elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then
778         die "endian test failed"
779     fi
780 fi
781
782 # autodetect options that weren't forced nor disabled
783
784 # pthread-win32 is lgpl, prevent its use if --disable-gpl is specified and targeting windows
785 [ "$SYS" = "WINDOWS" -a "$gpl" = "no" -a "$thread" = "auto" ] && thread="win32"
786
787 libpthread=""
788 if [ "$thread" = "auto" ]; then
789     thread="no"
790     case $SYS in
791         BEOS)
792             thread="beos"
793             define HAVE_BEOSTHREAD
794             ;;
795         WINDOWS)
796             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
797                 thread="posix"
798                 libpthread="-lpthread"
799             elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
800                 thread="posix"
801                 libpthread="-lpthreadGC2"
802             elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
803                 thread="posix"
804                 libpthread="-lpthreadGC2 -lwsock32"
805                 define PTW32_STATIC_LIB
806             elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
807                 thread="posix"
808                 libpthread="-lpthreadGC2 -lws2_32"
809                 define PTW32_STATIC_LIB
810             else
811                 # default to native threading if pthread-win32 is unavailable
812                 thread="win32"
813             fi
814             ;;
815         QNX)
816             cc_check pthread.h -lc "pthread_create(0,0,0,0);" && thread="posix" && libpthread="-lc"
817             ;;
818         *)
819             if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
820                thread="posix"
821                libpthread="-lpthread"
822             else
823                 cc_check pthread.h "" "pthread_create(0,0,0,0);" && thread="posix" && libpthread=""
824             fi
825             ;;
826     esac
827 fi
828 if [ "$thread" = "posix" ]; then
829     LDFLAGS="$LDFLAGS $libpthread"
830     define HAVE_POSIXTHREAD
831     if [ "$SYS" = "LINUX" ] && cc_check sched.h "-D_GNU_SOURCE -Werror" "cpu_set_t p_aff; return CPU_COUNT(&p_aff);" ; then
832         define HAVE_CPU_COUNT
833     fi
834 fi
835 if [ "$thread" = "win32" ]; then
836     # cygwin does not support win32 threads
837     if [ "$SYS" = "WINDOWS" ]; then
838         define HAVE_WIN32THREAD
839     else
840         thread="no"
841     fi
842 fi
843 [ "$thread" != "no" ] && define HAVE_THREAD
844
845 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
846     define HAVE_LOG2F
847 fi
848
849 if [ "$SYS" = "LINUX" -a \( "$ARCH" = "X86" -o "$ARCH" = "X86_64" \) ] && cc_check "sys/mman.h" "" "MADV_HUGEPAGE;" ; then
850     define HAVE_THP
851 fi
852
853 if [ "$swscale" = "auto" ] ; then
854     swscale="no"
855     if ${cross_prefix}pkg-config --exists libswscale 2>/dev/null; then
856         SWSCALE_LIBS="$SWSCALE_LIBS $(${cross_prefix}pkg-config --libs libswscale libavutil)"
857         SWSCALE_CFLAGS="$SWSCALE_CFLAGS $(${cross_prefix}pkg-config --cflags libswscale libavutil)"
858     fi
859     [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"
860
861     if cc_check "libswscale/swscale.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "sws_init_context(0,0,0);" ; then
862         if cpp_check "libavutil/pixdesc.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "defined(AV_PIX_FMT_FLAG_RGB)" ; then
863             swscale="yes"
864         else
865             echo "Warning: AV_PIX_FMT_FLAG_RGB is missing from libavutil, update for swscale support"
866         fi
867     fi
868 fi
869
870
871
872 if [ "$lavf" = "auto" ] ; then
873     lavf="no"
874     if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>/dev/null; then
875         LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libavutil libswscale)"
876         LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libavutil libswscale)"
877     fi
878     if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
879         LAVF_LIBS="-lavformat"
880         for lib in -lpostproc -lavcodec -lavcore -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32 -lws2_32; do
881             cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
882         done
883     fi
884     LAVF_LIBS="-L. $LAVF_LIBS"
885     if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avformat_close_input(0);" ; then
886         if [ "$swscale" = "yes" ]; then
887             lavf="yes"
888         else
889             echo "Warning: libavformat is not supported without swscale support"
890         fi
891     fi
892 fi
893
894 if [ "$ffms" = "auto" ] ; then
895     ffms_major="2"; ffms_minor="16"; ffms_micro="2"; ffms_bump="0"
896     ffms="no"
897
898     if ${cross_prefix}pkg-config --exists ffms2 2>/dev/null; then
899         FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
900         FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
901     fi
902     [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
903
904     if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
905         ffms="yes"
906     elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
907         ffms="yes"
908         FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
909     fi
910
911     error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
912     if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
913        ffms="no"
914        echo "Warning: $error"
915     fi
916     if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
917         echo "Warning: ffms is not supported without swscale support"
918         ffms="no"
919     fi
920 fi
921
922 if [ "$swscale" = "yes" ]; then
923     LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
924     CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
925     define HAVE_SWSCALE
926     if [ "$lavf" = "yes" ]; then
927         LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
928         CFLAGS="$CFLAGS $LAVF_CFLAGS"
929         define HAVE_LAVF
930     fi
931     if [ "$ffms" = "yes" ]; then
932         LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
933         CFLAGS="$CFLAGS $FFMS2_CFLAGS"
934         define HAVE_FFMS
935     fi
936 fi
937
938 if [ "$lsmash" = "auto" ] ; then
939     lsmash="no"
940     if ${cross_prefix}pkg-config --exists liblsmash 2>/dev/null; then
941         LSMASH_LIBS="$LSMASH_LIBS $(${cross_prefix}pkg-config --libs liblsmash)"
942         LSMASH_CFLAGS="$LSMASH_CFLAGS $(${cross_prefix}pkg-config --cflags liblsmash)"
943     fi
944     [ -z "$LSMASH_LIBS" ] && LSMASH_LIBS="-llsmash"
945
946     if cc_check lsmash.h "$LSMASH_CFLAGS $LSMASH_LIBS" ; then
947         if cpp_check lsmash.h "$LSMASH_CFLAGS" "LSMASH_VERSION_MAJOR > 0 || (LSMASH_VERSION_MAJOR == 0 && LSMASH_VERSION_MINOR >= 1)" ; then
948             lsmash="yes"
949         else
950             echo "Warning: lsmash is too old, update to rev.751 or later"
951         fi
952     fi
953 fi
954
955 if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
956     gpac="no"
957     GPAC_LIBS="-lgpac_static"
958     cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz"
959     if [ "$SYS" = "WINDOWS" ] ; then
960         cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32"
961         cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm"
962     fi
963     if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
964         if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
965             gpac="yes"
966         else
967             echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
968         fi
969     fi
970 fi
971
972 if [ "$lsmash" = "yes" ] ; then
973     mp4="lsmash"
974     LDFLAGSCLI="$LSMASH_LIBS $LDFLAGSCLI"
975     CFLAGS="$CFLAGS $LSMASH_CFLAGS"
976     define HAVE_LSMASH
977 elif [ "$gpac" = "yes" ] ; then
978     mp4="gpac"
979     define HAVE_GPAC
980     LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
981 fi
982
983 if [ "$avs" = "auto" ] ; then
984     avs="no"
985     # cygwin can use avisynth if it can use LoadLibrary
986     if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
987         avs="avisynth"
988         define HAVE_AVS
989         define USE_AVXSYNTH 0
990     elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
991     # AvxSynth currently only supports Linux and OSX
992         avs="avxsynth"
993         define HAVE_AVS
994         define USE_AVXSYNTH 1
995         AVS_LIBS="-ldl"
996         LDFLAGSCLI="$AVS_LIBS $LDFLAGSCLI"
997     fi
998 fi
999
1000 cc_check "stdint.h" "" "uint32_t test_vec __attribute__ ((vector_size (16))) = {0,1,2,3};" && define HAVE_VECTOREXT
1001
1002 if [ "$pic" = "yes" ] ; then
1003     CFLAGS="$CFLAGS -fPIC"
1004     ASFLAGS="$ASFLAGS -DPIC"
1005     # resolve textrels in the x86 asm
1006     cc_check stdio.h "-shared -Wl,-Bsymbolic" && SOFLAGS="$SOFLAGS -Wl,-Bsymbolic"
1007     [ $SYS = SunOS -a "$ARCH" = "X86" ] && SOFLAGS="$SOFLAGS -mimpure-text"
1008 fi
1009
1010 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
1011     CFLAGS="$CFLAGS -fomit-frame-pointer"
1012 fi
1013
1014 if [ "$strip" = "yes" ]; then
1015     CFLAGS="$CFLAGS -s"
1016     LDFLAGS="$LDFLAGS -s"
1017 fi
1018
1019 if [ "$debug" = "yes" ]; then
1020     CFLAGS="-O1 -g $CFLAGS"
1021 elif [ $ARCH = ARM ]; then
1022     # arm-gcc-4.2 produces incorrect output with -ffast-math
1023     # and it doesn't save any speed anyway on 4.4, so disable it
1024     CFLAGS="-O3 -fno-fast-math $CFLAGS"
1025 else
1026     CFLAGS="-O3 -ffast-math $CFLAGS"
1027 fi
1028
1029 if cc_check '' -fno-tree-vectorize ; then
1030     CFLAGS="$CFLAGS -fno-tree-vectorize"
1031 fi
1032
1033 if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then
1034     # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero
1035     cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss"
1036 fi
1037
1038 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
1039     define fseek fseeko
1040     define ftell ftello
1041 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
1042     define fseek fseeko64
1043     define ftell ftello64
1044 elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then
1045     define fseek _fseeki64
1046     define ftell _ftelli64
1047 fi
1048
1049 if cc_check '' -Wshadow ; then
1050     CFLAGS="-Wshadow $CFLAGS"
1051 fi
1052
1053 if [ "$bit_depth" -gt "8" ]; then
1054     define HIGH_BIT_DEPTH
1055     ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=1"
1056     opencl="no"
1057     mpeg2="no"
1058 else
1059     ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH=0"
1060 fi
1061
1062 if [ "$chroma_format" != "all" ]; then
1063     define CHROMA_FORMAT CHROMA_$chroma_format
1064 fi
1065
1066 if [ "$chroma_format" = "444" ]; then
1067     mpeg2="no"
1068 fi
1069
1070 ASFLAGS="$ASFLAGS -DBIT_DEPTH=$bit_depth"
1071
1072 [ $gpl = yes ] && define HAVE_GPL && x264_gpl=1 || x264_gpl=0
1073
1074 [ $interlaced = yes ] && define HAVE_INTERLACED && x264_interlaced=1 || x264_interlaced=0
1075
1076 [ $mpeg2 = yes ] && define HAVE_MPEG2 && x264_mpeg2=1 || x264_mpeg2=0
1077
1078 libdl=""
1079 if [ "$opencl" = "yes" ]; then
1080     opencl="no"
1081     log_check "for perl"
1082     output=$(perl -v)
1083     if [ "$output" = "" ]; then
1084         log_fail
1085         echo 'OpenCL support requires perl to compile.'
1086         echo 'use --disable-opencl to compile without OpenCL.'
1087         exit 1
1088     fi
1089     log_ok
1090     # cygwin can use opencl if it can use LoadLibrary
1091     if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
1092         opencl="yes"
1093         define HAVE_OPENCL
1094     elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
1095         opencl="yes"
1096         define HAVE_OPENCL
1097         libdl="-ldl"
1098     fi
1099     LDFLAGS="$LDFLAGS $libdl"
1100 fi
1101
1102 #define undefined vars as 0
1103 for var in $CONFIG_HAVE; do
1104     grep -q "HAVE_$var 1" config.h || define HAVE_$var 0
1105 done
1106
1107 if [ $compiler = ICL ]; then
1108     AR="xilib -nologo -out:"
1109     DEPMM=-QMM
1110     DEPMT=-QMT
1111     HAVE_GETOPT_LONG=0
1112     LD="xilink -out:"
1113     LDFLAGS="-nologo -incremental:no $(icl_ldflags $LDFLAGS)"
1114     LDFLAGSCLI="$(icl_ldflags $LDFLAGSCLI)"
1115     LIBX264=libx264.lib
1116     RANLIB=
1117     [ -n "$RC" ] && RCFLAGS="$RCFLAGS -I. -I\$(SRCPATH)/extras -fo"
1118     STRIP=
1119     if [ $debug = yes ]; then
1120         LDFLAGS="-debug $LDFLAGS"
1121         CFLAGS="-D_DEBUG $CFLAGS"
1122     else
1123         CFLAGS="-DNDEBUG $CFLAGS"
1124     fi
1125 else
1126     AR="$AR rc "
1127     DEPMM="-MM -g0"
1128     DEPMT="-MT"
1129     LD="$CC -o "
1130     LIBX264=libx264.a
1131     [ -n "$RC" ] && RCFLAGS="$RCFLAGS -I. -o "
1132 fi
1133 if [ $compiler = GNU ]; then
1134     PROF_GEN_CC="-fprofile-generate"
1135     PROF_GEN_LD="-fprofile-generate"
1136     PROF_USE_CC="-fprofile-use"
1137     PROF_USE_LD="-fprofile-use"
1138 else
1139     CFLAGS="$(intel_cflags $CFLAGS)"
1140     # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
1141     [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
1142     PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir."
1143     PROF_GEN_LD=
1144     PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir."
1145     PROF_USE_LD=
1146 fi
1147
1148 rm -f conftest*
1149
1150 # generate exported config file
1151
1152 config_chroma_format="X264_CSP_I$chroma_format"
1153 [ "$config_chroma_format" == "X264_CSP_Iall" ] && config_chroma_format="0"
1154 cat > x264_config.h << EOF
1155 #define X264_BIT_DEPTH     $bit_depth
1156 #define X264_GPL           $x264_gpl
1157 #define X264_INTERLACED    $x264_interlaced
1158 #define X264_MPEG2         $x264_mpeg2
1159 #define X264_CHROMA_FORMAT $config_chroma_format
1160 EOF
1161
1162 # generate config files
1163
1164 cat > config.mak << EOF
1165 SRCPATH=$SRCPATH
1166 prefix=$prefix
1167 exec_prefix=$exec_prefix
1168 bindir=$bindir
1169 libdir=$libdir
1170 includedir=$includedir
1171 ARCH=$ARCH
1172 SYS=$SYS
1173 CC=$CC
1174 CFLAGS=$CFLAGS
1175 DEPMM=$DEPMM
1176 DEPMT=$DEPMT
1177 LD=$LD
1178 LDFLAGS=$LDFLAGS
1179 LIBX264=$LIBX264
1180 AR=$AR
1181 RANLIB=$RANLIB
1182 STRIP=$STRIP
1183 INSTALL=$INSTALL
1184 AS=$AS
1185 ASFLAGS=$ASFLAGS
1186 RC=$RC
1187 RCFLAGS=$RCFLAGS
1188 EXE=$EXE
1189 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
1190 HAVE_MPEG2=$x264_mpeg2
1191 DEVNULL=$DEVNULL
1192 PROF_GEN_CC=$PROF_GEN_CC
1193 PROF_GEN_LD=$PROF_GEN_LD
1194 PROF_USE_CC=$PROF_USE_CC
1195 PROF_USE_LD=$PROF_USE_LD
1196 HAVE_OPENCL=$opencl
1197 EOF
1198
1199 if [ $compiler = ICL ]; then
1200     echo '%.o: %.c' >> config.mak
1201     echo '  $(CC) $(CFLAGS) -c -Fo$@ $<' >> config.mak
1202 fi
1203
1204 if [ "$cli" = "yes" ]; then
1205     echo 'default: cli' >> config.mak
1206     echo 'install: install-cli' >> config.mak
1207 fi
1208
1209 if [ "$shared" = "yes" ]; then
1210     API=$(grep '#define X264_BUILD' < ${SRCPATH}/x264.h | cut -f 3 -d ' ')
1211     if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
1212         echo "SONAME=libx264-$API.dll" >> config.mak
1213         if [ $compiler = ICL ]; then
1214             echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
1215             # GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations
1216             # MSVC link does not act similarly, so it is required to make an export definition out of x264.h and use it at link time
1217             echo "SOFLAGS=-dll -def:x264.def -implib:\$(IMPLIBNAME) $SOFLAGS" >> config.mak
1218             echo "EXPORTS" > x264.def
1219             # export API functions
1220             grep "^\(int\|void\|x264_t\).*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264.*\)(.*/\1/;s/open/open_$API/g" >> x264.def
1221             # export API variables/data. must be flagged with the DATA keyword
1222             grep "extern.*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264\w*\)\W.*/\1 DATA/;" >> x264.def
1223         else
1224             echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
1225             echo "SOFLAGS=-shared -Wl,--out-implib,\$(IMPLIBNAME) -Wl,--enable-auto-image-base $SOFLAGS" >> config.mak
1226         fi
1227     elif [ "$SYS" = "MACOSX" ]; then
1228         echo "SOSUFFIX=dylib" >> config.mak
1229         echo "SONAME=libx264.$API.dylib" >> config.mak
1230         echo "SOFLAGS=-shared -dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name \$(DESTDIR)\$(libdir)/\$(SONAME) $SOFLAGS" >> config.mak
1231     elif [ "$SYS" = "SunOS" ]; then
1232         echo "SOSUFFIX=so" >> config.mak
1233         echo "SONAME=libx264.so.$API" >> config.mak
1234         echo "SOFLAGS=-shared -Wl,-h,\$(SONAME) $SOFLAGS" >> config.mak
1235     else
1236         echo "SOSUFFIX=so" >> config.mak
1237         echo "SONAME=libx264.so.$API" >> config.mak
1238         echo "SOFLAGS=-shared -Wl,-soname,\$(SONAME) $SOFLAGS" >> config.mak
1239     fi
1240     echo 'default: lib-shared' >> config.mak
1241     echo 'install: install-lib-shared' >> config.mak
1242 fi
1243
1244 if [ "$static" = "yes" ]; then
1245     echo 'default: lib-static' >> config.mak
1246     echo 'install: install-lib-static' >> config.mak
1247 fi
1248
1249 if [ "$cli_libx264" = "system" ] ; then
1250     if [ "$shared" = "yes" ]; then
1251         CLI_LIBX264='$(SONAME)'
1252     elif ${cross_prefix}pkg-config --exists x264 2>/dev/null; then
1253         LDFLAGSCLI="$LDFLAGSCLI $(${cross_prefix}pkg-config --libs x264)"
1254         CLI_LIBX264=
1255     else
1256         die "Can not find system libx264"
1257     fi
1258 else
1259     CLI_LIBX264='$(LIBX264)'
1260 fi
1261 echo "LDFLAGSCLI = $LDFLAGSCLI" >> config.mak
1262 echo "CLI_LIBX264 = $CLI_LIBX264" >> config.mak
1263
1264 ${SRCPATH}/version.sh "${SRCPATH}" >> x264_config.h
1265
1266 cat > x264.pc << EOF
1267 prefix=$prefix
1268 exec_prefix=$exec_prefix
1269 libdir=$libdir
1270 includedir=$includedir
1271
1272 Name: x264
1273 Description: H.264 (MPEG4 AVC) encoder library
1274 Version: $(grep POINTVER < x264_config.h | sed -e 's/.* "//; s/".*//')
1275 Libs: -L$libdir -lx264 $([ "$shared" = "yes" ] || echo $libpthread $libm $libdl)
1276 Libs.private: $([ "$shared" = "yes" ] && echo $libpthread $libm $libdl)
1277 Cflags: -I$includedir
1278 EOF
1279
1280 filters="crop select_every"
1281 gpl_filters=""
1282 [ $swscale = yes ] && filters="resize $filters"
1283 [ $gpl = yes ] && filters="$filters $gpl_filters"
1284
1285 cat > conftest.log <<EOF
1286 platform:      $ARCH
1287 system:        $SYS
1288 cli:           $cli
1289 libx264:       $cli_libx264
1290 shared:        $shared
1291 static:        $static
1292 asm:           $asm
1293 interlaced:    $interlaced
1294 mpeg2:         $mpeg2
1295 avs:           $avs
1296 lavf:          $lavf
1297 ffms:          $ffms
1298 mp4:           $mp4
1299 gpl:           $gpl
1300 thread:        $thread
1301 opencl:        $opencl
1302 filters:       $filters
1303 debug:         $debug
1304 gprof:         $gprof
1305 strip:         $strip
1306 PIC:           $pic
1307 bit depth:     $bit_depth
1308 chroma format: $chroma_format
1309 EOF
1310
1311 echo >> config.log
1312 cat conftest.log >> config.log
1313 cat conftest.log
1314 rm conftest.log
1315
1316 [ "$SRCPATH" != "." ] && ln -sf ${SRCPATH}/Makefile ./Makefile
1317 mkdir -p common/{arm,ppc,sparc,x86} encoder extras filters/video input output tools
1318
1319 echo
1320 echo "You can run 'make' or 'make fprofiled' now."
1321