3 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
5 echo "Usage: ./configure [options]"
7 echo "available options:"
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"
33 echo -n "checking $1... " >> config.log
37 echo "yes" >> config.log
41 echo "no" >> config.log
45 echo "$1" >> config.log
50 if [ -z "$1$2" ]; then
51 log_check "whether $CC works"
52 elif [ -z "$1" ]; then
57 elif [ -z "$1" ]; then
58 log_check "whether $CC supports $3"
60 log_check "for $3 in $1";
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
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 "--------------------------------------------------"
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
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 "--------------------------------------------------"
99 echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
108 rm -f config.h config.mak config.log x264.pc conftest*
111 exec_prefix='${prefix}'
112 bindir='${exec_prefix}/bin'
113 libdir='${exec_prefix}/lib'
114 includedir='${prefix}/include'
130 CFLAGS="$CFLAGS -Wall -I."
132 LDFLAGSCLI="$LDFLAGSCLI"
148 exec_prefix="$optarg"
175 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
178 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
181 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
191 LDFLAGS="$LDFLAGS -pg"
204 host="${opt#--host=}"
207 cross_prefix="${opt#--cross-prefix=}"
210 CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
211 LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
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]."
219 bit_depth=`expr $bit_depth + 0`
222 echo "Unknown option $opt, ignored"
227 CC="${CC-${cross_prefix}gcc}"
228 AR="${AR-${cross_prefix}ar}"
229 RANLIB="${RANLIB-${cross_prefix}ranlib}"
230 STRIP="${STRIP-${cross_prefix}strip}"
232 if [ "x$host" = x ]; then
233 host=`./config.guess`
235 # normalize a triplet into a quadruplet
236 host=`./config.sub $host`
239 host_cpu="${host%%-*}"
241 host_vendor="${host%%-*}"
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"
259 LDFLAGS="$LDFLAGS -lm"
264 LDFLAGS="$LDFLAGS -lm"
268 LDFLAGS="$LDFLAGS -lm"
272 CFLAGS="$CFLAGS -I/usr/X11R6/include"
273 LDFLAGS="$LDFLAGS -lm"
278 LDFLAGS="$LDFLAGS -lm"
284 if cc_check "" -mno-cygwin; then
285 CFLAGS="$CFLAGS -mno-cygwin"
286 LDFLAGS="$LDFLAGS -mno-cygwin"
297 LDFLAGS="$LDFLAGS -lm"
301 die "Unknown system $host, edit the configure"
309 ASFLAGS="$ASFLAGS -O2"
310 if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
311 CFLAGS="$CFLAGS -march=i686"
313 if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
314 CFLAGS="$CFLAGS -mfpmath=sse -msse"
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"
322 ASFLAGS="$ASFLAGS -f elf"
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"
334 elif [ "$SYS" = MINGW ]; then
335 ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
337 ASFLAGS="$ASFLAGS -f elf -m amd64"
342 if [ $asm = auto ] ; then
344 AS="${AS-${cross_prefix}gcc}"
345 if [ $SYS = MACOSX ] ; then
346 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
348 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
349 define HAVE_ALTIVEC_H
354 if [ $asm = auto ] && test "$(uname -m)" = "sun4u"; then
356 CFLAGS="$CFLAGS -mcpu=ultrasparc"
357 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
358 AS="${AS-${cross_prefix}as}"
359 ASFLAGS="$ASFLAGS -xarch=v8plusa"
364 mips|mipsel|mips64|mips64el)
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"
378 AS="${AS-${cross_prefix}gcc}"
391 ARCH="$(echo $host_cpu | tr a-z A-Z)"
395 log_msg "x264 configure script"
397 msg="Command line options:"
407 cc_check || die "No working C compiler found."
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"
415 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
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`
423 echo "Minimum version is yasm-0.6.2"
424 echo "If you really want to compile without asm, configure with --disable-asm."
427 if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
428 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
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."
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"
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"
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."
453 [ $asm = no ] && AS=""
454 [ "x$AS" = x ] && asm="no" || asm="yes"
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"
467 # autodetect options that weren't forced nor disabled
470 if test "$pthread" = "auto" ; then
477 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
479 libpthread="-lpthread"
480 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
482 libpthread="-lpthreadGC2"
483 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
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
489 libpthread="-lpthreadGC2 -lws2_32"
490 define PTW32_STATIC_LIB
494 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
497 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
501 if test "$pthread" = "yes" ; then
503 LDFLAGS="$LDFLAGS $libpthread"
506 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
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
517 if [ "$lavf" = "auto" ] ; then
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)"
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"
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
537 echo "Warning: libavformat is too old, update to ffmpeg r18351+"
542 if [ "$ffms" = "auto" ] ; then
543 ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
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)"
555 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
557 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
559 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
561 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
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
568 #if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)
569 #error Requires ffms2 version 2.13.1
572 [ $? = 0 ] && log_ok || { ffms="no"; log_fail; }
576 if [ "$ffms" = "yes" ]; then
577 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
578 [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
580 elif [ "$lavf" = "yes" ]; then
581 LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
582 [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
585 GPAC_LIBS="-lgpac_static"
586 if [ $SYS = MINGW ]; then
587 GPAC_LIBS="$GPAC_LIBS -lwinmm"
589 if [ "$gpac" = "auto" ] ; then
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
595 echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
599 if [ "$gpac" = "yes" ] ; then
601 if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
602 define HAVE_GF_MALLOC
604 LDFLAGSCLI="$LDFLAGSCLI $GPAC_LIBS"
607 if [ "$avs" = "auto" ] ; then
609 if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
612 define HAVE_AVISYNTH_C_H
613 elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
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"
626 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
627 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
628 LDFLAGS="$LDFLAGS -s"
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"
638 CFLAGS="-O3 -ffast-math $CFLAGS"
641 if cc_check '' -fno-tree-vectorize ; then
642 CFLAGS="$CFLAGS -fno-tree-vectorize"
645 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
648 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
649 define fseek fseeko64
650 define ftell ftello64
653 if cc_check '' -Wshadow ; then
654 CFLAGS="-Wshadow $CFLAGS"
657 if [ "$bit_depth" -gt "8" ]; then
658 define X264_HIGH_BIT_DEPTH
661 define BIT_DEPTH $bit_depth
665 # generate config files
667 cat > config.mak << EOF
669 exec_prefix=$exec_prefix
672 includedir=$includedir
678 LDFLAGSCLI=$LDFLAGSCLI
686 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
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
705 echo "SOSUFFIX=so" >> config.mak
706 echo "SONAME=libx264.so.$API" >> config.mak
707 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
709 echo 'default: $(SONAME)' >> config.mak
712 ./version.sh >> config.h
714 pclibs="-L$libdir -lx264 $libpthread"
718 exec_prefix=$exec_prefix
720 includedir=$includedir
723 Description: H.264 (MPEG4 AVC) encoder library
724 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
726 Cflags: -I$includedir
729 cat > conftest.log <<EOF
743 bit depth: $bit_depth
747 cat conftest.log >> config.log
752 echo "You can run 'make' or 'make fprofiled' now."