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