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