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