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-input disables avisynth input (win32 only)"
11 echo " --disable-lavf-input disables libavformat input"
12 echo " --disable-ffms-input disables ffmpegsource input"
13 echo " --disable-mp4-output disables mp4 output (using gpac)"
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 " --extra-asflags=EASFLAGS add EASFLAGS to ASFLAGS"
22 echo " --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS"
23 echo " --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
24 echo " --host=HOST build programs to run on HOST"
25 echo " --cross-prefix=PREFIX use PREFIX for compilation tools"
26 echo " --sysroot=SYSROOT root of cross-build tree"
32 echo -n "checking $1... " >> config.log
36 echo "yes" >> config.log
40 echo "no" >> config.log
44 echo "$1" >> config.log
49 if [ -z "$1$2" ]; then
50 log_check "whether $CC works"
51 elif [ -z "$1" ]; then
56 elif [ -z "$1" ]; then
57 log_check "whether $CC supports $3"
59 log_check "for $3 in $1";
62 [ -n "$1" ] && echo "#include <$1>" > conftest.c
63 echo "int main () { $3 return 0; }" >> conftest.c
64 if $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then
70 log_msg "Failed commandline was:"
71 log_msg "--------------------------------------------------"
72 log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2"
73 cat conftest.log >> config.log
74 log_msg "--------------------------------------------------"
80 log_check "whether $AS supports $1"
81 echo "$1" > conftest.asm
82 if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
88 log_msg "Failed commandline was:"
89 log_msg "--------------------------------------------------"
90 log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
91 cat conftest.log >> config.log
92 log_msg "--------------------------------------------------"
98 echo "#define $1$([ -n "$2" ] && echo " $2")" >> config.h
107 rm -f config.h config.mak config.log x264.pc conftest*
110 exec_prefix='${prefix}'
111 bindir='${exec_prefix}/bin'
112 libdir='${exec_prefix}/lib'
113 includedir='${prefix}/include'
128 CFLAGS="$CFLAGS -Wall -I."
130 LDFLAGSCLI="$LDFLAGSCLI"
146 exec_prefix="$optarg"
163 --disable-lavf-input)
166 --disable-ffms-input)
169 --disable-mp4-output)
173 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
176 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
179 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
189 LDFLAGS="$LDFLAGS -pg"
202 host="${opt#--host=}"
205 cross_prefix="${opt#--cross-prefix=}"
208 CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
209 LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
212 echo "Unknown option $opt, ignored"
217 CC="${CC-${cross_prefix}gcc}"
218 AR="${AR-${cross_prefix}ar}"
219 RANLIB="${RANLIB-${cross_prefix}ranlib}"
220 STRIP="${STRIP-${cross_prefix}strip}"
222 if [ "x$host" = x ]; then
223 host=`./config.guess`
225 # normalize a triplet into a quadruplet
226 host=`./config.sub $host`
229 host_cpu="${host%%-*}"
231 host_vendor="${host%%-*}"
241 CFLAGS="$CFLAGS -falign-loops=16"
242 LDFLAGS="$LDFLAGS -lm"
243 if [ "$pic" = "no" ]; then
244 cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
249 LDFLAGS="$LDFLAGS -lm"
254 LDFLAGS="$LDFLAGS -lm"
258 LDFLAGS="$LDFLAGS -lm"
262 CFLAGS="$CFLAGS -I/usr/X11R6/include"
263 LDFLAGS="$LDFLAGS -lm"
268 LDFLAGS="$LDFLAGS -lm"
274 if cc_check "" -mno-cygwin; then
275 CFLAGS="$CFLAGS -mno-cygwin"
276 LDFLAGS="$LDFLAGS -mno-cygwin"
287 LDFLAGS="$LDFLAGS -lm"
291 die "Unknown system $host, edit the configure"
299 ASFLAGS="$ASFLAGS -O2"
300 if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
301 CFLAGS="$CFLAGS -march=i686"
303 if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then
304 CFLAGS="$CFLAGS -mfpmath=sse -msse"
306 if [ "$SYS" = MACOSX ]; then
307 ASFLAGS="$ASFLAGS -f macho -DPREFIX"
308 elif [ "$SYS" = MINGW ]; then
309 ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
311 ASFLAGS="$ASFLAGS -f elf"
317 if [ "$SYS" = MACOSX ];then
318 ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
319 if cc_check '' "-arch x86_64"; then
320 CFLAGS="$CFLAGS -arch x86_64"
321 LDFLAGS="$LDFLAGS -arch x86_64"
323 elif [ "$SYS" = MINGW ]; then
324 ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
326 ASFLAGS="$ASFLAGS -f elf -m amd64"
331 if [ $asm = yes ] ; then
333 AS="${AS-${cross_prefix}gcc}"
334 if [ $SYS = MACOSX ] ; then
335 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
337 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
338 define HAVE_ALTIVEC_H
343 if [ $asm = yes ] && test "$(uname -m)" = "sun4u"; then
345 CFLAGS="$CFLAGS -mcpu=ultrasparc"
346 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
347 AS="${AS-${cross_prefix}as}"
348 ASFLAGS="$ASFLAGS -xarch=v8plusa"
353 mips|mipsel|mips64|mips64el)
358 if [ "$SYS" = MACOSX ] ; then
359 AS="${AS-extras/gas-preprocessor.pl $CC}"
360 ASFLAGS="$ASFLAGS -DPREFIX -DPIC" # apple's ld doesn't support movw/movt relocations at all
361 # build for armv7 by default
362 if ! echo $CFLAGS | grep -Eq '\-arch' ; then
363 CFLAGS="$CFLAGS -arch armv7"
364 LDFLAGS="$LDFLAGS -arch armv7"
367 AS="${AS-${cross_prefix}gcc}"
380 ARCH="$(echo $host_cpu | tr a-z A-Z)"
384 log_msg "x264 configure script"
386 msg="Command line options:"
396 cc_check || die "No working C compiler found."
398 if cc_check '' -std=gnu99 ; then
399 CFLAGS="$CFLAGS -std=gnu99"
400 elif cc_check '' -std=c99 ; then
401 CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
404 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
408 if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
409 if ! as_check "lzcnt eax, eax" ; then
410 VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
412 echo "Minimum version is yasm-0.6.2"
413 echo "If you really want to compile without asm, configure with --disable-asm."
416 if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
417 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
419 echo "Minimum version is binutils-2.17"
420 echo "Your compiler can't handle inline SSSE3 asm."
421 echo "If you really want to compile without asm, configure with --disable-asm."
427 if [ $asm = auto -a $ARCH = ARM ] ; then
428 # set flags so neon is built by default
429 echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
431 if cc_check '' '' '__asm__("rev ip, ip");' ; then define HAVE_ARMV6
432 cc_check '' '' '__asm__("movt r0, #0");' && define HAVE_ARMV6T2
433 cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
434 ASFLAGS="$ASFLAGS $CFLAGS -c"
436 echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
437 echo "If you really want to run on such a CPU, configure with --disable-asm."
442 [ $asm = no ] && AS=""
443 [ "x$AS" = x ] && asm="no" || asm="yes"
448 echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
449 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
450 if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
451 define WORDS_BIGENDIAN
452 elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
453 die "endian test failed"
456 # autodetect options that weren't forced nor disabled
459 if test "$pthread" = "auto" ; then
466 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
468 libpthread="-lpthread"
469 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
471 libpthread="-lpthreadGC2"
472 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
474 libpthread="-lpthreadGC2 -lwsock32"
475 define PTW32_STATIC_LIB
476 elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
478 libpthread="-lpthreadGC2 -lws2_32"
479 define PTW32_STATIC_LIB
483 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
486 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
490 if test "$pthread" = "yes" ; then
492 LDFLAGS="$LDFLAGS $libpthread"
495 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
499 if [ "$vis" = "yes" ] && cc_check "X11/Xlib.h" "-L/usr/X11R6/lib -lX11" "XOpenDisplay( 0 );" ; then
500 LDFLAGS="-L/usr/X11R6/lib -lX11 $LDFLAGS"
501 define HAVE_VISUALIZE
506 if [ "$lavf_input" = "auto" ] ; then
508 if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
509 LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libswscale)"
510 LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libswscale)"
512 if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
513 LAVF_LIBS="-lavformat -lswscale"
514 for lib in -lpostproc -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
515 cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
518 LAVF_LIBS="-L. $LAVF_LIBS"
519 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \
520 cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
521 # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
522 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
526 echo "Warning: libavformat is too old, update to ffmpeg r18351+"
531 if [ "$ffms_input" = "auto" ] ; then
532 ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
535 [ $ffms_micro -gt 0 -o $ffms_bump -gt 0 ] && vmicro=".$ffms_micro"
536 [ $ffms_bump -gt 0 ] && vbump=".$ffms_bump"
537 if ${cross_prefix}pkg-config --atleast-version="$ffms_major.$ffms_minor$vmicro$vbump" ffms2 2>$DEVNULL; then
538 FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
539 FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
544 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
546 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
548 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
550 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
553 if [ $api_check = "yes" -a $ffms_input = "yes" ]; then
554 log_check "whether ffms2 version is at least $ffms_major.$ffms_minor$vmicro$vbump"
555 $CC $CFLAGS $FFMS2_CFLAGS -c -o conftest -x c - >$DEVNULL 2>&1 <<EOF
557 #if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)
558 #error Requires ffms2 version 2.13.1
561 [ $? = 0 ] && log_ok || { ffms_input="no"; log_fail; }
565 if [ "$ffms_input" = "yes" ]; then
566 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
567 [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
569 elif [ "$lavf_input" = "yes" ]; then
570 LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
571 [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
574 MP4_LDFLAGS="-lgpac_static"
575 if [ $SYS = MINGW ]; then
576 MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
578 if [ "$mp4_output" = "auto" ] ; then
580 if cc_check gpac/isomedia.h "$MP4_LDFLAGS" ; then
581 if cc_check gpac/isomedia.h "$MP4_LDFLAGS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
584 echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
588 if [ "$mp4_output" = "yes" ] ; then
590 if cc_check gpac/isomedia.h "-Werror $MP4_LDFLAGS" "gf_malloc(1); gf_free(NULL);" ; then
591 define HAVE_GF_MALLOC
593 LDFLAGSCLI="$LDFLAGSCLI $MP4_LDFLAGS"
596 if [ "$avs_input" = "auto" ] ; then
598 if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
601 define HAVE_AVISYNTH_C_H
602 elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
608 if [ "$pic" = "yes" ] ; then
609 CFLAGS="$CFLAGS -fPIC"
610 ASFLAGS="$ASFLAGS -DPIC"
611 # resolve textrels in the x86 asm
612 cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
615 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
616 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
617 LDFLAGS="$LDFLAGS -s"
620 if [ "$debug" = "yes" ]; then
621 CFLAGS="-O1 -g $CFLAGS"
622 elif [ $ARCH = ARM ]; then
623 # arm-gcc-4.2 produces incorrect output with -ffast-math
624 # and it doesn't save any speed anyway on 4.4, so disable it
625 CFLAGS="-O3 -fno-fast-math $CFLAGS"
627 CFLAGS="-O3 -ffast-math $CFLAGS"
630 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
633 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
634 define fseek fseeko64
635 define ftell ftello64
640 # generate config files
642 cat > config.mak << EOF
644 exec_prefix=$exec_prefix
647 includedir=$includedir
653 LDFLAGSCLI=$LDFLAGSCLI
661 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
665 if [ "$shared" = "yes" ]; then
666 API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
667 if [ "$SYS" = "MINGW" ]; then
668 echo "SONAME=libx264-$API.dll" >> config.mak
669 echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
670 echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
671 elif [ "$SYS" = "MACOSX" ]; then
672 echo "SOSUFFIX=dylib" >> config.mak
673 echo "SONAME=libx264.$API.dylib" >> config.mak
674 echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
675 elif [ "$SYS" = "SunOS" ]; then
676 echo "SOSUFFIX=so" >> config.mak
677 echo "SONAME=libx264.so.$API" >> config.mak
678 echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
680 echo "SOSUFFIX=so" >> config.mak
681 echo "SONAME=libx264.so.$API" >> config.mak
682 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
684 echo 'default: $(SONAME)' >> config.mak
687 ./version.sh >> config.h
689 pclibs="-L$libdir -lx264 $libpthread"
693 exec_prefix=$exec_prefix
695 includedir=$includedir
698 Description: H.264 (MPEG4 AVC) encoder library
699 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
701 Cflags: -I$includedir
704 cat > conftest.log <<EOF
708 avs input: $avs_input
709 lavf input: $lavf_input
710 ffms input: $ffms_input
711 mp4 output: $mp4_output
721 cat conftest.log >> config.log
726 echo "You can run 'make' or 'make fprofiled' now."