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 assembly optimizations on x86 and arm"
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"
31 echo -n "checking $1... " >> config.log
35 echo "yes" >> config.log
39 echo "no" >> config.log
43 echo "$1" >> config.log
48 if [ -z "$1$2" ]; then
49 log_check "whether $CC works"
50 elif [ -z "$1" ]; then
55 elif [ -z "$1" ]; then
56 log_check "whether $CC supports $3"
58 log_check "for $3 in $1";
61 [ -n "$1" ] && echo "#include <$1>" > conftest.c
62 echo "int main () { $3 return 0; }" >> conftest.c
63 if $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then
69 log_msg "Failed commandline was:"
70 log_msg "--------------------------------------------------"
71 log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2"
72 cat conftest.log >> config.log
73 log_msg "--------------------------------------------------"
79 log_check "whether $AS supports $1"
80 echo "$1" > conftest.asm
81 if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
87 log_msg "Failed commandline was:"
88 log_msg "--------------------------------------------------"
89 log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
90 cat conftest.log >> config.log
91 log_msg "--------------------------------------------------"
97 echo "#define $1$([ -n "$2" ] && echo " $2")" >> config.h
106 rm -f config.h config.mak config.log x264.pc conftest*
109 exec_prefix='${prefix}'
110 bindir='${exec_prefix}/bin'
111 libdir='${exec_prefix}/lib'
112 includedir='${prefix}/include'
127 CFLAGS="$CFLAGS -Wall -I."
129 LDFLAGSCLI="$LDFLAGSCLI"
145 exec_prefix="$optarg"
171 --disable-lavf-input)
177 --disable-ffms-input)
183 --disable-mp4-output)
187 ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
190 CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
193 LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
196 pthread="auto" # can't skip detection, since it differs by OS
206 LDFLAGS="$LDFLAGS -pg"
216 LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
217 define HAVE_VISUALIZE
221 host="${opt#--host=}"
224 cross_prefix="${opt#--cross-prefix=}"
227 echo "Unknown option $opt, ignored"
232 CC="${CC-${cross_prefix}gcc}"
233 AR="${AR-${cross_prefix}ar}"
234 RANLIB="${RANLIB-${cross_prefix}ranlib}"
235 STRIP="${STRIP-${cross_prefix}strip}"
237 if [ "x$host" = x ]; then
238 host=`./config.guess`
240 # normalize a triplet into a quadruplet
241 host=`./config.sub $host`
244 host_cpu="${host%%-*}"
246 host_vendor="${host%%-*}"
256 CFLAGS="$CFLAGS -falign-loops=16"
257 LDFLAGS="$LDFLAGS -lm"
258 if [ "$pic" = "no" ]; then
259 cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
264 LDFLAGS="$LDFLAGS -lm"
269 LDFLAGS="$LDFLAGS -lm"
273 LDFLAGS="$LDFLAGS -lm"
277 CFLAGS="$CFLAGS -I/usr/X11R6/include"
278 LDFLAGS="$LDFLAGS -lm"
283 LDFLAGS="$LDFLAGS -lm"
289 if cc_check "" -mno-cygwin; then
290 CFLAGS="$CFLAGS -mno-cygwin"
291 LDFLAGS="$LDFLAGS -mno-cygwin"
302 LDFLAGS="$LDFLAGS -lm"
306 die "Unknown system $host, edit the configure"
314 ASFLAGS="$ASFLAGS -O2"
315 if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
316 CFLAGS="$CFLAGS -march=i686"
318 if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then
319 CFLAGS="$CFLAGS -mfpmath=sse -msse"
321 if [ "$SYS" = MACOSX ]; then
322 ASFLAGS="$ASFLAGS -f macho -DPREFIX"
323 elif [ "$SYS" = MINGW ]; then
324 ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
326 ASFLAGS="$ASFLAGS -f elf"
332 if [ "$SYS" = MACOSX ];then
333 ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
334 if cc_check '' "-arch x86_64"; then
335 CFLAGS="$CFLAGS -arch x86_64"
336 LDFLAGS="$LDFLAGS -arch x86_64"
338 elif [ "$SYS" = MINGW ]; then
339 ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
341 ASFLAGS="$ASFLAGS -f elf -m amd64"
348 CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
350 CFLAGS="$CFLAGS -maltivec -mabi=altivec"
351 define HAVE_ALTIVEC_H
355 if test "$(uname -m)" = "sun4u"; then
357 CFLAGS="$CFLAGS -mcpu=ultrasparc"
358 LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
359 AS="${cross_prefix}as"
360 ASFLAGS="$ASFLAGS -xarch=v8plusa"
365 mips|mipsel|mips64|mips64el)
370 AS="${AS-${cross_prefix}gcc}"
379 ARCH="$(echo $host_cpu | tr a-z A-Z)"
383 log_msg "x264 configure script"
385 msg="Command line options:"
395 cc_check || die "No working C compiler found."
397 if cc_check '' -std=gnu99 ; then
398 CFLAGS="$CFLAGS -std=gnu99"
399 elif cc_check '' -std=c99 ; then
400 CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
403 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" \) ] ; then
407 if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
408 if ! as_check "lzcnt eax, eax" ; then
409 VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
411 echo "Minimum version is yasm-0.6.2"
412 echo "If you really want to compile without asm, configure with --disable-asm."
415 if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
416 VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
418 echo "Minimum version is binutils-2.17"
419 echo "Your compiler can't handle inline SSSE3 asm."
420 echo "If you really want to compile without asm, configure with --disable-asm."
426 if [ $asm = yes -a $ARCH = ARM ] ; then
427 # set flags so neon is built by default
428 echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
430 if cc_check '' '' '__asm__("rev ip, ip");' ; then define HAVE_ARMV6 && ASFLAGS="$ASFLAGS -DHAVE_ARMV6"
431 cc_check '' '' '__asm__("movt r0, #0");' && define HAVE_ARMV6T2 && ASFLAGS="$ASFLAGS -DHAVE_ARMV6T2"
432 cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON && ASFLAGS="$ASFLAGS -DHAVE_NEON"
433 ASFLAGS="$ASFLAGS -c"
435 echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
436 echo "If you really want to run on such a CPU, configure with --disable-asm."
441 [ $asm = no ] && AS=""
442 [ "x$AS" = x ] && asm="no"
447 echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
448 $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
449 if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
450 define WORDS_BIGENDIAN
451 elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
452 die "endian test failed"
455 # autodetect options that weren't forced nor disabled
458 if test "$pthread" = "auto" ; then
465 if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
467 libpthread="-lpthread"
468 elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
470 libpthread="-lpthreadGC2"
471 elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
473 libpthread="-lpthreadGC2 -lwsock32"
474 define PTW32_STATIC_LIB
475 elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
477 libpthread="-lpthreadGC2 -lws2_32"
478 define PTW32_STATIC_LIB
482 cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
485 cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
489 if test "$pthread" = "yes" ; then
491 LDFLAGS="$LDFLAGS $libpthread"
494 if cc_check "math.h" "-Werror" "return log2f(2);" ; then
498 if [ "$lavf_input" = "auto" ] ; then
500 if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
501 LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libswscale)"
502 LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libswscale)"
504 if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
505 LAVF_LIBS="-lavformat -lswscale"
506 for lib in -lpostproc -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
507 cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
510 LAVF_LIBS="-L. $LAVF_LIBS"
511 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \
512 cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
513 # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
514 if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
518 echo "Warning: libavformat is too old, update to ffmpeg r18351+"
523 if [ "$ffms_input" = "auto" ] ; then
524 ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
527 [ $ffms_micro -gt 0 -o $ffms_bump -gt 0 ] && vmicro=".$ffms_micro"
528 [ $ffms_bump -gt 0 ] && vbump=".$ffms_bump"
529 if ${cross_prefix}pkg-config --atleast-version="$ffms_major.$ffms_minor$vmicro$vbump" ffms2 2>$DEVNULL; then
530 FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
531 FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
536 [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
538 if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
540 elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
542 FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
545 if [ $api_check = "yes" -a $ffms_input = "yes" ]; then
546 log_check "whether ffms2 version is at least $ffms_major.$ffms_minor$vmicro$vbump"
547 $CC $CFLAGS $FFMS2_CFLAGS -c -o conftest -x c - >$DEVNULL 2>&1 <<EOF
549 #if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)
550 #error Requires ffms2 version 2.13.1
553 [ $? = 0 ] && log_ok || { ffms_input="no"; log_fail; }
557 if [ "$ffms_input" = "yes" ]; then
558 LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
559 [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
561 elif [ "$lavf_input" = "yes" ]; then
562 LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
563 [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
566 MP4_LDFLAGS="-lgpac_static"
567 if [ $SYS = MINGW ]; then
568 MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
570 if [ "$mp4_output" = "auto" ] ; then
572 cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
574 if [ "$mp4_output" = "yes" ] ; then
576 LDFLAGSCLI="$LDFLAGSCLI $MP4_LDFLAGS"
579 if [ "$avs_input" = "auto" ] ; then
581 if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
584 define HAVE_AVISYNTH_C_H
585 elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
591 if [ "$pic" = "yes" ] ; then
592 CFLAGS="$CFLAGS -fPIC"
593 ASFLAGS="$ASFLAGS -DPIC"
594 # resolve textrels in the x86 asm
595 cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
598 if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
599 CFLAGS="$CFLAGS -s -fomit-frame-pointer"
600 LDFLAGS="$LDFLAGS -s"
603 if [ "$debug" = "yes" ]; then
604 CFLAGS="-O1 -g $CFLAGS"
605 elif [ $ARCH = ARM ]; then
606 # arm-gcc-4.2 produces incorrect output with -ffast-math
607 # and it doesn't save any speed anyway on 4.4, so disable it
608 CFLAGS="-O3 -fno-fast-math $CFLAGS"
610 CFLAGS="-O3 -ffast-math $CFLAGS"
613 if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
616 elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
617 define fseek fseeko64
618 define ftell ftello64
623 # generate config files
625 cat > config.mak << EOF
627 exec_prefix=$exec_prefix
630 includedir=$includedir
636 LDFLAGSCLI=$LDFLAGSCLI
644 HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
648 if [ "$shared" = "yes" ]; then
649 API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
650 if [ "$SYS" = "MINGW" ]; then
651 echo "SONAME=libx264-$API.dll" >> config.mak
652 echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
653 echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
654 elif [ "$SYS" = "MACOSX" ]; then
655 echo "SOSUFFIX=dylib" >> config.mak
656 echo "SONAME=libx264.$API.dylib" >> config.mak
657 echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
658 elif [ "$SYS" = "SunOS" ]; then
659 echo "SOSUFFIX=so" >> config.mak
660 echo "SONAME=libx264.so.$API" >> config.mak
661 echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
663 echo "SOSUFFIX=so" >> config.mak
664 echo "SONAME=libx264.so.$API" >> config.mak
665 echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
667 echo 'default: $(SONAME)' >> config.mak
672 pclibs="-L$libdir -lx264 $libpthread"
676 exec_prefix=$exec_prefix
678 includedir=$includedir
681 Description: H.264 (MPEG4 AVC) encoder library
682 Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
684 Cflags: -I$includedir
687 cat > conftest.log <<EOF
691 avs input: $avs_input
692 lavf input: $lavf_input
693 ffms input: $ffms_input
694 mp4 output: $mp4_output
704 cat conftest.log >> config.log
709 echo "You can run 'make' or 'make fprofiled' now."