]> git.sesse.net Git - ffmpeg/blob - configure
fix --enable-*threads
[ffmpeg] / configure
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-a52bin          open liba52.so.0 at runtime [default=no]"
82   echo "  --enable-avisynth        allow reading AVISynth script files [default=no]"
83   echo "  --enable-dts             enable GPLed libdts support [default=no]"
84   echo "  --enable-faac            enable FAAC support via libfaac [default=no]"
85   echo "  --enable-faad            enable FAAD support via libfaad [default=no]"
86   echo "  --enable-faadbin         build FAAD support with runtime linking [default=no]"
87   echo "  --enable-libgsm          enable GSM support via libgsm [default=no]"
88   echo "  --enable-mp3lame         enable MP3 encoding via libmp3lame [default=no]"
89   echo "  --enable-libnut          enable NUT (de)muxing via libnut,"
90   echo "                           native demuxer exists [default=no]"
91   echo "  --enable-libogg          enable Ogg muxing via libogg [default=no]"
92   echo "  --enable-libtheora       enable Theora encoding via libtheora [default=no]"
93   echo "  --enable-vorbis          enable Vorbis en/decoding via libvorbis,"
94   echo "                           native implementations exist [default=no]"
95   echo "  --enable-x264            enable H.264 encoding via x264 [default=no]"
96   echo "  --enable-xvid            enable Xvid encoding via xvidcore,"
97   echo "                           native MPEG-4/Xvid encoder exists [default=no]"
98   echo "  --enable-amr_nb          enable amr_nb float audio codec"
99   echo "  --enable-amr_nb-fixed    use fixed point for amr-nb codec"
100   echo "  --enable-amr_wb          enable amr_wb float audio codec"
101   echo "  --enable-amr_if2         enable amr_wb IF2 audio codec"
102   echo "  --enable-gpl             allow use of GPL code, the resulting libav*"
103   echo "                           and ffmpeg will be under GPL [default=no]"
104   echo ""
105   echo "Advanced options (experts only):"
106   echo "  --source-path=PATH       path to source code [$source_path]"
107   echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]"
108   echo "  --cross-compile          assume a cross-compiler is used"
109   echo "  --cc=CC                  use C compiler CC [$cc]"
110   echo "  --make=MAKE              use specified make [$make]"
111   echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
112   echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
113   echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
114   echo "  --build-suffix=SUFFIX    suffix for application specific build []"
115   echo "  --arch=ARCH              select architecture  [$arch]"
116   echo "  --cpu=CPU                selects the minimum cpu required (affects
117                                    instruction selection, may crash on older CPUs)"
118   echo "  --powerpc-perf-enable    enable performance report on PPC"
119   echo "                           (requires enabling PMC)"
120   echo "  --disable-mmx            disable MMX usage"
121   echo "  --disable-armv5te        disable armv5te usage"
122   echo "  --disable-armv6          disable armv6 usage"
123   echo "  --disable-iwmmxt         disable iwmmxt usage"
124   echo "  --disable-altivec        disable AltiVec usage"
125   echo "  --disable-audio-oss      disable OSS audio support [default=no]"
126   echo "  --disable-audio-beos     disable BeOS audio support [default=no]"
127   echo "  --disable-v4l            disable video4linux grabbing [default=no]"
128   echo "  --disable-v4l2           disable video4linux2 grabbing [default=no]"
129   echo "  --disable-bktr           disable bktr video grabbing [default=no]"
130   echo "  --disable-dv1394         disable DV1394 grabbing [default=no]"
131   echo "  --disable-network        disable network support [default=no]"
132   echo "  --disable-ipv6           disable ipv6 support [default=no]"
133   echo "  --disable-zlib           disable zlib [default=no]"
134   echo "  --disable-vhook          disable video hooking support"
135   echo "  --enable-gprof           enable profiling with gprof [$gprof]"
136   echo "  --disable-debug          disable debugging symbols"
137   echo "  --disable-opts           disable compiler optimizations"
138   echo "  --enable-extra-warnings  enable more compiler warnings"
139   echo "  --disable-mpegaudio-hp   faster (but less accurate)"
140   echo "                           MPEG audio decoding [default=no]"
141   echo "  --disable-protocols      disable I/O protocols support [default=no]"
142   echo "  --disable-ffmpeg         disable ffmpeg build"
143   echo "  --disable-ffserver       disable ffserver build"
144   echo "  --disable-ffplay         disable ffplay build"
145   echo "  --enable-small           optimize for size instead of speed"
146   echo "  --enable-memalign-hack   emulate memalign, interferes with memory debuggers"
147   echo "  --disable-strip          disable stripping of executables and shared libraries"
148   echo "  --disable-encoder=NAME   disables encoder NAME"
149   echo "  --enable-encoder=NAME    enables encoder NAME"
150   echo "  --disable-decoder=NAME   disables decoder NAME"
151   echo "  --enable-decoder=NAME    enables decoder NAME"
152   echo "  --disable-encoders       disables all encoders"
153   echo "  --disable-decoders       disables all decoders"
154   echo "  --disable-muxer=NAME     disables muxer NAME"
155   echo "  --enable-muxer=NAME      enables muxer NAME"
156   echo "  --disable-muxers         disables all muxers"
157   echo "  --disable-demuxer=NAME   disables demuxer NAME"
158   echo "  --enable-demuxer=NAME    enables demuxer NAME"
159   echo "  --disable-demuxers       disables all demuxers"
160   echo "  --enable-parser=NAME     enables parser NAME"
161   echo "  --disable-parser=NAME    disables parser NAME"
162   echo "  --disable-parsers        disables all parsers"
163   echo ""
164   echo "NOTE: Object files are built at the place where configure is launched."
165   exit 1
166 }
167
168 log(){
169     echo "$@" >>$logfile
170 }
171
172 log_file(){
173     log BEGIN $1
174     cat -n $1 >>$logfile
175     log END $1
176 }
177
178 echolog(){
179     log "$@"
180     echo "$@"
181 }
182
183 die(){
184     echolog "$@"
185     cat <<EOF
186 If you think configure made a mistake, make sure you are using the latest
187 version from SVN.  If the latest version fails, report the problem to the
188 ffmpeg-devel@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
189 EOF
190     if enabled logging; then
191         cat <<EOF
192 Include the log file "$logfile" produced by configure as this will help
193 solving the problem.
194 EOF
195     else
196 cat <<EOF
197 Rerun configure with logging enabled (do not use --log=no), and include the
198 log this produces with your report.
199 EOF
200     fi
201     rm -f $TMPC $TMPO $TMPE $TMPS $TMPH
202     exit 1
203 }
204
205 # "tr '[a-z]' '[A-Z]'" is a workaround for Solaris tr not grokking "tr a-z A-Z"
206 toupper(){
207     echo "$@" | tr '[a-z]' '[A-Z]'
208 }
209
210 set_all(){
211     value=$1
212     shift
213     for var in $*; do
214         eval $var=$value
215     done
216 }
217
218 pushvar(){
219     for var in $*; do
220         eval level=\${${var}_level:=0}
221         eval ${var}_${level}="\$$var"
222         eval ${var}_level=$(($level+1))
223     done
224 }
225
226 popvar(){
227     for var in $*; do
228         eval level=\${${var}_level:-0}
229         test $level = 0 && continue
230         eval level=$(($level-1))
231         eval $var="\${${var}_${level}}"
232         eval ${var}_level=$level
233         eval unset ${var}_${level}
234     done
235 }
236
237 enable(){
238     set_all yes $*
239 }
240
241 disable(){
242     set_all no $*
243 }
244
245 enabled(){
246     eval test "x\$$1" = "xyes"
247 }
248
249 disabled(){
250     eval test "x\$$1" = "xno"
251 }
252
253 enabled_all(){
254     for opt; do
255         enabled $opt || return 1
256     done
257 }
258
259 disabled_all(){
260     for opt; do
261         disabled $opt || return 1
262     done
263 }
264
265 enabled_any(){
266     for opt; do
267         enabled $opt && return 0
268     done
269 }
270
271 disabled_any(){
272     for opt; do
273         disabled $opt && return 0
274     done
275 }
276
277 check_deps(){
278     for cfg; do
279         enabled ${cfg}_checking && die "Circular dependency for $cfg."
280         disabled ${cfg}_checking && continue
281         enable ${cfg}_checking
282
283         eval dep_all="\$${cfg}_deps"
284         eval dep_any="\$${cfg}_deps_any"
285
286         pushvar cfg dep_all dep_any
287         check_deps $dep_all $dep_any
288         popvar cfg dep_all dep_any
289
290         enabled_all $dep_all || disable $cfg
291         enabled_any $dep_any || disable $cfg
292
293         disable ${cfg}_checking
294     done
295 }
296
297 print_config(){
298     pfx=$1
299     header=$2
300     makefile=$3
301     shift 3
302     for cfg; do
303         if enabled $cfg; then
304             ucname="${pfx}`toupper $cfg`"
305             echo "#define ${ucname} 1" >> $header
306             echo "${ucname}=yes" >> $makefile
307         fi
308     done
309 }
310
311 flags_saved(){
312     (: ${SAVE_CFLAGS?}) 2>/dev/null
313 }
314
315 save_flags(){
316     flags_saved && return
317     SAVE_CFLAGS="$CFLAGS"
318     SAVE_LDFLAGS="$LDFLAGS"
319     SAVE_extralibs="$extralibs"
320 }
321
322 restore_flags(){
323     flags_saved || return
324     CFLAGS="$SAVE_CFLAGS"
325     LDFLAGS="$SAVE_LDFLAGS"
326     extralibs="$SAVE_extralibs"
327     unset SAVE_CFLAGS
328     unset SAVE_LDFLAGS
329     unset SAVE_extralibs
330 }
331
332 temp_cflags(){
333     save_flags
334     CFLAGS="$CFLAGS $*"
335 }
336
337 temp_ldflags(){
338     save_flags
339     LDFLAGS="$LDFLAGS $*"
340 }
341
342 temp_extralibs(){
343     save_flags
344     extralibs="$extralibs $*"
345 }
346
347 append(){
348     var=$1
349     shift
350     flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
351     eval "$var=\"\$$var $*\""
352 }
353
354 add_cflags(){
355     append CFLAGS "$@"
356 }
357
358 add_ldflags(){
359     append LDFLAGS "$@"
360 }
361
362 add_extralibs(){
363     append extralibs "$@"
364 }
365
366 check_cmd(){
367     log "$@"
368     "$@" >>$logfile 2>&1
369 }
370
371 check_cc(){
372     log check_cc "$@"
373     cat >$TMPC
374     log_file $TMPC
375     check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
376 }
377
378 check_cpp(){
379     log check_cpp "$@"
380     cat >$TMPC
381     log_file $TMPC
382     check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
383 }
384
385 check_ld(){
386     log check_ld "$@"
387     check_cc || return
388     check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs
389 }
390
391 check_cflags(){
392     log check_cflags "$@"
393     check_cc "$@" <<EOF && add_cflags "$@"
394 int x;
395 EOF
396 }
397
398 check_ldflags(){
399     log check_ldflags "$@"
400     check_ld "$@" <<EOF && add_ldflags "$@"
401 int main(){
402     return 0;
403 }
404 EOF
405 }
406
407 check_header(){
408     log check_header "$@"
409     header=$1
410     shift
411     check_cpp "$@" <<EOF
412 #include <$header>
413 int x;
414 EOF
415     err=$?
416     var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
417     test "$err" = 0 && enable $var || disable $var
418     return $err
419 }
420
421 check_func(){
422     log check_func "$@"
423     func=$1
424     shift
425     check_ld "$@" <<EOF
426 extern int $func();
427 int main(){
428     $func();
429 }
430 EOF
431     err=$?
432     test "$err" = 0 && enable $func || disable $func
433     return $err
434 }
435
436 check_lib(){
437     log check_lib "$@"
438     header="$1"
439     func="$2"
440     shift 2
441     temp_extralibs "$@"
442     check_header $header && check_func $func && add_extralibs "$@"
443     err=$?
444     restore_flags
445     return $err
446 }
447
448 check_exec(){
449     check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; }
450 }
451
452 require(){
453     name="$1"
454     header="$2"
455     func="$3"
456     shift 3
457     check_lib $header $func "$@" || die "ERROR: $name not found"
458 }
459
460 apply(){
461     file=$1
462     shift
463     "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
464 }
465
466 CONFIG_LIST='
467     encoders
468     decoders
469     parsers
470     muxers
471     demuxers
472     amr
473     amr_nb
474     amr_nb_fixed
475     amr_wb
476     audio_beos
477     audio_oss
478     avisynth
479     beos_netserver
480     bktr
481     dc1394
482     dv1394
483     ffmpeg
484     ffplay
485     ffserver
486     gpl
487     gprof
488     ipv6
489     liba52bin
490     libdts
491     libfaac
492     libfaad
493     libfaadbin
494     libgsm
495     libmp3lame
496     libnut
497     libogg
498     libtheora
499     libvorbis
500     memalign_hack
501     mpegaudio_hp
502     network
503     pp
504     protocols
505     swscaler
506     vhook
507     video4linux
508     video4linux2
509     wince
510     x11grab
511     x264
512     xvid
513     zlib
514 '
515
516 HAVE_LIST='
517     altivec
518     altivec_h
519     armv5te
520     armv6
521     beosthreads
522     byteswap_h
523     cmov
524     dcbzl
525     dev_bktr_ioctl_bt848_h
526     dev_bktr_ioctl_meteor_h
527     dev_ic_bt8xx_h
528     dev_video_meteor_ioctl_meteor_h
529     dev_video_bktr_ioctl_bt848_h
530     dlfcn_h
531     dlopen
532     fast_cmov
533     freetype2
534     imlib2
535     inet_aton
536     iwmmxt
537     localtime_r
538     lrintf
539     machine_ioctl_bt848_h
540     machine_ioctl_meteor_h
541     malloc_h
542     memalign
543     mlib
544     mmi
545     mmx
546     os2
547     os2threads
548     pthreads
549     sdl
550     sdl_video_size
551     soundcard_h
552     sys_soundcard_h
553     threads
554     w32threads
555 '
556
557 TARGET_LIST='
558     altivec
559     armv5te
560     armv6
561     iwmmxt
562     mmi
563     mmx
564 '
565
566 CMDLINE_SELECT="
567     $CONFIG_LIST
568     $TARGET_LIST
569     debug
570     extra_warnings
571     mingw32
572     shared
573     static
574     beosthreads
575     os2threads
576     pthreads
577     w32threads
578 "
579
580 flashsv_decoder_deps="zlib"
581 flashsv_encoder_deps="zlib"
582 mpeg_xvmc_decoder_deps="xvmc"
583 png_decoder_deps="zlib"
584 png_encoder_deps="zlib"
585 x264_encoder_deps="x264"
586 xvid_encoder_deps="xvid"
587 zmbv_decoder_deps="zlib"
588 zmbv_encoder_deps="zlib"
589
590 aac_decoder_deps="libfaad"
591 mpeg4aac_decoder_deps="libfaad"
592 amr_nb_decoder_deps_any="amr_nb amr_nb_fixed"
593 amr_nb_encoder_deps_any="amr_nb amr_nb_fixed"
594 amr_wb_decoder_deps="amr_wb"
595 amr_wb_encoder_deps="amr_wb"
596 dts_decoder_deps="libdts"
597 faac_encoder_deps="libfaac"
598 liba52_decoder_deps="liba52bin"
599 libgsm_decoder_deps="libgsm"
600 libgsm_encoder_deps="libgsm"
601 libtheora_encoder_deps="libtheora"
602 mp3lame_encoder_deps="libmp3lame"
603 oggvorbis_decoder_deps="libvorbis"
604 oggvorbis_encoder_deps="libvorbis"
605
606 audio_demuxer_deps_any="audio_oss audio_beos"
607 audio_muxer_deps_any="audio_oss audio_beos"
608 dc1394_demuxer_deps="dc1394"
609 dv1394_demuxer_deps="dv1394"
610 gxf_muxer_deps="gpl"
611 libnut_demuxer_deps="libnut"
612 libnut_muxer_deps="libnut"
613 ogg_muxer_deps="libogg"
614 redir_demuxer_deps="network"
615 rtp_muxer_deps="network"
616 rtsp_demuxer_deps="network"
617 sdp_demuxer_deps="network"
618 v4l2_demuxer_deps="video4linux2"
619 video_grab_device_demuxer_deps_any="video4linux bktr"
620 x11_grab_device_demuxer_deps="x11grab"
621
622 ffplay_deps="sdl"
623 ffserver_deps="network protocols muxers"
624 network_deps="protocols"
625
626 # set temporary file name
627 if test ! -z "$TMPDIR" ; then
628     TMPDIR1="${TMPDIR}"
629 elif test ! -z "$TEMPDIR" ; then
630     TMPDIR1="${TEMPDIR}"
631 else
632     TMPDIR1="/tmp"
633 fi
634
635 TMPC="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
636 TMPO="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
637 TMPE="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}"
638 TMPS="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
639 TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
640
641 # default parameters
642
643 logging="yes"
644 logfile="config.err"
645
646 # installation paths
647 PREFIX="/usr/local"
648 libdir='${PREFIX}/lib'
649 shlibdir="$libdir"
650 incdir='${PREFIX}/include/ffmpeg'
651 mandir='${PREFIX}/man'
652 bindir='${PREFIX}/bin'
653
654 # toolchain
655 cross_prefix=""
656 cross_compile="no"
657 cc="gcc"
658 ar="ar"
659 ranlib="ranlib"
660 make="make"
661 strip="strip"
662 asmalign_pot="unknown"
663
664 # machine
665 arch=`uname -m`
666 cpu="generic"
667 powerpc_perf="no"
668 mmx="default"
669 cmov="no"
670 fast_cmov="no"
671 armv5te="default"
672 armv6="default"
673 iwmmxt="default"
674 altivec="default"
675 dcbzl="no"
676 mmi="default"
677 bigendian="no"
678
679 case "$arch" in
680   i386|i486|i586|i686|i86pc|BePC)
681     arch="x86_32"
682   ;;
683   x86_64|amd64)
684     arch="x86_32"
685     canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
686     if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
687       if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
688         arch="x86_64"
689       fi
690     fi
691   ;;
692   # armv4l is a subset of armv[567]*l
693   arm|armv[4567]*l)
694     arch="armv4l"
695   ;;
696   alpha)
697     arch="alpha"
698   ;;
699   "Power Macintosh"|ppc|ppc64|powerpc)
700     arch="powerpc"
701   ;;
702   mips|mipsel|IP*)
703     arch="mips"
704   ;;
705   sun4u|sparc64)
706     arch="sparc64"
707   ;;
708   sparc)
709     arch="sparc"
710   ;;
711   sh4)
712     arch="sh4"
713   ;;
714   parisc|parisc64)
715     arch="parisc"
716   ;;
717   s390|s390x)
718     arch="s390"
719   ;;
720   m68k)
721     arch="m68k"
722   ;;
723   ia64)
724     arch="ia64"
725   ;;
726   bfin)
727     arch="bfin"
728   ;;
729   *)
730     arch="unknown"
731   ;;
732 esac
733
734 # OS
735 beos_netserver="no"
736 mingw32="no"
737 os2="no"
738 wince="no"
739
740 # non-library system interfaces
741 audio_beos="no"
742 audio_oss="yes"
743 bktr="yes"
744 dv1394="yes"
745 video4linux2="yes"
746 video4linux="yes"
747
748 # libraries
749 amr_if2="no"
750 amr_nb="no"
751 amr_nb_fixed="no"
752 amr_wb="no"
753 avisynth="no"
754 dc1394="no"
755 dlfcn_h="no"
756 dlopen="no"
757 liba52bin="no"
758 libdts="no"
759 libfaac="no"
760 libfaad2="no"
761 libfaad="no"
762 libfaadbin="no"
763 libgsm="no"
764 libmp3lame="no"
765 libnut="no"
766 libogg="no"
767 libtheora="no"
768 libvorbis="no"
769 mlib="no"
770 x11grab="no"
771 x264="no"
772 xvid="no"
773 zlib="yes"
774
775 # configurable options
776 debug="yes"
777 dostrip="yes"
778 extra_warnings="no"
779 ffmpeg="yes"
780 ffplay="yes"
781 ffserver="yes"
782 gpl="no"
783 gprof="no"
784 ipv6="yes"
785 shared="no"
786 static="yes"
787 memalign_hack="no"
788 mpegaudio_hp="yes"
789 network="yes"
790 optimize="yes"
791 pp="no"
792 protocols="yes"
793 swscaler="no"
794 vhook="default"
795
796 # threading
797 beosthreads="no"
798 os2threads="no"
799 pthreads="no"
800 w32threads="no"
801 thread_type="no"
802
803 # build settings
804 extralibs="-lm"
805 SHFLAGS='-shared -Wl,-soname,$@'
806 VHOOKSHFLAGS='$(SHFLAGS)'
807 LIBOBJFLAGS=""
808 FFLDFLAGS=-Wl,--warn-common
809 LDLATEFLAGS='-Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil'
810 FFSERVERLDFLAGS=-Wl,-E
811 LDCONFIG="ldconfig"
812 LIBPREF="lib"
813 LIBSUF=".a"
814 LIB='$(LIBPREF)$(NAME)$(LIBSUF)'
815 SLIBPREF="lib"
816 SLIBSUF=".so"
817 SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF)'
818 SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
819 SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
820 EXESUF=""
821 BUILDSUF=""
822 LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"'
823
824 # OS specific
825 targetos=`uname -s`
826 case $targetos in
827   BeOS|Haiku|Zeta)
828     PREFIX="$HOME/config"
829     # helps building libavcodec
830     add_cflags "-DPIC -fomit-frame-pointer"
831     # 3 gcc releases known for BeOS, each with ugly bugs
832     gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
833     case "$gcc_version" in
834       2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
835         mmx="no"
836         ;;
837       *20010315*) echo "BeBits gcc"
838         add_cflags "-fno-expensive-optimizations"
839         ;;
840     esac
841     LDCONFIG="echo ignoring ldconfig"
842     SHFLAGS=-nostart
843     # disable Linux things
844     dv1394="no"
845     # enable BeOS things
846     audio_beos="yes"
847     # no need for libm, but the inet stuff
848     # Check for BONE
849     # XXX: actually should check for NOT net_server
850     if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then
851         extralibs="-lbind -lsocket"
852     else
853         beos_netserver="yes"
854         extralibs="-lnet"
855     fi ;;
856   SunOS)
857     dv1394="no"
858     FFLDFLAGS=""
859     FFSERVERLDFLAGS=""
860     SHFLAGS="-shared -Wl,-h,\$@"
861     add_extralibs "-lsocket -lnsl"
862     ;;
863   NetBSD)
864     dv1394="no"
865     add_extralibs "-lossaudio"
866     ;;
867   OpenBSD)
868     dv1394="no"
869     need_memalign="no"
870     LIBOBJFLAGS="\$(PIC)"
871     LDCONFIG="ldconfig -m \$(shlibdir)"
872     SHFLAGS='-shared'
873     SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF).$(LIBVERSION)'
874     SLIBNAME_WITH_VERSION='$(SLIBNAME)'
875     SLIBNAME_WITH_MAJOR='$(SLIBNAME)'
876     add_extralibs "-lossaudio"
877     ;;
878   FreeBSD)
879     dv1394="no"
880     need_memalign="no"
881     add_cflags "-pthread"
882     ;;
883   GNU/kFreeBSD)
884     dv1394="no"
885     add_cflags "-pthread"
886     ;;
887   BSD/OS)
888     dv1394="no"
889     extralibs="-lpoll -lgnugetopt -lm"
890     strip="strip -d"
891     ;;
892   Darwin)
893     cc="cc"
894     dv1394="no"
895     need_memalign="no"
896     SHFLAGS="-dynamiclib -Wl,-single_module -Wl,-install_name,\$(shlibdir)/\$(SLIBNAME),-current_version,\$(SPPVERSION),-compatibility_version,\$(SPPVERSION) -Wl,-read_only_relocs,suppress"
897     VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(shlibdir)/vhook/$@'
898     extralibs=""
899     strip="strip -x"
900     FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
901     SLIBSUF=".dylib"
902     SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
903     SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
904     FFSERVERLDFLAGS=-Wl,-bind_at_load
905     ;;
906   MINGW32*)
907     # Note: the rest of the mingw32 config is done afterwards as mingw32
908     # can be forced on the command line for Linux cross compilation.
909     mingw32="yes"
910     ;;
911   CYGWIN*)
912     targetos=CYGWIN
913     shlibdir="$bindir"
914     dv1394="no"
915     VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil'
916     VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
917     extralibs=""
918     EXESUF=".exe"
919     SLIBPREF="cyg"
920     SLIBSUF=".dll"
921     SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
922     SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
923     SHFLAGS='-shared -Wl,--out-implib=lib$(NAME).dll.a'
924     ;;
925   Linux)
926     LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS"
927     ;;
928   IRIX*)
929     targetos=IRIX
930     ranlib="echo ignoring ranlib"
931     ;;
932   OS/2)
933     TMPE=$TMPE".exe"
934     ar="emxomfar -p128"
935     ranlib="echo ignoring ranlib"
936     strip="echo ignoring strip"
937     add_cflags "-Zomf"
938     FFLDFLAGS="-Zomf -Zstack 16384 -s"
939     SHFLAGS="-Zdll -Zomf"
940     FFSERVERLDFLAGS=""
941     LIBPREF=""
942     LIBSUF=".lib"
943     SLIBPREF=""
944     SLIBSUF=".dll"
945     EXESUF=".exe"
946     extralibs=""
947     pkg_requires=""
948     dv1394="no"
949     ffserver="no"
950     vhook="no"
951     os2="yes"
952     ;;
953   *)
954     targetos="${targetos}-UNKNOWN"
955     ;;
956 esac
957
958 # find source path
959 source_path="`dirname \"$0\"`"
960 source_path_used="yes"
961 if test -z "$source_path" -o "$source_path" = "." ; then
962     source_path="`pwd`"
963     source_path_used="no"
964 else
965     source_path="`cd \"$source_path\"; pwd`"
966     echo "$source_path" | grep -q '[[:blank:]]' &&
967       die "Out of tree builds are impossible with whitespace in source path."
968 fi
969
970 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
971     show_help
972 fi
973
974 FFMPEG_CONFIGURATION="$@"
975
976 ENCODER_LIST=`sed -n 's/^[^#]*ENC.*, *\(.*\)).*/\1_encoder/p' "$source_path/libavcodec/allcodecs.c"`
977 DECODER_LIST=`sed -n 's/^[^#]*DEC.*, *\(.*\)).*/\1_decoder/p' "$source_path/libavcodec/allcodecs.c"`
978 PARSER_LIST=`sed -n 's/^[^#]*PARSER.*, *\(.*\)).*/\1_parser/p' "$source_path/libavcodec/allcodecs.c"`
979 MUXER_LIST=`sed -n 's/^[^#]*_MUX.*, *\(.*\)).*/\1_muxer/p' "$source_path/libavformat/allformats.c"`
980 DEMUXER_LIST=`sed -n 's/^[^#]*DEMUX.*, *\(.*\)).*/\1_demuxer/p' "$source_path/libavformat/allformats.c"`
981
982 enable $ENCODER_LIST $DECODER_LIST $PARSER_LIST $MUXER_LIST $DEMUXER_LIST
983
984 die_unknown(){
985     echo "Unknown option \"$1\"."
986     echo "See $0 --help for available options."
987     exit 1
988 }
989
990 for opt do
991   optval="${opt#*=}"
992   case "$opt" in
993   --log)
994   ;;
995   --log=*) logging="$optval"
996   ;;
997   --prefix=*) PREFIX="$optval"
998   ;;
999   --libdir=*) libdir="$optval"
1000   ;;
1001   --shlibdir=*) shlibdir="$optval"
1002   ;;
1003   --incdir=*) incdir="$optval"
1004   ;;
1005   --mandir=*) mandir="$optval"
1006   ;;
1007   --source-path=*) source_path="$optval"
1008   ;;
1009   --cross-prefix=*) cross_prefix="$optval"
1010   ;;
1011   --cross-compile) cross_compile="yes"
1012   ;;
1013   --cc=*) cc="$optval"
1014   ;;
1015   --make=*) make="$optval"
1016   ;;
1017   --extra-cflags=*) add_cflags "$optval"
1018   ;;
1019   --extra-ldflags=*) add_ldflags "$optval"
1020   ;;
1021   --extra-libs=*) add_extralibs "$optval"
1022   ;;
1023   --build-suffix=*) BUILDSUF="$optval"
1024   ;;
1025   --arch=*) arch="$optval"
1026   ;;
1027   --cpu=*) cpu="$optval"
1028   ;;
1029   --powerpc-perf-enable) powerpc_perf="yes"
1030   ;;
1031   --disable-v4l) video4linux="no"
1032   ;;
1033   --disable-v4l2) video4linux2="no"
1034   ;;
1035   --enable-a52bin) liba52bin="yes"
1036   ;;
1037   --enable-dts) libdts="yes"
1038   ;;
1039   --enable-mp3lame) libmp3lame="yes"
1040   ;;
1041   --enable-vorbis) libvorbis="yes"
1042   ;;
1043   --enable-faad) libfaad="yes"
1044   ;;
1045   --enable-faadbin) libfaadbin="yes"
1046   ;;
1047   --enable-faac) libfaac="yes"
1048   ;;
1049   --enable-mingwce) wince="yes"
1050   ;;
1051   --disable-opts) optimize="no"
1052   ;;
1053   --enable-small) optimize="small"
1054   ;;
1055   --enable-sunmlib) mlib="yes"
1056   ;;
1057   --disable-strip) dostrip="no"
1058   ;;
1059   --enable-encoder=*) enable ${optval}_encoder
1060   ;;
1061   --enable-decoder=*) enable ${optval}_decoder
1062   ;;
1063   --disable-encoder=*) disable ${optval}_encoder
1064   ;;
1065   --disable-decoder=*) disable ${optval}_decoder
1066   ;;
1067   --disable-encoders) disable $ENCODER_LIST
1068   ;;
1069   --disable-decoders) disable $DECODER_LIST
1070   ;;
1071   --enable-muxer=*) enable ${optval}_muxer
1072   ;;
1073   --disable-muxer=*) disable ${optval}_muxer
1074   ;;
1075   --disable-muxers) disable $MUXER_LIST
1076   ;;
1077   --enable-demuxer=*) enable ${optval}_demuxer
1078   ;;
1079   --disable-demuxer=*) disable ${optval}_demuxer
1080   ;;
1081   --disable-demuxers) disable $DEMUXER_LIST
1082   ;;
1083   --enable-parser=*) enable ${optval}_parser
1084   ;;
1085   --disable-parser=*) disable ${optval}_parser
1086   ;;
1087   --disable-parsers) disable $PARSER_LIST
1088   ;;
1089   --enable-?*|--disable-?*)
1090   eval `echo "${opt#-}" | sed 's/-/action=/;s/-/ option=/;s/-/_/g'`
1091   echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt
1092   $action $option
1093   ;;
1094   --help) show_help
1095   ;;
1096   *)
1097   die_unknown $opt
1098   ;;
1099   esac
1100 done
1101
1102 if ! disabled logging ; then
1103     enabled logging || logfile="$logging"
1104     echo "# $0 $@" >$logfile
1105     set >>$logfile
1106 else
1107     logfile=/dev/null
1108 fi
1109
1110 if enabled_any mingw32 wince; then
1111     if enabled_all shared static; then
1112         cat <<EOF
1113 You can only build one library type at once on MinGW.
1114 Specify --disable-static --enable-shared to only build
1115 the shared libraries. To build only the static libraries
1116 you do not need to pass additional options.
1117 EOF
1118         exit 1
1119     fi
1120     dv1394="no"
1121     dc1394="no"
1122     ffserver="no"
1123     network="no"
1124     if enabled wince; then
1125         protocols="no"
1126     fi
1127     SLIBPREF=""
1128     SLIBSUF=".dll"
1129     EXESUF=".exe"
1130     SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
1131     SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
1132     SLIB_EXTRA_CMD="-lib /machine:i386 /def:\$(@:${SLIBSUF}=.def)"
1133     SLIB_INSTALL_EXTRA_CMD="-install -m 644 \$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib) \"\$(shlibdir)/\$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib)\""
1134     SHFLAGS="-shared -Wl,--output-def,\$(@:${SLIBSUF}=.def),--out-implib,lib\$(SLIBNAME:\$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc"
1135 fi
1136
1137 # Combine FFLDFLAGS and the LDFLAGS environment variable.
1138 LDFLAGS="$FFLDFLAGS $LDFLAGS"
1139
1140 test -n "$cross_prefix" && cross_compile=yes
1141 cc="${cross_prefix}${cc}"
1142 ar="${cross_prefix}${ar}"
1143 ranlib="${cross_prefix}${ranlib}"
1144 strip="${cross_prefix}${strip}"
1145
1146 # we need to build at least one lib type
1147 if disabled_all static shared; then
1148     cat <<EOF
1149 At least one library type must be built.
1150 Specify --enable-static to build the static libraries or --enable-shared to
1151 build the shared libraries as well. To only build the shared libraries specify
1152 --disable-static in addition to --enable-shared.
1153 EOF
1154     exit 1;
1155 fi
1156
1157 if disabled libogg; then
1158     enabled libtheora && die "libogg must be enabled to enable libtheora."
1159     enabled libvorbis && die "libogg must be enabled to enable libvorbis."
1160 fi
1161
1162 if enabled_any libfaad libfaadbin ; then
1163     if check_header faad.h; then
1164         check_cc << EOF
1165 #include <faad.h>
1166 #ifndef FAAD2_VERSION
1167 ok faad1
1168 #endif
1169 int main( void ) { return 0; }
1170 EOF
1171         test $? = 0 && enable libfaad2
1172     else
1173         die "FAAD test failed."
1174     fi
1175 fi
1176
1177
1178 if disabled gpl ; then
1179     die_gpl_disabled(){
1180         name=$1
1181         shift
1182         enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
1183     }
1184     die_gpl_disabled "The Postprocessing code" pp
1185     die_gpl_disabled "liba52"                  liba52bin
1186     die_gpl_disabled "libxvidcore"             xvid
1187     die_gpl_disabled "x264"                    x264
1188     die_gpl_disabled "libdts"                  libdts
1189     die_gpl_disabled "FAAD2"                   libfaad2
1190     die_gpl_disabled "The X11 grabber"         x11grab
1191     die_gpl_disabled "The software scaler"     swscaler
1192 fi
1193
1194 # compute MMX state
1195 if test $mmx = "default"; then
1196     if test $arch = "x86_32" -o $arch = "x86_64"; then
1197         mmx="yes"
1198     else
1199         mmx="no"
1200     fi
1201 fi
1202
1203 test -z "$need_memalign" && need_memalign="$mmx"
1204
1205 #Darwin CC versions
1206 needmdynamicnopic="no"
1207 if test $targetos = Darwin; then
1208     if test -n "`$cc -v 2>&1 | grep xlc`"; then
1209         add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
1210     else
1211         gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
1212         case "$gcc_version" in
1213             *2.95*)
1214                 add_cflags "-no-cpp-precomp -pipe"
1215                 ;;
1216             *[34].*)
1217                 add_cflags "-no-cpp-precomp -pipe -force_cpusubtype_ALL -Wno-sign-compare"
1218                 if disabled shared; then
1219                    needmdynamicnopic="yes"
1220                 fi
1221                 ;;
1222             *)
1223                 add_cflags "-no-cpp-precomp -pipe"
1224                 if disabled shared; then
1225                    needmdynamicnopic="yes"
1226                 fi
1227                 ;;
1228         esac
1229     fi
1230 fi
1231
1232 disabled optimize || add_cflags -fomit-frame-pointer
1233
1234 # Can only do AltiVec on PowerPC
1235 if test $altivec = "default"; then
1236     if test $arch = "powerpc"; then
1237         altivec="yes"
1238     else
1239         altivec="no"
1240     fi
1241 fi
1242
1243 # Add processor-specific flags
1244 POWERPCMODE="32bits"
1245 if test $cpu != "generic"; then
1246     warn_altivec(){
1247         $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
1248     }
1249     case $cpu in
1250         601|ppc601|PowerPC601)
1251             add_cflags "-mcpu=601"
1252             warn_altivec enabled PPC601
1253         ;;
1254         603*|ppc603*|PowerPC603*)
1255             add_cflags "-mcpu=603"
1256             warn_altivec enabled PPC603
1257         ;;
1258         604*|ppc604*|PowerPC604*)
1259             add_cflags "-mcpu=604"
1260             warn_altivec enabled PPC604
1261         ;;
1262         G3|g3|75*|ppc75*|PowerPC75*)
1263             add_cflags "-mcpu=750 -mpowerpc-gfxopt"
1264             warn_altivec enabled PPC75x
1265         ;;
1266         G4|g4|745*|ppc745*|PowerPC745*)
1267             add_cflags "-mcpu=7450 -mpowerpc-gfxopt"
1268             warn_altivec disabled PPC745x
1269         ;;
1270         74*|ppc74*|PowerPC74*)
1271             add_cflags "-mcpu=7400 -mpowerpc-gfxopt"
1272             warn_altivec disabled PPC74xx
1273         ;;
1274         G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
1275             add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
1276             warn_altivec disabled PPC970
1277             POWERPCMODE="64bits"
1278         ;;
1279         # targets that do NOT support conditional mov (cmov)
1280         i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
1281             add_cflags "-march=$cpu"
1282             cmov="no"
1283         ;;
1284         # targets that do support conditional mov (cmov)
1285         i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
1286             add_cflags "-march=$cpu"
1287             cmov="yes"
1288             fast_cmov="yes"
1289         ;;
1290         # targets that do support conditional mov but on which it's slow
1291         pentium4|prescott|nocona)
1292             add_cflags "-march=$cpu"
1293             cmov="yes"
1294             fast_cmov="no"
1295         ;;
1296         sparc64)
1297             add_cflags "-mcpu=v9"
1298         ;;
1299         *)
1300         echo "WARNING: Unknown CPU \"$cpu\", ignored."
1301         ;;
1302     esac
1303 fi
1304
1305 gnu_make(){
1306     $1 --version 2>&1 | grep -q GNU
1307 }
1308
1309 if ! gnu_make $make; then
1310     gnu_make gmake && make=gmake || die "GNU make not found."
1311 fi
1312
1313 # make sure we can execute files in $TMPDIR
1314 cat >$TMPE 2>>$logfile <<EOF
1315 #! /bin/sh
1316 EOF
1317 chmod +x $TMPE >>$logfile 2>&1
1318 if ! $TMPE >>$logfile 2>&1; then
1319     cat <<EOF
1320 Unable to create and execute files in $TMPDIR1.  Set the TMPDIR environment
1321 variable to another directory and make sure that $TMPDIR1 is not mounted
1322 noexec.
1323 EOF
1324     die "Sanity test failed."
1325 fi
1326 rm $TMPE
1327
1328 # compiler sanity check
1329 check_exec <<EOF
1330 int main(){
1331     return 0;
1332 }
1333 EOF
1334 if test "$?" != 0; then
1335     echo "$cc is unable to create an executable file."
1336     if test -z "$cross_prefix" && disabled cross_compile ; then
1337         echo "If $cc is a cross-compiler, use the --cross-compile option."
1338         echo "Only do this if you know what cross compiling means."
1339     fi
1340     die "C compiler test failed."
1341 fi
1342
1343 # check for assembler specific support
1344
1345 if test $arch = "powerpc"; then
1346 check_cc <<EOF && dcbzl=yes
1347 int main(void) {
1348     register long zero = 0;
1349     char data[1024];
1350     asm volatile("dcbzl %0, %1" : : "b" (data), "r" (zero));
1351 return 0;
1352 }
1353 EOF
1354 fi
1355
1356 # check for SIMD availability
1357
1358 # AltiVec flags: The FSF version of GCC differs from the Apple version
1359 if test $arch = "powerpc"; then
1360     if enabled altivec; then
1361         if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
1362             add_cflags "-faltivec"
1363         else
1364             add_cflags "-maltivec -mabi=altivec"
1365         fi
1366     fi
1367 fi
1368
1369 check_header altivec.h
1370
1371 # check if our compiler supports Motorola AltiVec C API
1372 if enabled altivec; then
1373     if enabled altivec_h; then
1374         inc_altivec_h="#include <altivec.h>"
1375     else
1376         inc_altivec_h=
1377     fi
1378     check_cc <<EOF || altivec=no
1379 $inc_altivec_h
1380 int main(void) {
1381     vector signed int v1, v2, v3;
1382     v1 = vec_add(v2,v3);
1383     return 0;
1384 }
1385 EOF
1386 fi
1387
1388 # check armv5te instructions support
1389 if test $armv5te = "default" -a $arch = "armv4l"; then
1390     armv5te=no
1391     check_cc <<EOF && armv5te=yes
1392         int main(void) {
1393         __asm__ __volatile__ ("qadd r0, r0, r0");
1394         }
1395 EOF
1396 fi
1397
1398 if test $armv6 = "default" -a $arch = "armv4l"; then
1399     check_cc <<EOF && armv6=yes || armv6=no
1400 int main(void) {
1401     __asm__ __volatile__ ("sadd16 r0, r0, r0");
1402 }
1403 EOF
1404 fi
1405
1406 # check iwmmxt support
1407 if test $iwmmxt = "default" -a $arch = "armv4l"; then
1408     iwmmxt=no
1409     check_cc <<EOF && iwmmxt=yes
1410         int main(void) {
1411         __asm__ __volatile__ ("wunpckelub wr6, wr4");
1412         }
1413 EOF
1414 fi
1415
1416 # mmi only available on mips
1417 if test $mmi = "default"; then
1418     if test $arch = "mips"; then
1419         mmi="yes"
1420     else
1421         mmi="no"
1422     fi
1423 fi
1424
1425 # check if our compiler supports mmi
1426 enabled mmi && check_cc <<EOF || mmi="no"
1427 int main(void) {
1428     __asm__ ("lq \$2, 0(\$2)");
1429     return 0;
1430 }
1431 EOF
1432
1433 # ---
1434 # big/little-endian test
1435 if disabled cross_compile; then
1436     check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
1437 #include <inttypes.h>
1438 int main(int argc, char ** argv){
1439         volatile uint32_t i=0x01234567;
1440         return (*((uint8_t*)(&i))) == 0x67;
1441 }
1442 EOF
1443 else
1444     # programs cannot be launched if cross compiling, so make a static guess
1445     if test "$arch" = "powerpc" -o "$arch" = "mips" ; then
1446         bigendian="yes"
1447     fi
1448 fi
1449
1450 # ---
1451 # check availability of some header files
1452
1453 check_header malloc.h
1454 check_func memalign
1455
1456 if disabled_all memalign memalign_hack && enabled need_memalign ; then
1457     die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack."
1458 fi
1459
1460 check_header byteswap.h
1461
1462 check_func inet_aton
1463 check_func localtime_r
1464 enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
1465
1466 # check for some common methods of building with pthread support
1467 # do this before the optional library checks as some of them require pthreads
1468 if enabled pthreads; then
1469     if check_func pthread_create; then
1470         :
1471     elif check_func pthread_create -pthread; then
1472         add_cflags -pthread
1473         add_ldflags -pthread
1474     elif check_func pthread_create -pthreads; then
1475         add_cflags -pthreads
1476         add_ldflags -pthreads
1477     elif ! check_lib pthread.h pthread_create -lpthread; then
1478         die "ERROR: can't find pthreads library"
1479     fi
1480 fi
1481
1482 for thread in pthreads beosthreads os2threads w32threads; do
1483     if enabled $thread; then
1484         if ! disabled thread_type ; then
1485             die "ERROR: Only one thread type must be selected."
1486         else
1487             thread_type="$thread"
1488         fi
1489     fi
1490 done
1491
1492 enabled_any amr_nb amr_nb_fixed amr_wb amr_if2 && enable amr
1493 enabled_all amr_nb amr_nb_fixed &&
1494     die "Only one of amr_nb and amr_nb_fixed may be enabled."
1495
1496 # these are off by default, so fail if requested and not available
1497 enabled libdts     && require libdts dts.h dts_init -ldts -lm
1498 enabled libgsm     && require libgsm gsm.h gsm_create -lgsm
1499 enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
1500 enabled libtheora  && require libtheora theora/theora.h theora_info_init -ltheora -logg
1501 enabled libvorbis  && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
1502 enabled libogg     && require libogg ogg/ogg.h ogg_sync_init -logg
1503 enabled libnut     && require libnut libnut.h nut_demuxer_init -lnut
1504 enabled xvid       && require XviD xvid.h xvid_global -lxvidcore
1505 enabled x264       && require x264 x264.h x264_encoder_open -lx264
1506 enabled dc1394     && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
1507 enabled mlib       && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
1508
1509 # Ugh, libfaac uses stdcall calling convention on win32 so we can't use
1510 # the generic test functions
1511 if enabled libfaac; then
1512     save_flags
1513     temp_extralibs -lfaac
1514     check_ld <<EOF && add_extralibs -lfaac || die "ERROR: libfaac not found"
1515 #include <stdint.h>
1516 #include <faac.h>
1517 int main(){
1518     char *id, *cpr;
1519     faacEncGetVersion(&id, &cpr);
1520     return 0;
1521 }
1522 EOF
1523     restore_flags
1524 fi
1525
1526 # Ugh, recent faad2 versions have renamed all functions and #define the
1527 # old names in faad.h.  Generic tests won't work.
1528 if enabled libfaad; then
1529     save_flags
1530     temp_extralibs -lfaad
1531     check_ld <<EOF && add_extralibs -lfaad || die "ERROR: libfaad not found"
1532 #include <faad.h>
1533 int main(){
1534     faacDecOpen();
1535     return 0;
1536 }
1537 EOF
1538     restore_flags
1539 fi
1540
1541 # Ugh, avisynth uses WINAPI calls. Generic tests won't work.
1542 if enabled avisynth; then
1543     save_flags
1544     temp_extralibs -lvfw32
1545     check_ld <<EOF && add_extralibs -lvfw32 || die "ERROR: vfw32 not found"
1546 #include <windows.h>
1547 #include <vfw.h>
1548 int main(){
1549     AVIFileInit();
1550     return 0;
1551 }
1552 EOF
1553     restore_flags
1554 fi
1555
1556
1557 # test for lrintf in math.h
1558 check_exec <<EOF && lrintf=yes || lrintf=no
1559 #define _ISOC9X_SOURCE  1
1560 #include <math.h>
1561 int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
1562 EOF
1563
1564 _restrict=
1565 for restrict_keyword in restrict __restrict__ __restrict; do
1566     check_cc <<EOF && _restrict=$restrict_keyword && break
1567 void foo(char * $restrict_keyword p);
1568 EOF
1569 done
1570
1571 # dlopen/dlfcn.h probing
1572
1573 check_header dlfcn.h
1574
1575 if check_func dlopen; then
1576     ldl=
1577 elif check_func dlopen -ldl; then
1578     ldl=-ldl
1579 fi
1580
1581 test "$vhook" = "default" && vhook="$dlopen"
1582
1583 enabled_any vhook liba52bin libfaadbin && add_extralibs $ldl
1584
1585 if test "$targetos" = "CYGWIN" && enabled static ; then
1586     vhook="no"
1587     echo
1588     echo "At the moment vhooks don't work on Cygwin static builds."
1589     echo "Patches welcome."
1590     echo
1591 fi
1592
1593 if enabled vhook; then
1594     check_ldflags -rdynamic
1595     check_ldflags -export-dynamic
1596 fi
1597
1598 enabled audio_beos && add_extralibs "-lmedia -lbe"
1599
1600 ##########################################
1601 # imlib check
1602
1603 imlib2=no
1604 if imlib2-config --version >/dev/null 2>&1; then
1605     temp_cflags `imlib2-config --cflags`
1606     temp_extralibs `imlib2-config --libs`
1607     check_lib Imlib2.h imlib_load_font && enable imlib2
1608     restore_flags
1609 fi
1610
1611 ##########################################
1612 # FreeType check
1613
1614 freetype2=no
1615 if freetype-config --version >/dev/null 2>&1; then
1616     temp_cflags `freetype-config --cflags`
1617     temp_extralibs `freetype-config --libs`
1618     check_lib ft2build.h FT_Init_FreeType && enable freetype2
1619     restore_flags
1620 fi
1621
1622 ##########################################
1623 # SDL check
1624
1625 sdl_too_old=no
1626 sdl=no
1627 SDL_CONFIG="${cross_prefix}sdl-config"
1628 if "${SDL_CONFIG}" --version >/dev/null 2>&1; then
1629     sdl_cflags=`"${SDL_CONFIG}" --cflags`
1630     temp_cflags $sdl_cflags
1631     temp_extralibs `"${SDL_CONFIG}" --libs`
1632     if check_lib SDL.h SDL_Init; then
1633         _sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'`
1634         if test "$_sdlversion" -lt 121 ; then
1635             sdl_too_old=yes
1636         else
1637             sdl=yes
1638             check_cc $sdl_cflags <<EOF && enable sdl_video_size
1639 #include <SDL.h>
1640 int main(void){
1641     const SDL_VideoInfo *vi = SDL_GetVideoInfo();
1642     int w = vi->current_w;
1643     return 0;
1644 }
1645 EOF
1646         fi
1647     fi
1648     restore_flags
1649 fi
1650
1651 texi2html -version >/dev/null 2>&1 && enable texi2html || disable texi2html
1652
1653 ##########################################
1654 # IPv6 check
1655
1656 enabled network && enabled ipv6 && check_ld <<EOF && ipv6=yes || ipv6=no
1657 #include <sys/types.h>
1658 #include <sys/socket.h>
1659 #include <netinet/in.h>
1660 #include <netdb.h>
1661 int main( void ) {
1662   struct sockaddr_storage saddr;
1663   struct ipv6_mreq mreq6;
1664   getaddrinfo(0,0,0,0);
1665   getnameinfo(0,0,0,0,0,0,0);
1666   IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
1667 }
1668 EOF
1669
1670 enabled video4linux  && check_header linux/videodev.h  || disable video4linux
1671 enabled video4linux2 && check_header linux/videodev2.h || disable video4linux2
1672
1673 # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
1674 if enabled bktr; then
1675     { check_header dev/bktr/ioctl_meteor.h &&
1676       check_header dev/bktr/ioctl_bt848.h; } ||
1677     { check_header machine/ioctl_meteor.h &&
1678       check_header machine/ioctl_bt848.h; } ||
1679     { check_header dev/video/meteor/ioctl_meteor.h &&
1680       check_header dev/video/bktr/ioctl_bt848.h; } ||
1681     check_header dev/ic/bt8xx.h ||
1682     disable bktr
1683 fi
1684
1685 enabled audio_oss &&
1686     check_header sys/soundcard.h ||
1687     check_header soundcard.h ||
1688     disable audio_oss
1689
1690 # Deal with the x11 frame grabber
1691 enabled x11grab                         &&
1692 enabled gpl                             &&
1693 enabled x11_grab_device_demuxer         &&
1694 check_header X11/Xlib.h                 &&
1695 check_header X11/extensions/XShm.h      &&
1696 check_func XOpenDisplay -lX11           &&
1697 check_func XShmCreateImage -lX11 -lXext &&
1698 add_extralibs -lX11 -lXext              ||
1699 disable x11_grab_device_demuxer
1700
1701 enabled debug && add_cflags -g
1702
1703 # add some useful compiler flags if supported
1704 check_cflags -Wdeclaration-after-statement
1705 check_cflags -Wall
1706 check_cflags -Wno-switch
1707 check_cflags -Wdisabled-optimization
1708 check_cflags -Wpointer-arith
1709 check_cflags -Wredundant-decls
1710 check_cflags -Wno-pointer-sign
1711 enabled extra_warnings && check_cflags -Winline
1712
1713 # add some linker flags
1714 check_ldflags $LDLATEFLAGS
1715
1716 # not all compilers support -Os
1717 test "$optimize" = "small" && check_cflags -Os
1718
1719 if enabled optimize; then
1720     if test -n "`$cc -v 2>&1 | grep xlc`"; then
1721         add_cflags  "-O5"
1722         add_ldflags "-O5"
1723     else
1724         add_cflags "-O3"
1725     fi
1726 fi
1727
1728 # PIC flags for shared library objects where they are needed
1729 if enabled shared; then
1730     # LIBOBJFLAGS may have already been set in the OS configuration
1731     if test -z "$LIBOBJFLAGS" ; then
1732         case "$arch" in
1733             x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS="\$(PIC)" ;;
1734         esac
1735     fi
1736 fi
1737
1738 if enabled gprof; then
1739     add_cflags  "-p"
1740     add_ldflags "-p"
1741 fi
1742
1743 VHOOKCFLAGS="-fPIC $CFLAGS"
1744 enabled needmdynamicnopic && add_cflags -mdynamic-no-pic
1745
1746 # find if .align arg is power-of-two or not
1747 if test $asmalign_pot = "unknown"; then
1748     asmalign_pot="no"
1749     echo 'asm (".align 3");' | check_cc && asmalign_pot="yes"
1750 fi
1751
1752 enabled_any $ENCODER_LIST && enable encoders
1753 enabled_any $DECODER_LIST && enable decoders
1754 enabled_any $MUXER_LIST   && enable muxers
1755 enabled_any $DEMUXER_LIST && enable demuxers
1756
1757 enabled_any pthreads beosthreads os2threads w32threads && enable threads
1758
1759 check_deps $CONFIG_LIST $HAVE_LIST $DECODER_LIST $ENCODER_LIST $PARSER_LIST \
1760     $DEMUXER_LIST $MUXER_LIST
1761
1762 enabled libogg    && append pkg_requires "ogg >= 1.1"
1763 enabled libtheora && append pkg_requires "theora"
1764 enabled libvorbis && append pkg_requires "vorbis vorbisenc"
1765 enabled dc1394    && append pkg_requires "libraw1394"
1766
1767 echo "install prefix            $PREFIX"
1768 echo "source path               $source_path"
1769 echo "C compiler                $cc"
1770 echo "make                      $make"
1771 echo ".align is power-of-two    $asmalign_pot"
1772 echo "ARCH                      $arch ($cpu)"
1773 if test "$BUILDSUF" != ""; then
1774     echo "build suffix              $BUILDSUF"
1775 fi
1776 echo "big-endian                $bigendian"
1777 if test $arch = "x86_32" -o $arch = "x86_64"; then
1778     echo "MMX enabled               $mmx"
1779     echo "CMOV enabled              $cmov"
1780     echo "CMOV is fast              $fast_cmov"
1781 fi
1782 if test $arch = "armv4l"; then
1783     echo "ARMv5TE enabled           $armv5te"
1784     echo "ARMv6 enabled             $armv6"
1785     echo "IWMMXT enabled            $iwmmxt"
1786 fi
1787 if test $arch = "mips"; then
1788     echo "MMI enabled               $mmi"
1789 fi
1790 if test $arch = "powerpc"; then
1791     echo "AltiVec enabled           $altivec"
1792     echo "dcbzl available           $dcbzl"
1793 fi
1794 echo "gprof enabled             $gprof"
1795 echo "debug symbols             $debug"
1796 echo "strip symbols             $dostrip"
1797 echo "optimize                  $optimize"
1798 echo "static                    $static"
1799 echo "shared                    $shared"
1800 echo "postprocessing support    $pp"
1801 echo "software scaler enabled   $swscaler"
1802 echo "video hooking             $vhook"
1803 if enabled vhook; then
1804     echo "Imlib2 support            $imlib2"
1805     echo "FreeType support          $freetype2"
1806 fi
1807 echo "network support           $network"
1808 if enabled network; then
1809     echo "IPv6 support              $ipv6"
1810 fi
1811 echo "threading support         $thread_type"
1812 echo "SDL support               $sdl"
1813 if enabled sdl_too_old; then
1814     echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
1815 fi
1816 echo "Sun medialib support      $mlib"
1817 echo "AVISynth enabled          $avisynth"
1818 echo "liba52 dlopened           $liba52bin"
1819 echo "libdts support            $libdts"
1820 echo "libfaac enabled           $libfaac"
1821 echo "libfaad enabled           $libfaad"
1822 echo "faadbin enabled           $libfaadbin"
1823 echo "libgsm enabled            $libgsm"
1824 echo "libmp3lame enabled        $libmp3lame"
1825 echo "libnut enabled            $libnut"
1826 echo "libogg enabled            $libogg"
1827 echo "libtheora enabled         $libtheora"
1828 echo "libvorbis enabled         $libvorbis"
1829 echo "x264 enabled              $x264"
1830 echo "XviD enabled              $xvid"
1831 echo "zlib enabled              $zlib"
1832 echo "AMR-NB float support      $amr_nb"
1833 echo "AMR-NB fixed support      $amr_nb_fixed"
1834 echo "AMR-WB float support      $amr_wb"
1835 echo "AMR-WB IF2 support        $amr_if2"
1836 if disabled gpl; then
1837     echo "License: LGPL"
1838 else
1839     echo "License: GPL"
1840 fi
1841
1842 echo "Creating config.mak and config.h..."
1843
1844 echo "# Automatically generated by configure - do not modify!" > config.mak
1845 echo "/* Automatically generated by configure - do not modify! */" > $TMPH
1846 echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH
1847
1848 echo "PREFIX=$PREFIX" >> config.mak
1849 echo "prefix=\$(DESTDIR)\${PREFIX}" >> config.mak
1850 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
1851 echo "shlibdir=\$(DESTDIR)$shlibdir" >> config.mak
1852 echo "incdir=\$(DESTDIR)$incdir" >> config.mak
1853 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
1854 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
1855 echo "MAKE=$make" >> config.mak
1856 echo "CC=$cc" >> config.mak
1857 echo "AR=$ar" >> config.mak
1858 echo "RANLIB=$ranlib" >> config.mak
1859 if enabled dostrip; then
1860     echo "STRIP=$strip" >> config.mak
1861 else
1862     echo "STRIP=echo ignoring strip" >> config.mak
1863 fi
1864
1865 echo "OPTFLAGS=$CFLAGS" >> config.mak
1866 echo "VHOOKCFLAGS=$VHOOKCFLAGS">>config.mak
1867 echo "LDFLAGS=$LDFLAGS" >> config.mak
1868 echo "LDCONFIG=$LDCONFIG" >> config.mak
1869 echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
1870 echo "SHFLAGS=$SHFLAGS" >> config.mak
1871 echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak
1872 echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak
1873 echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
1874 echo "BUILD_STATIC=$static" >> config.mak
1875 echo "BUILDSUF=$BUILDSUF" >> config.mak
1876 echo "LIBPREF=$LIBPREF" >> config.mak
1877 echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak
1878 if enabled static; then
1879   echo "LIB=$LIB" >> config.mak
1880 else # Some Make complain if this variable does not exist.
1881   echo "LIB=" >> config.mak
1882 fi
1883 echo "SLIBPREF=$SLIBPREF" >> config.mak
1884 echo "SLIBSUF=\${BUILDSUF}$SLIBSUF" >> config.mak
1885 echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak
1886 echo "TARGET_OS=$targetos" >> config.mak
1887
1888 ucarch=`toupper $arch`
1889 echo "TARGET_ARCH_${ucarch}=yes" >> config.mak
1890 echo "#define ARCH_${ucarch} 1" >> $TMPH
1891
1892 # special cases
1893 case "$arch" in
1894     x86_32|x86_64)
1895         echo "TARGET_ARCH_X86=yes" >> config.mak
1896         echo "#define ARCH_X86 1" >> $TMPH
1897         ;;
1898     powerpc)
1899         if test "$POWERPCMODE" = "64bits"; then
1900             echo "#define POWERPC_MODE_64BITS 1" >> $TMPH
1901         fi
1902         if enabled powerpc_perf; then
1903             echo "#define POWERPC_PERFORMANCE_REPORT 1" >> $TMPH
1904         fi
1905         ;;
1906     sparc64)
1907         echo "TARGET_ARCH_SPARC=yes" >> config.mak
1908         echo "#define ARCH_SPARC 1" >> $TMPH
1909         ;;
1910 esac
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 HAVE_   $TMPH config.mak $HAVE_LIST
1959 print_config CONFIG_ $TMPH config.mak $CONFIG_LIST
1960 print_config TARGET_ $TMPH config.mak $TARGET_LIST
1961
1962 if test "$targetos" = "Darwin"; then
1963   echo "#define CONFIG_DARWIN 1"  >> $TMPH
1964 fi
1965
1966 echo "#define restrict $_restrict" >> $TMPH
1967
1968 if test "$optimize" = "small"; then
1969   echo "#define always_inline"  >> $TMPH
1970   echo "#define CONFIG_SMALL 1" >> $TMPH
1971 fi
1972
1973 echo "SRC_PATH=\"$source_path\"" >> config.mak
1974 echo "SRC_PATH_BARE=$source_path" >> config.mak
1975 echo "BUILD_ROOT=\"$PWD\"" >> config.mak
1976
1977 if enabled amr_if2; then
1978   echo "AMR_CFLAGS=-DIF2=1" >> config.mak
1979 fi
1980
1981 # Apparently it's not possible to portably echo a backslash.
1982 if enabled asmalign_pot; then
1983   printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH
1984 else
1985   printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH
1986 fi
1987
1988
1989 for codec in $DECODER_LIST $ENCODER_LIST $PARSER_LIST $DEMUXER_LIST $MUXER_LIST; do
1990     ucname="`toupper $codec`"
1991     config_name="CONFIG_$ucname"
1992     enabled_name="ENABLE_$ucname"
1993     if enabled $codec; then
1994         echo "#define $config_name 1" >> $TMPH
1995         echo "#define $enabled_name 1" >> $TMPH
1996         echo "$config_name=yes" >> config.mak
1997     else
1998         echo "#define $enabled_name 0" >> $TMPH
1999     fi
2000 done
2001
2002 # Do not overwrite config.h if unchanged to avoid superfluous rebuilds.
2003 if ! cmp -s $TMPH config.h; then
2004         mv -f $TMPH config.h
2005 else
2006         echo "config.h is unchanged"
2007 fi
2008
2009 rm -f $TMPO $TMPC $TMPE $TMPS $TMPH
2010
2011 # build tree in object directory if source path is different from current one
2012 if enabled source_path_used; then
2013     DIRS="\
2014          doc \
2015          libavformat \
2016          libavcodec \
2017          libavcodec/alpha \
2018          libavcodec/armv4l \
2019          libavcodec/bfin \
2020          libavcodec/i386 \
2021          libavcodec/sparc \
2022          libavcodec/mlib \
2023          libavcodec/ppc \
2024          libavcodec/amr \
2025          libavcodec/amr_float \
2026          libavcodec/amrwb_float \
2027          libpostproc \
2028          libavutil \
2029          libswscale \
2030          tests \
2031          vhook \
2032          "
2033     FILES="\
2034           Makefile \
2035           common.mak \
2036           libavformat/Makefile \
2037           libavcodec/Makefile \
2038           libpostproc/Makefile \
2039           libavutil/Makefile \
2040           libswscale/Makefile \
2041           tests/Makefile \
2042           vhook/Makefile \
2043           doc/Makefile \
2044           doc/texi2pod.pl \
2045           "
2046     for dir in $DIRS ; do
2047             mkdir -p $dir
2048     done
2049     for f in $FILES ; do
2050         ln -sf "$source_path/$f" $f
2051     done
2052 fi
2053
2054
2055 # build pkg-config files
2056 # FIXME: libdir and includedir are hardcoded and may differ from the real path.
2057
2058 pkgconfig_generate(){
2059 name=$1
2060 comment=$2
2061 version=$3
2062 libs=$4
2063 requires=$5
2064 include=$6
2065 cat <<EOF >$name.pc
2066 prefix=$PREFIX
2067 exec_prefix=\${prefix}
2068 libdir=\${exec_prefix}/lib
2069 includedir=\${prefix}/include
2070
2071 Name: $name
2072 Description: $comment
2073 Version: $version
2074 Requires: $requires
2075 Conflicts:
2076 Libs: -L\${libdir} $libs
2077 Cflags: -I\${includedir} -I\${includedir}/$include
2078 EOF
2079 }
2080
2081 pkgconfig_generate_uninstalled(){
2082 name=$1
2083 shortname=${name#lib}
2084 comment=$2
2085 version=$3
2086 libs=$4
2087 requires=$5
2088 cat <<EOF >$name-uninstalled.pc
2089 prefix=
2090 exec_prefix=
2091 libdir=\${pcfiledir}/$name
2092 includedir=\${pcfiledir}/$name
2093
2094 Name: $name
2095 Description: $comment
2096 Version: $version
2097 Requires: $requires
2098 Conflicts:
2099 Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
2100 Cflags: -I\${includedir}
2101 EOF
2102 }
2103
2104 pkgconfig_generate libavutil "FFmpeg utility library" "$lavu_version" -lavutil "" ffmpeg
2105 pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$lavu_version"
2106
2107 pkgconfig_generate libavcodec "FFmpeg codec library" "$lavc_version" "-lavcodec $extralibs" "$pkg_requires libavutil = $lavu_version" ffmpeg
2108 pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$lavc_version" "$extralibs" "$pkg_requires libavutil = $lavu_version"
2109
2110 pkgconfig_generate libavformat "FFmpeg container format library" "$lavf_version" "-lavformat $extralibs" "$pkg_requires libavcodec = $lavc_version" ffmpeg
2111 pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$lavf_version" "$extralibs" "$pkg_requires libavcodec = $lavc_version"
2112
2113 if enabled pp; then
2114   pkgconfig_generate libpostproc "FFmpeg post processing library" "$pp_version" -lpostproc "" postproc
2115   pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$pp_version"
2116 fi
2117
2118 if enabled swscaler; then
2119   pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "-lswscale" "libavutil = $lavu_version" swscale
2120   pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "libavutil = $lavu_version"
2121 else
2122   pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" swscale
2123   pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version"
2124   apply libswscale.pc sed s/^Libs:.*$/Libs:/
2125   apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/
2126 fi