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