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