configure 19 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"
10
echo "  --disable-avs-input      disables avisynth input (win32 only)"
11 12
echo "  --disable-lavf-input     disables libavformat input"
echo "  --disable-ffms-input     disables ffmpegsource input"
13 14
echo "  --disable-mp4-output     disables mp4 output (using gpac)"
echo "  --disable-pthread        disables multithreaded encoding"
15
echo "  --disable-asm            disables assembly optimizations on x86 and arm"
Loren Merritt's avatar
Loren Merritt committed
16
echo "  --enable-debug           adds -g, doesn't strip"
17
echo "  --enable-gprof           adds -pg, doesn't strip"
Loren Merritt's avatar
Loren Merritt committed
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"
Loren Merritt's avatar
Loren Merritt committed
22 23
echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS"
echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS"
24
echo "  --host=HOST              build programs to run on HOST"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
25
echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools"
Loren Merritt's avatar
Loren Merritt committed
26 27 28 29
echo ""
exit 1
fi

Diogo Franco's avatar
Diogo Franco committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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
}

46
cc_check() {
Diogo Franco's avatar
Diogo Franco committed
47
    if [ -z "$3" ]; then
48
        if [ -z "$1$2" ]; then
Diogo Franco's avatar
Diogo Franco committed
49
            log_check "whether $CC works"
50 51
        elif [ -z "$1" ]; then
            log_check "for $2"
Diogo Franco's avatar
Diogo Franco committed
52 53 54 55 56 57
        else
            log_check "for $1"
        fi
    elif [ -z "$1" ]; then
        log_check "whether $CC supports $3"
    else
58
        log_check "for $3 in $1";
Diogo Franco's avatar
Diogo Franco committed
59
    fi
60 61 62
    rm -f conftest.c
    [ -n "$1" ] && echo "#include <$1>" > conftest.c
    echo "int main () { $3 return 0; }" >> conftest.c
Diogo Franco's avatar
Diogo Franco committed
63 64 65 66 67 68 69 70 71 72 73 74 75
    if $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then
        res=$?
        log_ok
    else
        res=$?
        log_fail
        log_msg "Failed commandline was:"
        log_msg "--------------------------------------------------"
        log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2"
        cat conftest.log >> config.log
        log_msg "--------------------------------------------------"
    fi
    return $res
76 77
}

78
as_check() {
Diogo Franco's avatar
Diogo Franco committed
79
    log_check "whether $AS supports $1"
80
    echo "$1" > conftest.asm
Diogo Franco's avatar
Diogo Franco committed
81 82 83 84 85 86 87 88 89 90 91 92 93
    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 "--------------------------------------------------"
    fi
    return $res
94 95
}

Diogo Franco's avatar
Diogo Franco committed
96 97 98 99
define() {
    echo "#define $1$([ -n "$2" ] && echo " $2")" >> config.h
}

100
die() {
Diogo Franco's avatar
Diogo Franco committed
101
    log_msg "DIED: $@"
102 103 104 105
    echo "$@"
    exit 1
}

Diogo Franco's avatar
Diogo Franco committed
106
rm -f config.h config.mak config.log x264.pc conftest*
Loren Merritt's avatar
Loren Merritt committed
107

108
prefix='/usr/local'
Loren Merritt's avatar
Loren Merritt committed
109 110 111
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
112
includedir='${prefix}/include'
113
DEVNULL='/dev/null'
114

115
avs_input="auto"
116 117
lavf_input="auto"
ffms_input="auto"
118 119
mp4_output="auto"
pthread="auto"
120
asm="yes"
121
debug="no"
122
gprof="no"
123
pic="no"
Loren Merritt's avatar
Loren Merritt committed
124
vis="no"
125
shared="no"
Loren Merritt's avatar
Loren Merritt committed
126

127
CFLAGS="$CFLAGS -Wall -I."
128
LDFLAGS="$LDFLAGS"
129
LDFLAGSCLI="$LDFLAGSCLI"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
130
ASFLAGS="$ASFLAGS"
131
HAVE_GETOPT_LONG=1
Anton Mitrofanov's avatar
Anton Mitrofanov committed
132
cross_prefix=""
133

Loren Merritt's avatar
Loren Merritt committed
134 135
EXE=""

136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
# 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"
            ;;
156 157 158 159 160 161
        --enable-asm)
            asm="yes"
            ;;
        --disable-asm)
            asm="no"
            ;;
162 163
        --enable-avs-input)
            avs_input="auto"
164
            ;;
165 166
        --disable-avs-input)
            avs_input="no"
167
            ;;
168 169 170 171 172 173 174 175 176 177 178 179
        --enable-lavf-input)
            lavf_input="auto"
            ;;
        --disable-lavf-input)
            lavf_input="no"
            ;;
        --enable-ffms-input)
            ffms_input="auto"
            ;;
        --disable-ffms-input)
            ffms_input="no"
            ;;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        --enable-mp4-output)
            mp4_output="yes"
            ;;
        --disable-mp4-output)
            mp4_output="no"
            ;;
        --extra-asflags=*)
            ASFLAGS="$ASFLAGS ${opt#--extra-asflags=}"
            ;;
        --extra-cflags=*)
            CFLAGS="$CFLAGS ${opt#--extra-cflags=}"
            ;;
        --extra-ldflags=*)
            LDFLAGS="$LDFLAGS ${opt#--extra-ldflags=}"
            ;;
        --enable-pthread)
            pthread="auto" # can't skip detection, since it differs by OS
            ;;
        --disable-pthread)
            pthread="no"
            ;;
        --enable-debug)
            debug="yes"
            ;;
        --enable-gprof)
            CFLAGS="$CFLAGS -pg"
            LDFLAGS="$LDFLAGS -pg"
            gprof="yes"
            ;;
        --enable-pic)
            pic="yes"
            ;;
        --enable-shared)
            shared="yes"
            ;;
        --enable-visualize)
            LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
217
            define HAVE_VISUALIZE
218 219 220 221 222
            vis="yes"
            ;;
        --host=*)
            host="${opt#--host=}"
            ;;
Anton Mitrofanov's avatar
Anton Mitrofanov committed
223 224 225
        --cross-prefix=*)
            cross_prefix="${opt#--cross-prefix=}"
            ;;
226 227 228 229 230 231
        *)
            echo "Unknown option $opt, ignored"
            ;;
    esac
done

Anton Mitrofanov's avatar
Anton Mitrofanov committed
232 233 234 235 236
CC="${CC-${cross_prefix}gcc}"
AR="${AR-${cross_prefix}ar}"
RANLIB="${RANLIB-${cross_prefix}ranlib}"
STRIP="${STRIP-${cross_prefix}strip}"

237 238 239 240 241
if [ "x$host" = x ]; then
    host=`./config.guess`
fi
# normalize a triplet into a quadruplet
host=`./config.sub $host`
242

243
# split $host
Loren Merritt's avatar
Loren Merritt committed
244
host_cpu="${host%%-*}"
245
host="${host#*-}"
Loren Merritt's avatar
Loren Merritt committed
246
host_vendor="${host%%-*}"
247
host_os="${host#*-}"
248 249

case $host_os in
250
  beos*)
251
    SYS="BEOS"
Diogo Franco's avatar
Diogo Franco committed
252
    define HAVE_MALLOC_H
253
    ;;
254
  darwin*)
255
    SYS="MACOSX"
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"
260
    fi
261
    ;;
262
  freebsd*)
263 264 265
    SYS="FREEBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
266 267
  kfreebsd*-gnu)
    SYS="FREEBSD"
Diogo Franco's avatar
Diogo Franco committed
268
    define HAVE_MALLOC_H
269 270
    LDFLAGS="$LDFLAGS -lm"
    ;;
271
  netbsd*)
272 273 274
    SYS="NETBSD"
    LDFLAGS="$LDFLAGS -lm"
    ;;
275
  openbsd*)
Loren Merritt's avatar
Loren Merritt committed
276 277 278 279
    SYS="OPENBSD"
    CFLAGS="$CFLAGS -I/usr/X11R6/include"
    LDFLAGS="$LDFLAGS -lm"
    ;;
Mike Frysinger's avatar
Mike Frysinger committed
280
  *linux*)
281
    SYS="LINUX"
Diogo Franco's avatar
Diogo Franco committed
282
    define HAVE_MALLOC_H
283 284
    LDFLAGS="$LDFLAGS -lm"
    ;;
285
  cygwin*)
286
    SYS="MINGW"
Loren Merritt's avatar
Loren Merritt committed
287
    EXE=".exe"
288
    DEVNULL="NUL"
289 290 291 292
    if cc_check "" -mno-cygwin; then
        CFLAGS="$CFLAGS -mno-cygwin"
        LDFLAGS="$LDFLAGS -mno-cygwin"
    fi
Eric Petit's avatar
Eric Petit committed
293
    ;;
294
  mingw*)
295
    SYS="MINGW"
Loren Merritt's avatar
Loren Merritt committed
296
    EXE=".exe"
297
    DEVNULL="NUL"
Loren Merritt's avatar
Loren Merritt committed
298
    ;;
299
  sunos*|solaris*)
300
    SYS="SunOS"
Diogo Franco's avatar
Diogo Franco committed
301
    define HAVE_MALLOC_H
302 303 304
    LDFLAGS="$LDFLAGS -lm"
    HAVE_GETOPT_LONG=0
    ;;
305
  *)
306
    die "Unknown system $host, edit the configure"
307 308 309
    ;;
esac

310
case $host_cpu in
311
  i*86)
312
    ARCH="X86"
313 314
    AS="yasm"
    ASFLAGS="$ASFLAGS -O2"
315 316 317
    if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then
      CFLAGS="$CFLAGS -march=i686"
    fi
318 319 320
    if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then
      CFLAGS="$CFLAGS -mfpmath=sse -msse"
    fi
321
    if [ "$SYS" = MACOSX ]; then
322
      ASFLAGS="$ASFLAGS -f macho -DPREFIX"
323
    elif [ "$SYS" = MINGW ]; then
324 325 326
      ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
    else
      ASFLAGS="$ASFLAGS -f elf"
327
    fi
328
    ;;
Måns Rullgård's avatar
Måns Rullgård committed
329 330
  x86_64)
    ARCH="X86_64"
331
    AS="yasm"
332
    if [ "$SYS" = MACOSX ];then
333
      ASFLAGS="$ASFLAGS -f macho64 -m amd64 -DPIC -DPREFIX"
334 335 336 337
      if cc_check '' "-arch x86_64"; then
        CFLAGS="$CFLAGS -arch x86_64"
        LDFLAGS="$LDFLAGS -arch x86_64"
      fi
Anton Mitrofanov's avatar
Anton Mitrofanov committed
338 339
    elif [ "$SYS" = MINGW ]; then
      ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX"
340
    else
Anton Mitrofanov's avatar
Anton Mitrofanov committed
341
      ASFLAGS="$ASFLAGS -f elf -m amd64"
342
    fi
Måns Rullgård's avatar
Måns Rullgård committed
343
    ;;
344
  powerpc|powerpc64)
345 346 347
    ARCH="PPC"
    if [ $SYS = MACOSX ]
    then
David Conrad's avatar
David Conrad committed
348
      CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
349
    else
Diogo Franco's avatar
Diogo Franco committed
350 351
      CFLAGS="$CFLAGS -maltivec -mabi=altivec"
      define HAVE_ALTIVEC_H
352 353
    fi
    ;;
354 355 356 357 358
  sparc)
    if test "$(uname -m)" = "sun4u"; then
      ARCH="UltraSparc"
      CFLAGS="$CFLAGS -mcpu=ultrasparc"
      LDFLAGS="$LDFLAGS -mcpu=ultrasparc"
Anton Mitrofanov's avatar
Anton Mitrofanov committed
359
      AS="${cross_prefix}as"
360
      ASFLAGS="$ASFLAGS -xarch=v8plusa"
361 362 363
    else
      ARCH="Sparc"
    fi
364
    ;;
365
  mips|mipsel|mips64|mips64el)
366 367
    ARCH="MIPS"
    ;;
368
  arm*)
369
    ARCH="ARM"
370
    AS="${AS-${cross_prefix}gcc}"
371 372 373 374 375 376 377
    ;;
  s390|s390x)
    ARCH="S390"
    ;;
  parisc|parisc64)
    ARCH="PARISC"
    ;;
378
  *)
379
    ARCH="$(echo $host_cpu | tr a-z A-Z)"
380 381 382
    ;;
esac

Diogo Franco's avatar
Diogo Franco committed
383 384 385 386 387 388 389 390 391 392
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 ""

393 394
# check requirements

395 396
cc_check || die "No working C compiler found."

397 398 399 400 401 402
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

403
if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" \) ] ; then
404 405 406
    pic="yes"
fi

407
if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
Fiona Glaser's avatar
Fiona Glaser committed
408
    if ! as_check "lzcnt eax, eax" ; then
Fiona Glaser's avatar
Fiona Glaser committed
409
        VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
410
        echo "Found $VER"
Fiona Glaser's avatar
Fiona Glaser committed
411
        echo "Minimum version is yasm-0.6.2"
412 413
        echo "If you really want to compile without asm, configure with --disable-asm."
        exit 1
414
    fi
415
    if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
416 417 418 419 420 421 422
        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
423
    define HAVE_MMX
424
fi
425 426

if [ $asm = yes -a $ARCH = ARM ] ; then
427 428 429
    # 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"

430 431 432
    if  cc_check '' '' '__asm__("rev ip, ip");' ; then      define HAVE_ARMV6   && ASFLAGS="$ASFLAGS -DHAVE_ARMV6"
        cc_check '' '' '__asm__("movt r0, #0");'         && define HAVE_ARMV6T2 && ASFLAGS="$ASFLAGS -DHAVE_ARMV6T2"
        cc_check '' '' '__asm__("vadd.i16 q0, q0, q0");' && define HAVE_NEON    && ASFLAGS="$ASFLAGS -DHAVE_NEON"
Diogo Franco's avatar
Diogo Franco committed
433
        ASFLAGS="$ASFLAGS -c"
434
    else
435
        echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
436 437
        echo "If you really want to run on such a CPU, configure with --disable-asm."
        exit 1
438 439 440
    fi
fi

441 442
[ $asm = no ] && AS=""
[ "x$AS" = x ] && asm="no"
443

Diogo Franco's avatar
Diogo Franco committed
444 445
define ARCH_$ARCH
define SYS_$SYS
446

Kieran Kunhya's avatar
Kieran Kunhya committed
447
echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
Loren Merritt's avatar
Loren Merritt committed
448
$CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
Kieran Kunhya's avatar
Kieran Kunhya committed
449
if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
Diogo Franco's avatar
Diogo Franco committed
450
    define WORDS_BIGENDIAN
Kieran Kunhya's avatar
Kieran Kunhya committed
451 452 453
elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
    die "endian test failed"
fi
Loren Merritt's avatar
Loren Merritt committed
454

455 456
# autodetect options that weren't forced nor disabled

457
libpthread=""
458
if test "$pthread" = "auto" ; then
459
    pthread="no"
460
    case $SYS in
461
        BEOS)
462 463
            pthread="yes"
            ;;
464
        MINGW)
465 466 467 468 469 470 471 472
            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
473
                libpthread="-lpthreadGC2 -lwsock32"
Diogo Franco's avatar
Diogo Franco committed
474
                define PTW32_STATIC_LIB
Anton Mitrofanov's avatar
Anton Mitrofanov committed
475 476 477
            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
478
                define PTW32_STATIC_LIB
479 480
            fi
            ;;
481 482 483
        OPENBSD)
            cc_check pthread.h -pthread && pthread="yes" && libpthread="-pthread"
            ;;
484
        *)
485
            cc_check pthread.h -lpthread && pthread="yes" && libpthread="-lpthread"
486 487 488 489
            ;;
    esac
fi
if test "$pthread" = "yes" ; then
Diogo Franco's avatar
Diogo Franco committed
490
    define HAVE_PTHREAD
491
    LDFLAGS="$LDFLAGS $libpthread"
492 493
fi

494
if cc_check "math.h" "-Werror" "return log2f(2);" ; then
Diogo Franco's avatar
Diogo Franco committed
495
    define HAVE_LOG2F
496 497
fi

498 499
if [ "$lavf_input" = "auto" ] ; then
    lavf_input="no"
500 501 502
    if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
        LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libswscale)"
        LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libswscale)"
503
    fi
504 505
    if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
        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"
508 509
        done
    fi
510 511 512
    LAVF_LIBS="-L. $LAVF_LIBS"
    if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \
       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
515
            lavf_input="yes"
Diogo Franco's avatar
Diogo Franco committed
516
            define LAVF_INPUT
517 518 519 520 521 522 523
        else
            echo "Warning: libavformat is too old, update to ffmpeg r18351+"
        fi
    fi
fi

if [ "$ffms_input" = "auto" ] ; then
Diogo Franco's avatar
Diogo Franco committed
524 525
    ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"

526
    ffms_input="no"
Diogo Franco's avatar
Diogo Franco committed
527 528 529
    [ $ffms_micro -gt 0 -o $ffms_bump -gt 0 ] && vmicro=".$ffms_micro"
    [ $ffms_bump -gt 0 ] && vbump=".$ffms_bump"
    if ${cross_prefix}pkg-config --atleast-version="$ffms_major.$ffms_minor$vmicro$vbump" ffms2 2>$DEVNULL; then
530 531
        FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
        FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
Diogo Franco's avatar
Diogo Franco committed
532 533 534
        api_check="no"
    else
        api_check="yes"
535 536 537 538 539 540 541 542
    fi
    [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"

    if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
        ffms_input="yes"
    elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
        ffms_input="yes"
        FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
543
    fi
Diogo Franco's avatar
Diogo Franco committed
544 545 546 547 548 549 550 551 552 553 554

    if [ $api_check = "yes" -a $ffms_input = "yes" ]; then
        log_check "whether ffms2 version is at least $ffms_major.$ffms_minor$vmicro$vbump"
        $CC $CFLAGS $FFMS2_CFLAGS -c -o conftest -x c - >$DEVNULL 2>&1 <<EOF
#include <ffms.h>
#if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)
#error Requires ffms2 version 2.13.1
#endif
EOF
        [ $? = 0 ] && log_ok || { ffms_input="no"; log_fail; }
    fi
555 556
fi

557 558 559
if [ "$ffms_input" = "yes" ]; then
    LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
    [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
Diogo Franco's avatar
Diogo Franco committed
560
    define FFMS_INPUT
561 562 563 564 565
elif [ "$lavf_input" = "yes" ]; then
    LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
    [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
fi

566
MP4_LDFLAGS="-lgpac_static"
567
if [ $SYS = MINGW ]; then
568 569 570 571 572 573 574
    MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
fi
if [ "$mp4_output" = "auto" ] ; then
    mp4_output="no"
    cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
fi
if [ "$mp4_output" = "yes" ] ; then
Diogo Franco's avatar
Diogo Franco committed
575
    define MP4_OUTPUT
576
    LDFLAGSCLI="$LDFLAGSCLI $MP4_LDFLAGS"
577 578
fi

579 580
if [ "$avs_input" = "auto" ] ; then
    avs_input=no
581
    if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
582
        avs_input="yes"
Diogo Franco's avatar
Diogo Franco committed
583 584
        define AVS_INPUT
        define HAVE_AVISYNTH_C_H
585
    elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
586
        avs_input="yes"
Diogo Franco's avatar
Diogo Franco committed
587
        define AVS_INPUT
Anton Mitrofanov's avatar
Anton Mitrofanov committed
588
    fi
589 590
fi

591 592
if [ "$pic" = "yes" ] ; then
    CFLAGS="$CFLAGS -fPIC"
Loren Merritt's avatar
Loren Merritt committed
593
    ASFLAGS="$ASFLAGS -DPIC"
594
    # resolve textrels in the x86 asm
595
    cc_check stdio.h -Wl,-Bsymbolic && LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
596 597
fi

598
if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
Loren Merritt's avatar
Loren Merritt committed
599
    CFLAGS="$CFLAGS -s -fomit-frame-pointer"
Loren Merritt's avatar
Loren Merritt committed
600
    LDFLAGS="$LDFLAGS -s"
601 602
fi

Loren Merritt's avatar
Loren Merritt committed
603
if [ "$debug" = "yes" ]; then
604
    CFLAGS="-O1 -g $CFLAGS"
605 606 607
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
608
    CFLAGS="-O3 -fno-fast-math $CFLAGS"
609
else
Diogo Franco's avatar
Diogo Franco committed
610
    CFLAGS="-O3 -ffast-math $CFLAGS"
611 612
fi

Loren Merritt's avatar
Loren Merritt committed
613
if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
Diogo Franco's avatar
Diogo Franco committed
614 615
    define fseek fseeko
    define ftell ftello
Loren Merritt's avatar
Loren Merritt committed
616
elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
Diogo Franco's avatar
Diogo Franco committed
617 618
    define fseek fseeko64
    define ftell ftello64
Loren Merritt's avatar
Loren Merritt committed
619 620
fi

Loren Merritt's avatar
Loren Merritt committed
621 622
rm -f conftest*

623 624
# generate config files

625
cat > config.mak << EOF
626
prefix=$prefix
Loren Merritt's avatar
Loren Merritt committed
627
exec_prefix=$exec_prefix
628 629 630
bindir=$bindir
libdir=$libdir
includedir=$includedir
631 632 633 634 635
ARCH=$ARCH
SYS=$SYS
CC=$CC
CFLAGS=$CFLAGS
LDFLAGS=$LDFLAGS
636
LDFLAGSCLI=$LDFLAGSCLI
Anton Mitrofanov's avatar
Anton Mitrofanov committed
637 638 639
AR=$AR
RANLIB=$RANLIB
STRIP=$STRIP
640 641
AS=$AS
ASFLAGS=$ASFLAGS
Loren Merritt's avatar
Loren Merritt committed
642
EXE=$EXE
Loren Merritt's avatar
Loren Merritt committed
643
VIS=$vis
644
HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
645
DEVNULL=$DEVNULL
646 647
EOF

648
if [ "$shared" = "yes" ]; then
649
    API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
Zuxy Meng's avatar
Zuxy Meng committed
650 651 652 653
    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
Guillaume Poirier's avatar
Guillaume Poirier committed
654
    elif [ "$SYS" = "MACOSX" ]; then
655
        echo "SOSUFFIX=dylib" >> config.mak
Guillaume Poirier's avatar
Guillaume Poirier committed
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 659 660 661
    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
662
    else
663
        echo "SOSUFFIX=so" >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
664
        echo "SONAME=libx264.so.$API" >> config.mak
Loren Merritt's avatar
Loren Merritt committed
665
        echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak
Zuxy Meng's avatar
Zuxy Meng committed
666
    fi
667 668 669
    echo 'default: $(SONAME)' >> config.mak
fi

670 671
./version.sh

672
pclibs="-L$libdir -lx264 $libpthread"
673

Loren Merritt's avatar
Loren Merritt committed
674 675 676 677 678 679 680 681
cat > x264.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir

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

Diogo Franco's avatar
Diogo Franco committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
cat > conftest.log <<EOF
Platform:   $ARCH
System:     $SYS
asm:        $asm
avs input:  $avs_input
lavf input: $lavf_input
ffms input: $ffms_input
mp4 output: $mp4_output
pthread:    $pthread
debug:      $debug
gprof:      $gprof
PIC:        $pic
shared:     $shared
visualize:  $vis
EOF

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

708
echo
709
echo "You can run 'make' or 'make fprofiled' now."
710