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