Statistics
| Branch: | Revision:

ffmpeg / configure @ 794f8e97

History | View | Annotate | Download (57.3 KB)

1
#!/bin/sh
2
#
3
# FFmpeg configure script
4
#
5
# Copyright (c) 2000, 2001, 2002 Fabrice Bellard
6
# Copyright (c) 2005-2006 Diego Biurrun
7
# Copyright (c) 2005-2006 Mans Rullgard
8
#
9

    
10
# make sure we are running under a compatible shell
11
# try to make this part work with most shells
12

    
13
try_exec(){
14
    echo "Trying shell $1"
15
    type "$1" >/dev/null 2>&1 && exec "$@"
16
}
17

    
18
unset foo
19
(: ${foo%%bar}) 2>/dev/null
20
E1="$?"
21

    
22
(: ${foo?}) 2>/dev/null
23
E2="$?"
24

    
25
if test "$E1" != 0 || test "$E2" = 0; then
26
    echo "Broken shell detected.  Trying alternatives."
27
    export FF_CONF_EXEC
28
    if test "0$FF_CONF_EXEC" -lt 1; then
29
        FF_CONF_EXEC=1
30
        try_exec bash "$0" "$@"
31
    fi
32
    if test "0$FF_CONF_EXEC" -lt 2; then
33
        FF_CONF_EXEC=2
34
        try_exec ksh "$0" "$@"
35
    fi
36
    if test "0$FF_CONF_EXEC" -lt 3; then
37
        FF_CONF_EXEC=3
38
        try_exec /usr/xpg4/bin/sh "$0" "$@"
39
    fi
40
    echo "No compatible shell script interpreter found."
41
    echo "This configure script requires a POSIX-compatible shell"
42
    echo "such as bash or ksh."
43
    echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
44
    echo "Instead, install a working POSIX-compatible shell."
45
    echo "Disabling this configure test will create a broken FFmpeg."
46
    if test "$BASH_VERSION" = '2.04.0(1)-release'; then
47
        echo "This bash version ($BASH_VERSION) is broken on your platform."
48
        echo "Upgrade to a later version if available."
49
    fi
50
    exit 1
51
fi
52

    
53
show_help(){
54
  echo "Usage: configure [options]"
55
  echo "Options: [defaults in brackets after descriptions]"
56
  echo
57
  echo "Standard options:"
58
  echo "  --help                   print this message"
59
  echo "  --log[=FILE|yes|no]      log tests and output to FILE [config.err]"
60
  echo "  --prefix=PREFIX          install in PREFIX [$PREFIX]"
61
  echo "  --libdir=DIR             install libs in DIR [PREFIX/lib]"
62
  echo "  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]"
63
  echo "  --incdir=DIR             install includes in DIR [PREFIX/include/ffmpeg]"
64
  echo "  --mandir=DIR             install man page in DIR [PREFIX/man]"
65
  echo "  --enable-static          build static libraries [default=yes]"
66
  echo "  --disable-static         do not build static libraries [default=no]"
67
  echo "  --enable-shared          build shared libraries [default=no]"
68
  echo "  --disable-shared         do not build shared libraries [default=yes]"
69
  echo "  --enable-gpl             allow use of GPL code, the resulting libav*"
70
  echo "                           and ffmpeg will be under GPL [default=no]"
71
  echo "  --enable-pp              enable GPLed postprocessing support [default=no]"
72
  echo "  --enable-swscaler        software scaler support [default=no]"
73
  echo "  --enable-beosthreads     use BeOS threads [default=no]"
74
  echo "  --enable-pthreads        use pthreads [default=no]"
75
  echo "  --enable-w32threads      use Win32 threads [default=no]"
76
  echo "  --enable-x11grab         enable X11 grabbing [default=no]"
77
  echo
78
  echo "External library support:"
79
  echo "  --enable-sunmlib         use Sun medialib [default=no]"
80
  echo "  --enable-dc1394          enable IIDC-1394 grabbing using libdc1394"
81
  echo "                           and libraw1394 [default=no]"
82
  echo "  --enable-liba52          enable GPLed liba52 support [default=no]"
83
  echo "  --enable-liba52bin       open liba52.so.0 at runtime [default=no]"
84
  echo "  --enable-avisynth        allow reading AVISynth script files [default=no]"
85
  echo "  --enable-libamr-nb       enable libamr-nb floating point audio codec"
86
  echo "  --enable-libamr-wb       enable libamr-wb floating point audio codec"
87
  echo "  --enable-libfaac         enable FAAC support via libfaac [default=no]"
88
  echo "  --enable-libfaad         enable FAAD support via libfaad [default=no]"
89
  echo "  --enable-libfaadbin      open libfaad.so.0 at runtime [default=no]"
90
  echo "  --enable-libgsm          enable GSM support via libgsm [default=no]"
91
  echo "  --enable-libmp3lame      enable MP3 encoding via libmp3lame [default=no]"
92
  echo "  --enable-libnut          enable NUT (de)muxing via libnut,"
93
  echo "                           native demuxer exists [default=no]"
94
  echo "  --enable-libogg          enable Ogg muxing via libogg [default=no]"
95
  echo "  --enable-libtheora       enable Theora encoding via libtheora [default=no]"
96
  echo "  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,"
97
  echo "                           native implementations exist [default=no]"
98
  echo "  --enable-libx264         enable H.264 encoding via x264 [default=no]"
99
  echo "  --enable-libxvid         enable Xvid encoding via xvidcore,"
100
  echo "                           native MPEG-4/Xvid encoder exists [default=no]"
101
  echo ""
102
  echo "Advanced options (experts only):"
103
  echo "  --source-path=PATH       path to source code [$source_path]"
104
  echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]"
105
  echo "  --cross-compile          assume a cross-compiler is used"
106
  echo "  --target-os=OS           compiler targets OS [$targetos]"
107
  echo "  --cc=CC                  use C compiler CC [$cc]"
108
  echo "  --make=MAKE              use specified make [$make]"
109
  echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
110
  echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
111
  echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
112
  echo "  --build-suffix=SUFFIX    suffix for application specific build []"
113
  echo "  --arch=ARCH              select architecture  [$arch]"
114
  echo "  --cpu=CPU                selects the minimum cpu required (affects"
115
  echo "                           instruction selection, may crash on older CPUs)"
116
  echo "  --enable-powerpc-perf    enable performance report on PPC"
117
  echo "                           (requires enabling PMC)"
118
  echo "  --disable-mmx            disable MMX usage"
119
  echo "  --disable-armv5te        disable armv5te usage"
120
  echo "  --disable-armv6          disable armv6 usage"
121
  echo "  --disable-iwmmxt         disable iwmmxt usage"
122
  echo "  --disable-altivec        disable AltiVec usage"
123
  echo "  --disable-audio-oss      disable OSS audio support [default=no]"
124
  echo "  --disable-audio-beos     disable BeOS audio support [default=no]"
125
  echo "  --disable-v4l            disable video4linux grabbing [default=no]"
126
  echo "  --disable-v4l2           disable video4linux2 grabbing [default=no]"
127
  echo "  --disable-bktr           disable bktr video grabbing [default=no]"
128
  echo "  --disable-dv1394         disable DV1394 grabbing [default=no]"
129
  echo "  --disable-network        disable network support [default=no]"
130
  echo "  --disable-ipv6           disable ipv6 support [default=no]"
131
  echo "  --disable-zlib           disable zlib [default=no]"
132
  echo "  --disable-vhook          disable video hooking support"
133
  echo "  --disable-debug          disable debugging symbols"
134
  echo "  --disable-mpegaudio-hp   faster (but less accurate)"
135
  echo "                           MPEG audio decoding [default=no]"
136
  echo "  --disable-ffmpeg         disable ffmpeg build"
137
  echo "  --disable-ffserver       disable ffserver build"
138
  echo "  --disable-ffplay         disable ffplay build"
139
  echo "  --enable-small           optimize for size instead of speed"
140
  echo "  --enable-memalign-hack   emulate memalign, interferes with memory debuggers"
141
  echo "  --disable-encoder=NAME   disables encoder NAME"
142
  echo "  --enable-encoder=NAME    enables encoder NAME"
143
  echo "  --disable-decoder=NAME   disables decoder NAME"
144
  echo "  --enable-decoder=NAME    enables decoder NAME"
145
  echo "  --disable-encoders       disables all encoders"
146
  echo "  --disable-decoders       disables all decoders"
147
  echo "  --disable-muxer=NAME     disables muxer NAME"
148
  echo "  --enable-muxer=NAME      enables muxer NAME"
149
  echo "  --disable-muxers         disables all muxers"
150
  echo "  --disable-demuxer=NAME   disables demuxer NAME"
151
  echo "  --enable-demuxer=NAME    enables demuxer NAME"
152
  echo "  --disable-demuxers       disables all demuxers"
153
  echo "  --enable-parser=NAME     enables parser NAME"
154
  echo "  --disable-parser=NAME    disables parser NAME"
155
  echo "  --disable-parsers        disables all parsers"
156
  echo "  --enable-bsf=NAME        enables bitstream filter NAME"
157
  echo "  --disable-bsf=NAME       disables bitstream filter NAME"
158
  echo "  --disable-bsfs           disables all bitstream filters"
159
  echo "  --enable-protocol=NAME   enables protocol NAME"
160
  echo "  --disable-protocol=NAME  disables protocol NAME"
161
  echo "  --disable-protocols      disables all protocols"
162
  echo "  --list-decoders          show all available decoders"
163
  echo "  --list-encoders          show all available encoders"
164
  echo "  --list-muxers            show all available muxers"
165
  echo "  --list-demuxers          show all available demuxers"
166
  echo "  --list-parsers           show all available parsers"
167
  echo "  --list-protocols         show all available protocols"
168
  echo "  --list-bsfs              show all available bitstream filters"
169
  echo
170
  echo "Developer options (useful when working on FFmpeg itself):"
171
  echo "  --enable-gprof           enable profiling with gprof [$gprof]"
172
  echo "  --disable-opts           disable compiler optimizations"
173
  echo "  --enable-extra-warnings  enable more compiler warnings"
174
  echo "  --disable-strip          disable stripping of executables and shared libraries"
175
  echo ""
176
  echo "NOTE: Object files are built at the place where configure is launched."
177
  exit 1
178
}
179

    
180
log(){
181
    echo "$@" >>$logfile
182
}
183

    
184
log_file(){
185
    log BEGIN $1
186
    cat -n $1 >>$logfile
187
    log END $1
188
}
189

    
190
echolog(){
191
    log "$@"
192
    echo "$@"
193
}
194

    
195
die(){
196
    echolog "$@"
197
    cat <<EOF
198
If you think configure made a mistake, make sure you are using the latest
199
version from SVN.  If the latest version fails, report the problem to the
200
ffmpeg-devel@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
201
EOF
202
    if enabled logging; then
203
        cat <<EOF
204
Include the log file "$logfile" produced by configure as this will help
205
solving the problem.
206
EOF
207
    else
208
cat <<EOF
209
Rerun configure with logging enabled (do not use --log=no), and include the
210
log this produces with your report.
211
EOF
212
    fi
213
    rm -f $TMPC $TMPO $TMPE $TMPS $TMPH
214
    exit 1
215
}
216

    
217
# "tr '[a-z]' '[A-Z]'" is a workaround for Solaris tr not grokking "tr a-z A-Z"
218
toupper(){
219
    echo "$@" | tr '[a-z]' '[A-Z]'
220
}
221

    
222
tolower(){
223
    echo "$@" | tr '[A-Z]' '[a-z]'
224
}
225

    
226
set_all(){
227
    value=$1
228
    shift
229
    for var in $*; do
230
        eval $var=$value
231
    done
232
}
233

    
234
pushvar(){
235
    for var in $*; do
236
        eval level=\${${var}_level:=0}
237
        eval ${var}_${level}="\$$var"
238
        eval ${var}_level=$(($level+1))
239
    done
240
}
241

    
242
popvar(){
243
    for var in $*; do
244
        eval level=\${${var}_level:-0}
245
        test $level = 0 && continue
246
        eval level=$(($level-1))
247
        eval $var="\${${var}_${level}}"
248
        eval ${var}_level=$level
249
        eval unset ${var}_${level}
250
    done
251
}
252

    
253
enable(){
254
    set_all yes $*
255
}
256

    
257
disable(){
258
    set_all no $*
259
}
260

    
261
enabled(){
262
    eval test "x\$$1" = "xyes"
263
}
264

    
265
disabled(){
266
    eval test "x\$$1" = "xno"
267
}
268

    
269
enabled_all(){
270
    for opt; do
271
        enabled $opt || return 1
272
    done
273
}
274

    
275
disabled_all(){
276
    for opt; do
277
        disabled $opt || return 1
278
    done
279
}
280

    
281
enabled_any(){
282
    for opt; do
283
        enabled $opt && return 0
284
    done
285
}
286

    
287
disabled_any(){
288
    for opt; do
289
        disabled $opt && return 0
290
    done
291
}
292

    
293
check_deps(){
294
    for cfg; do
295
        enabled ${cfg}_checking && die "Circular dependency for $cfg."
296
        disabled ${cfg}_checking && continue
297
        enable ${cfg}_checking
298

    
299
        eval dep_all="\$${cfg}_deps"
300
        eval dep_any="\$${cfg}_deps_any"
301

    
302
        pushvar cfg dep_all dep_any
303
        check_deps $dep_all $dep_any
304
        popvar cfg dep_all dep_any
305

    
306
        enabled_all $dep_all || disable $cfg
307
        enabled_any $dep_any || disable $cfg
308

    
309
        disable ${cfg}_checking
310
    done
311
}
312

    
313
print_config(){
314
    pfx=$1
315
    header=$2
316
    makefile=$3
317
    shift 3
318
    for cfg; do
319
        ucname="`toupper $cfg`"
320
        if enabled $cfg; then
321
            echo "#define ${pfx}${ucname} 1" >> $header
322
            echo "#define ENABLE_${ucname} 1" >> $header
323
            echo "${pfx}${ucname}=yes" >> $makefile
324
        else
325
            echo "#define ENABLE_${ucname} 0" >> $header
326
        fi
327
    done
328
}
329

    
330
flags_saved(){
331
    (: ${SAVE_CFLAGS?}) 2>/dev/null
332
}
333

    
334
save_flags(){
335
    flags_saved && return
336
    SAVE_CFLAGS="$CFLAGS"
337
    SAVE_LDFLAGS="$LDFLAGS"
338
    SAVE_extralibs="$extralibs"
339
}
340

    
341
restore_flags(){
342
    flags_saved || return
343
    CFLAGS="$SAVE_CFLAGS"
344
    LDFLAGS="$SAVE_LDFLAGS"
345
    extralibs="$SAVE_extralibs"
346
    unset SAVE_CFLAGS
347
    unset SAVE_LDFLAGS
348
    unset SAVE_extralibs
349
}
350

    
351
temp_cflags(){
352
    save_flags
353
    CFLAGS="$CFLAGS $*"
354
}
355

    
356
temp_ldflags(){
357
    save_flags
358
    LDFLAGS="$LDFLAGS $*"
359
}
360

    
361
temp_extralibs(){
362
    save_flags
363
    extralibs="$extralibs $*"
364
}
365

    
366
append(){
367
    var=$1
368
    shift
369
    flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
370
    eval "$var=\"\$$var $*\""
371
}
372

    
373
add_cflags(){
374
    append CFLAGS "$@"
375
}
376

    
377
add_ldflags(){
378
    append LDFLAGS "$@"
379
}
380

    
381
add_extralibs(){
382
    append extralibs "$@"
383
}
384

    
385
check_cmd(){
386
    log "$@"
387
    "$@" >>$logfile 2>&1
388
}
389

    
390
check_cc(){
391
    log check_cc "$@"
392
    cat >$TMPC
393
    log_file $TMPC
394
    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
395
}
396

    
397
check_cpp(){
398
    log check_cpp "$@"
399
    cat >$TMPC
400
    log_file $TMPC
401
    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
402
}
403

    
404
check_ld(){
405
    log check_ld "$@"
406
    check_cc || return
407
    flags=''
408
    libs=''
409
    for f; do
410
        test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
411
    done
412
    check_cmd $cc $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs
413
}
414

    
415
check_cflags(){
416
    log check_cflags "$@"
417
    check_cc "$@" <<EOF && add_cflags "$@"
418
int x;
419
EOF
420
}
421

    
422
check_ldflags(){
423
    log check_ldflags "$@"
424
    check_ld "$@" <<EOF && add_ldflags "$@"
425
int main(){
426
    return 0;
427
}
428
EOF
429
}
430

    
431
check_header(){
432
    log check_header "$@"
433
    header=$1
434
    shift
435
    var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
436
    disable $var
437
    check_cpp "$@" <<EOF && enable $var
438
#include <$header>
439
int x;
440
EOF
441
}
442

    
443
check_func(){
444
    log check_func "$@"
445
    func=$1
446
    shift
447
    disable $func
448
    check_ld "$@" <<EOF && enable $func
449
extern int $func();
450
int main(){
451
    $func();
452
}
453
EOF
454
}
455

    
456
check_func2(){
457
    log check_func2 "$@"
458
    headers=$1
459
    func=$2
460
    shift 2
461
    disable $func
462
    incs=""
463
    for hdr in $headers; do
464
        incs="$incs
465
#include <$hdr>"
466
    done
467
    check_ld "$@" <<EOF && enable $func
468
$incs
469
int main(){
470
    (void) $func;
471
    return 0;
472
}
473
EOF
474
}
475

    
476
check_lib(){
477
    log check_lib "$@"
478
    header="$1"
479
    func="$2"
480
    shift 2
481
    temp_extralibs "$@"
482
    check_header $header && check_func $func && add_extralibs "$@"
483
    err=$?
484
    restore_flags
485
    return $err
486
}
487

    
488
check_lib2(){
489
    log check_lib2 "$@"
490
    headers="$1"
491
    func="$2"
492
    shift 2
493
    temp_extralibs "$@"
494
    check_func2 "$headers" $func && add_extralibs "$@"
495
    err=$?
496
    restore_flags
497
    return $err
498
}
499

    
500
check_exec(){
501
    check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; }
502
}
503

    
504
check_exec_crash(){
505
    code=`cat`
506

    
507
    # exit() is not async signal safe.  _Exit (C99) and _exit (POSIX)
508
    # are safe but may not be available everywhere.  Thus we use
509
    # raise(SIGTERM) instead.  The check is run in a subshell so we
510
    # can redirect the "Terminated" message from the shell.  SIGBUS
511
    # is not defined by standard C so it is used conditionally.
512

    
513
    (check_exec "$@") >>$logfile 2>&1 <<EOF
514
#include <signal.h>
515
static void sighandler(int sig){
516
    raise(SIGTERM);
517
}
518
int main(){
519
    signal(SIGILL, sighandler);
520
    signal(SIGFPE, sighandler);
521
    signal(SIGSEGV, sighandler);
522
#ifdef SIGBUS
523
    signal(SIGBUS, sighandler);
524
#endif
525
    { $code }
526
}
527
EOF
528
}
529

    
530
require(){
531
    name="$1"
532
    header="$2"
533
    func="$3"
534
    shift 3
535
    check_lib $header $func "$@" || die "ERROR: $name not found"
536
}
537

    
538
require2(){
539
    name="$1"
540
    headers="$2"
541
    func="$3"
542
    shift 3
543
    check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
544
}
545

    
546
check_foo_config(){
547
    cfg=$1
548
    pkg=$2
549
    header=$3
550
    func=$4
551
    shift 4
552
    disable $cfg
553
    check_cmd ${pkg}-config --version
554
    err=$?
555
    if test "$err" = 0; then
556
        temp_cflags `${pkg}-config --cflags`
557
        temp_extralibs `${pkg}-config --libs`
558
        check_lib "$@" $header $func && enable $cfg
559
    fi
560
    return $err
561
}
562

    
563
apply(){
564
    file=$1
565
    shift
566
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
567
}
568

    
569
CONFIG_LIST='
570
    encoders
571
    decoders
572
    parsers
573
    bsfs
574
    muxers
575
    demuxers
576
    audio_beos
577
    audio_oss
578
    avisynth
579
    beos_netserver
580
    bktr
581
    dc1394
582
    dv1394
583
    ffmpeg
584
    ffplay
585
    ffserver
586
    gpl
587
    gprof
588
    ipv6
589
    liba52
590
    liba52bin
591
    libamr
592
    libamr_nb
593
    libamr_wb
594
    libfaac
595
    libfaad
596
    libfaadbin
597
    libgsm
598
    libmp3lame
599
    libnut
600
    libogg
601
    libtheora
602
    libvorbis
603
    libx264
604
    libxvid
605
    memalign_hack
606
    mpegaudio_hp
607
    network
608
    powerpc_perf
609
    pp
610
    protocols
611
    small
612
    swscaler
613
    vhook
614
    v4l
615
    v4l2
616
    x11grab
617
    zlib
618
'
619

    
620
THREADS_LIST='
621
    beosthreads
622
    pthreads
623
    w32threads
624
'
625

    
626
ARCH_LIST='
627
    alpha
628
    armv4l
629
    bfin
630
    ia64
631
    m68k
632
    mips
633
    parisc
634
    powerpc
635
    s390
636
    sh4
637
    sparc
638
    sparc64
639
    x86
640
    x86_32
641
    x86_64
642
'
643

    
644
ARCH_EXT_LIST='
645
    altivec
646
    armv5te
647
    armv6
648
    iwmmxt
649
    mmi
650
    mmx
651
    ssse3
652
'
653

    
654
HAVE_LIST="
655
    $ARCH_EXT_LIST
656
    $THREADS_LIST
657
    altivec_h
658
    arpa_inet_h
659
    byteswap_h
660
    cmov
661
    conio_h
662
    dcbzl
663
    dev_bktr_ioctl_bt848_h
664
    dev_bktr_ioctl_meteor_h
665
    dev_ic_bt8xx_h
666
    dev_video_meteor_ioctl_meteor_h
667
    dev_video_bktr_ioctl_bt848_h
668
    dlfcn_h
669
    dlopen
670
    ebp_available
671
    ebx_available
672
    fast_64bit
673
    fast_cmov
674
    fast_unaligned
675
    fork
676
    freetype2
677
    GetProcessTimes
678
    getrusage
679
    imlib2
680
    inet_aton
681
    lrintf
682
    machine_ioctl_bt848_h
683
    machine_ioctl_meteor_h
684
    malloc_h
685
    memalign
686
    mkstemp
687
    mlib
688
    ppc64
689
    sdl
690
    sdl_video_size
691
    soundcard_h
692
    sys_poll_h
693
    sys_soundcard_h
694
    termios_h
695
    threads
696
"
697

    
698
CMDLINE_SELECT="
699
    $ARCH_EXT_LIST
700
    $CONFIG_LIST
701
    $THREADS_LIST
702
    debug
703
    extra_warnings
704
    shared
705
    static
706
"
707

    
708
# code dependency declarations
709

    
710
# architecture extensions
711
altivec_deps="powerpc"
712
armv5te_deps="armv4l"
713
armv6_deps="armv4l"
714
iwmmxt_deps="armv4l"
715
mmi_deps="mips"
716
mmx_deps="x86"
717
ssse3_deps="x86"
718

    
719
# decoders / encoders
720
dxa_decoder_deps="zlib"
721
flashsv_decoder_deps="zlib"
722
flashsv_encoder_deps="zlib"
723
flv_decoder_deps="h263_decoder"
724
h263_decoder_deps="h263_parser mpeg4video_parser"
725
h263i_decoder_deps="h263_decoder"
726
h264_decoder_deps="h264_parser"
727
mpeg_xvmc_decoder_deps="xvmc"
728
mpeg4_decoder_deps="h263_decoder"
729
msmpeg4v1_decoder_deps="h263_decoder"
730
msmpeg4v2_decoder_deps="h263_decoder"
731
msmpeg4v3_decoder_deps="h263_decoder"
732
png_decoder_deps="zlib"
733
png_encoder_deps="zlib"
734
svq3_decoder_deps="h264_parser"
735
vc1_decoder_deps="h263_decoder"
736
wmv1_decoder_deps="h263_decoder"
737
wmv2_decoder_deps="h263_decoder"
738
wmv3_decoder_deps="h263_decoder"
739
zmbv_decoder_deps="zlib"
740
zmbv_encoder_deps="zlib"
741

    
742
# external libraries
743
mpeg4aac_decoder_deps="libfaad"
744
liba52_decoder_deps="liba52"
745
libamr_nb_decoder_deps="libamr_nb"
746
libamr_nb_encoder_deps="libamr_nb"
747
libamr_wb_decoder_deps="libamr_wb"
748
libamr_wb_encoder_deps="libamr_wb"
749
libfaac_encoder_deps="libfaac"
750
libfaad_decoder_deps="libfaad"
751
libgsm_decoder_deps="libgsm"
752
libgsm_encoder_deps="libgsm"
753
libgsm_ms_decoder_deps="libgsm"
754
libgsm_ms_encoder_deps="libgsm"
755
libmp3lame_encoder_deps="libmp3lame"
756
libtheora_encoder_deps="libtheora"
757
libvorbis_decoder_deps="libvorbis"
758
libvorbis_encoder_deps="libvorbis"
759
libx264_encoder_deps="libx264"
760
libxvid_encoder_deps="libxvid"
761

    
762
# demuxers / muxers
763
ac3_demuxer_deps="ac3_parser"
764
audio_demuxer_deps_any="audio_oss audio_beos"
765
audio_muxer_deps_any="audio_oss audio_beos"
766
dc1394_demuxer_deps="dc1394"
767
dv1394_demuxer_deps="dv1394"
768
libnut_demuxer_deps="libnut"
769
libnut_muxer_deps="libnut"
770
mp3_demuxer_deps="mpegaudio_parser"
771
ogg_muxer_deps="libogg"
772
redir_demuxer_deps="network"
773
rtp_muxer_deps="network mpegts_demuxer"
774
rtsp_demuxer_deps="rtp_protocol rtp_muxer"
775
sdp_demuxer_deps="rtsp_demuxer"
776
v4l2_demuxer_deps="v4l2"
777
video_grab_bktr_demuxer_deps="bktr"
778
video_grab_v4l_demuxer_deps="v4l"
779
x11_grab_device_demuxer_deps="x11grab"
780

    
781
# protocols
782
http_protocol_deps="network"
783
rtp_protocol_deps="udp_protocol"
784
tcp_protocol_deps="network"
785
udp_protocol_deps="network"
786

    
787
# programs
788
ffplay_deps="sdl"
789
ffserver_deps="muxers rtp_protocol"
790

    
791

    
792
# set temporary file name
793
if test ! -z "$TMPDIR" ; then
794
    TMPDIR1="${TMPDIR}"
795
elif test ! -z "$TEMPDIR" ; then
796
    TMPDIR1="${TEMPDIR}"
797
else
798
    TMPDIR1="/tmp"
799
fi
800

    
801
TMPC="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
802
TMPO="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
803
TMPE="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}"
804
TMPS="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
805
TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
806

    
807
# default parameters
808

    
809
logging="yes"
810
logfile="config.err"
811

    
812
# installation paths
813
PREFIX="/usr/local"
814
libdir='$(PREFIX)/lib'
815
shlibdir="$libdir"
816
incdir='$(PREFIX)/include/ffmpeg'
817
mandir='$(PREFIX)/man'
818
bindir='$(PREFIX)/bin'
819

    
820
# toolchain
821
cross_prefix=""
822
cross_compile="no"
823
cc="gcc"
824
ar="ar"
825
ranlib="ranlib"
826
make="make"
827
strip="strip"
828
asmalign_pot="unknown"
829

    
830
# machine
831
arch=`uname -m`
832
cpu="generic"
833

    
834
# OS
835
targetos=$(tolower $(uname -s))
836

    
837
# non-library system interfaces
838
audio_oss="yes"
839
bktr="yes"
840
dv1394="yes"
841
v4l2="yes"
842
v4l="yes"
843

    
844
# libraries
845
zlib="yes"
846

    
847
# configurable options
848
debug="yes"
849
dostrip="yes"
850
ffmpeg="yes"
851
ffplay="yes"
852
ffserver="yes"
853
gpl="no"
854
ipv6="yes"
855
shared="no"
856
static="yes"
857
memalign_hack="no"
858
mpegaudio_hp="yes"
859
network="yes"
860
optimize="yes"
861
protocols="yes"
862
vhook="default"
863

    
864
# build settings
865
SHFLAGS='-shared -Wl,-soname,$@'
866
VHOOKSHFLAGS='$(SHFLAGS)'
867
LIBOBJFLAGS=""
868
FFLDFLAGS=
869
LDLATEFLAGS='-Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil'
870
FFSERVERLDFLAGS=-Wl,-E
871
LDCONFIG="ldconfig"
872
LIBPREF="lib"
873
LIBSUF=".a"
874
LIB='$(LIBPREF)$(NAME)$(LIBSUF)'
875
SLIBPREF="lib"
876
SLIBSUF=".so"
877
SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF)'
878
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
879
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
880
EXESUF=""
881
BUILDSUF=""
882
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIB)"'
883

    
884
# find source path
885
source_path="`dirname \"$0\"`"
886
source_path_used="yes"
887
if test -z "$source_path" -o "$source_path" = "." ; then
888
    source_path="`pwd`"
889
    source_path_used="no"
890
else
891
    source_path="`cd \"$source_path\"; pwd`"
892
    echo "$source_path" | grep -q '[[:blank:]]' &&
893
      die "Out of tree builds are impossible with whitespace in source path."
894
fi
895

    
896
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
897
    show_help
898
fi
899

    
900
FFMPEG_CONFIGURATION="$@"
901

    
902
ENCODER_LIST=`sed -n 's/^[^#]*ENC.*(.*, *\(.*\)).*/\1_encoder/p' "$source_path/libavcodec/allcodecs.c"`
903
DECODER_LIST=`sed -n 's/^[^#]*DEC.*(.*, *\(.*\)).*/\1_decoder/p' "$source_path/libavcodec/allcodecs.c"`
904
PARSER_LIST=`sed -n 's/^[^#]*PARSER.*(.*, *\(.*\)).*/\1_parser/p' "$source_path/libavcodec/allcodecs.c"`
905
BSF_LIST=`sed -n 's/^[^#]*BSF.*(.*, *\(.*\)).*/\1_bsf/p' "$source_path/libavcodec/allcodecs.c"`
906
MUXER_LIST=`sed -n 's/^[^#]*_MUX.*(.*, *\(.*\)).*/\1_muxer/p' "$source_path/libavformat/allformats.c"`
907
DEMUXER_LIST=`sed -n 's/^[^#]*DEMUX.*(.*, *\(.*\)).*/\1_demuxer/p' "$source_path/libavformat/allformats.c"`
908
PROTOCOL_LIST=`sed -n 's/^[^#]*PROTOCOL.*(.*, *\(.*\)).*/\1_protocol/p' "$source_path/libavformat/allformats.c"`
909

    
910
enable $ENCODER_LIST $DECODER_LIST $PARSER_LIST $MUXER_LIST $DEMUXER_LIST $PROTOCOL_LIST $BSF_LIST
911
enable $ARCH_EXT_LIST
912

    
913
die_unknown(){
914
    echo "Unknown option \"$1\"."
915
    echo "See $0 --help for available options."
916
    exit 1
917
}
918

    
919
show_list() {
920
    for part in $*; do
921
        echo $part | sed 's/_[^_]*$//'
922
    done | sort
923
    exit 0
924
}
925

    
926
for opt do
927
  optval="${opt#*=}"
928
  case "$opt" in
929
  --log)
930
  ;;
931
  --log=*) logging="$optval"
932
  ;;
933
  --prefix=*) PREFIX="$optval"
934
  ;;
935
  --libdir=*) libdir="$optval"
936
  ;;
937
  --shlibdir=*) shlibdir="$optval"
938
  ;;
939
  --incdir=*) incdir="$optval"
940
  ;;
941
  --mandir=*) mandir="$optval"
942
  ;;
943
  --source-path=*) source_path="$optval"
944
  ;;
945
  --cross-prefix=*) cross_prefix="$optval"
946
  ;;
947
  --cross-compile) cross_compile="yes"
948
  ;;
949
  --target-os=*) targetos="$optval"
950
  ;;
951
  --cc=*) cc="$optval"
952
  ;;
953
  --make=*) make="$optval"
954
  ;;
955
  --extra-cflags=*) add_cflags "$optval"
956
  ;;
957
  --extra-ldflags=*) add_ldflags "$optval"
958
  ;;
959
  --extra-libs=*) add_extralibs "$optval"
960
  ;;
961
  --build-suffix=*) BUILDSUF="$optval"
962
  ;;
963
  --arch=*) arch="$optval"
964
  ;;
965
  --cpu=*) cpu="$optval"
966
  ;;
967
  --disable-opts) optimize="no"
968
  ;;
969
  --enable-sunmlib) mlib="yes"
970
  ;;
971
  --disable-strip) dostrip="no"
972
  ;;
973
  --disable-encoders) disable $ENCODER_LIST
974
  ;;
975
  --disable-decoders) disable $DECODER_LIST
976
  ;;
977
  --disable-muxers) disable $MUXER_LIST
978
  ;;
979
  --disable-demuxers) disable $DEMUXER_LIST
980
  ;;
981
  --disable-parsers) disable $PARSER_LIST
982
  ;;
983
  --disable-bsfs) disable $BSF_LIST
984
  ;;
985
  --disable-protocols) disable $PROTOCOL_LIST
986
  ;;
987
  --enable-*=*|--disable-*=*)
988
  eval `echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/'`
989
  case "$thing" in
990
      encoder|decoder|muxer|demuxer|parser|bsf|protocol) $action ${optval}_${thing} ;;
991
      *) die_unknown "$opt" ;;
992
  esac
993
  ;;
994
  --enable-?*|--disable-?*)
995
  eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
996
  echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt
997
  $action $option
998
  ;;
999
  --list-*)
1000
    NAME="${opt#--list-}"
1001
    NAME=$(toupper ${NAME%s})
1002
    eval show_list \$${NAME}_LIST
1003
  ;;
1004
  --help) show_help
1005
  ;;
1006
  *)
1007
  die_unknown $opt
1008
  ;;
1009
  esac
1010
done
1011

    
1012
case "$arch" in
1013
  i386|i486|i586|i686|i86pc|BePC)
1014
    arch="x86_32"
1015
    enable fast_unaligned
1016
  ;;
1017
  x86_64|amd64)
1018
    arch="x86_32"
1019
    enable fast_unaligned
1020
    canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
1021
    if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
1022
      if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
1023
        arch="x86_64"
1024
        enable fast_64bit
1025
      fi
1026
    fi
1027
  ;;
1028
  # armv4l is a subset of armv[567]*l
1029
  arm|armv[4567]*l)
1030
    arch="armv4l"
1031
  ;;
1032
  alpha)
1033
    arch="alpha"
1034
    enable fast_64bit
1035
  ;;
1036
  "Power Macintosh"|ppc|powerpc)
1037
    arch="powerpc"
1038
  ;;
1039
  ppc64)
1040
    arch="powerpc"
1041
    enable fast_64bit
1042
  ;;
1043
  mips|mipsel|IP*)
1044
    arch="mips"
1045
  ;;
1046
  sun4u|sparc64)
1047
    arch="sparc64"
1048
    enable fast_64bit
1049
  ;;
1050
  sparc)
1051
    arch="sparc"
1052
  ;;
1053
  sh4)
1054
    arch="sh4"
1055
  ;;
1056
  parisc)
1057
    arch="parisc"
1058
  ;;
1059
  parisc64)
1060
    arch="parisc"
1061
    enable fast_64bit
1062
  ;;
1063
  s390|s390x)
1064
    arch="s390"
1065
  ;;
1066
  m68k)
1067
    arch="m68k"
1068
  ;;
1069
  ia64)
1070
    arch="ia64"
1071
    enable fast_64bit
1072
  ;;
1073
  bfin)
1074
    arch="bfin"
1075
  ;;
1076
  *)
1077
    arch="unknown"
1078
  ;;
1079
esac
1080

    
1081
enable $arch
1082
enabled_any x86_32 x86_64 && enable x86
1083
enabled     sparc64       && enable sparc
1084

    
1085
# OS specific
1086
osextralibs="-lm"
1087
case $targetos in
1088
  beos|haiku|zeta)
1089
    PREFIX="$HOME/config"
1090
    # helps building libavcodec
1091
    add_cflags "-DPIC -fomit-frame-pointer"
1092
    # 3 gcc releases known for BeOS, each with ugly bugs
1093
    gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
1094
    case "$gcc_version" in
1095
      2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
1096
        mmx="no"
1097
        ;;
1098
      *20010315*) echo "BeBits gcc"
1099
        add_cflags "-fno-expensive-optimizations"
1100
        ;;
1101
    esac
1102
    LDCONFIG="echo ignoring ldconfig"
1103
    SHFLAGS=-nostart
1104
    # disable Linux things
1105
    dv1394="no"
1106
    # enable BeOS things
1107
    disabled audio_beos || enable_audio_beos
1108
    # no need for libm, but the inet stuff
1109
    # Check for BONE
1110
    # XXX: actually should check for NOT net_server
1111
    if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then
1112
        osextralibs="-lbind -lsocket"
1113
    else
1114
        beos_netserver="yes"
1115
        osextralibs="-lnet"
1116
    fi ;;
1117
  sunos)
1118
    dv1394="no"
1119
    FFLDFLAGS=""
1120
    FFSERVERLDFLAGS=""
1121
    SHFLAGS="-shared -Wl,-h,\$@"
1122
    add_extralibs "-lsocket -lnsl"
1123
    ;;
1124
  netbsd)
1125
    dv1394="no"
1126
    add_extralibs "-lossaudio"
1127
    ;;
1128
  openbsd)
1129
    dv1394="no"
1130
    need_memalign="no"
1131
    LIBOBJFLAGS="\$(PIC)"
1132
    LDCONFIG="ldconfig -m \$(SHLIBDIR)"
1133
    SHFLAGS='-shared'
1134
    SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF).$(LIBVERSION)'
1135
    SLIBNAME_WITH_VERSION='$(SLIBNAME)'
1136
    SLIBNAME_WITH_MAJOR='$(SLIBNAME)'
1137
    add_extralibs "-lossaudio"
1138
    ;;
1139
  freebsd)
1140
    dv1394="no"
1141
    need_memalign="no"
1142
    add_cflags "-pthread"
1143
    ;;
1144
  gnu/kfreebsd)
1145
    dv1394="no"
1146
    add_cflags "-pthread"
1147
    ;;
1148
  bsd/os)
1149
    dv1394="no"
1150
    osextralibs="-lpoll -lgnugetopt -lm"
1151
    strip="strip -d"
1152
    ;;
1153
  darwin)
1154
    dv1394="no"
1155
    need_memalign="no"
1156
    SHFLAGS="-dynamiclib -Wl,-single_module -Wl,-install_name,\$(SHLIBDIR)/\$(SLIBNAME),-current_version,\$(SPPVERSION),-compatibility_version,\$(SPPVERSION) -Wl,-read_only_relocs,suppress"
1157
    VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(SHLIBDIR)/vhook/$@'
1158
    osextralibs=""
1159
    strip="strip -x"
1160
    FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
1161
    SLIBSUF=".dylib"
1162
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
1163
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
1164
    FFSERVERLDFLAGS=-Wl,-bind_at_load
1165
    ;;
1166
  mingw32*)
1167
    targetos=mingw32
1168
    shlibdir="$bindir"
1169
    dv1394="no"
1170
    VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libswscale -L$(BUILD_ROOT)/libavutil'
1171
    VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lswscale$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
1172
    ffserver="no"
1173
    network="no"
1174
    SLIBPREF=""
1175
    SLIBSUF=".dll"
1176
    EXESUF=".exe"
1177
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
1178
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
1179
    SLIB_EXTRA_CMD="-lib /machine:i386 /def:\$(@:${SLIBSUF}=.def)"
1180
    SLIB_INSTALL_EXTRA_CMD="-install -m 644 \$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib) \"\$(SHLIBDIR)/\$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib)\""
1181
    SHFLAGS="-shared -Wl,--output-def,\$(@:${SLIBSUF}=.def),--out-implib,lib\$(SLIBNAME:\$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base"
1182
    enabled network && add_extralibs -lws2_32
1183
    ;;
1184
  cygwin*)
1185
    targetos=cygwin
1186
    shlibdir="$bindir"
1187
    dv1394="no"
1188
    VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil'
1189
    VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
1190
    if enabled swscaler; then
1191
        VHOOKSHFLAGS="$VHOOKSHFLAGS -L\$(BUILD_ROOT)/libswscale"
1192
        VHOOKLIBS="$VHOOKLIBS -lswscale\$(BUILDSUF)"
1193
    fi
1194
    osextralibs=""
1195
    EXESUF=".exe"
1196
    SLIBPREF="cyg"
1197
    SLIBSUF=".dll"
1198
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
1199
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
1200
    SHFLAGS='-shared -Wl,--out-implib=lib$(NAME).dll.a -Wl,--enable-auto-image-base'
1201
    ;;
1202
  linux)
1203
    LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS"
1204
    ;;
1205
  irix*)
1206
    targetos=irix
1207
    ranlib="echo ignoring ranlib"
1208
    ;;
1209
  *)
1210
    targetos="${targetos}-UNKNOWN"
1211
    ;;
1212
esac
1213

    
1214
add_extralibs $osextralibs
1215

    
1216
if ! disabled logging ; then
1217
    enabled logging || logfile="$logging"
1218
    echo "# $0 $@" >$logfile
1219
    set >>$logfile
1220
else
1221
    logfile=/dev/null
1222
fi
1223

    
1224
# Combine FFLDFLAGS and the LDFLAGS environment variable.
1225
LDFLAGS="$FFLDFLAGS $LDFLAGS"
1226

    
1227
test -n "$cross_prefix" && cross_compile=yes
1228
cc="${cross_prefix}${cc}"
1229
ar="${cross_prefix}${ar}"
1230
ranlib="${cross_prefix}${ranlib}"
1231
strip="${cross_prefix}${strip}"
1232

    
1233
# we need to build at least one lib type
1234
if disabled_all static shared; then
1235
    cat <<EOF
1236
At least one library type must be built.
1237
Specify --enable-static to build the static libraries or --enable-shared to
1238
build the shared libraries as well. To only build the shared libraries specify
1239
--disable-static in addition to --enable-shared.
1240
EOF
1241
    exit 1;
1242
fi
1243

    
1244
if disabled libogg; then
1245
    enabled libtheora && die "libogg must be enabled to enable libtheora."
1246
    enabled libvorbis && die "libogg must be enabled to enable libvorbis."
1247
fi
1248

    
1249
if enabled_any libfaad libfaadbin ; then
1250
    if check_header faad.h; then
1251
        check_cc << EOF
1252
#include <faad.h>
1253
#ifndef FAAD2_VERSION
1254
ok faad1
1255
#endif
1256
int main( void ) { return 0; }
1257
EOF
1258
        test $? = 0 && enable libfaad2
1259
    else
1260
        die "FAAD test failed."
1261
    fi
1262
fi
1263

    
1264

    
1265
if disabled gpl ; then
1266
    die_gpl_disabled(){
1267
        name=$1
1268
        shift
1269
        enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
1270
    }
1271
    die_gpl_disabled "The Postprocessing code" pp
1272
    die_gpl_disabled "liba52"                  liba52
1273
    die_gpl_disabled "libx264"                 libx264
1274
    die_gpl_disabled "libxvidcore"             libxvid
1275
    die_gpl_disabled "FAAD2"                   libfaad2
1276
    die_gpl_disabled "The X11 grabber"         x11grab
1277
    die_gpl_disabled "The software scaler"     swscaler
1278
fi
1279

    
1280
check_deps $ARCH_EXT_LIST
1281

    
1282
test -z "$need_memalign" && need_memalign="$mmx"
1283

    
1284
#Darwin CC versions
1285
needmdynamicnopic="no"
1286
if test $targetos = darwin; then
1287
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
1288
        add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
1289
    else
1290
        add_cflags "-no-cpp-precomp -pipe"
1291
        check_cflags "-force_cpusubtype_ALL"
1292
        check_cflags "-Wno-sign-compare"
1293
        disabled shared && needmdynamicnopic="yes"
1294
    fi
1295
fi
1296
enabled needmdynamicnopic && add_cflags -mdynamic-no-pic
1297

    
1298
disabled optimize || add_cflags -fomit-frame-pointer
1299

    
1300
# Add processor-specific flags
1301
if test $cpu != "generic"; then
1302
    warn_altivec(){
1303
        $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
1304
    }
1305
    case $cpu in
1306
        601|ppc601|PowerPC601)
1307
            add_cflags "-mcpu=601"
1308
            warn_altivec enabled PPC601
1309
        ;;
1310
        603*|ppc603*|PowerPC603*)
1311
            add_cflags "-mcpu=603"
1312
            warn_altivec enabled PPC603
1313
        ;;
1314
        604*|ppc604*|PowerPC604*)
1315
            add_cflags "-mcpu=604"
1316
            warn_altivec enabled PPC604
1317
        ;;
1318
        G3|g3|75*|ppc75*|PowerPC75*)
1319
            add_cflags "-mcpu=750 -mpowerpc-gfxopt"
1320
            warn_altivec enabled PPC75x
1321
        ;;
1322
        G4|g4|745*|ppc745*|PowerPC745*)
1323
            add_cflags "-mcpu=7450 -mpowerpc-gfxopt"
1324
            warn_altivec disabled PPC745x
1325
        ;;
1326
        74*|ppc74*|PowerPC74*)
1327
            add_cflags "-mcpu=7400 -mpowerpc-gfxopt"
1328
            warn_altivec disabled PPC74xx
1329
        ;;
1330
        G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
1331
            add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
1332
            warn_altivec disabled PPC970
1333
            enable ppc64
1334
        ;;
1335
        Cell|CELL|cell)
1336
            add_cflags "-mcpu=cell"
1337
            warn_altivec disabled Cell
1338
            enable ppc64
1339
        ;;
1340
        # targets that do NOT support conditional mov (cmov)
1341
        i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
1342
            add_cflags "-march=$cpu"
1343
            cmov="no"
1344
        ;;
1345
        # targets that do support conditional mov (cmov)
1346
        i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
1347
            add_cflags "-march=$cpu"
1348
            cmov="yes"
1349
            fast_cmov="yes"
1350
        ;;
1351
        # targets that do support conditional mov but on which it's slow
1352
        pentium4|prescott|nocona)
1353
            add_cflags "-march=$cpu"
1354
            cmov="yes"
1355
            fast_cmov="no"
1356
        ;;
1357
        sparc64)
1358
            add_cflags "-mcpu=v9"
1359
        ;;
1360
        bf*) #bf531 bf532 bf533 bf561 bf5xx all get this config
1361
            add_cflags "-mfdpic"
1362
            add_ldflags "-mfdpic"
1363
        ;;
1364
        *)
1365
        echo "WARNING: Unknown CPU \"$cpu\", ignored."
1366
        ;;
1367
    esac
1368
fi
1369

    
1370
gnu_make(){
1371
    $1 --version 2>&1 | grep -q GNU
1372
}
1373

    
1374
if ! gnu_make $make; then
1375
    gnu_make gmake && make=gmake || die "GNU make not found."
1376
fi
1377

    
1378
# make sure we can execute files in $TMPDIR
1379
cat >$TMPE 2>>$logfile <<EOF
1380
#! /bin/sh
1381
EOF
1382
chmod +x $TMPE >>$logfile 2>&1
1383
if ! $TMPE >>$logfile 2>&1; then
1384
    cat <<EOF
1385
Unable to create and execute files in $TMPDIR1.  Set the TMPDIR environment
1386
variable to another directory and make sure that $TMPDIR1 is not mounted
1387
noexec.
1388
EOF
1389
    die "Sanity test failed."
1390
fi
1391
rm $TMPE
1392

    
1393
# compiler sanity check
1394
check_exec <<EOF
1395
int main(){
1396
    return 0;
1397
}
1398
EOF
1399
if test "$?" != 0; then
1400
    echo "$cc is unable to create an executable file."
1401
    if test -z "$cross_prefix" && disabled cross_compile ; then
1402
        echo "If $cc is a cross-compiler, use the --cross-compile option."
1403
        echo "Only do this if you know what cross compiling means."
1404
    fi
1405
    die "C compiler test failed."
1406
fi
1407

    
1408
if enabled x86; then
1409
    # check whether EBP is available on x86
1410
    # As 'i' is stored on the stack, this program will crash
1411
    # if the base pointer is used to access it because the
1412
    # base pointer is cleared in the inline assembly code.
1413
    check_exec_crash <<EOF && enable ebp_available
1414
    volatile int i=0;
1415
    asm volatile (
1416
        "xorl %%ebp, %%ebp"
1417
    ::: "%ebp");
1418
    return i;
1419
EOF
1420

    
1421
    # check wether EBX is available on x86
1422
    check_cc <<EOF && enable ebx_available
1423
int main(){
1424
    asm volatile ("":::"%ebx");
1425
}
1426
EOF
1427

    
1428
    # check whether binutils is new enough to compile SSSE3
1429
    enabled ssse3 && check_cc <<EOF || disable ssse3
1430
int main(){
1431
    asm volatile ("pabsw %xmm0, %xmm0");
1432
}
1433
EOF
1434
fi
1435

    
1436
# check for assembler specific support
1437

    
1438
if test $arch = "powerpc"; then
1439
check_cc <<EOF && dcbzl=yes
1440
int main(void) {
1441
    register long zero = 0;
1442
    char data[1024];
1443
    asm volatile("dcbzl %0, %1" : : "b" (data), "r" (zero));
1444
return 0;
1445
}
1446
EOF
1447
fi
1448

    
1449
# check for SIMD availability
1450

    
1451
# AltiVec flags: The FSF version of GCC differs from the Apple version
1452
if enabled altivec; then
1453
    if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
1454
        add_cflags "-faltivec"
1455
    else
1456
        add_cflags "-maltivec -mabi=altivec"
1457
    fi
1458

    
1459
    check_header altivec.h
1460

    
1461
    # check if our compiler supports Motorola AltiVec C API
1462
    if enabled altivec_h; then
1463
        inc_altivec_h="#include <altivec.h>"
1464
    else
1465
        inc_altivec_h=
1466
    fi
1467
    check_cc <<EOF || altivec=no
1468
$inc_altivec_h
1469
int main(void) {
1470
    vector signed int v1, v2, v3;
1471
    v1 = vec_add(v2,v3);
1472
    return 0;
1473
}
1474
EOF
1475
fi
1476

    
1477
# check armv5te instructions support
1478
enabled armv5te && check_cc <<EOF || disable armv5te
1479
int main(void) {
1480
    __asm__ __volatile__ ("qadd r0, r0, r0");
1481
}
1482
EOF
1483

    
1484
enabled armv6 && check_cc <<EOF || disable armv6
1485
int main(void) {
1486
    __asm__ __volatile__ ("sadd16 r0, r0, r0");
1487
}
1488
EOF
1489

    
1490
# check iwmmxt support
1491
enabled iwmmxt && check_cc <<EOF || disable iwmmxt
1492
int main(void) {
1493
    __asm__ __volatile__ ("wunpckelub wr6, wr4");
1494
}
1495
EOF
1496

    
1497
# check if our compiler supports mmi
1498
enabled mmi && check_cc <<EOF || mmi="no"
1499
int main(void) {
1500
    __asm__ ("lq \$2, 0(\$2)");
1501
    return 0;
1502
}
1503
EOF
1504

    
1505
# ---
1506
# big/little-endian test
1507
if disabled cross_compile; then
1508
    check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
1509
#include <inttypes.h>
1510
int main(int argc, char ** argv){
1511
        volatile uint32_t i=0x01234567;
1512
        return (*((uint8_t*)(&i))) == 0x67;
1513
}
1514
EOF
1515
else
1516
    # programs cannot be launched if cross compiling, so make a static guess
1517
    if test "$arch" = "powerpc" -o "$arch" = "mips" ; then
1518
        bigendian="yes"
1519
    fi
1520
fi
1521

    
1522
# ---
1523
# check availability of some header files
1524

    
1525
check_header malloc.h
1526
check_func memalign
1527

    
1528
if disabled_all memalign memalign_hack && enabled need_memalign ; then
1529
    die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack."
1530
fi
1531

    
1532
check_header byteswap.h
1533

    
1534
check_func mkstemp
1535

    
1536
check_header termios.h
1537
check_header conio.h
1538

    
1539
check_header arpa/inet.h
1540

    
1541
check_func inet_aton
1542
enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
1543

    
1544
# ffserver uses poll(),
1545
# if it's not found we can emulate it using select().
1546
if enabled ffserver; then
1547
    check_header sys/poll.h
1548
fi
1549

    
1550
# check for some common methods of building with pthread support
1551
# do this before the optional library checks as some of them require pthreads
1552
if enabled pthreads; then
1553
    if check_func pthread_create; then
1554
        :
1555
    elif check_func pthread_create -pthread; then
1556
        add_cflags -pthread
1557
        add_ldflags -pthread
1558
    elif check_func pthread_create -pthreads; then
1559
        add_cflags -pthreads
1560
        add_ldflags -pthreads
1561
    elif ! check_lib pthread.h pthread_create -lpthread; then
1562
        die "ERROR: can't find pthreads library"
1563
    fi
1564
fi
1565

    
1566
for thread in $THREADS_LIST; do
1567
    if enabled $thread; then
1568
        if test -n "$thread_type"; then
1569
            die "ERROR: Only one thread type must be selected."
1570
        else
1571
            thread_type="$thread"
1572
        fi
1573
    fi
1574
done
1575

    
1576
# test for lrintf in math.h
1577
check_exec <<EOF && lrintf=yes || lrintf=no
1578
#define _ISOC9X_SOURCE  1
1579
#include <math.h>
1580
int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
1581
EOF
1582

    
1583
enabled_any libamr_nb libamr_wb && enable libamr
1584

    
1585
# these are off by default, so fail if requested and not available
1586
enabled liba52     && require liba52 a52dec/a52.h a52_init -la52
1587
enabled libamr_nb  && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm
1588
enabled libamr_wb  && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
1589
enabled libgsm     && require libgsm gsm.h gsm_create -lgsm
1590
enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
1591
enabled libtheora  && require libtheora theora/theora.h theora_info_init -ltheora -logg
1592
enabled libvorbis  && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
1593
enabled libogg     && require libogg ogg/ogg.h ogg_sync_init -logg
1594
enabled libnut     && require libnut libnut.h nut_demuxer_init -lnut
1595
enabled libx264    && require x264 x264.h x264_encoder_open -lx264
1596
enabled libxvid    && require Xvid xvid.h xvid_global -lxvidcore
1597
enabled dc1394     && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
1598
enabled mlib       && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
1599
enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
1600
enabled libfaad    && require2 libfaad faad.h faacDecOpen -lfaad
1601
enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
1602

    
1603
_restrict=
1604
for restrict_keyword in restrict __restrict__ __restrict; do
1605
    check_cc <<EOF && _restrict=$restrict_keyword && break
1606
void foo(char * $restrict_keyword p);
1607
EOF
1608
done
1609

    
1610
# dlopen/dlfcn.h probing
1611

    
1612
check_header dlfcn.h
1613

    
1614
if check_func dlopen; then
1615
    ldl=
1616
elif check_func dlopen -ldl; then
1617
    ldl=-ldl
1618
fi
1619

    
1620
check_func getrusage
1621
check_func2 windows.h GetProcessTimes
1622

    
1623
check_func fork
1624

    
1625
test "$vhook" = "default" && vhook="$dlopen"
1626

    
1627
enabled_any vhook liba52bin libfaadbin ffserver && add_extralibs $ldl
1628

    
1629
if test "$targetos" = cygwin -o "$targetos" = mingw32 && enabled_all static vhook ; then
1630
    vhook="no"
1631
    echo
1632
    echo "At the moment vhooks don't work on Cygwin or MinGW static builds."
1633
    echo "Patches welcome."
1634
    echo
1635
fi
1636

    
1637
if enabled vhook; then
1638
    check_ldflags -rdynamic
1639
    check_ldflags -export-dynamic
1640
fi
1641

    
1642
enabled audio_beos && add_extralibs "-lmedia -lbe"
1643

    
1644
check_foo_config imlib2 imlib2 Imlib2.h imlib_load_font
1645
check_foo_config freetype2 freetype ft2build.h FT_Init_FreeType
1646

    
1647
##########################################
1648
# SDL check
1649

    
1650
sdl_too_old=no
1651
sdl=no
1652
SDL_CONFIG="${cross_prefix}sdl-config"
1653
if "${SDL_CONFIG}" --version >/dev/null 2>&1; then
1654
    sdl_cflags=`"${SDL_CONFIG}" --cflags`
1655
    temp_cflags $sdl_cflags
1656
    temp_extralibs `"${SDL_CONFIG}" --libs`
1657
    if check_lib SDL.h SDL_Init; then
1658
        _sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'`
1659
        if test "$_sdlversion" -lt 121 ; then
1660
            sdl_too_old=yes
1661
        else
1662
            sdl=yes
1663
            check_cc $sdl_cflags <<EOF && enable sdl_video_size
1664
#include <SDL.h>
1665
int main(void){
1666
    const SDL_VideoInfo *vi = SDL_GetVideoInfo();
1667
    int w = vi->current_w;
1668
    return 0;
1669
}
1670
EOF
1671
        fi
1672
    fi
1673
    restore_flags
1674
fi
1675

    
1676
texi2html -version >/dev/null 2>&1 && enable texi2html || disable texi2html
1677

    
1678
##########################################
1679
# IPv6 check
1680

    
1681
enabled network && enabled ipv6 && check_ld <<EOF && ipv6=yes || ipv6=no
1682
#include <sys/types.h>
1683
#include <sys/socket.h>
1684
#include <netinet/in.h>
1685
#include <netdb.h>
1686
int main( void ) {
1687
  struct sockaddr_storage saddr;
1688
  struct ipv6_mreq mreq6;
1689
  getaddrinfo(0,0,0,0);
1690
  getnameinfo(0,0,0,0,0,0,0);
1691
  IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
1692
}
1693
EOF
1694

    
1695
enabled v4l  && check_header linux/videodev.h  || disable v4l
1696
enabled v4l2 && check_header linux/videodev2.h || disable v4l2
1697

    
1698
# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
1699
if enabled bktr; then
1700
    { check_header dev/bktr/ioctl_meteor.h &&
1701
      check_header dev/bktr/ioctl_bt848.h; } ||
1702
    { check_header machine/ioctl_meteor.h &&
1703
      check_header machine/ioctl_bt848.h; } ||
1704
    { check_header dev/video/meteor/ioctl_meteor.h &&
1705
      check_header dev/video/bktr/ioctl_bt848.h; } ||
1706
    check_header dev/ic/bt8xx.h ||
1707
    disable bktr
1708
fi
1709

    
1710
enabled audio_oss &&
1711
    check_header sys/soundcard.h ||
1712
    check_header soundcard.h ||
1713
    disable audio_oss
1714

    
1715
# Deal with the x11 frame grabber
1716
enabled x11grab                         &&
1717
enabled gpl                             &&
1718
enabled x11_grab_device_demuxer         &&
1719
check_header X11/Xlib.h                 &&
1720
check_header X11/extensions/XShm.h      &&
1721
check_func XOpenDisplay -lX11           &&
1722
check_func XShmCreateImage -lX11 -lXext &&
1723
add_extralibs -lX11 -lXext              ||
1724
disable x11_grab_device_demuxer
1725

    
1726
enabled debug && add_cflags -g
1727

    
1728
# add some useful compiler flags if supported
1729
check_cflags -Wdeclaration-after-statement
1730
check_cflags -Wall
1731
check_cflags -Wno-switch
1732
check_cflags -Wdisabled-optimization
1733
check_cflags -Wpointer-arith
1734
check_cflags -Wredundant-decls
1735
check_cflags -Wno-pointer-sign
1736
enabled extra_warnings && check_cflags -Winline
1737

    
1738
# add some linker flags
1739
check_ldflags -Wl,--warn-common
1740
check_ldflags $LDLATEFLAGS
1741

    
1742
if enabled small; then
1743
    check_cflags -Os            # not all compilers support -Os
1744
    optimize="small"
1745
elif enabled optimize; then
1746
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
1747
        add_cflags  "-O5"
1748
        add_ldflags "-O5"
1749
    else
1750
        add_cflags "-O3"
1751
    fi
1752
fi
1753

    
1754
# PIC flags for shared library objects where they are needed
1755
if enabled shared; then
1756
    # LIBOBJFLAGS may have already been set in the OS configuration
1757
    if test -z "$LIBOBJFLAGS" ; then
1758
        case "$arch" in
1759
            x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS="\$(PIC)" ;;
1760
        esac
1761
    fi
1762
fi
1763

    
1764
if enabled gprof; then
1765
    add_cflags  "-p"
1766
    add_ldflags "-p"
1767
fi
1768

    
1769
VHOOKCFLAGS="-fPIC"
1770

    
1771
# find if .align arg is power-of-two or not
1772
if test $asmalign_pot = "unknown"; then
1773
    asmalign_pot="no"
1774
    echo 'asm (".align 3");' | check_cc && asmalign_pot="yes"
1775
fi
1776

    
1777
enabled_any $ENCODER_LIST  && enable encoders
1778
enabled_any $DECODER_LIST  && enable decoders
1779
enabled_any $MUXER_LIST    && enable muxers
1780
enabled_any $DEMUXER_LIST  && enable demuxers
1781
enabled_any $PROTOCOL_LIST && enable protocols
1782
enabled_any $BSF_LIST      && enable bsfs
1783

    
1784
enabled_any $THREADS_LIST  && enable threads
1785

    
1786
check_deps $CONFIG_LIST $HAVE_LIST $DECODER_LIST $ENCODER_LIST $PARSER_LIST \
1787
    $BSF_LIST $DEMUXER_LIST $MUXER_LIST $PROTOCOL_LIST
1788

    
1789
enabled libogg    && append pkg_requires "ogg >= 1.1"
1790
enabled libtheora && append pkg_requires "theora"
1791
enabled libvorbis && append pkg_requires "vorbis vorbisenc"
1792
enabled dc1394    && append pkg_requires "libraw1394"
1793

    
1794
echo "install prefix            $PREFIX"
1795
echo "source path               $source_path"
1796
echo "C compiler                $cc"
1797
echo "make                      $make"
1798
echo ".align is power-of-two    $asmalign_pot"
1799
echo "ARCH                      $arch ($cpu)"
1800
if test "$BUILDSUF" != ""; then
1801
    echo "build suffix              $BUILDSUF"
1802
fi
1803
echo "big-endian                ${bigendian-no}"
1804
if test $arch = "x86_32" -o $arch = "x86_64"; then
1805
    echo "MMX enabled               ${mmx-no}"
1806
    echo "CMOV enabled              ${cmov-no}"
1807
    echo "CMOV is fast              ${fast_cmov-no}"
1808
fi
1809
if test $arch = "armv4l"; then
1810
    echo "ARMv5TE enabled           ${armv5te-no}"
1811
    echo "ARMv6 enabled             ${armv6-no}"
1812
    echo "IWMMXT enabled            ${iwmmxt-no}"
1813
fi
1814
if test $arch = "mips"; then
1815
    echo "MMI enabled               ${mmi-no}"
1816
fi
1817
if test $arch = "powerpc"; then
1818
    echo "AltiVec enabled           ${altivec-no}"
1819
    echo "dcbzl available           ${dcbzl-no}"
1820
fi
1821
echo "gprof enabled             ${gprof-no}"
1822
echo "debug symbols             ${debug-no}"
1823
echo "strip symbols             ${dostrip-no}"
1824
echo "optimize                  ${optimize-no}"
1825
echo "static                    ${static-no}"
1826
echo "shared                    ${shared-no}"
1827
echo "postprocessing support    ${pp-no}"
1828
echo "software scaler enabled   ${swscaler-no}"
1829
echo "video hooking             ${vhook-no}"
1830
if enabled vhook; then
1831
    echo "Imlib2 support            ${imlib2-no}"
1832
    echo "FreeType support          ${freetype2-no}"
1833
fi
1834
echo "network support           ${network-no}"
1835
if enabled network; then
1836
    echo "IPv6 support              ${ipv6-no}"
1837
fi
1838
echo "threading support         ${thread_type-no}"
1839
echo "SDL support               ${sdl-no}"
1840
if enabled sdl_too_old; then
1841
    echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
1842
fi
1843
echo "Sun medialib support      ${mlib-no}"
1844
echo "AVISynth enabled          ${avisynth-no}"
1845
echo "liba52 support            ${liba52-no}"
1846
echo "liba52 dlopened           ${liba52bin-no}"
1847
echo "libamr-nb support         ${libamr_nb-no}"
1848
echo "libamr-wb support         ${libamr_wb-no}"
1849
echo "libfaac enabled           ${libfaac-no}"
1850
echo "libfaad enabled           ${libfaad-no}"
1851
echo "libfaad dlopened          ${libfaadbin-no}"
1852
echo "libgsm enabled            ${libgsm-no}"
1853
echo "libmp3lame enabled        ${libmp3lame-no}"
1854
echo "libnut enabled            ${libnut-no}"
1855
echo "libogg enabled            ${libogg-no}"
1856
echo "libtheora enabled         ${libtheora-no}"
1857
echo "libvorbis enabled         ${libvorbis-no}"
1858
echo "x264 enabled              ${libx264-no}"
1859
echo "XviD enabled              ${libxvid-no}"
1860
echo "zlib enabled              ${zlib-no}"
1861
if disabled gpl; then
1862
    echo "License: LGPL"
1863
else
1864
    echo "License: GPL"
1865
fi
1866

    
1867
echo "Creating config.mak and config.h..."
1868

    
1869
echo "# Automatically generated by configure - do not modify!" > config.mak
1870
echo "/* Automatically generated by configure - do not modify! */" > $TMPH
1871
echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH
1872

    
1873
echo "PREFIX=$PREFIX" >> config.mak
1874
echo "prefix=\$(DESTDIR)\$(PREFIX)" >> config.mak
1875
echo "LIBDIR=\$(DESTDIR)$libdir" >> config.mak
1876
echo "SHLIBDIR=\$(DESTDIR)$shlibdir" >> config.mak
1877
echo "INCDIR=\$(DESTDIR)$incdir" >> config.mak
1878
echo "BINDIR=\$(DESTDIR)$bindir" >> config.mak
1879
echo "MANDIR=\$(DESTDIR)$mandir" >> config.mak
1880
echo "MAKE=$make" >> config.mak
1881
echo "CC=$cc" >> config.mak
1882
echo "AR=$ar" >> config.mak
1883
echo "RANLIB=$ranlib" >> config.mak
1884
if enabled dostrip; then
1885
    echo "STRIP=$strip" >> config.mak
1886
else
1887
    echo "STRIP=echo ignoring strip" >> config.mak
1888
fi
1889

    
1890
echo "OPTFLAGS=$CFLAGS" >> config.mak
1891
echo "VHOOKCFLAGS=$VHOOKCFLAGS">>config.mak
1892
echo "LDFLAGS=$LDFLAGS" >> config.mak
1893
echo "LDCONFIG=$LDCONFIG" >> config.mak
1894
echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
1895
echo "SHFLAGS=$SHFLAGS" >> config.mak
1896
echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak
1897
echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak
1898
echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
1899
echo "BUILD_STATIC=$static" >> config.mak
1900
echo "BUILDSUF=$BUILDSUF" >> config.mak
1901
echo "LIBPREF=$LIBPREF" >> config.mak
1902
echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak
1903
if enabled static; then
1904
  echo "LIB=$LIB" >> config.mak
1905
else # Some Make complain if this variable does not exist.
1906
  echo "LIB=" >> config.mak
1907
fi
1908
echo "SLIBPREF=$SLIBPREF" >> config.mak
1909
echo "SLIBSUF=\${BUILDSUF}$SLIBSUF" >> config.mak
1910
echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak
1911

    
1912
if enabled bigendian; then
1913
  echo "WORDS_BIGENDIAN=yes" >> config.mak
1914
  echo "#define WORDS_BIGENDIAN 1" >> $TMPH
1915
fi
1916
if enabled mmx; then
1917
  echo "#define __CPU__ 586" >> $TMPH
1918
fi
1919

    
1920
if enabled sdl; then
1921
  echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak
1922
  echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak
1923
fi
1924
if enabled texi2html; then
1925
  echo "BUILD_DOC=yes" >> config.mak
1926
fi
1927

    
1928
sws_version=`grep '#define LIBSWSCALE_VERSION ' "$source_path/libswscale/swscale.h" | sed 's/[^0-9\.]//g'`
1929
pp_version=`grep '#define LIBPOSTPROC_VERSION ' "$source_path/libpostproc/postprocess.h" | sed 's/[^0-9\.]//g'`
1930
lavc_version=`grep '#define LIBAVCODEC_VERSION ' "$source_path/libavcodec/avcodec.h" | sed 's/[^0-9\.]//g'`
1931
lavf_version=`grep '#define LIBAVFORMAT_VERSION ' "$source_path/libavformat/avformat.h" | sed 's/[^0-9\.]//g'`
1932
lavu_version=`grep '#define LIBAVUTIL_VERSION ' "$source_path/libavutil/avutil.h" | sed 's/[^0-9\.]//g'`
1933

    
1934

    
1935

    
1936
if enabled shared; then
1937
  echo "BUILD_SHARED=yes" >> config.mak
1938
  echo "PIC=-fPIC -DPIC" >> config.mak
1939
  echo "SPPMAJOR=${pp_version%%.*}" >> config.mak
1940
  echo "SPPVERSION=$pp_version" >> config.mak
1941
  echo "LAVCMAJOR=${lavc_version%%.*}" >> config.mak
1942
  echo "LAVCVERSION=$lavc_version" >> config.mak
1943
  echo "LAVFMAJOR=${lavf_version%%.*}" >> config.mak
1944
  echo "LAVFVERSION=$lavf_version" >> config.mak
1945
  echo "LAVUMAJOR=${lavu_version%%.*}" >> config.mak
1946
  echo "LAVUVERSION=$lavu_version" >> config.mak
1947
  echo "SWSMAJOR=${sws_version%%.*}" >> config.mak
1948
  echo "SWSVERSION=$sws_version" >> config.mak
1949
  echo "SLIBNAME=${SLIBNAME}" >> config.mak
1950
  echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak
1951
  echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak
1952
  echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak
1953
  echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak
1954
fi
1955
echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
1956
echo "EXTRALIBS=$extralibs" >> config.mak
1957

    
1958
print_config ARCH_   $TMPH config.mak $ARCH_LIST
1959
print_config HAVE_   $TMPH config.mak $HAVE_LIST
1960
print_config CONFIG_ $TMPH config.mak $CONFIG_LIST   \
1961
                                      $DECODER_LIST  \
1962
                                      $ENCODER_LIST  \
1963
                                      $PARSER_LIST   \
1964
                                      $BSF_LIST      \
1965
                                      $DEMUXER_LIST  \
1966
                                      $MUXER_LIST    \
1967
                                      $PROTOCOL_LIST \
1968

    
1969
if test "$targetos" = darwin; then
1970
  echo "#define CONFIG_DARWIN 1"  >> $TMPH
1971
fi
1972

    
1973
echo "#define restrict $_restrict" >> $TMPH
1974

    
1975
if enabled small; then
1976
  echo "#define always_inline"  >> $TMPH
1977
fi
1978

    
1979
echo "SRC_PATH=\"$source_path\"" >> config.mak
1980
echo "SRC_PATH_BARE=$source_path" >> config.mak
1981
echo "BUILD_ROOT=\"$PWD\"" >> config.mak
1982

    
1983
# Apparently it's not possible to portably echo a backslash.
1984
if enabled asmalign_pot; then
1985
  printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH
1986
else
1987
  printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH
1988
fi
1989

    
1990

    
1991
# Do not overwrite config.h if unchanged to avoid superfluous rebuilds.
1992
if ! cmp -s $TMPH config.h; then
1993
        mv -f $TMPH config.h
1994
else
1995
        echo "config.h is unchanged"
1996
fi
1997

    
1998
rm -f $TMPO $TMPC $TMPE $TMPS $TMPH
1999

    
2000
# build tree in object directory if source path is different from current one
2001
if enabled source_path_used; then
2002
    DIRS="\
2003
         doc \
2004
         libavformat \
2005
         libavcodec \
2006
         libavcodec/alpha \
2007
         libavcodec/armv4l \
2008
         libavcodec/bfin \
2009
         libavcodec/i386 \
2010
         libavcodec/sparc \
2011
         libavcodec/mlib \
2012
         libavcodec/ppc \
2013
         libpostproc \
2014
         libavutil \
2015
         libswscale \
2016
         tests \
2017
         tools \
2018
         vhook \
2019
         "
2020
    FILES="\
2021
          Makefile \
2022
          common.mak \
2023
          libavformat/Makefile \
2024
          libavcodec/Makefile \
2025
          libpostproc/Makefile \
2026
          libavutil/Makefile \
2027
          libswscale/Makefile \
2028
          doc/texi2pod.pl \
2029
          "
2030
    for dir in $DIRS ; do
2031
            mkdir -p $dir
2032
    done
2033
    for f in $FILES ; do
2034
        ln -sf "$source_path/$f" $f
2035
    done
2036
fi
2037

    
2038

    
2039
# build pkg-config files
2040
# FIXME: libdir and includedir are hardcoded and may differ from the real path.
2041

    
2042
pkgconfig_generate(){
2043
name=$1
2044
comment=$2
2045
version=$3
2046
libs=$4
2047
requires=$5
2048
include=$6
2049
cat <<EOF >$name.pc
2050
prefix=$PREFIX
2051
exec_prefix=\${prefix}
2052
libdir=\${exec_prefix}/lib
2053
includedir=\${prefix}/include
2054

    
2055
Name: $name
2056
Description: $comment
2057
Version: $version
2058
Requires: $requires
2059
Conflicts:
2060
Libs: -L\${libdir} $libs
2061
Cflags: -I\${includedir} -I\${includedir}/$include
2062
EOF
2063
}
2064

    
2065
pkgconfig_generate_uninstalled(){
2066
name=$1
2067
shortname=${name#lib}
2068
comment=$2
2069
version=$3
2070
libs=$4
2071
requires=$5
2072
cat <<EOF >$name-uninstalled.pc
2073
prefix=
2074
exec_prefix=
2075
libdir=\${pcfiledir}/$name
2076
includedir=\${pcfiledir}/$name
2077

    
2078
Name: $name
2079
Description: $comment
2080
Version: $version
2081
Requires: $requires
2082
Conflicts:
2083
Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
2084
Cflags: -I\${includedir}
2085
EOF
2086
}
2087

    
2088
pkgconfig_generate libavutil "FFmpeg utility library" "$lavu_version" -lavutil "" ffmpeg
2089
pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$lavu_version"
2090

    
2091
pkgconfig_generate libavcodec "FFmpeg codec library" "$lavc_version" "-lavcodec $extralibs" "$pkg_requires libavutil = $lavu_version" ffmpeg
2092
pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$lavc_version" "$extralibs" "$pkg_requires libavutil = $lavu_version"
2093

    
2094
pkgconfig_generate libavformat "FFmpeg container format library" "$lavf_version" "-lavformat $extralibs" "$pkg_requires libavcodec = $lavc_version" ffmpeg
2095
pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$lavf_version" "$extralibs" "$pkg_requires libavcodec = $lavc_version"
2096

    
2097
if enabled pp; then
2098
  pkgconfig_generate libpostproc "FFmpeg post processing library" "$pp_version" -lpostproc "" postproc
2099
  pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$pp_version"
2100
fi
2101

    
2102
if enabled swscaler; then
2103
  pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" -lswscale "libavutil = $lavu_version" ffmpeg
2104
  pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "libavutil = $lavu_version"
2105
else
2106
  pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" ffmpeg
2107
  pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version"
2108
  apply libswscale.pc sed s/^Libs:.*$/Libs:/
2109
  apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/
2110
fi