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