configure 24.2 KB
Newer Older
1
#!/bin/bash
2

Loren Merritt's avatar
Loren Merritt committed
3 4 5 6 7 8 9
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then

echo "Usage: ./configure [options]"
echo ""
echo "available options:"
echo ""
echo "  --help                   print this message"
Steven Walters's avatar
Steven Walters committed
10 11 12 13
echo "  --disable-avs            disables avisynth support (windows only)"
echo "  --disable-lavf           disables libavformat support"
echo "  --disable-ffms           disables ffmpegsource support"
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"
Loren Merritt's avatar
Loren Merritt committed
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"
Loren Merritt's avatar
Loren Merritt committed
25 26
echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
27
echo "  --host=HOST              build programs to run on HOST"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
28
echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools"
David Conrad's avatar
David Conrad committed
29
echo "  --sysroot=SYSROOT        root of cross-build tree"
Loren Merritt's avatar
Loren Merritt committed
30 31 32 33
echo ""
exit 1
fi

Diogo Franco's avatar
Diogo Franco committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
log_check() {
    echo -n "checking $1... " >> config.log
}

log_ok() {
    echo "yes" >> config.log
}

log_fail() {
    echo "no" >> config.log
}

log_msg() {
    echo "$1" >> config.log
}

50
cc_check() {
Diogo Franco's avatar
Diogo Franco committed
51
    if [ -z "$3" ]; then
52
        if [ -z "$1$2" ]; then
Diogo Franco's avatar
Diogo Franco committed
53
            log_check "whether $CC works"
54 55
        elif [ -z "$1" ]; then
            log_check "for $2"
Diogo Franco's avatar
Diogo Franco committed
56 57 58 59 60 61
        else
            log_check "for $1"
        fi
    elif [ -z "$1" ]; then
        log_check "whether $CC supports $3"
    else
62
        log_check "for $3 in $1";
Diogo Franco's avatar
Diogo Franco committed
63
    fi
64 65 66
    rm -f conftest.c
    [ -n "$1" ] && echo "#include <$1>" > conftest.c
    echo "int main () { $3 return 0; }" >> conftest.c
67
    if $CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest >conftest.log 2>&1; then
Diogo Franco's avatar
Diogo Franco committed
68 69 70 71 72 73 74
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
75 76 77
        log_msg "$CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS"
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
78 79 80 81
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.c >> config.log
        log_msg "--------------------------------------------------"
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    fi
    return $res
}

cpp_check() {
    log_check "whether $3 is true"
    rm -f conftest.c
    [ -n "$1" ] && echo "#include <$1>" > conftest.c
    echo -e "#if !($3) \n#error $4 \n#endif " >> conftest.c

    if $CC conftest.c $CFLAGS $2 -E -o conftest >conftest.log 2>&1; then
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
99 100
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
101 102 103 104
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.c >> config.log
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
105 106
    fi
    return $res
107 108
}

109
as_check() {
Diogo Franco's avatar
Diogo Franco committed
110
    log_check "whether $AS supports $1"
111
    echo "$1" > conftest.asm
Diogo Franco's avatar
Diogo Franco committed
112 113 114 115 116 117 118 119 120 121 122
    if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
        log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
123 124 125 126
        log_msg "Failed program was:"
        log_msg "--------------------------------------------------"
        cat conftest.asm >> config.log
        log_msg "--------------------------------------------------"
Diogo Franco's avatar
Diogo Franco committed
127 128
    fi
    return $res
129 130
}

Diogo Franco's avatar
Diogo Franco committed
131
define() {
Steven Walters's avatar
Steven Walters committed
132
    echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
Diogo Franco's avatar
Diogo Franco committed
133 134
}

135
die() {
Diogo Franco's avatar
Diogo Franco committed
136
    log_msg "DIED: $@"
137 138 139 140
    echo "$@"
    exit 1
}

141
rm -f x264_config.h config.h config.mak config.log x264.pc conftest*
Loren Merritt's avatar
Loren Merritt committed
142

143
prefix='/usr/local'
Loren Merritt's avatar
Loren Merritt committed
144 145 146
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
147
includedir='${prefix}/include'
148
DEVNULL='/dev/null'
149

Steven Walters's avatar
Steven Walters committed
150 151 152 153
avs="auto"
lavf="auto"
ffms="auto"
gpac="auto"
154
gpl="yes"
155
pthread="auto"
156
swscale="auto"
157
asm="auto"
158
debug="no"
159
gprof="no"
160
pic="no"
Loren Merritt's avatar
Loren Merritt committed
161
vis="no"
162
shared="no"
163
bit_depth="8"
Loren Merritt's avatar
Loren Merritt committed
164

165
CFLAGS="$CFLAGS -Wall -I."
166
LDFLAGS="$LDFLAGS"
167
LDFLAGSCLI="$LDFLAGSCLI"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
168
ASFLAGS="$ASFLAGS"
169
HAVE_GETOPT_LONG=1
Anton Mitrofanov's avatar
Anton Mitrofanov committed
170
cross_prefix=""
171

Loren Merritt's avatar
Loren Merritt committed
172 173
EXE=""

174 175 176
# list of all preprocessor HAVE values we can define
CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON PTHREAD LOG2F VISUALIZE SWSCALE LAVF FFMS GPAC GF_MALLOC AVS GPL"

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
# parse options

for opt do
    optarg="${opt#*=}"
    case "$opt" in
        --prefix=*)
            prefix="$optarg"
            ;;
        --exec-prefix=*)
            exec_prefix="$optarg"
            ;;
        --bindir=*)
            bindir="$optarg"
            ;;
        --libdir=*)
            libdir="$optarg"
            ;;
        --includedir=*)
            includedir="$optarg"
            ;;
197 198 199
        --disable-asm)
            asm="no"
            ;;
Steven Walters's avatar
Steven Walters committed
200 201
        --disable-avs)
            avs="no"
202
            ;;
Steven Walters's avatar
Steven Walters committed
203 204
        --disable-lavf)
            lavf="no"
205
            ;;
Steven Walters's avatar
Steven Walters committed
206 207
        --disable-ffms)
            ffms="no"
208
            ;;
Steven Walters's avatar
Steven Walters committed
209 210
        --disable-gpac)
            gpac="no"
211
            ;;
212 213 214
        --disable-gpl)
            gpl="no"
            ;;
215 216 217 218 219 220 221 222 223 224 225 226
        --extra-asflags=*)
            ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
            ;;
        --extra-cflags=*)
            CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
            ;;
        --extra-ldflags=*)
            LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
            ;;
        --disable-pthread)
            pthread="no"
            ;;
227 228 229
        --disable-swscale)
            swscale="no"
            ;;
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        --enable-debug)
            debug="yes"
            ;;
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
        --enable-pic)
            pic="yes"
            ;;
        --enable-shared)
            shared="yes"
            ;;
        --enable-visualize)
            vis="yes"
            ;;
        --host=*)
            host="${opt#--host=}"
            ;;
Anton Mitrofanov's avatar
Anton Mitrofanov committed
250 251 252
        --cross-prefix=*)
            cross_prefix="${opt#--cross-prefix=}"
            ;;
David Conrad's avatar
David Conrad committed
253 254 255 256
        --sysroot=*)
            CFLAGS="$CFLAGS --sysroot=${opt#--sysroot=}"
            LDFLAGS="$LDFLAGS --sysroot=${opt#--sysroot=}"
            ;;
257 258 259 260 261 262 263 264
        --bit-depth=*)
            bit_depth="${opt#--bit-depth=}"
            if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
                echo "Supplied bit depth must be in range [8,10]."
                exit 1
            fi
            bit_depth=`expr $bit_depth + 0`
            ;;
265 266 267 268 269 270
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

Anton Mitrofanov's avatar
Anton Mitrofanov committed
271 272 273 274 275
CC="${CC-${cross_prefix}gcc}"
AR="${AR-${cross_prefix}ar}"
RANLIB="${RANLIB-${cross_prefix}ranlib}"
STRIP="${STRIP-${cross_prefix}strip}"

276 277 278 279 280
if [ "x$host" = x ]; then
    host=`./config.guess`
fi
# normalize a triplet into a quadruplet
host=`./config.sub $host`
281

282
# split $host
Loren Merritt's avatar
Loren Merritt committed
283
host_cpu="${host%%-*}"
284
host="${host#*-}"
Loren Merritt's avatar
Loren Merritt committed
285
host_vendor="${host%%-*}"
286
host_os="${host#*-}"
287 288

case $host_os in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
    beos*)
        SYS="BEOS"
        define HAVE_MALLOC_H
        ;;
    darwin*)
        SYS="MACOSX"
        CFLAGS="$CFLAGS -falign-loops=16"
        LDFLAGS="$LDFLAGS -lm"
        if [ "$pic" = "no" ]; then
            cc_check "" -mdynamic-no-pic && CFLAGS="$CFLAGS -mdynamic-no-pic"
        fi
        ;;
    freebsd*)
        SYS="FREEBSD"
        LDFLAGS="$LDFLAGS -lm"
        ;;
    kfreebsd*-gnu)
        SYS="FREEBSD"
        define HAVE_MALLOC_H
        LDFLAGS="$LDFLAGS -lm"
        ;;
    netbsd*)
        SYS="NETBSD"
        LDFLAGS="$LDFLAGS -lm"
        ;;
    openbsd*)
        SYS="OPENBSD"
        LDFLAGS="$LDFLAGS -lm"
        ;;
    *linux*)
        SYS="LINUX"
        define HAVE_MALLOC_H
        LDFLAGS="$LDFLAGS -lm"
        ;;
    cygwin*)
        SYS="MINGW"
        EXE=".exe"
        DEVNULL="NUL"
        if cc_check "" -mno-cygwin; then
            CFLAGS="$CFLAGS -mno-cygwin"
            LDFLAGS="$LDFLAGS -mno-cygwin"
        fi
        ;;
    mingw*)
        SYS="MINGW"
        EXE=".exe"
        DEVNULL="NUL"
        ;;
    sunos*|solaris*)
        SYS="SunOS"
        define HAVE_MALLOC_H
        LDFLAGS="$LDFLAGS -lm"
        HAVE_GETOPT_LONG=0
        ;;
    *)
        die "Unknown system $host, edit the configure"
        ;;
346 347
esac

348
case $host_cpu in
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    i*86)
        ARCH="X86"
        AS="yasm"
        ASFLAGS="$ASFLAGS -O2"
        if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
            CFLAGS="$CFLAGS -march=i686"
        fi
        if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
            CFLAGS="$CFLAGS -mfpmath=sse -msse"
        fi
        if [ "$SYS" = MACOSX ]; then
            ASFLAGS="$ASFLAGS -f macho -DPREFIX"
        elif [ "$SYS" = MINGW ]; then
            ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
            LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
        else
            ASFLAGS="$ASFLAGS -f elf"
366 367
        fi
        ;;
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
    x86_64)
        ARCH="X86_64"
        AS="yasm"
        if [ "$SYS" = MACOSX ];then
            ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
            if cc_check '' "-arch x86_64"; then
                CFLAGS="$CFLAGS -arch x86_64"
                LDFLAGS="$LDFLAGS -arch x86_64"
            fi
        elif [ "$SYS" = MINGW ]; then
            ASFLAGS="$ASFLAGS -f win32 -m amd64"
            cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX"
        else
            ASFLAGS="$ASFLAGS -f elf -m amd64"
        fi
        ;;
    powerpc|powerpc64)
        ARCH="PPC"
        if [ $asm = auto ] ; then
            define HAVE_ALTIVEC
            AS="${AS-${cross_prefix}gcc}"
            if [ $SYS = MACOSX ] ; then
                CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
            else
                CFLAGS="$CFLAGS -maltivec -mabi=altivec"
                define HAVE_ALTIVEC_H
            fi
        fi
        ;;
    sparc)
        ARCH="SPARC"
        case $(uname -m) in
            sun4u|sun4v)
                if [ $asm = auto ]; then
                    ARCH="UltraSPARC"
                    if ! echo $CFLAGS | grep -Eq '\-mcpu' ; then
                        CFLAGS="$CFLAGS -mcpu=ultrasparc"
                        LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
                    fi
                    AS="${AS-${cross_prefix}as}"
                    ASFLAGS="$ASFLAGS -xarch=v8plusa"
                fi
                ;;
        esac
        ;;
    mips|mipsel|mips64|mips64el)
        ARCH="MIPS"
        ;;
    arm*)
        ARCH="ARM"
        if [ "$SYS" = MACOSX ] ; then
            AS="${AS-extras/gas-preprocessor.pl $CC}"
            ASFLAGS="$ASFLAGS -DPREFIX -DPIC"  # apple's ld doesn't support movw/movt relocations at all
            # build for armv7 by default
            if ! echo $CFLAGS | grep -Eq '\-arch' ; then
                CFLAGS="$CFLAGS -arch armv7"
                LDFLAGS="$LDFLAGS -arch armv7"
            fi
        else
            AS="${AS-${cross_prefix}gcc}"
        fi
        ;;
    s390|s390x)
        ARCH="S390"
        ;;
    parisc|parisc64)
        ARCH="PARISC"
        ;;
    ia64)
        ARCH="IA64"
        ;;
    *)
        ARCH="$(echo $host_cpu | tr a-z A-Z)"
        ;;
442 443
esac

Diogo Franco's avatar
Diogo Franco committed
444 445 446 447 448 449 450 451 452 453
log_msg "x264 configure script"
if [ -n "$*" ]; then
    msg="Command line options:"
    for i in $@; do
        msg="$msg \"$i\""
    done
    log_msg "$msg"
fi
log_msg ""

454 455
# check requirements

456 457
cc_check || die "No working C compiler found."

458 459 460 461 462 463
if cc_check '' -std=gnu99 ; then
    CFLAGS="$CFLAGS -std=gnu99"
elif cc_check '' -std=c99 ; then
    CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE"
fi

Loic Minier's avatar
Loic Minier committed
464
if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then
465 466 467
    pic="yes"
fi

468
if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
Fiona Glaser's avatar
Fiona Glaser committed
469
    if ! as_check "lzcnt eax, eax" ; then
Fiona Glaser's avatar
Fiona Glaser committed
470
        VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
471
        echo "Found $VER"
Fiona Glaser's avatar
Fiona Glaser committed
472
        echo "Minimum version is yasm-0.6.2"
473 474
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
475
    fi
476
    if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
477 478 479 480 481 482 483
        VER=`(as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
        echo "Found $VER"
        echo "Minimum version is binutils-2.17"
        echo "Your compiler can't handle inline SSSE3 asm."
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
    fi
Diogo Franco's avatar
Diogo Franco committed
484
    define HAVE_MMX
485
fi
486

487
if [ $asm = auto -a $ARCH = ARM ] ; then
488 489 490
    # set flags so neon is built by default
    echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"

David Conrad's avatar
David Conrad committed
491 492 493 494
    if  cc_check '' '' '__asm__("rev ip, ip");' ; then      define HAVE_ARMV6
        cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2
        cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON
        ASFLAGS="$ASFLAGS $CFLAGS -c"
495
    else
496
        echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
497 498
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
499 500 501
    fi
fi

502
[ $asm = no ] && AS=""
503
[ "x$AS" = x ] && asm="no" || asm="yes"
504

Diogo Franco's avatar
Diogo Franco committed
505 506
define ARCH_$ARCH
define SYS_$SYS
507

508
echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
509
$CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
510
if (strings -a conftest.o | grep -q BIGE) && (strings -a conftest.o | grep -q FPendian) ; then
Diogo Franco's avatar
Diogo Franco committed
511
    define WORDS_BIGENDIAN
512
elif !(strings -a conftest.o | grep -q EGIB && strings -a conftest.o | grep -q naidnePF) ; then
Kieran Kunhya's avatar
Kieran Kunhya committed
513 514
    die "endian test failed"
fi
515

516 517
# autodetect options that weren't forced nor disabled

518
libpthread=""
519
if test "$pthread" = "auto" ; then
520
    pthread="no"
521
    case $SYS in
522
        BEOS)
523 524
            pthread="yes"
            ;;
525
        MINGW)
526 527 528 529 530 531 532 533
            if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthread"
            elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthreadGC2"
            elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
                pthread="yes"
Loren Merritt's avatar
Loren Merritt committed
534
                libpthread="-lpthreadGC2 -lwsock32"
Diogo Franco's avatar
Diogo Franco committed
535
                define PTW32_STATIC_LIB
Anton Mitrofanov's avatar
Anton Mitrofanov committed
536 537 538
            elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
                pthread="yes"
                libpthread="-lpthreadGC2 -lws2_32"
Diogo Franco's avatar
Diogo Franco committed
539
                define PTW32_STATIC_LIB
540 541
            fi
            ;;
542 543 544
        OPENBSD)
            cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
            ;;
545
        *)
546
            cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
547 548 549 550
            ;;
    esac
fi
if test "$pthread" = "yes" ; then
Diogo Franco's avatar
Diogo Franco committed
551
    define HAVE_PTHREAD
552
    LDFLAGS="$LDFLAGS $libpthread"
553 554
fi

555
if cc_check "math.h" "-Werror" "return log2f(2);" ; then
Diogo Franco's avatar
Diogo Franco committed
556
    define HAVE_LOG2F
557 558
fi

559 560 561 562 563 564 565 566 567 568
if [ "$vis" = "yes" ] ; then
    save_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -I/usr/X11R6/include"
    if cc_check "X11/Xlib.h" "-L/usr/X11R6/lib -lX11" "XOpenDisplay(0);" ; then
        LDFLAGS="-L/usr/X11R6/lib -lX11 $LDFLAGS"
        define HAVE_VISUALIZE
    else
        vis="no"
        CFLAGS="$save_CFLAGS"
   fi
569 570
fi

571 572 573 574 575 576 577 578 579 580 581
if [ "$swscale" = "auto" ] ; then
    swscale="no"
    if ${cross_prefix}pkg-config --exists libswscale 2>$DEVNULL; then
        SWSCALE_LIBS="$SWSCALE_LIBS $(${cross_prefix}pkg-config --libs libswscale)"
        SWSCALE_CFLAGS="$SWSCALE_CFLAGS $(${cross_prefix}pkg-config --cflags libswscale)"
    fi
    [ -z "$SWSCALE_LIBS" ] && SWSCALE_LIBS="-lswscale -lavutil"

    error="swscale must be at least version 0.9.0"
    if cc_check "libswscale/swscale.h" "$SWSCALE_CFLAGS $SWSCALE_LIBS" "sws_getContext(0,0,0,0,0,0,0,0,0,0);" ; then
        if cpp_check "libswscale/swscale.h" "$SWSCALE_CFLAGS" "LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0,9,0)" "$error"; then
582 583 584 585 586 587
            # we use colorspaces that were defined in libavutil r19775
            if cc_check "libavutil/pixfmt.h" "$SWSCALE_CFLAGS" "enum PixelFormat pixfmt = PIX_FMT_YUV422P16LE;" ; then
                swscale="yes"
            else
                echo "Warning: libavutil is too old, update to ffmpeg r19775+"
            fi
588 589 590 591 592 593
        else
            echo "Warning: ${error}"
        fi
    fi
fi

Steven Walters's avatar
Steven Walters committed
594 595
if [ "$lavf" = "auto" ] ; then
    lavf="no"
596
    if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
597 598
        LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libavutil libswscale)"
        LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libavutil libswscale)"
599
    fi
600
    if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
601
        LAVF_LIBS="-lavformat"
602
        for lib in -lpostproc -lavcodec -lavcore -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
603
            cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
604 605
        done
    fi
606
    LAVF_LIBS="-L. $LAVF_LIBS"
607 608 609 610 611 612 613 614
    if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then
        # libvautil/pixdesc.h included the private header intreadwrite.h until r21854
        if cc_check libavutil/pixdesc.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
            if [ "$swscale" = "yes" ]; then
                lavf="yes"
            else
                echo "Warning: libavformat is not supported without swscale support"
            fi
615
        else
616
            echo "Warning: libavutil is too old, update to ffmpeg r21854+"
617 618 619 620
        fi
    fi
fi

Steven Walters's avatar
Steven Walters committed
621
if [ "$ffms" = "auto" ] ; then
622
    ffms_major="2"; ffms_minor="14"; ffms_micro="0"; ffms_bump="0"
Steven Walters's avatar
Steven Walters committed
623
    ffms="no"
624 625

    if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
626
        FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
James Darnley's avatar
James Darnley committed
627
        FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
628 629 630 631
    fi
    [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"

    if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
Steven Walters's avatar
Steven Walters committed
632
        ffms="yes"
633
    elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
Steven Walters's avatar
Steven Walters committed
634
        ffms="yes"
635
        FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
636
    fi
Diogo Franco's avatar
Diogo Franco committed
637

638 639 640 641 642 643 644 645
    error="ffms must be at least version $ffms_major.$ffms_minor.$ffms_micro.$ffms_bump"
    if [ $ffms = "yes" ] && ! cpp_check "ffms.h" "$FFMS2_CFLAGS" "FFMS_VERSION >= (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)" "$error"; then
       ffms="no"
       echo "Warning: $error"
    fi
    if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
        echo "Warning: ffms is not supported without swscale support"
        ffms="no"
Diogo Franco's avatar
Diogo Franco committed
646
    fi
647 648
fi

Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
649
if [ "$swscale" = "yes" ]; then
650 651
    LDFLAGSCLI="$SWSCALE_LIBS $LDFLAGSCLI"
    CFLAGS="$CFLAGS $SWSCALE_CFLAGS"
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
652 653 654 655 656 657
    define HAVE_SWSCALE
    if [ "$lavf" = "yes" ]; then
        LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
        CFLAGS="$CFLAGS $LAVF_CFLAGS"
        define HAVE_LAVF
    fi
Fiona Glaser's avatar
Fiona Glaser committed
658
    if [ "$ffms" = "yes" ]; then
Yasuhiro Ikeda's avatar
Yasuhiro Ikeda committed
659 660 661 662
        LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
        CFLAGS="$CFLAGS $FFMS2_CFLAGS"
        define HAVE_FFMS
    fi
663 664
fi

Steven Walters's avatar
Steven Walters committed
665
GPAC_LIBS="-lgpac_static"
666
if [ $SYS = MINGW ]; then
Steven Walters's avatar
Steven Walters committed
667
    GPAC_LIBS="$GPAC_LIBS -lwinmm"
668
fi
Steven Walters's avatar
Steven Walters committed
669 670 671 672 673
if [ "$gpac" = "auto" ] ; then
    gpac="no"
    if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
        if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
            gpac="yes"
Yusuke Nakamura's avatar
Yusuke Nakamura committed
674 675 676 677
        else
            echo "Warning: gpac is too old, update to 2007-06-21 UTC or later"
        fi
    fi
678
fi
Steven Walters's avatar
Steven Walters committed
679 680 681
if [ "$gpac" = "yes" ] ; then
    define HAVE_GPAC
    if cc_check gpac/isomedia.h "-Werror $GPAC_LIBS" "gf_malloc(1); gf_free(NULL);" ; then
682 683
        define HAVE_GF_MALLOC
    fi
684
    LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
685 686
fi

Steven Walters's avatar
Steven Walters committed
687
if [ "$avs" = "auto" ] ; then
688 689
    avs="no"
    if [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
Steven Walters's avatar
Steven Walters committed
690 691
        avs="yes"
        define HAVE_AVS
Anton Mitrofanov's avatar
Anton Mitrofanov committed
692
    fi
693 694
fi

695 696
if [ "$pic" = "yes" ] ; then
    CFLAGS="$CFLAGS -fPIC"
Loren Merritt's avatar
Loren Merritt committed
697
    ASFLAGS="$ASFLAGS -DPIC"
698
    # resolve textrels in the x86 asm
699
    cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
700 701
fi

702
if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
Loren Merritt's avatar
Loren Merritt committed
703
    CFLAGS="$CFLAGS -s -fomit-frame-pointer"
704
    LDFLAGS="$LDFLAGS -s"
705 706
fi

Loren Merritt's avatar
Loren Merritt committed
707
if [ "$debug" = "yes" ]; then
708
    CFLAGS="-O1 -g $CFLAGS"
709 710 711
elif [ $ARCH = ARM ]; then
    # arm-gcc-4.2 produces incorrect output with -ffast-math
    # and it doesn't save any speed anyway on 4.4, so disable it
Diogo Franco's avatar
Diogo Franco committed
712
    CFLAGS="-O3 -fno-fast-math $CFLAGS"
713
else
Diogo Franco's avatar
Diogo Franco committed
714
    CFLAGS="-O3 -ffast-math $CFLAGS"
715 716
fi

717 718 719 720
if cc_check '' -fno-tree-vectorize ; then
    CFLAGS="$CFLAGS -fno-tree-vectorize"
fi

Loren Merritt's avatar
Loren Merritt committed
721
if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
Diogo Franco's avatar
Diogo Franco committed
722 723
    define fseek fseeko
    define ftell ftello
Loren Merritt's avatar
Loren Merritt committed
724
elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
Diogo Franco's avatar
Diogo Franco committed
725 726
    define fseek fseeko64
    define ftell ftello64
Loren Merritt's avatar
Loren Merritt committed
727 728
fi

729 730 731 732
if cc_check '' -Wshadow ; then
    CFLAGS="-Wshadow $CFLAGS"
fi

733
if [ "$bit_depth" -gt "8" ]; then
734 735
    define HIGH_BIT_DEPTH
    ASFLAGS="$ASFLAGS -DHIGH_BIT_DEPTH"
736 737
fi

738
ASFLAGS="$ASFLAGS -DBIT_DEPTH=$bit_depth"
739

740
[ $gpl = yes ] && define HAVE_GPL && x264_gpl=1 || x264_gpl=0
741 742 743 744 745

#define undefined vars as 0
for var in $CONFIG_HAVE; do
    grep -q "HAVE_$var 1" config.h || define HAVE_$var 0
done
746

747 748
rm -f conftest*

749 750 751 752 753 754 755
# generate exported config file

cat > x264_config.h << EOF
#define X264_BIT_DEPTH $bit_depth
#define X264_GPL       $x264_gpl
EOF

756 757
# generate config files

758
cat > config.mak << EOF
759
prefix=$prefix
Loren Merritt's avatar
Loren Merritt committed
760
exec_prefix=$exec_prefix
761 762 763
bindir=$bindir
libdir=$libdir
includedir=$includedir
764 765 766 767 768
ARCH=$ARCH
SYS=$SYS
CC=$CC
CFLAGS=$CFLAGS
LDFLAGS=$LDFLAGS
769
LDFLAGSCLI=$LDFLAGSCLI
Anton Mitrofanov's avatar
Anton Mitrofanov committed
770 771 772
AR=$AR
RANLIB=$RANLIB
STRIP=$STRIP
773 774
AS=$AS
ASFLAGS=$ASFLAGS
Loren Merritt's avatar
Loren Merritt committed
775
EXE=$EXE
776
HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
777
DEVNULL=$DEVNULL
778 779
EOF

780
if [ "$shared" = "yes" ]; then
781
    API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
Zuxy Meng's avatar
Zuxy Meng committed
782 783 784 785
    if [ "$SYS" = "MINGW" ]; then
        echo "SONAME=libx264-$API.dll" >> config.mak
        echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
        echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak
786
    elif [ "$SYS" = "MACOSX" ]; then
787
        echo "SOSUFFIX=dylib" >> config.mak
788
        echo "SONAME=libx264.$API.dylib" >> config.mak
789
        echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak
790 791 792 793
    elif [ "$SYS" = "SunOS" ]; then
        echo "SOSUFFIX=so" >> config.mak
        echo "SONAME=libx264.so.$API" >> config.mak
        echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
794
    else
795
        echo "SOSUFFIX=so" >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
796
        echo "SONAME=libx264.so.$API" >> config.mak
Loren Merritt's avatar
Loren Merritt committed
797
        echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
798
    fi
799 800 801
    echo 'default: $(SONAME)' >> config.mak
fi

802
./version.sh >> config.h
803

804
pclibs="-L$libdir -lx264 $libpthread"
805

Loren Merritt's avatar
Loren Merritt committed
806 807 808 809 810 811 812 813
cat > x264.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir

Name: x264
Description: H.264 (MPEG4 AVC) encoder library
814
Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
815
Libs: $pclibs
Loren Merritt's avatar
Loren Merritt committed
816 817 818
Cflags: -I$includedir
EOF

819
filters="crop select_every"
820
gpl_filters=""
821
[ $swscale = yes ] && filters="resize $filters"
822
[ $gpl = yes ] && filters="$filters $gpl_filters"
823

Diogo Franco's avatar
Diogo Franco committed
824 825 826 827
cat > conftest.log <<EOF
Platform:   $ARCH
System:     $SYS
asm:        $asm
Steven Walters's avatar
Steven Walters committed
828 829 830 831
avs:        $avs
lavf:       $lavf
ffms:       $ffms
gpac:       $gpac
832
gpl:        $gpl
Diogo Franco's avatar
Diogo Franco committed
833
pthread:    $pthread
834
filters:    $filters
Diogo Franco's avatar
Diogo Franco committed
835 836 837 838 839
debug:      $debug
gprof:      $gprof
PIC:        $pic
shared:     $shared
visualize:  $vis
840
bit depth:  $bit_depth
Diogo Franco's avatar
Diogo Franco committed
841 842 843 844 845 846
EOF

echo >> config.log
cat conftest.log >> config.log
cat conftest.log
rm conftest.log
Loren Merritt's avatar
Loren Merritt committed
847

848
echo
849
echo "You can run 'make' or 'make fprofiled' now."
850