Fix typo in configure error message.
[ffmpeg.git] / configure
index 1bd8dc2..ebac14b 100755 (executable)
--- a/configure
+++ b/configure
@@ -190,6 +190,7 @@ show_help(){
   echo "  --nm=NM                  use nm tool"
   echo "  --as=AS                  use assembler AS [$as_default]"
   echo "  --cc=CC                  use C compiler CC [$cc_default]"
+  echo "  --ld=LD                  use linker LD"
   echo "  --host-cc=HOSTCC         use host C compiler HOSTCC"
   echo "  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host"
   echo "  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host"
@@ -220,6 +221,7 @@ show_help(){
   echo "  --disable-neon           disable neon optimizations"
   echo "  --disable-vis            disable VIS optimizations"
   echo "  --disable-yasm           disable use of yasm assembler"
+  echo "  --enable-pic             build position-independent code"
   echo
   echo "Developer options (useful when working on FFmpeg itself):"
   echo "  --disable-debug          disable debugging symbols"
@@ -289,6 +291,14 @@ sh_quote(){
     echo "$v"
 }
 
+filter(){
+    pat=$1
+    shift
+    for v; do
+        eval "case $v in $pat) echo $v ;; esac"
+    done
+}
+
 set_all(){
     value=$1
     shift
@@ -511,8 +521,16 @@ append(){
     eval "$var=\"\$$var $*\""
 }
 
+add_cppflags(){
+    append CPPFLAGS $($filter_cppflags "$@")
+}
+
 add_cflags(){
-    append CFLAGS "$@"
+    append CFLAGS $($filter_cflags "$@")
+}
+
+add_asflags(){
+    append ASFLAGS $($filter_asflags "$@")
 }
 
 add_ldflags(){
@@ -532,21 +550,21 @@ check_cc(){
     log check_cc "$@"
     cat > $TMPC
     log_file $TMPC
-    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
+    check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC
 }
 
 check_cpp(){
     log check_cpp "$@"
     cat > $TMPC
     log_file $TMPC
-    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
+    check_cmd $cc $CPPFLAGS $CFLAGS "$@" -E -o $TMPO $TMPC
 }
 
 check_as(){
     log check_as "$@"
     cat > $TMPC
     log_file $TMPC
-    check_cmd $as $CFLAGS "$@" -c -o $TMPO $TMPC
+    check_cmd $as $CPPFLAGS $ASFLAGS "$@" -c -o $TMPO $TMPC
 }
 
 check_asm(){
@@ -575,12 +593,21 @@ check_ld(){
     for f; do
         test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
     done
-    check_cmd $cc $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs
+    check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs
+}
+
+check_cppflags(){
+    log check_cppflags "$@"
+    set -- $($filter_cppflags "$@")
+    check_cc "$@" <<EOF && append CPPFLAGS "$@"
+int x;
+EOF
 }
 
 check_cflags(){
     log check_cflags "$@"
-    check_cc "$@" <<EOF && add_cflags "$@"
+    set -- $($filter_cflags "$@")
+    check_cc "$@" <<EOF && append CFLAGS "$@"
 int x;
 EOF
 }
@@ -628,8 +655,7 @@ check_func_headers(){
     check_ld "$@" <<EOF && enable $func && enable_safe $headers
 $incs
 int main(int argc, char **argv){
-    (void) $func;
-    return 0;
+    return (long) $func;
 }
 EOF
 }
@@ -815,6 +841,7 @@ CONFIG_LIST="
     mpegaudio_hp
     network
     nonfree
+    pic
     postproc
     powerpc_perf
     rdft
@@ -840,6 +867,9 @@ THREADS_LIST='
 ARCH_LIST='
     alpha
     arm
+    avr32
+    avr32_ap
+    avr32_uc
     bfin
     ia64
     m68k
@@ -882,6 +912,7 @@ HAVE_LIST="
     alsa_asoundlib_h
     altivec_h
     arpa_inet_h
+    attribute_packed
     bigendian
     bswap
     closesocket
@@ -907,6 +938,7 @@ HAVE_LIST="
     getrusage
     inet_aton
     inline_asm
+    isatty
     ldbrx
     libdc1394_1
     libdc1394_2
@@ -940,6 +972,7 @@ HAVE_LIST="
     termios_h
     threads
     truncf
+    vfp_args
     VirtualAlloc
     winsock2_h
     xform_asm
@@ -983,12 +1016,14 @@ CMDLINE_SET="
     cc
     cpu
     cross_prefix
+    dep_cc
     extra_version
     host_cc
     host_cflags
     host_ldflags
     host_libs
     host_os
+    ld
     logfile
     nm
     source_path
@@ -999,6 +1034,10 @@ CMDLINE_SET="
     target_path
 "
 
+CMDLINE_APPEND="
+    extra_cflags
+"
+
 # code dependency declarations
 
 # architecture extensions
@@ -1019,8 +1058,12 @@ sse_deps="mmx"
 ssse3_deps="sse"
 vis_deps="sparc"
 
+need_memalign="altivec neon sse"
+inline_asm_deps="!tms470"
+
 # decoders / encoders / hardware accelerators
 aac_decoder_select="fft mdct"
+aac_encoder_select="fft mdct"
 ac3_decoder_select="fft mdct"
 atrac3_decoder_select="fft mdct"
 cavs_decoder_select="golomb"
@@ -1029,7 +1072,8 @@ cscd_decoder_suggest="zlib"
 dca_decoder_select="fft mdct"
 dnxhd_encoder_select="aandct"
 dxa_decoder_select="zlib"
-eac3_decoder_select="fft mdct"
+eac3_decoder_select="ac3_decoder"
+eamad_decoder_select="aandct"
 eatgq_decoder_select="aandct"
 eatqi_decoder_select="aandct"
 ffv1_decoder_select="golomb"
@@ -1037,17 +1081,17 @@ flac_decoder_select="golomb"
 flac_encoder_select="golomb"
 flashsv_decoder_select="zlib"
 flashsv_encoder_select="zlib"
-flv_encoder_select="aandct"
+flv_encoder_select="h263_encoder"
 h261_encoder_select="aandct"
 h263_encoder_select="aandct"
 h263_vaapi_hwaccel_deps="va_va_h"
-h263_vaapi_hwaccel_select="vaapi"
-h263p_encoder_select="aandct"
+h263_vaapi_hwaccel_select="vaapi h263_decoder"
+h263p_encoder_select="h263_encoder"
 h264_decoder_select="golomb"
 h264_vaapi_hwaccel_deps="va_va_h"
 h264_vaapi_hwaccel_select="vaapi"
 h264_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
-h264_vdpau_decoder_select="vdpau"
+h264_vdpau_decoder_select="vdpau h264_decoder"
 imc_decoder_select="fft mdct"
 jpegls_decoder_select="golomb"
 jpegls_encoder_select="golomb"
@@ -1056,26 +1100,27 @@ loco_decoder_select="golomb"
 mjpeg_encoder_select="aandct"
 mpeg1video_encoder_select="aandct"
 mpeg2video_encoder_select="aandct"
-mpeg4_encoder_select="aandct"
+mpeg4_encoder_select="h263_encoder"
 mpeg_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
-mpeg_vdpau_decoder_select="vdpau"
+mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
 mpeg1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
-mpeg1_vdpau_decoder_select="vdpau"
+mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
 mpeg2_vaapi_hwaccel_deps="va_va_h"
-mpeg2_vaapi_hwaccel_select="vaapi"
+mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
 mpeg4_vaapi_hwaccel_deps="va_va_h"
-mpeg4_vaapi_hwaccel_select="vaapi"
+mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
 mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
-msmpeg4v1_encoder_select="aandct"
-msmpeg4v2_encoder_select="aandct"
-msmpeg4v3_encoder_select="aandct"
+mpeg_xvmc_decoder_select="mpegvideo_decoder"
+msmpeg4v1_encoder_select="h263_encoder"
+msmpeg4v2_encoder_select="h263_encoder"
+msmpeg4v3_encoder_select="h263_encoder"
 nellymoser_decoder_select="fft mdct"
 nellymoser_encoder_select="fft mdct"
 png_decoder_select="zlib"
 png_encoder_select="zlib"
 qdm2_decoder_select="fft mdct rdft"
-rv10_encoder_select="aandct"
-rv20_encoder_select="aandct"
+rv10_encoder_select="h263_encoder"
+rv20_encoder_select="h263_encoder"
 rv30_decoder_select="golomb"
 rv40_decoder_select="golomb"
 shorten_decoder_select="golomb"
@@ -1084,25 +1129,27 @@ sonic_encoder_select="golomb"
 sonic_ls_encoder_select="golomb"
 svq3_decoder_select="golomb"
 svq3_decoder_suggest="zlib"
+theora_decoder_select="vp3_decoder"
 tiff_decoder_suggest="zlib"
 tiff_encoder_suggest="zlib"
 tscc_decoder_select="zlib"
 vc1_vaapi_hwaccel_deps="va_va_h"
-vc1_vaapi_hwaccel_select="vaapi"
+vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
 vc1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
-vc1_vdpau_decoder_select="vdpau"
+vc1_vdpau_decoder_select="vdpau vc1_decoder"
 vorbis_decoder_select="fft mdct"
 vorbis_encoder_select="fft mdct"
+vp6a_decoder_select="vp6_decoder"
+vp6f_decoder_select="vp6_decoder"
 wmav1_decoder_select="fft mdct"
 wmav1_encoder_select="fft mdct"
 wmav2_decoder_select="fft mdct"
 wmav2_encoder_select="fft mdct"
-wmv1_encoder_select="aandct"
-wmv2_encoder_select="aandct"
-wmv3_vaapi_hwaccel_deps="va_va_h"
-wmv3_vaapi_hwaccel_select="vaapi"
-wmv3_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
-wmv3_vdpau_decoder_select="vdpau"
+wmv1_encoder_select="h263_encoder"
+wmv2_encoder_select="h263_encoder"
+wmv3_decoder_select="vc1_decoder"
+wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
+wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
 zlib_decoder_select="zlib"
 zlib_encoder_select="zlib"
 zmbv_decoder_select="zlib"
@@ -1136,17 +1183,26 @@ libxvid_encoder_deps="libxvid"
 
 # demuxers / muxers
 ac3_demuxer_deps="ac3_parser"
+asf_stream_muxer_select="asf_muxer"
 avisynth_demuxer_deps="avisynth"
 dirac_demuxer_deps="dirac_parser"
+ipod_muxer_select="mov_muxer"
 libnut_demuxer_deps="libnut"
 libnut_muxer_deps="libnut"
+matroska_audio_muxer_select="matroska_muxer"
 matroska_demuxer_suggest="zlib bzlib"
 mov_demuxer_suggest="zlib"
 mp3_demuxer_deps="mpegaudio_parser"
+mp4_muxer_select="mov_muxer"
+mpegtsraw_demuxer_select="mpegts_demuxer"
+mxf_d10_muxer_select="mxf_muxer"
+psp_muxer_select="mov_muxer"
 redir_demuxer_deps="network"
 rtp_muxer_deps="network rtp_protocol"
 rtsp_demuxer_deps="sdp_demuxer"
 sdp_demuxer_deps="rtp_protocol mpegts_demuxer"
+tg2_muxer_select="mov_muxer"
+tgp_muxer_select="mov_muxer"
 
 # indevs / outdevs
 alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
@@ -1174,6 +1230,7 @@ x11_grab_device_indev_extralibs="-lX11 -lXext"
 # protocols
 gopher_protocol_deps="network"
 http_protocol_deps="network"
+rtmp_protocol_deps="tcp_protocol"
 rtp_protocol_deps="udp_protocol"
 tcp_protocol_deps="network"
 udp_protocol_deps="network"
@@ -1235,7 +1292,6 @@ enable stripping
 enable swscale_alpha
 
 # build settings
-add_cflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112
 SHFLAGS='-shared -Wl,-soname,$$(@F)'
 FFSERVERLDFLAGS=-Wl,-E
 LIBPREF="lib"
@@ -1249,6 +1305,8 @@ SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
 SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
 LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
 
+CC_O='-o $@'
+
 host_cflags='-O3 -g -Wall'
 host_libs='-lm'
 
@@ -1256,12 +1314,13 @@ target_path='.'
 
 # gcc stupidly only outputs the basename of targets with -MM, but we need the
 # full relative path for objects in subdirectories for non-recursive Make.
-DEPEND_CMD='$(CC) $(CFLAGS) -MM $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o,"'
+DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
+DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -MM'
 
 # find source path
 source_path="$(dirname "$0")"
 enable source_path_used
-if test -z "$source_path" -o "$source_path" = "." ; then
+if test -f configure; then
     source_path="$(pwd)"
     disable source_path_used
 else
@@ -1327,8 +1386,6 @@ show_list() {
 for opt do
     optval="${opt#*=}"
     case "$opt" in
-    --extra-cflags=*) add_cflags $optval
-    ;;
     --extra-ldflags=*) add_ldflags $optval
     ;;
     --extra-libs=*) add_extralibs $optval
@@ -1338,11 +1395,11 @@ for opt do
     --enable-debug=*) debuglevel="$optval"
     ;;
     --enable-*=*|--disable-*=*)
-    eval $(echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/')
-    case "$thing" in
-        encoder|decoder|hwaccel|muxer|demuxer|indev|outdev|parser|bsf|protocol|filter) $action ${optval}_${thing} ;;
-        *) die_unknown "$opt" ;;
-    esac
+    eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/')
+    is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
+    eval list=\$$(toupper $thing)_LIST
+    name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
+    $action $(filter "$name" $list)
     ;;
     --enable-?*|--disable-?*)
     eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
@@ -1367,8 +1424,13 @@ for opt do
     optname="${opt%%=*}"
     optname="${optname#--}"
     optname=$(echo "$optname" | sed 's/-/_/g')
-    is_in $optname $CMDLINE_SET || die_unknown $opt
-    eval $optname='$optval'
+    if is_in $optname $CMDLINE_SET; then
+        eval $optname='$optval'
+    elif is_in $optname $CMDLINE_APPEND; then
+        append $optname "$optval"
+    else
+         die_unknown $opt
+    fi
     ;;
     esac
 done
@@ -1389,7 +1451,6 @@ strip="${cross_prefix}${strip}"
 sysinclude_default="${sysroot}/usr/include"
 
 set_default cc nm sysinclude
-as_default=$cc
 enabled cross_compile || host_cc_default=$cc
 set_default host_cc
 
@@ -1418,7 +1479,7 @@ fi
 tmpfile(){
     tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 &&
         (set -C; exec > $tmp) 2>/dev/null ||
-        die "Unable to create temoporary file in $TMPDIR."
+        die "Unable to create temporary file in $TMPDIR."
     append TMPFILES $tmp
     eval $1=$tmp
 }
@@ -1448,15 +1509,25 @@ EOF
     die "Sanity test failed."
 fi
 
-if   $cc --version 2>/dev/null | grep -qi gcc; then
+filter_cflags=echo
+filter_cppflags=echo
+filter_asflags=echo
+
+if   $cc -v 2>&1 | grep -qi ^gcc; then
     cc_type=gcc
+    if ! $cc -dumpversion | grep -q '^2\.'; then
+        CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
+        AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
+    fi
 elif $cc --version 2>/dev/null | grep -q Intel; then
     cc_type=icc
+    CC_DEPFLAGS='-MMD'
+    AS_DEPFLAGS='-MMD'
 elif $cc -v 2>&1 | grep -q xlc; then
     cc_type=xlc
 elif $cc -V 2>/dev/null | grep -q Compaq; then
     cc_type=ccc
-    DEPEND_CMD='$(CC) $(CFLAGS) -M $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o,"'
+    DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -M'
     debuglevel=3
     add_ldflags -Wl,-z,now # calls to libots crash without this
 elif $cc --vsn 2>/dev/null | grep -q RVCT; then
@@ -1470,21 +1541,183 @@ elif $cc --vsn 2>/dev/null | grep -q RVCT; then
         die "Error creating armcc configuration file."
     cc="$cc --arm_linux_config_file=$armcc_conf --translate_gcc"
     as_default="${cross_prefix}gcc"
+    CC_DEPFLAGS='-MMD'
+    AS_DEPFLAGS='-MMD'
+elif $cc -version 2>/dev/null | grep -q TMS470; then
+    cc_type=tms470
+    cc="$cc --gcc --abi=eabi -eo=.o -mc -me"
+    CC_O='-fr=$(@D)'
+    as_default="${cross_prefix}gcc"
+    ld_default="${cross_prefix}gcc"
+    TMPO=$(basename $TMPC .c).o
+    append TMPFILES $TMPO
+    add_cflags -D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__=
+    CC_DEPFLAGS='-ppa -ppd=$(@:.o=.d)'
+    AS_DEPFLAGS='-MMD'
+    filter_cflags=tms470_flags
+    tms470_flags(){
+        for flag; do
+            case $flag in
+                -march=*|-mcpu=*)
+                    case "${flag#*=}" in
+                        armv7-a|cortex-a*)      echo -mv=7a8 ;;
+                        armv7-r|cortex-r*)      echo -mv=7r4 ;;
+                        armv7-m|cortex-m*)      echo -mv=7m3 ;;
+                        armv6*|arm11*)          echo -mv=6   ;;
+                        armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
+                                                echo -mv=5e  ;;
+                        armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
+                    esac
+                    ;;
+                -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
+                -mfpu=vfp)      echo --float_support=vfpv2        ;;
+                -mfpu=softvfp)  echo --float_support=vfplib       ;;
+                -Os)            echo -O3 -mf=2                    ;;
+                -O[0-3])        echo $flag -mf=5                  ;;
+                -g)             echo -g -mn                       ;;
+            esac
+        done
+    }
 fi
 
 test -n "$cc_type" && enable $cc_type || echolog "Unknown C compiler $cc"
 
-set_default as
+: ${as_default:=$cc}
+: ${dep_cc_default:=$cc}
+: ${ld_default:=$cc}
+set_default as dep_cc ld
+
+test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD
+test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD
+
+add_cflags $extra_cflags
+add_asflags $extra_cflags
 
 if test -n "$sysroot"; then
     case "$cc_type" in
         gcc)
-            add_cflags  --sysroot="$sysroot"
+            add_cppflags --sysroot="$sysroot"
             add_ldflags --sysroot="$sysroot"
         ;;
+        tms470)
+            add_cppflags -I"$sysinclude"
+            add_ldflags  --sysroot="$sysroot"
+        ;;
+    esac
+fi
+
+if test "$cpu" = host; then
+    enabled cross_compile && die "--cpu=host makes no sense when cross-compiling."
+
+    case "$cc_type" in
+        gcc)
+            check_native(){
+                $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
+                awk "/$1=/{ match(\$0, /$1=(\\w+)/, a);print a[1];exit }" $TMPE
+            }
+            cpu=$(check_native -march || check_native -mcpu)
+        ;;
     esac
+
+    test "${cpu:-host}" = host && die "--cpu=host not supported with compiler $cc"
 fi
 
+# Add processor-specific flags
+case $cpu in
+    601|ppc601|PowerPC601)
+        cpuflags="-mcpu=601"
+    ;;
+    603*|ppc603*|PowerPC603*)
+        cpuflags="-mcpu=603"
+    ;;
+    604*|ppc604*|PowerPC604*)
+        cpuflags="-mcpu=604"
+    ;;
+    G3|g3|75*|ppc75*|PowerPC75*)
+        cpuflags="-mcpu=750 -mpowerpc-gfxopt"
+    ;;
+    G4|g4|745*|ppc745*|PowerPC745*)
+        cpuflags="-mcpu=7450 -mpowerpc-gfxopt"
+    ;;
+    74*|ppc74*|PowerPC74*)
+        cpuflags="-mcpu=7400 -mpowerpc-gfxopt"
+    ;;
+    G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
+        cpuflags="-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
+    ;;
+    Cell|CELL|cell)
+        cpuflags="-mcpu=cell"
+        enable ldbrx
+    ;;
+    # targets that do NOT support conditional mov (cmov)
+    i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
+        cpuflags="-march=$cpu"
+        disable cmov
+    ;;
+    # targets that do support conditional mov (cmov)
+    i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
+        cpuflags="-march=$cpu"
+        enable cmov
+        enable fast_cmov
+    ;;
+    # targets that do support conditional mov but on which it's slow
+    pentium4|pentium4m|prescott|nocona)
+        cpuflags="-march=$cpu"
+        enable cmov
+        disable fast_cmov
+    ;;
+    sparc64)
+        cpuflags="-mcpu=v9"
+    ;;
+    arm11*|cortex*)
+        cpuflags="-mcpu=$cpu"
+        enable fast_unaligned
+    ;;
+    armv[67]*)
+        cpuflags="-march=$cpu"
+        enable fast_unaligned
+    ;;
+    armv*)
+        cpuflags="-march=$cpu"
+    ;;
+    arm*)
+        cpuflags="-mcpu=$cpu"
+    ;;
+    ev4|ev45|ev5|ev56|pca56|ev6|ev67)
+        enabled ccc && cpuflags="-arch $cpu" || cpuflags="-mcpu=$cpu"
+    ;;
+    bf*)
+        cpuflags="-mcpu=$cpu"
+    ;;
+    mips*|[45]k*|[237]4k*|m4k|r*000|loongson2[ef])
+        cpuflags="-march=$cpu"
+    ;;
+    ap7[02]0[0-2])
+        subarch="avr32_ap"
+        cpuflags="-mpart=$cpu"
+    ;;
+    ap)
+        subarch="avr32_ap"
+        cpuflags="-march=$cpu"
+    ;;
+    uc3[ab]*)
+        subarch="avr32_uc"
+        cpuflags="-mcpu=$cpu"
+    ;;
+    uc)
+        subarch="avr32_uc"
+        cpuflags="-march=$cpu"
+    ;;
+    generic)
+    ;;
+    *)
+        echo "WARNING: Unknown CPU \"$cpu\", ignored."
+    ;;
+esac
+
+add_cflags $cpuflags
+add_asflags $cpuflags
+
 # compiler sanity check
 check_exec <<EOF
 int main(void){ return 0; }
@@ -1498,11 +1731,12 @@ if test "$?" != 0; then
     die "C compiler test failed."
 fi
 
+add_cppflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112
 check_cflags -std=c99
-check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cflags -D_FILE_OFFSET_BITS=64
+check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
 #include <stdlib.h>
 EOF
-check_cc -D_LARGEFILE_SOURCE <<EOF && add_cflags -D_LARGEFILE_SOURCE
+check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE
 #include <stdlib.h>
 EOF
 
@@ -1511,6 +1745,7 @@ case "$arch" in
         arch="alpha"
         enable fast_64bit
         check_cflags -mieee
+        spic=$shared
     ;;
     arm|armv[4567]*l)
         arch="arm"
@@ -1523,24 +1758,29 @@ case "$arch" in
     ia64)
         arch="ia64"
         enable fast_64bit
+        spic=$shared
     ;;
     m68k)
         arch="m68k"
     ;;
     mips|mipsel|IP*)
         arch="mips"
+        spic=$shared
     ;;
     mips64)
         arch="mips"
         subarch="mips64"
         enable fast_64bit
+        spic=$shared
     ;;
     parisc|hppa)
         arch="parisc"
+        spic=$shared
     ;;
     parisc64|hppa64)
         arch="parisc"
         enable fast_64bit
+        spic=$shared
     ;;
     "Power Macintosh"|ppc|powerpc)
         arch="ppc"
@@ -1560,11 +1800,13 @@ case "$arch" in
     ;;
     sparc)
         arch="sparc"
+        spic=$shared
     ;;
     sun4u|sparc64)
         arch="sparc"
         subarch="sparc64"
         enable fast_64bit
+        spic=$shared
     ;;
     i386|i486|i586|i686|i86pc|BePC)
         arch="x86"
@@ -1577,7 +1819,7 @@ case "$arch" in
         enable cmov
         enable fast_cmov
         enable fast_unaligned
-        check_cc <<EOF && enable fast_64bit && subarch="x86_64"
+        check_cc <<EOF && enable fast_64bit && subarch="x86_64" && spic=$shared
         int test[sizeof(char*) - 7];
 EOF
     ;;
@@ -1587,13 +1829,15 @@ EOF
 esac
 
 enable $arch $subarch
+enabled spic && enable pic
 
 # OS specific
 case $target_os in
     beos|haiku|zeta)
         prefix_default="$HOME/config"
         # helps building libavcodec
-        add_cflags -DPIC -fomit-frame-pointer
+        add_cppflags -DPIC
+        add_cflags -fomit-frame-pointer
         # 3 gcc releases known for BeOS, each with ugly bugs
         gcc_version="$($cc -v 2>&1 | grep version | cut -d ' ' -f3-)"
         case "$gcc_version" in
@@ -1620,28 +1864,28 @@ case $target_os in
         FFSERVERLDFLAGS=""
         SHFLAGS='-shared -Wl,-h,$$(@F)'
         network_extralibs="-lsocket -lnsl"
-        add_cflags -D__EXTENSIONS__
+        add_cppflags -D__EXTENSIONS__
         ;;
     netbsd)
         oss_indev_extralibs="-lossaudio"
         oss_outdev_extralibs="-lossaudio"
         ;;
     openbsd)
-        disable need_memalign
-        LIBOBJFLAGS='$(PIC)'
+        enable malloc_aligned
+        enable pic
         SHFLAGS='-shared'
         oss_indev_extralibs="-lossaudio"
         oss_outdev_extralibs="-lossaudio"
         ;;
     freebsd|dragonfly)
-        disable need_memalign
+        enable malloc_aligned
         ;;
     bsd/os)
         osextralibs="-lpoll -lgnugetopt"
         strip="strip -d"
         ;;
     darwin)
-        disable need_memalign
+        enable malloc_aligned
         SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR) -Wl,-read_only_relocs,suppress'
         strip="strip -x"
         FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
@@ -1651,13 +1895,21 @@ case $target_os in
         FFSERVERLDFLAGS=-Wl,-bind_at_load
         objformat="macho"
         enabled x86_64 && objformat="macho64"
+        enabled shared ||
+            { check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
         ;;
     mingw32*)
-        target_os=mingw32
+        if test $target_os = "mingw32ce"; then
+            disable network
+        else
+            target_os=mingw32
+        fi
         LIBTARGET=i386
         if enabled x86_64; then
-            disable need_memalign
+            enable malloc_aligned
             LIBTARGET=x64
+        elif enabled arm; then
+            LIBTARGET=arm
         fi
         shlibdir_default="$bindir_default"
         disable ffserver
@@ -1667,7 +1919,9 @@ case $target_os in
         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
         SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)'
         SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \
-            install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"'
+            install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"; \
+            install -d "$(LIBDIR)"; \
+            install -m 644 $(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) "$(LIBDIR)/lib$(SLIBNAME:$(SLIBSUF)=.dll.a)"'
         SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"'
         SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
         objformat="win32"
@@ -1676,9 +1930,9 @@ case $target_os in
         if ! enabled x86_64; then
             check_cpp_condition _mingw.h "(__MINGW32_MAJOR_VERSION > 3) || (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
                 die "ERROR: MinGW runtime version must be >= 3.15."
-            enabled_any avisynth vfwcap_demuxer &&
+            enabled_any avisynth vfwcap_indev &&
                 { check_cpp_condition w32api.h "(__W32API_MAJOR_VERSION > 3) || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION >= 13)" ||
-                  die "ERROR: avisynth and vfwcap_demuxer require w32api version 3.13 or later."; }
+                  die "ERROR: avisynth and vfwcap_indev require w32api version 3.13 or later."; }
             fi
         ;;
     cygwin*)
@@ -1795,108 +2049,12 @@ enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
 
 check_deps $ARCH_EXT_LIST
 
-test -z "$need_memalign" && need_memalign="$mmx"
-
-#Darwin CC versions
-if test $target_os = darwin; then
-    if enabled xlc; then
-        add_cflags -qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto
-    else
-        add_cflags -pipe
-        check_cflags -force_cpusubtype_ALL
-        check_cflags -Wno-sign-compare
-        enabled shared || check_cflags -mdynamic-no-pic
-    fi
-fi
-
 disabled optimizations || check_cflags -fomit-frame-pointer
 
-# Add processor-specific flags
-if test $cpu != "generic"; then
-    warn_altivec(){
-        $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
-    }
-    case $cpu in
-        601|ppc601|PowerPC601)
-            add_cflags -mcpu=601
-            warn_altivec enabled PPC601
-        ;;
-        603*|ppc603*|PowerPC603*)
-            add_cflags -mcpu=603
-            warn_altivec enabled PPC603
-        ;;
-        604*|ppc604*|PowerPC604*)
-            add_cflags -mcpu=604
-            warn_altivec enabled PPC604
-        ;;
-        G3|g3|75*|ppc75*|PowerPC75*)
-            add_cflags -mcpu=750 -mpowerpc-gfxopt
-            warn_altivec enabled PPC75x
-        ;;
-        G4|g4|745*|ppc745*|PowerPC745*)
-            add_cflags -mcpu=7450 -mpowerpc-gfxopt
-            warn_altivec disabled PPC745x
-        ;;
-        74*|ppc74*|PowerPC74*)
-            add_cflags -mcpu=7400 -mpowerpc-gfxopt
-            warn_altivec disabled PPC74xx
-        ;;
-        G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
-            add_cflags -mcpu=970 -mpowerpc-gfxopt -mpowerpc64
-            warn_altivec disabled PPC970
-        ;;
-        Cell|CELL|cell)
-            add_cflags -mcpu=cell
-            warn_altivec disabled Cell
-            enable ldbrx
-        ;;
-        # targets that do NOT support conditional mov (cmov)
-        i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
-            add_cflags -march=$cpu
-            disable cmov
-        ;;
-        # targets that do support conditional mov (cmov)
-        i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
-            add_cflags -march=$cpu
-            enable cmov
-            enable fast_cmov
-        ;;
-        # targets that do support conditional mov but on which it's slow
-        pentium4|pentium4m|prescott|nocona)
-            add_cflags -march=$cpu
-            enable cmov
-            disable fast_cmov
-        ;;
-        sparc64)
-            add_cflags -mcpu=v9
-        ;;
-        arm11*|cortex*)
-            add_cflags -mcpu=$cpu
-            enable fast_unaligned
-        ;;
-        armv[67]*)
-            add_cflags -march=$cpu
-            enable fast_unaligned
-        ;;
-        armv*)
-            add_cflags -march=$cpu
-        ;;
-        arm*)
-            add_cflags -mcpu=$cpu
-        ;;
-        ev4|ev45|ev5|ev56|pca56|ev6|ev67)
-            enabled ccc && add_cflags -arch $cpu || add_cflags -mcpu=$cpu
-        ;;
-        bf*)
-            add_cflags -mcpu=$cpu
-        ;;
-        mips*|[45]k*|[237]4k*|m4k|r*000|loongson2[ef])
-            add_cflags -march=$cpu
-        ;;
-        *)
-            echo "WARNING: Unknown CPU \"$cpu\", ignored."
-        ;;
-    esac
+if enabled pic; then
+    add_cppflags -DPIC
+    add_cflags   -fPIC
+    add_asflags  -fPIC
 fi
 
 check_cc <<EOF || die "Symbol mangling check failed."
@@ -1909,7 +2067,80 @@ check_cc <<EOF && enable inline_asm
 void foo(void) { __asm__ volatile ("" ::); }
 EOF
 
-if enabled x86; then
+_restrict=
+for restrict_keyword in restrict __restrict__ __restrict; do
+    check_cc <<EOF && _restrict=$restrict_keyword && break
+void foo(char * $restrict_keyword p);
+EOF
+done
+
+check_cc <<EOF && enable attribute_packed
+struct { int x; } __attribute__((packed)) x;
+EOF
+
+check_cc <<EOF || die "endian test failed"
+unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
+EOF
+od -A n -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
+
+if enabled arm; then
+
+    check_ld <<EOF && enable vfp_args
+__asm__ (".eabi_attribute 28, 1");
+int main(void) { return 0; }
+EOF
+
+    # We have to check if pld is a nop and disable it.
+    check_asm pld '"pld [r0]"'
+
+    enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"'
+    enabled armv6   && check_asm armv6   '"sadd16 r0, r0, r0"'
+    enabled armv6t2 && check_asm armv6t2 '"movt r0, #0"'
+    enabled armvfp  && check_asm armvfp  '"fadds s0, s0, s0"'
+    enabled iwmmxt  && check_asm iwmmxt  '"wunpckelub wr6, wr4"'
+    enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
+
+elif enabled mips; then
+
+    check_asm loongson '"dmult.g $1, $2, $3"'
+    enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
+
+elif enabled ppc; then
+
+    check_asm dcbzl     '"dcbzl 0, 1"'
+    check_asm ppc4xx    '"maclhw r10, r11, r12"'
+    check_asm xform_asm '"lwzx 0, %y0" :: "Z"(*(int*)0)'
+
+    # AltiVec flags: The FSF version of GCC differs from the Apple version
+    if enabled altivec; then
+        check_cflags -maltivec -mabi=altivec &&
+        { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
+        check_cflags -faltivec
+
+        # check if our compiler supports Motorola AltiVec C API
+        check_cc <<EOF || disable altivec
+$inc_altivec_h
+int main(void) {
+    vector signed int v1, v2, v3;
+    v1 = vec_add(v2,v3);
+    return 0;
+}
+EOF
+
+        # check if our compiler supports braces for vector declarations
+        check_cc <<EOF || die "You need a compiler that supports {} in AltiVec vector declarations."
+$inc_altivec_h
+int main (void) { (vector int) {1}; return 0; }
+EOF
+    fi
+
+elif enabled sparc; then
+
+    enabled vis && check_asm vis '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc &&
+        add_cflags -mcpu=ultrasparc -mtune=ultrasparc
+
+elif enabled x86; then
+
     # check whether EBP is available on x86
     # As 'i' is stored on the stack, this program will crash
     # if the base pointer is used to access it because the
@@ -1952,64 +2183,9 @@ EOF
         *)                    append YASMFLAGS "-DPREFIX"  ;;
     esac
     disabled yasm || { check_yasm "pabsw xmm0, xmm0" && enable yasm; }
-fi
-
-# check for assembler specific support
-
-enabled mips && check_asm loongson '"dmult.g $1, $2, $3"'
-
-enabled ppc && check_asm dcbzl '"dcbzl 0, 1"'
-enabled ppc && check_asm ppc4xx '"maclhw r10, r11, r12"'
-enabled ppc && check_asm xform_asm '"lwzx 0, %y0" :: "Z"(*(int*)0)'
-
-# check for SIMD availability
-
-# AltiVec flags: The FSF version of GCC differs from the Apple version
-if enabled altivec; then
-    check_cflags -maltivec -mabi=altivec &&
-        { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
-        check_cflags -faltivec
-
-    # check if our compiler supports Motorola AltiVec C API
-    check_cc <<EOF || disable altivec
-$inc_altivec_h
-int main(void) {
-    vector signed int v1, v2, v3;
-    v1 = vec_add(v2,v3);
-    return 0;
-}
-EOF
 
-    # check if our compiler supports braces for vector declarations
-    check_cc <<EOF || die "You need a compiler that supports {} in AltiVec vector declarations."
-$inc_altivec_h
-int main (void) { (vector int) {1}; return 0; }
-EOF
 fi
 
-# We have to check if pld is a nop and disable it.
-enabled arm     && check_asm pld     '"pld [r0]"'
-enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"'
-enabled armv6   && check_asm armv6   '"sadd16 r0, r0, r0"'
-enabled armv6t2 && check_asm armv6t2 '"movt r0, #0"'
-enabled armvfp  && check_asm armvfp  '"fadds s0, s0, s0"'
-enabled iwmmxt  && check_asm iwmmxt  '"wunpckelub wr6, wr4"'
-enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
-enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
-enabled vis     && check_asm vis     '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc
-
-enabled vis && add_cflags -mcpu=ultrasparc -mtune=ultrasparc
-
-# ---
-# big/little-endian test
-check_cc <<EOF || die "endian test failed"
-unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
-EOF
-od -A n -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
-
-# ---
-# check availability of some header files
-
 if check_func dlopen; then
     ldl=
 elif check_func dlopen -ldl; then
@@ -2023,6 +2199,7 @@ check_func  fork
 check_func  gethrtime
 check_func  getrusage
 check_func  inet_aton $network_extralibs
+check_func  isatty
 check_func  memalign
 check_func  mkstemp
 check_func  posix_memalign
@@ -2043,7 +2220,8 @@ check_header vdpau/vdpau.h
 check_header vdpau/vdpau_x11.h
 check_header X11/extensions/XvMClib.h
 
-if ! enabled_any memalign memalign_hack posix_memalign && enabled need_memalign ; then
+if ! enabled_any memalign memalign_hack posix_memalign malloc_aligned &&
+     enabled_any $need_memalign ; then
     die "Error, no aligned memory allocator but SSE enabled, disable it or use --enable-memalign-hack."
 fi
 
@@ -2079,19 +2257,19 @@ done
 check_lib math.h sin -lm
 check_lib va/va.h vaInitialize -lva
 
-# test for C99 functions in math.h
-for func in llrint log2 lrint lrintf round roundf truncf; do
-    check_exec <<EOF && enable $func || disable $func
-#include <math.h>
-int main(void) { return ($func(3.999f) > 0)?0:1; }
-EOF
-done
+check_func llrint
+check_func log2
+check_func lrint
+check_func lrintf
+check_func round
+check_func roundf
+check_func truncf
 
 # these are off by default, so fail if requested and not available
 enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
 enabled libdirac   && add_cflags $(pkg-config --cflags dirac) &&
-                      require  libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init -ldirac_decoder &&
-                      require  libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init -ldirac_encoder
+                      require  libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init $(pkg-config --libs dirac) &&
+                      require  libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init $(pkg-config --libs dirac)
 enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
 enabled libfaad    && require2 libfaad faad.h faacDecOpen -lfaad
 enabled libgsm     && require  libgsm gsm.h gsm_create -lgsm
@@ -2105,7 +2283,7 @@ enabled libschroedinger && add_cflags $(pkg-config --cflags schroedinger-1.0) &&
 enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
 enabled libtheora  && require  libtheora theora/theora.h theora_info_init -ltheora -logg
 enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
-enabled libx264    && require  libx264 x264.h x264_encoder_open -lx264 -lm &&
+enabled libx264    && require  libx264 x264.h x264_encoder_encode -lx264 -lm &&
                       { check_cpp_condition x264.h "X264_BUILD >= 65" ||
                         die "ERROR: libx264 version must be >= 0.65."; }
 enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore
@@ -2120,17 +2298,6 @@ if enabled libdc1394; then
     die "ERROR: No version of libdc1394 found "
 fi
 
-
-_restrict=
-for restrict_keyword in restrict __restrict__ __restrict; do
-    check_cc <<EOF && _restrict=$restrict_keyword && break
-void foo(char * $restrict_keyword p);
-EOF
-done
-
-##########################################
-# SDL check
-
 disable sdl_too_old
 disable sdl
 SDL_CONFIG="${cross_prefix}sdl-config"
@@ -2159,27 +2326,23 @@ fi
 
 texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
 
-##########################################
-# Network check
-
 if enabled network; then
     check_type "sys/types.h sys/socket.h" socklen_t
     # Prefer arpa/inet.h over winsock2
     if check_header arpa/inet.h ; then
         check_func closesocket
     elif check_header winsock2.h ; then
-        network_extralibs="-lws2_32"
+        check_func_headers winsock2.h closesocket -lws2 && \
+            network_extralibs="-lws2" || \
+        { check_func_headers winsock2.h closesocket -lws2_32 && \
+            network_extralibs="-lws2_32"; }
         check_type ws2tcpip.h socklen_t
-        check_func_headers winsock2.h closesocket
     else
         disable network
     fi
 fi
 
-##########################################
-# IPv6 check
-
-enabled network && enabled ipv6 && check_ld <<EOF && enable ipv6 || disable ipv6
+enabled_all network ipv6 && check_ld <<EOF || disable ipv6
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -2211,11 +2374,10 @@ check_header dev/ic/bt8xx.h
 check_header sys/soundcard.h
 check_header soundcard.h
 
-enabled alsa_demuxer || enabled alsa_muxer && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
+enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
 
-enabled jack_demuxer && check_lib2 jack/jack.h jack_client_open -ljack
+enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
 
-# deal with the X11 frame grabber
 enabled x11grab                         &&
 check_header X11/Xlib.h                 &&
 check_header X11/extensions/XShm.h      &&
@@ -2260,7 +2422,6 @@ fi
 check_cflags -fno-math-errno
 check_cflags -fno-signed-zeros
 
-# add some flags for Intel C Compiler
 if enabled icc; then
     # Just warnings, no remarks
     check_cflags -w1
@@ -2284,16 +2445,8 @@ elif enabled ccc; then
     add_cflags -msg_disable nomainieee
     add_cflags -msg_disable ptrmismatch1
     add_cflags -msg_disable unreachcode
-fi
-
-# PIC flags for shared library objects where they are needed
-if enabled shared; then
-    # LIBOBJFLAGS may have already been set in the OS configuration
-    if test -z "$LIBOBJFLAGS" ; then
-        case "${subarch-$arch}" in
-            x86_64|ia64|alpha|sparc*|power*|parisc*|mips*) LIBOBJFLAGS='$(PIC)' ;;
-        esac
-    fi
+elif enabled gcc; then
+    check_cflags -fno-tree-vectorize
 fi
 
 if enabled gprof; then
@@ -2311,8 +2464,8 @@ enabled_any $BSF_LIST          && enable bsfs
 enabled_any $DEMUXER_LIST      && enable demuxers
 enabled_any $MUXER_LIST        && enable muxers
 enabled_any $FILTER_LIST       && enable filters
-enabled_any $INDEV_LIST        && enable demuxers
-enabled_any $OUTDEV_LIST       && enable muxers
+enabled_any $INDEV_LIST        && enable indevs
+enabled_any $OUTDEV_LIST       && enable outdevs
 enabled_any $PROTOCOL_LIST     && enable protocols
 
 enabled_any $THREADS_LIST      && enable threads
@@ -2451,6 +2604,9 @@ echo "#define FFMPEG_CONFIG_H" >> $TMPH
 echo "#define FFMPEG_CONFIGURATION \"$(c_escape $FFMPEG_CONFIGURATION)\"" >> $TMPH
 echo "#define FFMPEG_DATADIR \"$(eval c_escape $datadir)\"" >> $TMPH
 
+echo "ifndef FFMPEG_CONFIG_MAK" >> config.mak
+echo "FFMPEG_CONFIG_MAK=1" >> config.mak
+
 echo "FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION" >> config.mak
 echo "prefix=$prefix" >> config.mak
 echo "LIBDIR=\$(DESTDIR)$libdir" >> config.mak
@@ -2464,6 +2620,8 @@ echo "SRC_PATH_BARE=$source_path" >> config.mak
 echo "BUILD_ROOT=\"$PWD\"" >> config.mak
 echo "CC=$cc" >> config.mak
 echo "AS=$as" >> config.mak
+echo "LD=$ld" >> config.mak
+echo "DEPCC=$dep_cc" >> config.mak
 echo "YASM=$yasmexe" >> config.mak
 echo "AR=$ar" >> config.mak
 echo "RANLIB=$ranlib" >> config.mak
@@ -2472,13 +2630,14 @@ enabled stripping &&
     echo "STRIP=$strip" >> config.mak ||
     echo "STRIP=echo ignoring strip" >> config.mak
 
-echo "OPTFLAGS=$CFLAGS" >> config.mak
+echo "CPPFLAGS=$CPPFLAGS" >> config.mak
+echo "CFLAGS=$CFLAGS" >> config.mak
+echo "ASFLAGS=$ASFLAGS" >> config.mak
+echo "CC_O=$CC_O" >> config.mak
 echo "LDFLAGS=$LDFLAGS" >> config.mak
 echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
 echo "SHFLAGS=$SHFLAGS" >> config.mak
 echo "YASMFLAGS=$YASMFLAGS" >> config.mak
-echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
-echo "BUILD_STATIC=$static" >> config.mak
 echo "BUILDSUF=$build_suffix" >> config.mak
 echo "FULLNAME=$FULLNAME" >> config.mak
 echo "LIBPREF=$LIBPREF" >> config.mak
@@ -2488,7 +2647,11 @@ echo "SLIBPREF=$SLIBPREF" >> config.mak
 echo "SLIBSUF=$SLIBSUF" >> config.mak
 echo "EXESUF=$EXESUF" >> config.mak
 echo "EXTRA_VERSION=$extra_version" >> config.mak
-echo "DEPEND_CMD=$DEPEND_CMD" >> config.mak
+echo "DEPFLAGS=$DEPFLAGS" >> config.mak
+echo "CCDEP=$CCDEP" >> config.mak
+echo "ASDEP=$ASDEP" >> config.mak
+echo "CC_DEPFLAGS=$CC_DEPFLAGS" >> config.mak
+echo "AS_DEPFLAGS=$AS_DEPFLAGS" >> config.mak
 echo "HOSTCC=$host_cc" >> config.mak
 echo "HOSTCFLAGS=$host_cflags" >> config.mak
 echo "HOSTEXESUF=$HOSTEXESUF" >> config.mak
@@ -2497,11 +2660,6 @@ echo "HOSTLIBS=$host_libs" >> config.mak
 echo "TARGET_EXEC=$target_exec" >> config.mak
 echo "TARGET_PATH=$target_path" >> config.mak
 
-if enabled bigendian; then
-    echo "WORDS_BIGENDIAN=yes" >> config.mak
-    echo "#define WORDS_BIGENDIAN 1" >> $TMPH
-fi
-
 if enabled sdl; then
     echo "SDL_LIBS=$("${SDL_CONFIG}" --libs)" >> config.mak
     echo "SDL_CFLAGS=$("${SDL_CONFIG}" --cflags)" >> config.mak
@@ -2529,8 +2687,6 @@ get_version LIBAVUTIL   libavutil/avutil.h
 get_version LIBAVFILTER libavfilter/avfilter.h
 
 if enabled shared; then
-    echo "BUILD_SHARED=yes" >> config.mak
-    echo "PIC=-fPIC -DPIC" >> config.mak
     echo "LIBTARGET=${LIBTARGET}" >> config.mak
     echo "SLIBNAME=${SLIBNAME}" >> config.mak
     echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak
@@ -2563,7 +2719,7 @@ print_config CONFIG_ $TMPH config.mak $CONFIG_LIST       \
 
 echo "#define restrict $_restrict" >> $TMPH
 
-if enabled small; then
+if enabled small || disabled optimizations; then
     echo "#define av_always_inline"  >> $TMPH
 fi
 
@@ -2576,6 +2732,7 @@ enabled asmalign_pot &&
 echo "#define EXTERN_PREFIX \"${extern_prefix}\"" >> $TMPH
 
 echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
+echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
 
 # Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
 cmp -s $TMPH config.h &&
@@ -2587,25 +2744,15 @@ if enabled source_path_used; then
     DIRS="\
         doc               \
         libavcodec        \
-        libavcodec/alpha  \
-        libavcodec/arm    \
-        libavcodec/bfin   \
-        libavcodec/mlib   \
-        libavcodec/ppc    \
-        libavcodec/sh4    \
-        libavcodec/sparc  \
-        libavcodec/x86    \
+        libavcodec/$arch  \
         libavdevice       \
         libavfilter       \
         libavformat       \
         libavutil         \
+        libavutil/$arch   \
         libpostproc       \
         libswscale        \
-        libswscale/bfin   \
-        libswscale/mlib   \
-        libswscale/ppc    \
-        libswscale/sparc  \
-        libswscale/x86    \
+        libswscale/$arch  \
         tests             \
         tools             \
         "