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