Statistics
| Branch: | Revision:

ffmpeg / configure @ 35f97369

History | View | Annotate | Download (56.4 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-mingw32         enable MinGW native/cross Windows compile"
66
  echo "  --enable-mingwce         enable MinGW native/cross WinCE compile"
67
  echo "  --enable-static          build static libraries [default=yes]"
68
  echo "  --disable-static         do not build static libraries [default=no]"
69
  echo "  --enable-shared          build shared libraries [default=no]"
70
  echo "  --disable-shared         do not build shared libraries [default=yes]"
71
  echo "  --enable-pp              enable GPLed postprocessing support [default=no]"
72
  echo "  --enable-swscaler        software scaler support [default=no]"
73
  echo "  --enable-sunmlib         use Sun medialib [default=no]"
74
  echo "  --enable-beosthreads     use BeOS threads [default=no]"
75
  echo "  --enable-os2threads      use OS/2 threads [default=no]"
76
  echo "  --enable-pthreads        use pthreads [default=no]"
77
  echo "  --enable-w32threads      use Win32 threads [default=no]"
78
  echo "  --enable-x11grab         enable X11 grabbing [default=no]"
79
  echo "  --enable-dc1394          enable IIDC-1394 grabbing using libdc1394"
80
  echo "                           and libraw1394 [default=no]"
81
  echo "  --enable-liba52          enable GPLed liba52 support [default=no]"
82
  echo "  --enable-liba52bin       open liba52.so.0 at runtime [default=no]"
83
  echo "  --enable-avisynth        allow reading AVISynth script files [default=no]"
84
  echo "  --enable-libdts          enable GPLed libdts support [default=no]"
85
  echo "  --enable-libfaac         enable FAAC support via libfaac [default=no]"
86
  echo "  --enable-libfaad         enable FAAD support via libfaad [default=no]"
87
  echo "  --enable-libfaadbin      build FAAD support with runtime linking [default=no]"
88
  echo "  --enable-libgsm          enable GSM support via libgsm [default=no]"
89
  echo "  --enable-libmp3lame      enable MP3 encoding via libmp3lame [default=no]"
90
  echo "  --enable-libnut          enable NUT (de)muxing via libnut,"
91
  echo "                           native demuxer exists [default=no]"
92
  echo "  --enable-libogg          enable Ogg muxing via libogg [default=no]"
93
  echo "  --enable-libtheora       enable Theora encoding via libtheora [default=no]"
94
  echo "  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,"
95
  echo "                           native implementations exist [default=no]"
96
  echo "  --enable-x264            enable H.264 encoding via x264 [default=no]"
97
  echo "  --enable-xvid            enable Xvid encoding via xvidcore,"
98
  echo "                           native MPEG-4/Xvid encoder exists [default=no]"
99
  echo "  --enable-amr_nb          enable amr_nb float audio codec"
100
  echo "  --enable-amr_nb-fixed    use fixed point for amr-nb codec"
101
  echo "  --enable-amr_wb          enable amr_wb float audio codec"
102
  echo "  --enable-amr_if2         enable amr_wb IF2 audio codec"
103
  echo "  --enable-gpl             allow use of GPL code, the resulting libav*"
104
  echo "                           and ffmpeg will be under GPL [default=no]"
105
  echo ""
106
  echo "Advanced options (experts only):"
107
  echo "  --source-path=PATH       path to source code [$source_path]"
108
  echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]"
109
  echo "  --cross-compile          assume a cross-compiler is used"
110
  echo "  --cc=CC                  use C compiler CC [$cc]"
111
  echo "  --make=MAKE              use specified make [$make]"
112
  echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
113
  echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
114
  echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
115
  echo "  --build-suffix=SUFFIX    suffix for application specific build []"
116
  echo "  --arch=ARCH              select architecture  [$arch]"
117
  echo "  --cpu=CPU                selects the minimum cpu required (affects"
118
  echo "                           instruction selection, may crash on older CPUs)"
119
  echo "  --powerpc-perf-enable    enable performance report on PPC"
120
  echo "                           (requires enabling PMC)"
121
  echo "  --disable-mmx            disable MMX usage"
122
  echo "  --disable-armv5te        disable armv5te usage"
123
  echo "  --disable-armv6          disable armv6 usage"
124
  echo "  --disable-iwmmxt         disable iwmmxt usage"
125
  echo "  --disable-altivec        disable AltiVec usage"
126
  echo "  --disable-audio-oss      disable OSS audio support [default=no]"
127
  echo "  --disable-audio-beos     disable BeOS audio support [default=no]"
128
  echo "  --disable-v4l            disable video4linux grabbing [default=no]"
129
  echo "  --disable-v4l2           disable video4linux2 grabbing [default=no]"
130
  echo "  --disable-bktr           disable bktr video grabbing [default=no]"
131
  echo "  --disable-dv1394         disable DV1394 grabbing [default=no]"
132
  echo "  --disable-network        disable network support [default=no]"
133
  echo "  --disable-ipv6           disable ipv6 support [default=no]"
134
  echo "  --disable-zlib           disable zlib [default=no]"
135
  echo "  --disable-vhook          disable video hooking support"
136
  echo "  --enable-gprof           enable profiling with gprof [$gprof]"
137
  echo "  --disable-debug          disable debugging symbols"
138
  echo "  --disable-opts           disable compiler optimizations"
139
  echo "  --enable-extra-warnings  enable more compiler warnings"
140
  echo "  --disable-mpegaudio-hp   faster (but less accurate)"
141
  echo "                           MPEG audio decoding [default=no]"
142
  echo "  --disable-protocols      disable I/O protocols support [default=no]"
143
  echo "  --disable-ffmpeg         disable ffmpeg build"
144
  echo "  --disable-ffserver       disable ffserver build"
145
  echo "  --disable-ffplay         disable ffplay build"
146
  echo "  --enable-small           optimize for size instead of speed"
147
  echo "  --enable-memalign-hack   emulate memalign, interferes with memory debuggers"
148
  echo "  --disable-strip          disable stripping of executables and shared libraries"
149
  echo "  --disable-encoder=NAME   disables encoder NAME"
150
  echo "  --enable-encoder=NAME    enables encoder NAME"
151
  echo "  --disable-decoder=NAME   disables decoder NAME"
152
  echo "  --enable-decoder=NAME    enables decoder NAME"
153
  echo "  --disable-encoders       disables all encoders"
154
  echo "  --disable-decoders       disables all decoders"
155
  echo "  --disable-muxer=NAME     disables muxer NAME"
156
  echo "  --enable-muxer=NAME      enables muxer NAME"
157
  echo "  --disable-muxers         disables all muxers"
158
  echo "  --disable-demuxer=NAME   disables demuxer NAME"
159
  echo "  --enable-demuxer=NAME    enables demuxer NAME"
160
  echo "  --disable-demuxers       disables all demuxers"
161
  echo "  --enable-parser=NAME     enables parser NAME"
162
  echo "  --disable-parser=NAME    disables parser NAME"
163
  echo "  --disable-parsers        disables all parsers"
164
  echo ""
165
  echo "NOTE: Object files are built at the place where configure is launched."
166
  exit 1
167
}
168

    
169
log(){
170
    echo "$@" >>$logfile
171
}
172

    
173
log_file(){
174
    log BEGIN $1
175
    cat -n $1 >>$logfile
176
    log END $1
177
}
178

    
179
echolog(){
180
    log "$@"
181
    echo "$@"
182
}
183

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

    
206
# "tr '[a-z]' '[A-Z]'" is a workaround for Solaris tr not grokking "tr a-z A-Z"
207
toupper(){
208
    echo "$@" | tr '[a-z]' '[A-Z]'
209
}
210

    
211
set_all(){
212
    value=$1
213
    shift
214
    for var in $*; do
215
        eval $var=$value
216
    done
217
}
218

    
219
pushvar(){
220
    for var in $*; do
221
        eval level=\${${var}_level:=0}
222
        eval ${var}_${level}="\$$var"
223
        eval ${var}_level=$(($level+1))
224
    done
225
}
226

    
227
popvar(){
228
    for var in $*; do
229
        eval level=\${${var}_level:-0}
230
        test $level = 0 && continue
231
        eval level=$(($level-1))
232
        eval $var="\${${var}_${level}}"
233
        eval ${var}_level=$level
234
        eval unset ${var}_${level}
235
    done
236
}
237

    
238
enable(){
239
    set_all yes $*
240
}
241

    
242
disable(){
243
    set_all no $*
244
}
245

    
246
enabled(){
247
    eval test "x\$$1" = "xyes"
248
}
249

    
250
disabled(){
251
    eval test "x\$$1" = "xno"
252
}
253

    
254
enabled_all(){
255
    for opt; do
256
        enabled $opt || return 1
257
    done
258
}
259

    
260
disabled_all(){
261
    for opt; do
262
        disabled $opt || return 1
263
    done
264
}
265

    
266
enabled_any(){
267
    for opt; do
268
        enabled $opt && return 0
269
    done
270
}
271

    
272
disabled_any(){
273
    for opt; do
274
        disabled $opt && return 0
275
    done
276
}
277

    
278
check_deps(){
279
    for cfg; do
280
        enabled ${cfg}_checking && die "Circular dependency for $cfg."
281
        disabled ${cfg}_checking && continue
282
        enable ${cfg}_checking
283

    
284
        eval dep_all="\$${cfg}_deps"
285
        eval dep_any="\$${cfg}_deps_any"
286

    
287
        pushvar cfg dep_all dep_any
288
        check_deps $dep_all $dep_any
289
        popvar cfg dep_all dep_any
290

    
291
        enabled_all $dep_all || disable $cfg
292
        enabled_any $dep_any || disable $cfg
293

    
294
        disable ${cfg}_checking
295
    done
296
}
297

    
298
print_config(){
299
    pfx=$1
300
    header=$2
301
    makefile=$3
302
    shift 3
303
    for cfg; do
304
        if enabled $cfg; then
305
            ucname="${pfx}`toupper $cfg`"
306
            echo "#define ${ucname} 1" >> $header
307
            echo "${ucname}=yes" >> $makefile
308
        fi
309
    done
310
}
311

    
312
flags_saved(){
313
    (: ${SAVE_CFLAGS?}) 2>/dev/null
314
}
315

    
316
save_flags(){
317
    flags_saved && return
318
    SAVE_CFLAGS="$CFLAGS"
319
    SAVE_LDFLAGS="$LDFLAGS"
320
    SAVE_extralibs="$extralibs"
321
}
322

    
323
restore_flags(){
324
    flags_saved || return
325
    CFLAGS="$SAVE_CFLAGS"
326
    LDFLAGS="$SAVE_LDFLAGS"
327
    extralibs="$SAVE_extralibs"
328
    unset SAVE_CFLAGS
329
    unset SAVE_LDFLAGS
330
    unset SAVE_extralibs
331
}
332

    
333
temp_cflags(){
334
    save_flags
335
    CFLAGS="$CFLAGS $*"
336
}
337

    
338
temp_ldflags(){
339
    save_flags
340
    LDFLAGS="$LDFLAGS $*"
341
}
342

    
343
temp_extralibs(){
344
    save_flags
345
    extralibs="$extralibs $*"
346
}
347

    
348
append(){
349
    var=$1
350
    shift
351
    flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
352
    eval "$var=\"\$$var $*\""
353
}
354

    
355
add_cflags(){
356
    append CFLAGS "$@"
357
}
358

    
359
add_ldflags(){
360
    append LDFLAGS "$@"
361
}
362

    
363
add_extralibs(){
364
    append extralibs "$@"
365
}
366

    
367
check_cmd(){
368
    log "$@"
369
    "$@" >>$logfile 2>&1
370
}
371

    
372
check_cc(){
373
    log check_cc "$@"
374
    cat >$TMPC
375
    log_file $TMPC
376
    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
377
}
378

    
379
check_cpp(){
380
    log check_cpp "$@"
381
    cat >$TMPC
382
    log_file $TMPC
383
    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
384
}
385

    
386
check_ld(){
387
    log check_ld "$@"
388
    check_cc || return
389
    check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs
390
}
391

    
392
check_cflags(){
393
    log check_cflags "$@"
394
    check_cc "$@" <<EOF && add_cflags "$@"
395
int x;
396
EOF
397
}
398

    
399
check_ldflags(){
400
    log check_ldflags "$@"
401
    check_ld "$@" <<EOF && add_ldflags "$@"
402
int main(){
403
    return 0;
404
}
405
EOF
406
}
407

    
408
check_header(){
409
    log check_header "$@"
410
    header=$1
411
    shift
412
    check_cpp "$@" <<EOF
413
#include <$header>
414
int x;
415
EOF
416
    err=$?
417
    var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
418
    test "$err" = 0 && enable $var || disable $var
419
    return $err
420
}
421

    
422
check_func(){
423
    log check_func "$@"
424
    func=$1
425
    shift
426
    check_ld "$@" <<EOF
427
extern int $func();
428
int main(){
429
    $func();
430
}
431
EOF
432
    err=$?
433
    test "$err" = 0 && enable $func || disable $func
434
    return $err
435
}
436

    
437
check_lib(){
438
    log check_lib "$@"
439
    header="$1"
440
    func="$2"
441
    shift 2
442
    temp_extralibs "$@"
443
    check_header $header && check_func $func && add_extralibs "$@"
444
    err=$?
445
    restore_flags
446
    return $err
447
}
448

    
449
check_exec(){
450
    check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; }
451
}
452

    
453
require(){
454
    name="$1"
455
    header="$2"
456
    func="$3"
457
    shift 3
458
    check_lib $header $func "$@" || die "ERROR: $name not found"
459
}
460

    
461
apply(){
462
    file=$1
463
    shift
464
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
465
}
466

    
467
CONFIG_LIST='
468
    encoders
469
    decoders
470
    parsers
471
    muxers
472
    demuxers
473
    amr
474
    amr_nb
475
    amr_nb_fixed
476
    amr_wb
477
    audio_beos
478
    audio_oss
479
    avisynth
480
    beos_netserver
481
    bktr
482
    dc1394
483
    dv1394
484
    ffmpeg
485
    ffplay
486
    ffserver
487
    gpl
488
    gprof
489
    ipv6
490
    liba52
491
    liba52bin
492
    libdts
493
    libfaac
494
    libfaad
495
    libfaadbin
496
    libgsm
497
    libmp3lame
498
    libnut
499
    libogg
500
    libtheora
501
    libvorbis
502
    memalign_hack
503
    mpegaudio_hp
504
    network
505
    pp
506
    protocols
507
    swscaler
508
    vhook
509
    video4linux
510
    video4linux2
511
    wince
512
    x11grab
513
    x264
514
    xvid
515
    zlib
516
'
517

    
518
HAVE_LIST='
519
    altivec
520
    altivec_h
521
    armv5te
522
    armv6
523
    beosthreads
524
    byteswap_h
525
    cmov
526
    dcbzl
527
    dev_bktr_ioctl_bt848_h
528
    dev_bktr_ioctl_meteor_h
529
    dev_ic_bt8xx_h
530
    dev_video_meteor_ioctl_meteor_h
531
    dev_video_bktr_ioctl_bt848_h
532
    dlfcn_h
533
    dlopen
534
    fast_cmov
535
    freetype2
536
    imlib2
537
    inet_aton
538
    iwmmxt
539
    localtime_r
540
    lrintf
541
    machine_ioctl_bt848_h
542
    machine_ioctl_meteor_h
543
    malloc_h
544
    memalign
545
    mlib
546
    mmi
547
    mmx
548
    os2
549
    os2threads
550
    pthreads
551
    sdl
552
    sdl_video_size
553
    soundcard_h
554
    sys_soundcard_h
555
    threads
556
    w32threads
557
'
558

    
559
TARGET_LIST='
560
    altivec
561
    armv5te
562
    armv6
563
    iwmmxt
564
    mmi
565
    mmx
566
'
567

    
568
CMDLINE_SELECT="
569
    $CONFIG_LIST
570
    $TARGET_LIST
571
    debug
572
    extra_warnings
573
    mingw32
574
    shared
575
    static
576
    beosthreads
577
    os2threads
578
    pthreads
579
    w32threads
580
"
581

    
582
flashsv_decoder_deps="zlib"
583
flashsv_encoder_deps="zlib"
584
mpeg_xvmc_decoder_deps="xvmc"
585
png_decoder_deps="zlib"
586
png_encoder_deps="zlib"
587
x264_encoder_deps="x264"
588
xvid_encoder_deps="xvid"
589
zmbv_decoder_deps="zlib"
590
zmbv_encoder_deps="zlib"
591

    
592
aac_decoder_deps="libfaad"
593
mpeg4aac_decoder_deps="libfaad"
594
amr_nb_decoder_deps_any="amr_nb amr_nb_fixed"
595
amr_nb_encoder_deps_any="amr_nb amr_nb_fixed"
596
amr_wb_decoder_deps="amr_wb"
597
amr_wb_encoder_deps="amr_wb"
598
dts_decoder_deps="libdts"
599
faac_encoder_deps="libfaac"
600
liba52_decoder_deps="liba52"
601
libgsm_decoder_deps="libgsm"
602
libgsm_encoder_deps="libgsm"
603
libtheora_encoder_deps="libtheora"
604
mp3lame_encoder_deps="libmp3lame"
605
oggvorbis_decoder_deps="libvorbis"
606
oggvorbis_encoder_deps="libvorbis"
607

    
608
audio_demuxer_deps_any="audio_oss audio_beos"
609
audio_muxer_deps_any="audio_oss audio_beos"
610
dc1394_demuxer_deps="dc1394"
611
dv1394_demuxer_deps="dv1394"
612
gxf_muxer_deps="gpl"
613
libnut_demuxer_deps="libnut"
614
libnut_muxer_deps="libnut"
615
ogg_muxer_deps="libogg"
616
redir_demuxer_deps="network"
617
rtp_muxer_deps="network"
618
rtsp_demuxer_deps="network"
619
sdp_demuxer_deps="network"
620
v4l2_demuxer_deps="video4linux2"
621
video_grab_device_demuxer_deps_any="video4linux bktr"
622
x11_grab_device_demuxer_deps="x11grab"
623

    
624
ffplay_deps="sdl"
625
ffserver_deps="network protocols muxers"
626
network_deps="protocols"
627

    
628
# set temporary file name
629
if test ! -z "$TMPDIR" ; then
630
    TMPDIR1="${TMPDIR}"
631
elif test ! -z "$TEMPDIR" ; then
632
    TMPDIR1="${TEMPDIR}"
633
else
634
    TMPDIR1="/tmp"
635
fi
636

    
637
TMPC="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
638
TMPO="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
639
TMPE="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}"
640
TMPS="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
641
TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
642

    
643
# default parameters
644

    
645
logging="yes"
646
logfile="config.err"
647

    
648
# installation paths
649
PREFIX="/usr/local"
650
libdir='${PREFIX}/lib'
651
shlibdir="$libdir"
652
incdir='${PREFIX}/include/ffmpeg'
653
mandir='${PREFIX}/man'
654
bindir='${PREFIX}/bin'
655

    
656
# toolchain
657
cross_prefix=""
658
cross_compile="no"
659
cc="gcc"
660
ar="ar"
661
ranlib="ranlib"
662
make="make"
663
strip="strip"
664
asmalign_pot="unknown"
665

    
666
# machine
667
arch=`uname -m`
668
cpu="generic"
669
powerpc_perf="no"
670
mmx="default"
671
cmov="no"
672
fast_cmov="no"
673
armv5te="default"
674
armv6="default"
675
iwmmxt="default"
676
altivec="default"
677
dcbzl="no"
678
mmi="default"
679
bigendian="no"
680

    
681
case "$arch" in
682
  i386|i486|i586|i686|i86pc|BePC)
683
    arch="x86_32"
684
  ;;
685
  x86_64|amd64)
686
    arch="x86_32"
687
    canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
688
    if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
689
      if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
690
        arch="x86_64"
691
      fi
692
    fi
693
  ;;
694
  # armv4l is a subset of armv[567]*l
695
  arm|armv[4567]*l)
696
    arch="armv4l"
697
  ;;
698
  alpha)
699
    arch="alpha"
700
  ;;
701
  "Power Macintosh"|ppc|ppc64|powerpc)
702
    arch="powerpc"
703
  ;;
704
  mips|mipsel|IP*)
705
    arch="mips"
706
  ;;
707
  sun4u|sparc64)
708
    arch="sparc64"
709
  ;;
710
  sparc)
711
    arch="sparc"
712
  ;;
713
  sh4)
714
    arch="sh4"
715
  ;;
716
  parisc|parisc64)
717
    arch="parisc"
718
  ;;
719
  s390|s390x)
720
    arch="s390"
721
  ;;
722
  m68k)
723
    arch="m68k"
724
  ;;
725
  ia64)
726
    arch="ia64"
727
  ;;
728
  bfin)
729
    arch="bfin"
730
  ;;
731
  *)
732
    arch="unknown"
733
  ;;
734
esac
735

    
736
# OS
737
beos_netserver="no"
738
mingw32="no"
739
os2="no"
740
wince="no"
741

    
742
# non-library system interfaces
743
audio_beos="no"
744
audio_oss="yes"
745
bktr="yes"
746
dv1394="yes"
747
video4linux2="yes"
748
video4linux="yes"
749

    
750
# libraries
751
amr_if2="no"
752
amr_nb="no"
753
amr_nb_fixed="no"
754
amr_wb="no"
755
avisynth="no"
756
dc1394="no"
757
dlfcn_h="no"
758
dlopen="no"
759
liba52="no"
760
liba52bin="no"
761
libdts="no"
762
libfaac="no"
763
libfaad2="no"
764
libfaad="no"
765
libfaadbin="no"
766
libgsm="no"
767
libmp3lame="no"
768
libnut="no"
769
libogg="no"
770
libtheora="no"
771
libvorbis="no"
772
mlib="no"
773
x11grab="no"
774
x264="no"
775
xvid="no"
776
zlib="yes"
777

    
778
# configurable options
779
debug="yes"
780
dostrip="yes"
781
extra_warnings="no"
782
ffmpeg="yes"
783
ffplay="yes"
784
ffserver="yes"
785
gpl="no"
786
gprof="no"
787
ipv6="yes"
788
shared="no"
789
static="yes"
790
memalign_hack="no"
791
mpegaudio_hp="yes"
792
network="yes"
793
optimize="yes"
794
pp="no"
795
protocols="yes"
796
swscaler="no"
797
vhook="default"
798

    
799
# threading
800
beosthreads="no"
801
os2threads="no"
802
pthreads="no"
803
w32threads="no"
804
thread_type="no"
805

    
806
# build settings
807
extralibs="-lm"
808
SHFLAGS='-shared -Wl,-soname,$@'
809
VHOOKSHFLAGS='$(SHFLAGS)'
810
LIBOBJFLAGS=""
811
FFLDFLAGS=-Wl,--warn-common
812
LDLATEFLAGS='-Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil'
813
FFSERVERLDFLAGS=-Wl,-E
814
LDCONFIG="ldconfig"
815
LIBPREF="lib"
816
LIBSUF=".a"
817
LIB='$(LIBPREF)$(NAME)$(LIBSUF)'
818
SLIBPREF="lib"
819
SLIBSUF=".so"
820
SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF)'
821
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
822
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
823
EXESUF=""
824
BUILDSUF=""
825
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"'
826

    
827
# OS specific
828
targetos=`uname -s`
829
case $targetos in
830
  BeOS|Haiku|Zeta)
831
    PREFIX="$HOME/config"
832
    # helps building libavcodec
833
    add_cflags "-DPIC -fomit-frame-pointer"
834
    # 3 gcc releases known for BeOS, each with ugly bugs
835
    gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
836
    case "$gcc_version" in
837
      2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
838
        mmx="no"
839
        ;;
840
      *20010315*) echo "BeBits gcc"
841
        add_cflags "-fno-expensive-optimizations"
842
        ;;
843
    esac
844
    LDCONFIG="echo ignoring ldconfig"
845
    SHFLAGS=-nostart
846
    # disable Linux things
847
    dv1394="no"
848
    # enable BeOS things
849
    audio_beos="yes"
850
    # no need for libm, but the inet stuff
851
    # Check for BONE
852
    # XXX: actually should check for NOT net_server
853
    if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then
854
        extralibs="-lbind -lsocket"
855
    else
856
        beos_netserver="yes"
857
        extralibs="-lnet"
858
    fi ;;
859
  SunOS)
860
    dv1394="no"
861
    FFLDFLAGS=""
862
    FFSERVERLDFLAGS=""
863
    SHFLAGS="-shared -Wl,-h,\$@"
864
    add_extralibs "-lsocket -lnsl"
865
    ;;
866
  NetBSD)
867
    dv1394="no"
868
    add_extralibs "-lossaudio"
869
    ;;
870
  OpenBSD)
871
    dv1394="no"
872
    need_memalign="no"
873
    LIBOBJFLAGS="\$(PIC)"
874
    LDCONFIG="ldconfig -m \$(shlibdir)"
875
    SHFLAGS='-shared'
876
    SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF).$(LIBVERSION)'
877
    SLIBNAME_WITH_VERSION='$(SLIBNAME)'
878
    SLIBNAME_WITH_MAJOR='$(SLIBNAME)'
879
    add_extralibs "-lossaudio"
880
    ;;
881
  FreeBSD)
882
    dv1394="no"
883
    need_memalign="no"
884
    add_cflags "-pthread"
885
    ;;
886
  GNU/kFreeBSD)
887
    dv1394="no"
888
    add_cflags "-pthread"
889
    ;;
890
  BSD/OS)
891
    dv1394="no"
892
    extralibs="-lpoll -lgnugetopt -lm"
893
    strip="strip -d"
894
    ;;
895
  Darwin)
896
    cc="cc"
897
    dv1394="no"
898
    need_memalign="no"
899
    SHFLAGS="-dynamiclib -Wl,-single_module -Wl,-install_name,\$(shlibdir)/\$(SLIBNAME),-current_version,\$(SPPVERSION),-compatibility_version,\$(SPPVERSION) -Wl,-read_only_relocs,suppress"
900
    VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(shlibdir)/vhook/$@'
901
    extralibs=""
902
    strip="strip -x"
903
    FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
904
    SLIBSUF=".dylib"
905
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
906
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
907
    FFSERVERLDFLAGS=-Wl,-bind_at_load
908
    ;;
909
  MINGW32*)
910
    # Note: the rest of the mingw32 config is done afterwards as mingw32
911
    # can be forced on the command line for Linux cross compilation.
912
    mingw32="yes"
913
    ;;
914
  CYGWIN*)
915
    targetos=CYGWIN
916
    shlibdir="$bindir"
917
    dv1394="no"
918
    VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil'
919
    VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
920
    extralibs=""
921
    EXESUF=".exe"
922
    SLIBPREF="cyg"
923
    SLIBSUF=".dll"
924
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
925
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
926
    SHFLAGS='-shared -Wl,--out-implib=lib$(NAME).dll.a'
927
    ;;
928
  Linux)
929
    LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS"
930
    ;;
931
  IRIX*)
932
    targetos=IRIX
933
    ranlib="echo ignoring ranlib"
934
    ;;
935
  OS/2)
936
    TMPE=$TMPE".exe"
937
    ar="emxomfar -p128"
938
    ranlib="echo ignoring ranlib"
939
    strip="echo ignoring strip"
940
    add_cflags "-Zomf"
941
    FFLDFLAGS="-Zomf -Zstack 16384 -s"
942
    SHFLAGS="-Zdll -Zomf"
943
    FFSERVERLDFLAGS=""
944
    LIBPREF=""
945
    LIBSUF=".lib"
946
    SLIBPREF=""
947
    SLIBSUF=".dll"
948
    EXESUF=".exe"
949
    extralibs=""
950
    pkg_requires=""
951
    dv1394="no"
952
    ffserver="no"
953
    vhook="no"
954
    os2="yes"
955
    ;;
956
  *)
957
    targetos="${targetos}-UNKNOWN"
958
    ;;
959
esac
960

    
961
# find source path
962
source_path="`dirname \"$0\"`"
963
source_path_used="yes"
964
if test -z "$source_path" -o "$source_path" = "." ; then
965
    source_path="`pwd`"
966
    source_path_used="no"
967
else
968
    source_path="`cd \"$source_path\"; pwd`"
969
    echo "$source_path" | grep -q '[[:blank:]]' &&
970
      die "Out of tree builds are impossible with whitespace in source path."
971
fi
972

    
973
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
974
    show_help
975
fi
976

    
977
FFMPEG_CONFIGURATION="$@"
978

    
979
ENCODER_LIST=`sed -n 's/^[^#]*ENC.*, *\(.*\)).*/\1_encoder/p' "$source_path/libavcodec/allcodecs.c"`
980
DECODER_LIST=`sed -n 's/^[^#]*DEC.*, *\(.*\)).*/\1_decoder/p' "$source_path/libavcodec/allcodecs.c"`
981
PARSER_LIST=`sed -n 's/^[^#]*PARSER.*, *\(.*\)).*/\1_parser/p' "$source_path/libavcodec/allcodecs.c"`
982
MUXER_LIST=`sed -n 's/^[^#]*_MUX.*, *\(.*\)).*/\1_muxer/p' "$source_path/libavformat/allformats.c"`
983
DEMUXER_LIST=`sed -n 's/^[^#]*DEMUX.*, *\(.*\)).*/\1_demuxer/p' "$source_path/libavformat/allformats.c"`
984

    
985
enable $ENCODER_LIST $DECODER_LIST $PARSER_LIST $MUXER_LIST $DEMUXER_LIST
986

    
987
die_unknown(){
988
    echo "Unknown option \"$1\"."
989
    echo "See $0 --help for available options."
990
    exit 1
991
}
992

    
993
for opt do
994
  optval="${opt#*=}"
995
  case "$opt" in
996
  --log)
997
  ;;
998
  --log=*) logging="$optval"
999
  ;;
1000
  --prefix=*) PREFIX="$optval"
1001
  ;;
1002
  --libdir=*) libdir="$optval"
1003
  ;;
1004
  --shlibdir=*) shlibdir="$optval"
1005
  ;;
1006
  --incdir=*) incdir="$optval"
1007
  ;;
1008
  --mandir=*) mandir="$optval"
1009
  ;;
1010
  --source-path=*) source_path="$optval"
1011
  ;;
1012
  --cross-prefix=*) cross_prefix="$optval"
1013
  ;;
1014
  --cross-compile) cross_compile="yes"
1015
  ;;
1016
  --cc=*) cc="$optval"
1017
  ;;
1018
  --make=*) make="$optval"
1019
  ;;
1020
  --extra-cflags=*) add_cflags "$optval"
1021
  ;;
1022
  --extra-ldflags=*) add_ldflags "$optval"
1023
  ;;
1024
  --extra-libs=*) add_extralibs "$optval"
1025
  ;;
1026
  --build-suffix=*) BUILDSUF="$optval"
1027
  ;;
1028
  --arch=*) arch="$optval"
1029
  ;;
1030
  --cpu=*) cpu="$optval"
1031
  ;;
1032
  --powerpc-perf-enable) powerpc_perf="yes"
1033
  ;;
1034
  --disable-v4l) video4linux="no"
1035
  ;;
1036
  --disable-v4l2) video4linux2="no"
1037
  ;;
1038
  --enable-mingwce) wince="yes"
1039
  ;;
1040
  --disable-opts) optimize="no"
1041
  ;;
1042
  --enable-small) optimize="small"
1043
  ;;
1044
  --enable-sunmlib) mlib="yes"
1045
  ;;
1046
  --disable-strip) dostrip="no"
1047
  ;;
1048
  --enable-encoder=*) enable ${optval}_encoder
1049
  ;;
1050
  --enable-decoder=*) enable ${optval}_decoder
1051
  ;;
1052
  --disable-encoder=*) disable ${optval}_encoder
1053
  ;;
1054
  --disable-decoder=*) disable ${optval}_decoder
1055
  ;;
1056
  --disable-encoders) disable $ENCODER_LIST
1057
  ;;
1058
  --disable-decoders) disable $DECODER_LIST
1059
  ;;
1060
  --enable-muxer=*) enable ${optval}_muxer
1061
  ;;
1062
  --disable-muxer=*) disable ${optval}_muxer
1063
  ;;
1064
  --disable-muxers) disable $MUXER_LIST
1065
  ;;
1066
  --enable-demuxer=*) enable ${optval}_demuxer
1067
  ;;
1068
  --disable-demuxer=*) disable ${optval}_demuxer
1069
  ;;
1070
  --disable-demuxers) disable $DEMUXER_LIST
1071
  ;;
1072
  --enable-parser=*) enable ${optval}_parser
1073
  ;;
1074
  --disable-parser=*) disable ${optval}_parser
1075
  ;;
1076
  --disable-parsers) disable $PARSER_LIST
1077
  ;;
1078
  --enable-?*|--disable-?*)
1079
  eval `echo "${opt#-}" | sed 's/-/action=/;s/-/ option=/;s/-/_/g'`
1080
  echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt
1081
  $action $option
1082
  ;;
1083
  --help) show_help
1084
  ;;
1085
  *)
1086
  die_unknown $opt
1087
  ;;
1088
  esac
1089
done
1090

    
1091
if ! disabled logging ; then
1092
    enabled logging || logfile="$logging"
1093
    echo "# $0 $@" >$logfile
1094
    set >>$logfile
1095
else
1096
    logfile=/dev/null
1097
fi
1098

    
1099
if enabled_any mingw32 wince; then
1100
    if enabled_all shared static; then
1101
        cat <<EOF
1102
You can only build one library type at once on MinGW.
1103
Specify --disable-static --enable-shared to only build
1104
the shared libraries. To build only the static libraries
1105
you do not need to pass additional options.
1106
EOF
1107
        exit 1
1108
    fi
1109
    dv1394="no"
1110
    dc1394="no"
1111
    ffserver="no"
1112
    network="no"
1113
    if enabled wince; then
1114
        protocols="no"
1115
    fi
1116
    SLIBPREF=""
1117
    SLIBSUF=".dll"
1118
    EXESUF=".exe"
1119
    SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
1120
    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
1121
    SLIB_EXTRA_CMD="-lib /machine:i386 /def:\$(@:${SLIBSUF}=.def)"
1122
    SLIB_INSTALL_EXTRA_CMD="-install -m 644 \$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib) \"\$(shlibdir)/\$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib)\""
1123
    SHFLAGS="-shared -Wl,--output-def,\$(@:${SLIBSUF}=.def),--out-implib,lib\$(SLIBNAME:\$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc"
1124
fi
1125

    
1126
# Combine FFLDFLAGS and the LDFLAGS environment variable.
1127
LDFLAGS="$FFLDFLAGS $LDFLAGS"
1128

    
1129
test -n "$cross_prefix" && cross_compile=yes
1130
cc="${cross_prefix}${cc}"
1131
ar="${cross_prefix}${ar}"
1132
ranlib="${cross_prefix}${ranlib}"
1133
strip="${cross_prefix}${strip}"
1134

    
1135
# we need to build at least one lib type
1136
if disabled_all static shared; then
1137
    cat <<EOF
1138
At least one library type must be built.
1139
Specify --enable-static to build the static libraries or --enable-shared to
1140
build the shared libraries as well. To only build the shared libraries specify
1141
--disable-static in addition to --enable-shared.
1142
EOF
1143
    exit 1;
1144
fi
1145

    
1146
if disabled libogg; then
1147
    enabled libtheora && die "libogg must be enabled to enable libtheora."
1148
    enabled libvorbis && die "libogg must be enabled to enable libvorbis."
1149
fi
1150

    
1151
if enabled_any libfaad libfaadbin ; then
1152
    if check_header faad.h; then
1153
        check_cc << EOF
1154
#include <faad.h>
1155
#ifndef FAAD2_VERSION
1156
ok faad1
1157
#endif
1158
int main( void ) { return 0; }
1159
EOF
1160
        test $? = 0 && enable libfaad2
1161
    else
1162
        die "FAAD test failed."
1163
    fi
1164
fi
1165

    
1166

    
1167
if disabled gpl ; then
1168
    die_gpl_disabled(){
1169
        name=$1
1170
        shift
1171
        enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
1172
    }
1173
    die_gpl_disabled "The Postprocessing code" pp
1174
    die_gpl_disabled "liba52"                  liba52
1175
    die_gpl_disabled "libxvidcore"             xvid
1176
    die_gpl_disabled "x264"                    x264
1177
    die_gpl_disabled "libdts"                  libdts
1178
    die_gpl_disabled "FAAD2"                   libfaad2
1179
    die_gpl_disabled "The X11 grabber"         x11grab
1180
    die_gpl_disabled "The software scaler"     swscaler
1181
fi
1182

    
1183
# compute MMX state
1184
if test $mmx = "default"; then
1185
    if test $arch = "x86_32" -o $arch = "x86_64"; then
1186
        mmx="yes"
1187
    else
1188
        mmx="no"
1189
    fi
1190
fi
1191

    
1192
test -z "$need_memalign" && need_memalign="$mmx"
1193

    
1194
#Darwin CC versions
1195
needmdynamicnopic="no"
1196
if test $targetos = Darwin; then
1197
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
1198
        add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
1199
    else
1200
        gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
1201
        case "$gcc_version" in
1202
            *2.95*)
1203
                add_cflags "-no-cpp-precomp -pipe"
1204
                ;;
1205
            *[34].*)
1206
                add_cflags "-no-cpp-precomp -pipe -force_cpusubtype_ALL -Wno-sign-compare"
1207
                if disabled shared; then
1208
                   needmdynamicnopic="yes"
1209
                fi
1210
                ;;
1211
            *)
1212
                add_cflags "-no-cpp-precomp -pipe"
1213
                if disabled shared; then
1214
                   needmdynamicnopic="yes"
1215
                fi
1216
                ;;
1217
        esac
1218
    fi
1219
fi
1220

    
1221
disabled optimize || add_cflags -fomit-frame-pointer
1222

    
1223
# Can only do AltiVec on PowerPC
1224
if test $altivec = "default"; then
1225
    if test $arch = "powerpc"; then
1226
        altivec="yes"
1227
    else
1228
        altivec="no"
1229
    fi
1230
fi
1231

    
1232
# Add processor-specific flags
1233
POWERPCMODE="32bits"
1234
if test $cpu != "generic"; then
1235
    warn_altivec(){
1236
        $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
1237
    }
1238
    case $cpu in
1239
        601|ppc601|PowerPC601)
1240
            add_cflags "-mcpu=601"
1241
            warn_altivec enabled PPC601
1242
        ;;
1243
        603*|ppc603*|PowerPC603*)
1244
            add_cflags "-mcpu=603"
1245
            warn_altivec enabled PPC603
1246
        ;;
1247
        604*|ppc604*|PowerPC604*)
1248
            add_cflags "-mcpu=604"
1249
            warn_altivec enabled PPC604
1250
        ;;
1251
        G3|g3|75*|ppc75*|PowerPC75*)
1252
            add_cflags "-mcpu=750 -mpowerpc-gfxopt"
1253
            warn_altivec enabled PPC75x
1254
        ;;
1255
        G4|g4|745*|ppc745*|PowerPC745*)
1256
            add_cflags "-mcpu=7450 -mpowerpc-gfxopt"
1257
            warn_altivec disabled PPC745x
1258
        ;;
1259
        74*|ppc74*|PowerPC74*)
1260
            add_cflags "-mcpu=7400 -mpowerpc-gfxopt"
1261
            warn_altivec disabled PPC74xx
1262
        ;;
1263
        G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
1264
            add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
1265
            warn_altivec disabled PPC970
1266
            POWERPCMODE="64bits"
1267
        ;;
1268
        # targets that do NOT support conditional mov (cmov)
1269
        i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
1270
            add_cflags "-march=$cpu"
1271
            cmov="no"
1272
        ;;
1273
        # targets that do support conditional mov (cmov)
1274
        i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
1275
            add_cflags "-march=$cpu"
1276
            cmov="yes"
1277
            fast_cmov="yes"
1278
        ;;
1279
        # targets that do support conditional mov but on which it's slow
1280
        pentium4|prescott|nocona)
1281
            add_cflags "-march=$cpu"
1282
            cmov="yes"
1283
            fast_cmov="no"
1284
        ;;
1285
        sparc64)
1286
            add_cflags "-mcpu=v9"
1287
        ;;
1288
        *)
1289
        echo "WARNING: Unknown CPU \"$cpu\", ignored."
1290
        ;;
1291
    esac
1292
fi
1293

    
1294
gnu_make(){
1295
    $1 --version 2>&1 | grep -q GNU
1296
}
1297

    
1298
if ! gnu_make $make; then
1299
    gnu_make gmake && make=gmake || die "GNU make not found."
1300
fi
1301

    
1302
# make sure we can execute files in $TMPDIR
1303
cat >$TMPE 2>>$logfile <<EOF
1304
#! /bin/sh
1305
EOF
1306
chmod +x $TMPE >>$logfile 2>&1
1307
if ! $TMPE >>$logfile 2>&1; then
1308
    cat <<EOF
1309
Unable to create and execute files in $TMPDIR1.  Set the TMPDIR environment
1310
variable to another directory and make sure that $TMPDIR1 is not mounted
1311
noexec.
1312
EOF
1313
    die "Sanity test failed."
1314
fi
1315
rm $TMPE
1316

    
1317
# compiler sanity check
1318
check_exec <<EOF
1319
int main(){
1320
    return 0;
1321
}
1322
EOF
1323
if test "$?" != 0; then
1324
    echo "$cc is unable to create an executable file."
1325
    if test -z "$cross_prefix" && disabled cross_compile ; then
1326
        echo "If $cc is a cross-compiler, use the --cross-compile option."
1327
        echo "Only do this if you know what cross compiling means."
1328
    fi
1329
    die "C compiler test failed."
1330
fi
1331

    
1332
# check for assembler specific support
1333

    
1334
if test $arch = "powerpc"; then
1335
check_cc <<EOF && dcbzl=yes
1336
int main(void) {
1337
    register long zero = 0;
1338
    char data[1024];
1339
    asm volatile("dcbzl %0, %1" : : "b" (data), "r" (zero));
1340
return 0;
1341
}
1342
EOF
1343
fi
1344

    
1345
# check for SIMD availability
1346

    
1347
# AltiVec flags: The FSF version of GCC differs from the Apple version
1348
if test $arch = "powerpc"; then
1349
    if enabled altivec; then
1350
        if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
1351
            add_cflags "-faltivec"
1352
        else
1353
            add_cflags "-maltivec -mabi=altivec"
1354
        fi
1355
    fi
1356
fi
1357

    
1358
check_header altivec.h
1359

    
1360
# check if our compiler supports Motorola AltiVec C API
1361
if enabled altivec; then
1362
    if enabled altivec_h; then
1363
        inc_altivec_h="#include <altivec.h>"
1364
    else
1365
        inc_altivec_h=
1366
    fi
1367
    check_cc <<EOF || altivec=no
1368
$inc_altivec_h
1369
int main(void) {
1370
    vector signed int v1, v2, v3;
1371
    v1 = vec_add(v2,v3);
1372
    return 0;
1373
}
1374
EOF
1375
fi
1376

    
1377
# check armv5te instructions support
1378
if test $armv5te = "default" -a $arch = "armv4l"; then
1379
    armv5te=no
1380
    check_cc <<EOF && armv5te=yes
1381
        int main(void) {
1382
        __asm__ __volatile__ ("qadd r0, r0, r0");
1383
        }
1384
EOF
1385
fi
1386

    
1387
if test $armv6 = "default" -a $arch = "armv4l"; then
1388
    check_cc <<EOF && armv6=yes || armv6=no
1389
int main(void) {
1390
    __asm__ __volatile__ ("sadd16 r0, r0, r0");
1391
}
1392
EOF
1393
fi
1394

    
1395
# check iwmmxt support
1396
if test $iwmmxt = "default" -a $arch = "armv4l"; then
1397
    iwmmxt=no
1398
    check_cc <<EOF && iwmmxt=yes
1399
        int main(void) {
1400
        __asm__ __volatile__ ("wunpckelub wr6, wr4");
1401
        }
1402
EOF
1403
fi
1404

    
1405
# mmi only available on mips
1406
if test $mmi = "default"; then
1407
    if test $arch = "mips"; then
1408
        mmi="yes"
1409
    else
1410
        mmi="no"
1411
    fi
1412
fi
1413

    
1414
# check if our compiler supports mmi
1415
enabled mmi && check_cc <<EOF || mmi="no"
1416
int main(void) {
1417
    __asm__ ("lq \$2, 0(\$2)");
1418
    return 0;
1419
}
1420
EOF
1421

    
1422
# ---
1423
# big/little-endian test
1424
if disabled cross_compile; then
1425
    check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
1426
#include <inttypes.h>
1427
int main(int argc, char ** argv){
1428
        volatile uint32_t i=0x01234567;
1429
        return (*((uint8_t*)(&i))) == 0x67;
1430
}
1431
EOF
1432
else
1433
    # programs cannot be launched if cross compiling, so make a static guess
1434
    if test "$arch" = "powerpc" -o "$arch" = "mips" ; then
1435
        bigendian="yes"
1436
    fi
1437
fi
1438

    
1439
# ---
1440
# check availability of some header files
1441

    
1442
check_header malloc.h
1443
check_func memalign
1444

    
1445
if disabled_all memalign memalign_hack && enabled need_memalign ; then
1446
    die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack."
1447
fi
1448

    
1449
check_header byteswap.h
1450

    
1451
check_func inet_aton
1452
check_func localtime_r
1453
enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
1454

    
1455
# check for some common methods of building with pthread support
1456
# do this before the optional library checks as some of them require pthreads
1457
if enabled pthreads; then
1458
    if check_func pthread_create; then
1459
        :
1460
    elif check_func pthread_create -pthread; then
1461
        add_cflags -pthread
1462
        add_ldflags -pthread
1463
    elif check_func pthread_create -pthreads; then
1464
        add_cflags -pthreads
1465
        add_ldflags -pthreads
1466
    elif ! check_lib pthread.h pthread_create -lpthread; then
1467
        die "ERROR: can't find pthreads library"
1468
    fi
1469
fi
1470

    
1471
for thread in pthreads beosthreads os2threads w32threads; do
1472
    if enabled $thread; then
1473
        if ! disabled thread_type ; then
1474
            die "ERROR: Only one thread type must be selected."
1475
        else
1476
            thread_type="$thread"
1477
        fi
1478
    fi
1479
done
1480

    
1481
enabled_any amr_nb amr_nb_fixed amr_wb amr_if2 && enable amr
1482
enabled_all amr_nb amr_nb_fixed &&
1483
    die "Only one of amr_nb and amr_nb_fixed may be enabled."
1484

    
1485
# these are off by default, so fail if requested and not available
1486
enabled liba52     && require liba52 a52dec/a52.h a52_init -la52
1487
enabled libdts     && require libdts dts.h dts_init -ldts -lm
1488
enabled libgsm     && require libgsm gsm.h gsm_create -lgsm
1489
enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
1490
enabled libtheora  && require libtheora theora/theora.h theora_info_init -ltheora -logg
1491
enabled libvorbis  && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
1492
enabled libogg     && require libogg ogg/ogg.h ogg_sync_init -logg
1493
enabled libnut     && require libnut libnut.h nut_demuxer_init -lnut
1494
enabled xvid       && require XviD xvid.h xvid_global -lxvidcore
1495
enabled x264       && require x264 x264.h x264_encoder_open -lx264
1496
enabled dc1394     && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
1497
enabled mlib       && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
1498

    
1499
# Ugh, libfaac uses stdcall calling convention on win32 so we can't use
1500
# the generic test functions
1501
if enabled libfaac; then
1502
    save_flags
1503
    temp_extralibs -lfaac
1504
    check_ld <<EOF && add_extralibs -lfaac || die "ERROR: libfaac not found"
1505
#include <stdint.h>
1506
#include <faac.h>
1507
int main(){
1508
    char *id, *cpr;
1509
    faacEncGetVersion(&id, &cpr);
1510
    return 0;
1511
}
1512
EOF
1513
    restore_flags
1514
fi
1515

    
1516
# Ugh, recent faad2 versions have renamed all functions and #define the
1517
# old names in faad.h.  Generic tests won't work.
1518
if enabled libfaad; then
1519
    save_flags
1520
    temp_extralibs -lfaad
1521
    check_ld <<EOF && add_extralibs -lfaad || die "ERROR: libfaad not found"
1522
#include <faad.h>
1523
int main(){
1524
    faacDecOpen();
1525
    return 0;
1526
}
1527
EOF
1528
    restore_flags
1529
fi
1530

    
1531
# Ugh, avisynth uses WINAPI calls. Generic tests won't work.
1532
if enabled avisynth; then
1533
    save_flags
1534
    temp_extralibs -lvfw32
1535
    check_ld <<EOF && add_extralibs -lvfw32 || die "ERROR: vfw32 not found"
1536
#include <windows.h>
1537
#include <vfw.h>
1538
int main(){
1539
    AVIFileInit();
1540
    return 0;
1541
}
1542
EOF
1543
    restore_flags
1544
fi
1545

    
1546

    
1547
# test for lrintf in math.h
1548
check_exec <<EOF && lrintf=yes || lrintf=no
1549
#define _ISOC9X_SOURCE  1
1550
#include <math.h>
1551
int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
1552
EOF
1553

    
1554
_restrict=
1555
for restrict_keyword in restrict __restrict__ __restrict; do
1556
    check_cc <<EOF && _restrict=$restrict_keyword && break
1557
void foo(char * $restrict_keyword p);
1558
EOF
1559
done
1560

    
1561
# dlopen/dlfcn.h probing
1562

    
1563
check_header dlfcn.h
1564

    
1565
if check_func dlopen; then
1566
    ldl=
1567
elif check_func dlopen -ldl; then
1568
    ldl=-ldl
1569
fi
1570

    
1571
test "$vhook" = "default" && vhook="$dlopen"
1572

    
1573
enabled_any vhook liba52bin libfaadbin && add_extralibs $ldl
1574

    
1575
if test "$targetos" = "CYGWIN" && enabled static ; then
1576
    vhook="no"
1577
    echo
1578
    echo "At the moment vhooks don't work on Cygwin static builds."
1579
    echo "Patches welcome."
1580
    echo
1581
fi
1582

    
1583
if enabled vhook; then
1584
    check_ldflags -rdynamic
1585
    check_ldflags -export-dynamic
1586
fi
1587

    
1588
enabled audio_beos && add_extralibs "-lmedia -lbe"
1589

    
1590
##########################################
1591
# imlib check
1592

    
1593
imlib2=no
1594
if imlib2-config --version >/dev/null 2>&1; then
1595
    temp_cflags `imlib2-config --cflags`
1596
    temp_extralibs `imlib2-config --libs`
1597
    check_lib Imlib2.h imlib_load_font && enable imlib2
1598
    restore_flags
1599
fi
1600

    
1601
##########################################
1602
# FreeType check
1603

    
1604
freetype2=no
1605
if freetype-config --version >/dev/null 2>&1; then
1606
    temp_cflags `freetype-config --cflags`
1607
    temp_extralibs `freetype-config --libs`
1608
    check_lib ft2build.h FT_Init_FreeType && enable freetype2
1609
    restore_flags
1610
fi
1611

    
1612
##########################################
1613
# SDL check
1614

    
1615
sdl_too_old=no
1616
sdl=no
1617
SDL_CONFIG="${cross_prefix}sdl-config"
1618
if "${SDL_CONFIG}" --version >/dev/null 2>&1; then
1619
    sdl_cflags=`"${SDL_CONFIG}" --cflags`
1620
    temp_cflags $sdl_cflags
1621
    temp_extralibs `"${SDL_CONFIG}" --libs`
1622
    if check_lib SDL.h SDL_Init; then
1623
        _sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'`
1624
        if test "$_sdlversion" -lt 121 ; then
1625
            sdl_too_old=yes
1626
        else
1627
            sdl=yes
1628
            check_cc $sdl_cflags <<EOF && enable sdl_video_size
1629
#include <SDL.h>
1630
int main(void){
1631
    const SDL_VideoInfo *vi = SDL_GetVideoInfo();
1632
    int w = vi->current_w;
1633
    return 0;
1634
}
1635
EOF
1636
        fi
1637
    fi
1638
    restore_flags
1639
fi
1640

    
1641
texi2html -version >/dev/null 2>&1 && enable texi2html || disable texi2html
1642

    
1643
##########################################
1644
# IPv6 check
1645

    
1646
enabled network && enabled ipv6 && check_ld <<EOF && ipv6=yes || ipv6=no
1647
#include <sys/types.h>
1648
#include <sys/socket.h>
1649
#include <netinet/in.h>
1650
#include <netdb.h>
1651
int main( void ) {
1652
  struct sockaddr_storage saddr;
1653
  struct ipv6_mreq mreq6;
1654
  getaddrinfo(0,0,0,0);
1655
  getnameinfo(0,0,0,0,0,0,0);
1656
  IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
1657
}
1658
EOF
1659

    
1660
enabled video4linux  && check_header linux/videodev.h  || disable video4linux
1661
enabled video4linux2 && check_header linux/videodev2.h || disable video4linux2
1662

    
1663
# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
1664
if enabled bktr; then
1665
    { check_header dev/bktr/ioctl_meteor.h &&
1666
      check_header dev/bktr/ioctl_bt848.h; } ||
1667
    { check_header machine/ioctl_meteor.h &&
1668
      check_header machine/ioctl_bt848.h; } ||
1669
    { check_header dev/video/meteor/ioctl_meteor.h &&
1670
      check_header dev/video/bktr/ioctl_bt848.h; } ||
1671
    check_header dev/ic/bt8xx.h ||
1672
    disable bktr
1673
fi
1674

    
1675
enabled audio_oss &&
1676
    check_header sys/soundcard.h ||
1677
    check_header soundcard.h ||
1678
    disable audio_oss
1679

    
1680
# Deal with the x11 frame grabber
1681
enabled x11grab                         &&
1682
enabled gpl                             &&
1683
enabled x11_grab_device_demuxer         &&
1684
check_header X11/Xlib.h                 &&
1685
check_header X11/extensions/XShm.h      &&
1686
check_func XOpenDisplay -lX11           &&
1687
check_func XShmCreateImage -lX11 -lXext &&
1688
add_extralibs -lX11 -lXext              ||
1689
disable x11_grab_device_demuxer
1690

    
1691
enabled debug && add_cflags -g
1692

    
1693
# add some useful compiler flags if supported
1694
check_cflags -Wdeclaration-after-statement
1695
check_cflags -Wall
1696
check_cflags -Wno-switch
1697
check_cflags -Wdisabled-optimization
1698
check_cflags -Wpointer-arith
1699
check_cflags -Wredundant-decls
1700
check_cflags -Wno-pointer-sign
1701
enabled extra_warnings && check_cflags -Winline
1702

    
1703
# add some linker flags
1704
check_ldflags $LDLATEFLAGS
1705

    
1706
# not all compilers support -Os
1707
test "$optimize" = "small" && check_cflags -Os
1708

    
1709
if enabled optimize; then
1710
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
1711
        add_cflags  "-O5"
1712
        add_ldflags "-O5"
1713
    else
1714
        add_cflags "-O3"
1715
    fi
1716
fi
1717

    
1718
# PIC flags for shared library objects where they are needed
1719
if enabled shared; then
1720
    # LIBOBJFLAGS may have already been set in the OS configuration
1721
    if test -z "$LIBOBJFLAGS" ; then
1722
        case "$arch" in
1723
            x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS="\$(PIC)" ;;
1724
        esac
1725
    fi
1726
fi
1727

    
1728
if enabled gprof; then
1729
    add_cflags  "-p"
1730
    add_ldflags "-p"
1731
fi
1732

    
1733
VHOOKCFLAGS="-fPIC $CFLAGS"
1734
enabled needmdynamicnopic && add_cflags -mdynamic-no-pic
1735

    
1736
# find if .align arg is power-of-two or not
1737
if test $asmalign_pot = "unknown"; then
1738
    asmalign_pot="no"
1739
    echo 'asm (".align 3");' | check_cc && asmalign_pot="yes"
1740
fi
1741

    
1742
enabled_any $ENCODER_LIST && enable encoders
1743
enabled_any $DECODER_LIST && enable decoders
1744
enabled_any $MUXER_LIST   && enable muxers
1745
enabled_any $DEMUXER_LIST && enable demuxers
1746

    
1747
enabled_any pthreads beosthreads os2threads w32threads && enable threads
1748

    
1749
check_deps $CONFIG_LIST $HAVE_LIST $DECODER_LIST $ENCODER_LIST $PARSER_LIST \
1750
    $DEMUXER_LIST $MUXER_LIST
1751

    
1752
enabled libogg    && append pkg_requires "ogg >= 1.1"
1753
enabled libtheora && append pkg_requires "theora"
1754
enabled libvorbis && append pkg_requires "vorbis vorbisenc"
1755
enabled dc1394    && append pkg_requires "libraw1394"
1756

    
1757
echo "install prefix            $PREFIX"
1758
echo "source path               $source_path"
1759
echo "C compiler                $cc"
1760
echo "make                      $make"
1761
echo ".align is power-of-two    $asmalign_pot"
1762
echo "ARCH                      $arch ($cpu)"
1763
if test "$BUILDSUF" != ""; then
1764
    echo "build suffix              $BUILDSUF"
1765
fi
1766
echo "big-endian                $bigendian"
1767
if test $arch = "x86_32" -o $arch = "x86_64"; then
1768
    echo "MMX enabled               $mmx"
1769
    echo "CMOV enabled              $cmov"
1770
    echo "CMOV is fast              $fast_cmov"
1771
fi
1772
if test $arch = "armv4l"; then
1773
    echo "ARMv5TE enabled           $armv5te"
1774
    echo "ARMv6 enabled             $armv6"
1775
    echo "IWMMXT enabled            $iwmmxt"
1776
fi
1777
if test $arch = "mips"; then
1778
    echo "MMI enabled               $mmi"
1779
fi
1780
if test $arch = "powerpc"; then
1781
    echo "AltiVec enabled           $altivec"
1782
    echo "dcbzl available           $dcbzl"
1783
fi
1784
echo "gprof enabled             $gprof"
1785
echo "debug symbols             $debug"
1786
echo "strip symbols             $dostrip"
1787
echo "optimize                  $optimize"
1788
echo "static                    $static"
1789
echo "shared                    $shared"
1790
echo "postprocessing support    $pp"
1791
echo "software scaler enabled   $swscaler"
1792
echo "video hooking             $vhook"
1793
if enabled vhook; then
1794
    echo "Imlib2 support            $imlib2"
1795
    echo "FreeType support          $freetype2"
1796
fi
1797
echo "network support           $network"
1798
if enabled network; then
1799
    echo "IPv6 support              $ipv6"
1800
fi
1801
echo "threading support         $thread_type"
1802
echo "SDL support               $sdl"
1803
if enabled sdl_too_old; then
1804
    echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
1805
fi
1806
echo "Sun medialib support      $mlib"
1807
echo "AVISynth enabled          $avisynth"
1808
echo "liba52 support            $liba52"
1809
echo "liba52 dlopened           $liba52bin"
1810
echo "libdts support            $libdts"
1811
echo "libfaac enabled           $libfaac"
1812
echo "libfaad enabled           $libfaad"
1813
echo "faadbin enabled           $libfaadbin"
1814
echo "libgsm enabled            $libgsm"
1815
echo "libmp3lame enabled        $libmp3lame"
1816
echo "libnut enabled            $libnut"
1817
echo "libogg enabled            $libogg"
1818
echo "libtheora enabled         $libtheora"
1819
echo "libvorbis enabled         $libvorbis"
1820
echo "x264 enabled              $x264"
1821
echo "XviD enabled              $xvid"
1822
echo "zlib enabled              $zlib"
1823
echo "AMR-NB float support      $amr_nb"
1824
echo "AMR-NB fixed support      $amr_nb_fixed"
1825
echo "AMR-WB float support      $amr_wb"
1826
echo "AMR-WB IF2 support        $amr_if2"
1827
if disabled gpl; then
1828
    echo "License: LGPL"
1829
else
1830
    echo "License: GPL"
1831
fi
1832

    
1833
echo "Creating config.mak and config.h..."
1834

    
1835
echo "# Automatically generated by configure - do not modify!" > config.mak
1836
echo "/* Automatically generated by configure - do not modify! */" > $TMPH
1837
echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH
1838

    
1839
echo "PREFIX=$PREFIX" >> config.mak
1840
echo "prefix=\$(DESTDIR)\${PREFIX}" >> config.mak
1841
echo "libdir=\$(DESTDIR)$libdir" >> config.mak
1842
echo "shlibdir=\$(DESTDIR)$shlibdir" >> config.mak
1843
echo "incdir=\$(DESTDIR)$incdir" >> config.mak
1844
echo "bindir=\$(DESTDIR)$bindir" >> config.mak
1845
echo "mandir=\$(DESTDIR)$mandir" >> config.mak
1846
echo "MAKE=$make" >> config.mak
1847
echo "CC=$cc" >> config.mak
1848
echo "AR=$ar" >> config.mak
1849
echo "RANLIB=$ranlib" >> config.mak
1850
if enabled dostrip; then
1851
    echo "STRIP=$strip" >> config.mak
1852
else
1853
    echo "STRIP=echo ignoring strip" >> config.mak
1854
fi
1855

    
1856
echo "OPTFLAGS=$CFLAGS" >> config.mak
1857
echo "VHOOKCFLAGS=$VHOOKCFLAGS">>config.mak
1858
echo "LDFLAGS=$LDFLAGS" >> config.mak
1859
echo "LDCONFIG=$LDCONFIG" >> config.mak
1860
echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
1861
echo "SHFLAGS=$SHFLAGS" >> config.mak
1862
echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak
1863
echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak
1864
echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
1865
echo "BUILD_STATIC=$static" >> config.mak
1866
echo "BUILDSUF=$BUILDSUF" >> config.mak
1867
echo "LIBPREF=$LIBPREF" >> config.mak
1868
echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak
1869
if enabled static; then
1870
  echo "LIB=$LIB" >> config.mak
1871
else # Some Make complain if this variable does not exist.
1872
  echo "LIB=" >> config.mak
1873
fi
1874
echo "SLIBPREF=$SLIBPREF" >> config.mak
1875
echo "SLIBSUF=\${BUILDSUF}$SLIBSUF" >> config.mak
1876
echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak
1877
echo "TARGET_OS=$targetos" >> config.mak
1878

    
1879
ucarch=`toupper $arch`
1880
echo "TARGET_ARCH_${ucarch}=yes" >> config.mak
1881
echo "#define ARCH_${ucarch} 1" >> $TMPH
1882

    
1883
# special cases
1884
case "$arch" in
1885
    x86_32|x86_64)
1886
        echo "TARGET_ARCH_X86=yes" >> config.mak
1887
        echo "#define ARCH_X86 1" >> $TMPH
1888
        ;;
1889
    powerpc)
1890
        if test "$POWERPCMODE" = "64bits"; then
1891
            echo "#define POWERPC_MODE_64BITS 1" >> $TMPH
1892
        fi
1893
        if enabled powerpc_perf; then
1894
            echo "#define CONFIG_POWERPC_PERF 1" >> $TMPH
1895
        fi
1896
        ;;
1897
    sparc64)
1898
        echo "TARGET_ARCH_SPARC=yes" >> config.mak
1899
        echo "#define ARCH_SPARC 1" >> $TMPH
1900
        ;;
1901
esac
1902

    
1903
if enabled bigendian; then
1904
  echo "WORDS_BIGENDIAN=yes" >> config.mak
1905
  echo "#define WORDS_BIGENDIAN 1" >> $TMPH
1906
fi
1907
if enabled mmx; then
1908
  echo "#define __CPU__ 586" >> $TMPH
1909
fi
1910

    
1911
if enabled sdl; then
1912
  echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak
1913
  echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak
1914
fi
1915
if enabled texi2html; then
1916
  echo "BUILD_DOC=yes" >> config.mak
1917
fi
1918

    
1919
sws_version=`grep '#define LIBSWSCALE_VERSION ' "$source_path/libswscale/swscale.h" | sed 's/[^0-9\.]//g'`
1920
pp_version=`grep '#define LIBPOSTPROC_VERSION ' "$source_path/libpostproc/postprocess.h" | sed 's/[^0-9\.]//g'`
1921
lavc_version=`grep '#define LIBAVCODEC_VERSION ' "$source_path/libavcodec/avcodec.h" | sed 's/[^0-9\.]//g'`
1922
lavf_version=`grep '#define LIBAVFORMAT_VERSION ' "$source_path/libavformat/avformat.h" | sed 's/[^0-9\.]//g'`
1923
lavu_version=`grep '#define LIBAVUTIL_VERSION ' "$source_path/libavutil/avutil.h" | sed 's/[^0-9\.]//g'`
1924

    
1925

    
1926

    
1927
if enabled shared; then
1928
  echo "BUILD_SHARED=yes" >> config.mak
1929
  echo "PIC=-fPIC -DPIC" >> config.mak
1930
  echo "SPPMAJOR=${pp_version%%.*}" >> config.mak
1931
  echo "SPPVERSION=$pp_version" >> config.mak
1932
  echo "LAVCMAJOR=${lavc_version%%.*}" >> config.mak
1933
  echo "LAVCVERSION=$lavc_version" >> config.mak
1934
  echo "LAVFMAJOR=${lavf_version%%.*}" >> config.mak
1935
  echo "LAVFVERSION=$lavf_version" >> config.mak
1936
  echo "LAVUMAJOR=${lavu_version%%.*}" >> config.mak
1937
  echo "LAVUVERSION=$lavu_version" >> config.mak
1938
  echo "SWSMAJOR=${sws_version%%.*}" >> config.mak
1939
  echo "SWSVERSION=$sws_version" >> config.mak
1940
  echo "SLIBNAME=${SLIBNAME}" >> config.mak
1941
  echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak
1942
  echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak
1943
  echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak
1944
  echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak
1945
fi
1946
echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
1947
echo "EXTRALIBS=$extralibs" >> config.mak
1948

    
1949
print_config HAVE_   $TMPH config.mak $HAVE_LIST
1950
print_config CONFIG_ $TMPH config.mak $CONFIG_LIST
1951
print_config TARGET_ $TMPH config.mak $TARGET_LIST
1952

    
1953
if test "$targetos" = "Darwin"; then
1954
  echo "#define CONFIG_DARWIN 1"  >> $TMPH
1955
fi
1956

    
1957
echo "#define restrict $_restrict" >> $TMPH
1958

    
1959
if test "$optimize" = "small"; then
1960
  echo "#define always_inline"  >> $TMPH
1961
  echo "#define CONFIG_SMALL 1" >> $TMPH
1962
fi
1963

    
1964
echo "SRC_PATH=\"$source_path\"" >> config.mak
1965
echo "SRC_PATH_BARE=$source_path" >> config.mak
1966
echo "BUILD_ROOT=\"$PWD\"" >> config.mak
1967

    
1968
if enabled amr_if2; then
1969
  echo "AMR_CFLAGS=-DIF2=1" >> config.mak
1970
fi
1971

    
1972
# Apparently it's not possible to portably echo a backslash.
1973
if enabled asmalign_pot; then
1974
  printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH
1975
else
1976
  printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH
1977
fi
1978

    
1979

    
1980
for codec in $DECODER_LIST $ENCODER_LIST $PARSER_LIST $DEMUXER_LIST $MUXER_LIST; do
1981
    ucname="`toupper $codec`"
1982
    config_name="CONFIG_$ucname"
1983
    enabled_name="ENABLE_$ucname"
1984
    if enabled $codec; then
1985
        echo "#define $config_name 1" >> $TMPH
1986
        echo "#define $enabled_name 1" >> $TMPH
1987
        echo "$config_name=yes" >> config.mak
1988
    else
1989
        echo "#define $enabled_name 0" >> $TMPH
1990
    fi
1991
done
1992

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

    
2000
rm -f $TMPO $TMPC $TMPE $TMPS $TMPH
2001

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

    
2045

    
2046
# build pkg-config files
2047
# FIXME: libdir and includedir are hardcoded and may differ from the real path.
2048

    
2049
pkgconfig_generate(){
2050
name=$1
2051
comment=$2
2052
version=$3
2053
libs=$4
2054
requires=$5
2055
include=$6
2056
cat <<EOF >$name.pc
2057
prefix=$PREFIX
2058
exec_prefix=\${prefix}
2059
libdir=\${exec_prefix}/lib
2060
includedir=\${prefix}/include
2061

    
2062
Name: $name
2063
Description: $comment
2064
Version: $version
2065
Requires: $requires
2066
Conflicts:
2067
Libs: -L\${libdir} $libs
2068
Cflags: -I\${includedir} -I\${includedir}/$include
2069
EOF
2070
}
2071

    
2072
pkgconfig_generate_uninstalled(){
2073
name=$1
2074
shortname=${name#lib}
2075
comment=$2
2076
version=$3
2077
libs=$4
2078
requires=$5
2079
cat <<EOF >$name-uninstalled.pc
2080
prefix=
2081
exec_prefix=
2082
libdir=\${pcfiledir}/$name
2083
includedir=\${pcfiledir}/$name
2084

    
2085
Name: $name
2086
Description: $comment
2087
Version: $version
2088
Requires: $requires
2089
Conflicts:
2090
Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
2091
Cflags: -I\${includedir}
2092
EOF
2093
}
2094

    
2095
pkgconfig_generate libavutil "FFmpeg utility library" "$lavu_version" -lavutil "" ffmpeg
2096
pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$lavu_version"
2097

    
2098
pkgconfig_generate libavcodec "FFmpeg codec library" "$lavc_version" "-lavcodec $extralibs" "$pkg_requires libavutil = $lavu_version" ffmpeg
2099
pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$lavc_version" "$extralibs" "$pkg_requires libavutil = $lavu_version"
2100

    
2101
pkgconfig_generate libavformat "FFmpeg container format library" "$lavf_version" "-lavformat $extralibs" "$pkg_requires libavcodec = $lavc_version" ffmpeg
2102
pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$lavf_version" "$extralibs" "$pkg_requires libavcodec = $lavc_version"
2103

    
2104
if enabled pp; then
2105
  pkgconfig_generate libpostproc "FFmpeg post processing library" "$pp_version" -lpostproc "" postproc
2106
  pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$pp_version"
2107
fi
2108

    
2109
if enabled swscaler; then
2110
  pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "-lswscale" "libavutil = $lavu_version" swscale
2111
  pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "libavutil = $lavu_version"
2112
else
2113
  pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" swscale
2114
  pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version"
2115
  apply libswscale.pc sed s/^Libs:.*$/Libs:/
2116
  apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/
2117
fi