view configure @ 36311:9fab03575b89

configure: prevent future ffmpeg from failing to build Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
author michael
date Tue, 06 Aug 2013 16:22:46 +0000
parents 4508e308371a
children ebf1b3af62cd
line wrap: on
line source

#! /bin/sh
#
# Original version (C) 2000 Pontscho/fresh!mindworkz
#                      pontscho@makacs.poliod.hu
#
# History / Contributors: Check the Subversion log.
#
# Cleanups all over the place (c) 2001 pl
#
#
# This configure script is *not* autoconf-based and has different semantics.
# It attempts to autodetect all settings and options where possible. It is
# possible to override autodetection with the --enable-option/--disable-option
# command line parameters.  --enable-option forces the option on skipping
# autodetection. Yes, this means that compilation may fail and yes, this is not
# how autoconf-based configure scripts behave.
#
# configure generates a series of configuration files:
#  - config.h contains #defines that are used in the C code.
#  - config.mak is included from the Makefiles.
#
# If you want to add a new check for $feature, look at the existing checks
# and try to use helper functions where you can.
#
# Furthermore you need to add the variable _feature to the list of default
# settings and set it to one of yes/no/auto. Also add appropriate
# --enable-feature/--disable-feature command line options.
# The results of the check should be written to config.h and config.mak
# at the end of this script. The variable names used for this should be
# uniform, i.e. if the option is named 'feature':
#
# _feature     : should have a value of yes/no/auto
# def_feature  : '#define ... 1' or '#undef ...' for conditional compilation
# ld_feature   : '-L/path/dir -lfeature' GCC options
#
#############################################################################

# Prevent locale nonsense from breaking basic text processing utilities
export LC_ALL=C

# Store the configure line that was used
configuration="$*"

# utility functions
tolower() {
  tr '[A-Z]' '[a-z]'
}

toupper() {
  tr '[a-z]' '[A-Z]'
}

# Prefer these macros to full length text !
# These macros only return an error code - NO display is done
compile_check() {
  source="$1"
  shift
  echo >> "$TMPLOG"
  cat "$source" >> "$TMPLOG"
  echo >> "$TMPLOG"
  echo "$_cc $WARNFLAGS $WARN_CFLAGS $CFLAGS $source $extra_cflags $ld_static $extra_ldflags $libs_mplayer $libs_mencoder -o $TMPEXE $@ -lm" >> "$TMPLOG"
  rm -f "$TMPEXE"
  $_cc $WARNFLAGS $WARN_CFLAGS $CFLAGS "$source" $extra_cflags $ld_static $extra_ldflags $libs_mplayer $libs_mencoder -o "$TMPEXE" "$@" -lm >> "$TMPLOG" 2>&1
  TMPRES="$?"
  echo >> "$TMPLOG"
  echo >> "$TMPLOG"
  return "$TMPRES"
}

cc_check() {
  compile_check $TMPC $@
}

cxx_check() {
  compile_check $TMPCPP $@ -lstdc++
}

cpp_condition_check() {
  inc=""
  if test -n "$1" ; then
    inc="#include <$1>"
  fi
  cat > $TMPC << EOF
$inc
#if !($2)
#error condition not true: $2
#endif
int main(void) { return 0; }
EOF
  shift 2
  compile_check $TMPC $@
}

cflag_check() {
  cat > $TMPC << EOF
int main(void) { return 0; }
EOF
  compile_check $TMPC $@
}

header_check() {
  cat > $TMPC << EOF
#include <$1>
int main(void) { return 0; }
EOF
  shift
  compile_check $TMPC $@
}

return_check() {
  cat > $TMPC << EOF
#include <$1>
int main(void) { return $2; }
EOF
  shift 2
  compile_check $TMPC $@
}

statement_check() {
  cat > $TMPC << EOF
#include <$1>
int main(void) { $2; return 0; }
EOF
  shift
  shift
  compile_check $TMPC $@
}

define_statement_check() {
  cat > $TMPC << EOF
#define $1
#include <$2>
int main(void) { $3; return 0; }
EOF
  shift 3
  compile_check $TMPC $@
}

return_statement_check() {
  cat > $TMPC << EOF
#include <$1>
int main(void) { $2; return $3; }
EOF
  shift 3
  compile_check $TMPC $@
}

inline_asm_check() {
  cat > $TMPC << EOF
int main(void) { __asm__ volatile ($1); return 0; }
EOF
  shift
  compile_check $TMPC $@
}

# The following checks are special and should only be used with broken and
# non-self-sufficient headers that do not include all of their dependencies.

header_check_broken() {
  cat > $TMPC << EOF
#include <$1>
#include <$2>
int main(void) { return 0; }
EOF
  shift
  shift
  compile_check $TMPC $@
}

statement_check_broken() {
  cat > $TMPC << EOF
#include <$1>
#include <$2>
int main(void) { $3; return 0; }
EOF
  shift 3
  compile_check $TMPC $@
}

yasm_check() {
  echo >> "$TMPLOG"
  cat "$TMPS" >> "$TMPLOG"
  echo >> "$TMPLOG"
  echo "$_yasm $YASMFLAGS -o $TMPEXE $TMPS $@" >> "$TMPLOG"
  rm -f "$TMPEXE"
  $_yasm $YASMFLAGS -o "$TMPEXE" "$TMPS" "$@" >> "$TMPLOG" 2>&1
  TMPRES="$?"
  echo >> "$TMPLOG"
  echo >> "$TMPLOG"
  return "$TMPRES"
}

tmp_run() {
  "$TMPEXE" >> "$TMPLOG" 2>&1
}

# Display error message, flush temporary file, exit.
die () {
  echo
  echo "Error: $@" >&2
  echo >&2
  rm -f "$TMPEXE" "$TMPC" "$TMPS" "$TMPCPP"
  echo "Check \"$TMPLOG\" if you do not understand why it failed."
  exit 1
}

# OS test booleans functions
issystem() {
  test "$(echo $system_name | tolower)" = "$(echo $1 | tolower)"
}
aix()       { issystem "AIX"; }
amigaos()   { issystem "AmigaOS"; }
bsdos()     { issystem "BSD/OS"; }
cygwin()    { issystem "CYGWIN"; }
darwin()    { issystem "Darwin"; }
dragonfly() { issystem "DragonFly"; }
freebsd()   { issystem "FreeBSD" || issystem "GNU/kFreeBSD"; }
gnu()       { issystem "GNU"; }
hpux()      { issystem "HP-UX"; }
irix()      { issystem "IRIX"; }
linux()     { issystem "Linux"; }
mingw32()   { issystem "MINGW32"; }
morphos()   { issystem "MorphOS"; }
netbsd()    { issystem "NetBSD"; }
openbsd()   { issystem "OpenBSD"; }
os2()       { issystem "OS/2"; }
qnx()       { issystem "QNX"; }
sunos()     { issystem "SunOS"; }
wine()      { issystem "Wine"; }
win32()     { cygwin || mingw32 || wine; }

# arch test boolean functions
# x86/x86pc is used by QNX
x86_32() {
  case "$host_arch" in
    i[3-9]86|x86|x86pc|k5|k6|k6-2|k6-3|pentium*|athlon*|i586-i686) return 0 ;;
    *) return 1 ;;
  esac
}

x86_64() {
  case "$host_arch" in
    x86_64|amd64) return 0 ;;
    *) return 1 ;;
  esac
}

x86() {
  x86_32 || x86_64
}

ppc() {
  case "$host_arch" in
    ppc*|powerpc*) return 0;;
    *) return 1;;
  esac
}

sparc() {
  case "$host_arch" in
    sparc*) return 0;;
    *) return 1;;
  esac
}

alpha() {
  case "$host_arch" in
    alpha*) return 0;;
    *) return 1;;
  esac
}

arm() {
  case "$host_arch" in
    arm*) return 0;;
    *) return 1;;
  esac
}

# Use this before starting a check
echocheck() {
  echo "============ Checking for $@ ============" >> "$TMPLOG"
  echo ${_echo_n} "Checking for $@ ... ${_echo_c}"
}

# Use this to echo the results of a check
echores() {
  if test "$res_comment" ; then
    res_comment="($res_comment)"
  fi
  echo "Result is: $@ $res_comment" >> "$TMPLOG"
  echo "##########################################" >> "$TMPLOG"
  echo "" >> "$TMPLOG"
  echo "$@ $res_comment"
  res_comment=""
}
#############################################################################

# Check how echo works in this /bin/sh
case $(echo -n) in
  -n)   _echo_n=        _echo_c='\c'    ;;      # SysV echo
  *)    _echo_n='-n '   _echo_c=        ;;      # BSD echo
esac

msg_lang_all=$(echo help/help_mp-??.h help/help_mp-??_??.h | sed -e "s:help/help_mp-\(..\).h:\1:g" -e "s:help/help_mp-\(.....\).h:\1:g")
man_lang_all=$(echo DOCS/man/??/mplayer.1 DOCS/man/??_??/mplayer.1 | sed -e "s:DOCS/man/\(..\)/mplayer.1:\1:g" -e "s:DOCS/man/\(.._..\)/mplayer.1:\1:g")
doc_lang_all=$(echo DOCS/xml/??/ DOCS/xml/??_??/ | sed -e "s:DOCS/xml/\(..\)/:\1:g" -e "s:DOCS/xml/\(.._..\)/:\1:g")

show_help(){
cat << EOF
Usage: $0 [OPTIONS]...

Configuration:
  -h, --help             display this help and exit

Installation directories:
  --prefix=DIR           prefix directory for installation [/usr/local]
  --bindir=DIR           directory for installing binaries [PREFIX/bin]
  --datadir=DIR          directory for installing machine independent
                         data files (skins, etc) [PREFIX/share/mplayer]
  --mandir=DIR           directory for installing man pages [PREFIX/share/man]
  --confdir=DIR          directory for installing configuration files
                         [PREFIX/etc/mplayer]
  --libdir=DIR           directory for object code libraries [PREFIX/lib]
  --codecsdir=DIR        directory for binary codecs [LIBDIR/codecs]

Optional features:
  --disable-mencoder     disable MEncoder (A/V encoder) compilation [enable]
  --disable-mplayer      disable MPlayer compilation [enable]
  --enable-gui           enable GMPlayer compilation (GTK+ GUI) [disable]
  --enable-gtk1          force using GTK 1.2 for the GUI  [disable]
  --enable-termcap       use termcap database for key codes [autodetect]
  --enable-termios       use termios database for key codes [autodetect]
  --disable-iconv        disable iconv for encoding conversion [autodetect]
  --disable-langinfo     do not use langinfo [autodetect]
  --enable-lirc          enable LIRC (remote control) support [autodetect]
  --enable-lircc         enable LIRCCD (LIRC client daemon) input [autodetect]
  --enable-joystick      enable joystick support [disable]
  --enable-apple-remote  enable Apple Remote input (Mac OS X only) [autodetect]
  --enable-apple-ir      enable Apple IR Remote input (Linux only) [autodetect]
  --disable-vm           disable X video mode extensions [autodetect]
  --disable-xf86keysym   disable support for multimedia keys [autodetect]
  --enable-radio         enable radio interface [disable]
  --enable-radio-capture enable radio capture (through PCI/line-in) [disable]
  --disable-radio-v4l2   disable Video4Linux2 radio interface [autodetect]
  --disable-radio-bsdbt848   disable BSD BT848 radio interface [autodetect]
  --disable-tv           disable TV interface (TV/DVB grabbers) [enable]
  --disable-tv-v4l1      disable Video4Linux TV interface [autodetect]
  --disable-tv-v4l2      disable Video4Linux2 TV interface [autodetect]
  --disable-tv-bsdbt848  disable BSD BT848 interface [autodetect]
  --disable-pvr          disable Video4Linux2 MPEG PVR [autodetect]
  --disable-rtc          disable RTC (/dev/rtc) on Linux [autodetect]
  --disable-networking   disable networking [enable]
  --enable-winsock2_h    enable winsock2_h [autodetect]
  --enable-smb           enable Samba (SMB) input [autodetect]
  --enable-live          enable LIVE555 Streaming Media [autodetect]
  --enable-nemesi        enable Nemesi Streaming Media [autodetect]
  --enable-librtmp       enable RTMPDump Streaming Media [autodetect]
  --disable-vcd          disable VCD support [autodetect]
  --disable-bluray       disable Blu-ray support [autodetect]
  --disable-dvdnav       disable libdvdnav [autodetect]
  --disable-dvdread      disable libdvdread [autodetect]
  --disable-dvdread-internal  disable internal libdvdread [autodetect]
  --disable-libdvdcss-internal  disable internal libdvdcss [autodetect]
  --disable-cdparanoia   disable cdparanoia [autodetect]
  --disable-cddb         disable cddb [autodetect]
  --disable-bitmap-font  disable bitmap font support [enable]
  --disable-freetype     disable FreeType 2 font rendering [autodetect]
  --disable-fontconfig   disable fontconfig font lookup [autodetect]
  --disable-unrarexec    disable using of UnRAR executable [enabled]
  --enable-menu          enable OSD menu (not DVD menu) [disabled]
  --disable-sortsub      disable subtitle sorting [enabled]
  --enable-fribidi       enable the FriBiDi libs [autodetect]
  --disable-enca         disable ENCA charset oracle library [autodetect]
  --disable-maemo        disable maemo specific features [autodetect]
  --enable-macosx-finder enable Mac OS X Finder invocation parameter
                         parsing [disabled]
  --enable-macosx-bundle enable Mac OS X bundle file locations [autodetect]
  --disable-inet6        disable IPv6 support [autodetect]
  --disable-sctp         disable SCTP support [autodetect]
  --disable-gethostbyname2  gethostbyname2 part of the C library [autodetect]
  --disable-ftp          disable FTP support [enabled]
  --disable-vstream      disable TiVo vstream client support [autodetect]
  --disable-pthreads     disable Posix threads support [autodetect]
  --disable-w32threads   disable Win32 threads support [autodetect]
  --disable-os2threads   disable OS/2 threads support [autodetect]
  --enable-ass-internal  enable internal SSA/ASS subtitle support [autodetect]
  --disable-ass          disable SSA/ASS subtitle support [autodetect]
  --enable-rpath         enable runtime linker path for extra libs [disabled]

Codecs:
  --enable-gif              enable GIF support [autodetect]
  --enable-png              enable PNG input/output support [autodetect]
  --enable-mng              enable MNG input/output support [autodetect]
  --enable-jpeg             enable JPEG input/output support [autodetect]
  --enable-libcdio          enable libcdio support [autodetect]
  --enable-liblzo           enable liblzo support [autodetect]
  --disable-win32dll        disable Win32 DLL support [autodetect]
  --disable-qtx             disable QuickTime codecs support [enabled]
  --disable-xanim           disable XAnim codecs support [enabled]
  --disable-real            disable RealPlayer codecs support [enabled]
  --disable-xvid            disable Xvid [autodetect]
  --disable-xvid-lavc       disable Xvid in libavcodec [autodetect]
  --disable-x264            disable x264 [autodetect]
  --disable-x264-lavc       disable x264 in libavcodec [autodetect]
  --disable-libdirac-lavc   disable Dirac in libavcodec [autodetect]
  --disable-libschroedinger-lavc   disable Dirac in libavcodec (Schroedinger
                                   decoder) [autodetect]
  --disable-libvpx-lavc     disable libvpx in libavcodec [autodetect]
  --disable-libnut          disable libnut [autodetect]
  --disable-ffmpeg_a        disable static FFmpeg [autodetect]
  --disable-ffmpeg_so       disable shared FFmpeg [autodetect]
  --disable-postproc        disable libpostproc [autodetect]
  --enable-vf-lavfi         enable libavfilter wrapper [disabled]
  --disable-libavcodec_mpegaudio_hp disable high precision audio decoding
                                    in libavcodec [enabled]
  --enable-tremor           enable integer libvorbis [autodetect]
  --disable-libvorbis       disable libvorbis support [autodetect]
  --disable-speex           disable Speex support [autodetect]
  --disable-libgsm          disable libgsm support [autodetect]
  --enable-theora           enable OggTheora libraries [autodetect]
  --enable-faad             enable FAAD2 (AAC) [autodetect]
  --disable-faac            disable support for FAAC (AAC encoder) [autodetect]
  --disable-faac-lavc       disable support for FAAC in libavcodec [autodetect]
  --disable-ladspa          disable LADSPA plugin support [autodetect]
  --disable-libbs2b         disable libbs2b audio filter support [autodetect]
  --disable-libdv           disable libdv 0.9.5 en/decoding support [autodetect]
  --disable-libilbc         disable libilbc decoding support [autodetect]
  --disable-libopus         disable libopus decoding support [autodetect]
  --disable-mpg123          disable libmpg123 MP3 decoding support [autodetect]
  --disable-mad             disable libmad (MPEG audio) support [autodetect]
  --disable-mp3lame         disable LAME MP3 encoding support [autodetect]
  --disable-mp3lame-lavc    disable LAME in libavcodec [autodetect]
  --disable-toolame         disable Toolame (MPEG layer 2) encoding [autodetect]
  --disable-twolame         disable Twolame (MPEG layer 2) encoding [autodetect]
  --enable-xmms             enable XMMS input plugin support [disabled]
  --enable-libdca           enable libdca support [autodetect]
  --disable-liba52          disable liba52 [autodetect]
  --disable-libmpeg2        disable libmpeg2 [autodetect]
  --disable-libmpeg2-internal disable builtin libmpeg2 [autodetect]
  --enable-musepack         enable libmpcdec support (deprecated in favour of libavcodec) [disabled]
  --disable-libopencore_amrnb disable libopencore_amr narrowband [autodetect]
  --disable-libopencore_amrwb disable libopencore_amr wideband [autodetect]
  --disable-libopenjpeg     disable OpenJPEG (JPEG 2000) input/output support [autodetect]
  --disable-crystalhd       disable CrystalHD support [autodetect]
  --disable-decoder=DECODER disable specified FFmpeg decoder
  --enable-decoder=DECODER  enable specified FFmpeg decoder
  --disable-encoder=ENCODER disable specified FFmpeg encoder
  --enable-encoder=ENCODER  enable specified FFmpeg encoder
  --disable-parser=PARSER   disable specified FFmpeg parser
  --enable-parser=PARSER    enable specified FFmpeg parser
  --disable-protocol=PROTO  disable specified FFmpeg protocol
  --enable-protocol=PROTO   enable specified FFmpeg protocol
  --disable-demuxer=DEMUXER disable specified FFmpeg demuxer
  --enable-demuxer=DEMUXER  enable specified FFmpeg demuxer
  --disable-muxer=MUXER     disable specified FFmpeg muxer
  --enable-muxer=MUXER      enable specified FFmpeg muxer

Video output:
  --disable-vidix          disable VIDIX [for x86 *nix]
  --with-vidix-drivers[=*] list of VIDIX drivers to be compiled in
                           Available: cyberblade, ivtv, mach64, mga, mga_crtc2,
                           nvidia, pm2, pm3, radeon, rage128, s3, sis, unichrome
  --disable-vidix-pcidb    disable VIDIX PCI device name database
  --enable-dhahelper       enable VIDIX dhahelper support
  --enable-svgalib_helper  enable VIDIX svgalib_helper support
  --enable-gl              enable OpenGL video output [autodetect]
  --disable-matrixview     disable OpenGL MatrixView video output [autodetect]
  --enable-dga2            enable DGA 2 support [autodetect]
  --enable-dga1            enable DGA 1 support [autodetect]
  --enable-vesa            enable VESA video output [autodetect]
  --enable-svga            enable SVGAlib video output [autodetect]
  --enable-sdl             enable SDL video output [autodetect]
  --enable-kva             enable KVA video output [autodetect]
  --enable-aa              enable AAlib video output [autodetect]
  --enable-caca            enable CACA  video output [autodetect]
  --enable-ggi             enable GGI video output [autodetect]
  --enable-ggiwmh          enable GGI libggiwmh extension [autodetect]
  --enable-direct3d        enable Direct3D video output [autodetect]
  --enable-directx         enable DirectX video output [autodetect]
  --enable-dxr2            enable DXR2 video output [autodetect]
  --enable-dxr3            enable DXR3/H+ video output [autodetect]
  --enable-ivtv            enable IVTV TV-Out video output [autodetect]
  --enable-v4l2            enable V4L2 Decoder audio/video output [autodetect]
  --enable-dvb             enable DVB video output [autodetect]
  --enable-mga             enable mga_vid video output [autodetect]
  --enable-xmga            enable mga_vid X11 video output [autodetect]
  --enable-xv              enable Xv video output [autodetect]
  --enable-xvmc            enable XvMC acceleration [disable]
  --enable-vda             enable VDA acceleration [autodetect]
  --enable-vdpau           enable VDPAU acceleration [autodetect]
  --enable-vm              enable XF86VidMode support [autodetect]
  --enable-xinerama        enable Xinerama support [autodetect]
  --enable-x11             enable X11 video output [autodetect]
  --enable-xshape          enable XShape support [autodetect]
  --disable-xss            disable screensaver support via xss [autodetect]
  --enable-fbdev           enable FBDev video output [autodetect]
  --enable-mlib            enable mediaLib video output (Solaris) [disable]
  --enable-3dfx            enable obsolete /dev/3dfx video output [disable]
  --enable-tdfxfb          enable tdfxfb video output [disable]
  --enable-s3fb            enable s3fb (S3 ViRGE) video output [disable]
  --enable-wii             enable Nintendo Wii/GameCube video output [disable]
  --enable-directfb        enable DirectFB video output [autodetect]
  --enable-zr              enable ZR360[56]7/ZR36060 video output [autodetect]
  --enable-bl              enable Blinkenlights video output [disable]
  --enable-tdfxvid         enable tdfx_vid video output [disable]
  --enable-xvr100          enable SUN XVR-100 video output [autodetect]
  --disable-tga            disable Targa video output [enable]
  --disable-pnm            disable PNM video output [enable]
  --disable-md5sum         disable md5sum video output [enable]
  --disable-yuv4mpeg       disable yuv4mpeg video output [enable]
  --disable-corevideo      disable CoreVideo video output [autodetect]
  --disable-quartz         disable Quartz video output [autodetect]

Audio output:
  --disable-alsa         disable ALSA audio output [autodetect]
  --disable-ossaudio     disable OSS audio output [autodetect]
  --disable-arts         disable aRts audio output [autodetect]
  --disable-esd          disable esd audio output [autodetect]
  --disable-pulse        disable Pulseaudio audio output [autodetect]
  --disable-jack         disable JACK audio output [autodetect]
  --disable-openal       disable OpenAL audio output [autodetect]
  --disable-nas          disable NAS audio output [autodetect]
  --disable-sgiaudio     disable SGI audio output [autodetect]
  --disable-sunaudio     disable Sun audio output [autodetect]
  --disable-kai          disable KAI audio output [autodetect]
  --disable-dart         disable DART audio output [autodetect]
  --disable-win32waveout disable Windows waveout audio output [autodetect]
  --disable-coreaudio    disable CoreAudio audio output [autodetect]
  --disable-select       disable using select() on the audio device [enable]

Language options:
  --charset=charset      convert the console messages to this character set
  --language-doc=lang    language to use for the documentation [en]
  --language-man=lang    language to use for the man pages [en]
  --language-msg=lang    language to use for the messages and the GUI [en]
  --language=lang        default language to use [en]
Specific options override --language. You can pass a list of languages separated
by whitespace or commas instead of a single language. Nonexisting translations
will be dropped from each list. All documentation and man page translations
available in the list will be installed, for the messages the first available
translation will be used. The value "all" will activate all translations. The
LINGUAS environment variable is honored. In all cases the fallback is English.
Available values are: all $msg_lang_all

Miscellaneous options:
  --enable-runtime-cpudetection    enable runtime CPU detection [disable]
  --enable-cross-compile enable cross-compilation [autodetect]
  --cc=COMPILER          C compiler to build MPlayer [gcc]
  --host-cc=COMPILER     C compiler for tools needed while building [gcc]
  --as=ASSEMBLER         assembler to build MPlayer [as]
  --nm=NM                nm tool to build MPlayer [nm]
  --yasm=YASM            Yasm assembler to build MPlayer [yasm]
  --ar=AR                librarian to build MPlayer [ar]
  --ranlib=RANLIB        ranlib to build MPlayer [ranlib]
  --windres=WINDRES      windres to build MPlayer [windres]
  --target=PLATFORM      target platform (i386-linux, arm-linux, etc)
  --enable-static        build a statically linked binary
  --with-install=PATH    path to a custom install program

Advanced options:
  --enable-mmx              enable MMX [autodetect]
  --enable-mmxext           enable MMX2 (Pentium III, Athlon) [autodetect]
  --enable-3dnow            enable 3DNow! [autodetect]
  --enable-3dnowext         enable extended 3DNow! [autodetect]
  --enable-sse              enable SSE [autodetect]
  --enable-sse2             enable SSE2 [autodetect]
  --enable-sse3             enable SSE3 [autodetect]
  --enable-ssse3            enable SSSE3 [autodetect]
  --enable-sse4             enable SSE4 [autodetect]
  --enable-sse42            enable SSE4.2 [autodetect]
  --enable-avx              enable AVX [autodetect]
  --enable-shm              enable shm [autodetect]
  --enable-altivec          enable AltiVec (PowerPC) [autodetect]
  --enable-armv5te          enable DSP extensions (ARM) [autodetect]
  --enable-armv6            enable ARMv6 (ARM) [autodetect]
  --enable-armv6t2          enable ARMv6t2 (ARM) [autodetect]
  --enable-armvfp           enable ARM VFP (ARM) [autodetect]
  --enable-vfpv3            enable ARM VFPV3 (ARM) [autodetect]
  --enable-neon             enable NEON (ARM) [autodetect]
  --enable-thumb            enable THUMB (ARM) [autodetect]
  --enable-iwmmxt           enable iWMMXt (ARM) [autodetect]
  --disable-fastmemcpy      disable 3DNow!/SSE/MMX optimized memcpy [enable]
  --enable-hardcoded-tables put tables in binary instead of calculating them at startup [disable]
  --enable-big-endian       force byte order to big-endian [autodetect]
  --enable-debug[=1-3]      compile-in debugging information [disable]
  --enable-profile          compile-in profiling information [disable]
  --disable-sighandler      disable sighandler for crashes [enable]
  --enable-relocatable      enable compiling as relocatable/PIE executable [disable]
  --enable-crash-debug      enable automatic gdb attach on crash [disable]
  --enable-dynamic-plugins  enable dynamic A/V plugins [disable]

Use these options if autodetection fails:
  --extra-cflags=FLAGS        extra CFLAGS
  --extra-ldflags=FLAGS       extra LDFLAGS
  --extra-libs=FLAGS          extra linker flags
  --extra-libs-mplayer=FLAGS  extra linker flags for MPlayer
  --extra-libs-mencoder=FLAGS extra linker flags for MEncoder
  --with-xvmclib=NAME         adapter-specific library name (e.g. XvMCNVIDIA)

  --with-freetype-config=PATH path to freetype-config
  --with-glib-config=PATH     path to glib*-config
  --with-gtk-config=PATH      path to gtk*-config
  --with-sdl-config=PATH      path to sdl*-config
  --with-dvdnav-config=PATH   path to dvdnav-config
  --with-dvdread-config=PATH  path to dvdread-config

This configure script is NOT autoconf-based, even though its output is similar.
It will try to autodetect all configuration options. If you --enable an option
it will be forcefully turned on, skipping autodetection. This can break
compilation, so you need to know what you are doing.
EOF
exit 0
} #show_help()

# GOTCHA: the variables below defines the default behavior for autodetection
# and have - unless stated otherwise - at least 2 states : yes no
# If autodetection is available then the third state is: auto
_mmx=auto
_3dnow=auto
_3dnowext=auto
_mmxext=auto
_sse=auto
_sse2=auto
_sse3=auto
_ssse3=auto
_sse4_1=auto
_sse4_2=auto
_avx=auto
_cmov=auto
_fast_cmov=auto
_fast_clz=auto
_armv5te=auto
_armv6=auto
_armv6t2=auto
_armvfp=auto
vfpv3=auto
neon=auto
armthumb=auto
_iwmmxt=auto
_mtrr=auto
_altivec=auto
_install=install
_ranlib=ranlib
_windres=windres
_cc=cc
_ar=ar
test "$CC" && _cc="$CC"
_as=auto
_nm=auto
_yasm=yasm
_runtime_cpudetection=no
_cross_compile=auto
_prefix="/usr/local"
ffmpeg_a=auto
ffmpeg_so=auto
postproc=auto
_vf_lavfi=no
_libavcodec_mpegaudio_hp=yes
_libopencore_amrnb=auto
_libopencore_amrwb=auto
libopenjpeg=auto
_mencoder=yes
_mplayer=yes
_x11=auto
_xshape=auto
_xss=auto
_dga1=auto
_dga2=auto
_xv=auto
_xvmc=no  #auto when complete
_vda=auto
_vdpau=auto
_sdl=auto
_kva=auto
_direct3d=auto
_directx=auto
_win32waveout=auto
_nas=auto
_png=auto
_mng=auto
_jpeg=auto
_pnm=yes
_md5sum=yes
_yuv4mpeg=yes
_gif=auto
_gl=auto
matrixview=auto
_ggi=auto
_ggiwmh=auto
_aa=auto
_caca=auto
_svga=auto
_vesa=auto
_fbdev=auto
_dvb=auto
_dxr2=auto
_dxr3=auto
_ivtv=auto
_v4l2=auto
_iconv=auto
_langinfo=auto
_rtc=auto
_ossaudio=auto
_arts=auto
_esd=auto
_pulse=auto
_jack=auto
_kai=auto
_dart=auto
_openal=auto
_libcdio=auto
_liblzo=auto
_mad=auto
_mp3lame=auto
_mp3lame_lavc=auto
_toolame=auto
_twolame=auto
_tremor=auto
_libvorbis=auto
_speex=auto
_libgsm=auto
_theora=auto
_mpg123=auto
_liba52=auto
_libdca=auto
_libmpeg2=auto
_libmpeg2_internal=auto
_faad=auto
_faac=auto
_faac_lavc=auto
_ladspa=auto
_libbs2b=auto
_libilbc=auto
_libopus=auto
_xmms=no
_vcd=auto
_bluray=auto
_dvdnav=auto
_dvdnavconfig=dvdnav-config
_dvdreadconfig=dvdread-config
_dvdread=auto
_dvdread_internal=auto
_libdvdcss_internal=auto
_xanim=auto
_real=auto
_live=auto
_nemesi=auto
_librtmp=auto
_native_rtsp=yes
_xinerama=auto
_mga=auto
_xmga=auto
_vm=auto
_xf86keysym=auto
_mlib=no #broken, thus disabled
_sgiaudio=auto
_sunaudio=auto
_alsa=auto
_fastmemcpy=yes
hardcoded_tables=no
_unrar_exec=auto
_win32dll=auto
_select=yes
_radio=no
_radio_capture=no
_radio_v4l=auto
_radio_v4l2=auto
_radio_bsdbt848=auto
_tv=yes
_tv_v4l1=auto
_tv_v4l2=auto
_tv_bsdbt848=auto
_tv_dshow=auto
_pvr=auto
networking=yes
_winsock2_h=auto
_struct_addrinfo=auto
_getaddrinfo=auto
_struct_sockaddr_storage=auto
_smb=auto
_vidix=auto
_vidix_pcidb=yes
_dhahelper=no
_svgalib_helper=no
_joystick=no
crystalhd=auto
_xvid=auto
_xvid_lavc=auto
_x264=auto
_x264_lavc=auto
_libdirac_lavc=auto
_libschroedinger_lavc=auto
_libvpx_lavc=auto
_libnut=auto
_lirc=auto
_lircc=auto
_apple_remote=auto
_apple_ir=auto
_gui=no
_gtk1=no
_termcap=auto
_termios=auto
_3dfx=no
_s3fb=no
_wii=no
_tdfxfb=no
_tdfxvid=no
_xvr100=auto
_tga=yes
_directfb=auto
_zr=auto
_bl=no
#language=en
_shm=auto
_charset="UTF-8"
_dynamic_plugins=no
_crash_debug=no
_sighandler=yes
relocatable=auto
_libdv=auto
_cdparanoia=auto
_cddb=auto
_big_endian=auto
_bitmap_font=yes
_freetype=auto
_fontconfig=auto
_menu=no
_qtx=auto
_maemo=auto
_coreaudio=auto
_corevideo=auto
_quartz=auto
quicktime=auto
_macosx_finder=no
_macosx_bundle=auto
_sortsub=yes
_freetypeconfig='freetype-config'
_fribidi=auto
_enca=auto
_inet6=auto
_sctp=auto
_gethostbyname2=auto
_ftp=auto
_musepack=no
_vstream=auto
_pthreads=auto
_w32threads=auto
_os2threads=auto
_ass=auto
ass_internal=auto
_rpath=no
_asmalign_pot=auto
_stream_cache=yes
_priority=no
def_dos_paths="#define HAVE_DOS_PATHS 0"
def_stream_cache="#define CONFIG_STREAM_CACHE 1"
def_path_max_check="#define CONFIG_PATH_MAX_CHECK 0"
def_priority="#undef CONFIG_PRIORITY"
def_pthread_cache="#undef PTHREAD_CACHE"
shmem=no

option_value(){
  echo $(echo $* | cut -d '=' -f 2-)
}

option_value_uc(){
  echo $(option_value $1 | toupper)
}

for ac_option do
  case "$ac_option" in
  --help|-help|-h)
    show_help
    ;;
  --prefix=*)
    _prefix=$(option_value $ac_option)
    ;;
  --bindir=*)
    _bindir=$(option_value $ac_option)
    ;;
  --datadir=*)
    _datadir=$(option_value $ac_option)
    ;;
  --mandir=*)
    _mandir=$(option_value $ac_option)
    ;;
  --confdir=*)
    _confdir=$(option_value $ac_option)
    ;;
  --libdir=*)
    _libdir=$(option_value $ac_option)
    ;;
  --codecsdir=*)
    _codecsdir=$(option_value $ac_option)
    ;;

  --with-install=*)
    _install=$(option_value $ac_option)
    ;;
  --with-xvmclib=*)
    _xvmclib=$(option_value $ac_option)
    ;;

  --with-sdl-config=*)
    _sdlconfig=$(option_value $ac_option)
    ;;
  --with-freetype-config=*)
    _freetypeconfig=$(option_value $ac_option)
    ;;
  --with-gtk-config=*)
    _gtkconfig=$(option_value $ac_option)
    ;;
  --with-glib-config=*)
    _glibconfig=$(option_value $ac_option)
    ;;
  --with-dvdnav-config=*)
    _dvdnavconfig=$(option_value $ac_option)
    ;;
  --with-dvdread-config=*)
    _dvdreadconfig=$(option_value $ac_option)
    ;;

  --extra-cflags=*)
    extra_cflags=$(option_value $ac_option)
    ;;
  --extra-ldflags=*)
    extra_ldflags=$(option_value $ac_option)
    ;;
  --extra-libs=*)
    extra_libs=$(option_value $ac_option)
    ;;
  --extra-libs-mplayer=*)
    libs_mplayer=$(option_value $ac_option)
    ;;
  --extra-libs-mencoder=*)
    libs_mencoder=$(option_value $ac_option)
    ;;

  --target=*)
    _target=$(option_value $ac_option)
    ;;
  --cc=*)
    _cc=$(option_value $ac_option)
    ;;
  --host-cc=*)
    _host_cc=$(option_value $ac_option)
    ;;
  --as=*)
    _as=$(option_value $ac_option)
    ;;
  --nm=*)
    _nm=$(option_value $ac_option)
    ;;
  --yasm=*)
    _yasm=$(option_value $ac_option)
    ;;
  --ar=*)
    _ar=$(option_value $ac_option)
    ;;
  --ranlib=*)
    _ranlib=$(option_value $ac_option)
    ;;
  --windres=*)
    _windres=$(option_value $ac_option)
    ;;
  --charset=*)
    _charset=$(option_value $ac_option)
    ;;
  --language-doc=*)
    language_doc=$(option_value $ac_option)
    ;;
  --language-man=*)
    language_man=$(option_value $ac_option)
    ;;
  --language-msg=*)
    language_msg=$(option_value $ac_option)
    ;;
  --language=*)
    language=$(option_value $ac_option)
    ;;

  --enable-static)
    ld_static='-static'
    ;;
  --disable-static)
    ld_static=''
    ;;
  --enable-profile)
    _profile='-p'
    ;;
  --disable-profile)
    _profile=
    ;;
  --enable-debug)
    _debug='-g'
    ;;
  --enable-debug=*)
    _debug=$(echo $_echo_n '-g'$_echo_c; option_value $ac_option)
    ;;
  --disable-debug)
    _debug=
    ;;
  --enable-runtime-cpudetection)    _runtime_cpudetection=yes   ;;
  --disable-runtime-cpudetection)   _runtime_cpudetection=no    ;;
  --enable-cross-compile)           _cross_compile=yes          ;;
  --disable-cross-compile)          _cross_compile=no           ;;
  --enable-mencoder)    _mencoder=yes   ;;
  --disable-mencoder)   _mencoder=no    ;;
  --enable-mplayer)     _mplayer=yes    ;;
  --disable-mplayer)    _mplayer=no     ;;
  --enable-dynamic-plugins) _dynamic_plugins=yes ;;
  --disable-dynamic-plugins) _dynamic_plugins=no ;;
  --enable-x11)         _x11=yes        ;;
  --disable-x11)        _x11=no         ;;
  --enable-xshape)      _xshape=yes     ;;
  --disable-xshape)     _xshape=no      ;;
  --enable-xss)         _xss=yes        ;;
  --disable-xss)        _xss=no         ;;
  --enable-xv)          _xv=yes         ;;
  --disable-xv)         _xv=no          ;;
  --enable-xvmc)        _xvmc=yes       ;;
  --disable-xvmc)       _xvmc=no        ;;
  --enable-vda)         _vda=yes        ;;
  --disable-vda)        _vda=no         ;;
  --enable-vdpau)       _vdpau=yes      ;;
  --disable-vdpau)      _vdpau=no       ;;
  --enable-sdl)         _sdl=yes        ;;
  --disable-sdl)        _sdl=no         ;;
  --enable-kva)         _kva=yes        ;;
  --disable-kva)        _kva=no         ;;
  --enable-direct3d)    _direct3d=yes   ;;
  --disable-direct3d)   _direct3d=no    ;;
  --enable-directx)     _directx=yes    ;;
  --disable-directx)    _directx=no     ;;
  --enable-win32waveout)  _win32waveout=yes ;;
  --disable-win32waveout) _win32waveout=no  ;;
  --enable-nas)         _nas=yes        ;;
  --disable-nas)        _nas=no         ;;
  --enable-png)         _png=yes        ;;
  --disable-png)        _png=no         ;;
  --enable-mng)         _mng=yes        ;;
  --disable-mng)        _mng=no         ;;
  --enable-jpeg)        _jpeg=yes       ;;
  --disable-jpeg)       _jpeg=no        ;;
  --enable-libopenjpeg) libopenjpeg=yes ;;
  --disable-libopenjpeg)libopenjpeg=no  ;;
  --enable-pnm)         _pnm=yes        ;;
  --disable-pnm)        _pnm=no         ;;
  --enable-md5sum)      _md5sum=yes     ;;
  --disable-md5sum)     _md5sum=no      ;;
  --enable-yuv4mpeg)    _yuv4mpeg=yes   ;;
  --disable-yuv4mpeg)   _yuv4mpeg=no    ;;
  --enable-gif)         _gif=yes        ;;
  --disable-gif)        _gif=no         ;;
  --enable-gl)          _gl=yes         ;;
  --disable-gl)         _gl=no          ;;
  --enable-matrixview)  matrixview=yes  ;;
  --disable-matrixview) matrixview=no   ;;
  --enable-ggi)         _ggi=yes        ;;
  --disable-ggi)        _ggi=no         ;;
  --enable-ggiwmh)      _ggiwmh=yes     ;;
  --disable-ggiwmh)     _ggiwmh=no      ;;
  --enable-aa)          _aa=yes         ;;
  --disable-aa)         _aa=no          ;;
  --enable-caca)        _caca=yes       ;;
  --disable-caca)       _caca=no        ;;
  --enable-svga)        _svga=yes       ;;
  --disable-svga)       _svga=no        ;;
  --enable-vesa)        _vesa=yes       ;;
  --disable-vesa)       _vesa=no        ;;
  --enable-fbdev)       _fbdev=yes      ;;
  --disable-fbdev)      _fbdev=no       ;;
  --enable-dvb)         _dvb=yes        ;;
  --disable-dvb)        _dvb=no         ;;
  --enable-dxr2)        _dxr2=yes       ;;
  --disable-dxr2)       _dxr2=no        ;;
  --enable-dxr3)        _dxr3=yes       ;;
  --disable-dxr3)       _dxr3=no        ;;
  --enable-ivtv)        _ivtv=yes       ;;
  --disable-ivtv)       _ivtv=no        ;;
  --enable-v4l2)        _v4l2=yes       ;;
  --disable-v4l2)       _v4l2=no        ;;
  --enable-iconv)       _iconv=yes      ;;
  --disable-iconv)      _iconv=no       ;;
  --enable-langinfo)    _langinfo=yes   ;;
  --disable-langinfo)   _langinfo=no    ;;
  --enable-rtc)         _rtc=yes        ;;
  --disable-rtc)        _rtc=no         ;;
  --enable-libdv)       _libdv=yes      ;;
  --disable-libdv)      _libdv=no       ;;
  --enable-ossaudio)    _ossaudio=yes   ;;
  --disable-ossaudio)   _ossaudio=no    ;;
  --enable-arts)        _arts=yes       ;;
  --disable-arts)       _arts=no        ;;
  --enable-esd)         _esd=yes        ;;
  --disable-esd)        _esd=no         ;;
  --enable-pulse)       _pulse=yes      ;;
  --disable-pulse)      _pulse=no       ;;
  --enable-jack)        _jack=yes       ;;
  --disable-jack)       _jack=no        ;;
  --enable-openal)      _openal=yes     ;;
  --disable-openal)     _openal=no      ;;
  --enable-kai)         _kai=yes        ;;
  --disable-kai)        _kai=no         ;;
  --enable-dart)        _dart=yes       ;;
  --disable-dart)       _dart=no        ;;
  --enable-mad)         _mad=yes        ;;
  --disable-mad)        _mad=no         ;;
  --enable-mp3lame)     _mp3lame=yes    ;;
  --disable-mp3lame)    _mp3lame=no     ;;
  --enable-mp3lame-lavc)  _mp3lame_lavc=yes       ;;
  --disable-mp3lame-lavc) _mp3lame_lavc=no        ;;
  --enable-toolame)     _toolame=yes    ;;
  --disable-toolame)    _toolame=no     ;;
  --enable-twolame)     _twolame=yes    ;;
  --disable-twolame)    _twolame=no     ;;
  --enable-libcdio)     _libcdio=yes    ;;
  --disable-libcdio)    _libcdio=no     ;;
  --enable-liblzo)      _liblzo=yes     ;;
  --disable-liblzo)     _liblzo=no      ;;
  --enable-libvorbis)   _libvorbis=yes  ;;
  --disable-libvorbis)  _libvorbis=no   ;;
  --enable-speex)       _speex=yes      ;;
  --disable-speex)      _speex=no       ;;
  --enable-libgsm)      _libgsm=yes     ;;
  --disable-libgsm)     _libgsm=no      ;;
  --enable-tremor)      _tremor=yes     ;;
  --disable-tremor)     _tremor=no      ;;
  --enable-theora)      _theora=yes     ;;
  --disable-theora)     _theora=no      ;;
  --enable-mpg123)      _mpg123=yes     ;;
  --disable-mpg123)     _mpg123=no      ;;
  --enable-liba52)      _liba52=yes     ;;
  --disable-liba52)     _liba52=no      ;;
  --enable-libdca)      _libdca=yes     ;;
  --disable-libdca)     _libdca=no      ;;
  --enable-libmpeg2)    _libmpeg2=yes   ;;
  --disable-libmpeg2)   _libmpeg2=no    ;;
  --enable-libmpeg2-internal)    _libmpeg2_internal=yes   ;;
  --disable-libmpeg2-internal)   _libmpeg2_internal=no    ;;
  --enable-musepack)    _musepack=yes   ;;
  --disable-musepack)   _musepack=no    ;;
  --enable-faad)        _faad=yes       ;;
  --disable-faad)       _faad=no        ;;
  --enable-faac)        _faac=yes       ;;
  --disable-faac)       _faac=no        ;;
  --enable-faac-lavc)   _faac_lavc=yes  ;;
  --disable-faac-lavc)  _faac_lavc=no   ;;
  --enable-ladspa)      _ladspa=yes     ;;
  --disable-ladspa)     _ladspa=no      ;;
  --enable-libbs2b)     _libbs2b=yes    ;;
  --disable-libbs2b)    _libbs2b=no     ;;
  --enable-libilbc)     _libilbc=yes    ;;
  --disable-libilbc)    _libilbc=no     ;;
  --enable-libopus)     _libopus=yes    ;;
  --disable-libopus)    _libopus=no     ;;
  --enable-xmms)        _xmms=yes       ;;
  --disable-xmms)       _xmms=no        ;;
  --enable-vcd)         _vcd=yes        ;;
  --disable-vcd)        _vcd=no         ;;
  --enable-bluray)      _bluray=yes     ;;
  --disable-bluray)     _bluray=no      ;;
  --enable-dvdread)     _dvdread=yes    ;;
  --disable-dvdread)    _dvdread=no     ;;
  --enable-dvdread-internal)    _dvdread_internal=yes   ;;
  --disable-dvdread-internal)   _dvdread_internal=no    ;;
  --enable-libdvdcss-internal)  _libdvdcss_internal=yes ;;
  --disable-libdvdcss-internal) _libdvdcss_internal=no  ;;
  --enable-dvdnav)      _dvdnav=yes     ;;
  --disable-dvdnav)     _dvdnav=no      ;;
  --enable-xanim)       _xanim=yes      ;;
  --disable-xanim)      _xanim=no       ;;
  --enable-real)        _real=yes       ;;
  --disable-real)       _real=no        ;;
  --enable-live)        _live=yes       ;;
  --disable-live)       _live=no        ;;
  --enable-nemesi)      _nemesi=yes     ;;
  --disable-nemesi)     _nemesi=no      ;;
  --enable-librtmp)     _librtmp=yes    ;;
  --disable-librtmp)    _librtmp=no     ;;
  --enable-xinerama)    _xinerama=yes   ;;
  --disable-xinerama)   _xinerama=no    ;;
  --enable-mga)         _mga=yes        ;;
  --disable-mga)        _mga=no         ;;
  --enable-xmga)        _xmga=yes       ;;
  --disable-xmga)       _xmga=no        ;;
  --enable-vm)          _vm=yes         ;;
  --disable-vm)         _vm=no          ;;
  --enable-xf86keysym)  _xf86keysym=yes ;;
  --disable-xf86keysym) _xf86keysym=no  ;;
  --enable-mlib)        _mlib=yes       ;;
  --disable-mlib)       _mlib=no        ;;
  --enable-sunaudio)    _sunaudio=yes   ;;
  --disable-sunaudio)   _sunaudio=no    ;;
  --enable-sgiaudio)    _sgiaudio=yes   ;;
  --disable-sgiaudio)   _sgiaudio=no    ;;
  --enable-alsa)        _alsa=yes       ;;
  --disable-alsa)       _alsa=no        ;;
  --enable-tv)          _tv=yes         ;;
  --disable-tv)         _tv=no          ;;
  --enable-tv-bsdbt848)  _tv_bsdbt848=yes ;;
  --disable-tv-bsdbt848) _tv_bsdbt848=no  ;;
  --enable-tv-v4l1)     _tv_v4l1=yes    ;;
  --disable-tv-v4l1)    _tv_v4l1=no     ;;
  --enable-tv-v4l2)     _tv_v4l2=yes    ;;
  --disable-tv-v4l2)    _tv_v4l2=no     ;;
  --enable-tv-dshow)    _tv_dshow=yes   ;;
  --disable-tv-dshow)   _tv_dshow=no    ;;
  --enable-radio)       _radio=yes      ;;
  --enable-radio-capture)       _radio_capture=yes      ;;
  --disable-radio-capture)      _radio_capture=no       ;;
  --disable-radio)      _radio=no       ;;
  --enable-radio-v4l)   _radio_v4l=yes  ;;
  --disable-radio-v4l)  _radio_v4l=no   ;;
  --enable-radio-v4l2)  _radio_v4l2=yes ;;
  --disable-radio-v4l2) _radio_v4l2=no  ;;
  --enable-radio-bsdbt848)      _radio_bsdbt848=yes     ;;
  --disable-radio-bsdbt848)     _radio_bsdbt848=no      ;;
  --enable-pvr)         _pvr=yes        ;;
  --disable-pvr)        _pvr=no         ;;
  --enable-fastmemcpy)  _fastmemcpy=yes ;;
  --disable-fastmemcpy) _fastmemcpy=no  ;;
  --enable-hardcoded-tables)  hardcoded_tables=yes ;;
  --disable-hardcoded-tables) hardcoded_tables=no  ;;
  --enable-networking)     networking=yes    ;;
  --disable-networking)    networking=no     ;;
  --enable-winsock2_h)  _winsock2_h=yes ;;
  --disable-winsock2_h) _winsock2_h=no  ;;
  --enable-smb)         _smb=yes        ;;
  --disable-smb)        _smb=no ;;
  --enable-vidix)       _vidix=yes      ;;
  --disable-vidix)      _vidix=no       ;;
  --with-vidix-drivers=*)
    _vidix_drivers=$(option_value $ac_option)
    ;;
  --disable-vidix-pcidb)  _vidix_pcidb=no         ;;
  --enable-dhahelper)   _dhahelper=yes  ;;
  --disable-dhahelper)  _dhahelper=no   ;;
  --enable-svgalib_helper)      _svgalib_helper=yes     ;;
  --disable-svgalib_helper)     _svgalib_helper=no      ;;
  --enable-joystick)    _joystick=yes   ;;
  --disable-joystick)   _joystick=no    ;;
  --enable-crystalhd)   crystalhd=yes  ;;
  --disable-crystalhd)  crystalhd=no   ;;
  --enable-xvid)        _xvid=yes       ;;
  --disable-xvid)       _xvid=no        ;;
  --enable-xvid-lavc)   _xvid_lavc=yes  ;;
  --disable-xvid-lavc)  _xvid_lavc=no   ;;
  --enable-x264)        _x264=yes       ;;
  --disable-x264)       _x264=no        ;;
  --enable-x264-lavc)   _x264_lavc=yes  ;;
  --disable-x264-lavc)  _x264_lavc=no   ;;
  --enable-libdirac-lavc)   _libdirac_lavc=yes  ;;
  --disable-libdirac-lavc)  _libdirac_lavc=no   ;;
  --enable-libschroedinger-lavc)   _libschroedinger_lavc=yes  ;;
  --disable-libschroedinger-lavc)  _libschroedinger_lavc=no   ;;
  --enable-libvpx-lavc)   _libvpx_lavc=yes  ;;
  --disable-libvpx-lavc)  _libvpx_lavc=no   ;;
  --enable-libnut)      _libnut=yes     ;;
  --disable-libnut)     _libnut=no      ;;
  --enable-libopencore_amrnb)   _libopencore_amrnb=yes  ;;
  --disable-libopencore_amrnb)  _libopencore_amrnb=no   ;;
  --enable-libopencore_amrwb)   _libopencore_amrwb=yes  ;;
  --disable-libopencore_amrwb)  _libopencore_amrwb=no   ;;
  --enable-ffmpeg_a)    ffmpeg_a=yes    ;;
  --disable-ffmpeg_a)   ffmpeg_a=no     ;;
  --enable-ffmpeg_so)   ffmpeg_so=yes   ;;
  --disable-ffmpeg_so)  ffmpeg_so=no    ;;
  --enable-postproc)    postproc=yes    ;;
  --disable-postproc)   postproc=no     ;;
  --enable-vf-lavfi)    _vf_lavfi=yes   ;;
  --disable-vf-lavfi)   _vf_lavfi=no    ;;
  --enable-libavcodec_mpegaudio_hp)     _libavcodec_mpegaudio_hp=yes    ;;
  --disable-libavcodec_mpegaudio_hp)    _libavcodec_mpegaudio_hp=no     ;;

  --enable-lirc)        _lirc=yes       ;;
  --disable-lirc)       _lirc=no        ;;
  --enable-lircc)       _lircc=yes      ;;
  --disable-lircc)      _lircc=no       ;;
  --enable-apple-remote)  _apple_remote=yes ;;
  --disable-apple-remote) _apple_remote=no  ;;
  --enable-apple-ir)    _apple_ir=yes   ;;
  --disable-apple-ir)   _apple_ir=no    ;;
  --enable-gui)         _gui=yes        ;;
  --disable-gui)        _gui=no         ;;
  --enable-gtk1)        _gtk1=yes       ;;
  --disable-gtk1)       _gtk1=no        ;;
  --enable-termcap)     _termcap=yes    ;;
  --disable-termcap)    _termcap=no     ;;
  --enable-termios)     _termios=yes    ;;
  --disable-termios)    _termios=no     ;;
  --enable-3dfx)        _3dfx=yes       ;;
  --disable-3dfx)       _3dfx=no        ;;
  --enable-s3fb)        _s3fb=yes       ;;
  --disable-s3fb)       _s3fb=no        ;;
  --enable-wii)         _wii=yes        ;;
  --disable-wii)        _wii=no         ;;
  --enable-tdfxfb)      _tdfxfb=yes     ;;
  --disable-tdfxfb)     _tdfxfb=no      ;;
  --disable-tdfxvid)    _tdfxvid=no     ;;
  --enable-tdfxvid)     _tdfxvid=yes    ;;
  --disable-xvr100)     _xvr100=no      ;;
  --enable-xvr100)      _xvr100=yes     ;;
  --disable-tga)        _tga=no         ;;
  --enable-tga)         _tga=yes        ;;
  --enable-directfb)    _directfb=yes   ;;
  --disable-directfb)   _directfb=no    ;;
  --enable-zr)          _zr=yes         ;;
  --disable-zr)         _zr=no          ;;
  --enable-bl)          _bl=yes         ;;
  --disable-bl)         _bl=no          ;;
  --enable-mtrr)        _mtrr=yes       ;;
  --disable-mtrr)       _mtrr=no        ;;
  --enable-shm)         _shm=yes        ;;
  --disable-shm)        _shm=no         ;;
  --enable-select)      _select=yes     ;;
  --disable-select)     _select=no      ;;
  --enable-cdparanoia)  _cdparanoia=yes ;;
  --disable-cdparanoia) _cdparanoia=no  ;;
  --enable-cddb)        _cddb=yes       ;;
  --disable-cddb)       _cddb=no        ;;
  --enable-big-endian)  _big_endian=yes ;;
  --disable-big-endian) _big_endian=no  ;;
  --enable-bitmap-font)    _bitmap_font=yes   ;;
  --disable-bitmap-font)   _bitmap_font=no    ;;
  --enable-freetype)    _freetype=yes   ;;
  --disable-freetype)   _freetype=no    ;;
  --enable-fontconfig)  _fontconfig=yes ;;
  --disable-fontconfig) _fontconfig=no  ;;
  --enable-unrarexec)   _unrar_exec=yes ;;
  --disable-unrarexec)  _unrar_exec=no  ;;
  --enable-ftp)         _ftp=yes        ;;
  --disable-ftp)        _ftp=no         ;;
  --enable-vstream)     _vstream=yes    ;;
  --disable-vstream)    _vstream=no     ;;
  --enable-pthreads)    _pthreads=yes   ;;
  --disable-pthreads)   _pthreads=no    ;;
  --enable-w32threads)  _w32threads=yes ;;
  --disable-w32threads) _w32threads=no  ;;
  --enable-os2threads)  _os2threads=yes ;;
  --disable-os2threads) _os2threads=no  ;;
  --enable-ass)         _ass=yes        ;;
  --disable-ass)        _ass=no         ;;
  --enable-ass-internal)  ass_internal=yes ;;
  --disable-ass-internal) ass_internal=no  ;;
  --enable-rpath)       _rpath=yes      ;;
  --disable-rpath)      _rpath=no       ;;

  --enable-fribidi)     _fribidi=yes    ;;
  --disable-fribidi)    _fribidi=no     ;;

  --enable-enca)        _enca=yes       ;;
  --disable-enca)       _enca=no        ;;

  --enable-inet6)       _inet6=yes      ;;
  --disable-inet6)      _inet6=no       ;;

  --enable-sctp)        _sctp=yes       ;;
  --disable-sctp)       _sctp=no        ;;

  --enable-gethostbyname2)      _gethostbyname2=yes     ;;
  --disable-gethostbyname2)     _gethostbyname2=no      ;;

  --enable-dga1) _dga1=yes ;;
  --disable-dga1) _dga1=no ;;
  --enable-dga2) _dga2=yes ;;
  --disable-dga2) _dga2=no ;;

  --enable-menu) _menu=yes ;;
  --disable-menu) _menu=no ;;

  --enable-qtx) _qtx=yes ;;
  --disable-qtx) _qtx=no ;;

  --enable-coreaudio) _coreaudio=yes ;;
  --disable-coreaudio) _coreaudio=no ;;
  --enable-corevideo) _corevideo=yes ;;
  --disable-corevideo) _corevideo=no ;;
  --enable-quartz) _quartz=yes ;;
  --disable-quartz) _quartz=no ;;
  --enable-macosx-finder) _macosx_finder=yes ;;
  --disable-macosx-finder) _macosx_finder=no ;;
  --enable-macosx-bundle) _macosx_bundle=yes ;;
  --disable-macosx-bundle) _macosx_bundle=no ;;

  --enable-maemo) _maemo=yes ;;
  --disable-maemo) _maemo=no ;;

  --enable-sortsub) _sortsub=yes ;;
  --disable-sortsub) _sortsub=no ;;

  --enable-crash-debug) _crash_debug=yes ;;
  --disable-crash-debug) _crash_debug=no ;;
  --enable-sighandler)  _sighandler=yes  ;;
  --disable-sighandler) _sighandler=no   ;;
  --enable-relocatable)  relocatable=yes  ;;
  --disable-relocatable) relocatable=no   ;;
  --enable-win32dll) _win32dll=yes ;;
  --disable-win32dll) _win32dll=no ;;

  --enable-sse) _sse=yes ;;
  --disable-sse) _sse=no ;;
  --enable-sse2) _sse2=yes ;;
  --disable-sse2) _sse2=no ;;
  --enable-sse3) _sse3=yes ;;
  --disable-sse3) _sse3=no ;;
  --enable-ssse3) _ssse3=yes ;;
  --disable-ssse3) _ssse3=no ;;
  --enable-sse4) _sse4_1=yes;;
  --disable-sse4) _sse4_1=no;;
  --enable-sse42) _sse4_2=yes;;
  --disable-sse42) _sse4_2=no;;
  --enable-avx) _avx=yes;;
  --disable-avx) _avx=no;;
  --enable-mmxext) _mmxext=yes ;;
  --disable-mmxext) _mmxext=no ;;
  --enable-3dnow) _3dnow=yes ;;
  --disable-3dnow) _3dnow=no _3dnowext=no ;;
  --enable-3dnowext) _3dnow=yes _3dnowext=yes ;;
  --disable-3dnowext) _3dnowext=no ;;
  --enable-cmov) _cmov=yes ;;
  --disable-cmov) _cmov=no ;;
  --enable-fast-cmov) _fast_cmov=yes ;;
  --disable-fast-cmov) _fast_cmov=no ;;
  --enable-fast-clz) _fast_clz=yes ;;
  --disable-fast-clz) _fast_clz=no ;;
  --enable-altivec) _altivec=yes ;;
  --disable-altivec) _altivec=no ;;
  --enable-armv5te) _armv5te=yes ;;
  --disable-armv5te) _armv5te=no ;;
  --enable-armv6) _armv6=yes ;;
  --disable-armv6) _armv6=no ;;
  --enable-armv6t2) _armv6t2=yes ;;
  --disable-armv6t2) _armv6t2=no ;;
  --enable-armvfp) _armvfp=yes ;;
  --disable-armvfp) _armvfp=no ;;
  --enable-vfpv3) vfpv3=yes ;;
  --disable-vfpv3) vfpv3=no ;;
  --enable-neon) neon=yes ;;
  --disable-neon) neon=no ;;
  --enable-thumb) armthumb=yes ;;
  --disable-thumb) armthumb=no ;;
  --enable-iwmmxt) _iwmmxt=yes ;;
  --disable-iwmmxt) _iwmmxt=no ;;
  --enable-mmx) _mmx=yes ;;
  --disable-mmx) # 3DNow! and MMX2 require MMX
        _3dnow=no _3dnowext=no _mmx=no _mmxext=no ;;

  # Handle these options in a second pass.
  --*-decoder=*|--*-encoder=*|--*-parser=*|--*-protocol=*|--*-demuxer=*|--*-muxer=*|--*-filter=*)  ;;

  *)
    echo "Unknown parameter: $ac_option"
    exit 1
    ;;

  esac
done

# Atmos: moved this here, to be correct, if --prefix is specified
test -z "$_bindir"  && _bindir="$_prefix/bin"
test -z "$_datadir" && _datadir="$_prefix/share/mplayer"
test -z "$_mandir"  && _mandir="$_prefix/share/man"
test -z "$_confdir" && _confdir="$_prefix/etc/mplayer"
test -z "$_libdir"  && _libdir="$_prefix/lib"

for tmpdir in "$TMPDIR" "$TEMPDIR" "/tmp" ; do
  test "$tmpdir" && break
done

mplayer_tmpdir="$tmpdir/mplayer-configure-$RANDOM-$$"
mkdir $mplayer_tmpdir || die "Unable to create tmpdir."

cleanup() {
  rm -rf "$mplayer_tmpdir"
}

trap cleanup EXIT

TMPLOG="config.log"
TMPC="$mplayer_tmpdir/tmp.c"
TMPCPP="$mplayer_tmpdir/tmp.cpp"
TMPH="$mplayer_tmpdir/tmp.h"
TMPS="$mplayer_tmpdir/tmp.S"
# We will update this later once we know the executable suffix
TMPEXE="$mplayer_tmpdir/tmp"

rm -f "$TMPLOG"
echo configuration: $configuration > "$TMPLOG"
echo >> "$TMPLOG"


# local FFmpeg checkout handling
if test -e ffmpeg/.svn ; then
    echo "You have an outdated FFmpeg SVN checkout in ffmpeg/, please (re)move or replace it"
    exit 1
fi

if test -e ffmpeg/mp_auto_pull ; then
    echo "Updating FFmpeg, (re)move ffmpeg/mp_auto_pull to disable"
    (cd ffmpeg && git checkout master)
    if ! (cd ffmpeg && git pull --rebase --ff-only) ; then
        echo "git pull failed, (re)move ffmpeg/mp_auto_pull to disable pulling"
        exit 1
    fi
fi

if ! test -e ffmpeg ; then
    echo "No FFmpeg checkout, press enter to download one with git or CTRL+C to abort"
    read tmp
    if ! git clone --depth 1 git://source.ffmpeg.org/ffmpeg.git ffmpeg ; then
        rm -rf ffmpeg
        echo "Failed to get a FFmpeg checkout"
        echo "Please try again or put FFmpeg source code copy into ffmpeg/ manually."
        echo "Nightly snapshot: http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2"
        echo "To use a github mirror via http (e.g. because a firewall blocks git):"
        echo "git clone --depth 1 https://github.com/FFmpeg/FFmpeg ffmpeg; touch ffmpeg/mp_auto_pull"
        exit 1
    fi
    touch ffmpeg/mp_auto_pull
fi

list_subparts() {
  pattern="s/^[^#]*${1}.*([^ ,]*, *\([^ ,)]*\).*/\1_${2}/p"
  sed -n "$pattern" ffmpeg/libav${3} | toupper
}

libavdecoders_all=$(list_subparts  DEC      decoder  codec/allcodecs.c)
libavencoders_all=$(list_subparts  ENC      encoder  codec/allcodecs.c)
libavparsers_all=$(list_subparts   PARSER   parser   codec/allcodecs.c)
libavbsfs_all=$(list_subparts      BSF      bsf      codec/allcodecs.c)
libavhwaccels_all=$(list_subparts  HWACCEL  hwaccel  codec/allcodecs.c)
libavdemuxers_all=$(list_subparts  DEMUX    demuxer  format/allformats.c)
libavmuxers_all=$(list_subparts    _MUX     muxer    format/allformats.c)
libavprotocols_all=$(list_subparts PROTOCOL protocol format/allformats.c)
libavfilters_all=$(list_subparts   FILTER   filter   filter/allfilters.c)

filter_out_component() {
  eval list=\$libav${1}s
  type=$(echo $1 | toupper)
  shift
  for item in $@; do
    filter_patterns="$filter_patterns -e s/[^A-Z0-9_]${item}_${type}//g"
  done
  echo " $list" | sed $filter_patterns
}

libavdecoders=$(echo $libavdecoders_all)
libavencoders=$(echo $libavencoders_all)
libavparsers=$(echo $libavparsers_all)
libavbsfs=$(echo $libavbsfs_all)
# Disable all hardware accelerators for now.
libavhwaccels=
libavdemuxers=$(echo $libavdemuxers_all)
libavmuxers=$(echo $libavmuxers_all)
libavprotocols=$(echo $libavprotocols_all)
libavfilters=$(echo $libavfilters_all)

libavdecoders=$(filter_out_component decoder 'LIB[A-Z0-9_]*')
libavencoders=$(filter_out_component encoder 'LIB[A-Z0-9_]*')
libavdemuxers=$(filter_out_component demuxer 'AVISYNTH LIB[A-Z0-9_]* REDIR')
libavmuxers=$(filter_out_component muxer 'LIB[A-Z0-9_]* RTP RTSP SAP')
libavprotocols=$(filter_out_component protocol 'BLURAY FFRTMPCRYPT HTTPS TLS')
libavfilters=$(filter_out_component filter 'FREI0R[A-Z0-9_]* LIB[A-Z0-9_]* MP OCV')

# second pass command line parsing for options needing local FFmpeg checkout
for ac_option do
  case "$ac_option" in
  --enable-decoder=*)   libavdecoders="$libavdecoders   $(option_value_uc $ac_option)" ;;
  --enable-encoder=*)   libavencoders="$libavencoders   $(option_value_uc $ac_option)" ;;
  --enable-parser=*)    libavparsers="$libavparsers     $(option_value_uc $ac_option)" ;;
  --enable-protocol=*)  libavprotocols="$libavprotocols $(option_value_uc $ac_option)" ;;
  --enable-demuxer=*)   libavdemuxers="$libavdemuxers   $(option_value_uc $ac_option)" ;;
  --enable-muxer=*)     libavmuxers="$libavmuxers       $(option_value_uc $ac_option)" ;;
  --enable-filter=*)    libavfilters="$libavfilters     $(option_value_uc $ac_option)" ;;

  --disable-decoder=*)  libavdecoders=$(filter_out_component  decoder  "$(option_value_uc $ac_option)") ;;
  --disable-encoder=*)  libavencoders=$(filter_out_component  encoder  "$(option_value_uc $ac_option)") ;;
  --disable-parser=*)   libavparsers=$(filter_out_component   parser   "$(option_value_uc $ac_option)") ;;
  --disable-protocol=*) libavprotocols=$(filter_out_component protocol "$(option_value_uc $ac_option)") ;;
  --disable-demuxer=*)  libavdemuxers=$(filter_out_component  demuxer  "$(option_value_uc $ac_option)") ;;
  --disable-muxer=*)    libavmuxers=$(filter_out_component    muxer    "$(option_value_uc $ac_option)") ;;
  --disable-filter=*)   libavfilters=$(filter_out_component   filter   "$(option_value_uc $ac_option)") ;;
  esac
done


# Checking CC version...
# Intel C++ Compilers (no autoselect, use CC=/some/binary ./configure)
if test "$(basename $_cc)" = "icc" || test "$(basename $_cc)" = "ecc"; then
  echocheck "$_cc version"
  cc_vendor=intel
  cc_name=$($_cc -V 2>&1 | head -n 1 | cut -d ',' -f 1)
  cc_version=$($_cc -V 2>&1 | head -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 3)
  _cc_major=$(echo $cc_version | cut -d '.' -f 1)
  _cc_minor=$(echo $cc_version | cut -d '.' -f 2)
  # TODO verify older icc/ecc compatibility
  case $cc_version in
    '')
      cc_version="v. ?.??, bad"
      cc_fail=yes
      ;;
    10.1|11.1|12.*|13.*)
      cc_version="$cc_version, ok"
      ;;
    *)
      cc_version="$cc_version, bad"
      cc_fail=yes
      ;;
  esac
  echores "$cc_version"
else
  for _cc in "$_cc" gcc cc ; do
    cc_name_tmp=$($_cc -v 2>&1 | tail -n 1 | cut -d ' ' -f 1)
    if test "$cc_name_tmp" = "gcc"; then
      cc_name=$cc_name_tmp
      echocheck "$_cc version"
      cc_vendor=gnu
      cc_version=$($_cc -dumpversion 2>&1)
      case $cc_version in
        2.96*)
          cc_fail=yes
          ;;
        *)
          _cc_major=$(echo $cc_version | cut -d '.' -f 1)
          _cc_minor=$(echo $cc_version | cut -d '.' -f 2)
          _cc_mini=$(echo $cc_version | cut -d '.' -f 3)
          ;;
      esac
      echores "$cc_version"
      break
    fi
    if $_cc -v 2>&1 | grep -q "clang"; then
      echocheck "$_cc version"
      cc_vendor=clang
      cc_version=$($_cc -dumpversion 2>&1)
      res_comment="experimental support only"
      echores "clang $cc_version"
      break
    fi
    cc_name_tmp=$($_cc -V 2>&1 | head -n 1 | cut -d ' ' -f 2,3)
    if test "$cc_name_tmp" = "Sun C"; then
      echocheck "$_cc version"
      cc_vendor=sun
      cc_version=$($_cc -V 2>&1 | head -n 1 | cut -d ' ' -f 4)
      res_comment="experimental support only"
      echores "Sun C $cc_version"
      break
    fi
  done
fi # icc
test "$cc_fail" = yes && die "unsupported compiler version"

# Determine our OS name and CPU architecture
if test -z "$_target" ; then
  # OS name
  system_name=$(uname -s 2>&1)
  case "$system_name" in
  Linux|FreeBSD|NetBSD|OpenBSD|DragonFly|BSD/OS|Darwin|SunOS|QNX|GNU|MorphOS|AIX|AmigaOS|Haiku)
    ;;
  IRIX*)
    system_name=IRIX
    ;;
  GNU/kFreeBSD)
    system_name=FreeBSD
    ;;
  HP-UX*)
    system_name=HP-UX
    ;;
  [cC][yY][gG][wW][iI][nN]*)
    system_name=CYGWIN
    ;;
  MINGW32*)
    system_name=MINGW32
    ;;
  OS/2*)
    system_name=OS/2
    ;;
  *)
    system_name="$system_name-UNKNOWN"
    ;;
  esac
  cpp_condition_check '' 'defined(__MINGW32__)' && system_name=MINGW32


  # host's CPU/instruction set
  case "$(uname -m 2>&1)" in
      x86_64|amd64|i[3-9]86*|i86pc|x86|x86pc|k5|k6|k6_2|k6_3|k6-2|k6-3|pentium*|athlon*|i586_i686|i586-i686) host_arch=i386 ;;
      ia64) host_arch=ia64 ;;
      macppc|ppc*|Power*) host_arch=ppc ;;
      alpha) host_arch=alpha ;;
      sun4*|sparc*) host_arch=sparc ;;
      parisc*|hppa*|9000*) host_arch=hppa ;;
      arm*|zaurus|cats) host_arch=arm ;;
      sh3|sh4|sh4a) host_arch=sh ;;
      s390) host_arch=s390 ;;
      s390x) host_arch=s390x ;;
      *mips*) host_arch=mips ;;
      vax) host_arch=vax ;;
      xtensa*) host_arch=xtensa ;;
      *) host_arch=UNKNOWN ;;
  esac
else # if test -z "$_target"
  for component in 3 2; do
    system_name=$(echo $_target | cut -d '-' -f $component)
    case "$(echo $system_name | tolower)" in
      linux) system_name=Linux ;;
      freebsd) system_name=FreeBSD ;;
      gnu/kfreebsd) system_name=FreeBSD ;;
      netbsd) system_name=NetBSD ;;
      bsd/os) system_name=BSD/OS ;;
      openbsd) system_name=OpenBSD ;;
      dragonfly) system_name=DragonFly ;;
      sunos) system_name=SunOS ;;
      qnx) system_name=QNX ;;
      morphos) system_name=MorphOS ;;
      amigaos) system_name=AmigaOS ;;
      mingw32*) system_name=MINGW32 ;;
      wine) system_name=Wine ;;
    esac
  done
  # We need to convert underscores so that values like k6-2 and pentium-mmx can be passed
  host_arch=$(echo $_target | cut -d '-' -f 1)
  if test $(echo $host_arch) != "x86_64" ; then
    host_arch=$(echo $host_arch | tr '_' '-')
  fi
fi

_timer=timer-linux.c
_getch=getch2.c

if darwin; then
  extra_cflags="-mdynamic-no-pic $extra_cflags"
  _timer=timer-darwin.c
fi

if aix ; then
  extra_ldflags="$extra_ldflags -lC"
fi

if irix ; then
  _ranlib='ar -r'
elif linux ; then
  _ranlib='true'
fi

if win32 ; then
  _exesuf=".exe"
  extra_cflags="$extra_cflags -fno-common"
  # -lwinmm is always needed for osdep/timer-win2.c
  timer_libs=-lwinmm
  _pe_executable=yes
  _timer=timer-win2.c
  _priority=yes
  def_dos_paths="#define HAVE_DOS_PATHS 1"
  def_priority="#define CONFIG_PRIORITY 1"
fi

if mingw32 ; then
  _getch=getch2-win.c
  shmem=yes
fi

if amigaos ; then
  _select=no
  _sighandler=no
  _stream_cache=no
  def_stream_cache="#undef CONFIG_STREAM_CACHE"
  extra_cflags="-DNEWLIB -D__USE_INLINE__ $extra_cflags"
fi

if qnx ; then
  extra_ldflags="$extra_ldflags -lph"
fi

if os2 ; then
  _exesuf=".exe"
  _getch=getch2-os2.c
  shmem=yes
  _priority=yes
  def_dos_paths="#define HAVE_DOS_PATHS 1"
  def_priority="#define CONFIG_PRIORITY 1"
  def_path_max_check="#define CONFIG_PATH_MAX_CHECK 1"
fi

if wine ; then
  extra_cflags="-fno-pic -UWIN32 -U_WIN32 -U__WIN32 -U__WIN32__ -DWINE_NOWINSOCK -Dstricmp=strcasecmp $extra_cflags"
fi

if darwin && test "$cc_vendor" != "clang" ; then
  extra_cflags="-falign-loops=16 -shared-libgcc $extra_cflags"
fi

TMPEXE="$mplayer_tmpdir/tmp$_exesuf"

echocheck "working compiler"
cflag_check "" || die "Compiler is not functioning correctly. Check your installation and custom CFLAGS $CFLAGS ."
echo "yes"

if test -z "$_target" ; then
  cat > $TMPC << EOF
int main(void) {
    int test[(int)sizeof(char *)-7];
    return 0;
}
EOF
if x86 ; then
  cc_check && host_arch=x86_64 || host_arch=i386
fi
if ppc ; then
  cc_check && host_arch=ppc64 || host_arch=ppc
fi
if sparc ; then
  cc_check && host_arch=sparc64 || host_arch=sparc
fi
fi

echo "Detected operating system: $system_name"
echo "Detected host architecture: $host_arch"

if test "$_runtime_cpudetection" = yes && ! x86 && ! ppc; then
  die "Runtime CPU detection only works for x86, x86-64 and PPC!"
fi

echocheck "cross compilation"
if test $_cross_compile = auto ; then
  _cross_compile=yes
  cflag_check "" && "$TMPEXE" && _cross_compile=no
fi
echores $_cross_compile

if test $_cross_compile = yes; then
  tmp_run() {
    return 0
  }
  test "$_host_cc" || _host_cc=cc
fi

echocheck "host cc"
test "$_host_cc" || _host_cc=$_cc
echores $_host_cc

# ---

# now that we know what compiler should be used for compilation, try to find
# out which assembler is used by the $_cc compiler
if test "$_as" = auto ; then
  _as=$($_cc -print-prog-name=as)
  test -z "$_as" && _as=as
fi

if test "$_nm" = auto ; then
  _nm=$($_cc -print-prog-name=nm)
  test -z "$_nm" && _nm=nm
fi

# XXX: this should be OK..
_cpuinfo="echo"

if test "$_runtime_cpudetection" = no ; then

# Cygwin has /proc/cpuinfo, but only supports Intel CPUs
# FIXME: Remove the Cygwin check once AMD CPUs are supported
if test -r /proc/cpuinfo && ! cygwin; then
  # Linux with /proc mounted, extract CPU information from it
  _cpuinfo="cat /proc/cpuinfo"
elif test -r /compat/linux/proc/cpuinfo && ! x86 ; then
  # FreeBSD with Linux emulation /proc mounted,
  # extract CPU information from it
  # Don't use it on x86 though, it never reports 3DNow!
  _cpuinfo="cat /compat/linux/proc/cpuinfo"
elif darwin && ! x86 ; then
  # use hostinfo on Darwin
  _cpuinfo="hostinfo"
elif aix; then
  # use 'lsattr' on AIX
  _cpuinfo="lsattr -E -l proc0 -a type"
elif x86; then
  # all other OSes try to extract CPU information from a small helper
  # program cpuinfo instead
  $_host_cc -o cpuinfo$_exesuf cpuinfo.c
  _cpuinfo="./cpuinfo$_exesuf"
fi

if x86 ; then
  # gather more CPU information
  pname=$($_cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -n 1)
  pvendor=$($_cpuinfo | grep 'vendor_id' | cut -d ':' -f 2  | cut -d ' ' -f 2 | head -n 1)
  pfamily=$($_cpuinfo | grep 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
  pmodel=$($_cpuinfo | grep -v 'model name' | grep 'model' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
  pstepping=$($_cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)

  exts=$($_cpuinfo | egrep 'features|flags' | cut -d ':' -f 2 | head -n 1)

  pparam=$(echo $exts | sed -e s/k6_mtrr/mtrr/ -e s/cyrix_arr/mtrr/ -e s/centaur_mcr/mtrr/ \
                            -e s/xmm/sse/ -e s/kni/sse/ -e s/pni/sse3/)
  # SSE implies MMX2, but not all SSE processors report the mmxext CPU flag.
  pparam=$(echo $pparam | sed -e 's/sse/sse mmxext/')

  for ext in $pparam ; do
    eval test \"\$_$ext\" = auto 2>/dev/null && eval _$ext=kernel_check
  done

  echocheck "CPU vendor"
  echores "$pvendor ($pfamily:$pmodel:$pstepping)"

  echocheck "CPU type"
  echores "$pname"
fi

fi # test "$_runtime_cpudetection" = no

if x86 && test "$_runtime_cpudetection" = no ; then
  extcheck() {
    if test "$1" = kernel_check ; then
      echocheck "kernel support of $2"
      cat > $TMPC <<EOF
#include <stdlib.h>
#include <signal.h>
static void catch(int sig) { exit(1); }
int main(void) {
  signal(SIGILL, catch);
  __asm__ volatile ("$3":::"memory"); return 0;
}
EOF

      if cc_check && tmp_run ; then
        eval _$2=yes
        echores "yes"
        _optimizing="$_optimizing $2"
        return 0
      else
        eval _$2=no
        echores "failed"
        echo "It seems that your kernel does not correctly support $2."
        echo "To use $2 extensions in MPlayer, you have to upgrade/recompile your kernel!"
        return 1
      fi
    fi
    return 0
  }

  extcheck $_mmx      "mmx"      "emms"
  extcheck $_mmxext   "mmxext"   "sfence"
  extcheck $_3dnow    "3dnow"    "femms"
  extcheck $_3dnowext "3dnowext" "pswapd %%mm0, %%mm0"
  extcheck $_sse      "sse"      "xorps %%xmm0, %%xmm0" || _gcc3_ext="$_gcc3_ext -mno-sse"
  extcheck $_sse2     "sse2"     "xorpd %%xmm0, %%xmm0" || _gcc3_ext="$_gcc3_ext -mno-sse2"
  extcheck $_sse3     "sse3"     "addsubps %%xmm0, %%xmm0"
  extcheck $_ssse3    "ssse3"    "pabsd %%xmm0, %%xmm0"
  extcheck $_sse4_1   "sse4_1"   "pmaxsb %%xmm0, %%xmm0"
  extcheck $_sse4_2   "sse4_2"   "pcmpgtq %%xmm0, %%xmm0"
  extcheck $_avx      "avx"      "vpabsw %%xmm0, %%xmm0"
  extcheck $_cmov     "cmov"     "cmovb %%eax,  %%ebx"

  echocheck "mtrr support"
  if test "$_mtrr" = kernel_check ; then
    _mtrr="yes"
    _optimizing="$_optimizing mtrr"
  fi
  echores "$_mtrr"

  if test "$_gcc3_ext" != ""; then
    # If we had to disable SSE/SSE2 because the active kernel does not
    # support this instruction set extension, we also have to tell
    # gcc3 to not generate SSE/SSE2 instructions for normal C code.
    cflag_check $_march $_gcc3_ext && _march="$_march $_gcc3_ext"
  fi

fi


def_fast_64bit='#define HAVE_FAST_64BIT 0'
def_fast_unaligned='#define HAVE_FAST_UNALIGNED 0'
def_av_fast_unaligned='#define AV_HAVE_FAST_UNALIGNED 0'
def_local_aligned_8='#define HAVE_LOCAL_ALIGNED_8 0'
def_local_aligned_16='#define HAVE_LOCAL_ALIGNED_16 0'
arch_all='X86 IA64 SPARC ARM AVR32 SH4 PPC ALPHA MIPS PA_RISC S390 S390X VAX BFIN XTENSA TOMI GENERIC'
subarch_all='X86_32 X86_64 PPC64'
case "$host_arch" in
  i[3-9]86|x86|x86pc|k5|k6|k6-2|k6-3|pentium*|athlon*|i586-i686)
  arch='x86'
  subarch='x86_32'
  def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
  def_av_fast_unaligned='#define AV_HAVE_FAST_UNALIGNED 1'
  def_local_aligned_8='#define HAVE_LOCAL_ALIGNED_8 1'
  def_local_aligned_16='#define HAVE_LOCAL_ALIGNED_16 1'
  iproc=486
  proc=i486


  if test "$_runtime_cpudetection" = no ; then
  case "$pvendor" in
  AuthenticAMD)
    case "$pfamily" in
    3) proc=i386 iproc=386 ;;
    4) proc=i486 iproc=486 ;;
    5) iproc=586       # LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3
        # K6 model 13 are the K6-2+ and K6-III+, only differing in cache size.
        if test "$pmodel" -eq 9 -o "$pmodel" -eq 13; then
            proc=k6-3
        elif test "$pmodel" -eq 5 -o "$pmodel" -eq 10; then
            proc=geode
        elif test "$pmodel" -ge 8; then
            proc=k6-2
        elif test "$pmodel" -ge 6; then
            proc=k6
        else
            proc=i586
        fi
        ;;
    6) iproc=686
        # It's a bit difficult to determine the correct type of Family 6
        # AMD CPUs just from their signature. Instead, we check directly
        # whether it supports SSE.
        if test "$_sse" = yes; then
            # gcc treats athlon-xp, athlon-4 and athlon-mp similarly.
            proc=athlon-xp
        else
            # Again, gcc treats athlon and athlon-tbird similarly.
            proc=athlon
        fi
        ;;
    15) iproc=686
        # k8 CPU type only supported in gcc >= 3.4.0, but that will be
        # caught and remedied in the optimization tests below.
        proc=k8
        ;;

    *) proc=amdfam10 iproc=686
        test $_fast_clz = "auto" && _fast_clz=yes
        ;;
    esac
    ;;
  GenuineIntel)
    case "$pfamily" in
    3) proc=i386 iproc=386 ;;
    4) proc=i486 iproc=486 ;;
    5) iproc=586
        if test "$pmodel" -eq 4 || test "$pmodel" -eq 8; then
            proc=pentium-mmx # 4 is desktop, 8 is mobile
        else
            proc=i586
        fi
        ;;
    6) iproc=686
        if test "$pmodel" -eq 28 -o "$pmodel" -eq 38 -o "$pmodel" -eq 54; then
            proc=atom
        elif test "$pmodel" -ge 15; then
            proc=core2
        elif test "$pmodel" -eq 9 -o "$pmodel" -ge 13; then
            proc=pentium-m
        elif test "$pmodel" -ge 7; then
            proc=pentium3
        elif test "$pmodel" -ge 3; then
            proc=pentium2
        else
            proc=i686
        fi
        test $_fast_clz = "auto" && _fast_clz=yes
        ;;
    15) iproc=686
        # A nocona in 32-bit mode has no more capabilities than a prescott.
        if test "$pmodel" -ge 3; then
            proc=prescott
        else
            proc=pentium4
            test $_fast_clz = "auto" && _fast_clz=yes
        fi
        test $_fast_cmov = "auto" && _fast_cmov=no
        ;;
    *) proc=prescott iproc=686 ;;
    esac
    ;;
  CentaurHauls)
    case "$pfamily" in
    5) iproc=586
        if test "$pmodel" -ge 8; then
            proc=winchip2
        elif test "$pmodel" -ge 4; then
            proc=winchip-c6
        else
            proc=i586
        fi
        ;;
    6) iproc=686
        if test "$pmodel" -ge 9; then
            proc=c3-2
        else
            proc=c3
            iproc=586
        fi
        ;;
    *) proc=i686 iproc=i686 ;;
    esac
    ;;
  unknown)
    case "$pfamily" in
    3) proc=i386 iproc=386 ;;
    4) proc=i486 iproc=486 ;;
    *) proc=i586 iproc=586 ;;
    esac
    ;;
  *)
    proc=i586 iproc=586 ;;
  esac
  test $_fast_clz = "auto" && _fast_clz=no
  fi # test "$_runtime_cpudetection" = no


    # check that gcc supports our CPU, if not, fall back to earlier ones
    # LGB: check -mcpu and -march swithing step by step with enabling
    # to fall back till 386.

    # gcc >= 3.4.0  doesn't support -mcpu, we have to use -mtune instead

    if [ "$cc_vendor" = "gnu" ] && ([ "$_cc_major" -gt 3 ] || ( [ "$_cc_major" = 3 ] && [ "$_cc_minor" -ge 4 ])) ; then
        cpuopt=-mtune
    else
        cpuopt=-mcpu
    fi

    echocheck "GCC & CPU optimization abilities"
  if test "$_runtime_cpudetection" = no ; then
    if test $cc_vendor != "intel" && test $cc_vendor != "clang" ; then
      cflag_check -march=native && proc=native
    fi
    if test "$proc" = "amdfam10"; then
      cflag_check -march=$proc $cpuopt=$proc || proc=k8
    fi
    if test "$proc" = "k8"; then
      cflag_check -march=$proc $cpuopt=$proc || proc=athlon-xp
    fi
    if test "$proc" = "athlon-xp"; then
      cflag_check -march=$proc $cpuopt=$proc || proc=athlon
    fi
    if test "$proc" = "k6-3" || test "$proc" = "k6-2"; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=k6
    fi
    if test "$proc" = "k6" || test "$proc" = "c3"; then
      if ! cflag_check -march=$proc $cpuopt=$proc; then
        if cflag_check -march=i586 $cpuopt=i686; then
          proc=i586-i686
        else
          proc=i586
        fi
      fi
    fi
    if test "$proc" = "atom" ; then
      cflag_check -march=$proc $cpuopt=$proc || proc=core2
    fi
    if test "$proc" = "prescott" ; then
      cflag_check -march=$proc $cpuopt=$proc || proc=pentium4
    fi
    if test "$proc" = "core2" ; then
      cflag_check -march=$proc $cpuopt=$proc || proc=pentium-m
    fi
    if test "$proc" = "pentium4" || test "$proc" = "pentium-m" || test "$proc" = "pentium3" || test "$proc" = "pentium2" || test "$proc" = "athlon" || test "$proc" = "c3-2" || test "$proc" = "geode"; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=i686
    fi
    if test "$proc" = "i686" || test "$proc" = "pentium-mmx" || test "$proc" = "winchip-c6" || test "$proc" = "winchip2"; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=i586
    fi
    if test "$proc" = "i586"; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=i486
    fi
    if test "$proc" = "i486" ; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=i386
    fi
    if test "$proc" = "i386" ; then
      cflag_check -march=$proc $cpuopt=$proc  || proc=error
    fi
    if test "$proc" = "error" ; then
        echores "CPU optimization disabled. CPU not recognized or your compiler is too old."
      _mcpu=""
      _march=""
      _optimizing=""
    elif test "$proc" = "i586-i686"; then
      _march="-march=i586"
      _mcpu="$cpuopt=i686"
      _optimizing="$proc"
    else
      _march="-march=$proc"
      _mcpu="$cpuopt=$proc"
      _optimizing="$proc"
    fi
  else # if test "$_runtime_cpudetection" = no
    _mcpu="$cpuopt=generic"
    # at least i486 required, for bswap instruction
    _march="-march=i486"
    cflag_check $_mcpu || _mcpu="$cpuopt=i686"
    cflag_check $_mcpu || _mcpu=""
    cflag_check $_march $_mcpu || _march=""
  fi

    ## Gabucino : --target takes effect here (hopefully...) by overwriting
    ##             autodetected mcpu/march parameters
    if test "$_target" ; then
      # TODO: it may be a good idea to check GCC and fall back in all cases
      if test "$host_arch" = "i586-i686"; then
        _march="-march=i586"
        _mcpu="$cpuopt=i686"
      else
        _march="-march=$host_arch"
        _mcpu="$cpuopt=$host_arch"
      fi

      proc="$host_arch"

      case "$proc" in
        i386) iproc=386 ;;
        i486) iproc=486 ;;
        i586|k5|k6|k6-2|k6-3|pentium|pentium-mmx) iproc=586 ;;
        i686|athlon*|pentium*) iproc=686 ;;
        *) iproc=586 ;;
      esac
    fi

    if test $_cmov = "yes" && test $_fast_cmov = "auto" ; then
        _fast_cmov="yes"
    else
        _fast_cmov="no"
    fi
    test $_fast_clz = "auto" && _fast_clz=yes

    echores "$proc"
    ;;

  ia64)
    arch='ia64'
    def_fast_64bit='#define HAVE_FAST_64BIT 1'
    iproc='ia64'
    ;;

  x86_64|amd64)
    arch='x86'
    subarch='x86_64'
    def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
    def_av_fast_unaligned='#define AV_HAVE_FAST_UNALIGNED 1'
    def_local_aligned_8='#define HAVE_LOCAL_ALIGNED_8 1'
    def_local_aligned_16='#define HAVE_LOCAL_ALIGNED_16 1'
    def_fast_64bit='#define HAVE_FAST_64BIT 1'
    iproc='x86_64'

    # gcc >= 3.4.0  doesn't support -mcpu, we have to use -mtune instead
    if test "$cc_vendor" = "gnu" && test "$_cc_major" -gt 3 -o "$_cc_major" -eq 3 -a "$_cc_minor" -ge 4 ; then
        cpuopt=-mtune
    else
        cpuopt=-mcpu
    fi
    if test "$_runtime_cpudetection" = no ; then
      case "$pvendor" in
      AuthenticAMD)
        case "$pfamily" in
        15) proc=k8
          test $_fast_clz = "auto" && _fast_clz=no
          ;;
        *) proc=amdfam10;;
        esac
        ;;
      GenuineIntel)
        case "$pfamily" in
        6)
          if test "$pmodel" -eq 28 -o "$pmodel" -eq 38 -o "$pmodel" -eq 54; then
            proc=atom
          elif test "$pmodel" -ge 42; then
            proc=corei7-avx
          elif test "$pmodel" -ge 26; then
            proc=corei7
          else
            proc=core2
          fi
          ;;
        *)
          # 64-bit prescotts exist, but as far as GCC is concerned they
          # have the same capabilities as a nocona.
          proc=nocona
          test $_fast_cmov = "auto" && _fast_cmov=no
          test $_fast_clz = "auto" && _fast_clz=no
          ;;
        esac
        ;;
      *)
        proc=error;;
      esac
    fi # test "$_runtime_cpudetection" = no

    echocheck "GCC & CPU optimization abilities"
    # This is a stripped-down version of the i386 fallback.
    if test "$_runtime_cpudetection" = no ; then
      if test $cc_vendor != "intel" && test $cc_vendor != "clang" ; then
        cflag_check -march=native && proc=native
      fi
      # --- AMD processors ---
      if test "$proc" = "amdfam10"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=k8
      fi
      if test "$proc" = "k8"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=athlon-xp
      fi
      # This will fail if gcc version < 3.3, which is OK because earlier
      # versions don't really support 64-bit on amd64.
      # Is this a valid assumption? -Corey
      if test "$proc" = "athlon-xp"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=error
      fi
      # --- Intel processors ---
      if test "$proc" = "atom" || test "$proc" = "corei7-avx" || test "$proc" = "corei7"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=core2
      fi
      if test "$proc" = "core2"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=x86-64
      fi
      if test "$proc" = "x86-64"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=nocona
      fi
      if test "$proc" = "nocona"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=pentium4
      fi
      if test "$proc" = "pentium4"; then
        cflag_check -march=$proc $cpuopt=$proc || proc=error
      fi

      _march="-march=$proc"
      _mcpu="$cpuopt=$proc"
      if test "$proc" = "error" ; then
        echores "CPU optimization disabled. CPU not recognized or your compiler is too old."
        _mcpu=""
        _march=""
      fi
    else # if test "$_runtime_cpudetection" = no
      # x86-64 is an undocumented option, an intersection of k8 and nocona.
      _march="-march=x86-64"
      _mcpu="$cpuopt=generic"
      cflag_check $_mcpu || _mcpu="x86-64"
      cflag_check $_mcpu || _mcpu=""
      cflag_check $_march $_mcpu || _march=""
    fi

    _optimizing="$proc"
    test $_fast_cmov = "auto" && _fast_cmov=yes
    test $_fast_clz = "auto" && _fast_clz=yes

    echores "$proc"
    ;;

  sparc|sparc64)
    arch='sparc'
    iproc='sparc'
    if test "$host_arch" = "sparc64" ; then
      _vis='yes'
      proc='ultrasparc'
      def_fast_64bit='#define HAVE_FAST_64BIT 1'
    elif sunos ; then
        echocheck "CPU type"
        karch=$(uname -m)
        case "$(echo $karch)" in
            sun4) proc=v7 ;;
            sun4c) proc=v7 ;;
            sun4d) proc=v8 ;;
            sun4m) proc=v8 ;;
            sun4u) proc=ultrasparc _vis='yes' ;;
            sun4v) proc=v9 ;;
            *) proc=v8 ;;
        esac
        echores "$proc"
    else
        proc=v8
    fi
    _mcpu="-mcpu=$proc"
    _optimizing="$proc"
    ;;

  arm*)
    arch='arm'
    iproc='arm'
    ;;

  avr32)
    arch='avr32'
    def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
    def_av_fast_unaligned='#define AV_HAVE_FAST_UNALIGNED 1'
    iproc='avr32'
    test $_fast_clz = "auto" && _fast_clz=yes
    ;;

  sh|sh4)
    arch='sh4'
    iproc='sh4'
    ;;

  ppc*|powerpc*)
    arch='ppc'
    def_dcbzl='#define HAVE_DCBZL 0'
    def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
    def_av_fast_unaligned='#define AV_HAVE_FAST_UNALIGNED 1'
    def_local_aligned_8='#define HAVE_LOCAL_ALIGNED_8 1'
    def_local_aligned_16='#define HAVE_LOCAL_ALIGNED_16 1'
    iproc='ppc'

    if test "$host_arch" = "ppc64" ; then
      subarch='ppc64'
      def_fast_64bit='#define HAVE_FAST_64BIT 1'
    fi
    echocheck "CPU type"
    case $system_name in
      Linux)
        proc=$($_cpuinfo | grep 'cpu' | cut -d ':' -f 2 | cut -d ',' -f 1 | cut -b 2- | head -n 1)
        if test -n "$($_cpuinfo | grep altivec)"; then
            test $_altivec = auto && _altivec=yes
        fi
        ;;
      Darwin)
        proc=$($_cpuinfo | grep "Processor type" | cut -f 3 -d ' ' | sed 's/ppc//')
        if [ $(sysctl -n hw.vectorunit) -eq 1 -o \
            "$(sysctl -n hw.optional.altivec 2> /dev/null)" = "1" ]; then
            test $_altivec = auto && _altivec=yes
        fi
        ;;
      NetBSD)
        # only gcc 3.4 works reliably with AltiVec code under NetBSD
        case $cc_version in
            2*|3.0*|3.1*|3.2*|3.3*)
                ;;
            *)
                if [ $(sysctl -n machdep.altivec) -eq 1 ]; then
                    test $_altivec = auto && _altivec=yes
                fi
                ;;
        esac
        ;;
      AIX)
        proc=$($_cpuinfo | grep 'type' | cut -f 2 -d ' ' | sed 's/PowerPC_//')
        ;;
    esac
    if test "$_altivec" = yes; then
        echores "$proc altivec"
    else
        _altivec=no
        echores "$proc"
    fi

    echocheck "GCC & CPU optimization abilities"

    if test -n "$proc"; then
        case "$proc" in
            601) _march='-mcpu=601' _mcpu='-mtune=601' ;;
            603) _march='-mcpu=603' _mcpu='-mtune=603' ;;
            603e|603ev) _march='-mcpu=603e' _mcpu='-mtune=603e' ;;
            604|604e|604r|604ev) _march='-mcpu=604' _mcpu='-mtune=604' ;;
            740|740/750|745/755) _march='-mcpu=740' _mcpu='-mtune=740' ;;
            750|750CX) _march='-mcpu=750' _mcpu='-mtune=750' ;;
            POWER)  _march='-mcpu=power'  _mcpu='-mtune=power'  ;;
            POWER2) _march='-mcpu=power2' _mcpu='-mtune=power2' ;;
            POWER3) _march='-mcpu=power3' _mcpu='-mtune=power3' ;;
            *) ;;
        esac
        # gcc 3.1(.1) and up supports 7400 and 7450
        if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "1" || test "$_cc_major" -ge "4"; then
            case "$proc" in
                7400*|7410*) _march='-mcpu=7400' _mcpu='-mtune=7400' ;;
                7447*|7450*|7455*) _march='-mcpu=7450' _mcpu='-mtune=7450' ;;
                *) ;;
            esac
        fi
        # gcc 3.2 and up supports 970
        if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "3" || test "$_cc_major" -ge "4"; then
            case "$proc" in
                970*|PPC970*) _march='-mcpu=970' _mcpu='-mtune=970'
                      def_dcbzl='#define HAVE_DCBZL 1' ;;
                *) ;;
            esac
        fi
        # gcc 3.3 and up supports POWER4
        if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "3" || test "$_cc_major" -ge "4"; then
            case "$proc" in
                POWER4) _march='-mcpu=power4' _mcpu='-mtune=power4' ;;
                *) ;;
            esac
        fi
        # gcc 3.4 and up supports 440*
        if test "$_cc_major" -ge "3" && test "$_cc_minor" -ge "4" || test "$_cc_major" -ge "4"; then
            case "$proc" in
                440EP*) _march='-mcpu=440fp' _mcpu='-mtune=440fp' ;;
                440G* ) _march='-mcpu=440'   _mcpu='-mtune=440'   ;;
                *) ;;
            esac
        fi
        # gcc 4.0 and up supports POWER5
        if test "$_cc_major" -ge "4"; then
            case "$proc" in
                POWER5*) _march='-mcpu=power5' _mcpu='-mtune=power5' ;;
                *) ;;
            esac
        fi
    fi

    if test -n "$_mcpu"; then
        _optimizing=$(echo $_mcpu | cut -c 8-)
        echores "$_optimizing"
    else
        echores "none"
    fi

    test $_fast_clz = "auto" && _fast_clz=yes

    ;;

  alpha*)
    arch='alpha'
    iproc='alpha'

    echocheck "CPU type"
    cat > $TMPC << EOF
int main(void) {
    unsigned long ver, mask;
    __asm__ ("implver %0" : "=r" (ver));
    __asm__ ("amask %1, %0" : "=r" (mask) : "r" (-1));
    printf("%ld-%x\n", ver, ~mask);
    return 0;
}
EOF
    $_cc -o "$TMPEXE" "$TMPC"
    case $("$TMPEXE") in

        0-0)    proc="ev4";   _mvi="0";;
        1-0)    proc="ev5";   _mvi="0";;
        1-1)    proc="ev56";  _mvi="0";;
        1-101)  proc="pca56"; _mvi="1";;
        2-303)  proc="ev6";   _mvi="1";;
        2-307)  proc="ev67";  _mvi="1";;
        2-1307) proc="ev68";  _mvi="1";;
    esac
    echores "$proc"

    echocheck "GCC & CPU optimization abilities"
    if test "$proc" = "ev68" ; then
      cc_check -mcpu=$proc || proc=ev67
    fi
    if test "$proc" = "ev67" ; then
      cc_check -mcpu=$proc || proc=ev6
    fi
    _mcpu="-mcpu=$proc"
    echores "$proc"

    test $_fast_clz = "auto" && _fast_clz=yes

    _optimizing="$proc"
    ;;

  mips*)
    arch='mips'
    iproc='mips'

    if irix ; then
        echocheck "CPU type"
        proc=$(hinv -c processor | grep CPU | cut -d " " -f3)
        case "$(echo $proc)" in
            R3000) _march='-mips1' _mcpu='-mtune=r2000' ;;
            R4000) _march='-mips3' _mcpu='-mtune=r4000' ;;
            R4400) _march='-mips3' _mcpu='-mtune=r4400' ;;
            R4600) _march='-mips3' _mcpu='-mtune=r4600' ;;
            R5000) _march='-mips4' _mcpu='-mtune=r5000' ;;
            R8000|R10000|R12000|R14000|R16000) _march='-mips4' _mcpu='-mtune=r8000' ;;
        esac
        # gcc < 3.x does not support -mtune.
        if test "$cc_vendor" = "gnu" && test "$_cc_major" -lt 3 ; then
            _mcpu=''
        fi
        echores "$proc"
    fi

    test $_fast_clz = "auto" && _fast_clz=yes

    ;;

  hppa)
    arch='pa_risc'
    iproc='PA-RISC'
    ;;

  s390)
    arch='s390'
    iproc='390'
    ;;

  s390x)
    arch='s390x'
    iproc='390x'
    ;;

  vax)
    arch='vax'
    iproc='vax'
    ;;

  xtensa)
    arch='xtensa'
    iproc='xtensa'
    ;;

  generic)
    arch='generic'
    ;;

  *)
    echo "The architecture of your CPU ($host_arch) is not supported by this configure script"
    echo "It seems nobody has ported MPlayer to your OS or CPU type yet."
    die "unsupported architecture $host_arch"
    ;;
esac # case "$host_arch" in

if test "$_runtime_cpudetection" = yes ; then
  if x86 ; then
    test "$_cmov"     != no && _cmov=yes
    x86_32 && _cmov=no
    test "$_mmx"      != no && _mmx=yes
    test "$_3dnow"    != no && _3dnow=yes
    test "$_3dnowext" != no && _3dnowext=yes
    test "$_mmxext"   != no && _mmxext=yes
    test "$_sse"      != no && _sse=yes
    test "$_sse2"     != no && _sse2=yes
    test "$_sse3"     != no && _sse3=yes
    test "$_ssse3"    != no && _ssse3=yes
    test "$_sse4_1"   != no && _sse4_1=yes
    test "$_sse4_2"   != no && _sse4_2=yes
    test "$_avx"      != no && _avx=yes
    test "$_mtrr"     != no && _mtrr=yes
  fi
  if ppc; then
    _altivec=yes
  fi
fi


# endian testing
echocheck "byte order"
if test "$_big_endian" = auto ; then
  cat > $TMPC <<EOF
short ascii_name[] = {
  'M' << 8 | 'P', 'l' << 8 | 'a', 'y' << 8 | 'e', 'r' << 8 | 'B',
  'i' << 8 | 'g', 'E' << 8 | 'n', 'd' << 8 | 'i', 'a' << 8 | 'n', 0 };
int main(void) { return (long)ascii_name; }
EOF
  if cc_check ; then
    # stdin is used to make "strings" not try something clever like
    # parse executable section headers (and possibly fail in the process)
    if strings < $TMPEXE | grep -q -l MPlayerBigEndian ; then
      _big_endian=yes
    else
      _big_endian=no
    fi
  else
    echo ${_echo_n} "failed to autodetect byte order, defaulting to ${_echo_c}"
  fi
fi
if test "$_big_endian" = yes ; then
  _byte_order='big-endian'
  def_bigendian='#define HAVE_BIGENDIAN 1'
  def_av_bigendian='#define AV_HAVE_BIGENDIAN 1'
else
  _byte_order='little-endian'
  def_bigendian='#define HAVE_BIGENDIAN 0'
  def_av_bigendian='#define AV_HAVE_BIGENDIAN 0'
fi
echores "$_byte_order"


echocheck "extern symbol prefix"
cat > $TMPC << EOF
int ff_extern;
EOF
cc_check -c || die "Symbol mangling check failed."
sym=$($_nm -P -g $TMPEXE)
extern_prefix=${sym%%ff_extern*}
def_extern_asm="#define EXTERN_ASM $extern_prefix"
def_extern_prefix="#define EXTERN_PREFIX \"$extern_prefix\""
echores $extern_prefix


echocheck "assembler support of -pipe option"
# -I. helps to detect compilers that just misunderstand -pipe like Sun C
cflag_check -pipe -I. && _pipe="-pipe" && echores "yes" || echores "no"


if darwin && test "$cc_vendor" = "gnu" ; then
echocheck "GCC support of -mstackrealign"
# GCC 4.2 and some earlier Apple versions support this flag on x86. Since
# Mac OS X/Intel has an ABI different from Windows this is needed to avoid
# crashes when loading Win32 DLLs. Unfortunately some gcc versions create
# wrong code with this flag, but this can be worked around by adding
# -fno-unit-at-a-time as described in the blog post at
# http://www.dribin.org/dave/blog/archives/2006/12/05/missing_third_param/
cat > $TMPC << EOF
__attribute__((noinline)) static int foo3(int i1, int i2, int i3) { return i3; }
int main(void) { return foo3(1, 2, 3) == 3 ? 0 : 1; }
EOF
  cc_check -O4 -mstackrealign && tmp_run && cflags_stackrealign=-mstackrealign
  test -z "$cflags_stackrealign" && cc_check -O4 -mstackrealign -fno-unit-at-a-time &&
    tmp_run && cflags_stackrealign="-mstackrealign -fno-unit-at-a-time"
  test -n "$cflags_stackrealign" && echores "yes" || echores "no"
fi # if darwin && test "$cc_vendor" = "gnu" ; then


# Checking for CFLAGS
_install_strip="-s"
if test -z "$CFLAGS" || test "$_profile" != "" || test "$_debug" != ""; then
  if test "$cc_vendor" = "intel" ; then
    CFLAGS="-O2 $_march $_mcpu $_pipe -fomit-frame-pointer"
    WARNFLAGS="-wd167 -wd556 -wd144"
  elif test "$cc_vendor" = "sun" ; then
    CFLAGS="-O2 $_march $_mcpu $_pipe -xc99 -xregs=frameptr"
  elif test "$cc_vendor" = "clang"; then
    CFLAGS="-O2 $_march $_pipe"
  elif test "$cc_vendor" != "gnu" ; then
    CFLAGS="-O2 $_march $_mcpu $_pipe"
  else
    CFLAGS="-O4 $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
    WARNFLAGS="-Wall -Wno-switch -Wno-parentheses -Wpointer-arith -Wredundant-decls"
    WARN_CFLAGS="-Werror-implicit-function-declaration"
    extra_ldflags="$extra_ldflags -ffast-math"
  fi

  if test "$_profile" != "" || test "$_debug" != ""; then
    CFLAGS="-O2 $_march $_mcpu $_pipe $_debug $_profile"
    WARNFLAGS="-W -Wall $WARNFLAGS"
    _install_strip=
  fi
else
  warn_cflags=yes
fi

CFLAGS="-D_ISOC99_SOURCE -I. -Iffmpeg $CFLAGS"
HOSTCFLAGS="-D_ISOC99_SOURCE -I. -Iffmpeg -O3"

# On glibc, add some more CPPFLAGS for enabling required functionality.
cpp_condition_check features.h "defined __GLIBC__" &&
  CFLAGS="-D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 $CFLAGS" &&
  HOSTCFLAGS="-D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 $HOSTCFLAGS" &&

if test "$cc_vendor" = "gnu" ; then
  cflag_check -fno-tree-vectorize && CFLAGS="$CFLAGS -fno-tree-vectorize"
  cflag_check -Wundef && WARNFLAGS="-Wundef $WARNFLAGS"
  cflag_check -std=gnu99 && WARN_CFLAGS="-std=gnu99 $WARN_CFLAGS"
  cflag_check -Wdeclaration-after-statement && WARN_CFLAGS="-Wdeclaration-after-statement $WARN_CFLAGS"
  cflag_check -Wno-pointer-sign && WARN_CFLAGS="-Wno-pointer-sign $WARN_CFLAGS"
  cflag_check -Wdisabled-optimization && WARN_CFLAGS="-Wdisabled-optimization $WARN_CFLAGS"
  cflag_check -Wmissing-prototypes && WARN_CFLAGS="-Wmissing-prototypes $WARN_CFLAGS"
  cflag_check -Wstrict-prototypes && WARN_CFLAGS="-Wstrict-prototypes $WARN_CFLAGS"
fi

cflag_check -mno-omit-leaf-frame-pointer && cflags_no_omit_leaf_frame_pointer="-mno-omit-leaf-frame-pointer"
cflag_check -MMD -MP && DEPFLAGS="-MMD -MP"


if test -n "$LDFLAGS" ; then
  extra_ldflags="$extra_ldflags $LDFLAGS"
  warn_cflags=yes
elif test "$cc_vendor" = "intel" ; then
  extra_ldflags="$extra_ldflags -i-static"
fi
if test -n "$CPPFLAGS" ; then
  extra_cflags="$extra_cflags $CPPFLAGS"
  warn_cflags=yes
fi


# try to create a relocatable binary by default
echocheck "relocatable binary"
if test $relocatable = "auto" ; then
  if test -n "$ld_static" ; then
    relocatable=no
    res_comment="PIE + static assumed to be broken"
  elif win32 && ! wine ; then
    relocatable=no
    res_comment="unnecessary and broken on win32"
  elif x86_32 && cflag_check -pie ; then
    extra_ldflags="$extra_ldflags -pie"
    relocatable=yes
    res_comment="non-PIC"
  elif x86_64 && cflag_check -fpie -pie ; then
    extra_ldflags="$extra_ldflags -fpie -pie"
    extra_cflags="$extra_cflags -fpie"
    relocatable=yes
    res_comment="fast PIC"
  else
    relocatable=no
    res_comment="unavailable or untested architecture"
  fi
elif test $relocatable = "yes" ; then
  if return_check "stdint.h" '(intptr_t)"test" >> 16' -pie ; then
    extra_ldflags="$extra_ldflags -pie"
    res_comment="non-PIC"
  else
    extra_ldflags="$extra_ldflags -fpie -pie"
    extra_cflags="$extra_cflags -fpie"
    res_comment="possibly slow PIC!"
  fi
fi
echores $relocatable

if x86_32 ; then
  # Checking assembler (_as) compatibility...
  # Added workaround for older as that reads from stdin by default - atmos
  as_version=$(echo '' | $_as -version 2>&1 | sed -n 's/^.*assembler \(version \)*\([0-9.]*\).*$/\2/p')
  echocheck "assembler ($_as $as_version)"

  _pref_as_version='2.9.1'
  echo 'nop' > $TMPS
  if test "$_mmx" = yes ; then
    echo 'emms' >> $TMPS
  fi
  if test "$_3dnow" = yes ; then
    _pref_as_version='2.10.1'
    echo 'femms' >> $TMPS
  fi
  if test "$_3dnowext" = yes ; then
    _pref_as_version='2.10.1'
    echo 'pswapd %mm0, %mm0' >> $TMPS
  fi
  if test "$_mmxext" = yes ; then
    _pref_as_version='2.10.1'
    echo 'movntq %mm0, (%eax)' >> $TMPS
  fi
  if test "$_sse" = yes ; then
    _pref_as_version='2.10.1'
    echo 'xorps %xmm0, %xmm0' >> $TMPS
  fi
  #if test "$_sse2" = yes ; then
  #  _pref_as_version='2.11'
  #  echo 'xorpd %xmm0, %xmm0' >> $TMPS
  #fi
  if test "$_cmov" = yes ; then
    _pref_as_version='2.10.1'
    echo 'cmovb %eax, %ebx' >> $TMPS
  fi
  if test "$_ssse3" = yes ; then
    _pref_as_version='2.16.92'
    echo 'pabsd %xmm0, %xmm1' >> $TMPS
  fi
  $_as $TMPS -o $TMPEXE > /dev/null 2>&1 || as_verc_fail=yes

  if test "$as_verc_fail" != yes ; then
    echores "ok"
  else
    res_comment="Upgrade binutils to ${_pref_as_version} or use --disable-ssse3 etc."
    echores "failed"
    die "obsolete binutils version"
  fi

fi #if x86_32


# Check if we need to compile as PIC for this combination of architecture, toolchain,
# gcc configuration (e.g. hardened or not) and compiler options.
# Needs to be after the relocatable handling, since PIE changes whether we need PIC or not.
echocheck "PIC"
def_pic='#define CONFIG_PIC 0'
pic=no
cpp_condition_check '' 'defined(__PIC__) || defined(__pic__) || defined(PIC)' && pic=yes
# This check is needed to work around issues with clang on OSX when compiling 64 bit relocatable binaries.
if x86_64 && test "$relocatable" = "yes" && test "$pic" = "no"; then
  res_comment="Broken compiler incorrectly claims PIC not necessary for PIE"
  pic=yes
fi
echores $pic
if test "$pic" = "yes" ; then
  extra_cflags="$extra_cflags -DPIC" && def_pic='#define CONFIG_PIC 1'
fi


def_bswap='#define HAVE_BSWAP 0'
def_ebx_available='#define HAVE_EBX_AVAILABLE 0'
def_xmm_clobbers='#define HAVE_XMM_CLOBBERS 0'

if x86_64 ; then
inline_asm_check '"mov (%eax), %eax"' || die "Your binutils version is too old to compile for 64-bit (on OSX try --cc=clang)"
fi

if x86 ; then

echocheck ".align is a power of two"
if test "$_asmalign_pot" = auto ; then
_asmalign_pot=no
inline_asm_check '".align 3"' && _asmalign_pot=yes
fi
if test "$_asmalign_pot" = "yes" ; then
  def_asmalign_pot='#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\n\t"'
else
  def_asmalign_pot='#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\n\t"'
fi
echores $_asmalign_pot


echocheck "ebx availability"
ebx_available=no
cat > $TMPC << EOF
int main(void) {
    int x;
    __asm__ volatile(
        "xor %0, %0"
        :"=b"(x)
        // just adding ebx to clobber list seems unreliable with some
        // compilers, e.g. Haiku's gcc 2.95
    );
    // and the above check does not work for OSX 64 bit...
    __asm__ volatile("":::"%ebx");
    return 0;
}
EOF
cc_check && ebx_available=yes && def_ebx_available='#define HAVE_EBX_AVAILABLE 1'
echores $ebx_available


echocheck "yasm"
if test -z "$YASMFLAGS" ; then
  if darwin ; then
    x86_64 && objformat="macho64" || objformat="macho"
  elif win32 && ! wine ; then
    objformat="win32"
  elif os2 ; then
    _yasm=nasm
    objformat="aout"
  else
    objformat="elf"
  fi
  yasmdefines=""
  # currently tested for Linux x86, x86_64
  test "$pic" = "yes"      && yasmdefines="$yasmdefines -DPIC"
  test -n "$extern_prefix" && yasmdefines="$yasmdefines -DPREFIX"

  YASMFLAGS="-f $objformat $yasmdefines"
  x86_64 && YASMFLAGS="$YASMFLAGS -m amd64"
  case "$objformat" in
    elf) test $_debug && YASMFLAGS="$YASMFLAGS -g dwarf2" ;;
  esac
else
  warn_cflags=yes
fi

echo "pextrd [eax], xmm0, 1" > $TMPS
yasm_features_all="cpunop"
if test "$_yasm" ; then
  if ! yasm_check ; then
    if x86_64 ; then
      case "$objformat" in
        elf)   objformat=elf64 ;;
        win32) objformat=win64 ;;
      esac
    fi
    YASMFLAGS="-f $objformat $yasmdefines"
    yasm_check || die "yasm not found, use --yasm='' if you really want to compile without"
    echo "CPU amdnop" > $TMPS
    yasm_check && yasm_features="cpunop"
  fi
fi
if test $_yasm ; then
  def_yasm='#define HAVE_YASM 1'
  have_yasm="yes"
  echores "$_yasm"
else
  def_yasm='#define HAVE_YASM 0'
  have_yasm="no"
  echores "no"
fi

echocheck "bswap"
echo 'bswap %eax' > $TMPS
$_as $TMPS -o $TMPEXE > /dev/null 2>&1 && def_bswap='#define HAVE_BSWAP 1' && bswap=yes || bswap=no
echores "$bswap"


echocheck "xmm clobbers"
inline_asm_check '"":::"%xmm0"' &&
  def_xmm_clobbers='#define HAVE_XMM_CLOBBERS 1' &&
  xmm_clobbers=yes || xmm_clobbers=no
echores "$xmm_clobbers"

else
  _yasm=''
  def_yasm='#define HAVE_YASM 0'
  have_yasm="no"
fi #if x86

#FIXME: This should happen before the check for CFLAGS..
def_altivec_h='#define HAVE_ALTIVEC_H 0'
if ppc && ( test "$_altivec" = yes || test "$_runtime_cpudetection" = yes ) ; then

    # check if AltiVec is supported by the compiler, and how to enable it
    echocheck "GCC AltiVec flags"
    if $(cflag_check -maltivec -mabi=altivec) ; then
    _altivec_gcc_flags="-maltivec -mabi=altivec"
    # check if <altivec.h> should be included
        if $(header_check altivec.h $_altivec_gcc_flags) ; then
            def_altivec_h='#define HAVE_ALTIVEC_H 1'
            inc_altivec_h='#include <altivec.h>'
        else
            if $(cflag_check -faltivec) ; then
                _altivec_gcc_flags="-faltivec"
            else
                _altivec=no
                _altivec_gcc_flags="none, AltiVec disabled"
            fi
        fi
    fi
    echores "$_altivec_gcc_flags"

    # check if the compiler supports braces for vector declarations
    cat > $TMPC << EOF
$inc_altivec_h
int main(void) { (vector int) {1}; return 0; }
EOF
    cc_check $_altivec_gcc_flags || die "You need a compiler that supports {} in AltiVec vector declarations."

    # Disable runtime cpudetection if we cannot generate AltiVec code or
    # AltiVec is disabled by the user.
    test "$_runtime_cpudetection" = yes && test "$_altivec" = no \
        && _runtime_cpudetection=no

    # Show that we are optimizing for AltiVec (if enabled and supported).
    test "$_runtime_cpudetection" = no && test "$_altivec" = yes \
        && _optimizing="$_optimizing altivec"

    # If AltiVec is enabled, make sure the correct flags turn up in CFLAGS.
    test "$_altivec" = yes && CFLAGS="$CFLAGS $_altivec_gcc_flags"
fi

if ppc ; then
def_xform_asm='#define HAVE_XFORM_ASM 0'
xform_asm=no
echocheck "XFORM ASM support"
inline_asm_check '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)' &&
  xform_asm=yes && def_xform_asm='#define HAVE_XFORM_ASM 1'
echores "$xform_asm"

def_ibm_asm='#define HAVE_IBM_ASM 0'
ibm_asm=no
echocheck "IBM ASM support"
inline_asm_check '"add 0, 0, 0"' &&
  ibm_asm=yes && def_ibm_asm='#define HAVE_IBM_ASM 1'
echores "$ibm_asm"

def_gnu_as='#define HAVE_GNU_AS 0'
gnu_as=no
echocheck "GNU assembler"
inline_asm_check '".macro m n\n\\n:.int 0\n.endm\nm x"' &&
  gnu_as=yes && def_gnu_as='#define HAVE_GNU_AS 1'
echores "$gnu_as"

fi

if arm ; then
  echocheck "ARMv5TE (Enhanced DSP Extensions)"
  if test $_armv5te = "auto" ; then
    _armv5te=no
    inline_asm_check '"qadd r0, r0, r0"' && _armv5te=yes
  fi
  echores "$_armv5te"

  test $_armv5te = "yes" && test $_fast_clz = "auto" && _fast_clz=yes

  echocheck "ARMv6 (SIMD instructions)"
  if test $_armv6 = "auto" ; then
    _armv6=no
    inline_asm_check '"sadd16 r0, r0, r0"' && _armv6=yes
  fi
  echores "$_armv6"

  echocheck "ARMv6t2 (SIMD instructions)"
  if test $_armv6t2 = "auto" ; then
    _armv6t2=no
    inline_asm_check '"movt r0, #0"' && _armv6t2=yes
  fi
  echores "$_armv6t2"

  echocheck "ARM VFP"
  if test $_armvfp = "auto" ; then
    _armvfp=no
    inline_asm_check '"fadds s0, s0, s0"' && _armvfp=yes
  fi
  echores "$_armvfp"

  echocheck "ARM VFPV3"
  if test $vfpv3 = "auto" ; then
    vfpv3=no
    inline_asm_check '"vmov.f32 s0, #1.0"' && vfpv3=yes
  fi
  echores "$vfpv3"

  echocheck "softfloat ABI"
  softfloat=yes
  cpp_condition_check '' 'defined(__ARM_PCS_VFP) || (!defined(__ARM_PCS) && !defined(__SOFTFP__))' && softfloat=no
  if test $softfloat = "yes" ; then
    def_vfp_args='#define HAVE_VFP_ARGS 0'
  else
    def_vfp_args='#define HAVE_VFP_ARGS 1'
  fi
  echores "$softfloat"

  echocheck "ARM NEON"
  if test $neon = "auto" ; then
    neon=no
    inline_asm_check '"vadd.i16 q0, q0, q0"' && neon=yes
  fi
  echores "$neon"

  echocheck "ARM THUMB"
  if test $armthumb = "auto" ; then
    armthumb=no
  fi
  if test $armthumb = "yes" ; then
    extra_cflags="$extra_cflags -mthumb"
    def_armthumb='#define CONFIG_THUMB 1'
  else
    extra_cflags="$extra_cflags -marm"
    def_armthumb='#define CONFIG_THUMB 0'
  fi
  echores "$armthumb"

  echocheck "iWMMXt (Intel XScale SIMD instructions)"
  if test $_iwmmxt = "auto" ; then
    _iwmmxt=no
    inline_asm_check '"wunpckelub wr6, wr4"' && _iwmmxt=yes
  fi
  echores "$_iwmmxt"
fi

cpuexts_all='ALTIVEC AVX MMX MMX2 MMXEXT AMD3DNOW AMD3DNOWEXT SSE SSE2 SSE3 SSSE3 SSE4 SSE42 FAST_CMOV I686 FAST_CLZ ARMV5TE ARMV6 ARMV6T2 VFP VFPV3 NEON IWMMXT MMI VIS MVI'
test "$_altivec"   = yes && cpuexts="ALTIVEC $cpuexts"
test "$_mmx"       = yes && cpuexts="MMX $cpuexts"
test "$_mmxext"    = yes && cpuexts="MMX2 $cpuexts"
test "$_mmxext"    = yes && cpuexts="MMXEXT $cpuexts"
test "$_3dnow"     = yes && cpuexts="AMD3DNOW $cpuexts"
test "$_3dnowext"  = yes && cpuexts="AMD3DNOWEXT $cpuexts"
test "$_sse"       = yes && cpuexts="SSE $cpuexts"
test "$_sse2"      = yes && cpuexts="SSE2 $cpuexts"
test "$_sse3"      = yes && cpuexts="SSE3 $cpuexts"
test "$_ssse3"     = yes && cpuexts="SSSE3 $cpuexts"
test "$_sse4_1"    = yes && cpuexts="SSE4 $cpuexts"
test "$_sse4_2"    = yes && cpuexts="SSE42 $cpuexts"
test "$_avx"       = yes && cpuexts="AVX $cpuexts"
test "$_cmov"      = yes && cpuexts="I686 $cpuexts"
test "$_fast_cmov" = yes && cpuexts="FAST_CMOV $cpuexts"
test "$_fast_clz"  = yes && cpuexts="FAST_CLZ $cpuexts"
test "$_armv5te"   = yes && cpuexts="ARMV5TE $cpuexts"
test "$_armv6"     = yes && cpuexts="ARMV6 $cpuexts"
test "$_armv6t2"   = yes && cpuexts="ARMV6T2 $cpuexts"
test "$_armvfp"    = yes && cpuexts="VFP $cpuexts"
test "$vfpv3"      = yes && cpuexts="VFPV3 $cpuexts"
test "$neon"       = yes && cpuexts="NEON $cpuexts"
test "$_iwmmxt"    = yes && cpuexts="IWMMXT $cpuexts"
test "$_vis"       = yes && cpuexts="VIS $cpuexts"
test "$_mvi"       = yes && cpuexts="MVI $cpuexts"

# Checking kernel version...
if x86_32 && linux ; then
  _k_verc_problem=no
  kernel_version=$(uname -r 2>&1)
  echocheck "$system_name kernel version"
  case "$kernel_version" in
    '') kernel_version="?.??"; _k_verc_fail=yes;;
    [0-1].[0-9].[0-9]*|2.[0-3].[0-9]*)
      _k_verc_problem=yes;;
  esac
  if test "$_k_verc_problem" = yes && test "$_sse" = yes ; then
    _k_verc_fail=yes
  fi
  if test "$_k_verc_fail" ; then
    echores "$kernel_version, fail"
    echo "WARNING! If you want to run MPlayer on this system, get prepared for problems!"
    echo "2.2.x has limited SSE support. Upgrade the kernel or use --disable-sse if you"
    echo "experience crashes. MPlayer tries to autodetect if your kernel correctly"
    echo "supports SSE, but you have been warned! If you are using a kernel older than"
    echo "2.2.x you must upgrade it to get SSE support!"
#    die "Your kernel is too old for this CPU." # works fine on some 2.2.x so don't die (later check will test)
  else
    echores "$kernel_version, ok"
  fi
fi

######################
# MAIN TESTS GO HERE #
######################


echocheck "langinfo"
if test "$_langinfo" = auto ; then
  _langinfo=no
  statement_check langinfo.h 'nl_langinfo(CODESET)' && _langinfo=yes
fi
if test "$_langinfo" = yes ; then
  def_langinfo='#define HAVE_LANGINFO 1'
else
  def_langinfo='#undef HAVE_LANGINFO'
fi
echores "$_langinfo"


echocheck "language"
# Set preferred languages, "all" uses English as main language.
test -z "$language" && language=$LINGUAS
test -z "$language_doc" && language_doc=$language
test -z "$language_man" && language_man=$language
test -z "$language_msg" && language_msg=$language
language_doc=$(echo $language_doc | tr , " ")
language_man=$(echo $language_man | tr , " ")
language_msg=$(echo $language_msg | tr , " ")

test "$language_doc" = "all" && language_doc=$doc_lang_all
test "$language_man" = "all" && language_man=$man_lang_all
test "$language_msg" = "all" && language_msg=en

# Prune non-existing translations from language lists.
# Set message translation to the first available language.
# Fall back on English.
for lang in $language_doc ; do
  test -d DOCS/xml/$lang && tmp_language_doc="$tmp_language_doc $lang"
done
language_doc=$tmp_language_doc
test -z "$language_doc" && language_doc=en

for lang in $language_man ; do
  test -d DOCS/man/$lang && tmp_language_man="$tmp_language_man $lang"
done
language_man=$tmp_language_man
test -z "$language_man" && language_man=en

for lang in $language_msg ; do
  test -f "help/help_mp-${lang}.h" && tmp_language_msg=$lang && break
done
language_msg=$tmp_language_msg
test -z "$language_msg" && language_msg=en
_mp_help="help/help_mp-${language_msg}.h"
echores "messages: $language_msg - man pages: $language_man - documentation: $language_doc"


echocheck "enable sighandler"
if test "$_sighandler" = yes ; then
  def_sighandler='#define CONFIG_SIGHANDLER 1'
else
  def_sighandler='#undef CONFIG_SIGHANDLER'
fi
echores "$_sighandler"

echocheck "runtime cpudetection"
if test "$_runtime_cpudetection" = yes ; then
  _optimizing="Runtime CPU-Detection enabled"
  def_runtime_cpudetection='#define CONFIG_RUNTIME_CPUDETECT 1'
else
  def_runtime_cpudetection='#define CONFIG_RUNTIME_CPUDETECT 0'
fi
echores "$_runtime_cpudetection"


echocheck "restrict keyword"
for restrict_keyword in restrict __restrict __restrict__ ; do
  echo "void foo(char * $restrict_keyword p); int main(void) { return 0; }" > $TMPC
  if cc_check; then
    def_restrict_keyword=$restrict_keyword
    break;
  fi
done
if [ -n "$def_restrict_keyword" ]; then
  echores "$def_restrict_keyword"
else
  echores "none"
fi
# Avoid infinite recursion loop ("#define restrict restrict")
if [ "$def_restrict_keyword" != "restrict" ]; then
  def_restrict_keyword="#define restrict $def_restrict_keyword"
else
  def_restrict_keyword=""
fi


echocheck "__builtin_expect"
# GCC branch prediction hint
cat > $TMPC << EOF
static int foo(int a) {
    a = __builtin_expect(a, 10);
    return a == 10 ? 0 : 1;
}
int main(void) { return foo(10) && foo(0); }
EOF
_builtin_expect=no
cc_check && _builtin_expect=yes
if test "$_builtin_expect" = yes ; then
  def_builtin_expect='#define HAVE_BUILTIN_EXPECT 1'
else
  def_builtin_expect='#undef HAVE_BUILTIN_EXPECT'
fi
echores "$_builtin_expect"


echocheck "kstat"
_kstat=no
statement_check kstat.h 'kstat_open()' -lkstat && _kstat=yes
if test "$_kstat" = yes ; then
  def_kstat="#define HAVE_LIBKSTAT 1"
  extra_ldflags="$extra_ldflags -lkstat"
else
  def_kstat="#undef HAVE_LIBKSTAT"
fi
echores "$_kstat"


for func in atanf cbrt cbrtf cosf expf exp2 exp2f isnan isinf llrint llrintf log2 log2f log10f lrint lrintf rint round roundf sinf trunc truncf; do
echocheck $func
eval _$func=no
statement_check math.h "${func}(2.0)" && eval _$func=yes
if eval test "x\$_$func" = "xyes"; then
  eval def_$func="\"#define HAVE_$(echo $func | toupper) 1\""
  echores yes
else
  eval def_$func="\"#define HAVE_$(echo $func | toupper) 0\""
  echores no
fi
done


for func in atan2f ldexpf powf; do
echocheck $func
eval _$func=no
statement_check math.h "${func}(1.0,1.0)" && eval _$func=yes
if eval test "x\$_$func" = "xyes"; then
  eval def_$func="\"#define HAVE_$(echo $func | toupper) 1\""
  echores yes
else
  eval def_$func="\"#define HAVE_$(echo $func | toupper) 0\""
  echores no
fi
done


echocheck "mkstemp"
_mkstemp=no
statement_check stdlib.h 'mkstemp("")' && _mkstemp=yes
if test "$_mkstemp" = yes ; then
  def_mkstemp='#define HAVE_MKSTEMP 1'
else
  def_mkstemp='#define HAVE_MKSTEMP 0'
fi
echores "$_mkstemp"


echocheck "nanosleep"
_nanosleep=no
statement_check time.h 'nanosleep(0, 0)' && _nanosleep=yes
if test "$_nanosleep" = yes ; then
  def_nanosleep='#define HAVE_NANOSLEEP 1'
else
  def_nanosleep='#undef HAVE_NANOSLEEP'
fi
echores "$_nanosleep"


echocheck "socklib"
# for Solaris (socket stuff is in -lsocket, gethostbyname and friends in -lnsl):
cat > $TMPC << EOF
#include <netdb.h>
#include <sys/socket.h>
int main(void) { gethostbyname(0); socket(AF_INET, SOCK_STREAM, 0); return 0; }
EOF
_socklib=no
for ld_tmp in "" "-lsocket -ldnet" "-lsocket -lnsl" "-lnsl" "-lsocket" ; do
  cc_check $ld_tmp && ld_sock="$ld_tmp" && _socklib=yes && break
done
test $_socklib = yes && test $_winsock2_h = auto && _winsock2_h=no
if test $_winsock2_h = auto ; then
  _winsock2_h=no
  statement_check winsock2.h 'gethostbyname(0)' -lws2_32 && ld_sock="-lws2_32" && _winsock2_h=yes
fi
test "$ld_sock" && res_comment="using $ld_sock"
echores "$_socklib"


if test $_winsock2_h = yes ; then
  ld_sock="-lws2_32"
  def_winsock2_h='#define HAVE_WINSOCK2_H 1'
  cc_check_winsock2_h='-DHAVE_WINSOCK2_H=1'
else
  def_winsock2_h='#define HAVE_WINSOCK2_H 0'
  cc_check_winsock2_h='-DHAVE_WINSOCK2_H=0'
fi


echocheck "netdb.h, struct addrinfo"
if test "$_struct_addrinfo" = auto; then
  _struct_addrinfo=no
  cat > $TMPC << EOF
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#endif
int main(void) { struct addrinfo ai; return 0; }
EOF
  cc_check $cc_check_winsock2_h && _struct_addrinfo=yes
fi
echores "$_struct_addrinfo"

if test "$_struct_addrinfo" = yes; then
  def_struct_addrinfo="#define HAVE_STRUCT_ADDRINFO 1"
else
  def_struct_addrinfo="#define HAVE_STRUCT_ADDRINFO 0"
fi


echocheck "netdb.h, getaddrinfo()"
if test "$_getaddrinfo" = auto; then
  _getaddrinfo=no
  cat > $TMPC << EOF
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#endif
int main(void) { getaddrinfo(0, 0, 0, 0); return 0; }
EOF
  cc_check $cc_check_winsock2_h && _getaddrinfo=yes
fi
echores "$_getaddrinfo"

if test "$_getaddrinfo" = yes; then
  def_getaddrinfo="#define HAVE_GETADDRINFO 1"
else
  def_getaddrinfo="#define HAVE_GETADDRINFO 0"
fi


echocheck "sockaddr_storage"
if test "$_struct_sockaddr_storage" = auto; then
  _struct_sockaddr_storage=no
  cat > $TMPC << EOF
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#endif
int main(void) { struct sockaddr_storage sas; return 0; }
EOF
  cc_check $cc_check_winsock2_h && _struct_sockaddr_storage=yes
fi
echores "$_struct_sockaddr_storage"

if test "$_struct_sockaddr_storage" = yes; then
  def_struct_sockaddr_storage="#define HAVE_STRUCT_SOCKADDR_STORAGE 1"
else
  def_struct_sockaddr_storage="#define HAVE_STRUCT_SOCKADDR_STORAGE 0"
fi


echocheck "struct ipv6_mreq"
_struct_ipv6_mreq=no
def_struct_ipv6_mreq="#define HAVE_STRUCT_IPV6_MREQ 0"
for header in "netinet/in.h" "ws2tcpip.h" ; do
  statement_check $header 'struct ipv6_mreq mreq6' && _struct_ipv6_mreq=yes &&
    def_struct_ipv6_mreq="#define HAVE_STRUCT_IPV6_MREQ 1" && break
done
echores "$_struct_ipv6_mreq"


echocheck "struct sockaddr_in6"
_struct_sockaddr_in6=no
def_struct_sockaddr_in6="#define HAVE_STRUCT_SOCKADDR_IN6 0"
for header in "netinet/in.h" "ws2tcpip.h" ; do
  statement_check $header 'struct sockaddr_in6 addr' && _struct_sockaddr_in6=yes &&
    def_struct_sockaddr_in6="#define HAVE_STRUCT_SOCKADDR_IN6 1" && break
done
echores "$_struct_sockaddr_in6"


echocheck "struct sockaddr sa_len"
_struct_sockaddr_sa_len=no
def_struct_sockaddr_sa_len="#define HAVE_STRUCT_SOCKADDR_SA_LEN 0"
cat > $TMPC << EOF
#if HAVE_WINSOCK2_H
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#endif
int main(void) { const void *p = &((struct sockaddr *)0)->sa_len; return 0; }
EOF
cc_check $cc_check_winsock2_h && _struct_sockaddr_sa_len=yes &&
  def_struct_sockaddr_sa_len="#define HAVE_STRUCT_SOCKADDR_SA_LEN 1"
echores "$_struct_sockaddr_sa_len"


echocheck "arpa/inet.h"
arpa_inet_h=no
def_arpa_inet_h='#define HAVE_ARPA_INET_H 0'
header_check arpa/inet.h && arpa_inet_h=yes &&
  def_arpa_inet_h='#define HAVE_ARPA_INET_H 1'
echores "$arpa_inet_h"


echocheck "inet_pton()"
def_inet_pton='#define HAVE_INET_PTON 0'
inet_pton=no
for ld_tmp in "$ld_sock" "$ld_sock -lresolv" ; do
  statement_check arpa/inet.h 'inet_pton(0, 0, 0)' $ld_tmp && inet_pton=yes && break
done
if test $inet_pton = yes ; then
  test "$ld_tmp" && res_comment="using $ld_tmp"
  def_inet_pton='#define HAVE_INET_PTON 1'
fi
echores "$inet_pton"


echocheck "inet_aton()"
def_inet_aton='#define HAVE_INET_ATON 0'
inet_aton=no
for ld_tmp in "$ld_sock" "$ld_sock -lresolv" ; do
  statement_check arpa/inet.h 'inet_aton(0, 0)' $ld_tmp && inet_aton=yes && break
done
if test $inet_aton = yes ; then
  test "$ld_tmp" && res_comment="using $ld_tmp"
  def_inet_aton='#define HAVE_INET_ATON 1'
fi
echores "$inet_aton"


echocheck "socklen_t"
_socklen_t=no
for header in "sys/socket.h" "ws2tcpip.h" "sys/types.h" ; do
  statement_check $header 'socklen_t v = 0' && _socklen_t=yes && break
done
if test "$_socklen_t" = yes ; then
  def_socklen_t='#define HAVE_SOCKLEN_T 1'
else
  def_socklen_t='#define HAVE_SOCKLEN_T 0'
fi
echores "$_socklen_t"


echocheck "closesocket()"
_closesocket=no
statement_check winsock2.h 'closesocket(~0)' $ld_sock && _closesocket=yes
if test "$_closesocket" = yes ; then
  def_closesocket='#define HAVE_CLOSESOCKET 1'
else
  def_closesocket='#define HAVE_CLOSESOCKET 0'
fi
echores "$_closesocket"


echocheck "networking"
test $_winsock2_h = no && test $inet_pton = no &&
  test $inet_aton = no && networking=no
if test "$networking" = yes ; then
  def_network='#define CONFIG_NETWORK 1'
  def_networking='#define CONFIG_NETWORKING 1'
  def_rtpdec='#define CONFIG_RTPDEC 1'
  extra_ldflags="$extra_ldflags $ld_sock"
  inputmodules="networking $inputmodules"
else
  noinputmodules="networking $noinputmodules"
  def_network='#define CONFIG_NETWORK 0'
  def_networking='#undef CONFIG_NETWORKING'
  def_rtpdec='#define CONFIG_RTPDEC 0'
  libavprotocols=$(filter_out_component protocol 'GOPHER HTTP MMSH MMST RTMP RTP SCTP TCP UDP')
  libavdemuxers=$(filter_out_component demuxer 'RTP RTSP SAP SDP')
fi
echores "$networking"


echocheck "inet6"
if test "$_inet6" = auto ; then
  cat > $TMPC << EOF
#include <sys/types.h>
#if !defined(_WIN32)
#include <sys/socket.h>
#include <netinet/in.h>
#else
#include <ws2tcpip.h>
#endif
int main(void) { struct sockaddr_in6 six; socket(AF_INET6, SOCK_STREAM, AF_INET6); return 0; }
EOF
  _inet6=no
  if cc_check $ld_sock ; then
    _inet6=yes
  fi
fi
if test "$_inet6" = yes ; then
  def_inet6='#define HAVE_AF_INET6 1'
else
  def_inet6='#undef HAVE_AF_INET6'
fi
echores "$_inet6"


echocheck "gethostbyname2"
if test "$_gethostbyname2" = auto ; then
cat > $TMPC << EOF
#define _BSD_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main(void) { gethostbyname2("", AF_INET); return 0; }
EOF
  _gethostbyname2=no
  if cc_check ; then
    _gethostbyname2=yes
  fi
fi
if test "$_gethostbyname2" = yes ; then
  def_gethostbyname2='#define HAVE_GETHOSTBYNAME2 1'
else
  def_gethostbyname2='#undef HAVE_GETHOSTBYNAME2'
fi
echores "$_gethostbyname2"

echocheck "SCTP"
if test "$_sctp" = auto ; then
  _sctp=no
  if header_check netinet/sctp.h; then
    _sctp=yes
  fi
fi
if test "$_sctp" = no ; then
  libavprotocols=$(filter_out_component protocol 'SCTP')
fi
echores "$_sctp"

echocheck "sys/poll.h"
poll_h=no
def_poll_h='#define HAVE_POLL_H 0'
header_check sys/poll.h && poll_h=yes &&
  def_poll_h='#define HAVE_POLL_H 1'
echores "$poll_h"


echocheck "inttypes.h (required)"
_inttypes=no
header_check inttypes.h && _inttypes=yes
echores "$_inttypes"

if test "$_inttypes" = no ; then
  echocheck "sys/bitypes.h (inttypes.h predecessor)"
  header_check sys/bitypes.h && _inttypes=yes
  if test "$_inttypes" = yes ; then
    die "You don't have inttypes.h, but sys/bitypes.h is present. Please copy etc/inttypes.h into the include path, and re-run configure."
  else
    die "Cannot find header either inttypes.h or bitypes.h. There is no chance for compilation to succeed."
  fi
fi


echocheck "int_fastXY_t in inttypes.h"
_fast_inttypes=no
statement_check "inttypes.h" 'volatile int_fast16_t v = 0' && _fast_inttypes=yes
if test "$_fast_inttypes" = no ; then
  def_fast_inttypes='
    typedef signed char int_fast8_t;
    typedef signed int  int_fast16_t;
    typedef signed int  int_fast32_t;
    typedef signed long long int_fast64_t;
    typedef unsigned char uint_fast8_t;
    typedef unsigned int  uint_fast16_t;
    typedef unsigned int  uint_fast32_t;
    typedef unsigned long long uint_fast64_t;'
fi
echores "$_fast_inttypes"


echocheck "malloc.h"
_malloc=no
header_check malloc.h && _malloc=yes
if test "$_malloc" = yes ; then
  def_malloc_h='#define HAVE_MALLOC_H 1'
else
  def_malloc_h='#define HAVE_MALLOC_H 0'
fi
echores "$_malloc"


echocheck "aligned malloc"
aligned_malloc=no
def_aligned_malloc='#define HAVE_ALIGNED_MALLOC 0'
statement_check malloc.h '_aligned_malloc(0)' && aligned_malloc=yes &&
  def_aligned_malloc='#define HAVE_ALIGNED_MALLOC 1'
echores "$aligned_malloc"


echocheck "memalign()"
# XXX restrict to x86 ? extend to other CPUs/cacheline sizes ?
def_memalign_hack='#define CONFIG_MEMALIGN_HACK 0'
_memalign=no
statement_check malloc.h 'memalign(64, sizeof(char))' && _memalign=yes
if test "$_memalign" = yes ; then
  def_memalign='#define HAVE_MEMALIGN 1'
else
  def_memalign='#define HAVE_MEMALIGN 0'
  def_map_memalign='#define memalign(a, b) malloc(b)'
  darwin || def_memalign_hack='#define CONFIG_MEMALIGN_HACK 1'
fi
echores "$_memalign"


echocheck "posix_memalign()"
posix_memalign=no
def_posix_memalign='#define HAVE_POSIX_MEMALIGN 0'
statement_check stdlib.h 'posix_memalign(NULL, 0, 0)' &&
    posix_memalign=yes && def_posix_memalign='#define HAVE_POSIX_MEMALIGN 1'
echores "$posix_memalign"


echocheck "alloca.h"
_alloca=no
statement_check alloca.h 'alloca(0)' && _alloca=yes
if test "$_alloca" = yes ; then
  def_alloca_h='#define HAVE_ALLOCA_H 1'
else
  def_alloca_h='#undef HAVE_ALLOCA_H'
fi
echores "$_alloca"


echocheck "fastmemcpy"
if test "$_fastmemcpy" = yes ; then
  def_fastmemcpy='#define CONFIG_FASTMEMCPY 1'
else
  def_fastmemcpy='#undef CONFIG_FASTMEMCPY'
fi
echores "$_fastmemcpy"


echocheck "hard-coded tables"
if test "$hardcoded_tables" = yes ; then
  def_hardcoded_tables='#define CONFIG_HARDCODED_TABLES 1'
  mak_hardcoded_tables='CONFIG_HARDCODED_TABLES = yes'
else
  def_hardcoded_tables='#define CONFIG_HARDCODED_TABLES 0'
fi
echores "$hardcoded_tables"


echocheck "mman.h"
_mman=no
statement_check sys/mman.h 'mmap(0, 0, 0, 0, 0, 0)' && _mman=yes
if test "$_mman" = yes ; then
  def_mmap='#define HAVE_MMAP 1'
  def_mman_h='#define HAVE_SYS_MMAN_H 1'
else
  def_mmap='#define HAVE_MMAP 0'
  def_mman_h='#define HAVE_SYS_MMAN_H 0'
  os2 && mmap=no
fi
echores "$_mman"

_mman_has_map_failed=no
statement_check sys/mman.h 'void *p = MAP_FAILED' && _mman_has_map_failed=yes
if test "$_mman_has_map_failed" = yes ; then
  def_mman_has_map_failed=''
else
  def_mman_has_map_failed='#define MAP_FAILED ((void *) -1)'
fi


echocheck "mprotect"
mprotect=no
def_mprotect='#define HAVE_MPROTECT 0'
statement_check_broken stddef.h sys/mman.h 'mprotect(NULL, 0, 0)' && mprotect=yes
echores "$mprotect"


echocheck "dynamic loader"
_dl=no
for ld_tmp in "" -ldl; do
  statement_check dlfcn.h 'dlopen("", 0)' $ld_tmp && ld_dl="$ld_tmp" && _dl=yes && break
done
if test "$_dl" = yes ; then
  def_dl='#define HAVE_LIBDL 1'
else
  def_dl='#undef HAVE_LIBDL'
fi
echores "$_dl"


echocheck "dynamic a/v plugins support"
if test "$_dl" = no ; then
  _dynamic_plugins=no
fi
if test "$_dynamic_plugins" = yes ; then
  def_dynamic_plugins='#define CONFIG_DYNAMIC_PLUGINS 1'
else
  def_dynamic_plugins='#undef CONFIG_DYNAMIC_PLUGINS'
fi
echores "$_dynamic_plugins"


def_threads='#define HAVE_THREADS 0'
def_pthreads='#define HAVE_PTHREADS 0'
def_w32threads='#define HAVE_W32THREADS 0'
def_os2threads='#define HAVE_OS2THREADS 0'

echocheck "pthread"
if linux ; then
  THREAD_CFLAGS=-D_REENTRANT
elif freebsd || netbsd || openbsd || bsdos ; then
  THREAD_CFLAGS=-D_THREAD_SAFE
fi
if test "$_pthreads" = auto ; then
cat > $TMPC << EOF
#include <pthread.h>
static void *func(void *arg) { return arg; }
int main(void) { pthread_t tid; return pthread_create(&tid, 0, func, 0) == 0 ? 0 : 1; }
EOF
_pthreads=no
if ! hpux ; then
  for ld_tmp in "-lpthreadGC2" "" "-lpthread" "-pthread" ; do
    # for crosscompilation, we cannot execute the program, be happy if we can link statically
    cc_check $THREAD_CFLAGS $ld_tmp && (tmp_run || test "$ld_static") && ld_pthread="$ld_tmp" && _pthreads=yes && break
  done
fi
fi
if test "$_pthreads" = yes ; then
  test $ld_pthread && res_comment="using $ld_pthread"
  def_pthreads='#define HAVE_PTHREADS 1'
  def_threads='#define HAVE_THREADS 1'
  extra_cflags="$extra_cflags $THREAD_CFLAGS"
else
  res_comment="v4l, v4l2, ao_nas, win32 loader disabled"
  def_pthreads='#define HAVE_PTHREADS 0'
  _nas=no ; _tv_v4l1=no ; _tv_v4l2=no
  mingw32 || _win32dll=no
fi
echores "$_pthreads"

if cygwin ; then
  if test "$_pthreads" = yes ; then
    def_pthread_cache="#define PTHREAD_CACHE 1"
  else
    _stream_cache=no
    def_stream_cache="#undef CONFIG_STREAM_CACHE"
  fi
fi


if win32; then
echocheck "w32threads"
if test "$_pthreads" = yes ; then
  res_comment="using pthread instead"
  _w32threads=no
fi
if test "$_w32threads" = auto ; then
  _w32threads=no
  mingw32 && _w32threads=yes
fi
test "$_w32threads" = yes && def_threads='#define HAVE_THREADS 1' && def_w32threads='#define HAVE_W32THREADS 1'
echores "$_w32threads"
fi #if win32; then


echocheck "direct.h"
_direct_h=no
def_direct_h='#define HAVE_DIRECT_H 0'
header_check direct.h && _direct_h=yes && def_direct_h='#define HAVE_DIRECT_H 1'
echores "$_direct_h"


if os2 ; then
echocheck "os2threads"
if test "$_pthreads" = yes ; then
  res_comment="using pthread instead"
  _os2threads=no
fi
if test "$_os2threads" = auto ; then
  _os2threads=no
  os2 && _os2threads=yes
fi
test "$_os2threads" = yes && def_threads='#define HAVE_THREADS 1' && def_os2threads='#define HAVE_OS2THREADS 1'
echores "$_os2threads"
fi #if os2


echocheck "windows.h"
windows_h=no
def_windows_h='#define HAVE_WINDOWS_H 0'
header_check windows.h && windows_h=yes && def_windows_h='#define HAVE_WINDOWS_H 1'
echores "$windows_h"


echocheck "io.h"
_io_h=no
header_check io.h && _io_h=yes
if [ $_io_h = yes ]; then
  def_io_h='#define HAVE_IO_H 1'
else
  def_io_h='#define HAVE_IO_H 0'
fi
echores "$_io_h"


echocheck "rpath"
if test "$_rpath" = yes ; then
  for I in $(echo $extra_ldflags | sed 's/-L//g') ; do
    tmp="$tmp $(echo $I | sed 's/.*/ -L& -Wl,-R&/')"
  done
extra_ldflags=$tmp
fi
echores "$_rpath"

echocheck "iconv"
if test "$_iconv" = auto ; then
  cat > $TMPC << EOF
#include <stdio.h>
#include <unistd.h>
#include <iconv.h>
#define INBUFSIZE 1024
#define OUTBUFSIZE 4096

char inbuffer[INBUFSIZE];
char outbuffer[OUTBUFSIZE];

int main(void) {
  size_t numread;
  iconv_t icdsc;
  char *tocode="UTF-8";
  char *fromcode="cp1250";
  if ((icdsc = iconv_open(tocode, fromcode)) != (iconv_t)(-1)) {
    while ((numread = read(0, inbuffer, INBUFSIZE))) {
      char *iptr=inbuffer;
      char *optr=outbuffer;
      size_t inleft=numread;
      size_t outleft=OUTBUFSIZE;
      if (iconv(icdsc, &iptr, &inleft, &optr, &outleft)
          != (size_t)(-1)) {
        write(1, outbuffer, OUTBUFSIZE - outleft);
      }
    }
    if (iconv_close(icdsc) == -1)
      ;
  }
  return 0;
}
EOF
  _iconv=no
  # NOTE: -L/usr/lib is a hack to avoid issues due to a
  # broken libiconv that e.g. macports installs into /opt/local/lib
  # which might get addded to the search path later by e.g. SDL
  for ld_tmp in "" "-L/usr/lib -liconv" "-liconv" "-liconv $ld_dl" ; do
    cc_check $ld_tmp && extra_ldflags="$extra_ldflags $ld_tmp" &&
      ld_iconv="$ld_tmp" && _iconv=yes && break
  done
fi
if test "$_iconv" = yes ; then
  def_iconv='#define CONFIG_ICONV 1'
else
  def_iconv='#undef CONFIG_ICONV'
fi
echores "$_iconv"


echocheck "soundcard.h"
_soundcard_h=no
def_soundcard_h='#undef HAVE_SOUNDCARD_H'
def_sys_soundcard_h='#undef HAVE_SYS_SOUNDCARD_H'
for _soundcard_header in "sys/soundcard.h" "soundcard.h"; do
  header_check $_soundcard_header && _soundcard_h=yes &&
    res_comment="$_soundcard_header" && break
done

if test "$_soundcard_h" = yes ; then
  if test $_soundcard_header = "sys/soundcard.h"; then
    def_sys_soundcard_h='#define HAVE_SYS_SOUNDCARD_H 1'
  else
    def_soundcard_h='#define HAVE_SOUNDCARD_H 1'
  fi
fi
echores "$_soundcard_h"


echocheck "termcap"
if test "$_termcap" = auto ; then
  _termcap=no
  for ld_tmp in "-lncurses" "-ltinfo" "-ltermcap"; do
    statement_check term.h 'tgetent(0, 0)' $ld_tmp &&
      extra_ldflags="$extra_ldflags $ld_tmp" &&
      ld_termcap="$ld_tmp" && _termcap=yes && break
  done
fi
if test "$_termcap" = yes ; then
  def_termcap='#define HAVE_TERMCAP 1'
  test $ld_termcap && res_comment="using $ld_termcap"
else
  def_termcap='#undef HAVE_TERMCAP'
fi
echores "$_termcap"


echocheck "termios"
def_termios='#undef HAVE_TERMIOS'
def_termios_h='#undef HAVE_TERMIOS_H'
def_termios_sys_h='#undef HAVE_SYS_TERMIOS_H'
if test "$_termios" = auto ; then
  _termios=no
  for _termios_header in "termios.h" "sys/termios.h"; do
  header_check $_termios_header && _termios=yes &&
    res_comment="using $_termios_header" && break
done
fi

if test "$_termios" = yes ; then
  def_termios='#define HAVE_TERMIOS 1'
  if test "$_termios_header" = "termios.h" ; then
    def_termios_h='#define HAVE_TERMIOS_H 1'
  else
    def_termios_sys_h='#define HAVE_SYS_TERMIOS_H 1'
  fi
fi
echores "$_termios"


echocheck "shm"
if test "$_shm" = auto ; then
  _shm=no
  statement_check sys/shm.h 'shmget(0, 0, 0); shmat(0, 0, 0); shmctl(0, 0, 0)' && _shm=yes
fi
if test "$_shm" = yes ; then
  def_shm='#define HAVE_SHM 1'
else
  def_shm='#undef HAVE_SHM'
fi
echores "$_shm"


echocheck "strsep()"
strsep=yes
def_strsep='#define HAVE_STRSEP 1'
define_statement_check _BSD_SOURCE string.h 'char *s = "Hello, world!"; strsep(&s, ",")' ||
    { strsep=no ; def_strsep='#undef HAVE_STRSEP' ; }
echores "$strsep"


echocheck "vsscanf()"
vsscanf=yes
def_vsscanf='#define HAVE_VSSCANF 1'
statement_check_broken stdarg.h stdio.h 'va_list ap; vsscanf("foo", "bar", ap)' ||
    { vsscanf=no ; def_vsscanf='#undef HAVE_VSSCANF' ; }
echores "$vsscanf"


echocheck "POSIX select()"
cat > $TMPC << EOF
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
int main(void) {int nfds = 1; fd_set readfds; struct timeval timeout; select(nfds, &readfds, NULL, NULL, &timeout); return 0; }
EOF
_posix_select=no
def_posix_select='#undef HAVE_POSIX_SELECT'
#select() of kLIBC (OS/2) supports socket only
! os2 && cc_check && _posix_select=yes &&
    def_posix_select='#define HAVE_POSIX_SELECT 1'
echores "$_posix_select"


echocheck "audio select()"
if test "$_select" = no ; then
  def_select='#undef HAVE_AUDIO_SELECT'
elif test  "$_select" = yes ; then
  def_select='#define HAVE_AUDIO_SELECT 1'
fi
echores "$_select"


echocheck "gettimeofday()"
gettimeofday=yes
def_gettimeofday='#define HAVE_GETTIMEOFDAY 1'
statement_check_broken stddef.h sys/time.h 'struct timeval tv; gettimeofday(&tv, NULL)' ||
    { gettimeofday=no ; def_gettimeofday='#undef HAVE_GETTIMEOFDAY' ; }
echores "$gettimeofday"


echocheck "glob()"
# glob_win disables a Windows-specific glob() replacement.
glob=yes
glob_win=yes
def_glob='#define HAVE_GLOB 1'
statement_check glob.h 'glob("filename", 0, 0, 0)' ||
    { glob=no ; def_glob='#undef HAVE_GLOB' ;
      mingw32 && glob_win=no ; }
echores "$glob"


echocheck "setenv()"
setenv=yes
def_setenv='#define HAVE_SETENV 1'
statement_check stdlib.h 'setenv("", "", 0)' ||
    { setenv=no ; def_setenv='#define HAVE_SETENV 0' ; }
echores "$setenv"


echocheck "setmode()"
_setmode=no
def_setmode='#define HAVE_SETMODE 0'
statement_check io.h 'setmode(0, 0)' && _setmode=yes && def_setmode='#define HAVE_SETMODE 1'
echores "$_setmode"


if sunos; then
echocheck "sysi86()"
_sysi86=no
def_sysi86='#define HAVE_SYSI86 0'
statement_check sys/sysi86.h 'int sysi86(int, void*); sysi86(0)' &&
  _sysi86=yes && def_sysi86='#define HAVE_SYSI86 1'
echores "$_sysi86"
fi #if sunos


echocheck "sys/sysinfo.h"
_sys_sysinfo=no
statement_check sys/sysinfo.h 'struct sysinfo s_info; s_info.mem_unit=0; sysinfo(&s_info)' && _sys_sysinfo=yes
if test "$_sys_sysinfo" = yes ; then
  def_sys_sysinfo_h='#define HAVE_SYS_SYSINFO_H 1'
else
  def_sys_sysinfo_h='#undef HAVE_SYS_SYSINFO_H'
fi
echores "$_sys_sysinfo"


if darwin; then

echocheck "Mac OS X Finder Support"
def_macosx_finder='#undef CONFIG_MACOSX_FINDER'
if test "$_macosx_finder" = yes ; then
  def_macosx_finder='#define CONFIG_MACOSX_FINDER 1'
  extra_ldflags="$extra_ldflags -framework Carbon"
fi
echores "$_macosx_finder"

echocheck "Mac OS X Bundle file locations"
def_macosx_bundle='#undef CONFIG_MACOSX_BUNDLE'
test "$_macosx_bundle" = auto && _macosx_bundle=$_macosx_finder
if test "$_macosx_bundle" = yes ; then
  def_macosx_bundle='#define CONFIG_MACOSX_BUNDLE 1'
  extra_ldflags="$extra_ldflags -framework Carbon"
fi
echores "$_macosx_bundle"

echocheck "Apple Remote"
if test "$_apple_remote" = auto ; then
  _apple_remote=no
  cat > $TMPC <<EOF
#include <stdio.h>
#include <IOKit/IOCFPlugIn.h>
int main(void) {
  io_iterator_t hidObjectIterator = (io_iterator_t)NULL;
  CFMutableDictionaryRef hidMatchDictionary;
  IOReturn ioReturnValue;

  // Set up a matching dictionary to search the I/O Registry by class.
  // name for all HID class devices
  hidMatchDictionary = IOServiceMatching("AppleIRController");

  // Now search I/O Registry for matching devices.
  ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault,
                      hidMatchDictionary, &hidObjectIterator);

  // If search is unsuccessful, return nonzero.
  if (ioReturnValue != kIOReturnSuccess ||
                       !IOIteratorIsValid(hidObjectIterator)) {
    return 1;
  }
  return 0;
}
EOF
  cc_check -framework IOKit && _apple_remote=yes
fi
if test "$_apple_remote" = yes ; then
  def_apple_remote='#define CONFIG_APPLE_REMOTE 1'
  libs_mplayer="$libs_mplayer -framework IOKit -framework Cocoa"
else
  def_apple_remote='#undef CONFIG_APPLE_REMOTE'
fi
echores "$_apple_remote"

fi #if darwin

if linux; then

echocheck "Apple IR"
if test "$_apple_ir" = auto ; then
  _apple_ir=no
  statement_check linux/input.h 'struct input_event ev; struct input_id id' && _apple_ir=yes
fi
if test "$_apple_ir" = yes ; then
  def_apple_ir='#define CONFIG_APPLE_IR 1'
else
  def_apple_ir='#undef CONFIG_APPLE_IR'
fi
echores "$_apple_ir"
fi #if linux

echocheck "pkg-config"
_pkg_config=pkg-config
if $($_pkg_config --version > /dev/null 2>&1); then
  if test "$ld_static"; then
    _pkg_config="$_pkg_config --static"
  fi
  echores "yes"
else
  _pkg_config=false
  echores "no"
fi


echocheck "Samba support (libsmbclient)"
if test "$_smb" = yes; then
  extra_ldflags="$extra_ldflags -lsmbclient"
fi
if test "$_smb" = auto; then
  _smb=no
  for ld_tmp in "-lsmbclient" "-lsmbclient $ld_dl" "-lsmbclient $ld_dl -lnsl" "-lsmbclient $ld_dl -lssl -lnsl" ; do
    statement_check libsmbclient.h 'smbc_opendir("smb://")' $ld_tmp &&
      extra_ldflags="$extra_ldflags $ld_tmp" && _smb=yes && break
  done
fi

if test "$_smb" = yes; then
    def_smb="#define CONFIG_LIBSMBCLIENT 1"
    inputmodules="smb $inputmodules"
else
    def_smb="#undef CONFIG_LIBSMBCLIENT"
    noinputmodules="smb $noinputmodules"
fi
echores "$_smb"


#########
# VIDEO #
#########


echocheck "/dev/mga_vid"
if test "$_mga" = auto ; then
  _mga=no
  test -c /dev/mga_vid && _mga=yes
fi
if test "$_mga" = yes ; then
  def_mga='#define CONFIG_MGA 1'
  vomodules="mga $vomodules"
else
  def_mga='#undef CONFIG_MGA'
  novomodules="mga $novomodules"
fi
echores "$_mga"


echocheck "tdfxfb"
if test "$_tdfxfb" = yes ; then
  def_tdfxfb='#define CONFIG_TDFXFB 1'
  vomodules="tdfxfb $vomodules"
else
  def_tdfxfb='#undef CONFIG_TDFXFB'
  novomodules="tdfxfb $novomodules"
fi
echores "$_tdfxfb"

echocheck "s3fb"
if test "$_s3fb" = yes ; then
  def_s3fb='#define CONFIG_S3FB 1'
  vomodules="s3fb $vomodules"
else
  def_s3fb='#undef CONFIG_S3FB'
  novomodules="s3fb $novomodules"
fi
echores "$_s3fb"

echocheck "wii"
if test "$_wii" = yes ; then
  def_wii='#define CONFIG_WII 1'
  vomodules="wii $vomodules"
else
  def_wii='#undef CONFIG_WII'
  novomodules="wii $novomodules"
fi
echores "$_wii"

echocheck "tdfxvid"
if test "$_tdfxvid" = yes ; then
  def_tdfxvid='#define CONFIG_TDFX_VID 1'
  vomodules="tdfx_vid $vomodules"
else
  def_tdfxvid='#undef CONFIG_TDFX_VID'
  novomodules="tdfx_vid $novomodules"
fi
echores "$_tdfxvid"

echocheck "xvr100"
if test "$_xvr100" = auto ; then
cat > $TMPC << EOF
#include <unistd.h>
#include <sys/fbio.h>
#include <sys/visual_io.h>
int main(void) {
struct vis_identifier ident;
struct fbgattr attr;
ioctl(0, VIS_GETIDENTIFIER, &ident);
ioctl(0, FBIOGATTR, &attr);
return 0;
}
EOF
  _xvr100=no
  cc_check && _xvr100=yes
fi
if test "$_xvr100" = yes ; then
  def_xvr100='#define CONFIG_XVR100 1'
  vomodules="xvr100 $vomodules"
else
  def_tdfxvid='#undef CONFIG_XVR100'
  novomodules="xvr100 $novomodules"
fi
echores "$_xvr100"

echocheck "tga"
if test "$_tga" = yes ; then
  def_tga='#define CONFIG_TGA 1'
  vomodules="tga $vomodules"
else
  def_tga='#undef CONFIG_TGA'
  novomodules="tga $novomodules"
fi
echores "$_tga"


echocheck "md5sum support"
if test "$_md5sum" = yes; then
  def_md5sum="#define CONFIG_MD5SUM 1"
  vomodules="md5sum $vomodules"
else
  def_md5sum="#undef CONFIG_MD5SUM"
  novomodules="md5sum $novomodules"
fi
echores "$_md5sum"


echocheck "yuv4mpeg support"
if test "$_yuv4mpeg" = yes; then
  def_yuv4mpeg="#define CONFIG_YUV4MPEG 1"
  vomodules="yuv4mpeg $vomodules"
else
  def_yuv4mpeg="#undef CONFIG_YUV4MPEG"
  novomodules="yuv4mpeg $novomodules"
fi
echores "$_yuv4mpeg"


echocheck "bl"
if test "$_bl" = yes ; then
  def_bl='#define CONFIG_BL 1'
  vomodules="bl $vomodules"
else
  def_bl='#undef CONFIG_BL'
  novomodules="bl $novomodules"
fi
echores "$_bl"


echocheck "DirectFB"
if test "$_directfb" = auto ; then
  _directfb=no
  cat > $TMPC << EOF
#include <directfb.h>
#include <directfb_version.h>
#if (DIRECTFB_MAJOR_VERSION << 16 | DIRECTFB_MINOR_VERSION << 8 | DIRECTFB_MICRO_VERSION) < (0 << 16 | 9 << 8 | 22)
#error "DirectFB version too old."
#endif
int main(void) { DirectFBInit(0, 0); return 0; }
EOF
  for inc_tmp in "" -I/usr/local/include/directfb -I/usr/include/directfb -I/usr/local/include; do
    cc_check $inc_tmp -ldirectfb &&
      _directfb=yes && extra_cflags="$extra_cflags $inc_tmp" && break
  done
fi
if test "$_directfb" = yes ; then
  def_directfb='#define CONFIG_DIRECTFB 1'
  vomodules="directfb dfbmga $vomodules"
  libs_mplayer="$libs_mplayer -ldirectfb"
else
  def_directfb='#undef CONFIG_DIRECTFB'
  novomodules="directfb dfbmga $novomodules"
fi
echores "$_directfb"


echocheck "X11 headers presence"
  _x11_headers="no"
  res_comment="check if the dev(el) packages are installed"
  for I in $(echo $extra_cflags | sed s/-I//g) /usr/include ; do
    if test -f "$I/X11/Xlib.h" ; then
      _x11_headers="yes"
      res_comment=""
      break
    fi
  done
  if test $_cross_compile = no; then
    for I in /usr/X11/include /usr/X11R7/include /usr/local/include /usr/X11R6/include \
             /usr/include/X11R6 /usr/openwin/include ; do
      if test -f "$I/X11/Xlib.h" ; then
        extra_cflags="$extra_cflags -I$I"
        _x11_headers="yes"
        res_comment="using $I"
        break
      fi
    done
  fi
echores "$_x11_headers"


echocheck "X11"
if test "$_x11" = auto && test "$_x11_headers" = yes ; then
  for I in "" -L/usr/X11R7/lib -L/usr/local/lib -L/usr/X11R6/lib -L/usr/lib/X11R6 \
           -L/usr/X11/lib -L/usr/lib32 -L/usr/openwin/lib -L/usr/local/lib64 -L/usr/X11R6/lib64 \
           -L/usr/lib ; do
    if netbsd; then
      ld_tmp="$I -lXext -lX11 $ld_pthread -Wl,-R$(echo $I | sed s/^-L//)"
    else
      ld_tmp="$I -lXext -lX11 $ld_pthread"
    fi
    statement_check X11/Xutil.h 'XCreateWindow(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)' $ld_tmp &&
      libs_mplayer="$libs_mplayer $ld_tmp" && _x11=yes && break
  done
fi
if test "$_x11" = yes ; then
  def_x11='#define CONFIG_X11 1'
  vomodules="x11 xover $vomodules"
else
  _x11=no
  def_x11='#undef CONFIG_X11'
  novomodules="x11 $novomodules"
  res_comment="check if the dev(el) packages are installed"
fi
echores "$_x11"

echocheck "Xss screensaver extensions"
if test "$_xss" = auto ; then
  _xss=no
  statement_check "X11/extensions/scrnsaver.h" 'XScreenSaverSuspend(NULL, True)' -lXss && _xss=yes
fi
if test "$_xss" = yes ; then
  def_xss='#define CONFIG_XSS 1'
  libs_mplayer="$libs_mplayer -lXss"
else
  def_xss='#undef CONFIG_XSS'
fi
echores "$_xss"

echocheck "DPMS"
_xdpms3=no
_xdpms4=no
if test "$_x11" = yes ; then
  cat > $TMPC <<EOF
#include <X11/Xmd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/dpms.h>
int main(void) { DPMSQueryExtension(0, 0, 0); return 0; }
EOF
  cc_check -lXdpms && _xdpms3=yes
  statement_check_broken X11/Xlib.h X11/extensions/dpms.h 'DPMSQueryExtension(0, 0, 0)' -lXext && _xdpms4=yes
fi
if test "$_xdpms4" = yes ; then
  def_xdpms='#define CONFIG_XDPMS 1'
  res_comment="using Xdpms 4"
  echores "yes"
elif test "$_xdpms3" = yes ; then
  def_xdpms='#define CONFIG_XDPMS 1'
  libs_mplayer="$libs_mplayer -lXdpms"
  res_comment="using Xdpms 3"
  echores "yes"
else
  def_xdpms='#undef CONFIG_XDPMS'
  echores "no"
fi


echocheck "Xv"
if test "$_xv" = auto && test "$_x11" = yes ; then
  _xv=no
  statement_check_broken X11/Xlib.h X11/extensions/Xvlib.h 'XvGetPortAttribute(0, 0, 0, 0)' -lXv && _xv=yes
fi

if test "$_xv" = yes ; then
  def_xv='#define CONFIG_XV 1'
  libs_mplayer="$libs_mplayer -lXv"
  vomodules="xv $vomodules"
else
  def_xv='#undef CONFIG_XV'
  novomodules="xv $novomodules"
fi
echores "$_xv"


echocheck "XvMC"
if test "$_xvmc" != no  && test "$_xv" = yes ; then
  _xvmc=no
  cat > $TMPC <<EOF
#include <X11/Xlib.h>
#include <X11/extensions/Xvlib.h>
#include <X11/extensions/XvMClib.h>
int main(void) {
  XvMCQueryExtension(0, 0, 0);
  XvMCCreateContext(0, 0, 0, 0, 0, 0, 0);
  return 0; }
EOF
  for ld_tmp in $_xvmclib XvMCNVIDIA XvMCW I810XvMC ; do
    cc_check -lXvMC -l$ld_tmp && _xvmc=yes && _xvmclib="$ld_tmp" && break
  done
fi
if test "$_xvmc" = yes ; then
  def_xvmc='#define CONFIG_XVMC 1'
  libs_mplayer="$libs_mplayer -lXvMC"
  test -n "$_xvmclib" && libs_mplayer="$libs_mplayer -l$_xvmclib"
  vomodules="xvmc $vomodules"
  res_comment="using $_xvmclib"
else
  def_xvmc='#define CONFIG_XVMC 0'
  novomodules="xvmc $novomodules"
  libavdecoders=$(filter_out_component decoder 'MPEG_XVMC')
fi
echores "$_xvmc"


echocheck "Video Decode Acceleration (VDA)"
if test "$_vda" = auto ; then
  _vda=no
  header_check VideoDecodeAcceleration/VDADecoder.h && _vda=yes
fi
if test "$_vda" = yes ; then
  def_vda='#define CONFIG_VDA 1'
  extra_ldflags="$extra_ldflags -framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore"
  libavhwaccels="H264_VDA_HWACCEL"
else
  def_vda='#define CONFIG_VDA 0'
  libavdecoders=$(filter_out_component decoder '[A-Z0-9]*_VDA')
fi
echores "$_vda"


echocheck "VDPAU"
if test "$_vdpau" = auto && test "$_x11" = yes ; then
  _vdpau=no
  if test "$_dl" = yes ; then
    return_statement_check vdpau/vdpau_x11.h 'vdp_device_create_x11(0, 0, 0, 0)' VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 -lvdpau && _vdpau=yes
  fi
fi
if test "$_vdpau" = yes ; then
  def_vdpau='#define CONFIG_VDPAU 1'
  libs_mplayer="$libs_mplayer -lvdpau"
  vomodules="vdpau $vomodules"
  libavhwaccels="MPEG1_VDPAU_HWACCEL MPEG2_VDPAU_HWACCEL"
else
  def_vdpau='#define CONFIG_VDPAU 0'
  novomodules="vdpau $novomodules"
  libavdecoders=$(filter_out_component decoder '[A-Z0-9]*_VDPAU')
fi
echores "$_vdpau"


echocheck "Xinerama"
if test "$_xinerama" = auto && test "$_x11" = yes ; then
  _xinerama=no
  statement_check X11/extensions/Xinerama.h 'XineramaIsActive(0)' -lXinerama && _xinerama=yes
fi

if test "$_xinerama" = yes ; then
  def_xinerama='#define CONFIG_XINERAMA 1'
  libs_mplayer="$libs_mplayer -lXinerama"
else
  def_xinerama='#undef CONFIG_XINERAMA'
fi
echores "$_xinerama"


# Note: the -lXxf86vm library is the VideoMode extension and though it's not
# needed for DGA, AFAIK every distribution packages together with DGA stuffs
# named 'X extensions' or something similar.
# This check may be useful for future MPlayer versions (to change resolution)
# If you run into problems, remove '-lXxf86vm'.
echocheck "Xxf86vm"
if test "$_vm" = auto && test "$_x11" = yes ; then
  _vm=no
  statement_check_broken X11/Xlib.h X11/extensions/xf86vmode.h 'XF86VidModeQueryExtension(0, 0, 0)' -lXxf86vm && _vm=yes
fi
if test "$_vm" = yes ; then
  def_vm='#define CONFIG_XF86VM 1'
  libs_mplayer="$libs_mplayer -lXxf86vm"
else
  def_vm='#undef CONFIG_XF86VM'
fi
echores "$_vm"

# Check for the presence of special keycodes, like audio control buttons
# that XFree86 might have.  Used to be bundled with the xf86vm check, but
# has nothing to do with xf86vm and XFree 3.x has xf86vm but does NOT
# have these new keycodes.
echocheck "XF86keysym"
if test "$_xf86keysym" = auto && test "$_x11" = yes ; then
  _xf86keysym=no
  return_check X11/XF86keysym.h XF86XK_AudioPause && _xf86keysym=yes
fi
if test "$_xf86keysym" = yes ; then
  def_xf86keysym='#define CONFIG_XF86XK 1'
else
  def_xf86keysym='#undef CONFIG_XF86XK'
fi
echores "$_xf86keysym"

echocheck "DGA"
if test "$_dga2" = auto && test "$_x11" = yes ; then
  _dga2=no
  statement_check_broken X11/Xlib.h X11/extensions/xf86dga.h 'XDGASetViewport(0, 0, 0, 0, 0)' -lXxf86dga && _dga2=yes
fi
if test "$_dga1" = auto && test "$_dga2" = no && test "$_vm" = yes ; then
  _dga1=no
  statement_check_broken X11/Xlib.h X11/extensions/xf86dga.h 'XF86DGASetViewPort(0, 0, 0, 0)' -lXxf86dga -lXxf86vm && _dga1=yes
fi

_dga=no
def_dga='#undef CONFIG_DGA'
def_dga1='#undef CONFIG_DGA1'
def_dga2='#undef CONFIG_DGA2'
if test "$_dga1" = yes ; then
  _dga=yes
  def_dga1='#define CONFIG_DGA1 1'
  res_comment="using DGA 1.0"
elif test "$_dga2" = yes ; then
  _dga=yes
  def_dga2='#define CONFIG_DGA2 1'
  res_comment="using DGA 2.0"
fi
if test "$_dga" = yes ; then
  def_dga='#define CONFIG_DGA 1'
  libs_mplayer="$libs_mplayer -lXxf86dga"
  vomodules="dga $vomodules"
else
  novomodules="dga $novomodules"
fi
echores "$_dga"


echocheck "xmga"
if test "$_xmga" = auto ; then
  _xmga=no
  test "$_x11" = yes && test "$_mga" = yes && _xmga=yes
fi
if test "$_xmga" = yes ; then
  def_xmga='#define CONFIG_XMGA 1'
  vomodules="xmga $vomodules"
else
  def_xmga='#undef CONFIG_XMGA'
  novomodules="xmga $novomodules"
fi
echores "$_xmga"


echocheck "3dfx"
if test "$_3dfx" = yes && test "$_dga" = yes ; then
  def_3dfx='#define CONFIG_3DFX 1'
  vomodules="3dfx $vomodules"
else
  def_3dfx='#undef CONFIG_3DFX'
  novomodules="3dfx $novomodules"
fi
echores "$_3dfx"


echocheck "VIDIX"
def_vidix='#undef CONFIG_VIDIX'
def_vidix_drv_cyberblade='#undef CONFIG_VIDIX_DRV_CYBERBLADE'
_vidix_drv_cyberblade=no
def_vidix_drv_ivtv='#undef CONFIG_VIDIX_DRV_IVTV'
_vidix_drv_ivtv=no
def_vidix_drv_mach64='#undef CONFIG_VIDIX_DRV_MACH64'
_vidix_drv_mach64=no
def_vidix_drv_mga='#undef CONFIG_VIDIX_DRV_MGA'
_vidix_drv_mga=no
def_vidix_drv_mga_crtc2='#undef CONFIG_VIDIX_DRV_MGA_CRTC2'
_vidix_drv_mga_crtc2=no
def_vidix_drv_nvidia='#undef CONFIG_VIDIX_DRV_NVIDIA'
_vidix_drv_nvidia=no
def_vidix_drv_pm2='#undef CONFIG_VIDIX_DRV_PM2'
_vidix_drv_pm2=no
def_vidix_drv_pm3='#undef CONFIG_VIDIX_DRV_PM3'
_vidix_drv_pm3=no
def_vidix_drv_radeon='#undef CONFIG_VIDIX_DRV_RADEON'
_vidix_drv_radeon=no
def_vidix_drv_rage128='#undef CONFIG_VIDIX_DRV_RAGE128'
_vidix_drv_rage128=no
def_vidix_drv_s3='#undef CONFIG_VIDIX_DRV_S3'
_vidix_drv_s3=no
def_vidix_drv_sh_veu='#undef CONFIG_VIDIX_DRV_SH_VEU'
_vidix_drv_sh_veu=no
def_vidix_drv_sis='#undef CONFIG_VIDIX_DRV_SIS'
_vidix_drv_sis=no
def_vidix_drv_unichrome='#undef CONFIG_VIDIX_DRV_UNICHROME'
_vidix_drv_unichrome=no
if test "$_vidix" = auto ; then
  _vidix=no
  x86 && (linux || freebsd || netbsd || openbsd || dragonfly || sunos || win32) && _vidix=yes
  win32 && ! header_check ddk/ntddk.h && _vidix=no
  x86_64 && ! linux && _vidix=no
  (ppc || alpha) && linux && _vidix=yes
fi
echores "$_vidix"

if test "$_vidix" = yes ; then
  def_vidix='#define CONFIG_VIDIX 1'
  vomodules="cvidix $vomodules"
  # FIXME: ivtv driver temporarily disabled until we have a proper test
  #test "$_vidix_drivers" || _vidix_drivers="cyberblade ivtv mach64 mga mga_crtc2 nvidia pm2 pm3 radeon rage128 s3 sh_veu sis unichrome"
  test "$_vidix_drivers" || _vidix_drivers="cyberblade mach64 mga mga_crtc2 nvidia pm2 pm3 radeon rage128 s3 sh_veu sis unichrome"

  # some VIDIX drivers are architecture and os-specific, discard them elsewhere
  x86 || _vidix_drivers=$(echo $_vidix_drivers | sed -e s/cyberblade// -e s/sis// -e s/unichrome// -e s/s3//)
  (test $host_arch = "sh" && linux) || _vidix_drivers=$(echo $_vidix_drivers | sed s/sh_veu//)

  for driver in $_vidix_drivers ; do
    uc_driver=$(echo $driver | toupper)
    eval _vidix_drv_${driver}=yes
    eval def_vidix_drv_${driver}=\"\#define CONFIG_VIDIX_DRV_${uc_driver} 1\"
  done

  echocheck "VIDIX PCI device name database"
  echores "$_vidix_pcidb"
  if test "$_vidix_pcidb" = yes ; then
    _vidix_pcidb_val=1
  else
    _vidix_pcidb_val=0
  fi

  echocheck "VIDIX dhahelper support"
  test "$_dhahelper" = yes && cflags_dhahelper=-DCONFIG_DHAHELPER
  echores "$_dhahelper"

  echocheck "VIDIX svgalib_helper support"
  test "$_svgalib_helper" = yes && cflags_svgalib_helper=-DCONFIG_SVGAHELPER
  echores "$_svgalib_helper"

else
  novomodules="cvidix $novomodules"
fi

if test "$_vidix" = yes && win32; then
  winvidix=yes
  vomodules="winvidix $vomodules"
  libs_mplayer="$libs_mplayer -lgdi32"
else
  novomodules="winvidix $novomodules"
fi
if test "$_vidix" = yes && test "$_x11" = yes; then
  xvidix=yes
  vomodules="xvidix $vomodules"
else
  novomodules="xvidix $novomodules"
fi


echocheck "GGI"
if test "$_ggi" = auto ; then
  _ggi=no
  statement_check ggi/ggi.h 'ggiInit()' -lggi && _ggi=yes
fi
if test "$_ggi" = yes ; then
  def_ggi='#define CONFIG_GGI 1'
  libs_mplayer="$libs_mplayer -lggi"
  vomodules="ggi $vomodules"
else
  def_ggi='#undef CONFIG_GGI'
  novomodules="ggi $novomodules"
fi
echores "$_ggi"

echocheck "GGI extension: libggiwmh"
if test "$_ggiwmh" = auto ; then
  _ggiwmh=no
  statement_check ggi/wmh.h 'ggiWmhInit()' -lggi -lggiwmh && _ggiwmh=yes
fi
# needed to get right output on obscure combination
# like --disable-ggi --enable-ggiwmh
if test "$_ggi" = yes && test "$_ggiwmh" = yes ; then
  def_ggiwmh='#define CONFIG_GGIWMH 1'
  libs_mplayer="$libs_mplayer -lggiwmh"
else
  _ggiwmh=no
  def_ggiwmh='#undef CONFIG_GGIWMH'
fi
echores "$_ggiwmh"


echocheck "AA"
if test "$_aa" = auto ; then
  cat > $TMPC << EOF
#include <aalib.h>
int main(void) {
aa_context *c;
aa_renderparams *p;
aa_init(0, 0, 0);
c = aa_autoinit(&aa_defparams);
p = aa_getrenderparams();
aa_autoinitkbd(c, 0);
return 0; }
EOF
  _aa=no
  for ld_tmp in "-laa" ; do
    cc_check $ld_tmp && libs_mplayer="$libs_mplayer $ld_tmp" && _aa=yes && break
  done
fi
if test "$_aa" = yes ; then
  def_aa='#define CONFIG_AA 1'
  if cygwin ; then
    libs_mplayer="$libs_mplayer $(aalib-config --libs | cut -d " " -f 2,5,6)"
  fi
  vomodules="aa $vomodules"
else
  def_aa='#undef CONFIG_AA'
  novomodules="aa $novomodules"
fi
echores "$_aa"


echocheck "CACA"
if test "$_caca" = auto ; then
  _caca=no
  if ( caca-config --version ) >> "$TMPLOG" 2>&1 ; then
  cat > $TMPC << EOF
#include <caca.h>
#ifdef CACA_API_VERSION_1
  #include <caca0.h>
#endif
int main(void) { caca_init(); return 0; }
EOF
  cc_check $(caca-config --libs) && _caca=yes
  fi
fi
if test "$_caca" = yes ; then
  def_caca='#define CONFIG_CACA 1'
  extra_cflags="$extra_cflags $(caca-config --cflags)"
  libs_mplayer="$libs_mplayer $(caca-config --libs)"
  vomodules="caca $vomodules"
else
  def_caca='#undef CONFIG_CACA'
  novomodules="caca $novomodules"
fi
echores "$_caca"


echocheck "SVGAlib"
if test "$_svga" = auto ; then
  _svga=no
  header_check vga.h -lvga && _svga=yes
fi
if test "$_svga" = yes ; then
  def_svga='#define CONFIG_SVGALIB 1'
  libs_mplayer="$libs_mplayer -lvga"
  vomodules="svga $vomodules"
else
  def_svga='#undef CONFIG_SVGALIB'
  novomodules="svga $novomodules"
fi
echores "$_svga"


echocheck "FBDev"
if test "$_fbdev" = auto ; then
  _fbdev=no
  linux && _fbdev=yes
fi
if test "$_fbdev" = yes ; then
  def_fbdev='#define CONFIG_FBDEV 1'
  vomodules="fbdev $vomodules"
else
  def_fbdev='#undef CONFIG_FBDEV'
  novomodules="fbdev $novomodules"
fi
echores "$_fbdev"



echocheck "DVB"
if test "$_dvb" = auto ; then
  _dvb=no
cat >$TMPC << EOF
#include <poll.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <linux/dvb/dmx.h>
#include <linux/dvb/frontend.h>
#include <linux/dvb/video.h>
#include <linux/dvb/audio.h>
int main(void) {return 0;}
EOF
  for inc_tmp in "" "-I/usr/src/DVB/include" ; do
    cc_check $inc_tmp && _dvb=yes &&
      extra_cflags="$extra_cflags $inc_tmp" && break
  done
fi
echores "$_dvb"
if test "$_dvb" = yes ; then
  _dvbin=yes
  inputmodules="dvb $inputmodules"
  def_dvb='#define CONFIG_DVB 1'
  def_dvbin='#define CONFIG_DVBIN 1'
  aomodules="mpegpes(dvb) $aomodules"
  vomodules="mpegpes(dvb) $vomodules"
else
  _dvbin=no
  noinputmodules="dvb $noinputmodules"
  def_dvb='#undef CONFIG_DVB'
  def_dvbin='#undef CONFIG_DVBIN '
  aomodules="mpegpes(file) $aomodules"
  vomodules="mpegpes(file) $vomodules"
fi


if darwin; then

echocheck "QuickTime"
if test "$quicktime" = auto ; then
  quicktime=no
  statement_check QuickTime/QuickTime.h 'ImageDescription *desc; EnterMovies(); ExitMovies()' -framework QuickTime && quicktime=yes
fi
if test "$quicktime" = yes ; then
  extra_ldflags="$extra_ldflags -framework QuickTime"
  def_quicktime='#define CONFIG_QUICKTIME 1'
else
  def_quicktime='#undef CONFIG_QUICKTIME'
  _quartz=no
fi
echores $quicktime

echocheck "Quartz"
if test "$_quartz" = auto ; then
  _quartz=no
  statement_check Carbon/Carbon.h 'CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false)' -framework Carbon && _quartz=yes
fi
if test "$_quartz" = yes ; then
  libs_mplayer="$libs_mplayer -framework Carbon"
  def_quartz='#define CONFIG_QUARTZ 1'
  vomodules="quartz $vomodules"
else
  def_quartz='#undef CONFIG_QUARTZ'
  novomodules="quartz $novomodules"
fi
echores $_quartz

echocheck "CoreVideo"
if test "$_corevideo" = auto ; then
  cat > $TMPC <<EOF
#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>
#include <OpenGL/OpenGL.h>
#include <QuartzCore/CoreVideo.h>
int main(void) { return 0; }
EOF
  _corevideo=no
  cc_check -framework Carbon -framework Cocoa -framework QuartzCore -framework OpenGL && _corevideo=yes
fi
if test "$_corevideo" = yes ; then
  vomodules="corevideo $vomodules"
  libs_mplayer="$libs_mplayer -framework Carbon -framework Cocoa -framework QuartzCore -framework OpenGL"
  def_corevideo='#define CONFIG_COREVIDEO 1'
else
  novomodules="corevideo $novomodules"
  def_corevideo='#undef CONFIG_COREVIDEO'
fi
echores "$_corevideo"

fi #if darwin


echocheck "PNG support"
if test "$_png" = auto ; then
  _png=no
  if irix ; then
    # Don't check for -lpng on IRIX since it has its own libpng
    # incompatible with the GNU libpng
    res_comment="disabled on irix (not GNU libpng)"
  else
cat > $TMPC << EOF
#include <stdio.h>
#include <string.h>
#include <png.h>
int main(void) {
  printf("png.h : %s\n", PNG_LIBPNG_VER_STRING);
  printf("libpng: %s\n", png_libpng_ver);
  return strcmp(PNG_LIBPNG_VER_STRING, png_libpng_ver);
}
EOF
    cc_check -lpng -lz && _png=yes
  fi
fi
echores "$_png"
if test "$_png" = yes ; then
  def_png='#define CONFIG_PNG 1'
  extra_ldflags="$extra_ldflags -lpng -lz"
else
  def_png='#undef CONFIG_PNG'
fi

echocheck "MNG support"
if test "$_mng" = auto ; then
  _mng=no
  for mnglibs in '-lmng -lz' '-lmng -ljpeg -lz' ; do
    return_statement_check libmng.h 'const char * p_ver = mng_version_text()' '!p_ver || p_ver[0] == 0' $mnglibs && _mng=yes
  done
fi
echores "$_mng"
if test "$_mng" = yes ; then
  def_mng='#define CONFIG_MNG 1'
  extra_ldflags="$extra_ldflags $mnglibs"
  vomodules="mng $vomodules"
else
  def_mng='#undef CONFIG_MNG'
  novomodules="mng $novomodules"
fi

echocheck "JPEG support"
if test "$_jpeg" = auto ; then
  _jpeg=no
  header_check_broken stdio.h jpeglib.h -ljpeg && _jpeg=yes
fi
echores "$_jpeg"

if test "$_jpeg" = yes ; then
  def_jpeg='#define CONFIG_JPEG 1'
  vomodules="jpeg $vomodules"
  extra_ldflags="$extra_ldflags -ljpeg"
else
  def_jpeg='#undef CONFIG_JPEG'
  novomodules="jpeg $novomodules"
fi


echocheck "OpenJPEG (JPEG 2000) support"
if test "$libopenjpeg" = auto ; then
  libopenjpeg=no
  define_statement_check OPJ_STATIC openjpeg.h 'opj_dparameters_t dec_params; opj_set_default_decoder_parameters(&dec_params);opj_decode_with_info(0,0,0)' -lopenjpeg && libopenjpeg=yes
fi
echores "$libopenjpeg"
if test "$libopenjpeg" = yes ; then
  def_libopenjpeg='#define CONFIG_LIBOPENJPEG 1'
  extra_ldflags="$extra_ldflags -lopenjpeg"
  libavdecoders="$libavdecoders LIBOPENJPEG_DECODER"
  libavencoders="$libavencoders LIBOPENJPEG_ENCODER"
  codecmodules="OpenJPEG $codecmodules"
else
  def_libopenjpeg='#define CONFIG_LIBOPENJPEG 0'
  nocodecmodules="OpenJPEG $nocodecmodules"
fi


echocheck "PNM support"
if test "$_pnm" = yes; then
  def_pnm="#define CONFIG_PNM 1"
  vomodules="pnm $vomodules"
else
  def_pnm="#undef CONFIG_PNM"
  novomodules="pnm $novomodules"
fi
echores "$_pnm"



echocheck "GIF support"
# This is to appease people who want to force GIF support.
# If it is forced to yes, then we still do checks to determine
# which GIF library to use.
if test "$_gif" = yes ; then
  _force_gif=yes
  _gif=auto
fi

if test "$_gif" = auto ; then
  _gif=no
  for ld_gif in "-lungif" "-lgif" ; do
    statement_check gif_lib.h 'QuantizeBuffer(0, 0, 0, 0, 0, 0, 0, 0)' $ld_gif && _gif=yes && break
    statement_check_broken stdlib.h gif_lib.h 'GifQuantizeBuffer(0, 0, 0, 0, 0, 0, 0, 0)' $ld_gif && _gif=yes && break
  done
fi

# If no library was found, and the user wants support forced,
# then we force it on with libgif, as this is the safest
# assumption IMHO.  (libungif & libregif both create symbolic
# links to libgif.  We also assume that no x11 support is needed,
# because if you are forcing this, then you _should_ know what
# you are doing.  [ Besides, package maintainers should never
# have compiled x11 deps into libungif in the first place. ] )
# </rant>
#   --Joey
if test "$_force_gif" = yes && test "$_gif" = no ; then
  _gif=yes
  ld_gif="-lgif"
fi

if test "$_gif" = yes ; then
  def_gif='#define CONFIG_GIF 1'
  codecmodules="gif $codecmodules"
  vomodules="gif89a $vomodules"
  res_comment="old version, some encoding functions disabled"
  def_gif_4='#undef CONFIG_GIF_4'
  extra_ldflags="$extra_ldflags $ld_gif"

  cat > $TMPC << EOF
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <gif_lib.h>
static void catch(int sig) { exit(1); }
int main(void) {
  signal(SIGSEGV, catch);  // catch segfault
  printf("EGifPutExtensionFirst is at address %p\n", EGifPutExtensionFirst);
  EGifSetGifVersion("89a");   // this will segfault a buggy gif lib.
  return 0;
}
EOF
  if cc_check "$ld_gif" ; then
    def_gif_4='#define CONFIG_GIF_4 1'
    res_comment=""
  fi
else
  def_gif='#undef CONFIG_GIF'
  def_gif_4='#undef CONFIG_GIF_4'
  novomodules="gif89a $novomodules"
  nocodecmodules="gif $nocodecmodules"
fi
echores "$_gif"


case "$_gif" in yes*)
  echocheck "broken giflib workaround"
  def_gif_tvt_hack='#define CONFIG_GIF_TVT_HACK 1'
  if statement_check_broken stdio.h gif_lib.h 'GifFileType gif = {.UserData = NULL}; printf("UserData is at address %p\n", gif.UserData)' "$ld_gif" ; then
    def_gif_tvt_hack='#undef CONFIG_GIF_TVT_HACK'
    echores "disabled"
  else
    echores "enabled"
  fi
  ;;
esac


echocheck "VESA support"
if test "$_vesa" = auto ; then
  _vesa=no
  statement_check vbe.h 'vbeInit()' -lvbe -llrmi && _vesa=yes
fi
if test "$_vesa" = yes ; then
  def_vesa='#define CONFIG_VESA 1'
  libs_mplayer="$libs_mplayer -lvbe -llrmi"
  vomodules="vesa $vomodules"
else
  def_vesa='#undef CONFIG_VESA'
  novomodules="vesa $novomodules"
fi
echores "$_vesa"

#################
# VIDEO + AUDIO #
#################


echocheck "SDL"
inc_tmp=""
ld_tmp=""
def_sdl_sdl_h="#undef CONFIG_SDL_SDL_H"
if test -z "$_sdlconfig" ; then
  if ( sdl-config --version ) >>"$TMPLOG" 2>&1 ; then
    _sdlconfig="sdl-config"
  else
    _sdlconfig=false
  fi
fi
if test "$_sdl" = auto || test "$_sdl" = yes ; then
  cat > $TMPC << EOF
#ifdef CONFIG_SDL_SDL_H
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#ifndef __APPLE__
// we allow SDL hacking our main() only on OSX
#undef main
#endif
int main(int argc, char *argv[]) {
  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE);
  return 0;
}
EOF
  _sdl=no
  for ld_tmp in "-lSDL" "-lSDL -lpthread" "-lSDL -lwinmm -lgdi32" "-lSDL -lwinmm -lgdi32 -ldxguid" ; do
    if cc_check -DCONFIG_SDL_SDL_H $inc_tmp $ld_tmp ; then
      _sdl=yes
      def_sdl_sdl_h="#define CONFIG_SDL_SDL_H 1"
      break
    fi
  done
  if test "$_sdl" = no && "$_sdlconfig" --version >>"$TMPLOG" 2>&1 ; then
    res_comment="using $_sdlconfig"
    if cygwin ; then
      inc_tmp="$($_sdlconfig --cflags | cut -d " " -f 1,5,6 | sed s/no-cygwin/cygwin/)"
      ld_tmp="$($_sdlconfig --libs | cut -d " " -f 1,4,6 | sed s/no-cygwin/cygwin/)"
    elif mingw32 ; then
      inc_tmp=$($_sdlconfig --cflags | sed s/-Dmain=SDL_main//)
      ld_tmp=$($_sdlconfig --libs | sed -e s/-mwindows// -e s/-lmingw32//)
    else
      inc_tmp="$($_sdlconfig --cflags)"
      ld_tmp="$($_sdlconfig --libs)"
    fi
    if cc_check $inc_tmp $ld_tmp >>"$TMPLOG" 2>&1 ; then
          _sdl=yes
    elif cc_check $inc_tmp $ld_tmp -lstdc++ >>"$TMPLOG" 2>&1 ; then
          # HACK for Haiku SDL
          ld_tmp="$ld_tmp -lstdc++"
          _sdl=yes
     fi
  fi
fi
if test "$_sdl" = yes ; then
  def_sdl='#define CONFIG_SDL 1'
  extra_cflags="$extra_cflags $inc_tmp"
  libs_mplayer="$libs_mplayer $ld_tmp"
  vomodules="sdl $vomodules"
  aomodules="sdl $aomodules"
else
  def_sdl='#undef CONFIG_SDL'
  novomodules="sdl $novomodules"
  noaomodules="sdl $noaomodules"
fi
echores "$_sdl"


echocheck "SDL image"
sdl_image=no
if test "$_sdl" = yes ; then
  header_check SDL/SDL_image.h -lSDL_image && sdl_image=yes
fi
echores "$sdl_image"


# make sure this stays below CoreVideo to avoid issues due to namespace
# conflicts between -lGL and -framework OpenGL
echocheck "OpenGL"
#Note: this test is run even with --enable-gl since we autodetect linker flags
if test "$_gl" != no ; then
  cat > $TMPC << EOF
#ifdef GL_WIN32
#include <windows.h>
#include <GL/gl.h>
#elif defined(GL_SDL)
#include <GL/gl.h>
#ifdef CONFIG_SDL_SDL_H
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#ifndef __APPLE__
// we allow SDL hacking our main() only on OSX
#undef main
#endif
#elif defined(GL_EGL_X11)
#include <GL/gl.h>
#include <X11/Xlib.h>
#include <EGL/egl.h>
#elif defined(GL_EGL_ANDROID)
#include <GLES/gl.h>
#include <EGL/egl.h>
#else
#include <GL/gl.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
#endif
int main(int argc, char *argv[]) {
#ifdef GL_WIN32
  HDC dc;
  wglCreateContext(dc);
#elif defined(GL_SDL)
  SDL_GL_SwapBuffers();
#elif defined(GL_EGL_X11) || defined(GL_EGL_ANDROID)
  EGLDisplay eglDisplay = EGL_NO_DISPLAY;
  eglInitialize(eglDisplay, NULL, NULL);
#else
  glXCreateContext(NULL, NULL, NULL, True);
#endif
#if !defined(GL_EGL_X11) && !defined(GL_EGL_ANDROID)
  glFinish();
#endif
  return 0;
}
EOF
  _gl=no
  for ld_tmp in "" -lGL "-lGL -lXdamage" "-lGL $ld_pthread" ; do
    if test "$_x11" = yes && cc_check $ld_tmp ; then
      _gl=yes
      _gl_x11=yes
      libs_mplayer="$libs_mplayer $ld_tmp $ld_dl"
      break
    fi
  done
  if test "$_x11" = yes && cc_check -DGL_EGL_X11 -lEGL ; then
    _gl=yes
    _gl_egl_x11=yes
    libs_mplayer="$libs_mplayer -lEGL $ld_dl"
  elif cc_check -DGL_EGL_ANDROID -lEGL ; then
    _gl=yes
    _gl_egl_android=yes
    libs_mplayer="$libs_mplayer -lEGL $ld_dl"
  fi
  if win32 && cc_check -DGL_WIN32 -lopengl32 ; then
    _gl=yes
    _gl_win32=yes
    libs_mplayer="$libs_mplayer -lopengl32 -lgdi32"
  fi
  # last so it can reuse any linker etc. flags detected before
  if test "$_sdl" = yes ; then
    if cc_check -DGL_SDL ||
       cc_check -DCONFIG_SDL_SDL_H -DGL_SDL ; then
      _gl=yes
      _gl_sdl=yes
    elif cc_check -DGL_SDL -lGL ||
       cc_check -DCONFIG_SDL_SDL_H -DGL_SDL -lGL ; then
      _gl=yes
      _gl_sdl=yes
      libs_mplayer="$libs_mplayer -lGL"
    fi
  fi
  if test "$_corevideo" = yes ; then
    _gl=yes
    _gl_osx=yes
  fi
else
  _gl=no
fi
if test "$_gl" = yes ; then
  def_gl='#define CONFIG_GL 1'
  res_comment="backends:"
  if test "$_gl_win32" = yes ; then
    def_gl_win32='#define CONFIG_GL_WIN32 1'
    res_comment="$res_comment win32"
  fi
  if test "$_gl_x11" = yes ; then
    def_gl_x11='#define CONFIG_GL_X11 1'
    res_comment="$res_comment x11"
  fi
  if test "$_gl_egl_android" = yes ; then
    def_gl_egl_android='#define CONFIG_GL_EGL_ANDROID 1'
    res_comment="$res_comment egl_android"
  fi
  if test "$_gl_egl_x11" = yes ; then
    def_gl_egl_x11='#define CONFIG_GL_EGL_X11 1'
    res_comment="$res_comment egl_x11"
  fi
  if test "$_gl_sdl" = yes ; then
    def_gl_sdl='#define CONFIG_GL_SDL 1'
    res_comment="$res_comment sdl"
  fi
  if test "$_gl_osx" = yes ; then
    def_gl_osx='#define CONFIG_GL_OSX 1'
    res_comment="$res_comment osx"
  fi
  vomodules="opengl $vomodules"
else
  def_gl='#undef CONFIG_GL'
  def_gl_win32='#undef CONFIG_GL_WIN32'
  def_gl_x11='#undef CONFIG_GL_X11'
  def_gl_egl_android='#undef CONFIG_GL_EGL_ANDROID'
  def_gl_egl_x11='#undef CONFIG_GL_EGL_X11'
  def_gl_sdl='#undef CONFIG_GL_SDL'
  def_gl_osx='#undef CONFIG_GL_OSX'
  novomodules="opengl $novomodules"
fi
echores "$_gl"


echocheck "MatrixView"
if test "$matrixview" = auto ; then
  matrixview="$_gl"
fi
if test "$matrixview" = yes ; then
  vomodules="matrixview $vomodules"
  def_matrixview='#define CONFIG_MATRIXVIEW 1'
else
  novomodules="matrixview $novomodules"
  def_matrixview='#undef CONFIG_MATRIXVIEW'
fi
echores "$matrixview"


if os2 ; then
echocheck "KVA (SNAP/WarpOverlay!/VMAN/DIVE)"
if test "$_kva" = auto; then
  _kva=no;
  header_check_broken os2.h kva.h -lkva && _kva=yes
fi
if test "$_kva" = yes ; then
  def_kva='#define CONFIG_KVA 1'
  libs_mplayer="$libs_mplayer -lkva"
  vomodules="kva $vomodules"
else
  def_kva='#undef CONFIG_KVA'
  novomodules="kva $novomodules"
fi
echores "$_kva"
fi #if os2


if win32; then

echocheck "Windows waveout"
if test "$_win32waveout" = auto ; then
  _win32waveout=no
  header_check_broken windows.h mmsystem.h -lwinmm && _win32waveout=yes
fi
if test "$_win32waveout" = yes ; then
  def_win32waveout='#define CONFIG_WIN32WAVEOUT 1'
  libs_mplayer="$libs_mplayer -lwinmm"
  aomodules="win32 $aomodules"
else
  def_win32waveout='#undef CONFIG_WIN32WAVEOUT'
  noaomodules="win32 $noaomodules"
fi
echores "$_win32waveout"

echocheck "Direct3D"
if test "$_direct3d" = auto ; then
  _direct3d=no
  header_check d3d9.h && _direct3d=yes
fi
if test "$_direct3d" = yes ; then
  def_direct3d='#define CONFIG_DIRECT3D 1'
  vomodules="direct3d $vomodules"
else
  def_direct3d='#undef CONFIG_DIRECT3D'
  novomodules="direct3d $novomodules"
fi
echores "$_direct3d"

echocheck "Directx"
if test "$_directx" = auto ; then
  cat > $TMPC << EOF
#include <windows.h>
#include <ddraw.h>
#include <dsound.h>
int main(void) { return 0; }
EOF
  _directx=no
  cc_check -lgdi32 && _directx=yes
fi
if test "$_directx" = yes ; then
  def_directx='#define CONFIG_DIRECTX 1'
  libs_mplayer="$libs_mplayer -lgdi32"
  vomodules="directx $vomodules"
  aomodules="dsound $aomodules"
else
  def_directx='#undef CONFIG_DIRECTX'
  novomodules="directx $novomodules"
  noaomodules="dsound $noaomodules"
fi
echores "$_directx"

fi #if win32; then


echocheck "DXR2"
if test "$_dxr2" = auto; then
  _dxr2=no
  for inc_tmp in "" -I/usr/local/include/dxr2 -I/usr/include/dxr2; do
    header_check dxr2ioctl.h $inc_tmp && _dxr2=yes &&
      extra_cflags="$extra_cflags $inc_tmp" && break
  done
fi
if test "$_dxr2" = yes; then
  def_dxr2='#define CONFIG_DXR2 1'
  aomodules="dxr2 $aomodules"
  vomodules="dxr2 $vomodules"
else
  def_dxr2='#undef CONFIG_DXR2'
  noaomodules="dxr2 $noaomodules"
  novomodules="dxr2 $novomodules"
fi
echores "$_dxr2"

echocheck "DXR3/H+"
if test "$_dxr3" = auto ; then
  _dxr3=no
  header_check linux/em8300.h && _dxr3=yes
fi
if test "$_dxr3" = yes ; then
  def_dxr3='#define CONFIG_DXR3 1'
  vomodules="dxr3 $vomodules"
else
  def_dxr3='#undef CONFIG_DXR3'
  novomodules="dxr3 $novomodules"
fi
echores "$_dxr3"


echocheck "IVTV TV-Out (pre linux-2.6.24)"
if test "$_ivtv" = auto ; then
  cat > $TMPC << EOF
#include <sys/time.h>
#include <linux/videodev2.h>
#include <linux/ivtv.h>
#include <sys/ioctl.h>
int main(void) {
struct ivtv_cfg_stop_decode sd;
struct ivtv_cfg_start_decode sd1;
ioctl(0, IVTV_IOC_START_DECODE, &sd1);
ioctl(0, IVTV_IOC_STOP_DECODE, &sd);
return 0; }
EOF
  _ivtv=no
  cc_check && _ivtv=yes
fi
if test "$_ivtv" = yes ; then
  def_ivtv='#define CONFIG_IVTV 1'
  vomodules="ivtv $vomodules"
  aomodules="ivtv $aomodules"
else
  def_ivtv='#undef CONFIG_IVTV'
  novomodules="ivtv $novomodules"
  noaomodules="ivtv $noaomodules"
fi
echores "$_ivtv"


echocheck "V4L2 MPEG Decoder"
if test "$_v4l2" = auto ; then
  cat > $TMPC << EOF
#include <sys/time.h>
#include <linux/videodev2.h>
#include <linux/version.h>
int main(void) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
#error kernel headers too old, need 2.6.22
#endif
  struct v4l2_ext_controls ctrls;
  ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
  return 0;
}
EOF
  _v4l2=no
  cc_check && _v4l2=yes
fi
if test "$_v4l2" = yes ; then
  def_v4l2='#define CONFIG_V4L2_DECODER 1'
  vomodules="v4l2 $vomodules"
  aomodules="v4l2 $aomodules"
else
  def_v4l2='#undef CONFIG_V4L2_DECODER'
  novomodules="v4l2 $novomodules"
  noaomodules="v4l2 $noaomodules"
fi
echores "$_v4l2"



#########
# AUDIO #
#########


echocheck "OSS Audio"
if test "$_ossaudio" = auto ; then
  _ossaudio=no
  return_check $_soundcard_header SNDCTL_DSP_SETFRAGMENT && _ossaudio=yes
fi
if test "$_ossaudio" = yes ; then
  def_ossaudio='#define CONFIG_OSS_AUDIO 1'
  aomodules="oss $aomodules"
  _real_ossaudio=no
  cpp_condition_check "$_soundcard_header" OPEN_SOUND_SYSTEM &&
      _real_ossaudio=yes
  if test "$_real_ossaudio" = yes; then
      def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/dsp"'
  elif netbsd || openbsd ; then
      def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/sound"'
      extra_ldflags="$extra_ldflags -lossaudio"
  else
      def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/dsp"'
  fi
  def_ossaudio_devmixer='#define PATH_DEV_MIXER "/dev/mixer"'
else
  def_ossaudio='#undef CONFIG_OSS_AUDIO'
  def_ossaudio_devdsp='#define PATH_DEV_DSP ""'
  def_ossaudio_devmixer='#define PATH_DEV_MIXER ""'
  noaomodules="oss $noaomodules"
fi
echores "$_ossaudio"


echocheck "aRts"
if test "$_arts" = auto ; then
  _arts=no
  if ( artsc-config --version ) >> "$TMPLOG" 2>&1 ; then
    statement_check artsc.h 'arts_init()' $(artsc-config --libs) $(artsc-config --cflags) &&
      _arts=yes
  fi
fi

if test "$_arts" = yes ; then
  def_arts='#define CONFIG_ARTS 1'
  aomodules="arts $aomodules"
  libs_mplayer="$libs_mplayer $(artsc-config --libs)"
  extra_cflags="$extra_cflags $(artsc-config --cflags)"
else
  noaomodules="arts $noaomodules"
fi
echores "$_arts"


echocheck "EsounD"
if test "$_esd" = auto ; then
  _esd=no
  if ( esd-config --version ) >> "$TMPLOG" 2>&1 ; then
    statement_check esd.h 'esd_open_sound("test")' $(esd-config --libs) $(esd-config --cflags) && _esd=yes
  fi
fi
echores "$_esd"

if test "$_esd" = yes ; then
  def_esd='#define CONFIG_ESD 1'
  aomodules="esd $aomodules"
  libs_mplayer="$libs_mplayer $(esd-config --libs)"
  extra_cflags="$extra_cflags $(esd-config --cflags)"

  echocheck "esd_get_latency()"
  statement_check esd.h 'esd_get_latency(0)' $(esd-config --libs) $(esd-config --cflags) &&
    _esd_latency=yes && def_esd_latency='#define CONFIG_ESD_LATENCY 1'
  echores "$_esd_latency"
else
  def_esd='#undef CONFIG_ESD'
  def_esd_latency='#undef CONFIG_ESD_LATENCY'
  noaomodules="esd $noaomodules"
fi


echocheck "NAS"
if test "$_nas" = auto ; then
  _nas=no
  header_check audio/audiolib.h -laudio -lXt && _nas=yes
fi
if test "$_nas" = yes ; then
  def_nas='#define CONFIG_NAS 1'
  libs_mplayer="$libs_mplayer -laudio -lXt"
  aomodules="nas $aomodules"
else
  noaomodules="nas $noaomodules"
  def_nas='#undef CONFIG_NAS'
fi
echores "$_nas"


echocheck "pulse"
if test "$_pulse" = auto ; then
  _pulse=no
  if $_pkg_config --exists 'libpulse >= 0.9' ; then
    header_check pulse/pulseaudio.h $($_pkg_config --libs --cflags libpulse) &&
      _pulse=yes
  fi
fi
echores "$_pulse"

if test "$_pulse" = yes ; then
  def_pulse='#define CONFIG_PULSE 1'
  aomodules="pulse $aomodules"
  libs_mplayer="$libs_mplayer $($_pkg_config --libs libpulse)"
  extra_cflags="$extra_cflags $($_pkg_config --cflags libpulse)"
else
  def_pulse='#undef CONFIG_PULSE'
  noaomodules="pulse $noaomodules"
fi


echocheck "JACK"
if test "$_jack" = auto ; then
  _jack=yes
  if statement_check jack/jack.h 'jack_client_open("test", JackUseExactName, NULL)' -ljack ; then
    libs_mplayer="$libs_mplayer -ljack"
  elif statement_check jack/jack.h 'jack_client_open("test", JackUseExactName, NULL)' $($_pkg_config --libs --cflags --silence-errors jack) ; then
    libs_mplayer="$libs_mplayer $($_pkg_config --libs jack)"
    extra_cflags="$extra_cflags "$($_pkg_config --cflags jack)""
  else
    _jack=no
  fi
fi

if test "$_jack" = yes ; then
  def_jack='#define CONFIG_JACK 1'
  aomodules="jack $aomodules"
else
  noaomodules="jack $noaomodules"
fi
echores "$_jack"

echocheck "OpenAL"
if test "$_openal" = auto ; then
  _openal=no
cat > $TMPC << EOF
#ifdef OPENAL_AL_H
#include <OpenAL/al.h>
#else
#include <AL/al.h>
#endif
int main(void) {
  alSourceQueueBuffers(0, 0, 0);
  return 0;
}
EOF
  for I in "-lopenal" "-lopenal32" "-framework OpenAL" ; do
    cc_check $I && _openal=yes && break
    cc_check -DOPENAL_AL_H=1 $I && def_openal_h='#define OPENAL_AL_H 1' && _openal=yes && break
  done
  test "$_openal" = yes && libs_mplayer="$libs_mplayer $I"
fi
if test "$_openal" = yes ; then
  def_openal='#define CONFIG_OPENAL 1'
  aomodules="openal $aomodules"
else
  noaomodules="openal $noaomodules"
fi
echores "$_openal"


echocheck "ALSA audio"
if test "$_alloca" = yes && test "$_alsa" = auto ; then
  _alsa=no
  header_check alsa/asoundlib.h -lasound $ld_dl $ld_pthread && _alsa=yes
fi
if test "$_alsa" = yes ; then
  aomodules="alsa $aomodules"
  def_alsa='#define CONFIG_ALSA 1'
  extra_ldflags="$extra_ldflags -lasound $ld_dl $ld_pthread"
else
  noaomodules="alsa $noaomodules"
  def_alsa='#undef CONFIG_ALSA'
fi
echores "$_alsa"


echocheck "Sun audio"
if test "$_sunaudio" = auto ; then
  cat > $TMPC << EOF
#include <sys/types.h>
#include <sys/audioio.h>
int main(void) { audio_info_t info; AUDIO_INITINFO(&info); return 0; }
EOF
  _sunaudio=no
  cc_check && _sunaudio=yes
fi
if test "$_sunaudio" = yes ; then
  def_sunaudio='#define CONFIG_SUN_AUDIO 1'
  aomodules="sun $aomodules"
else
  def_sunaudio='#undef CONFIG_SUN_AUDIO'
  noaomodules="sun $noaomodules"
fi
echores "$_sunaudio"


def_mlib='#define CONFIG_MLIB 0'
if sunos; then
echocheck "Sun mediaLib"
if test "$_mlib" = auto ; then
  _mlib=no
  cc_check mlib.h "mlib_VideoColorYUV2ABGR420(0, 0, 0, 0, 0, 0, 0, 0, 0)" -lmlib &&
    _mlib=yes && def_mlib='#define CONFIG_MLIB 1'
fi
echores "$_mlib"
fi #if sunos


if darwin; then
echocheck "CoreAudio"
if test "$_coreaudio" = auto ; then
  cat > $TMPC <<EOF
#include <CoreAudio/CoreAudio.h>
#include <AudioToolbox/AudioToolbox.h>
#include <AudioUnit/AudioUnit.h>
int main(void) { return 0; }
EOF
  _coreaudio=no
  cc_check -framework CoreAudio -framework AudioUnit -framework AudioToolbox && _coreaudio=yes
fi
if test "$_coreaudio" = yes ; then
  libs_mplayer="$libs_mplayer -framework CoreAudio -framework AudioUnit -framework AudioToolbox"
  def_coreaudio='#define CONFIG_COREAUDIO 1'
  aomodules="coreaudio $aomodules"
else
  def_coreaudio='#undef CONFIG_COREAUDIO'
  noaomodules="coreaudio $noaomodules"
fi
echores $_coreaudio
fi #if darwin


if irix; then
echocheck "SGI audio"
if test "$_sgiaudio" = auto ; then
  _sgiaudio=no
  header_check dmedia/audio.h && _sgiaudio=yes
fi
if test "$_sgiaudio" = "yes" ; then
  def_sgiaudio='#define CONFIG_SGI_AUDIO 1'
  libs_mplayer="$libs_mplayer -laudio"
  aomodules="sgi $aomodules"
else
  def_sgiaudio='#undef CONFIG_SGI_AUDIO'
  noaomodules="sgi $noaomodules"
fi
echores "$_sgiaudio"
fi #if irix


if os2 ; then
echocheck "KAI (UNIAUD/DART)"
if test "$_kai" = auto; then
  _kai=no;
  header_check_broken os2.h kai.h -lkai && _kai=yes
fi
if test "$_kai" = yes ; then
  def_kai='#define CONFIG_KAI 1'
  libs_mplayer="$libs_mplayer -lkai"
  aomodules="kai $aomodules"
else
  def_kai='#undef CONFIG_KAI'
  noaomodules="kai $noaomodules"
fi
echores "$_kai"

echocheck "DART"
if test "$_dart" = auto; then
  _dart=no;
  header_check_broken os2.h dart.h -ldart && _dart=yes
fi
if test "$_dart" = yes ; then
  def_dart='#define CONFIG_DART 1'
  libs_mplayer="$libs_mplayer -ldart"
  aomodules="dart $aomodules"
else
  def_dart='#undef CONFIG_DART'
  noaomodules="dart $noaomodules"
fi
echores "$_dart"
fi #if os2


# set default CD/DVD devices
if win32 || os2 ; then
  default_cdrom_device="D:"
elif darwin ; then
  default_cdrom_device="/dev/disk1"
elif dragonfly ; then
  default_cdrom_device="/dev/cd0"
elif freebsd ; then
  default_cdrom_device="/dev/acd0"
elif openbsd ; then
  default_cdrom_device="/dev/rcd0c"
elif sunos ; then
  default_cdrom_device="/vol/dev/aliases/cdrom0"
  # Solaris 10 and newer use HAL instead of the vold daemon.
  test $(uname -r | sed 's/^5\.//') -gt 10 && default_cdrom_device="/cdrom/cdrom0"
elif amigaos ; then
  default_cdrom_device="a1ide.device:2"
else
  default_cdrom_device="/dev/cdrom"
fi

if win32 || os2 || dragonfly || freebsd || openbsd || sunos || amigaos ; then
  default_dvd_device=$default_cdrom_device
elif darwin ; then
  default_dvd_device="/dev/rdiskN"
else
  default_dvd_device="/dev/dvd"
fi


echocheck "VCD support"
if test "$_vcd" = auto; then
  _vcd=no
  if linux || freebsd || netbsd || openbsd || dragonfly || bsdos || darwin || sunos || os2; then
    _vcd=yes
  elif mingw32; then
  header_check ddk/ntddcdrm.h && _vcd=yes
  fi
fi
if test "$_vcd" = yes; then
  inputmodules="vcd $inputmodules"
  def_vcd='#define CONFIG_VCD 1'
else
  def_vcd='#undef CONFIG_VCD'
  noinputmodules="vcd $noinputmodules"
  res_comment="not supported on this OS"
fi
echores "$_vcd"



echocheck "Blu-ray support"
if test "$_bluray" = auto ; then
  _bluray=no
  statement_check libbluray/bluray.h 'bd_get_title_info(0, 0, 0)' -lbluray && _bluray=yes
fi
if test "$_bluray" = yes ; then
  def_bluray='#define CONFIG_LIBBLURAY 1'
  extra_ldflags="$extra_ldflags -lbluray"
  inputmodules="bluray $inputmodules"
else
  def_bluray='#undef CONFIG_LIBBLURAY'
  noinputmodules="bluray $noinputmodules"
fi
echores "$_bluray"

echocheck "dvdread"
if test "$_dvdread_internal" = auto ; then
  _dvdread_internal=no
  if linux || freebsd || netbsd || openbsd || dragonfly || sunos || hpux ||
     darwin || win32 || os2; then
    _dvdread_internal=yes
    _dvdread=yes
    extra_cflags="-Ilibdvdread4 $extra_cflags"
  fi
fi
if test "$_dvdread" = auto ; then
  _dvdread=no
  if test "$_dl" = yes; then
    _dvdreadcflags=$($_dvdreadconfig --cflags 2> /dev/null)
    _dvdreadlibs=$($_dvdreadconfig --libs 2> /dev/null)
    if header_check dvdread/dvd_reader.h $_dvdreadcflags $_dvdreadlibs $ld_dl ; then
      _dvdread=yes
      extra_cflags="$extra_cflags $_dvdreadcflags"
      extra_ldflags="$extra_ldflags $_dvdreadlibs"
      res_comment="external"
    fi
  fi
fi

if test "$_dvdread_internal" = yes; then
  def_dvdread='#define CONFIG_DVDREAD 1'
  inputmodules="dvdread(internal) $inputmodules"
  res_comment="internal"
elif test "$_dvdread" = yes; then
  def_dvdread='#define CONFIG_DVDREAD 1'
  extra_ldflags="$extra_ldflags -ldvdread"
  inputmodules="dvdread(external) $inputmodules"
  res_comment="external"
else
  def_dvdread='#undef CONFIG_DVDREAD'
  noinputmodules="dvdread $noinputmodules"
fi
echores "$_dvdread"


echocheck "internal libdvdcss"
def_broken_mkdir='#undef HAVE_BROKEN_MKDIR'
def_dvdio='#undef DVD_STRUCT_IN_SYS_DVDIO_H'
def_dvd='#undef DVD_STRUCT_IN_DVD_H'
def_cdio='#undef DVD_STRUCT_IN_SYS_CDIO_H'
def_cdrom='#undef DVD_STRUCT_IN_LINUX_CDROM_H'
def_hpux_scsi_h='#undef HPUX_SCTL_IO'
def_sol_scsi_h='#undef SOLARIS_USCSI'
def_sys_uio_h='#undef HAVE_SYS_UIO_H'
_dvdio=no
_dvd=no
_cdio=no
_cdrom=no
_sol_scsi_h=no
_hpux_scsi_h=no
if test "$_libdvdcss_internal" = auto && test "$_dvdread_internal" = yes ; then
  _libdvdcss_internal=no
  test -d libdvdcss && _libdvdcss_internal=yes

  if header_check linux/cdrom.h ; then
     _cdrom=yes
     def_cdrom='#define DVD_STRUCT_IN_LINUX_CDROM_H 1'
  # FreeBSD 8.1 has broken dvdio.h
  elif header_check_broken sys/types.h sys/dvdio.h ; then
    _dvdio=yes
    def_dvdio='#define DVD_STRUCT_IN_SYS_DVDIO_H 1'
  elif header_check dvd.h ; then
    _dvd=yes
    def_dvd='#define DVD_STRUCT_IN_DVD_H 1'
  # at least OpenSolaris has a broken cdio.h
  elif header_check_broken sys/types.h sys/cdio.h ; then
    _cdio=yes
    def_cdio='#define DVD_STRUCT_IN_SYS_CDIO_H 1'
  fi

  if sunos; then
    header_check sys/scsi/scsi_types.h &&
      header_check_broken sys/types.h sys/scsi/impl/uscsi.h &&
        _sol_scsi_h=yes && def_sol_scsi_h='#define SOLARIS_USCSI 1'
  elif hpux; then
    # also used by AIX, but AIX does not support VCD and/or libdvdread
    header_check sys/scsi.h && _hpux_scsi_h=yes &&
      def_hpux_scsi_h='#define HPUX_SCTL_IO 1' ||
      _libdvdcss_internal=no
  fi

  statement_check_broken stddef.h sys/stat.h 'mkdir(NULL, 0)' ||
    def_broken_mkdir='#define HAVE_BROKEN_MKDIR 1'

  header_check "sys/uio.h" &&
    def_sys_uio_h='#define HAVE_SYS_UIO_H 1'

fi
if test "$_libdvdcss_internal" = yes ; then
  if linux || netbsd || openbsd || wine ; then
    def_dvd_linux='#define HAVE_LINUX_DVD_STRUCT 1'
    openbsd && def_dvd_openbsd='#define HAVE_OPENBSD_DVD_STRUCT 1'
  elif freebsd || dragonfly ; then
    def_dvd_bsd='#define HAVE_BSD_DVD_STRUCT 1'
  elif darwin ; then
    def_dvd_darwin='#define DARWIN_DVD_IOCTL'
    extra_ldflags="$extra_ldflags -framework IOKit -framework Carbon"
  elif cygwin ; then
    cflags_libdvdcss="-D_WIN32_IE=0x0500 -mwin32"
  elif mingw32 ; then
    cflags_libdvdcss="-D_WIN32_IE=0x0500"
  fi
  cflags_libdvdcss_dvdread="-Ilibdvdcss"
  def_dvdcss="#define HAVE_DVDCSS_DVDCSS_H 1"
  inputmodules="libdvdcss(internal) $inputmodules"
else
  noinputmodules="libdvdcss(internal) $noinputmodules"
fi
echores "$_libdvdcss_internal"


echocheck "libcdio"
if test "$_libcdio" = auto ; then
        cat > $TMPC << EOF
#include <stdio.h>
#include <cdio/version.h>
#include <cdio/cdda.h>
#include <cdio/paranoia.h>
int main(void) {
    void *test = cdda_verbose_set;
    printf("%s\n", CDIO_VERSION);
    return test == (void *)1;
}
EOF
        _libcdio=no
    for ld_tmp in "" "-lwinmm" ; do
        ld_tmp="-lcdio_cdda -lcdio -lcdio_paranoia $ld_tmp"
        cc_check $ld_tmp && _libcdio=yes &&
            extra_ldflags="$extra_ldflags $ld_tmp" && break
    done
    if test "$_libcdio" = no && $_pkg_config --exists libcdio_paranoia ; then
      inc_tmp=$($_pkg_config --cflags libcdio_paranoia)
      ld_tmp=$($_pkg_config --libs libcdio_paranoia)
      cc_check $inc_tmp $ld_tmp && _libcdio=yes &&
        extra_ldflags="$extra_ldflags $ld_tmp" && extra_cflags="$extra_cflags $inc_tmp"
    fi
fi
if test "$_libcdio" = yes ; then
    _cdda='yes'
    _cdparanoia=no
    def_libcdio='#define CONFIG_LIBCDIO 1'
    def_havelibcdio='yes'
else
    _libcdio=no
    def_libcdio='#undef CONFIG_LIBCDIO'
    def_havelibcdio='no'
fi
echores "$_libcdio"

echocheck "cdparanoia"
if test "$_cdparanoia" = auto ; then
    _cdparanoia=no
    for inc_tmp in "" "-I/usr/include/cdda" "-I/usr/local/include/cdda" ; do
      statement_check_broken cdda_interface.h cdda_paranoia.h 'paranoia_cachemodel_size(NULL, 0)' $inc_tmp -lcdda_interface -lcdda_paranoia &&
        _cdparanoia=yes && extra_cflags="$extra_cflags $inc_tmp" && break
    done
fi
if test "$_cdparanoia" = yes ; then
    _cdda='yes'
    extra_ldflags="$extra_ldflags -lcdda_interface -lcdda_paranoia"
    openbsd && extra_ldflags="$extra_ldflags -lutil"
elif test "$_libcdio" = yes ; then
    res_comment='using libcdio'
fi
echores "$_cdparanoia"


if test "$_cdda" = yes ; then
    test $_cddb = auto && test $networking = yes && _cddb=yes
    def_cdparanoia='#define CONFIG_CDDA 1'
    inputmodules="cdda $inputmodules"
else
    def_cdparanoia='#undef CONFIG_CDDA'
    noinputmodules="cdda $noinputmodules"
fi

if test "$_cddb" = yes ; then
    def_cddb='#define CONFIG_CDDB 1'
    inputmodules="cddb $inputmodules"
else
    _cddb=no
    def_cddb='#undef CONFIG_CDDB'
    noinputmodules="cddb $noinputmodules"
fi

echocheck "bitmap font support"
if test "$_bitmap_font" = yes ; then
  def_bitmap_font="#define CONFIG_BITMAP_FONT 1"
else
  def_bitmap_font="#undef CONFIG_BITMAP_FONT"
fi
echores "$_bitmap_font"


echocheck "freetype >= 2.0.9"

# freetype depends on iconv
if test "$_iconv" = no ; then
    _freetype=no
    res_comment="iconv support needed"
fi

if test "$_freetype" = auto ; then
    if ( $_freetypeconfig --version ) >/dev/null 2>&1 ; then
        cat > $TMPC << EOF
#include <stdio.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#if ((FREETYPE_MAJOR < 2) || ((FREETYPE_MINOR == 0) && (FREETYPE_PATCH < 9)))
#error "Need FreeType 2.0.9 or newer"
#endif
int main(void) {
    FT_Library library;
    FT_Init_FreeType(&library);
    return 0;
}
EOF
        _freetype=no
        cc_check $($_freetypeconfig --cflags) $($_freetypeconfig --libs) && _freetype=yes
    else
        _freetype=no
    fi
fi
if test "$_freetype" = yes ; then
    def_freetype='#define CONFIG_FREETYPE 1'
    extra_cflags="$extra_cflags $($_freetypeconfig --cflags)"
    extra_ldflags="$extra_ldflags $($_freetypeconfig --libs)"
else
    def_freetype='#undef CONFIG_FREETYPE'
fi
echores "$_freetype"

if test "$_freetype" = no ; then
    _fontconfig=no
    res_comment="FreeType support needed"
fi
echocheck "fontconfig"
if test "$_fontconfig" = auto ; then
        cat > $TMPC << EOF
#include <stdio.h>
#include <stdlib.h>
#include <fontconfig/fontconfig.h>
#if FC_VERSION < 20402
#error At least version 2.4.2 of Fontconfig required
#endif
int main(void) {
    int err = FcInit();
    if (err == FcFalse) {
        printf("Could not initialize Fontconfig library.\n");
        exit(err);
    }
    return 0;
}
EOF
  _fontconfig=no
  for ld_tmp in "" "-lexpat -lfreetype" "-lexpat -lfreetype -lz" "-lexpat -lfreetype -lz -liconv" ; do
    ld_tmp="-lfontconfig $ld_tmp"
    cc_check $ld_tmp && _fontconfig=yes && extra_ldflags="$extra_ldflags $ld_tmp" && break
  done
  if test "$_fontconfig" = no && $_pkg_config --exists fontconfig ; then
    inc_tmp=$($_pkg_config --cflags fontconfig)
    ld_tmp=$($_pkg_config --libs fontconfig)
    cc_check $inc_tmp $ld_tmp && _fontconfig=yes &&
      extra_ldflags="$extra_ldflags $ld_tmp" && extra_cflags="$extra_cflags $inc_tmp"
  fi
fi
if test "$_fontconfig" = yes ; then
    def_fontconfig='#define CONFIG_FONTCONFIG 1'
else
    def_fontconfig='#undef CONFIG_FONTCONFIG'
fi
echores "$_fontconfig"


echocheck "fribidi with charsets"
if test "$_fribidi" = auto ; then
    cat > $TMPC << EOF
#include <stdlib.h>
#include <fribidi/fribidi.h>
FriBidiParType test;
int main(void) {
    if (fribidi_parse_charset("UTF-8") != FRIBIDI_CHAR_SET_UTF8)
       exit(1);
    return 0;
}
EOF
    _fribidi=no
    cc_check -lfribidi && _fribidi=yes && extra_ldflags="$extra_ldflags -lfribidi"
    if $_pkg_config --exists fribidi > /dev/null 2>&1 &&
       test "$_fribidi" = no ; then
        inc_tmp="$($_pkg_config --cflags fribidi)"
        ld_tmp="$($_pkg_config --libs fribidi)"
        cc_check $inc_tmp $ld_tmp && _fribidi=yes &&
            extra_cflags="$extra_cflags $inc_tmp" &&
            extra_ldflags="$extra_ldflags $ld_tmp"
    fi
fi
if test "$_fribidi" = yes ; then
    def_fribidi='#define CONFIG_FRIBIDI 1'
else
    def_fribidi='#undef CONFIG_FRIBIDI'
fi
echores "$_fribidi"


echocheck "SSA/ASS support"
# libass depends on FreeType
if test "$_freetype" = no ; then
    _ass=no
    ass_internal=no
    res_comment="FreeType and FriBiDi support needed"
fi

if test "$_ass" = auto ; then
    cat > $TMPC << EOF
#include <ft2build.h>
#include FT_FREETYPE_H
#if ((FREETYPE_MAJOR < 2) || (FREETYPE_MINOR < 2) || ((FREETYPE_MINOR == 2) && (FREETYPE_PATCH < 1)))
#error "Need FreeType 2.2.1 or newer"
#endif
int main(void) { return 0; }
EOF
    _ass=no
    cc_check $($_freetypeconfig --cflags) $($_freetypeconfig --libs) && _ass=yes
    if test "$_ass" = no ; then
        res_comment="FreeType >= 2.2.1 needed"
    elif test "$ass_internal" != yes ; then
        cat > $TMPC << EOF
#include <ass/ass.h>
int main(void) {
#if !defined(LIBASS_VERSION) || LIBASS_VERSION < 0x00910000
#error "libass version too old"
#endif
  ass_process_force_style(0);
  return 0;
}
EOF
        if cc_check -lass ; then
            res_comment="external"
            extra_ldflags="$extra_ldflags -lass"
        elif test "$ass_internal" = auto ; then
            ass_internal=yes
        else
            _ass=no
        fi
    fi
fi
if test "$_ass" = yes ; then
    def_ass='#define CONFIG_ASS 1'
else
    def_ass='#undef CONFIG_ASS'
fi
if test "$ass_internal" = yes ; then
    def_ass_internal='#define CONFIG_ASS_INTERNAL 1'
else
    def_ass_internal='#undef CONFIG_ASS_INTERNAL'
    ass_internal=no
fi
echores "$_ass"


echocheck "ENCA"
if test "$_enca" = auto ; then
    _enca=no
    statement_check enca.h 'enca_get_languages(NULL)' -lenca && _enca=yes
fi
    if test "$_enca" = yes ; then
        def_enca='#define CONFIG_ENCA 1'
        extra_ldflags="$extra_ldflags -lenca"
    else
        def_enca='#undef CONFIG_ENCA'
    fi
echores "$_enca"


echocheck "zlib"
_zlib=no
statement_check zlib.h 'inflate(0, Z_NO_FLUSH)' -lz && _zlib=yes
if test "$_zlib" = yes ; then
  def_zlib='#define CONFIG_ZLIB 1'
  extra_ldflags="$extra_ldflags -lz"
  # necessary for vf_screenshot
  mplayer_encoders="$mplayer_encoders PNG_ENCODER"
else
  def_zlib='#define CONFIG_ZLIB 0'
  libavdecoders=$(filter_out_component decoder 'FLASHSV FLASHSV2 PNG ZMBV ZLIB DXA EXR G2M TSCC ZEROCODEC')
  libavencoders=$(filter_out_component encoder 'FLASHSV FLASHSV2 PNG ZMBV ZLIB')
fi
echores "$_zlib"


echocheck "bzlib"
bzlib=no
def_bzlib='#define CONFIG_BZLIB 0'
statement_check bzlib.h 'BZ2_bzlibVersion()' -lbz2 && bzlib=yes
if test "$bzlib" = yes ; then
  def_bzlib='#define CONFIG_BZLIB 1'
  extra_ldflags="$extra_ldflags -lbz2"
fi
echores "$bzlib"


echocheck "RTC"
if test "$_rtc" = auto ; then
  cat > $TMPC << EOF
#include <sys/ioctl.h>
#ifdef __linux__
#include <linux/rtc.h>
#else
#include <rtc.h>
#define RTC_PIE_ON RTCIO_PIE_ON
#endif
int main(void) { return RTC_PIE_ON; }
EOF
  _rtc=no
  cc_check && _rtc=yes
  ppc && _rtc=no
fi
if test "$_rtc" = yes ; then
  def_rtc='#define HAVE_RTC 1'
else
  def_rtc='#undef HAVE_RTC'
fi
echores "$_rtc"


echocheck "liblzo2 support"
if test "$_liblzo" = auto ; then
  _liblzo=no
  statement_check lzo/lzo1x.h 'lzo_init()' -llzo2 && _liblzo=yes
fi
if test "$_liblzo" = yes ; then
  def_liblzo='#define CONFIG_LIBLZO 1'
  extra_ldflags="$extra_ldflags -llzo2"
  codecmodules="liblzo $codecmodules"
else
  def_liblzo='#undef CONFIG_LIBLZO'
  nocodecmodules="liblzo $nocodecmodules"
fi
echores "$_liblzo"


echocheck "mad support"
if test "$_mad" = auto ; then
  _mad=no
  statement_check mad.h 'mad_synth_init(0)' -lmad && _mad=yes
fi
if test "$_mad" = yes ; then
  def_mad='#define CONFIG_LIBMAD 1'
  extra_ldflags="$extra_ldflags -lmad"
  codecmodules="libmad $codecmodules"
else
  def_mad='#undef CONFIG_LIBMAD'
  nocodecmodules="libmad $nocodecmodules"
fi
echores "$_mad"

echocheck "Twolame"
if test "$_twolame" = auto ; then
  _twolame=no
  statement_check twolame.h 'twolame_init()' -ltwolame && _twolame=yes
fi
if test "$_twolame" = yes ; then
  def_twolame='#define CONFIG_TWOLAME 1'
  libs_mencoder="$libs_mencoder -ltwolame"
  codecmodules="twolame $codecmodules"
else
  def_twolame='#undef CONFIG_TWOLAME'
  nocodecmodules="twolame $nocodecmodules"
fi
echores "$_twolame"

echocheck "Toolame"
if test "$_toolame" = auto ; then
  _toolame=no
if test "$_twolame" = yes ; then
  res_comment="disabled by twolame"
else
  statement_check toolame.h 'toolame_init()' -ltoolame && _toolame=yes
fi
fi
if test "$_toolame" = yes ; then
  def_toolame='#define CONFIG_TOOLAME 1'
  libs_mencoder="$libs_mencoder -ltoolame"
  codecmodules="toolame $codecmodules"
else
  def_toolame='#undef CONFIG_TOOLAME'
  nocodecmodules="toolame $nocodecmodules"
fi
if test "$_toolamedir" ; then
  res_comment="using $_toolamedir"
fi
echores "$_toolame"

echocheck "OggVorbis support"
if test "$_tremor" = auto; then
  _tremor=no
  statement_check tremor/ivorbiscodec.h 'vorbis_synthesis(0, 0)' -logg -lvorbisidec && _tremor=yes && _libvorbis=no
fi
if test "$_libvorbis" = auto; then
  _libvorbis=no
  for vorbislibs in '-lvorbisenc -lvorbis -logg' '-lvorbis -logg' ; do
    statement_check vorbis/vorbisenc.h 'vorbis_encode_ctl(0, 0, 0); ogg_stream_clear(0)' $vorbislibs && _libvorbis=yes && break
  done
fi
if test "$_tremor" = yes ; then
  _vorbis=yes
  def_vorbis='#define CONFIG_OGGVORBIS 1'
  def_tremor='#define CONFIG_TREMOR 1'
  codecmodules="tremor $codecmodules"
  res_comment="integer libvorbis"
  extra_ldflags="$extra_ldflags -logg -lvorbisidec"
elif test "$_libvorbis" = yes ; then
  _vorbis=yes
  def_vorbis='#define CONFIG_OGGVORBIS 1'
  codecmodules="libvorbis $codecmodules"
  res_comment="libvorbis"
  extra_ldflags="$extra_ldflags $vorbislibs"
  libavencoders="$libavencoders LIBVORBIS_ENCODER"
else
  _vorbis=no
  nocodecmodules="libvorbis $nocodecmodules"
fi
echores "$_vorbis"

echocheck "libspeex (version >= 1.1 required)"
if test "$_speex" = auto ; then
  _speex=no
  cat > $TMPC << EOF
#include <stddef.h>
#include <speex/speex.h>
int main(void) { SpeexBits bits; void *dec = NULL; speex_decode_int(dec, &bits, dec); return 0; }
EOF
  cc_check -lspeex && _speex=yes
fi
if test "$_speex" = yes ; then
  def_speex='#define CONFIG_SPEEX 1'
  extra_ldflags="$extra_ldflags -lspeex"
  codecmodules="speex $codecmodules"
else
  def_speex='#undef CONFIG_SPEEX'
  nocodecmodules="speex $nocodecmodules"
fi
echores "$_speex"

echocheck "libgsm"
if test "$_libgsm" = auto ; then
  _libgsm=no
  statement_check gsm/gsm.h 'gsm_create()' -lgsm && _libgsm=yes
fi
if test "$_libgsm" = yes ; then
  def_libgsm='#define CONFIG_LIBGSM 1'
  extra_ldflags="$extra_ldflags -lgsm"
  libavencoders="$libavencoders LIBGSM_ENCODER LIBGSM_MS_ENCODER"
  libavdecoders="$libavdecoders LIBGSM_DECODER LIBGSM_MS_DECODER"
  codecmodules="libgsm $codecmodules"
else
  def_libgsm='#define CONFIG_LIBGSM 0'
  nocodecmodules="libgsm $nocodecmodules"
fi
echores "$_libgsm"

echocheck "OggTheora support"
if test "$_theora" = auto ; then
  _theora=no
  ld_theora="-ltheoradec -logg"
  statement_check theora/theoradec.h 'th_info_init(NULL)' $ld_theora &&
    extra_ldflags="$extra_ldflags $ld_theora" && _theora=yes
  if test _theora = no; then
    ld_theora=$($_pkg_config --silence-errors --libs theoradec)
    inc_theora=$($_pkg_config --silence-errors --cflags theoradec)
    statement_check theora/theoradec.h 'th_info_init(NULL)' $inc_theora $ld_theora &&
      extra_ldflags="$extra_ldflags $ld_theora" &&
      extra_cflags="$extra_cflags $inc_theora" && _theora=yes
  fi
fi
if test "$_theora" = yes ; then
  def_theora='#define CONFIG_OGGTHEORA 1'
  codecmodules="libtheora $codecmodules"
  # when --enable-theora is forced, we'd better provide a probably sane
  # $ld_theora than nothing
  test -z "$ld_theora" && extra_ldflags="$extra_ldflags -ltheoradec -logg"
else
  def_theora='#undef CONFIG_OGGTHEORA'
  nocodecmodules="libtheora $nocodecmodules"
fi
echores "$_theora"

# Any version of libmpg123 that knows MPG123_RESYNC_LIMIT shall be fine.
# That is, 1.2.0 onwards. Recommened is 1.14 onwards, though.
echocheck "mpg123 support"
def_mpg123='#undef CONFIG_MPG123'
if test "$_mpg123" = auto; then
  _mpg123=no
  statement_check mpg123.h 'mpg123_param(NULL, MPG123_RESYNC_LIMIT, -1, 0.)' -lmpg123 &&
      _mpg123=yes && extra_ldflags="$extra_ldflags -lmpg123"
fi
if test "$_mpg123" = yes ; then
  def_mpg123='#define CONFIG_MPG123 1'
  codecmodules="mpg123 $codecmodules"
else
  nocodecmodules="mpg123 $nocodecmodules"
fi
echores "$_mpg123"

echocheck "liba52 support"
def_liba52='#undef CONFIG_LIBA52'
if test "$_liba52" = auto ; then
  _liba52=no
  statement_check_broken inttypes.h a52dec/a52.h 'a52_state_t *testHand; testHand=a52_init(0)' -la52 &&
    _liba52=yes && extra_ldflags="$extra_ldflags -la52"
fi
if test "$_liba52" = yes ; then
  def_liba52='#define CONFIG_LIBA52 1'
  codecmodules="liba52 $codecmodules"
else
  nocodecmodules="liba52 $nocodecmodules"
fi
echores "$_liba52"


echocheck "libmpeg2 support"
if test "$_libmpeg2_internal" = auto ; then
  if alpha && test cc_vendor=gnu; then
    case $cc_version in
      2*|3.0*|3.1*) # cannot compile MVI instructions
        _libmpeg2_internal=no
        ;;
    esac
  else
    _libmpeg2=yes
    _libmpeg2_internal=yes
    res_comment="internal"
  fi
fi
if test "$_libmpeg2" = auto ; then
  _libmpeg2=no
  header_check_broken stdint.h mpeg2dec/mpeg2.h -lmpeg2 &&
    _libmpeg2=yes && extra_ldflags="$extra_ldflags -lmpeg2"
fi

def_libmpeg2='#undef CONFIG_LIBMPEG2'
def_libmpeg2_internal='#undef CONFIG_LIBMPEG2_INTERNAL'
if test "$_libmpeg2" = yes ; then
  def_libmpeg2='#define CONFIG_LIBMPEG2 1'
  if test "$_libmpeg2_internal" = yes ; then
    def_libmpeg2_internal='#define CONFIG_LIBMPEG2_INTERNAL 1'
    codecmodules="libmpeg2(internal) $codecmodules"
  else
    codecmodules="libmpeg2 $codecmodules"
  fi
else
  nocodecmodules="libmpeg2 $nocodecmodules"
fi
echores "$_libmpeg2"


echocheck "libdca support"
if test "$_libdca" = auto ; then
  _libdca=no
  for ld_dca in -ldca -ldts ; do
    statement_check_broken stdint.h dts.h 'dts_init(0)' $ld_dca &&
      extra_ldflags="$extra_ldflags $ld_dca" && _libdca=yes && break
  done
fi
if test "$_libdca" = yes ; then
  def_libdca='#define CONFIG_LIBDCA 1'
  codecmodules="libdca $codecmodules"
else
  def_libdca='#undef CONFIG_LIBDCA'
  nocodecmodules="libdca $nocodecmodules"
fi
echores "$_libdca"

echocheck "libmpcdec (musepack, version >= 1.2.1 required)"
if test "$_musepack" = yes ; then
  _musepack=no
  cat > $TMPC << EOF
#include <stddef.h>
#include <mpcdec/mpcdec.h>
int main(void) {
  mpc_streaminfo info;
  mpc_decoder decoder;
  mpc_decoder_set_streaminfo(&decoder, &info);
  mpc_decoder_decode_frame(&decoder, NULL, 0, NULL);
  return 0;
}
EOF
  cc_check -lmpcdec && _musepack=yes
fi
if test "$_musepack" = yes ; then
  def_musepack='#define CONFIG_MUSEPACK 1'
  extra_ldflags="$extra_ldflags -lmpcdec"
  codecmodules="musepack $codecmodules"
else
  def_musepack='#undef CONFIG_MUSEPACK'
  nocodecmodules="musepack $nocodecmodules"
fi
echores "$_musepack"


echocheck "FAAC support"
if test "$_faac" = auto && test "$_mencoder" = yes ; then
  cat > $TMPC <<EOF
#include <inttypes.h>
#include <faac.h>
int main(void) { unsigned long x, y; faacEncOpen(48000, 2, &x, &y); return 0; }
EOF
  _faac=no
  for ld_faac in "-lfaac" "-lfaac -lmp4v2 -lstdc++" ; do
    cc_check $ld_faac && libs_mencoder="$libs_mencoder $ld_faac" && _faac=yes && break
  done
fi
if test "$_faac" = yes ; then
  def_faac="#define CONFIG_FAAC 1"
  test "$_faac_lavc" = auto && _faac_lavc=yes
  if test "$_faac_lavc" = yes ; then
    def_faac_lavc="#define CONFIG_LIBFAAC 1"
    libs_mplayer="$libs_mplayer $ld_faac"
    libavencoders="$libavencoders LIBFAAC_ENCODER"
  fi
  codecmodules="faac $codecmodules"
else
  _faac_lavc=no
  def_faac="#undef CONFIG_FAAC"
  def_faac_lavc="#define CONFIG_LIBFAAC 0"
  nocodecmodules="faac $nocodecmodules"
fi
res_comment="in FFmpeg: $_faac_lavc"
echores "$_faac"


echocheck "FAAD2 support"
if test "$_faad" = auto ; then
  _faad=no
  cat > $TMPC << EOF
#include <faad.h>
#ifndef FAAD_MIN_STREAMSIZE
#error Too old version
#endif
int main(void) { faacDecHandle testhand; faacDecFrameInfo testinfo;
    testhand = faacDecOpen(); faacDecInit(0, 0, 0, 0, 0); return 0; }
EOF
  cc_check -lfaad && _faad=yes
fi

def_faad='#undef CONFIG_FAAD'
if test "$_faad" = yes ; then
  def_faad='#define CONFIG_FAAD 1'
  extra_ldflags="$extra_ldflags -lfaad"
  codecmodules="faad2 $codecmodules"
else
  nocodecmodules="faad2 $nocodecmodules"
fi
echores "$_faad"


echocheck "libilbc support"
if test "$_libilbc" = auto; then
  _libilbc=no
  statement_check ilbc.h 'WebRtcIlbcfix_InitDecode(0, 0, 0);' -lilbc && _libilbc=yes
fi
echores "$_libilbc"
if test "$_libilbc" = yes ; then
  def_libilbc='#define CONFIG_LIBILBC 1'
  extra_ldflags="$extra_ldflags -lilbc"
  libavdecoders="$libavdecoders LIBILBC_DECODER"
  codecmodules="ilbc $codecmodules"
else
  def_libilbc='#define CONFIG_ILBC 0'
  nocodecmodules="ilbc $nocodecmodules"
fi


echocheck "libopus decoding support"
if test "$_libopus" = auto ; then
  _libopus=no
  if $_pkg_config --exists 'opus' ; then
    statement_check opus_multistream.h 'opus_multistream_decoder_create(0,0,0,0,0,0)' $($_pkg_config --libs --cflags opus) &&
      _libopus=yes
  fi
fi
if test "$_libopus" = yes ; then
  def_libopus='#define CONFIG_LIBOPUS 1'
  libavdecoders="$libavdecoders LIBOPUS_DECODER"
  extra_cflags="$extra_cflags $($_pkg_config --cflags opus)"
  extra_ldflags="$extra_ldflags $($_pkg_config --libs opus)"
  codecmodules="libopus $codecmodules"
else
  nocodecmodules="libopus $nocodecmodules"
  def_libopus='#undef CONFIG_LIBOPUS'
fi
echores "$_libopus"


echocheck "LADSPA plugin support"
if test "$_ladspa" = auto ; then
  _ladspa=no
  statement_check ladspa.h 'LADSPA_Descriptor ld = {0}' && _ladspa=yes
fi
if test "$_ladspa" = yes; then
  def_ladspa="#define CONFIG_LADSPA 1"
else
  def_ladspa="#undef CONFIG_LADSPA"
fi
echores "$_ladspa"


echocheck "libbs2b audio filter support"
if test "$_libbs2b" = auto ; then
  cat > $TMPC <<EOF
#include <bs2b.h>
#if BS2B_VERSION_MAJOR < 3
#error Please use libbs2b >= 3.0.0, older versions are not supported.
#endif
int main(void) {
    t_bs2bdp filter;
    filter=bs2b_open();
    bs2b_close(filter);
    return 0;
}
EOF
  _libbs2b=no
  if $_pkg_config --exists libbs2b ; then
    inc_tmp=$($_pkg_config --cflags libbs2b)
    ld_tmp=$($_pkg_config --libs libbs2b)
    cc_check $inc_tmp $ld_tmp && extra_ldflags="$extra_ldflags $ld_tmp" &&
      extra_cflags="$extra_cflags $inc_tmp" && _libbs2b=yes
  else
    for inc_tmp in "" -I/usr/include/bs2b -I/usr/local/include \
        -I/usr/local/include/bs2b ; do
      if cc_check $inc_tmp -lbs2b ; then
        extra_ldflags="$extra_ldflags -lbs2b"
        extra_cflags="$extra_cflags $inc_tmp"
        _libbs2b=yes
        break
      fi
    done
  fi
fi
def_libbs2b="#undef CONFIG_LIBBS2B"
test "$_libbs2b" = yes && def_libbs2b="#define CONFIG_LIBBS2B 1"
echores "$_libbs2b"


if test -z "$_codecsdir" ; then
  for dir in "$_libdir/codecs" "$_libdir/win32" /usr/local/lib/codecs \
             /usr/lib/codecs /usr/local/lib/win32 /usr/lib/win32 ; do
    if test -d "$dir" ; then
      _codecsdir="$dir"
      break;
    fi;
  done
fi
# Fall back on default directory.
if test -z "$_codecsdir" ; then
  _codecsdir="$_libdir/codecs"
  mingw32 || os2 && _codecsdir="codecs"
fi


echocheck "Win32 codecs"
if test "$_win32dll" = auto ; then
  _win32dll=no
  if x86_32 && ! qnx; then
    _win32dll=yes
  fi
fi
_win32_emulation=no
if test "$_win32dll" = yes ; then
  def_win32dll='#define CONFIG_WIN32DLL 1'
  if ! win32 ; then
    def_win32_loader='#define WIN32_LOADER 1'
    _win32_emulation=yes
  else
    extra_ldflags="$extra_ldflags -ladvapi32 -lole32"
    res_comment="using native windows"
  fi
  codecmodules="win32 $codecmodules"
else
  def_win32dll='#undef CONFIG_WIN32DLL'
  def_win32_loader='#undef WIN32_LOADER'
  nocodecmodules="win32 $nocodecmodules"
fi
echores "$_win32dll"


echocheck "XAnim codecs"
if test "$_xanim" = auto ; then
  _xanim=no
  res_comment="dynamic loader support needed"
  if test "$_dl" = yes ; then
    _xanim=yes
  fi
fi
if test "$_xanim" = yes ; then
  def_xanim='#define CONFIG_XANIM 1'
  codecmodules="xanim $codecmodules"
else
  def_xanim='#undef CONFIG_XANIM'
  nocodecmodules="xanim $nocodecmodules"
fi
echores "$_xanim"


echocheck "RealPlayer codecs"
if test "$_real" = auto ; then
  _real=no
  res_comment="dynamic loader support needed"
  if test "$_dl" = yes || test "$_win32dll" = yes &&
     (linux || freebsd || netbsd || openbsd || dragonfly || darwin || win32 || os2) ; then
    _real=yes
  fi
fi
if test "$_real" = yes ; then
  def_real='#define CONFIG_REALCODECS 1'
  codecmodules="real $codecmodules"
else
  def_real='#undef CONFIG_REALCODECS'
  nocodecmodules="real $nocodecmodules"
fi
echores "$_real"


echocheck "QuickTime codecs"
_qtx_emulation=no
def_qtx_win32='#undef CONFIG_QTX_CODECS_WIN32'
if test "$_qtx" = auto ; then
  test "$_win32dll" = yes || test "$quicktime" = yes && _qtx=yes
fi
if test "$_qtx" = yes ; then
    def_qtx='#define CONFIG_QTX_CODECS 1'
    win32 && _qtx_codecs_win32=yes && def_qtx_win32='#define CONFIG_QTX_CODECS_WIN32 1'
    codecmodules="qtx $codecmodules"
    darwin || win32 || _qtx_emulation=yes
else
    def_qtx='#undef CONFIG_QTX_CODECS'
    nocodecmodules="qtx $nocodecmodules"
fi
echores "$_qtx"

echocheck "Nemesi Streaming Media libraries"
if test "$_nemesi" = auto  && test "$networking" = yes ; then
    _nemesi=no
    if $_pkg_config libnemesi --atleast-version=0.6.3 ; then
        extra_cflags="$extra_cflags $($_pkg_config --cflags libnemesi)"
        extra_ldflags="$extra_ldflags $($_pkg_config --libs libnemesi)"
        _nemesi=yes
    fi
fi
if test "$_nemesi" = yes; then
    _native_rtsp=no
    def_nemesi='#define CONFIG_LIBNEMESI 1'
    inputmodules="nemesi $inputmodules"
else
    _native_rtsp="$networking"
    _nemesi=no
    def_nemesi='#undef CONFIG_LIBNEMESI'
    noinputmodules="nemesi $noinputmodules"
fi
echores "$_nemesi"

echocheck "LIVE555 Streaming Media libraries"
if test "$_live" = auto  && test "$networking" = yes ; then
  cat > $TMPCPP << EOF
#define RTSPCLIENT_SYNCHRONOUS_INTERFACE 1
#include <liveMedia.hh>
#if (LIVEMEDIA_LIBRARY_VERSION_INT < 1141257600)
#error Please upgrade to version 2006.03.03 or later of the "LIVE555 Streaming Media" libraries - available from <www.live555.com/liveMedia/>
#endif
#include "BasicUsageEnvironment.hh"
int main(void) { RTSPClient::createNew(*BasicUsageEnvironment::createNew(*BasicTaskScheduler::createNew()), 0, "", 0); return 0; }
EOF

  _live=no
  for I in $extra_cflags "-I$_libdir/live" "-I/usr/lib/live" "-I/usr/lib64/live" "-I/usr/local/live" "-I/usr/local/lib/live" ; do
    _livelibdir=$(echo $I| sed s/-I//)
    inc_tmp="-I$_livelibdir/liveMedia/include \
             -I$_livelibdir/UsageEnvironment/include \
             -I$_livelibdir/BasicUsageEnvironment/include \
             -I$_livelibdir/groupsock/include"
    ld_tmp="$_livelibdir/liveMedia/libliveMedia.a \
            $_livelibdir/BasicUsageEnvironment/libBasicUsageEnvironment.a \
            $_livelibdir/UsageEnvironment/libUsageEnvironment.a \
            $_livelibdir/groupsock/libgroupsock.a \
            -lstdc++ $ld_sock"
    test -e "$_livelibdir/BasicUsageEnvironment/libBasicUsageEnvironment.a" &&
        cxx_check $inc_tmp $ld_tmp &&
      extra_ldflags="$ld_tmp $extra_ldflags" &&
      extra_cxxflags="$inc_tmp" &&
      _live=yes && break
  done
  if test "$_live" != yes ; then
      for ld_tmp in "-lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment -lstdc++" "-lliveMedia_pic -lgroupsock_pic -lBasicUsageEnvironment_pic -lUsageEnvironment_pic -lstdc++" ; do
          inc_tmp="-I/usr/include/liveMedia -I/usr/include/UsageEnvironment -I/usr/include/BasicUsageEnvironment -I/usr/include/groupsock"
          cxx_check $inc_tmp $ld_tmp && _live_dist=yes && break
      done
  fi
fi
if test "$_live" = yes && test "$networking" = yes; then
  test $_livelibdir && res_comment="using $_livelibdir"
  def_live='#define CONFIG_LIVE555 1'
 inputmodules="live555 $inputmodules"
elif test "$_live_dist" = yes && test "$networking" = yes; then
  res_comment="using distribution version"
  _live="yes"
  def_live='#define CONFIG_LIVE555 1'
  extra_ldflags="$extra_ldflags $ld_tmp"
  extra_cxxflags="$inc_tmp"
 inputmodules="live555 $inputmodules"
else
  _live=no
  def_live='#undef CONFIG_LIVE555'
  noinputmodules="live555 $noinputmodules"
fi
echores "$_live"

echocheck "RTMPDump Streaming Media library"
if test "$_librtmp" = auto  && test "$networking" = yes ; then
  statement_check librtmp/rtmp.h 'RTMP_Socket(NULL)' -lrtmp &&
    _librtmp=yes && extra_ldflags="$extra_ldflags -lrtmp"
  if test "$_librtmp" != yes && $_pkg_config --exists librtmp ; then
    inc_tmp=$($_pkg_config --cflags librtmp)
    ld_tmp=$($_pkg_config --libs librtmp)
    cc_check $inc_tmp $ld_tmp && _librtmp=yes &&
      extra_ldflags="$extra_ldflags $ld_tmp" &&
      extra_cflags="$extra_cflags $inc_tmp"
  fi
fi
if test "$_librtmp" = yes && test "$networking" = yes; then
  nolibrtmp=no
  def_librtmp='#define CONFIG_LIBRTMP 1'
  inputmodules="librtmp $inputmodules"
else
  nolibrtmp=yes
  _librtmp=no
  def_librtmp='#define CONFIG_LIBRTMP 0'
  noinputmodules="librtmp $noinputmodules"
  libavprotocols=$(filter_out_component protocol 'LIBRTMP LIBRTMPE LIBRTMPS LIBRTMPT LIBRTMPTE')
fi
echores "$_librtmp"


echocheck "FFmpeg"
test -d ffmpeg/libavutil ||
  die "MPlayer will not compile without libavutil in the source tree."
ffmpeg=no
if test "$ffmpeg_a" = auto ; then
  test -d ffmpeg/libavutil && ffmpeg_a=yes && ffmpeg=yes
elif test "$ffmpeg_so" = auto ; then
  ffmpeg_so=no
  if $_pkg_config --exists libavutil ; then
    inc_ffmpeg=$($_pkg_config --cflags libswscale libavformat libavcodec libavutil)
    ld_tmp=$($_pkg_config --libs libswscale libavformat libavcodec libavutil)
    header_check libavutil/avutil.h $inc_ffmpeg $ld_tmp &&
      extra_ldflags="$extra_ldflags $ld_tmp" && ffmpeg_so=yes && ffmpeg=yes
  elif header_check libavutil/avutil.h -lswscale -lavformat -lavcodec -lavutil ; then
    extra_ldflags="$extra_ldflags -lswscale -lavformat -lavcodec -lavutil"
    ffmpeg_so=yes
    ffmpeg=yes
  fi
fi

if test "$ffmpeg" = yes; then
  def_ffmpeg='#define CONFIG_FFMPEG 1'
  if test "$ffmpeg_a" = yes ; then
    codecmodules="ffmpeg(internal) $codecmodules"
    def_ffmpeg_a='#define CONFIG_FFMPEG_A 1'
  elif test "$ffmpeg_so" = yes ; then
    codecmodules="ffmpeg $codecmodules"
    def_ffmpeg_so='#define CONFIG_FFMPEG_SO 1'
    res_comment="using shared FFmpeg, but static FFmpeg is recommended"
  fi
else
  def_ffmpeg='#undef CONFIG_FFMPEG'
  def_ffmpeg_a='#undef CONFIG_FFMPEG_A'
  def_ffmpeg_so='#undef CONFIG_FFMPEG_SO'
  nocodecmodules="ffmpeg $nocodecmodules"
fi
test "$_vf_lavfi" = yes && def_vf_lavfi='#define CONFIG_VF_LAVFI 1'|| libavfilters=''
test "$_libavcodec_mpegaudio_hp" = yes &&
  def_libavcodec_mpegaudio_hp='#define CONFIG_MPEGAUDIO_HP 1' &&
  mak_libavcodec_mpegaudio_hp='CONFIG_MPEGAUDIO_HP = yes'
echores "$ffmpeg"


echocheck "libpostproc"
if test "$postproc" = auto ; then
  postproc=no
  if test "$ffmpeg_a" = yes && test -d ffmpeg/libpostproc ; then
    postproc=yes
  elif $_pkg_config --exists libpostproc ; then
    inc_postproc=$($_pkg_config --cflags libpostproc)
    ld_tmp=$($_pkg_config --libs libpostproc)
    header_check libpostproc/postprocess.h $inc_postproc $ld_tmp &&
      extra_ldflags="$extra_ldflags $ld_tmp" && postproc=yes
  elif header_check libpostproc/postprocess.h -lpostproc ; then
    extra_ldflags="$extra_ldflags -lpostproc"
    postproc=yes
  fi
fi
if test "$postproc" = yes; then
  def_postproc='#define CONFIG_POSTPROC 1'
else
  def_postproc='#undef CONFIG_POSTPROC'
fi
echores "$postproc"


echocheck "libopencore_amr narrowband"
if test "$_libopencore_amrnb" = auto ; then
  _libopencore_amrnb=no
  statement_check opencore-amrnb/interf_dec.h 'Decoder_Interface_init()' -lopencore-amrnb && _libopencore_amrnb=yes
  if test "$ffmpeg_a" != yes ; then
    _libopencore_amrnb=no
    res_comment="ffmpeg (static) is required by libopencore_amrnb, sorry"
  fi
fi
if test "$_libopencore_amrnb" = yes ; then
  _libopencore_amr=yes
  extra_ldflags="$extra_ldflags -lopencore-amrnb"
  def_libopencore_amrnb='#define CONFIG_LIBOPENCORE_AMRNB 1'
  libavdecoders="$libavdecoders LIBOPENCORE_AMRNB_DECODER"
  libavencoders="$libavencoders LIBOPENCORE_AMRNB_ENCODER"
  codecmodules="libopencore_amrnb $codecmodules"
else
  def_libopencore_amrnb='#define CONFIG_LIBOPENCORE_AMRNB 0'
  nocodecmodules="libopencore_amrnb $nocodecmodules"
fi
echores "$_libopencore_amrnb"


echocheck "libopencore_amr wideband"
if test "$_libopencore_amrwb" = auto ; then
  _libopencore_amrwb=no
  statement_check opencore-amrwb/dec_if.h 'D_IF_init()' -lopencore-amrwb && _libopencore_amrwb=yes
  if test "$ffmpeg_a" != yes ; then
    _libopencore_amrwb=no
    res_comment="ffmpeg (static) is required by libopencore_amrwb, sorry"
  fi
fi
if test "$_libopencore_amrwb" = yes ; then
  _libopencore_amr=yes
  extra_ldflags="$extra_ldflags -lopencore-amrwb"
  def_libopencore_amrwb='#define CONFIG_LIBOPENCORE_AMRWB 1'
  libavdecoders="$libavdecoders LIBOPENCORE_AMRWB_DECODER"
  codecmodules="libopencore_amrwb $codecmodules"
else
  def_libopencore_amrwb='#define LIBOPENCORE_AMRWB 0'
  nocodecmodules="libopencore_amrwb $nocodecmodules"
fi
echores "$_libopencore_amrwb"


echocheck "libdv-0.9.5+"
if test "$_libdv" = auto ; then
  _libdv=no
  statement_check libdv/dv.h 'dv_encoder_new(1, 1, 1)' -ldv $ld_pthread && _libdv=yes
fi
if test "$_libdv" = yes ; then
  def_libdv='#define CONFIG_LIBDV095 1'
  extra_ldflags="$extra_ldflags -ldv"
  codecmodules="libdv $codecmodules"
else
  def_libdv='#undef CONFIG_LIBDV095'
  nocodecmodules="libdv $nocodecmodules"
fi
echores "$_libdv"

echocheck "CrystalHD"
if test "$crystalhd" = auto ; then
   crystalhd=no
   statement_check_broken libcrystalhd/bc_dts_types.h libcrystalhd/libcrystalhd_if.h 'DtsCrystalHDVersion(0, 0)' -lcrystalhd && crystalhd=yes
fi

if test "$crystalhd" = yes ; then
   extra_ldflags="$extra_ldflags -lcrystalhd"
   def_crystalhd="#define CONFIG_CRYSTALHD 1"
   codecmodules="crystalhd $codecmodules"
else
   def_crystalhd="#define CONFIG_CRYSTALHD 0"
   nocodecmodules="crystalhd $nocodecmodules"
   libavdecoders=$(filter_out_component decoder '[A-Z0-9]*_CRYSTALHD')
fi
echores "$crystalhd"

echocheck "Xvid"
if test "$_xvid" = auto ; then
  _xvid=no
  for ld_tmp in "-lxvidcore" "-lxvidcore $ld_pthread" ; do
    statement_check xvid.h 'xvid_global(0, 0, 0, 0)' $ld_tmp &&
      extra_ldflags="$extra_ldflags $ld_tmp" && _xvid=yes && break
  done
fi

if test "$_xvid" = yes ; then
  def_xvid='#define CONFIG_XVID4 1'
  codecmodules="xvid $codecmodules"
else
  def_xvid='#undef CONFIG_XVID4'
  nocodecmodules="xvid $nocodecmodules"
fi
echores "$_xvid"

echocheck "Xvid two pass plugin"
if test "$_mencoder" = yes && test "$_xvid" = yes && test "$_xvid_lavc" = auto ; then
  statement_check xvid.h 'xvid_plugin_2pass2_t s; s.vbv_size = 0' && _xvid_lavc=yes
fi
if test "$_xvid_lavc" = yes ; then
  def_xvid_lavc='#define CONFIG_LIBXVID 1'
  libavencoders="$libavencoders LIBXVID_ENCODER"
else
  _xvid_lavc=no
  def_xvid_lavc='#define CONFIG_LIBXVID 0'
fi
echores "$_xvid_lavc"


echocheck "x264"
if test "$_x264" = auto && test "$_mencoder" = yes ; then
  cat > $TMPC << EOF
#include <inttypes.h>
#include <x264.h>
#if !(X264_BUILD >= 118)
#error We do not support old versions of x264. Get the latest from git.
#endif
int main(void) { x264_encoder_open((void*)0); return 0; }
EOF
  _x264=no
  for ld_x264 in "-lx264 $ld_pthread" "-lx264 $ld_pthread" ; do
    cc_check $ld_x264 && libs_mencoder="$libs_mencoder $ld_x264" && _x264=yes && break
  done
fi

if test "$_x264" = yes ; then
  def_x264='#define CONFIG_X264 1'
  codecmodules="x264 $codecmodules"
  test "$_x264_lavc" = auto && _x264_lavc=yes
  if test "$_x264_lavc" = yes ; then
    def_x264_lavc='#define CONFIG_LIBX264 1'
    libs_mplayer="$libs_mplayer $ld_x264"
    libavencoders="$libavencoders LIBX264_ENCODER"
  fi
else
  _x264_lavc=no
  def_x264='#undef CONFIG_X264'
  def_x264_lavc='#define CONFIG_LIBX264 0'
  nocodecmodules="x264 $nocodecmodules"
fi
res_comment="in FFmpeg: $_x264_lavc"
echores "$_x264"


echocheck "libdirac"
if test "$_libdirac_lavc" = auto; then
  _libdirac_lavc=no
  if test "$ffmpeg_a" != yes; then
    res_comment="ffmpeg (static) is required by libdirac, sorry"
  else
    cat > $TMPC << EOF
#include <libdirac_encoder/dirac_encoder.h>
#include <libdirac_decoder/dirac_parser.h>
int main(void)
{
    dirac_encoder_context_t enc_ctx;
    dirac_decoder_t *dec_handle;
    dirac_encoder_context_init(&enc_ctx, VIDEO_FORMAT_SD_576I50);
    dec_handle = dirac_decoder_init(0);
    if (dec_handle)
        dirac_decoder_close(dec_handle);
    return 0;
}
EOF
    if $_pkg_config --exists dirac ; then
      inc_dirac=$($_pkg_config --silence-errors --cflags dirac)
      ld_dirac=$($_pkg_config --silence-errors --libs dirac)
      cc_check $inc_dirac $ld_dirac        &&
      _libdirac_lavc=yes                   &&
      extra_cflags="$extra_cflags $inc_dirac" &&
      extra_ldflags="$extra_ldflags $ld_dirac"
    fi
  fi
fi
if test "$_libdirac_lavc" = yes ; then
  def_libdirac_lavc='#define CONFIG_LIBDIRAC 1'
  libavencoders="$libavencoders LIBDIRAC_ENCODER"
  libavdecoders="$libavdecoders LIBDIRAC_DECODER"
  codecmodules="libdirac $codecmodules"
else
  def_libdirac_lavc='#define CONFIG_LIBDIRAC 0'
  nocodecmodules="libdirac $nocodecmodules"
fi
echores "$_libdirac_lavc"


echocheck "libschroedinger"
if test "$_libschroedinger_lavc" = auto ; then
  _libschroedinger_lavc=no
  if test "$ffmpeg_a" != yes; then
    res_comment="ffmpeg (static) is required by libschroedinger, sorry"
  else
    cat > $TMPC << EOF
#include <schroedinger/schro.h>
int main(void) { schro_init(); return SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY; }
EOF
    if $_pkg_config --exists schroedinger-1.0 ; then
      inc_schroedinger=$($_pkg_config --silence-errors --cflags schroedinger-1.0)
      ld_schroedinger=$($_pkg_config --silence-errors --libs schroedinger-1.0)
      cc_check $inc_schroedinger $ld_schroedinger   &&
      _libschroedinger_lavc=yes                     &&
      extra_cflags="$extra_cflags $inc_schroedinger"   &&
      extra_ldflags="$extra_ldflags $ld_schroedinger"
    fi
  fi
fi
if test "$_libschroedinger_lavc" = yes ; then
  def_libschroedinger_lavc='#define CONFIG_LIBSCHROEDINGER 1'
  libavencoders="$libavencoders LIBSCHROEDINGER_ENCODER"
  libavdecoders="$libavdecoders LIBSCHROEDINGER_DECODER"
  codecmodules="libschroedinger $codecmodules"
else
  def_libschroedinger_lavc='#define CONFIG_LIBSCHROEDINGER 0'
  nocodecmodules="libschroedinger $nocodecmodules"
fi
echores "$_libschroedinger_lavc"

echocheck "libvpx"
if test "$_libvpx_lavc" = auto; then
  _libvpx_lavc=no
  if test "$ffmpeg_a" != yes; then
    res_comment="dynamic linking to libvpx is irrelevant when using dynamic FFmpeg"
  else
    cat > $TMPC << EOF
#include <vpx/vpx_encoder.h>
#include <vpx/vpx_decoder.h>
#include <vpx/vp8dx.h>
#include <vpx/vp8cx.h>
struct vpx_codec_ctx decoder;
int main(void) {
  vpx_codec_dec_init(NULL, &vpx_codec_vp8_dx_algo, NULL, 0);
  vpx_codec_enc_init(NULL, &vpx_codec_vp8_dx_algo, NULL, 0);
  return VPX_CQ;
}
EOF
    cc_check -lvpx && _libvpx_lavc=yes && extra_ldflags="$extra_ldflags -lvpx"
  fi
fi
if test "$_libvpx_lavc" = yes ; then
  def_libvpx_lavc='#define CONFIG_LIBVPX 1'
  libavdecoders="$libavdecoders LIBVPX_VP8_DECODER"
  libavencoders="$libavencoders LIBVPX_VP8_ENCODER"
  codecmodules="libvpx $codecmodules"
else
  def_libvpx_lavc='#define CONFIG_LIBVPX 0'
  nocodecmodules="libvpx $nocodecmodules"
fi
echores "$_libvpx_lavc"

echocheck "libnut"
if test "$_libnut" = auto ; then
  _libnut=no
   statement_check libnut.h 'nut_context_tt * nut; nut_error(0)' -lnut && _libnut=yes
fi

if test "$_libnut" = yes ; then
  def_libnut='#define CONFIG_LIBNUT 1'
  extra_ldflags="$extra_ldflags -lnut"
else
  def_libnut='#undef CONFIG_LIBNUT'
fi
echores "$_libnut"

#check must be done after FFmpeg one
echocheck "zr"
if test "$_zr" = auto && test "$ffmpeg_a" = yes ; then
  #36067's seem to identify themselves as 36057PQC's, so the line
  #below should work for 36067's and 36057's.
  if grep -q -s -e "Multimedia video controller: Zoran Corporation ZR36057" /proc/pci ; then
    _zr=yes
  else
    _zr=no
  fi
fi
if test "$_zr" = yes ; then
    def_zr='#define CONFIG_ZR 1'
    vomodules="zr zr2 $vomodules"
    mplayer_encoders="$mplayer_encoders MJPEG_ENCODER"
else
    def_zr='#undef CONFIG_ZR'
    novomodules="zr zr2 $novomodules"
fi
echores "$_zr"


echocheck "libmp3lame"
def_mp3lame='#undef CONFIG_MP3LAME'
def_mp3lame_lavc="#define CONFIG_LIBMP3LAME 0"
def_mp3lame_preset='#undef CONFIG_MP3LAME_PRESET'
def_mp3lame_preset_medium='#undef CONFIG_MP3LAME_PRESET_MEDIUM'
if test "$_mp3lame" = auto && test "$_mencoder" = yes; then
  _mp3lame=no
  statement_check lame/lame.h 'lame_set_VBR_quality(NULL, 0)' -lmp3lame &&
    _mp3lame=yes && _mp3lame_lavc=yes
fi
if test "$_mp3lame" = yes ; then
  def_mp3lame="#define CONFIG_MP3LAME 1"
  ld_mp3lame=-lmp3lame
  libs_mencoder="$libs_mencoder $ld_mp3lame"
  statement_check lame/lame.h 'lame_set_preset(NULL, STANDARD_FAST)' $ld_mp3lame && def_mp3lame_preset="#define CONFIG_MP3LAME_PRESET 1"
  statement_check lame/lame.h 'lame_set_preset(NULL,   MEDIUM_FAST)' $ld_mp3lame && def_mp3lame_preset_medium="#define CONFIG_MP3LAME_PRESET_MEDIUM 1"
  if test "$_mp3lame_lavc" = yes ; then
    def_mp3lame_lavc="#define CONFIG_LIBMP3LAME 1"
    libavencoders="$libavencoders LIBMP3LAME_ENCODER"
    libs_mplayer="$libs_mplayer $ld_mp3lame"
  fi
else
  _mp3lame_lavc=no
fi
res_comment="in FFmpeg: $_mp3lame_lavc"
echores "$_mp3lame"


echocheck "mencoder"
if test "$_mencoder" = no ; then
  # mpeg1video for vf_lavc, snow for vf_uspp / vf_mcdeint,
  libavencoders="$mplayer_encoders MPEG1VIDEO_ENCODER SNOW_ENCODER"
fi
echores "$_mencoder"


echocheck "UnRAR executable"
if test "$_unrar_exec" = auto ; then
    _unrar_exec="yes"
    mingw32 && _unrar_exec="no"
fi
if test "$_unrar_exec" = yes ; then
    def_unrar_exec='#define CONFIG_UNRAR_EXEC 1'
else
    def_unrar_exec='#undef CONFIG_UNRAR_EXEC'
fi
echores "$_unrar_exec"

echocheck "TV interface"
if test "$_tv" = yes ; then
  def_tv='#define CONFIG_TV 1'
  inputmodules="tv $inputmodules"
else
  noinputmodules="tv $noinputmodules"
  def_tv='#undef CONFIG_TV'
fi
echores "$_tv"


if freebsd || netbsd || openbsd || dragonfly || bsdos ; then
  echocheck "*BSD BT848 bt8xx header"
  _ioctl_bt848_h=no
  for file in "machine/ioctl_bt848.h" \
            "dev/bktr/ioctl_bt848.h" \
            "dev/video/bktr/ioctl_bt848.h" \
            "dev/ic/bt8xx.h" ; do
    cat > $TMPC <<EOF
#include <sys/types.h>
#include <sys/ioctl.h>
#include <$file>
int main(void) { ioctl(0, TVTUNER_GETFREQ, 0); return 0; }
EOF
    if cc_check ; then
     _ioctl_bt848_h=yes
     _ioctl_bt848_h_name="$file"
     break;
    fi
  done
  if test "$_ioctl_bt848_h" = yes ; then
    def_ioctl_bt848_h_name="#define IOCTL_BT848_H_NAME <$_ioctl_bt848_h_name>"
    res_comment="using $_ioctl_bt848_h_name"
  else
    def_ioctl_bt848_h_name="#undef IOCTL_BT848_H_NAME"
  fi
  echores "$_ioctl_bt848_h"

  echocheck "*BSD ioctl_meteor.h"
  _ioctl_meteor_h=no
  for ioctl_meteor_h_path in "machine/ioctl_meteor.h" "dev/bktr/ioctl_meteor.h" "dev/video/bktr/ioctl_meteor.h" ; do
    statement_check_broken "sys/types.h" "$ioctl_meteor_h_path" 'ioctl(0, METEORSINPUT, 0)' &&
      _ioctl_meteor_h=yes && break
  done
  if test "$_ioctl_meteor_h" = yes ; then
    def_ioctl_meteor_h_name="#define IOCTL_METEOR_H_NAME <$ioctl_meteor_h_path>"
    res_comment="using $ioctl_meteor_h_path"
  else
    def_ioctl_meteor_h_name="#undef IOCTL_METEOR_H_NAME"
  fi
  echores "$_ioctl_meteor_h"

  echocheck "*BSD BrookTree 848 TV interface"
  if test "$_tv_bsdbt848" = auto ; then
    _tv_bsdbt848=no
    if test "$_tv" = yes ; then
      cat > $TMPC <<EOF
#include <sys/types.h>
$def_ioctl_meteor_h_name
$def_ioctl_bt848_h_name
#ifdef IOCTL_METEOR_H_NAME
#include IOCTL_METEOR_H_NAME
#endif
#ifdef IOCTL_BT848_H_NAME
#include IOCTL_BT848_H_NAME
#endif
int main(void) {
 ioctl(0, METEORSINPUT, 0);
 ioctl(0, TVTUNER_GETFREQ, 0);
 return 0;
}
EOF
      cc_check && _tv_bsdbt848=yes
    fi
  fi
  if test "$_tv_bsdbt848" = yes ; then
    def_tv_bsdbt848='#define CONFIG_TV_BSDBT848 1'
    inputmodules="tv-bsdbt848 $inputmodules"
  else
    def_tv_bsdbt848='#undef CONFIG_TV_BSDBT848'
    noinputmodules="tv-bsdbt848 $noinputmodules"
  fi
  echores "$_tv_bsdbt848"
fi #if freebsd || netbsd || openbsd || dragonfly || bsdos


echocheck "DirectShow TV interface"
if test "$_tv_dshow" = auto && test "$_tv" = yes && win32 ; then
    _tv_dshow=no
    statement_check ole2.h 'void* p; CoCreateInstance((GUID*)&GUID_NULL, NULL, CLSCTX_INPROC_SERVER, &GUID_NULL, &p)' -lole32 -luuid && _tv_dshow=yes
fi
if test "$_tv_dshow" = yes ; then
  inputmodules="tv-dshow $inputmodules"
  def_tv_dshow='#define CONFIG_TV_DSHOW 1'
  extra_ldflags="$extra_ldflags -lole32 -luuid"
else
  noinputmodules="tv-dshow $noinputmodules"
  def_tv_dshow='#undef CONFIG_TV_DSHOW'
fi
echores "$_tv_dshow"


echocheck "Video 4 Linux TV interface"
if test "$_tv_v4l1" = auto && test "$_tv" = yes && linux ; then
    _tv_v4l1=no
    header_check_broken sys/time.h linux/videodev.h && _tv_v4l1=yes
fi
if test "$_tv_v4l1" = yes ; then
  _audio_input=yes
  _tv_v4l=yes
  def_tv_v4l='#define CONFIG_TV_V4L 1'
  def_tv_v4l1='#define CONFIG_TV_V4L1 1'
  inputmodules="tv-v4l $inputmodules"
else
  noinputmodules="tv-v4l1 $noinputmodules"
  def_tv_v4l='#undef CONFIG_TV_V4L'
fi
echores "$_tv_v4l1"


echocheck "Video 4 Linux 2 TV interface"
if test "$_tv_v4l2" = auto && test "$_tv" = yes ; then
    _tv_v4l2=no
    if linux ; then
        header_check_broken sys/time.h linux/videodev2.h && _tv_v4l2=yes
    else
        header_check sys/videoio.h && _tv_v4l2=yes &&
            def_sys_videoio_h='#define HAVE_SYS_VIDEOIO_H 1'
    fi
fi
if test "$_tv_v4l2" = yes ; then
  _audio_input=yes
  _tv_v4l=yes
  def_tv_v4l='#define CONFIG_TV_V4L 1'
  def_tv_v4l2='#define CONFIG_TV_V4L2 1'
  inputmodules="tv-v4l2 $inputmodules"
else
  noinputmodules="tv-v4l2 $noinputmodules"
  def_tv_v4l2='#undef CONFIG_TV_V4L2'
fi
echores "$_tv_v4l2"


echocheck "Radio interface"
if test "$_radio" = yes ; then
  def_radio='#define CONFIG_RADIO 1'
  inputmodules="radio $inputmodules"
  if test "$_alsa" != yes -a "$_ossaudio" != yes ; then
    _radio_capture=no
  fi
  if test "$_radio_capture" = yes ; then
    _audio_input=yes
    def_radio_capture="#define CONFIG_RADIO_CAPTURE 1"
  else
    def_radio_capture="#undef CONFIG_RADIO_CAPTURE"
  fi
else
  noinputmodules="radio $noinputmodules"
  def_radio='#undef CONFIG_RADIO'
  def_radio_capture="#undef CONFIG_RADIO_CAPTURE"
  _radio_capture=no
fi
echores "$_radio"
echocheck "Capture for Radio interface"
echores "$_radio_capture"


echocheck "Video 4 Linux 2 Radio interface"
if test "$_radio_v4l2" = auto && test "$_radio" = yes && linux ; then
    _radio_v4l2=no
    header_check linux/videodev2.h && _radio_v4l2=yes
fi
if test "$_radio_v4l2" = yes ; then
  def_radio_v4l2='#define CONFIG_RADIO_V4L2 1'
else
  def_radio_v4l2='#undef CONFIG_RADIO_V4L2'
fi
echores "$_radio_v4l2"


echocheck "Video 4 Linux Radio interface"
if test "$_radio_v4l" = auto && test "$_radio" = yes && linux ; then
    _radio_v4l=no
    header_check linux/videodev.h && _radio_v4l=yes
fi
if test "$_radio_v4l" = yes ; then
  def_radio_v4l='#define CONFIG_RADIO_V4L 1'
else
  def_radio_v4l='#undef CONFIG_RADIO_V4L'
fi
echores "$_radio_v4l"

if freebsd || netbsd || openbsd || dragonfly || bsdos &&
  test "$_radio" = yes && test "$_radio_bsdbt848" = auto ; then
echocheck "*BSD BrookTree 848 Radio interface"
   _radio_bsdbt848=no
    cat > $TMPC <<EOF
#include <sys/types.h>
$def_ioctl_bt848_h_name
#ifdef IOCTL_BT848_H_NAME
#include IOCTL_BT848_H_NAME
#endif
int main(void) { ioctl(0, RADIO_GETFREQ, 0); return 0; }
EOF
    cc_check && _radio_bsdbt848=yes
echores "$_radio_bsdbt848"
fi #if freebsd || netbsd || openbsd || dragonfly || bsdos && _radio && _radio_bsdbt848

if test "$_radio_bsdbt848" = yes ; then
  def_radio_bsdbt848='#define CONFIG_RADIO_BSDBT848 1'
else
  def_radio_bsdbt848='#undef CONFIG_RADIO_BSDBT848'
fi

if test "$_radio_v4l" = no && test "$_radio_v4l2" = no &&
   test "$_radio_bsdbt848" = no && test "$_radio" = yes ; then
    die "Radio driver requires BSD BT848,  V4L or V4L2!"
fi

echocheck "Video 4 Linux 2 MPEG PVR interface"
if test "$_pvr" = auto && test "$_tv_v4l2" = yes && linux ; then
 _pvr=no
  cat > $TMPC <<EOF
#include <sys/time.h>
#include <linux/videodev2.h>
int main(void) { struct v4l2_ext_controls ext; return ext.controls->value; }
EOF
  cc_check && _pvr=yes
fi
if test "$_pvr" = yes ; then
  def_pvr='#define CONFIG_PVR 1'
  inputmodules="pvr $inputmodules"
else
  noinputmodules="pvr $noinputmodules"
  def_pvr='#undef CONFIG_PVR'
fi
echores "$_pvr"


echocheck "ftp"
if test "$_ftp" = "auto" && test "$networking" = "yes" ; then
    _ftp=yes
fi
if test "$_ftp" = yes ; then
  def_ftp='#define CONFIG_FTP 1'
  inputmodules="ftp $inputmodules"
else
  noinputmodules="ftp $noinputmodules"
  def_ftp='#undef CONFIG_FTP'
fi
echores "$_ftp"

echocheck "vstream client"
if test "$_vstream" = auto ; then
  _vstream=no
  cat > $TMPC <<EOF
#include <vstream-client.h>
void vstream_error(const char *format, ... ) {}
int main(void) { vstream_start(); return 0; }
EOF
  cc_check -lvstream-client && _vstream=yes
fi
if test "$_vstream" = yes ; then
  def_vstream='#define CONFIG_VSTREAM 1'
  inputmodules="vstream $inputmodules"
  extra_ldflags="$extra_ldflags -lvstream-client"
else
  noinputmodules="vstream $noinputmodules"
  def_vstream='#undef CONFIG_VSTREAM'
fi
echores "$_vstream"


echocheck "OSD menu"
if test "$_menu" = yes ; then
    def_menu='#define CONFIG_MENU 1'
    test $_dvbin = "yes" && _menu_dvbin=yes
else
def_menu='#undef CONFIG_MENU'
    _menu_dvbin=no
fi
echores "$_menu"


echocheck "Subtitles sorting"
if test "$_sortsub" = yes ; then
    def_sortsub='#define CONFIG_SORTSUB 1'
else
    def_sortsub='#undef CONFIG_SORTSUB'
fi
echores "$_sortsub"


echocheck "XMMS inputplugin support"
if test "$_xmms" = yes ; then
  if ( xmms-config --version ) >/dev/null 2>&1 ; then
      _xmmsplugindir=$(xmms-config --input-plugin-dir)
      _xmmslibdir=$(xmms-config --exec-prefix)/lib
  else
      _xmmsplugindir=/usr/lib/xmms/Input
      _xmmslibdir=/usr/lib
  fi

  def_xmms='#define CONFIG_XMMS 1'
  if darwin ; then
     extra_ldflags="$extra_ldflags ${_xmmslibdir}/libxmms.dylib"
  else
     extra_ldflags="$extra_ldflags ${_xmmslibdir}/libxmms.so.1 -export-dynamic"
  fi
else
  def_xmms='#undef CONFIG_XMMS'
fi
echores "$_xmms"


# --------------- GUI specific tests begin -------------------
echocheck "GUI"
echo "$_gui"
if test "$_gui" = yes ; then

  # Required libraries
  if test "$ffmpeg" != yes ||
      ! echo $libavdecoders | grep -q PNG_DECODER ; then
    die "The GUI requires libavcodec with PNG support (needs zlib)."
  fi
  test "$_freetype" = no && test "$_bitmap_font" = no &&
    die "The GUI requires either FreeType or bitmap font support."
if ! win32 ; then
  _gui_gtk=yes
  test "$_x11" != yes && die "X11 support required for GUI compilation."

  echocheck "XShape extension"
  if test "$_xshape" = auto ; then
    _xshape=no
    cat > $TMPC << EOF
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <stdlib.h>
int main(void) {
  char *name = ":0.0";
  Display *wsDisplay;
  int exitvar = 0;
  int eventbase, errorbase;
  if (getenv("DISPLAY"))
    name=getenv("DISPLAY");
  wsDisplay=XOpenDisplay(name);
  if (!XShapeQueryExtension(wsDisplay, &eventbase, &errorbase))
    exitvar=1;
  XCloseDisplay(wsDisplay);
  return exitvar;
}
EOF
    cc_check -lXext && _xshape=yes
  fi
  if test "$_xshape" = yes ; then
    def_xshape='#define CONFIG_XSHAPE 1'
  else
    die "The GUI requires the X11 extension XShape (which was not found)."
  fi
  echores "$_xshape"

#Check for GTK
if test "$_gtk1" = no ; then
  #Check for GTK2 :
  echocheck "GTK+ version"

  if $_pkg_config gtk+-2.0 --exists ; then
    _gtk=$($_pkg_config gtk+-2.0 --modversion 2>/dev/null)
    extra_cflags="$extra_cflags $($_pkg_config gtk+-2.0 --cflags 2>/dev/null)"
    libs_mplayer="$libs_mplayer $($_pkg_config gtk+-2.0 --libs 2>/dev/null)"
    echores "$_gtk"

    # Check for GLIB2
    if $_pkg_config glib-2.0 --exists ; then
      echocheck "glib version"
      _glib=$($_pkg_config glib-2.0 --modversion 2>/dev/null)
      libs_mplayer="$libs_mplayer $($_pkg_config glib-2.0 --libs 2>/dev/null)"
      echores "$_glib"

      def_gui='#define CONFIG_GUI 1'
      def_gtk2='#define CONFIG_GTK2 1'
    else
      _gtk1=yes
      echo "GLIB-2 devel packages were not found, trying GTK 1.2"
    fi
  else
    echo "GTK-2 devel packages were not found, trying GTK 1.2"
    _gtk1=yes
  fi
fi

if test "$_gtk1" = yes ; then
  # Check for old GTK (1.2.x)
  echocheck "GTK version"
  if test -z "$_gtkconfig" ; then
    if ( gtk-config --version ) >/dev/null 2>&1 ; then
      _gtkconfig="gtk-config"
    elif ( gtk12-config --version ) >/dev/null 2>&1 ; then
      _gtkconfig="gtk12-config"
    else
      die "The GUI requires GTK devel packages (which were not found)."
    fi
  fi
  _gtk=$($_gtkconfig --version 2>&1)
  extra_cflags="$extra_cflags $($_gtkconfig --cflags 2>&1)"
  libs_mplayer="$libs_mplayer $($_gtkconfig --libs 2>&1)"
  echores "$_gtk (using $_gtkconfig)"

  # Check for GLIB
  echocheck "glib version"
  if test -z "$_glibconfig" ; then
    if ( glib-config --version ) >/dev/null 2>&1 ; then
      _glibconfig="glib-config"
    elif ( glib12-config --version ) >/dev/null 2>&1 ; then
      _glibconfig="glib12-config"
    else
      die "The GUI requires GLIB devel packages (which were not found)"
    fi
  fi
  _glib=$($_glibconfig --version 2>&1)
  libs_mplayer="$libs_mplayer $($_glibconfig --libs 2>&1)"
  echores "$_glib (using $_glibconfig)"

  def_gui='#define CONFIG_GUI 1'
  def_gtk2='#undef CONFIG_GTK2'
fi

else #if ! win32
  _gui_win32=yes
  libs_mplayer="$libs_mplayer -lcomdlg32 -lcomctl32 -lshell32 -lkernel32"
  def_gui='#define CONFIG_GUI 1'
  def_gtk2='#undef CONFIG_GTK2'
fi #if ! win32

else #if test "$_gui"
  def_gui='#undef CONFIG_GUI'
  def_gtk2='#undef CONFIG_GTK2'
fi #if test "$_gui"
# --------------- GUI specific tests end -------------------


if test "$_charset" != "noconv" ; then
  def_charset="#define MSG_CHARSET \"$_charset\""
else
  def_charset="#undef MSG_CHARSET"
  _charset="UTF-8"
fi

if test -n "$_charset" && test "$_charset" != "UTF-8" ; then
echocheck "iconv program"
iconv -f UTF-8 -t $_charset ${_mp_help} > /dev/null 2>> "$TMPLOG"
if test "$?" -ne 0 ; then
  echores "no"
    echo "No working iconv program found, use "
    echo "--charset=UTF-8 to continue anyway."
    echo "If you also have problems with iconv library functions use --charset=noconv."
    echo "Messages in the GTK-2 interface will be broken then."
    exit 1
else
  echores "yes"
fi
fi

#############################################################################

echocheck "automatic gdb attach"
if test "$_crash_debug" = yes ; then
  def_crash_debug='#define CONFIG_CRASH_DEBUG 1'
else
  def_crash_debug='#undef CONFIG_CRASH_DEBUG'
  _crash_debug=no
fi
echores "$_crash_debug"

echocheck "compiler support for noexecstack"
if cflag_check -Wl,-z,noexecstack ; then
  extra_ldflags="-Wl,-z,noexecstack $extra_ldflags"
  echores "yes"
else
  echores "no"
fi

echocheck "linker support for --nxcompat --no-seh --dynamicbase"
if cflag_check "-Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase" ; then
  extra_ldflags="-Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase $extra_ldflags"
  echores "yes"
else
  echores "no"
fi

echocheck "linker support for --large-address-aware"
if cflag_check "-Wl,--large-address-aware" ; then
  extra_ldflags="-Wl,--large-address-aware $extra_ldflags"
  echores "yes"
else
  echores "no"
fi

echocheck "linker support for --version-script"
if cflag_check "-Wl,--version-script,binary.ver" ; then
  extra_ldflags="-Wl,--version-script,binary.ver $extra_ldflags"
  echores "yes"
else
  echores "no"
fi


# Dynamic linking flags
# (FIXME: 'echocheck "dynamic linking"' above and modify here accordingly)
ld_dl_dynamic=''
freebsd || netbsd || openbsd || dragonfly || bsdos && ld_dl_dynamic='-rdynamic'
if test "$_real" = yes || test "$_xanim" = yes && ! win32 && ! qnx && ! darwin && ! os2 && ! sunos; then
  ld_dl_dynamic='-rdynamic'
fi

extra_ldflags="$extra_ldflags $ld_pthread $ld_dl $ld_dl_dynamic"
bsdos && extra_ldflags="$extra_ldflags -ldvd"
(netbsd || openbsd) && x86_32 && extra_ldflags="$extra_ldflags -li386"

def_debug='#undef MP_DEBUG'
test "$_debug" != "" && def_debug='#define MP_DEBUG 1'


echocheck "joystick"
def_joystick='#undef CONFIG_JOYSTICK'
if test "$_joystick" = yes ; then
  if linux || freebsd ; then
    # TODO add some check
    def_joystick='#define CONFIG_JOYSTICK 1'
  else
    _joystick="no"
    res_comment="unsupported under $system_name"
  fi
fi
echores "$_joystick"

echocheck "lirc"
if test "$_lirc" = auto ; then
  _lirc=no
  header_check lirc/lirc_client.h -llirc_client && _lirc=yes
fi
if test "$_lirc" = yes ; then
  def_lirc='#define CONFIG_LIRC 1'
  libs_mplayer="$libs_mplayer -llirc_client"
else
  def_lirc='#undef CONFIG_LIRC'
fi
echores "$_lirc"

echocheck "lircc"
if test "$_lircc" = auto ; then
  _lircc=no
  header_check lirc/lircc.h -llircc && _lircc=yes
fi
if test "$_lircc" = yes ; then
  def_lircc='#define CONFIG_LIRCC 1'
  libs_mplayer="$libs_mplayer -llircc"
else
  def_lircc='#undef CONFIG_LIRCC'
fi
echores "$_lircc"

if arm; then
# Detect Maemo development platform libraries availability (http://www.maemo.org),
# they are used when run on Nokia 770|8x0
echocheck "maemo (Nokia 770|8x0)"
if test "$_maemo" = auto ; then
  _maemo=no
  statement_check libosso.h 'osso_initialize('', '', 0, NULL)' $($_pkg_config --cflags --libs libosso 2>/dev/null) && _maemo=yes
fi
if test "$_maemo" = yes ; then
  def_maemo='#define CONFIG_MAEMO 1'
  extra_cflags="$extra_cflags $($_pkg_config --cflags libosso)"
  extra_ldflags="$extra_ldflags $($_pkg_config --libs libosso) -lXsp"
else
  def_maemo='#undef CONFIG_MAEMO'
fi
echores "$_maemo"
fi

#############################################################################

# On OS/2 nm supports only a.out. So the -Zomf compiler option to generate
# the OMF format needs to come after the 'extern symbol prefix' check, which
# uses nm.
if os2 ; then
  extra_ldflags="$extra_ldflags -Zomf -Zstack 16384 -Zbin-files -Zargs-wild"
fi

# linker paths should be the same for mencoder and mplayer
ld_tmp=""
for I in $libs_mplayer ; do
  _tmp=$(echo $I | sed -e 's/^-L.*$//')
  if test -z "$_tmp" ; then
    extra_ldflags="$extra_ldflags $I"
  else
    ld_tmp="$ld_tmp $I"
  fi
done
libs_mplayer=$ld_tmp


#############################################################################

CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE"

CXXFLAGS=" $CFLAGS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"

# This must be the last test to be performed. Any other tests following it
# could fail due to linker errors. libdvdnavmini is intentionally not linked
# against libdvdread (to permit MPlayer to use its own copy of the library).
# So any compilation using the flags added here but not linking against
# libdvdread can fail.
echocheck "DVD support (libdvdnav)"
dvdnav_internal=no
if test "$_dvdnav" = auto ; then
  if test "$_dvdread_internal" = yes ; then
    _dvdnav=yes
    dvdnav_internal=yes
    res_comment="internal"
  else
    $_dvdnavconfig --version --minilibs >> $TMPLOG 2>&1 || _dvdnav=no
  fi
fi
if test "$_dvdnav" = auto ; then
  _dvdnav=no
  _dvdnavdir=$($_dvdnavconfig --cflags)
  _dvdnavlibs=$($_dvdnavconfig --libs)
  statement_check_broken stdint.h dvdnav/dvdnav.h 'dvdnav_t *dvd = 0' $_dvdnavdir $_dvdnavlibs $ld_dl $ld_pthread && _dvdnav=yes
fi
if test "$_dvdnav" = yes ; then
  def_dvdnav='#define CONFIG_DVDNAV 1'
  if test "$dvdnav_internal" = yes ; then
    cflags_libdvdnav="-Ilibdvdnav"
    inputmodules="dvdnav(internal) $inputmodules"
  else
    extra_cflags="$extra_cflags $($_dvdnavconfig --cflags)"
    extra_ldflags="$extra_ldflags $($_dvdnavconfig --minilibs)"
    inputmodules="dvdnav $inputmodules"
  fi
else
  def_dvdnav='#undef CONFIG_DVDNAV'
  noinputmodules="dvdnav $noinputmodules"
fi
echores "$_dvdnav"

extra_ldflags="$extra_ldflags -lm"

# DO NOT ADD ANY TESTS THAT USE LINKER FLAGS HERE (like cc_check).
# Read dvdnav comment above.


# XML documentation tests
echocheck "XML catalogs"
for try_catalog in \
  /etc/sgml/catalog \
  /usr/share/xml/docbook/*/catalog.xml \
  /opt/local/share/xml/docbook-xml/*/catalog.xml \
  /opt/local/share/xml/docbook/*/catalog.xml \
  /usr/share/sgml/docbook/*/*catalog \
  /usr/share/apps/ksgmltools2/customization/en/catalog \
  /usr/share/sgml/catalog \
  /usr/local/share/sgml/catalog \
  /usr/lib/sgml/catalog \
  /usr/local/lib/sgml/catalog \
  /usr/share/docbook-xml42/catalog.xml \
  /usr/share/sgml/docbook/xmlcatalog; do
  if test -f "$try_catalog"; then
    catalog=$try_catalog
    break
  fi
done

if test -n "$catalog"; then
  echores "SGML catalog"
  catalog_opts=--catalogs
else
  echores "No SGML catalog found."
fi

echocheck "XML chunked stylesheet"
for try_chunk_xsl in \
  /usr/share/xml/docbook/*/html/chunk.xsl \
  /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
  /usr/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
  /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
  /usr/local/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
  /usr/share/docbook-xsl/html/chunk.xsl \
  /usr/share/sgml/docbook/xsl-stylesheets*/html/chunk.xsl \
  /usr/share/xml/docbook/stylesheet/nwalsh/current/html/chunk.xsl \
  /opt/local/share/xsl/docbook-xsl/html/chunk.xsl; do
  if test -f "$try_chunk_xsl"; then
    chunk_xsl=$try_chunk_xsl
    break
  fi
done

if test -z "$chunk_xsl"; then
  chunk_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl
  echores "not found, using default"
  fake_chunk_xsl=yes
else
  echores "chunk.xsl"
fi

echocheck "XML monolithic stylesheet"
for try_docbook_xsl in \
  /usr/share/xml/docbook/*/html/docbook.xsl \
  /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
  /usr/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
  /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
  /usr/local/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
  /usr/share/docbook-xsl/html/docbook.xsl \
  /usr/share/sgml/docbook/xsl-stylesheets*/html/docbook.xsl \
  /usr/share/xml/docbook/stylesheet/nwalsh/current/html/docbook.xsl \
  /opt/local/share/xsl/docbook-xsl/html/docbook.xsl; do
  if test -f "$try_docbook_xsl"; then
    docbook_xsl=$try_docbook_xsl
    break
  fi
done

if test -z "$docbook_xsl"; then
  docbook_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl
  echores "not found, using default"
else
  echores "docbook.xsl"
fi

cat > DOCS/xml/html-chunk.xsl << EOF
<?xml version="1.0" encoding="utf-8"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:import href="$chunk_xsl"/>
  <xsl:include href="html-common.xsl"/>

</xsl:stylesheet>
EOF

cat > DOCS/xml/html-single.xsl << EOF
<?xml version="1.0" encoding="utf-8"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:import href="$docbook_xsl"/>
  <xsl:include href="html-common.xsl"/>

</xsl:stylesheet>
EOF

echocheck "XML DTD"
#FIXME: This should prefer higher version numbers, not the other way around ..
for try_dtd in \
  /usr/share/xml/docbook/*/dtd/4*/docbookx.dtd \
  /usr/share/xml/docbook/*/docbookx.dtd \
  /usr/share/sgml/docbook/*/docbookx.dtd \
  /usr/share/sgml/docbook/dtd/*/docbookx.dtd \
  /usr/share/sgml/docbook/dtd/xml/*/docbookx.dtd \
  /usr/share/docbook-xml*/docbookx.dtd \
  /opt/local/share/xml/docbook*/*/docbookx.dtd \
  /usr/share/apps/ksgmltools2/docbook/*/docbookx.dtd; do
  if test -f "$try_dtd"; then
    dtd=$try_dtd
    break
  fi
done

if test -z "$dtd"; then
  dtd=/usr/share/sgml/docbook/dtd/xml/4.1.2/docbookx.dtd
  echores "not found, using default"
else
  echores "docbookx.dtd"
fi

for lang in $language_doc; do
  cat > DOCS/xml/$lang/main.xml << EOF
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "$dtd"
[
<!ENTITY bugreports.xml SYSTEM "bugreports.xml">
<!ENTITY documentation.xml SYSTEM "documentation.xml">
<!ENTITY encoding-guide.xml SYSTEM "encoding-guide.xml">
<!ENTITY faq.xml SYSTEM "faq.xml">
<!ENTITY install.xml SYSTEM "install.xml">
<!ENTITY mencoder.xml SYSTEM "mencoder.xml">
<!ENTITY ports.xml SYSTEM "ports.xml">
<!ENTITY skin.xml SYSTEM "skin.xml">
<!ENTITY usage.xml SYSTEM "usage.xml">
<!ENTITY video.xml SYSTEM "video.xml">
]>
<book id="index" lang="$lang">
&documentation.xml;
&install.xml;
&usage.xml;
&video.xml;
&ports.xml;
&mencoder.xml;
&encoding-guide.xml;
&faq.xml;
&bugreports.xml;
&skin.xml;
</book>
EOF

done

echocheck "valid XSLT processor"
if xsltproc --version > /dev/null 2>&1; then
  if test -z "$fake_chunk_xsl"; then
    echores "xsltproc"
    xsltcommand="xsltproc $catalog_opts -o"
  else
    echores "Found xsltproc but no stylesheets on your system."
    echores "xsltproc is unusable without stylesheets."
  fi
else
  echores "xsltproc not found"
fi

#############################################################################

mak_enable () {
list=$(echo $1 | toupper)
item=$(echo $2 | toupper)
nprefix=$3;
for part in $list; do
  if $(echo $item | grep -q -E "(^| )$part($| )"); then
    echo "${nprefix}_$part = yes"
  else
    echo "${nprefix}_$part = no"
  fi
done
}

#############################################################################
echo "Creating config.mak"
cat > config.mak << EOF
# -------- Generated by configure -----------

# Ensure that locale settings do not interfere with shell commands.
export LC_ALL = C

CONFIGURATION = $configuration

CHARSET = $_charset
DOC_LANGS = $language_doc
DOC_LANG_ALL = $doc_lang_all
MAN_LANGS = $language_man
MAN_LANG_ALL = $man_lang_all

CATALOG = $catalog
XMLLINT_COMMAND = xmllint --noout --noent --postvalid $catalog_opts
XSLT_COMMAND = $xsltcommand

prefix  = \$(DESTDIR)$_prefix
BINDIR  = \$(DESTDIR)$_bindir
DATADIR = \$(DESTDIR)$_datadir
LIBDIR  = \$(DESTDIR)$_libdir
MANDIR  = \$(DESTDIR)$_mandir
CONFDIR = \$(DESTDIR)$_confdir

AR      = $_ar
ARFLAGS = rc
AR_O    = \$@
AS      = $_cc
CC      = $_cc
CXX     = $_cc
HOST_CC = $_host_cc
INSTALL = $_install
INSTALLSTRIP = $_install_strip
WINDRES = $_windres

CFLAGS   = $WARNFLAGS $WARN_CFLAGS $CFLAGS $extra_cflags
CXXFLAGS = $WARNFLAGS $CXXFLAGS $extra_cflags $extra_cxxflags
CC_DEPFLAGS = $DEPFLAGS

CFLAGS_DHAHELPER         = $cflags_dhahelper
CFLAGS_LIBDVDCSS         = $cflags_libdvdcss
CFLAGS_LIBDVDCSS_DVDREAD = $cflags_libdvdcss_dvdread
CFLAGS_LIBDVDNAV         = $cflags_libdvdnav
CFLAGS_NO_OMIT_LEAF_FRAME_POINTER = $cflags_no_omit_leaf_frame_pointer
CFLAGS_STACKREALIGN      = $cflags_stackrealign
CFLAGS_SVGALIB_HELPER    = $cflags_svgalib_helper

EXTRALIBS          = $extra_ldflags $ld_static $timer_libs $extra_libs
EXTRALIBS_MPLAYER  = $libs_mplayer
EXTRALIBS_MENCODER = $libs_mencoder

MP_MSG_LIBS = $ld_iconv $ld_termcap $timer_libs

GETCH = $_getch
HELP_FILE = $_mp_help
TIMER = $_timer

EXESUF      = $_exesuf
EXESUFS_ALL = .exe

ARCH = $arch
$(mak_enable "$arch_all"    "$arch"    ARCH)
$(mak_enable "$subarch_all" "$subarch" ARCH)
$(mak_enable "$cpuexts_all" "$cpuexts" HAVE)

MENCODER = $_mencoder
MPLAYER  = $_mplayer

# operating system features which have local fallbacks
GETTIMEOFDAY = $gettimeofday
GLOB         = $glob
GLOB_WIN     = $glob_win
MMAP         = $mmap
SETENV       = $setenv
SHMEM        = $shmem
STRSEP       = $strsep
VSSCANF      = $vsscanf

# features
3DFX = $_3dfx
AA = $_aa
ALSA = $_alsa
APPLE_IR = $_apple_ir
APPLE_REMOTE = $_apple_remote
ARTS = $_arts
AUDIO_INPUT = $_audio_input
BITMAP_FONT = $_bitmap_font
BL = $_bl
CACA = $_caca
CDDA = $_cdda
CDDB = $_cddb
COREAUDIO = $_coreaudio
COREVIDEO = $_corevideo
DART = $_dart
DGA = $_dga
DIRECT3D = $_direct3d
DIRECTFB = $_directfb
DIRECTX = $_directx
DVBIN = $_dvbin
DVDNAV = $_dvdnav
DVDNAV_INTERNAL = $dvdnav_internal
DVDREAD = $_dvdread
DVDREAD_INTERNAL = $_dvdread_internal
DXR2 = $_dxr2
DXR3 = $_dxr3
ESD = $_esd
FAAC=$_faac
FAAD = $_faad
FASTMEMCPY = $_fastmemcpy
FBDEV = $_fbdev
FREETYPE = $_freetype
FTP = $_ftp
GIF = $_gif
GGI = $_ggi
GL = $_gl
GL_WIN32 = $_gl_win32
GL_X11 = $_gl_x11
GL_EGL_X11 = $_gl_egl_x11
GL_SDL = $_gl_sdl
GL_OSX = $_gl_osx
MATRIXVIEW = $matrixview
GUI = $_gui
GUI_GTK = $_gui_gtk
GUI_WIN32 = $_gui_win32
HAVE_POSIX_SELECT = $_posix_select
HAVE_SYS_MMAN_H = $_mman
HAVE_WINDOWS_H = $windows_h
IVTV = $_ivtv
JACK = $_jack
JOYSTICK = $_joystick
JPEG = $_jpeg
KAI = $_kai
KVA = $_kva
LADSPA = $_ladspa
LIBA52 = $_liba52
LIBASS = $_ass
LIBASS_INTERNAL = $ass_internal
LIBBLURAY = $_bluray
LIBBS2B = $_libbs2b
LIBDCA = $_libdca
LIBDV = $_libdv
LIBDVDCSS_INTERNAL = $_libdvdcss_internal
LIBLZO = $_liblzo
LIBMAD = $_mad
LIBMENU = $_menu
LIBMENU_DVBIN = $_menu_dvbin
LIBMPEG2 = $_libmpeg2
LIBMPEG2_INTERNAL = $_libmpeg2_internal
LIBNEMESI = $_nemesi
LIBNUT = $_libnut
LIBSMBCLIENT = $_smb
LIBTHEORA = $_theora
LIRC = $_lirc
LIVE555 = $_live
MACOSX_FINDER = $_macosx_finder
MD5SUM = $_md5sum
MGA = $_mga
MNG = $_mng
MP3LAME = $_mp3lame
MPG123 = $_mpg123
MUSEPACK = $_musepack
NAS = $_nas
NATIVE_RTSP = $_native_rtsp
NETWORKING = $networking
OPENAL = $_openal
OSS = $_ossaudio
PE_EXECUTABLE = $_pe_executable
PNG = $_png
PNM = $_pnm
POSTPROC = $postproc
PRIORITY = $_priority
PULSE = $_pulse
PVR = $_pvr
QTX_CODECS = $_qtx
QTX_CODECS_WIN32 = $_qtx_codecs_win32
QTX_EMULATION = $_qtx_emulation
QUARTZ = $_quartz
RADIO=$_radio
RADIO_CAPTURE=$_radio_capture
REAL_CODECS = $_real
S3FB = $_s3fb
SDL = $_sdl
SDL_IMAGE = $sdl_image
SPEEX = $_speex
STREAM_CACHE = $_stream_cache
SGIAUDIO = $_sgiaudio
SUNAUDIO = $_sunaudio
SVGA = $_svga
TDFXFB = $_tdfxfb
TDFXVID = $_tdfxvid
TGA = $_tga
TOOLAME=$_toolame
TV = $_tv
TV_BSDBT848 = $_tv_bsdbt848
TV_DSHOW = $_tv_dshow
TV_V4L  = $_tv_v4l
TV_V4L1 = $_tv_v4l1
TV_V4L2 = $_tv_v4l2
TWOLAME=$_twolame
UNRAR_EXEC = $_unrar_exec
V4L2 = $_v4l2
VCD = $_vcd
VDA = $_vda
VDPAU = $_vdpau
VESA = $_vesa
VIDIX = $_vidix
VIDIX_PCIDB = $_vidix_pcidb_val
VIDIX_CYBERBLADE=$_vidix_drv_cyberblade
VIDIX_IVTV=$_vidix_drv_ivtv
VIDIX_MACH64=$_vidix_drv_mach64
VIDIX_MGA=$_vidix_drv_mga
VIDIX_MGA_CRTC2=$_vidix_drv_mga_crtc2
VIDIX_NVIDIA=$_vidix_drv_nvidia
VIDIX_PM2=$_vidix_drv_pm2
VIDIX_PM3=$_vidix_drv_pm3
VIDIX_RADEON=$_vidix_drv_radeon
VIDIX_RAGE128=$_vidix_drv_rage128
VIDIX_S3=$_vidix_drv_s3
VIDIX_SH_VEU=$_vidix_drv_sh_veu
VIDIX_SIS=$_vidix_drv_sis
VIDIX_UNICHROME=$_vidix_drv_unichrome
VORBIS = $_vorbis
VSTREAM = $_vstream
WII = $_wii
WIN32DLL = $_win32dll
WIN32WAVEOUT = $_win32waveout
WIN32_EMULATION = $_win32_emulation
WINVIDIX = $winvidix
X11 = $_x11
X264 = $_x264
XANIM_CODECS = $_xanim
XMGA = $_xmga
XMMS_PLUGINS = $_xmms
XV = $_xv
XVID4 = $_xvid
XVIDIX = $xvidix
XVMC = $_xvmc
XVR100 = $_xvr100
YUV4MPEG = $_yuv4mpeg
ZR = $_zr

# FFmpeg
FFMPEG     = $ffmpeg
FFMPEG_A   = $ffmpeg_a

CONFIG_AVCODEC  = $ffmpeg_a
CONFIG_AVDEVICE = $ffmpeg_a
CONFIG_AVFILTER = $ffmpeg_a
CONFIG_AVFORMAT = $ffmpeg_a
CONFIG_AVUTIL   = $ffmpeg_a
CONFIG_POSTPROC = $ffmpeg_a
CONFIG_SWSCALE  = $ffmpeg_a
CONFIG_SWRESAMPLE = $ffmpeg_a

ASFLAGS    = \$(CFLAGS)
AS_DEPFLAGS= $DEPFLAGS
HOSTCC     = \$(HOST_CC)
HOSTCFLAGS = $HOSTCFLAGS
HOSTLIBS   = -lm
AS_O       = -o \$@
CC_O       = -o \$@
CXX_O      = -o \$@
AS_C       = -c
CC_C       = -c
CXX_C      = -c
LD         = gcc
RANLIB     = $_ranlib
YASM       = $_yasm
DEPYASM    = $_yasm
YASMFLAGS  = $YASMFLAGS

CONFIG_FFPROBE       = no
CONFIG_LAVFI_INDEV   = no
CONFIG_AMOVIE_FILTER = no
CONFIG_MOVIE_FILTER  = no
CONFIG_SCALE_FILTER  = no
CONFIG_SELECT_FILTER = no

CONFIG_STATIC = yes
SRC_PATH      = .
LIBPREF       = lib
LIBSUF        = .a
FULLNAME      = \$(NAME)\$(BUILDSUF)
LIBNAME       = \$(LIBPREF)\$(FULLNAME)\$(LIBSUF)

# These are not necessary for building, since we do not use shared libraries,
# but without them target names clash, causing Make warnings by the boatload.
SLIBNAME            = \$(SLIBPREF)\$(FULLNAME)\$(SLIBSUF)
SLIBNAME_WITH_MAJOR = \$(SLIBNAME)-42

# Some FFmpeg codecs depend on these. Enable them unconditionally for now.
CONFIG_AANDCTTABLES  = yes
CONFIG_AUDIO_FRAME_QUEUE = yes
CONFIG_DCT     = yes
CONFIG_DSPUTIL = yes
CONFIG_DWT     = yes
CONFIG_ERROR_RESILIENCE = yes
CONFIG_FRAME_THREAD_ENCODER = yes
CONFIG_FFT     = yes
CONFIG_GOLOMB  = yes
CONFIG_H264CHROMA = yes
CONFIG_H264DSP = yes
CONFIG_H264PRED= yes
CONFIG_H264QPEL= yes
CONFIG_HPELDSP = yes
CONFIG_HUFFMAN = yes
CONFIG_LPC     = yes
CONFIG_LSP     = yes
CONFIG_LZO     = yes
CONFIG_MDCT    = yes
CONFIG_MPEGAUDIODSP = yes
CONFIG_MPEGVIDEO    = yes
CONFIG_MPEGVIDEOENC = yes
CONFIG_RANGECODER   = yes
CONFIG_RDFT    = yes
CONFIG_RIFFDEC = yes
CONFIG_RIFFENC = yes
CONFIG_RTPENC_CHAIN = yes
CONFIG_SINEWIN = yes
CONFIG_VIDEODSP = yes
CONFIG_VP3DSP  = yes

$mak_hardcoded_tables
$mak_libavcodec_mpegaudio_hp
!CONFIG_LIBRTMP = $nolibrtmp
CONFIG_LIBRTMP  = $_librtmp

CONFIG_AC3DSP   = yes
CONFIG_BZLIB    = $bzlib
CONFIG_CRYSTALHD= $crystalhd
CONFIG_ENCODERS = yes
CONFIG_GPL      = yes
CONFIG_ICONV    = $_iconv
CONFIG_MLIB     = $_mlib
CONFIG_MPEGAUDIO=yes
CONFIG_MUXERS   = yes
CONFIG_NETWORK  = $networking
CONFIG_RTPDEC   = $networking
CONFIG_VF_LAVFI = $_vf_lavfi
CONFIG_VDA      = $_vda
CONFIG_VDPAU    = $_vdpau
CONFIG_XVMC     = $_xvmc
CONFIG_ZLIB     = $_zlib

HAVE_GNU_AS     = $gnu_as
HAVE_OS2THREADS = $_os2threads
HAVE_PTHREADS   = $_pthreads
HAVE_SHM        = $_shm
HAVE_W32THREADS = $_w32threads
HAVE_YASM       = $have_yasm

CONFIG_LIBXVID = $_xvid_lavc
$(mak_enable "$libavdecoders_all"  "$libavdecoders"  CONFIG)
$(mak_enable "$libavencoders_all"  "$libavencoders"  CONFIG)
$(mak_enable "$libavparsers_all"   "$libavparsers"   CONFIG)
$(mak_enable "$libavdemuxers_all"  "$libavdemuxers"  CONFIG)
$(mak_enable "$libavmuxers_all"    "$libavmuxers"    CONFIG)
$(mak_enable "$libavprotocols_all" "$libavprotocols" CONFIG)
$(mak_enable "$libavbsfs_all"      "$libavbsfs"      CONFIG)
$(mak_enable "$libavhwaccels_all"  "$libavhwaccels"  CONFIG)
$(mak_enable "$libavfilters_all"   "$libavfilters"   CONFIG)
EOF

#############################################################################

ff_config_enable () {
list=$(echo $1 | toupper)
item=$(echo $2 | toupper)
_nprefix=$4;
_defineprefix=$3;
_postfix=$5;
test -z "$_nprefix" && _nprefix='CONFIG'
for part in $list; do
  if $(echo $item | grep -q -E "(^| )$part($| )"); then
    echo "${_defineprefix}define ${_nprefix}_${part}${_postfix} 1"
  else
    echo "${_defineprefix}define ${_nprefix}_${part}${_postfix} 0"
  fi
done
}

echo "Creating config.h"
cat > $TMPH << EOF
/*----------------------------------------------------------------------------
** This file has been automatically generated by configure any changes in it
** will be lost when you run configure again.
** Instead of modifying definitions here, use the --enable/--disable options
** of the configure script! See ./configure --help for details.
*---------------------------------------------------------------------------*/

#ifndef MPLAYER_CONFIG_H
#define MPLAYER_CONFIG_H

/* Undefine this if you do not want to select mono audio (left or right)
   with a stereo MPEG layer 2/3 audio stream. The command line option
   -stereo has three possible values (0 for stereo, 1 for left-only, 2 for
   right-only), with 0 being the default.
   */
#define CONFIG_FAKE_MONO 1

/* set up max. outburst. use 131072 for TrueHD SPDIF pass-through */
#define MAX_OUTBURST 131072

/* set up audio OUTBURST. Do not change this! */
#define OUTBURST 512

/* Enable fast OSD/SUB renderer (looks ugly, but uses less CPU power) */
#undef FAST_OSD
#undef FAST_OSD_TABLE

/* Required for libdvdcss and some files below stream/. */
#ifndef O_BINARY
#define O_BINARY 0
#endif

/* Define this to enable MPEG-1/2 image postprocessing in libmpeg2 */
#define MPEG12_POSTPROC 1
#define ATTRIBUTE_ALIGNED_MAX 16



#define CONFIGURATION "$configuration"

#define MPLAYER_DATADIR "$_datadir"
#define MPLAYER_CONFDIR "$_confdir"
#define MPLAYER_LIBDIR "$_libdir"

/* definitions needed by included libraries */
/* libmpeg2 */
$def_fast_inttypes
/* libdvdcss */
#define HAVE_ERRNO_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_UNISTD_H 1
$def_broken_mkdir
$def_cdio
$def_cdrom
$def_dvd
$def_dvd_bsd
$def_dvd_darwin
$def_dvd_linux
$def_dvd_openbsd
$def_dvdcss
$def_dvdio
$def_hpux_scsi_h
$def_sol_scsi_h
$def_sys_uio_h

/* libdvdcss + libdvdread */
#define HAVE_LIMITS_H 1
/* libdvdread */
#define HAVE_DLFCN_H 1
#define HAVE_MEMCPY 1
#define STDC_HEADERS 1
/* libdvdnav */
#define READ_CACHE_TRACE 0


/* system headers */
$def_alloca_h
$def_altivec_h
$def_malloc_h
$def_mman_h
$def_mman_has_map_failed
$def_soundcard_h
$def_sys_soundcard_h
$def_sys_sysinfo_h
$def_sys_videoio_h
$def_termios_h
$def_termios_sys_h
$def_winsock2_h


/* system functions */
$def_gethostbyname2
$def_gettimeofday
$def_glob
$def_langinfo
$def_map_memalign
$def_memalign
$def_nanosleep
$def_posix_select
$def_select
$def_setenv
$def_setmode
$def_shm
$def_strsep
$def_sysi86
$def_sysi86_iv
$def_termcap
$def_termios
$def_vsscanf


/* system-specific features */
$def_asmalign_pot
$def_builtin_expect
$def_dl
$def_dos_paths
$def_extern_asm
$def_extern_prefix
$def_iconv
$def_kstat
$def_macosx_bundle
$def_macosx_finder
$def_maemo
$def_memalign_hack
$def_path_max_check
$def_priority
$def_quicktime
$def_restrict_keyword
$def_rtc
$def_unrar_exec


/* configurable options */
$def_charset
$def_crash_debug
$def_debug
$def_dynamic_plugins
$def_fastmemcpy
$def_menu
$def_runtime_cpudetection
$def_sighandler
$def_sortsub
$def_stream_cache
$def_pthread_cache


/* CPU stuff */
#define __CPU__ $iproc
$def_armthumb
$def_bigendian
$def_ebx_available
$def_vfp_args
$(ff_config_enable "$arch_all" "$arch" "#" "ARCH")
$(ff_config_enable "$subarch_all" "$subarch" "#" "ARCH")
$(ff_config_enable "$cpuexts_all" "$cpuexts" "#" "HAVE")
$(ff_config_enable "$cpuexts_all" "$cpuexts" "#" "HAVE" "_EXTERNAL")
$(ff_config_enable "$cpuexts_all" "$cpuexts" "#" "HAVE" "_INLINE")


/* Blu-ray/DVD/VCD/CD */
#define DEFAULT_CDROM_DEVICE "$default_cdrom_device"
#define DEFAULT_DVD_DEVICE   "$default_dvd_device"
$def_bluray
$def_cddb
$def_cdparanoia
$def_dvdnav
$def_dvdread
$def_libcdio
$def_vcd


/* codec libraries */
$def_faac
$def_faad
$def_liba52
$def_libdca
$def_libdv
$def_liblzo
$def_libmpeg2
$def_libmpeg2_internal
$def_libilbc
$def_libopus
$def_mad
$def_mp3lame
$def_mp3lame_preset
$def_mp3lame_preset_medium
$def_mpg123
$def_musepack
$def_speex
$def_theora
$def_toolame
$def_tremor
$def_twolame
$def_vorbis
$def_x264
$def_xvid
$def_zlib

$def_libnut


/* binary codecs */
$def_qtx
$def_qtx_win32
$def_real
$def_win32_loader
$def_win32dll
$def_xanim
$def_xmms
#define BINARY_CODECS_PATH "$_codecsdir"
#define XMMS_INPUT_PLUGIN_DIR "$_xmmsplugindir"


/* GUI */
$def_gtk2
$def_gui
$def_xshape


/* Audio output drivers */
$def_alsa
$def_arts
$def_coreaudio
$def_dart
$def_esd
$def_esd_latency
$def_jack
$def_kai
$def_nas
$def_openal
$def_openal_h
$def_ossaudio
$def_ossaudio_devdsp
$def_ossaudio_devmixer
$def_pulse
$def_sgiaudio
$def_sunaudio
$def_win32waveout

$def_ladspa
$def_libbs2b


/* input */
$def_apple_ir
$def_apple_remote
$def_ioctl_bt848_h_name
$def_ioctl_meteor_h_name
$def_joystick
$def_lirc
$def_lircc
$def_pvr
$def_radio
$def_radio_bsdbt848
$def_radio_capture
$def_radio_v4l
$def_radio_v4l2
$def_tv
$def_tv_bsdbt848
$def_tv_dshow
$def_tv_v4l
$def_tv_v4l1
$def_tv_v4l2


/* font stuff */
$def_ass
$def_ass_internal
$def_bitmap_font
$def_enca
$def_fontconfig
$def_freetype
$def_fribidi


/* networking */
$def_closesocket
$def_ftp
$def_inet6
$def_inet_aton
$def_inet_pton
$def_live
$def_nemesi
$def_networking
$def_smb
$def_vstream


/* libvo options */
$def_3dfx
$def_aa
$def_bl
$def_caca
$def_corevideo
$def_dga
$def_dga1
$def_dga2
$def_direct3d
$def_directfb
$def_directx
$def_dvb
$def_dvbin
$def_dxr2
$def_dxr3
$def_fbdev
$def_ggi
$def_ggiwmh
$def_gif
$def_gif_4
$def_gif_tvt_hack
$def_gl
$def_gl_win32
$def_gl_x11
$def_gl_egl_android
$def_gl_egl_x11
$def_gl_sdl
$def_gl_osx
$def_matrixview
$def_ivtv
$def_jpeg
$def_kva
$def_md5sum
$def_mga
$def_mlib
$def_mng
$def_postproc
$def_png
$def_pnm
$def_quartz
$def_s3fb
$def_sdl
$def_sdl_sdl_h
$def_svga
$def_tdfxfb
$def_tdfxvid
$def_tga
$def_v4l2
$def_vdpau
$def_vesa
$def_vidix
$def_vidix_drv_cyberblade
$def_vidix_drv_ivtv
$def_vidix_drv_mach64
$def_vidix_drv_mga
$def_vidix_drv_mga_crtc2
$def_vidix_drv_nvidia
$def_vidix_drv_pm3
$def_vidix_drv_radeon
$def_vidix_drv_rage128
$def_vidix_drv_s3
$def_vidix_drv_sh_veu
$def_vidix_drv_sis
$def_vidix_drv_unichrome
$def_vidix_pfx
$def_vm
$def_wii
$def_x11
$def_xdpms
$def_xf86keysym
$def_xinerama
$def_xmga
$def_xss
$def_xv
$def_xvmc
$def_xvr100
$def_yuv4mpeg
$def_zr


/* FFmpeg */
#define av_restrict restrict

$def_ffmpeg
$def_ffmpeg_a
$def_ffmpeg_so

#define CONFIG_DECODERS 1
#define CONFIG_ENCODERS 1
#define CONFIG_DEMUXERS 1
#define CONFIG_MUXERS 1
$def_rtpdec

/* selectable features */
$def_hardcoded_tables
$def_libavcodec_mpegaudio_hp
$def_network
$def_vf_lavfi

/* headers */
$def_arpa_inet_h
$def_direct_h
$def_io_h
$def_poll_h
$def_windows_h

/* external libraries */
$def_bzlib
$def_crystalhd
$def_faac_lavc
$def_libdirac_lavc
$def_libgsm
$def_libopencore_amrnb
$def_libopencore_amrwb
$def_libopenjpeg
$def_librtmp
$def_libschroedinger_lavc
$def_mp3lame_lavc
$def_x264_lavc
$def_xvid_lavc

/* system features */
$def_fast_64bit
$def_fast_unaligned
$def_gnu_as
$def_ibm_asm
$def_local_aligned_8
$def_local_aligned_16
$def_os2threads
$def_pic
$def_pthreads
$def_socklen_t
$def_struct_addrinfo
$def_struct_ipv6_mreq
$def_struct_sockaddr_in6
$def_struct_sockaddr_sa_len
$def_struct_sockaddr_storage
$def_threads
$def_w32threads
$def_xform_asm
$def_xmm_clobbers
$def_yasm

/* system functions */
$def_aligned_malloc
$def_bswap
$def_dcbzl
$def_atanf
$def_atan2f
$def_cbrt
$def_cbrtf
$def_cosf
$def_expf
$def_exp2
$def_exp2f
$def_getaddrinfo
$def_isinf
$def_isnan
$def_ldexpf
$def_llrint
$def_llrintf
$def_log2
$def_log2f
$def_log10f
$def_lrint
$def_lrintf
$def_mkstemp
$def_mmap
$def_posix_memalign
$def_powf
$def_mprotect
$def_rint
$def_round
$def_roundf
$def_sinf
$def_trunc
$def_truncf

#define HAVE_INCOMPATIBLE_LIBAV_ABI 0
#define HAVE_PRAGMA_DEPRECATED 1
#define CONFIG_AUDIO_FLOAT 0
#define CONFIG_AVCODEC 1
#define CONFIG_AVSERVER 0
#define CONFIG_DXVA2 0
#define CONFIG_FASTDIV 0
#define CONFIG_FFSERVER 0
#define CONFIG_FTRAPV 0
#define CONFIG_GNUTLS 0
#define CONFIG_GPL 1
#define CONFIG_GRAY 0
#define CONFIG_LIBMODPLUG 0
#define CONFIG_LIBVORBIS 0
#define CONFIG_MEMORY_POISONING 0
#define CONFIG_OPENSSL 0
#define CONFIG_POWERPC_PERF 0
/* For now prefer speed over avoiding potential invalid reads */
#define CONFIG_SAFE_BITSTREAM_READER 0
#define CONFIG_SHARED 0
#define CONFIG_SMALL 0
#define CONFIG_SWSCALE_ALPHA 1
#define CONFIG_VAAPI 0

#define HAVE_ALIGNED_STACK 1
#define HAVE_ASM_MOD_Q 1
#define HAVE_ATOMICS_GCC 1
#define HAVE_ATOMICS_NATIVE 1
#define HAVE_ATTRIBUTE_PACKED 1
#define HAVE_GETHRTIME 0
#define HAVE_INLINE_ASM 1
#define HAVE_ISATTY 0
#define HAVE_LDBRX 0
#define HAVE_LOCALTIME_R 0
#define HAVE_MAPVIEWOFFILE 0
#define HAVE_MIPSDSPR1 0
#define HAVE_MIPSFPU 0
#define HAVE_MM_EMPTY 0
#define HAVE_PTHREAD_CANCEL 0
#define HAVE_PPC4XX 0
#define HAVE_RDTSC 0
#define HAVE_STRERROR_R 0
#define HAVE_STRPTIME 0
#define HAVE_STRUCT_POLLFD 0
#define HAVE_SYMVER_ASM_LABEL 0
#define HAVE_SYMVER_GNU_ASM 0
#define HAVE_SYNC_SYNCHRONIZE 1
#define HAVE_SYS_SELECT_H 0
#define HAVE_VIRTUALALLOC 0

/* Some FFmpeg codecs depend on these. Enable them unconditionally for now. */
#define CONFIG_AANDCTTABLES 1
#define CONFIG_AUDIO_FRAME_QUEUE 1
#define CONFIG_DCT 1
#define CONFIG_DSPUTIL 1
#define CONFIG_DWT 1
#define CONFIG_ERROR_RESILIENCE 1
#define CONFIG_FRAME_THREAD_ENCODER 1
#define CONFIG_FFT 1
#define CONFIG_GOLOMB 1
#define CONFIG_H264CHROMA 1
#define CONFIG_H264DSP 1
#define CONFIG_H264PRED 1
#define CONFIG_H264QPEL 1
#define CONFIG_HUFFMAN 1
#define CONFIG_LPC 1
#define CONFIG_LZO 1
#define CONFIG_MDCT 1
#define CONFIG_MPEGVIDEO 1
#define CONFIG_RDFT 1
#define CONFIG_RIFFDEC 1
#define CONFIG_RIFFENC 1
#define CONFIG_VIDEODSP 1

/* Use these registers in FFmpeg x86 inline asm. No proper detection yet. */
#ifndef MP_DEBUG
#define HAVE_EBP_AVAILABLE 1
#else
#define HAVE_EBP_AVAILABLE 0
#endif

#define FFMPEG_CONFIGURATION "--enable-gpl --enable-postproc"
#define FFMPEG_LICENSE "GPL version 2 or later"

#define LIBAV_CONFIGURATION FFMPEG_CONFIGURATION
#define LIBAV_LICENSE FFMPEG_LICENSE

$(ff_config_enable "$libavdecoders_all"  "$libavdecoders" "#")
$(ff_config_enable "$libavencoders_all"  "$libavencoders" "#")
$(ff_config_enable "$libavparsers_all"   "$libavparsers" "#")
$(ff_config_enable "$libavdemuxers_all"  "$libavdemuxers" "#")
$(ff_config_enable "$libavmuxers_all"    "$libavmuxers" "#")
$(ff_config_enable "$libavprotocols_all" "$libavprotocols" "#")
$(ff_config_enable "$libavbsfs_all"      "$libavbsfs" "#")
$(ff_config_enable "$libavhwaccels_all"  "$libavhwaccels" "#")
$(ff_config_enable "$libavfilters_all"   "$libavfilters" "#")

#endif /* MPLAYER_CONFIG_H */
EOF

# Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
cmp -s "$TMPH" config.h || mv -f "$TMPH" config.h

############################################################################

# Create avconfig.h for FFmpeg.
cat > "$TMPH" << EOF
/* Generated by mpconfigure */
#ifndef AVUTIL_AVCONFIG_H
#define AVUTIL_AVCONFIG_H
$def_av_bigendian
$def_av_fast_unaligned
#define AV_HAVE_INCOMPATIBLE_LIBAV_ABI 0
#endif /* AVUTIL_AVCONFIG_H */
EOF

# Do not overwrite an unchanged avconfig.h to avoid superfluous rebuilds.
cmp -s "$TMPH" ffmpeg/libavutil/avconfig.h || mv -f "$TMPH" ffmpeg/libavutil/avconfig.h


if x86; then
# Create a skeleton config.asm with just the ARCH_ and *CODER definitions for FFmpeg.
> "$TMPS"
echo "%define CONFIG_GPL 1" >> "$TMPS"
echo "%define HAVE_ALIGNED_STACK 1" >> "$TMPS"
echo "$(ff_config_enable "$arch_all" "$arch" "%" "ARCH")" >> "$TMPS"
echo "$(ff_config_enable "$subarch_all" "$subarch" "%" "ARCH")" >> "$TMPS"
echo "$(ff_config_enable "$cpuexts_all" "$cpuexts" "%" "HAVE" "_EXTERNAL")" >> "$TMPS"
echo "$(ff_config_enable "$yasm_features_all" "$yasm_features" "%" "HAVE")" >> "$TMPS"
echo "$(ff_config_enable "$libavdecoders_all"  "$libavdecoders" "%" "CONFIG")" >> "$TMPS"
echo "$(ff_config_enable "$libavencoders_all"  "$libavencoders" "%" "CONFIG")" >> "$TMPS"

cmp -s "$TMPS" ffmpeg/config.asm || mv -f "$TMPS" ffmpeg/config.asm
fi


# Create a config.mak for FFmpeg that includes MPlayer's config.mak.
cat > ffmpeg/config.mak << EOF
ifndef FFMPEG_CONFIG_MAK
FFMPEG_CONFIG_MAK = 1
include ../config.mak
endif # FFMPEG_CONFIG_MAK
EOF

cat > ffmpeg/config.h << EOF
#include "../config.h"
EOF
touch ffmpeg/.config

#############################################################################

cat << EOF

Config files successfully generated by ./configure $configuration !

  Install prefix: $_prefix
  Data directory: $_datadir
  Config direct.: $_confdir

  Byte order: $_byte_order
  Optimizing for: $_optimizing

  Languages:
    Messages/GUI: $language_msg
    Manual pages: $language_man
    Documentation: $language_doc

  Enabled optional drivers:
    Input: $inputmodules
    Codecs: $codecmodules
    Audio output: $aomodules
    Video output: $vomodules

  Disabled optional drivers:
    Input: $noinputmodules
    Codecs: $nocodecmodules
    Audio output: $noaomodules
    Video output: $novomodules

'config.h' and 'config.mak' contain your configuration options.
Note: If you alter theses files (for instance CFLAGS) MPlayer may no longer
      compile *** DO NOT REPORT BUGS if you tweak these files ***

'make' will now compile MPlayer and 'make install' will install it.
Note: On non-Linux systems you might need to use 'gmake' instead of 'make'.

EOF


if test "$_mtrr" = yes ; then
  echo "Please check MTRR settings at /proc/mtrr (see DOCS/HTML/$language_doc/video.html#mtrr)"
  echo
fi

if ! x86_32; then
  cat <<EOF
NOTE: Win32 codec DLLs are not supported on your CPU ($host_arch) or your
operating system ($system_name). You may encounter a few files that cannot
be played due to missing open source video/audio codec support.

EOF
fi


cat <<EOF
Check $TMPLOG if you wonder why an autodetection failed (make sure
development headers/packages are installed).

NOTE: The --enable-* parameters unconditionally force options on, completely
skipping autodetection. This behavior is unlike what you may be used to from
autoconf-based configure scripts that can decide to override you. This greater
level of control comes at a price. You may have to provide the correct compiler
and linker flags yourself.
If you used one of these options (except --enable-menu and similar ones that
turn on internal features) and experience a compilation or linking failure,
make sure you have passed the necessary compiler/linker flags to configure.

If you suspect a bug, please read DOCS/HTML/$language_doc/bugreports.html.

EOF

if test "$warn_cflags" = yes; then
  cat <<EOF

MPlayer compilation will use the CPPFLAGS/CFLAGS/LDFLAGS/YASMFLAGS set by you,
but:

    *** ***  DO NOT REPORT BUGS IF IT DOES NOT COMPILE/WORK!  *** ***

It is strongly recommended to let MPlayer choose the correct *FLAGS!
To do so, remove *FLAGS from the environment an re-run configure.
You can use --extra-*flags to add custom flags if necessary.

EOF
fi

# Last move:
cleanup