#! /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 utils
export LC_ALL=C

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

# 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 -o $TMPEXE $@" >> "$TMPLOG"
  rm -f "$TMPEXE"
  $_cc $WARNFLAGS $WARN_CFLAGS $CFLAGS "$source" $extra_cflags $_ld_static $extra_ldflags $libs_mplayer -o "$TMPEXE" "$@" >> "$TMPLOG" 2>&1
  TMPRES="$?"
  echo >> "$TMPLOG"
  echo >> "$TMPLOG"
  return "$TMPRES"
}

cc_check() {
  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-selfsufficient 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 $@
}

pkg_config_add() {
  unset IFS  # shell should not be used for programming
  echo >> "$TMPLOG"
  echo "$_pkg_config --cflags $@" >> "$TMPLOG"
  ctmp=$($_pkg_config --cflags "$@" 2>> "$TMPLOG") || return $?
  echo >> "$TMPLOG"
  echo "$_pkg_config --libs $@" >> "$TMPLOG"
  ltmp=$($_pkg_config --libs "$@" 2>> "$TMPLOG") || return $?
  echo >> "$TMPLOG"
  echo "cflags: $ctmp" >> "$TMPLOG"
  echo "libs: $ltmp" >> "$TMPLOG"
  echo >> "$TMPLOG"
  extra_cflags="$extra_cflags $ctmp"
  extra_ldflags="$extra_ldflags $ltmp"
}

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

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

# OS test booleans functions
issystem() {
  test "$(echo $system_name | tr A-Z a-z)" = "$(echo $1 | tr A-Z a-z)"
}
aix()       { issystem "AIX"; }
amigaos()   { issystem "AmigaOS"; }
beos()      { issystem "BEOS"; }
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"; }
linux()     { issystem "Linux"; }
mingw32()   { issystem "MINGW32"; }
morphos()   { issystem "MorphOS"; }
netbsd()    { issystem "NetBSD"; }
openbsd()   { issystem "OpenBSD"; }
qnx()       { issystem "QNX"; }
win32()     { cygwin || mingw32; }

# 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|ppc64|powerpc|powerpc64) 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=''
ls po/*.po >/dev/null 2>&1 && msg_lang_all=$(echo po/*.po | sed -e 's:po/\([^[:space:]]*\)\.po:\1:g')
man_lang_all=$(echo DOCS/man/*/mplayer.rst | sed -e "s:DOCS/man/\(..\)/mplayer.rst:\1:g" -e "s:DOCS/man/\(.._..\)/mplayer.rst:\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]
  --mandir=DIR           directory for installing man pages [PREFIX/share/man]
  --confdir=DIR          directory for installing configuration files
                         [PREFIX/etc/mplayer]
  --localedir=DIR        directory for locale tree [PREFIX/share/locale]
  --libdir=DIR           directory for object code libraries [PREFIX/lib]
  --codecsdir=DIR        directory for binary codecs [LIBDIR/codecs]

Optional features:
  --disable-mplayer      disable MPlayer compilation [enable]
  --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-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-libquvi       enable libquvi [autodetect]
  --enable-lcms2         enable LCMS2 support [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-cddb         disable cddb [autodetect]
  --disable-unrarexec    disable using of UnRAR executable [enabled]
  --disable-enca         disable ENCA charset oracle library [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-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-libass       disable subtitle rendering with libass [autodetect]
  --enable-rpath         enable runtime linker path for extra libs [disabled]
  --disable-libpostproc  disable postprocess filter (vf_pp) [autodetect]

Codecs:
  --enable-gif              enable GIF support [autodetect]
  --enable-png              enable PNG input/output support [autodetect]
  --enable-mng              enable MNG input support [autodetect]
  --enable-jpeg             enable JPEG input/output support [autodetect]
  --enable-libcdio          enable libcdio 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-libnut          disable libnut [autodetect]
  --enable-libav            skip Libav autodetection [autodetect]
  --disable-libvorbis       disable libvorbis support [autodetect]
  --disable-tremor          disable Tremor [autodetect if no libvorbis]
  --disable-speex           disable Speex support [autodetect]
  --enable-theora           enable OggTheora libraries [autodetect]
  --enable-faad             enable FAAD2 (AAC) [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-mpg123          disable libmpg123 MP3 decoding support [autodetect]
  --disable-mad             disable libmad (MPEG audio) support [autodetect]
  --enable-xmms             enable XMMS input plugin support [disabled]
  --enable-libdca           enable libdca support [autodetect]
  --disable-liba52          disable liba52 [autodetect]
  --enable-musepack         enable libmpcdec support (deprecated, libavcodec
                            Musepack decoder is preferred) [disabled]

Video output:
  --enable-gl              enable OpenGL video output [autodetect]
  --enable-sdl             enable SDL video output [autodetect]
  --enable-caca            enable CACA  video output [autodetect]
  --enable-direct3d        enable Direct3D video output [autodetect]
  --enable-directx         enable DirectX video output [autodetect]
  --enable-v4l2            enable V4L2 Decoder audio/video output [autodetect]
  --enable-dvb             enable DVB video input [autodetect]
  --enable-xv              enable Xv video output [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]
  --disable-xss            disable screensaver support via xss [autodetect]
  --enable-directfb        enable DirectFB 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-cocoa          disable Cocoa OpenGL backend [autodetect]
  --disable-sharedbuffer   disable OSX shared buffer video output [autodetect]

Audio output:
  --disable-alsa         disable ALSA audio output [autodetect]
  --disable-ossaudio     disable OSS audio output [autodetect]
  --disable-rsound       disable RSound audio output [autodetect]
  --disable-pulse        disable Pulseaudio audio output [autodetect]
  --disable-portaudio    disable PortAudio audio output [autodetect]
  --disable-jack         disable JACK audio output [autodetect]
  --enable-openal        enable OpenAL audio output [disable]
  --disable-coreaudio    disable CoreAudio audio output [autodetect]
  --disable-select       disable using select() on the audio device [enable]

Language options:
  --enable-translation   enable support for translated output [disable]
  --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    extra languages for program messages [all]
  --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 translations available in the list will be
installed. The value "all" will activate all translations. The LINGUAS
environment variable is honored. In all cases the fallback is English.
The program always supports English-language output; additional message
languages are only installed if --enable-translation is also specified.
Available values for --language-doc are: all $doc_lang_all
Available values for --language-man are: all $man_lang_all
Available values for --language-msg are: all $msg_lang_all

Miscellaneous options:
  --enable-runtime-cpudetection    enable runtime CPU detection [disable]
  --enable-cross-compile enable cross-compilation [disable]
  --cc=COMPILER          C compiler to build MPlayer [gcc]
  --pkg-config=PKGCONFIG pkg-config to find some libraries [pkg-config]
  --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-ssse3            enable SSSE3 [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-neon             enable NEON (ARM) [autodetect]
  --enable-iwmmxt           enable iWMMXt (ARM) [autodetect]
  --disable-fastmemcpy      disable 3DNow!/SSE/MMX optimized memcpy [enable]
  --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-crash-debug      enable automatic gdb attach on crash [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

  --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
_ssse3=auto
_cmov=auto
_fast_cmov=auto
_fast_clz=auto
_armv5te=auto
_armv6=auto
_armv6t2=auto
_armvfp=auto
neon=auto
_iwmmxt=auto
_altivec=auto
_install=install
_pkg_config=auto
_windres=auto
_cc=auto
test "$CC" && _cc="$CC"
_as=auto
_runtime_cpudetection=no
_cross_compile=no
_prefix="/usr/local"
ffmpeg=auto
_x11=auto
_xss=auto
_xv=auto
_vdpau=auto
_sdl=auto
_direct3d=auto
_directx=auto
_png=auto
_mng=auto
_jpeg=auto
_pnm=yes
_md5sum=yes
_yuv4mpeg=yes
_gif=auto
_gl=auto
_aa=auto
_caca=auto
_dvb=auto
_v4l2=auto
_iconv=auto
_langinfo=auto
_rtc=auto
_ossaudio=auto
_rsound=auto
_pulse=auto
_portaudio=auto
_jack=auto
_openal=no
_libcdio=auto
_mad=auto
_tremor=auto
_libvorbis=auto
_speex=auto
_theora=auto
_mpg123=auto
_liba52=auto
_libdca=auto
_faad=auto
_ladspa=auto
_libbs2b=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
_lcms2=auto
_xinerama=auto
_vm=auto
_xf86keysym=auto
_alsa=auto
_fastmemcpy=yes
_unrar_exec=auto
_win32dll=auto
_select=yes
_radio=no
_radio_capture=no
_radio_v4l2=auto
_radio_bsdbt848=auto
_tv=yes
_tv_v4l2=auto
_tv_bsdbt848=auto
_tv_dshow=auto
_pvr=auto
networking=yes
_winsock2_h=auto
_smb=auto
_libquvi=auto
_joystick=no
_xvid=auto
_libnut=auto
_lirc=auto
_lircc=auto
_apple_remote=auto
_apple_ir=auto
_termcap=auto
_termios=auto
_tga=yes
_directfb=auto
#language=en
_shm=auto
_translation=no
_charset="UTF-8"
_crash_debug=no
_sighandler=yes
_libdv=auto
_cdda=auto
_cddb=auto
_big_endian=auto
_qtx=auto
_coreaudio=auto
_corevideo=auto
_cocoa=auto
_sharedbuffer=auto
quicktime=auto
_macosx_finder=no
_macosx_bundle=auto
_enca=auto
_inet6=auto
_gethostbyname2=auto
_ftp=auto
_musepack=no
_vstream=auto
_pthreads=auto
_w32threads=auto
_ass=auto
_rpath=no
libpostproc=auto
_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_priority="#undef CONFIG_PRIORITY"
def_pthread_cache="#undef PTHREAD_CACHE"
need_shmem=yes
for ac_option do
  case "$ac_option" in
  --help|-help|-h)
    show_help
    ;;
  --prefix=*)
    _prefix=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --bindir=*)
    _bindir=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --mandir=*)
    _mandir=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --confdir=*)
    _confdir=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --libdir=*)
    _libdir=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --codecsdir=*)
    _codecsdir=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --localedir=*)
    _localedir=$(echo $ac_option | cut -d '=' -f 2)
    ;;

  --with-install=*)
    _install=$(echo $ac_option | cut -d '=' -f 2 )
    ;;

  --with-sdl-config=*)
    _sdlconfig=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --with-dvdnav-config=*)
    _dvdnavconfig=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --with-dvdread-config=*)
    _dvdreadconfig=$(echo $ac_option | cut -d '=' -f 2)
    ;;

  --extra-cflags=*)
    extra_cflags="$extra_cflags $(echo $ac_option | cut -d '=' -f 2-)"
    ;;
  --extra-ldflags=*)
    extra_ldflags="$extra_ldflags $(echo $ac_option | cut -d '=' -f 2-)"
    ;;
  --extra-libs=*)
    extra_libs=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --extra-libs-mplayer=*)
    libs_mplayer=$(echo $ac_option | cut -d '=' -f 2)
    ;;

  --target=*)
    _target=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --cc=*)
    _cc=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --pkg-config=*)
    _pkg_config=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --windres=*)
    _windres=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --charset=*)
    _charset=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --language-doc=*)
    language_doc=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --language-man=*)
    language_man=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --language-msg=*)
    language_msg=$(echo $ac_option | cut -d '=' -f 2)
    ;;
  --language=*)
    language=$(echo $ac_option | cut -d '=' -f 2)
    ;;

  --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; echo $ac_option | cut -d '=' -f 2)
    ;;
  --disable-debug)
    _debug=
    ;;
  --enable-translation)              _translation=yes           ;;
  --disable-translation)             _translation=no            ;;
  --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-x11)         _x11=yes        ;;
  --disable-x11)        _x11=no         ;;
  --enable-xss)         _xss=yes        ;;
  --disable-xss)        _xss=no         ;;
  --enable-xv)          _xv=yes         ;;
  --disable-xv)         _xv=no          ;;
  --enable-vdpau)       _vdpau=yes      ;;
  --disable-vdpau)      _vdpau=no       ;;
  --enable-sdl)         _sdl=yes        ;;
  --disable-sdl)        _sdl=no         ;;
  --enable-direct3d)    _direct3d=yes   ;;
  --disable-direct3d)   _direct3d=no    ;;
  --enable-directx)     _directx=yes    ;;
  --disable-directx)    _directx=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-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-caca)        _caca=yes       ;;
  --disable-caca)       _caca=no        ;;
  --enable-dvb)         _dvb=yes        ;;
  --disable-dvb)        _dvb=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-rsound)      _rsound=yes     ;;
  --disable-rsound)     _rsound=no      ;;
  --enable-pulse)       _pulse=yes      ;;
  --disable-pulse)      _pulse=no       ;;
  --enable-portaudio)   _portaudio=yes  ;;
  --disable-portaudio)  _portaudio=no   ;;
  --enable-jack)        _jack=yes       ;;
  --disable-jack)       _jack=no        ;;
  --enable-openal)      _openal=yes     ;;
  --disable-openal)     _openal=no      ;;
  --enable-mad)         _mad=yes        ;;
  --disable-mad)        _mad=no         ;;
  --enable-libcdio)     _libcdio=yes    ;;
  --disable-libcdio)    _libcdio=no     ;;
  --enable-libvorbis)   _libvorbis=yes  ;;
  --disable-libvorbis)  _libvorbis=no   ;;
  --enable-speex)       _speex=yes      ;;
  --disable-speex)      _speex=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-musepack)    _musepack=yes   ;;
  --disable-musepack)   _musepack=no    ;;
  --enable-faad)        _faad=yes       ;;
  --disable-faad)       _faad=no        ;;
  --enable-ladspa)      _ladspa=yes     ;;
  --disable-ladspa)     _ladspa=no      ;;
  --enable-libbs2b)     _libbs2b=yes    ;;
  --disable-libbs2b)    _libbs2b=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-lcms2)       _lcms2=yes      ;;
  --disable-lcms2)      _lcms2=no       ;;
  --enable-xinerama)    _xinerama=yes   ;;
  --disable-xinerama)   _xinerama=no    ;;
  --enable-vm)          _vm=yes         ;;
  --disable-vm)         _vm=no          ;;
  --enable-xf86keysym)  _xf86keysym=yes ;;
  --disable-xf86keysym) _xf86keysym=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-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-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-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-libquvi)     _libquvi=yes    ;;
  --disable-libquvi)    _libquvi=no     ;;
  --enable-joystick)    _joystick=yes   ;;
  --disable-joystick)   _joystick=no    ;;
  --enable-xvid)        _xvid=yes       ;;
  --disable-xvid)       _xvid=no        ;;
  --enable-libnut)      _libnut=yes     ;;
  --disable-libnut)     _libnut=no      ;;
  --enable-libav)       ffmpeg=yes      ;;

  --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-termcap)     _termcap=yes    ;;
  --disable-termcap)    _termcap=no     ;;
  --enable-termios)     _termios=yes    ;;
  --disable-termios)    _termios=no     ;;
  --disable-tga)        _tga=no         ;;
  --enable-tga)         _tga=yes        ;;
  --enable-directfb)    _directfb=yes   ;;
  --disable-directfb)   _directfb=no    ;;
  --enable-shm)         _shm=yes        ;;
  --disable-shm)        _shm=no         ;;
  --enable-select)      _select=yes     ;;
  --disable-select)     _select=no      ;;
  --enable-cddb)        _cddb=yes       ;;
  --disable-cddb)       _cddb=no        ;;
  --enable-big-endian)  _big_endian=yes ;;
  --disable-big-endian) _big_endian=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-libass)      _ass=yes        ;;
  --disable-libass)     _ass=no         ;;
  --enable-rpath)       _rpath=yes      ;;
  --disable-rpath)      _rpath=no       ;;
  --enable-libpostproc) libpostproc=yes ;;
  --disable-libpostproc) libpostproc=no ;;

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

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

  --enable-gethostbyname2)      _gethostbyname2=yes     ;;
  --disable-gethostbyname2)     _gethostbyname2=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-cocoa) _cocoa=yes ;;
  --disable-cocoa) _cocoa=no ;;
  --enable-sharedbuffer) _sharedbuffer=yes ;;
  --disable-sharedbuffer) _sharedbuffer=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-crash-debug) _crash_debug=yes ;;
  --disable-crash-debug) _crash_debug=no ;;
  --enable-sighandler)  _sighandler=yes  ;;
  --disable-sighandler) _sighandler=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-ssse3) _ssse3=yes ;;
  --disable-ssse3) _ssse3=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-neon) neon=yes ;;
  --disable-neon) neon=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 ;;

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

  esac
done

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

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."

TMPLOG="config.log"

rm -f "$TMPLOG"
echo Parameters configure was run with: > "$TMPLOG"
if test -n "$CFLAGS" ; then
    echo ${_echo_n} CFLAGS="'$CFLAGS' ${_echo_c}" >> "$TMPLOG"
fi
if test -n "$PKG_CONFIG_PATH" ; then
    echo ${_echo_n} PKG_CONFIG_PATH="'$PKG_CONFIG_PATH' ${_echo_c}" >> "$TMPLOG"
fi
echo ./configure $configuration >> "$TMPLOG"
echo >> "$TMPLOG"


echocheck "cross compilation"
echores $_cross_compile

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

tool_prefix=""

if test $_cross_compile = yes ; then
    # Usually cross-compiler prefixes match with the target triplet
    test -n "$_target" && tool_prefix="$_target"-
fi

test "$_windres" = auto && _windres="$tool_prefix"windres
test "$_pkg_config" = auto && _pkg_config="$tool_prefix"pkg-config

if test "$_cc" = auto ; then
    if test -n "$tool_prefix" ; then
        _cc="$tool_prefix"gcc
    else
        _cc=cc
    fi
fi

# 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|QNX|GNU|BeOS|MorphOS|AIX|AmigaOS)
    ;;
  Haiku)
    system_name=BeOS
    ;;
  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


  # host's CPU/instruction set
   host_arch=$(uname -p 2>&1)
   case "$host_arch" in
   i386|sparc|ppc|alpha|arm|mips|vax)
     ;;
   powerpc) # Darwin returns 'powerpc'
     host_arch=ppc
     ;;
   *) # uname -p on Linux returns 'unknown' for the processor type,
      # OpenBSD returns 'Intel Pentium/MMX ("Genuine Intel" 586-class)'

      # Maybe uname -m (machine hardware name) returns something we
      # recognize.

      # x86/x86pc is used by QNX
      case "$(uname -m 2>&1)" in
      x86_64|amd64|i[3-9]86*|x86|x86pc|k5|k6|k6_2|k6_3|k6-2|k6-3|pentium*|athlon*|i586_i686|i586-i686|BePC) host_arch=i386 ;;
      ia64) host_arch=ia64 ;;
      macppc|ppc) host_arch=ppc ;;
      ppc64) host_arch=ppc64 ;;
      alpha) host_arch=alpha ;;
      sparc) host_arch=sparc ;;
      sparc64) host_arch=sparc64 ;;
      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
    ;;
  esac
else # if test -z "$_target"
  for i in 2 3; do
    system_name=$(echo $_target | cut -d '-' -f $i)
    case "$(echo $system_name | tr A-Z a-z)" 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 ;;
      qnx) system_name=QNX ;;
      morphos) system_name=MorphOS ;;
      amigaos) system_name=AmigaOS ;;
      mingw32*) system_name=MINGW32 ;;
      *) continue ;;
    esac
    break
  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

extra_cflags="-I. $extra_cflags"
_timer=timer-linux.c
_getch=getch2.c
if freebsd ; then
  extra_ldflags="$extra_ldflags -L/usr/local/lib"
  extra_cflags="$extra_cflags -I/usr/local/include"
fi

if netbsd || dragonfly ; then
  extra_ldflags="$extra_ldflags -L/usr/pkg/lib"
  extra_cflags="$extra_cflags -I/usr/pkg/include"
fi

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 win32 ; then
  _exesuf=".exe"
  extra_cflags="$extra_cflags -fno-common"
  # -lwinmm is always needed for osdep/timer-win2.c
  extra_ldflags="$extra_ldflags -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
  need_shmem=no
  extra_cflags="$extra_cflags -D__USE_MINGW_ANSI_STDIO=1"
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

TMPC="$mplayer_tmpdir/tmp.c"
TMPEXE="$mplayer_tmpdir/tmp$_exesuf"
TMPH="$mplayer_tmpdir/tmp.h"
TMPS="$mplayer_tmpdir/tmp.S"

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

_rst2man=rst2man
if [ -f "$(which rst2man.py)" ] ; then
  _rst2man=rst2man.py
fi

# 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.0|11.1)
      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)
  done
fi # icc
test "$cc_fail" = yes && die "unsupported compiler version"

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

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

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

# ---

# 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
  $_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/xmm/sse/ -e s/kni/sse/)
  # 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 $_ssse3    "ssse3"    "pabsd %%xmm0, %%xmm0"
  extcheck $_cmov     "cmov"     "cmovb %%eax,  %%ebx"

  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'
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'
  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" -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" = "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_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) proc=core2;;
        *)
          # 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" = "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'
    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'
    iproc='avr32'
    test $_fast_clz = "auto" && _fast_clz=yes
    ;;

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

  ppc|ppc64|powerpc|powerpc64)
    arch='ppc'
    def_fast_unaligned='#define HAVE_FAST_UNALIGNED 1'
    iproc='ppc'

    if test "$host_arch" = "ppc64" -o "$host_arch" = "powerpc64" ; 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' ;;
                *) ;;
            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'
    def_fast_64bit='#define HAVE_FAST_64BIT 1'

    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'

    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 "$_ssse3"    != no && _ssse3=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
    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_words_endian='#define WORDS_BIGENDIAN 1'
  def_bigendian='#define HAVE_BIGENDIAN 1'
else
  _byte_order='little-endian'
  def_words_endian='#undef WORDS_BIGENDIAN'
  def_bigendian='#define HAVE_BIGENDIAN 0'
fi
echores "$_byte_order"


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 -O2 -mstackrealign && tmp_run && cflags_stackrealign=-mstackrealign
  test -z "$cflags_stackrealign" && cc_check -O2 -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 "$_profile" != "" || test "$_debug" != "" ; then
  _install_strip=
fi
if test -z "$CFLAGS" ; then
  if test "$cc_vendor" = "intel" ; then
    CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe -fomit-frame-pointer"
    WARNFLAGS="-wd167 -wd556 -wd144"
  elif test "$cc_vendor" = "clang"; then
    CFLAGS="-O2 $_debug $_profile $_march $_pipe"
    WARNFLAGS="-Wall -Wno-switch-enum -Wno-logical-op-parentheses -Wpointer-arith -Wundef -Wno-pointer-sign -Wmissing-prototypes"
    ERRORFLAGS="-Werror=implicit-function-declaration"
  elif test "$cc_vendor" != "gnu" ; then
    CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe"
  else
    CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
    WARNFLAGS="-Wall -Wno-switch -Wno-parentheses -Wpointer-arith -Wredundant-decls"
    ERRORFLAGS="-Werror-implicit-function-declaration"
    extra_ldflags="$extra_ldflags -ffast-math"
  fi
else
  warn_cflags=yes
fi

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

if test "$cc_vendor" = "gnu" ; then
  cflag_check -Wundef && WARNFLAGS="-Wundef $WARNFLAGS"
  # -std=gnu99 is not a warning flag but is placed in WARN_CFLAGS because
  # that's the only variable specific to C now, and this option is not valid
  # for C++.
  cflag_check -std=gnu99 && WARN_CFLAGS="-std=gnu99 $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"
else
  CFLAGS="-D_ISOC99_SOURCE -D_BSD_SOURCE $CFLAGS"
fi

cflag_check -mno-omit-leaf-frame-pointer && cflags_no_omit_leaf_frame_pointer="-mno-omit-leaf-frame-pointer"
cflag_check -MD -MP && DEPFLAGS="-MD -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



echocheck "PIC"
pic=no
cat > $TMPC << EOF
int main(void) {
#if !(defined(__PIC__) || defined(__pic__) || defined(PIC))
#error PIC not enabled
#endif
    return 0;
}
EOF
cc_check && pic=yes && extra_cflags="$extra_cflags -DPIC"
echores $pic


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
def_ebx_available='#define HAVE_EBX_AVAILABLE 0'
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

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 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 NEON"
  if test $neon = "auto" ; then
    neon=no
    inline_asm_check '"vadd.i16 q0, q0, q0"' && neon=yes
  fi
  echores "$neon"

  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 MMX MMX2 AMD3DNOW AMD3DNOWEXT SSE SSE2 SSSE3 FAST_CMOV CMOV FAST_CLZ ARMV5TE ARMV6 ARMV6T2 ARMVFP NEON IWMMXT MMI VIS MVI'
test "$_altivec"   = yes && cpuexts="ALTIVEC $cpuexts"
test "$_mmx"       = yes && cpuexts="MMX $cpuexts"
test "$_mmxext"    = yes && cpuexts="MMX2 $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 "$_ssse3"     = yes && cpuexts="SSSE3 $cpuexts"
test "$_cmov"      = yes && cpuexts="CMOV $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="ARMVFP $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 "-lposix"
if cflag_check -lposix ; then
  extra_ldflags="$extra_ldflags -lposix"
  echores "yes"
else
  echores "no"
fi

echocheck "-lm"
if cflag_check -lm ; then
  _ld_lm="-lm"
  echores "yes"
else
  _ld_lm=""
  echores "no"
fi


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 "translation support"
if test "$_translation" = yes; then
  def_translation="#define CONFIG_TRANSLATION 1"
else
  def_translation="#undef CONFIG_TRANSLATION"
fi
echores "$_translation"

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
test -z "$language_msg" && language_msg="all"
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=$msg_lang_all

if test "$_translation" != yes ; then
  language_msg=""
fi

# 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 po/$lang.po && tmp_language_msg="$tmp_language_msg $lang"
done
language_msg=$tmp_language_msg

echores "messages (en+): $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"


echocheck "posix4"
# required for nanosleep on some systems
_posix4=no
statement_check time.h 'nanosleep(0, 0)' -lposix4 && _posix4=yes
if test "$_posix4" = yes ; then
  extra_ldflags="$extra_ldflags -lposix4"
fi
echores "$_posix4"


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):
# for BeOS (socket stuff is in -lsocket, gethostbyname and friends in -lbind):
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 -lbind" "-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'
else
  def_winsock2_h='#define HAVE_WINSOCK2_H 0'
fi


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'
  extra_ldflags="$extra_ldflags $_ld_sock"
  inputmodules="networking $inputmodules"
else
  noinputmodules="networking $noinputmodules"
  def_network='#define CONFIG_NETWORK 0'
  def_networking='#undef CONFIG_NETWORKING'
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
#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 "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 "alloca.h"
_alloca=no
statement_check alloca.h 'alloca(0)' && _alloca=yes
if cc_check ; 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 "mman.h"
_mman=no
statement_check sys/mman.h 'mmap(0, 0, 0, 0, 0, 0)' && _mman=yes
if test "$_mman" = yes ; then
  def_mman_h='#define HAVE_SYS_MMAN_H 1'
else
  def_mman_h='#undef HAVE_SYS_MMAN_H'
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 "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 "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;
#ifdef PTW32_STATIC_LIB
 pthread_win32_process_attach_np();
 pthread_win32_thread_attach_np();
#endif
 return pthread_create (&tid, 0, func, 0) != 0;
}
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
  if test "$_pthreads" = no && mingw32 ; then
    _ld_tmp="-lpthreadGC2 -lws2_32"
    cc_check $_ld_tmp -DPTW32_STATIC_LIB && (tmp_run || test "$_ld_static") && _ld_pthread="$_ld_tmp" && _pthreads=yes && CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
  fi
fi
fi
if test "$_pthreads" = yes ; then
  test $_ld_pthread && res_comment="using $_ld_pthread"
  def_pthreads='#define HAVE_PTHREADS 1'
  extra_cflags="$extra_cflags $THREAD_CFLAGS"
else
  res_comment="v4l2, win32 loader disabled"
  def_pthreads='#undef HAVE_PTHREADS'
  _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

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
echores "$_w32threads"

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
  for _ld_tmp in "" "-liconv" "-liconv $_ld_dl" ; do
    cc_check $_ld_lm $_ld_tmp && extra_ldflags="$extra_ldflags $_ld_tmp" &&
      _iconv=yes && break
  done
  if test "$_iconv" != yes ; then
    die "Unable to find iconv which should be part of standard compilation environment. Aborting. If you really mean to compile without iconv support use --disable-iconv."
  fi
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 "sys/videoio.h"
sys_videoio_h=no
def_sys_videoio_h='#undef HAVE_SYS_VIDEOIO_H'
header_check sys/videoio.h && sys_videoio_h=yes &&
    def_sys_videoio_h='#define HAVE_SYS_VIDEOIO_H 1'
echores "$sys_videoio_h"


echocheck "sys/dvdio.h"
_dvdio=no
# FreeBSD 8.1 has broken dvdio.h
header_check_broken sys/types.h sys/dvdio.h && _dvdio=yes
if test "$_dvdio" = yes ; then
  def_dvdio='#define DVD_STRUCT_IN_SYS_DVDIO_H 1'
else
  def_dvdio='#undef DVD_STRUCT_IN_SYS_DVDIO_H'
fi
echores "$_dvdio"


echocheck "sys/cdio.h"
_cdio=no
# at least OpenSolaris has a broken cdio.h
header_check_broken sys/types.h sys/cdio.h && _cdio=yes
if test "$_cdio" = yes ; then
  def_cdio='#define DVD_STRUCT_IN_SYS_CDIO_H 1'
else
  def_cdio='#undef DVD_STRUCT_IN_SYS_CDIO_H'
fi
echores "$_cdio"


echocheck "linux/cdrom.h"
_cdrom=no
header_check linux/cdrom.h && _cdrom=yes
if test "$_cdrom" = yes ; then
  def_cdrom='#define DVD_STRUCT_IN_LINUX_CDROM_H 1'
else
  def_cdrom='#undef DVD_STRUCT_IN_LINUX_CDROM_H'
fi
echores "$_cdrom"


echocheck "dvd.h"
_dvd=no
header_check dvd.h && _dvd=yes
if test "$_dvd" = yes ; then
  def_dvd='#define DVD_STRUCT_IN_DVD_H 1'
else
  def_dvd='#undef DVD_STRUCT_IN_DVD_H'
fi
echores "$_dvd"


if bsdos; then
echocheck "BSDI dvd.h"
_bsdi_dvd=no
header_check dvd.h && _bsdi_dvd=yes
if test "$_bsdi_dvd" = yes ; then
  def_bsdi_dvd='#define DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H 1'
else
  def_bsdi_dvd='#undef DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H'
fi
echores "$_bsdi_dvd"
fi #if bsdos


if hpux; then
# also used by AIX, but AIX does not support VCD and/or libdvdread
echocheck "HP-UX SCSI header"
_hpux_scsi_h=no
header_check sys/scsi.h && _hpux_scsi_h=yes
if test "$_hpux_scsi_h" = yes ; then
  def_hpux_scsi_h='#define HPUX_SCTL_IO 1'
else
  def_hpux_scsi_h='#undef HPUX_SCTL_IO'
fi
echores "$_hpux_scsi_h"
fi #if hpux


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" && _termcap=yes && break
  done
fi
if test "$_termcap" = yes ; then
  def_termcap='#define HAVE_TERMCAP 1'
  test $_ld_tmp && res_comment="using $_ld_tmp"
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=no
statement_check string.h 'char *s = "Hello, world!"; strsep(&s, ",")' && _strsep=yes
if test "$_strsep" = yes ; then
  def_strsep='#define HAVE_STRSEP 1'
 need_strsep=no
else
  def_strsep='#undef HAVE_STRSEP'
 need_strsep=yes
fi
echores "$_strsep"


echocheck "vsscanf()"
cat > $TMPC << EOF
#define _ISOC99_SOURCE
#include <stdarg.h>
#include <stdio.h>
int main(void) { va_list ap; vsscanf("foo", "bar", ap); return 0; }
EOF
_vsscanf=no
cc_check && _vsscanf=yes
if test "$_vsscanf" = yes ; then
  def_vsscanf='#define HAVE_VSSCANF 1'
  need_vsscanf=no
else
  def_vsscanf='#undef HAVE_VSSCANF'
  need_vsscanf=yes
fi
echores "$_vsscanf"


echocheck "swab()"
_swab=no
define_statement_check "_XOPEN_SOURCE 600" "unistd.h" 'int a, b; swab(&a, &b, 0)' ||
    statement_check "string.h" 'int a, b; swab(&a, &b, 0)' && _swab=yes
if test "$_swab" = yes ; then
  def_swab='#define HAVE_SWAB 1'
  need_swab=no
else
  def_swab='#undef HAVE_SWAB'
  need_swab=yes
fi
echores "$_swab"

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'
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=no
statement_check sys/time.h 'struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz)' && _gettimeofday=yes
if test "$_gettimeofday" = yes ; then
  def_gettimeofday='#define HAVE_GETTIMEOFDAY 1'
  need_gettimeofday=no
else
  def_gettimeofday='#undef HAVE_GETTIMEOFDAY'
  need_gettimeofday=yes
fi
echores "$_gettimeofday"


echocheck "glob()"
_glob=no
statement_check glob.h 'glob("filename", 0, 0, 0)' && _glob=yes
need_glob=no
if test "$_glob" = yes ; then
  def_glob='#define HAVE_GLOB 1'
else
  def_glob='#undef HAVE_GLOB'
  # HACK! need_glob currently enables compilation of a
  # win32-specific glob()-replacement.
  # Other OS neither need it nor can they use it (mf:// is disabled for them).
  win32 && need_glob=yes
fi
echores "$_glob"


echocheck "setenv()"
_setenv=no
statement_check stdlib.h 'setenv("", "", 0)' && _setenv=yes
if test "$_setenv" = yes ; then
  def_setenv='#define HAVE_SETENV 1'
  need_setenv=no
else
  def_setenv='#undef HAVE_SETENV'
  need_setenv=yes
fi
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"


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 Cocoa"
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'
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"
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"

echocheck "libquvi support"
if test "$_libquvi" = auto ; then
    _libquvi=no
    if pkg_config_add 'libquvi >= 0.4.1' ; then
        _libquvi=yes
    fi
fi
if test "$_libquvi" = yes; then
    def_libquvi="#define CONFIG_LIBQUVI 1"
else
    def_libquvi="#undef CONFIG_LIBQUVI"
fi
echores "$_libquvi"

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


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 "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 $vomodules"
  libs_mplayer="$libs_mplayer -ldirectfb"
else
  def_directfb='#undef CONFIG_DIRECTFB'
  novomodules="directfb $novomodules"
fi
echores "$_directfb"


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'
fi
echores $quicktime

echocheck "Cocoa"
if test "$_cocoa" = auto ; then
  cat > $TMPC <<EOF
#include <CoreServices/CoreServices.h>
#include <OpenGL/OpenGL.h>
int main(void) {
  NSApplicationLoad();
}
EOF
  _cocoa=no
  cc_check -framework IOKit -framework Cocoa -framework OpenGL && _cocoa=yes
fi
if test "$_cocoa" = yes ; then
  libs_mplayer="$libs_mplayer -framework IOKit -framework Cocoa -framework OpenGL"
  def_cocoa='#define CONFIG_COCOA 1'
else
  def_cocoa='#undef CONFIG_COCOA'
fi
echores "$_cocoa"

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

echocheck "SharedBuffer"
if test "$_sharedbuffer" = auto ; then
  cat > $TMPC <<EOF
int main(void) {
  NSApplicationLoad();
}
EOF
  _sharedbuffer=no
  cc_check -framework Cocoa && _sharedbuffer=yes
fi
if test "$_sharedbuffer" = yes ; then
  vomodules="sharedbuffer $vomodules"
  libs_mplayer="$libs_mplayer -framework Cocoa"
  def_sharedbuffer='#define CONFIG_SHAREDBUFFER 1'
else
  novomodules="sharedbuffer $novomodules"
  def_sharedbuffer='#undef CONFIG_SHAREDBUFFER'
fi
echores "$_sharedbuffer"

depends_on_application_services(){
  test "$_corevideo" = yes
}

fi #if darwin


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 &&
      _x11=yes
    # Check that there aren't conflicting headers between ApplicationServices
    # and X11. On versions of Mac OSX prior to 10.7 the deprecated QuickDraw API
    # is included by -framework ApplicationServices and clashes with the X11
    # definition of the "Cursor" type.
    if darwin && depends_on_application_services && test "$_x11" = yes ; then
      _x11=no
      header_check_broken ApplicationServices/ApplicationServices.h \
        X11/Xutil.h $_ld_tmp && _x11=yes
    fi
    if test "$_x11" = yes ; then
      libs_mplayer="$libs_mplayer $_ld_tmp"
      break
    fi
  done
fi
if test "$_x11" = yes ; then
  def_x11='#define CONFIG_X11 1'
  vomodules="x11 $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 "VDPAU"
if test "$_vdpau" = auto && test "$_x11" = yes ; then
  _vdpau=no
  if test "$_dl" = yes ; then
    pkg_config_add 'vdpau >= 0.2' && _vdpau=yes
  fi
fi
if test "$_vdpau" = yes ; then
  def_vdpau='#define CONFIG_VDPAU 1'
  vomodules="vdpau $vomodules"
else
  def_vdpau='#define CONFIG_VDPAU 0'
  novomodules="vdpau $novomodules"
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 "CACA"
if test "$_caca" = auto ; then
  _caca=no
  pkg_config_add 'caca' && _caca=yes
fi
if test "$_caca" = yes ; then
  def_caca='#define CONFIG_CACA 1'
  vomodules="caca $vomodules"
else
  def_caca='#undef CONFIG_CACA'
  novomodules="caca $novomodules"
fi
echores "$_caca"


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_dvbin='#define CONFIG_DVBIN 1'
else
  _dvbin=no
  noinputmodules="dvb $noinputmodules"
  def_dvbin='#undef CONFIG_DVBIN '
fi


echocheck "PNG support"
if test "$_png" = auto ; then
  _png=no
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 $_ld_lm && _png=yes
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
  return_statement_check libmng.h 'const char * p_ver = mng_version_text()' '!p_ver || p_ver[0] == 0' -lmng -lz $_ld_lm && _mng=yes
fi
echores "$_mng"
if test "$_mng" = yes ; then
  def_mng='#define CONFIG_MNG 1'
  extra_ldflags="$extra_ldflags -lmng -lz"
else
  def_mng='#undef CONFIG_MNG'
fi

echocheck "JPEG support"
if test "$_jpeg" = auto ; then
  _jpeg=no
  header_check_broken stdio.h jpeglib.h -ljpeg $_ld_lm && _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 "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
  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'

  cat > $TMPC << EOF
#include <stdio.h>
#include <gif_lib.h>
int main(void) {
  GifFileType gif = {.UserData = NULL};
  printf("UserData is at address %p\n", gif.UserData);
  return 0;
}
EOF
  if cc_check "$_ld_gif" ; then
    def_gif_tvt_hack='#undef CONFIG_GIF_TVT_HACK'
    echores "disabled"
  else
    echores "enabled"
  fi
  ;;
esac


#################
# 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"
  elif ( sdl11-config --version ) >>"$TMPLOG" 2>&1 ; then
    _sdlconfig="sdl11-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 BeOS/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"


# 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 "$_x11" = yes || test "$_sdl" = yes || test "$_cocoa" = yes || win32) && 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
#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();
#else
  glXCreateContext(NULL, NULL, NULL, True);
#endif
  glFinish();
  return 0;
}
EOF
  _gl=no
  if test "$_x11" = yes ; then
    for _ld_tmp in "" -lGL "-lGL -lXdamage" "-lGL $_ld_pthread" ; do
      if cc_check $_ld_tmp $_ld_lm ; then
        _gl=yes
        _gl_x11=yes
        libs_mplayer="$libs_mplayer $_ld_tmp $_ld_dl"
        break
      fi
    done
  fi
  if win32 && cc_check -DGL_WIN32 -lopengl32 ; then
    _gl=yes
    _gl_win32=yes
    libs_mplayer="$libs_mplayer -lopengl32 -lgdi32"
  fi
  if test "$_cocoa" = yes ; then
    _gl=yes
    _gl_cocoa=yes
  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
else
  _gl=no
fi
if test "$_gl" = yes ; then
  def_gl='#define CONFIG_GL 1'
  res_comment="backends:"
  if test "$_gl_cocoa" = yes ; then
    def_gl_cocoa='#define CONFIG_GL_COCOA 1'
    res_comment="$res_comment cocoa"
  fi
  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_sdl" = yes ; then
    def_gl_sdl='#define CONFIG_GL_SDL 1'
    res_comment="$res_comment sdl"
  fi
  vomodules="opengl $vomodules"
else
  def_gl='#undef CONFIG_GL'
  def_gl_cocoa='#undef CONFIG_GL_COCOA'
  def_gl_win32='#undef CONFIG_GL_WIN32'
  def_gl_x11='#undef CONFIG_GL_X11'
  def_gl_sdl='#undef CONFIG_GL_SDL'
  novomodules="opengl $novomodules"
fi
echores "$_gl"


if win32; then

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 <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 "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"
  cat > $TMPC << EOF
#include <$_soundcard_header>
#ifdef OPEN_SOUND_SYSTEM
int main(void) { return 0; }
#else
#error Not the real thing
#endif
EOF
   _real_ossaudio=no
   cc_check && _real_ossaudio=yes
   if test "$_real_ossaudio" = yes; then
     def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/dsp"'
     # Check for OSS4 headers (override default headers)
     # Does not apply to systems where OSS4 is native (e.g. FreeBSD)
     if test -f /etc/oss.conf; then
       . /etc/oss.conf
       _ossinc="$OSSLIBDIR/include"
       if test -f "$_ossinc/sys/soundcard.h"; then
         extra_cflags="-I$_ossinc $extra_cflags"
       fi
     fi
   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 "RSound"
if test "$_rsound" = auto ; then
   _rsound=no
   statement_check rsound.h 'rsd_init(NULL);' -lrsound && _rsound=yes
fi
echores "$_rsound"

if test "$_rsound" = yes ; then
   def_rsound='#define CONFIG_RSOUND 1'
   aomodules="rsound $aomodules"
   libs_mplayer="$libs_mplayer -lrsound"
else
   def_rsound='#undef CONFIG_RSOUND'
   noaomodules="rsound $noaomodules"
fi


echocheck "pulse"
if test "$_pulse" = auto ; then
  _pulse=no
  if pkg_config_add 'libpulse >= 0.9' ; then
      _pulse=yes
  fi
fi
echores "$_pulse"

if test "$_pulse" = yes ; then
  def_pulse='#define CONFIG_PULSE 1'
  aomodules="pulse $aomodules"
else
  def_pulse='#undef CONFIG_PULSE'
  noaomodules="pulse $noaomodules"
fi


echocheck "PortAudio"
if test "$_portaudio" = auto && test "$_pthreads" != yes ; then
    _portaudio=no
    res_comment="pthreads not enabled"
fi
if test "$_portaudio" = auto ; then
  _portaudio=no
  if pkg_config_add 'portaudio-2.0 >= 19' ; then
      _portaudio=yes
  fi
fi
echores "$_portaudio"

if test "$_portaudio" = yes ; then
  def_portaudio='#define CONFIG_PORTAUDIO 1'
  aomodules="portaudio $aomodules"
else
  def_portaudio='#undef CONFIG_PORTAUDIO'
  noaomodules="portaudio $noaomodules"
fi


echocheck "JACK"
if test "$_jack" = auto ; then
  _jack=no
  if pkg_config_add jack ; then
      _jack=yes
  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);
//  alGetSourcei(0, AL_SAMPLE_OFFSET, 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 ; then
  _alsa=no
  res_comment="alloca missing"
fi
if test "$_alsa" = auto ; then
    _alsa=no
    if pkg_config_add "alsa >= 1.0.9" ; then
        _alsa=yes
    fi
fi
def_alsa='#undef CONFIG_ALSA'
if test "$_alsa" = yes ; then
    aomodules="alsa $aomodules"
    def_alsa='#define CONFIG_ALSA 1'
else
    noaomodules="alsa $noaomodules"
fi
echores "$_alsa"


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


# set default CD/DVD devices
if win32 ; 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 amigaos ; then
  default_cdrom_device="a1ide.device:2"
else
  default_cdrom_device="/dev/cdrom"
fi

if win32 || dragonfly || freebsd || openbsd || 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 ; 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
  pkg_config_add 'libbluray >= 0.2.1' && _bluray=yes
fi
if test "$_bluray" = yes ; then
  def_bluray='#define CONFIG_LIBBLURAY 1'
  inputmodules="bluray $inputmodules"
else
  def_bluray='#undef CONFIG_LIBBLURAY'
  noinputmodules="bluray $noinputmodules"
fi
echores "$_bluray"

echocheck "dvdread"
if test "$_dvdread_internal" = auto && test ! -f "libdvdread4/dvd_reader.c" ; then
  _dvdread_internal=no
fi
if test "$_dvdread_internal" = auto ; then
  _dvdread_internal=no
  _dvdread=no
  if (linux || freebsd || netbsd || openbsd || dragonfly || hpux) &&
     (test "$_dvd" = yes || test "$_cdrom" = yes || test "$_cdio" = yes ||
      test "$_dvdio" = yes || test "$_bsdi_dvd" = yes) ||
     darwin || win32; then
    _dvdread_internal=yes
    _dvdread=yes
    extra_cflags="-Ilibdvdread4 $extra_cflags"
  fi
elif 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"
if test "$_libdvdcss_internal" = auto ; then
  _libdvdcss_internal=no
  test "$_dvdread_internal" = yes && test -d libdvdcss && _libdvdcss_internal=yes
  hpux && test "$_hpux_scsi_h" = no && _libdvdcss_internal=no
fi
if test "$_libdvdcss_internal" = yes ; then
  if linux || netbsd || openbsd || bsdos ; 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="-DSYS_CYGWIN -DWIN32"
  elif beos ; then
    cflags_libdvdcss="-DSYS_BEOS"
  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
    _libcdio=no
    if pkg_config_add libcdio_paranoia ; then
        _libcdio=yes
    fi
fi
if test "$_libcdio" = yes ; then
    _cdda='yes'
    def_cdda='#define CONFIG_CDDA 1'
    test $_cddb = auto && test $networking = yes && _cddb=yes
    inputmodules="cdda $inputmodules"
else
    _libcdio=no
    _cdda='no'
    def_cdda='#undef CONFIG_CDDA'
    noinputmodules="cdda $noinputmodules"
fi
echores "$_libcdio"

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 "SSA/ASS support"
if test "$_ass" = auto ; then
    if pkg_config_add libass ; then
        _ass=yes
        def_ass='#define CONFIG_ASS 1'
    else
        die "Unable to find development files for libass. Aborting. If you really mean to compile without libass support use --disable-libass."
    fi
else
    def_ass='#undef CONFIG_ASS'
fi
echores "$_ass"


echocheck "ENCA"
if test "$_enca" = auto ; then
    _enca=no
    statement_check enca.h 'enca_get_languages(NULL)' -lenca $_ld_lm && _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"
else
  def_zlib='#define CONFIG_ZLIB 0'
fi
echores "$_zlib"


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 "mad support"
if test "$_mad" = auto ; then
  _mad=no
  header_check mad.h -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 "OggVorbis support"
if test "$_libvorbis" = auto; then
  _libvorbis=no
  statement_check vorbis/codec.h 'vorbis_packet_blocksize(0, 0)' -lvorbis -logg $_ld_lm && _libvorbis=yes && _tremor=no
elif test "$_libvorbis" = yes ; then
  _tremor=no
fi
if test "$_tremor" = auto; then
  _tremor=no
  statement_check tremor/ivorbiscodec.h 'vorbis_packet_blocksize(0, 0)' -logg -lvorbisidec $_ld_lm && _tremor=yes
fi
if test "$_tremor" = yes ; then
  _vorbis=yes
  def_vorbis='#define CONFIG_OGGVORBIS 1'
  def_tremor='#define CONFIG_TREMOR 1'
  codecmodules="tremor(external) $codecmodules"
  res_comment="external Tremor"
  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 -lvorbis -logg"
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 $_ld_lm && _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 "OggTheora support"
if test "$_theora" = auto ; then
  _theora=no
  if pkg_config_add theora ; then
      _theora=yes
  fi
fi
if test "$_theora" = yes ; then
  def_theora='#define CONFIG_OGGTHEORA 1'
  codecmodules="libtheora $codecmodules"
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
  pkg_config_add 'libmpg123 >= 1.2.0' && _mpg123=yes
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
  cat > $TMPC << EOF
#include <inttypes.h>
#include <a52dec/a52.h>
int main(void) { a52_state_t *testHand; testHand=a52_init(0); return 0; }
EOF
  cc_check -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 "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 $_ld_lm &&
      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 $_ld_lm && _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 "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 $_ld_lm && _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 "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
    _libbs2b=no
    if pkg_config_add libbs2b ; then
        _libbs2b=yes
    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 && _codecsdir="codecs"
fi


echocheck "Win32 codecs"
if test "$_win32dll" = auto ; then
  _win32dll=no
  if x86_32 && ! qnx; then
    _win32dll=yes
  fi
fi
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) ; 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 "LCMS2 support"
if test "$_lcms2" = auto ; then
    _lcms2=no
    if pkg_config_add lcms2 ; then
        _lcms2=yes
    fi
fi
if test "$_lcms2" = yes; then
    def_lcms2="#define CONFIG_LCMS2 1"
else
    def_lcms2="#undef CONFIG_LCMS2"
fi
echores "$_lcms2"


all_libav_libs="libavutil > 51.21.0:libavcodec >= 54.25.0:libavformat > 53.20.0:libswscale >= 2.0.0:libavresample >= 1.0.0"
echocheck "Libav ($all_libav_libs)"
if test "$ffmpeg" = auto ; then
  IFS=":"   # shell should not be used for programming
  if ! pkg_config_add $all_libav_libs ; then
    die "Unable to find development files for some of the required Libav libraries above. Aborting."
  fi
fi
echores "yes"

echocheck "libpostproc >= 52.0.0"
if test "$libpostproc" = auto ; then
    libpostproc=no
    if pkg_config_add "libpostproc >= 52.0.0" ; then
        libpostproc=yes
    fi
fi
if test "$libpostproc" = yes ; then
    def_libpostproc='#define CONFIG_LIBPOSTPROC 1'
else
    def_libpostproc='#undef CONFIG_LIBPOSTPROC'
fi
echores "$libpostproc"

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 $_ld_lm && _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 "Xvid"
if test "$_xvid" = auto ; then
  _xvid=no
  for _ld_tmp in "-lxvidcore $_ld_lm" "-lxvidcore $_ld_lm $_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 "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"


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 ; then
  _tv_dshow=no
  if test "$_tv" = yes && win32 ; then
    statement_check ole2.h 'void* p; CoCreateInstance((GUID*)&GUID_NULL, NULL, CLSCTX_INPROC_SERVER, &GUID_NULL, &p)' -lole32 -luuid && _tv_dshow=yes
  fi
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 2 TV interface"
if test "$_tv_v4l2" = auto ; then
  _tv_v4l2=no
  if test "$_tv" = yes && linux ; then
    header_check_broken sys/time.h linux/videodev2.h && _tv_v4l2=yes
  elif test "$_tv" = yes && test "$sys_videoio_h" = "yes" ; then
    _tv_v4l2=yes
  fi
fi
if test "$_tv_v4l2" = yes ; then
  _audio_input=yes
  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 ; then
  _radio_v4l2=no
  if test "$_radio" = yes && linux ; then
    header_check linux/videodev2.h && _radio_v4l2=yes
  fi
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"

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_v4l2" = no &&
   test "$_radio_bsdbt848" = no && test "$_radio" = yes ; then
    die "Radio driver requires BSD BT848 or V4L2!"
fi

echocheck "Video 4 Linux 2 MPEG PVR interface"
if test "$_pvr" = auto ; then
 _pvr=no
 if test "$_tv_v4l2" = yes && linux ; then
  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
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" ; then
test "$networking" = "yes" && ! beos && _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 "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"

if test "$_charset" != "noconv" ; then
  def_charset="#define MSG_CHARSET \"$_charset\""
else
  def_charset="#undef MSG_CHARSET"
  _charset="UTF-8"
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


# 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 ; 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"

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

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

# 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)"
if test "$_dvdread_internal" = yes && test ! -f "libdvdnav/dvdnav.c" ; then
  _dvdnav=no
fi
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"

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

mak_enable () {
list=$(echo $1 | tr '[a-z]' '[A-Z]')
item=$(echo $2 | tr '[a-z]' '[A-Z]')
nprefix=$3;
for part in $list; do
  if $(echo $item | grep -q -E "(^| )$part($| )"); then
    echo "${nprefix}_$part = yes"
  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
MSG_LANGS = $language_msg
MSG_LANG_ALL = $msg_lang_all

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

CC      = $_cc
INSTALL = $_install
INSTALLSTRIP = $_install_strip
WINDRES = $_windres

CFLAGS   = $WARNFLAGS $ERRORFLAGS $WARN_CFLAGS $CFLAGS $extra_cflags
DEPFLAGS = $DEPFLAGS

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

EXTRALIBS          = $extra_ldflags $_ld_static $_ld_lm $extra_libs
EXTRALIBS_MPLAYER  = $libs_mplayer

GETCH = $_getch
TIMER = $_timer
RST2MAN = $_rst2man

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)

NEED_GETTIMEOFDAY = $need_gettimeofday
NEED_GLOB         = $need_glob
NEED_SETENV       = $need_setenv
NEED_SHMEM        = $need_shmem
NEED_STRSEP       = $need_strsep
NEED_SWAB         = $need_swab
NEED_VSSCANF      = $need_vsscanf

# features
ALSA = $_alsa
APPLE_IR = $_apple_ir
APPLE_REMOTE = $_apple_remote
AUDIO_INPUT = $_audio_input
CACA = $_caca
CDDA = $_cdda
CDDB = $_cddb
COCOA = $_cocoa
COREAUDIO = $_coreaudio
COREVIDEO = $_corevideo
SHAREDBUFFER = $_sharedbuffer
DIRECT3D = $_direct3d
DIRECTFB = $_directfb
DIRECTX = $_directx
DVBIN = $_dvbin
DVDNAV = $_dvdnav
DVDNAV_INTERNAL = $dvdnav_internal
DVDREAD = $_dvdread
DVDREAD_INTERNAL = $_dvdread_internal
DXR3 = $_dxr3
FAAD = $_faad
FASTMEMCPY = $_fastmemcpy
FTP = $_ftp
GIF = $_gif
GL = $_gl
GL_COCOA = $_gl_cocoa
GL_WIN32 = $_gl_win32
GL_X11 = $_gl_x11
GL_SDL = $_gl_sdl
HAVE_POSIX_SELECT = $_posix_select
HAVE_SYS_MMAN_H = $_mman
JACK = $_jack
JOYSTICK = $_joystick
JPEG = $_jpeg
LADSPA = $_ladspa
LIBA52 = $_liba52
LIBASS = $_ass
LIBBLURAY = $_bluray
LIBBS2B = $_libbs2b
LIBDCA = $_libdca
LIBDV = $_libdv
LIBDVDCSS_INTERNAL = $_libdvdcss_internal
LIBMAD = $_mad
LCMS2 = $_lcms2
LIBNUT = $_libnut
LIBPOSTPROC = $libpostproc
LIBSMBCLIENT = $_smb
LIBQUVI = $_libquvi
LIBTHEORA = $_theora
LIRC = $_lirc
MACOSX_FINDER = $_macosx_finder
MD5SUM = $_md5sum
MNG = $_mng
MPG123 = $_mpg123
MUSEPACK = $_musepack
NETWORKING = $networking
OPENAL = $_openal
OSS = $_ossaudio
PE_EXECUTABLE = $_pe_executable
PNG = $_png
PNM = $_pnm
PRIORITY = $_priority
PULSE = $_pulse
PORTAUDIO = $_portaudio
PVR = $_pvr
QTX_CODECS = $_qtx
QTX_CODECS_WIN32 = $_qtx_codecs_win32
QTX_EMULATION = $_qtx_emulation
RADIO=$_radio
RADIO_CAPTURE=$_radio_capture
REAL_CODECS = $_real
RSOUND = $_rsound
SDL = $_sdl
SPEEX = $_speex
STREAM_CACHE = $_stream_cache
TGA = $_tga
TV = $_tv
TV_BSDBT848 = $_tv_bsdbt848
TV_DSHOW = $_tv_dshow
TV_V4L2 = $_tv_v4l2
UNRAR_EXEC = $_unrar_exec
V4L2 = $_v4l2
VCD = $_vcd
VDPAU = $_vdpau
VORBIS = $_vorbis
VSTREAM = $_vstream
WIN32DLL = $_win32dll
WIN32_EMULATION = $_win32_emulation
X11 = $_x11
XANIM_CODECS = $_xanim
XMMS_PLUGINS = $_xmms
XV = $_xv
XVID4 = $_xvid
YUV4MPEG = $_yuv4mpeg

CONFIG_VDPAU    = $_vdpau
CONFIG_ZLIB     = $_zlib

HAVE_PTHREADS   = $_pthreads
HAVE_SHM        = $_shm
HAVE_W32THREADS = $_w32threads

EOF

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

ff_config_enable () {
list=$(echo $1 | tr '[a-z]' '[A-Z]')
item=$(echo $2 | tr '[a-z]' '[A-Z]')
_nprefix=$3;
test -z "$_nprefix" && _nprefix='CONFIG'
for part in $list; do
  if $(echo $item | grep -q -E "(^| )$part($| )"); then
    echo "#define ${_nprefix}_$part 1"
  else
    echo "#define ${_nprefix}_$part 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

#define CONFIGURATION "$configuration"

#define MPLAYER_CONFDIR "$_confdir"
#define MPLAYER_LOCALEDIR "$_localedir"

$def_translation

/* definitions needed by included libraries */
#define HAVE_INTTYPES_H 1
/* libdvdcss */
#define HAVE_ERRNO_H 1
/* libdvdcss + libdvdread */
#define HAVE_LIMITS_H 1
/* libdvdcss */
#define HAVE_UNISTD_H 1
/* libdvdread */
#define STDC_HEADERS 1
#define HAVE_MEMCPY 1
/* libdvdnav */
#define READ_CACHE_TRACE 0
/* libdvdread */
#define HAVE_DLFCN_H 1
$def_dvdcss


/* system headers */
$def_alloca_h
$def_altivec_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_nanosleep
$def_posix_select
$def_select
$def_setenv
$def_setmode
$def_shm
$def_strsep
$def_swab
$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_priority
$def_quicktime
$def_restrict_keyword
$def_rtc
$def_unrar_exec


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


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


/* Blu-ray/DVD/VCD/CD */
#define DEFAULT_CDROM_DEVICE "$default_cdrom_device"
#define DEFAULT_DVD_DEVICE   "$default_dvd_device"
$def_bluray
$def_bsdi_dvd
$def_cdda
$def_cddb
$def_cdio
$def_cdrom
$def_dvd
$def_dvd_bsd
$def_dvd_darwin
$def_dvd_linux
$def_dvd_openbsd
$def_dvdio
$def_dvdnav
$def_dvdread
$def_hpux_scsi_h
$def_sol_scsi_h
$def_vcd


/* codec libraries */
$def_faad
$def_liba52
$def_libdca
$def_libdv
$def_mad
$def_mpg123
$def_musepack
$def_speex
$def_theora
$def_tremor
$def_vorbis
$def_xvid
$def_zlib

$def_libpostproc
$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"


/* Audio output drivers */
$def_alsa
$def_coreaudio
$def_jack
$def_openal
$def_openal_h
$def_ossaudio
$def_ossaudio_devdsp
$def_ossaudio_devmixer
$def_pulse
$def_portaudio
$def_rsound

$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_v4l2
$def_tv
$def_tv_bsdbt848
$def_tv_dshow
$def_tv_v4l2


/* font stuff */
$def_ass
$def_enca

/* networking */
$def_closesocket
$def_ftp
$def_inet6
$def_inet_aton
$def_inet_pton
$def_networking
$def_smb
$def_libquvi
$def_socklen_t
$def_vstream

$def_lcms2


/* libvo options */
$def_caca
$def_corevideo
$def_cocoa
$def_sharedbuffer
$def_direct3d
$def_directfb
$def_directx
$def_dvbin
$def_gif
$def_gif_4
$def_gif_tvt_hack
$def_gl
$def_gl_cocoa
$def_gl_win32
$def_gl_x11
$def_gl_sdl
$def_jpeg
$def_md5sum
$def_mng
$def_png
$def_pnm
$def_sdl
$def_sdl_sdl_h
$def_tga
$def_v4l2
$def_vdpau
$def_vm
$def_x11
$def_xdpms
$def_xf86keysym
$def_xinerama
$def_xss
$def_xv
$def_yuv4mpeg


$def_fast_64bit
$def_fast_unaligned
$def_pthreads

/* Use these registers in x86 inline asm. No proper detection yet. */
#define HAVE_EBP_AVAILABLE 1

#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

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

cat << EOF

Config files successfully generated by ./configure $configuration !

  Install prefix: $_prefix
  Config direct.: $_confdir

  Byte order: $_byte_order
  Optimizing for: $_optimizing

  Languages:
    Messages (in addition to English): $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


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-runtime-cpudetection 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 set by you,
but:

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

It is strongly recommended to let MPlayer choose the correct CFLAGS!
To do so, execute 'CFLAGS= ./configure <options>'

EOF
fi

# Last move:
rm -rf "$mplayer_tmpdir"
