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-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"
34 echo -n "checking $1... " >> config.log
38 echo "yes" >> config.log
42 echo "no" >> config.log
46 echo "$1" >> config.log
51 if [ -z "$1$2" ]; then
52 log_check "whether $CC works"
53 elif [ -z "$1" ]; then
58 elif [ -z "$1" ]; then
59 log_check "whether $CC supports $3"
61 log_check "for $3 in $1";
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
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 "--------------------------------------------------"
82 log_check "whether $3 is true"
84 [ -n "$1" ] && echo "#include <$1>" > conftest.c
85 echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c
87 if $CC conftest.c $CFLAGS $2 -E -o conftest >conftest.log 2>&1; then
93 log_msg "--------------------------------------------------"
94 cat conftest.log >> config.log
95 log_msg "--------------------------------------------------"
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
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 "--------------------------------------------------"
119 echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
128 rm -f config.h config.mak config.log x264.pc conftest*
131 exec_prefix='${prefix}'
132 bindir='${exec_prefix}/bin'
133 libdir='${exec_prefix}/lib'
134 includedir='${prefix}/include'
151 CFLAGS="$CFLAGS -Wall -I."
153 LDFLAGSCLI="$LDFLAGSCLI"
169 exec_prefix="$optarg"
196 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
199 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
202 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
215 LDFLAGS="$LDFLAGS -pg"
228 host="${opt#--host=}"
231 cross_prefix="${opt#--cross-prefix=}"
234 CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
235 LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
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]."
243 bit_depth=`expr $bit_depth + 0`
246 echo "Unknown option $opt, ignored"
251 CC="${CC-${cross_prefix}gcc}"
252 AR="${AR-${cross_prefix}ar}"
253 RANLIB="${RANLIB-${cross_prefix}ranlib}"
254 STRIP="${STRIP-${cross_prefix}strip}"
256 if [ "x$host" = x ]; then
257 host=`./config.guess`
259 # normalize a triplet into a quadruplet
260 host=`./config.sub $host`
263 host_cpu="${host%%-*}"
265 host_vendor="${host%%-*}"
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"
283 LDFLAGS="$LDFLAGS -lm"
288 LDFLAGS="$LDFLAGS -lm"
292 LDFLAGS="$LDFLAGS -lm"
296 CFLAGS="$CFLAGS -I/usr/X11R6/include"
297 LDFLAGS="$LDFLAGS -lm"
302 LDFLAGS="$LDFLAGS -lm"
308 if cc_check "" -mno-cygwin; then
309 CFLAGS="$CFLAGS -mno-cygwin"
310 LDFLAGS="$LDFLAGS -mno-cygwin"
321 LDFLAGS="$LDFLAGS -lm"
325 die "Unknown system $host, edit the configure"
333 ASFLAGS="$ASFLAGS -O2"
334 if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
335 CFLAGS="$CFLAGS -march=i686"
337 if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
338 CFLAGS="$CFLAGS -mfpmath=sse -msse"
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"
346 ASFLAGS="$ASFLAGS -f elf"
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"
358 elif [ "$SYS" = MINGW ]; then
359 ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
361 ASFLAGS="$ASFLAGS -f elf -m amd64"
366 if [ $asm = auto ] ; then
368 AS="${AS-${cross_prefix}gcc}"
369 if [ $SYS = MACOSX ] ; then
370 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
372 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
373 define HAVE_ALTIVEC_H
378 if [ $asm = auto ] && test "$(uname -m)" = "sun4u"; then
380 CFLAGS="$CFLAGS -mcpu=ultrasparc"
381 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
382 AS="${AS-${cross_prefix}as}"
383 ASFLAGS="$ASFLAGS -xarch=v8plusa"
388 mips|mipsel|mips64|mips64el)
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"
402 AS="${AS-${cross_prefix}gcc}"
415 ARCH="$(echo $host_cpu | tr a-z A-Z)"
419 log_msg "x264 configure script"
421 msg="Command line options:"
431 cc_check || die "No working C compiler found."
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"
439 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
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`
447 echo "Minimum version is yasm-0.6.2"
448 echo "If you really want to compile without asm, configure with --disable-asm."
451 if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
452 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
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."
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"
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"
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."
477 [ $asm = no ] && AS=""
478 [ "x$AS" = x ] && asm="no" || asm="yes"
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"
491 # autodetect options that weren't forced nor disabled
494 if test "$pthread" = "auto" ; then
501 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
503 libpthread="-lpthread"
504 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
506 libpthread="-lpthreadGC2"
507 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
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
513 libpthread="-lpthreadGC2 -lws2_32"
514 define PTW32_STATIC_LIB
518 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
521 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
525 if test "$pthread" = "yes" ; then
527 LDFLAGS="$LDFLAGS $libpthread"
530 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
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
541 if [ "$swscale" = "auto" ] ; then
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)"
547 [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"
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
555 echo "Warning: ${error}"
560 if [ "$lavf" = "auto" ] ; then
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)"
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"
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
580 echo "Warning: libavformat is not supported without swscale support"
583 echo "Warning: libavutil is too old, update to ffmpeg r21854+"
588 if [ "$ffms" = "auto" ] ; then
589 ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
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)"
596 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
598 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
600 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
602 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
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
608 echo "Warning: $error"
610 if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
611 echo "Warning: ffms is not supported without swscale support"
616 if [ "$ffms" = "yes" ]; then
617 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
618 CFLAGS="$CFLAGS $FFMS2_CFLAGS"
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"
628 GPAC_LIBS="-lgpac_static"
629 if [ $SYS = MINGW ]; then
630 GPAC_LIBS="$GPAC_LIBS -lwinmm"
632 if [ "$gpac" = "auto" ] ; then
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
638 echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
642 if [ "$gpac" = "yes" ] ; then
644 if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
645 define HAVE_GF_MALLOC
647 LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
650 if [ "$avs" = "auto" ] ; then
652 if [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
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"
665 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
666 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
667 LDFLAGS="$LDFLAGS -s"
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"
677 CFLAGS="-O3 -ffast-math $CFLAGS"
680 if cc_check '' -fno-tree-vectorize ; then
681 CFLAGS="$CFLAGS -fno-tree-vectorize"
684 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
687 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
688 define fseek fseeko64
689 define ftell ftello64
692 if cc_check '' -Wshadow ; then
693 CFLAGS="-Wshadow $CFLAGS"
696 if [ "$bit_depth" -gt "8" ]; then
697 define X264_HIGH_BIT_DEPTH
700 define BIT_DEPTH $bit_depth
704 # generate config files
706 cat > config.mak << EOF
708 exec_prefix=$exec_prefix
711 includedir=$includedir
717 LDFLAGSCLI=$LDFLAGSCLI
725 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
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
744 echo "SOSUFFIX=so" >> config.mak
745 echo "SONAME=libx264.so.$API" >> config.mak
746 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
748 echo 'default: $(SONAME)' >> config.mak
751 ./version.sh >> config.h
753 pclibs="-L$libdir -lx264 $libpthread"
757 exec_prefix=$exec_prefix
759 includedir=$includedir
762 Description: H.264 (MPEG4 AVC) encoder library
763 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
765 Cflags: -I$includedir
768 filters="crop select_every"
769 [ $swscale = yes ] && filters="resize $filters"
771 cat > conftest.log <<EOF
786 bit depth: $bit_depth
790 cat conftest.log >> config.log
795 echo "You can run 'make' or 'make fprofiled' now."