]> git.sesse.net Git - x264/blob - configure
aeb215afc3b171e0be98220b0207d58b11c82565
[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             define HAVE_SWSCALE
553             swscale="yes"
554         else
555             echo "Warning: ${error}"
556         fi
557     fi
558 fi
559
560 if [ "$lavf" = "auto" ] ; then
561     lavf="no"
562     if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
563         LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libavutil libswscale)"
564         LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libavutil libswscale)"
565     fi
566     if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
567         LAVF_LIBS="-lavformat"
568         for lib in -lpostproc -lavcodec -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
569             cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
570         done
571     fi
572     LAVF_LIBS="-L. $LAVF_LIBS"
573     if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then
574         # libvautil/pixdesc.h included the private header intreadwrite.h until r21854
575         if cc_check libavutil/pixdesc.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
576             if [ "$swscale" = "yes" ]; then
577                 lavf="yes"
578                 define HAVE_LAVF
579             else
580                 echo "Warning: libavformat is not supported without swscale support"
581             fi
582         else
583             echo "Warning: libavutil is too old, update to ffmpeg r21854+"
584         fi
585     fi
586 fi
587
588 if [ "$ffms" = "auto" ] ; then
589     ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
590     ffms="no"
591
592     if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
593         FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
594         FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
595     fi
596     [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
597
598     if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
599         ffms="yes"
600     elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
601         ffms="yes"
602         FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
603     fi
604
605     error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
606     if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
607        ffms="no"
608        echo "Warning: $error"
609     fi
610     if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
611         echo "Warning: ffms is not supported without swscale support"
612         ffms="no"
613     fi
614 fi
615
616 if [ "$ffms" = "yes" ]; then
617     LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
618     CFLAGS="$CFLAGS $FFMS2_CFLAGS"
619     define HAVE_FFMS
620 elif [ "$lavf" = "yes" ]; then
621     LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
622     CFLAGS="$CFLAGS $LAVF_CFLAGS"
623 elif [ "$swscale" = "yes" ]; then
624     LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
625     CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
626 fi
627
628 GPAC_LIBS="-lgpac_static"
629 if [ $SYS = MINGW ]; then
630     GPAC_LIBS="$GPAC_LIBS -lwinmm"
631 fi
632 if [ "$gpac" = "auto" ] ; then
633     gpac="no"
634     if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
635         if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
636             gpac="yes"
637         else
638             echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
639         fi
640     fi
641 fi
642 if [ "$gpac" = "yes" ] ; then
643     define HAVE_GPAC
644     if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
645         define HAVE_GF_MALLOC
646     fi
647     LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
648 fi
649
650 if [ "$avs" = "auto" ] ; then
651     avs="no"
652     if [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
653         avs="yes"
654         define HAVE_AVS
655     fi
656 fi
657
658 if [ "$pic" = "yes" ] ; then
659     CFLAGS="$CFLAGS -fPIC"
660     ASFLAGS="$ASFLAGS -DPIC"
661     # resolve textrels in the x86 asm
662     cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
663 fi
664
665 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
666     CFLAGS="$CFLAGS -s -fomit-frame-pointer"
667     LDFLAGS="$LDFLAGS -s"
668 fi
669
670 if [ "$debug" = "yes" ]; then
671     CFLAGS="-O1 -g $CFLAGS"
672 elif [ $ARCH = ARM ]; then
673     # arm-gcc-4.2 produces incorrect output with -ffast-math
674     # and it doesn't save any speed anyway on 4.4, so disable it
675     CFLAGS="-O3 -fno-fast-math $CFLAGS"
676 else
677     CFLAGS="-O3 -ffast-math $CFLAGS"
678 fi
679
680 if cc_check '' -fno-tree-vectorize ; then
681     CFLAGS="$CFLAGS -fno-tree-vectorize"
682 fi
683
684 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
685     define fseek fseeko
686     define ftell ftello
687 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
688     define fseek fseeko64
689     define ftell ftello64
690 fi
691
692 if cc_check '' -Wshadow ; then
693     CFLAGS="-Wshadow $CFLAGS"
694 fi
695
696 if [ "$bit_depth" -gt "8" ]; then
697     define X264_HIGH_BIT_DEPTH
698 fi
699
700 define BIT_DEPTH $bit_depth
701
702 rm -f conftest*
703
704 # generate config files
705
706 cat > config.mak << EOF
707 prefix=$prefix
708 exec_prefix=$exec_prefix
709 bindir=$bindir
710 libdir=$libdir
711 includedir=$includedir
712 ARCH=$ARCH
713 SYS=$SYS
714 CC=$CC
715 CFLAGS=$CFLAGS
716 LDFLAGS=$LDFLAGS
717 LDFLAGSCLI=$LDFLAGSCLI
718 AR=$AR
719 RANLIB=$RANLIB
720 STRIP=$STRIP
721 AS=$AS
722 ASFLAGS=$ASFLAGS
723 EXE=$EXE
724 VIS=$vis
725 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
726 DEVNULL=$DEVNULL
727 EOF
728
729 if [ "$shared" = "yes" ]; then
730     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
731     if [ "$SYS" = "MINGW" ]; then
732         echo "SONAME=libx264-$API.dll" >> config.mak
733         echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
734         echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
735     elif [ "$SYS" = "MACOSX" ]; then
736         echo "SOSUFFIX=dylib" >> config.mak
737         echo "SONAME=libx264.$API.dylib" >> config.mak
738         echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
739     elif [ "$SYS" = "SunOS" ]; then
740         echo "SOSUFFIX=so" >> config.mak
741         echo "SONAME=libx264.so.$API" >> config.mak
742         echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
743     else
744         echo "SOSUFFIX=so" >> config.mak
745         echo "SONAME=libx264.so.$API" >> config.mak
746         echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
747     fi
748     echo 'default: $(SONAME)' >> config.mak
749 fi
750
751 ./version.sh >> config.h
752
753 pclibs="-L$libdir -lx264 $libpthread"
754
755 cat > x264.pc << EOF
756 prefix=$prefix
757 exec_prefix=$exec_prefix
758 libdir=$libdir
759 includedir=$includedir
760
761 Name: x264
762 Description: H.264 (MPEG4 AVC) encoder library
763 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
764 Libs: $pclibs
765 Cflags: -I$includedir
766 EOF
767
768 filters="crop select_every"
769 [ $swscale = yes ] && filters="resize $filters"
770
771 cat > conftest.log <<EOF
772 Platform:   $ARCH
773 System:     $SYS
774 asm:        $asm
775 avs:        $avs
776 lavf:       $lavf
777 ffms:       $ffms
778 gpac:       $gpac
779 pthread:    $pthread
780 filters:    $filters
781 debug:      $debug
782 gprof:      $gprof
783 PIC:        $pic
784 shared:     $shared
785 visualize:  $vis
786 bit depth:  $bit_depth
787 EOF
788
789 echo >> config.log
790 cat conftest.log >> config.log
791 cat conftest.log
792 rm conftest.log
793
794 echo
795 echo "You can run 'make' or 'make fprofiled' now."
796