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-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"
35 echo -n "checking $1... " >> config.log
39 echo "yes" >> config.log
43 echo "no" >> config.log
47 echo "$1" >> config.log
52 if [ -z "$1$2" ]; then
53 log_check "whether $CC works"
54 elif [ -z "$1" ]; then
59 elif [ -z "$1" ]; then
60 log_check "whether $CC supports $3"
62 log_check "for $3 in $1";
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
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 "--------------------------------------------------"
83 log_check "whether $3 is true"
85 [ -n "$1" ] && echo "#include <$1>" > conftest.c
86 echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
88 if $CC conftest.c $CFLAGS $2 -E -o conftest >conftest.log 2>&1; then
94 log_msg "--------------------------------------------------"
95 cat conftest.log >> config.log
96 log_msg "--------------------------------------------------"
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
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 "--------------------------------------------------"
120 echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
129 rm -f config.h config.mak config.log x264.pc conftest*
132 exec_prefix='${prefix}'
133 bindir='${exec_prefix}/bin'
134 libdir='${exec_prefix}/lib'
135 includedir='${prefix}/include'
153 CFLAGS="$CFLAGS -Wall -I."
155 LDFLAGSCLI="$LDFLAGSCLI"
171 exec_prefix="$optarg"
201 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
204 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
207 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
220 LDFLAGS="$LDFLAGS -pg"
233 host="${opt#--host=}"
236 cross_prefix="${opt#--cross-prefix=}"
239 CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
240 LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
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]."
248 bit_depth=`expr $bit_depth + 0`
251 echo "Unknown option $opt, ignored"
256 CC="${CC-${cross_prefix}gcc}"
257 AR="${AR-${cross_prefix}ar}"
258 RANLIB="${RANLIB-${cross_prefix}ranlib}"
259 STRIP="${STRIP-${cross_prefix}strip}"
261 if [ "x$host" = x ]; then
262 host=`./config.guess`
264 # normalize a triplet into a quadruplet
265 host=`./config.sub $host`
268 host_cpu="${host%%-*}"
270 host_vendor="${host%%-*}"
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"
288 LDFLAGS="$LDFLAGS -lm"
293 LDFLAGS="$LDFLAGS -lm"
297 LDFLAGS="$LDFLAGS -lm"
301 LDFLAGS="$LDFLAGS -lm"
306 LDFLAGS="$LDFLAGS -lm"
312 if cc_check "" -mno-cygwin; then
313 CFLAGS="$CFLAGS -mno-cygwin"
314 LDFLAGS="$LDFLAGS -mno-cygwin"
325 LDFLAGS="$LDFLAGS -lm"
329 die "Unknown system $host, edit the configure"
337 ASFLAGS="$ASFLAGS -O2"
338 if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
339 CFLAGS="$CFLAGS -march=i686"
341 if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
342 CFLAGS="$CFLAGS -mfpmath=sse -msse"
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"
350 ASFLAGS="$ASFLAGS -f elf"
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"
362 elif [ "$SYS" = MINGW ]; then
363 ASFLAGS="$ASFLAGS -f win32 -m amd64"
364 cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
366 ASFLAGS="$ASFLAGS -f elf -m amd64"
371 if [ $asm = auto ] ; then
373 AS="${AS-${cross_prefix}gcc}"
374 if [ $SYS = MACOSX ] ; then
375 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
377 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
378 define HAVE_ALTIVEC_H
383 if [ $asm = auto ] && test "$(uname -m)" = "sun4u"; then
385 CFLAGS="$CFLAGS -mcpu=ultrasparc"
386 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
387 AS="${AS-${cross_prefix}as}"
388 ASFLAGS="$ASFLAGS -xarch=v8plusa"
393 mips|mipsel|mips64|mips64el)
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"
407 AS="${AS-${cross_prefix}gcc}"
420 ARCH="$(echo $host_cpu | tr a-z A-Z)"
424 log_msg "x264 configure script"
426 msg="Command line options:"
436 cc_check || die "No working C compiler found."
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"
444 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
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`
452 echo "Minimum version is yasm-0.6.2"
453 echo "If you really want to compile without asm, configure with --disable-asm."
456 if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
457 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
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."
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"
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"
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."
482 [ $asm = no ] && AS=""
483 [ "x$AS" = x ] && asm="no" || asm="yes"
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"
496 # autodetect options that weren't forced nor disabled
499 if test "$pthread" = "auto" ; then
506 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
508 libpthread="-lpthread"
509 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
511 libpthread="-lpthreadGC2"
512 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
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
518 libpthread="-lpthreadGC2 -lws2_32"
519 define PTW32_STATIC_LIB
523 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
526 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
530 if test "$pthread" = "yes" ; then
532 LDFLAGS="$LDFLAGS $libpthread"
535 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
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
547 CFLAGS="$save_CFLAGS"
551 if [ "$swscale" = "auto" ] ; then
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)"
557 [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"
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
567 echo "Warning: libavutil is too old, update to ffmpeg r19775+"
570 echo "Warning: ${error}"
575 if [ "$lavf" = "auto" ] ; then
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)"
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"
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
595 echo "Warning: libavformat is not supported without swscale support"
598 echo "Warning: libavutil is too old, update to ffmpeg r21854+"
603 if [ "$ffms" = "auto" ] ; then
604 ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
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)"
611 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
613 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
615 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
617 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
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
623 echo "Warning: $error"
625 if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
626 echo "Warning: ffms is not supported without swscale support"
631 if [ "$ffms" = "yes" ]; then
632 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
633 CFLAGS="$CFLAGS $FFMS2_CFLAGS"
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"
643 GPAC_LIBS="-lgpac_static"
644 if [ $SYS = MINGW ]; then
645 GPAC_LIBS="$GPAC_LIBS -lwinmm"
647 if [ "$gpac" = "auto" ] ; then
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
653 echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
657 if [ "$gpac" = "yes" ] ; then
659 if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
660 define HAVE_GF_MALLOC
662 LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
665 if [ "$avs" = "auto" ] ; then
667 if [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
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"
680 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
681 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
682 LDFLAGS="$LDFLAGS -s"
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"
692 CFLAGS="-O3 -ffast-math $CFLAGS"
695 if cc_check '' -fno-tree-vectorize ; then
696 CFLAGS="$CFLAGS -fno-tree-vectorize"
699 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
702 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
703 define fseek fseeko64
704 define ftell ftello64
707 if cc_check '' -Wshadow ; then
708 CFLAGS="-Wshadow $CFLAGS"
711 if [ "$bit_depth" -gt "8" ]; then
712 define X264_HIGH_BIT_DEPTH
715 define BIT_DEPTH $bit_depth
717 if [ $gpl = yes ]; then
725 # generate config files
727 cat > config.mak << EOF
729 exec_prefix=$exec_prefix
732 includedir=$includedir
738 LDFLAGSCLI=$LDFLAGSCLI
746 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
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
766 echo "SOSUFFIX=so" >> config.mak
767 echo "SONAME=libx264.so.$API" >> config.mak
768 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
770 echo 'default: $(SONAME)' >> config.mak
773 ./version.sh >> config.h
775 pclibs="-L$libdir -lx264 $libpthread"
779 exec_prefix=$exec_prefix
781 includedir=$includedir
784 Description: H.264 (MPEG4 AVC) encoder library
785 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
787 Cflags: -I$includedir
790 filters="crop select_every"
792 [ $swscale = yes ] && filters="resize $filters"
793 [ $gpl = yes ] && filters="$filters $gpl_filters"
795 cat > conftest.log <<EOF
811 bit depth: $bit_depth
815 cat conftest.log >> config.log
820 echo "You can run 'make' or 'make fprofiled' now."