dnl
dnl This file is part of VICE, the Versatile Commodore Emulator.
dnl See README for copyright notice.
dnl
dnl Process this file with GNU autoconf to produce a configure script.
dnl

AC_INIT(src/maincpu.c)

dnl Command-line options
VICE_ARG_INIT()

VICE_VERSION_MAJOR=3
VICE_VERSION_MINOR=0
VICE_VERSION_BUILD=0

dnl Miminum required version of yasm to build static/shared ffmpeg
YASM_VERSION_MAJOR=1
YASM_VERSION_MINOR=2
YASM_VERSION_BUILD=0


VICE_ARG_WITH_LIST(xaw3d,         [  --with-xaw3d            use Xaw3d library instead of plain Xaw])
VICE_ARG_WITH_LIST(readline,      [  --without-readline      do not try to use the system's readline library])
VICE_ARG_WITH_LIST(midas,         [  --with-midas            use MIDAS sound system instead of Allegro for audio])
VICE_ARG_WITH_LIST(arts,          [  --with-arts             use aRts sound system])
VICE_ARG_WITH_LIST(pulse,         [  --without-pulse         do not use PulseAudio sound system])
VICE_ARG_WITH_LIST(alsa,          [  --without-alsa          do not use the ALSA sound system])
VICE_ARG_WITH_LIST(oss,           [  --without-oss           do not use the OSS sound system])
VICE_ARG_WITH_LIST(sdlsound,      [  --with-sdlsound         use SDL sound system])
VICE_ARG_WITH_LIST(resid,         [  --without-resid         do not use the reSID engine])
VICE_ARG_WITH_LIST(jpeg,          [  --without-jpeg          do not use the JPEG screenshot system])
VICE_ARG_WITH_LIST(png,           [  --without-png           do not use the PNG screenshot system])
VICE_ARG_WITH_LIST(zlib,          [  --without-zlib          do not use the zlib support])
VICE_ARG_WITH_LIST(picasso96,     [  --with-picasso96        use Amiga P96 grafix system instead of cgx])
VICE_ARG_WITH_LIST(cocoa,         [  --with-cocoa            enables native Cocoa UI on Macs])
VICE_ARG_WITH_LIST(uithreads,     [  --with-uithreads        enables multi threading for Unix UIs])
VICE_ARG_ENABLE_LIST(textfield,   [  --disable-textfield     disable enhanced text field widget])
VICE_ARG_ENABLE_LIST(fullscreen,  [  --disable-fullscreen    disable XFree86 fullscreen detection])
VICE_ARG_ENABLE_LIST(gnomeui,     [  --enable-gnomeui        enables GNOME UI with GTK2 support])
VICE_ARG_ENABLE_LIST(gnomeui3,    [  --enable-gnomeui3       enables GNOME UI with GTK3 support])
VICE_ARG_ENABLE_LIST(sdlui,       [  --enable-sdlui          enables SDL UI support])
VICE_ARG_ENABLE_LIST(sdlui2,      [  --enable-sdlui2         enables SDL2 UI support])
VICE_ARG_ENABLE_LIST(nls,         [  --disable-nls           disables national language support])
VICE_ARG_ENABLE_LIST(vte,         [  --disable-vte           disable VTE support])
VICE_ARG_ENABLE_LIST(realdevice,  [  --disable-realdevice    disables access to real peripheral devices (CBM4Linux/OpenCBM)])
VICE_ARG_ENABLE_LIST(shared-ffmpeg, [  --enable-shared-ffmpeg  enable included shared FFmpeg support])
VICE_ARG_ENABLE_LIST(static-ffmpeg, [  --enable-static-ffmpeg  enable included static FFmpeg support])
VICE_ARG_ENABLE_LIST(external-ffmpeg, [ --enable-external-ffmpeg  enable external FFmpeg support])
VICE_ARG_ENABLE_LIST(quicktime,   [  --enable-quicktime      enables Apple QuickTime support])
VICE_ARG_ENABLE_LIST(ethernet,    [  --enable-ethernet       enables The Final Ethernet emulation])
VICE_ARG_ENABLE_LIST(ipv6,        [  --disable-ipv6          disables the checking for IPv6 compatibility])
VICE_ARG_ENABLE_LIST(ssi2001,     [  --disable-ssi2001       disables SSI2001 (ISA SID card) support])
VICE_ARG_ENABLE_LIST(catweasel,   [  --disable-catweasel     disables CatWeasel (PCI/Zorro/Clockport SID card) support])
VICE_ARG_ENABLE_LIST(hardsid,     [  --disable-hardsid       disables HardSID support])
VICE_ARG_ENABLE_LIST(parsid,      [  --disable-parsid        disables ParSID support])
VICE_ARG_ENABLE_LIST(bundle,      [  --disable-bundle        do not use application bundles on Macs])
VICE_ARG_ENABLE_LIST(memmap,      [  --enable-memmap         enable the memmap feature])
VICE_ARG_ENABLE_LIST(unicode,     [  --enable-unicode        enable Unicode UI on WinNT])
VICE_ARG_ENABLE_LIST(editline,    [  --disable-editline      disable history in Cocoa UI's console])
VICE_ARG_ENABLE_LIST(lame,        [  --disable-lame          disable MP3 export with LAME])
VICE_ARG_ENABLE_LIST(static-lame, [  --enable-static-lame    enable static LAME linking])
VICE_ARG_ENABLE_LIST(rs232,       [  --disable-rs232         disable RS232 support])
VICE_ARG_ENABLE_LIST(midi,        [  --disable-midi          disable MIDI support])
VICE_ARG_ENABLE_LIST(platformdox, [  --enable-platformdox    enable generating of documentation specific to the current host])
VICE_ARG_ENABLE_LIST(embedded,    [  --enable-embedded       enable embedding of emulation data files])
VICE_ARG_ENABLE_LIST(hidmgr,      [  --disable-hidmgr        disable IOHIDManager joystick support on Mac])
VICE_ARG_ENABLE_LIST(hidutils,    [  --disable-hidutils      disable HID Uitlities joystick support on Mac])
VICE_ARG_ENABLE_LIST(debug,       [  --enable-debug          enable debug source options])
VICE_ARG_ENABLE_LIST(native-tools,[  --enable-native-tools[[=compiler]]    enable native tools instead of scripts])

dnl register ReSID options here to pass arg checks
VICE_ARG_ENABLE_LIST(inline,      [  --enable-inline         enable inlining of functions [default=yes]])
VICE_ARG_ENABLE_LIST(arch,        [  --enable-arch[[=arch]]    enable architecture specific compilation [[default=yes]]], [], [enable_arch=yes])
VICE_ARG_ENABLE_LIST(no-pic,      [  --enable-no-pic         enable the use of the no-pic switch [[default=yes]]])

dnl this hack is needed because the default for the auto-tools
dnl is 'no', and we want the default to be 'yes' unless
dnl '--disable-option-checking' is used.
enable_option_checking=yes
for command_option in $@
do
  if test x"$command_option" = "x--disable-option-checking"; then
    enable_option_checking=no
  fi
done

dnl check for invalid options
echo "option checking is $enable_option_checking"
if test x"$enable_option_checking" = "xyes"; then
  VICE_ARG_LIST_CHECK()
fi

dnl check for conflicting ui options
vice_ui_list="--enable-gnomeui --enable-gnomeui3 --enable-sdlui --enable-sdlui2 --with-cocoa"
vice_ui_1=none
vice_ui_2=none

for command_option in $@
do
  for vice_ui in $vice_ui_list
  do
    if test x"$command_option" = x"$vice_ui"; then
      if test x"$vice_ui_1" = "xnone"; then
        vice_ui_1=$vice_ui
      else
        vice_ui_2=$vice_ui
      fi
    fi
  done
done

if test x"$vice_ui_1" != "xnone" -a x"$vice_ui_2" != "xnone"; then
  AC_MSG_ERROR([conflicting UI options: $vice_ui_1 $vice_ui_2])
fi


dnl Test for bash for building static/shared ffmpeg
if test x"$enable_shared_ffmpeg" = "xyes" -o x"$enable_static_ffmpeg" = "xyes"; then
  AC_CHECK_PROG(ffmpeg_have_bash, bash, "yes", "no")
  if test x"$ffmpeg_have_bash" != "xyes"; then
    AC_MSG_ERROR([bash is required for ffmpeg compiling])
  fi
fi

dnl check for conflicting ffmpeg options
vice_ffmpeg_list="--enable-static-ffmpeg --enable-shared-ffmpeg --enable-external-ffmpeg"
vice_ffmpeg_1=none
vice_ffmpeg_2=none

for command_option in $@
do
  for vice_ffmpeg in $vice_ffmpeg_list
  do
    if test x"$command_option" = x"$vice_ffmpeg"; then
      if test x"$vice_ffmpeg_1" = "xnone"; then
        vice_ffmpeg_1=$vice_ffmpeg
      else
        vice_ffmpeg_2=$vice_ffmpeg
      fi
    fi
  done
done

if test x"$vice_ffmpeg_1" != "xnone" -a x"$vice_ffmpeg_2" != "xnone"; then
  AC_MSG_ERROR([conflicting FFMPEG options: $vice_ffmpeg_1 $vice_ffmpeg_2])
fi

dnl enable_gnomeui3 is only checked for special cases.
if test x"$enable_gnomeui3" = "xyes"; then
  enable_gnomeui="yes"
fi

AC_SUBST(VICE_VERSION_MAJOR)
AC_SUBST(VICE_VERSION_MINOR)
AC_SUBST(VICE_VERSION_BUILD)

if test x"$VICE_VERSION_BUILD" = "x" -o x"$VICE_VERSION_BUILD" = "x0" ; then
  VICE_VERSION=$VICE_VERSION_MAJOR"."$VICE_VERSION_MINOR
else
  VICE_VERSION=$VICE_VERSION_MAJOR"."$VICE_VERSION_MINOR"."$VICE_VERSION_BUILD
  AC_DEFINE(UNSTABLE,,[Define if this version is unstable.])
fi
AC_SUBST(VICE_VERSION)

AM_INIT_AUTOMAKE(vice, $VICE_VERSION)
AM_CONFIG_HEADER(src/config.h)

if test x"$VICE_VERSION_BUILD" = "x" -o x"$VICE_VERSION_BUILD" = "x0" ; then
  VERSION_RC=$VICE_VERSION_MAJOR","$VICE_VERSION_MINOR",0,0"
else
  VERSION_RC=$VICE_VERSION_MAJOR","$VICE_VERSION_MINOR","$VICE_VERSION_BUILD",0"
fi
AC_SUBST(VERSION_RC)

AC_DEFINE(VERSION_RC,"$VERSION_RC",[Win32 Version string.])

VERSION_COMBINED=`expr $VICE_VERSION_MAJOR \* 65536 + $VICE_VERSION_MINOR \* 256 + $VICE_VERSION_BUILD`
AC_SUBST(VERSION_COMBINED)

is_unix=no
is_unix_x11=no
is_unix_macosx=no
is_dos=no
is_win32=no
is_win32_x11=no
is_os2=no
is_beos=no
is_beos_x11=no
is_amiga=no

HAVE_FULLSCREEN_SUPPORT="no "
HAVE_OPENGL_SYNC_SUPPORT="no "
HAVE_CAIRO_SUPPORT="no "
HAVE_PANGO_SUPPORT="no "
HAVE_HWSCALE_SUPPORT="no "
USE_XF86_EXTENSIONS_SUPPORT="no "
USE_MITSHM_SUPPORT="no "
USE_XF86_VIDMODE_EXT_SUPPORT="no "
HAVE_XVIDEO_SUPPORT="no "
HAVE_XRANDR_SUPPORT="no "
USE_UI_THREADS_SUPPORT="no "
HAVE_LIBXPM_SUPPORT="no "
HAVE_VTE_SUPPORT="no "
HAVE_D3D9_H_SUPPORT="no "
ENABLE_UNICODE_API_SUPPORT="no "

HAVE_CATWEASELMKIII_SUPPORT="no "
HAVE_HARDSID_SUPPORT="no "
HAVE_MIDI_SUPPORT="no "
HAVE_PARSID_SUPPORT="no "
HAVE_SSI2001_SUPPORT="no "
HAVE_IOSID_SUPPORT="no "
HAVE_PORTSID_SUPPORT="no "
HAVE_PCIUTILS_SUPPORT="no "
HAVE_SYS_AUDIO_H_SUPPORT="no "
HAVE_SYS_AUDIOIO_H_SUPPORT="no "
USE_AIX_AUDIO_SUPPORT="no "
USE_ALSA_SUPPORT="no "
USE_ARTS_SUPPORT="no "
USE_DMEDIA_SUPPORT="no "
USE_OSS_SUPPORT="no "
USE_PORTAUDIO_SUPPORT="no "
USE_PULSE_SUPPORT="no "
USE_SDL_AUDIO_SUPPORT="no "
USE_LAMEMP3_SUPPORT="no "
USE_MPG123_SUPPORT="no "
USE_FLAC_SUPPORT="no "
USE_VORBIS_SUPPORT="no "
USE_COREAUDIO_SUPPORT="no "
HAVE_AUDIO_UNIT_SUPPORT="no "
USE_ALLEGRO_SOUND_SUPPORT="yes"
USE_MIDAS_SOUND_SUPPORT="no "
HAVE_DEVICES_AHI_H_SUPPORT="no "
USE_DXSOUND_SUPPORT="no "

HAVE_GIF_SUPPORT="no "
HAVE_JPEG_SUPPORT="no "
HAVE_PNG_SUPPORT="no "

HAVE_FFMPEG_SUPPORT="no "
HAVE_FFMPEG_SWSCALE_SUPPORT="no "
HAVE_FFMPEG_SWRESAMPLE_SUPPORT="no "
HAVE_FFMPEG_AVRESAMPLE_SUPPORT="no "
SHARED_FFMPEG_SUPPORT="no "
STATIC_FFMPEG_SUPPORT="no "
HAVE_QUICKTIME_SUPPORT="no "

HAS_JOYSTICK_SUPPORT="no "
HAVE_MOUSE_SUPPORT="no "
HAVE_LIGHTPEN_SUPPORT="no "
LINUX_JOYSTICK_SUPPORT="no "
BSD_JOYSTICK_SUPPORT="no "
HAS_DIGITAL_JOYSTICK_SUPPORT="no "
HAS_USB_JOYSTICK_SUPPORT="no "
MAC_JOYSTICK_SUPPORT="no "
HAS_HIDMGR_SUPPORT="no "
HAVE_DINPUT_SUPPORT="no "
HAVE_SDL_NUMJOYSTICKS_SUPPORT="no "

HAVE_RS232DEV_SUPPORT="no "
HAVE_NETWORK_SUPPORT="no "
HAVE_RS232NET_SUPPORT="no "
HAVE_IPV6_SUPPORT="no "
HAVE_PCAP_SUPPORT="no "

HAVE_RAWDRIVE_SUPPORT="no "
HAVE_OPENCBM_SUPPORT="no "

HAVE_DYNLIB_SUPPORT_TOO="no "

HAVE_ZLIB_SUPPORT="no "
HAVE_LIBIEEE1284_SUPPORT="no "
ENABLE_NLS_SUPPORT="no "
HAVE_PROTO_OPENPCI_H_SUPPORT="no "

HAVE_RESID_SUPPORT="no "
FEATURE_CPUMEMHISTORY_SUPPORT="no "
DEBUG_SUPPORT="no "
USE_EMBEDDED_SUPPORT="no "

dnl Try to find out which system we are on...
AC_CANONICAL_HOST

if test x"$enable_memmap" = "xyes"; then
  AC_DEFINE(FEATURE_CPUMEMHISTORY,,[Use the memmap feature.])
  FEATURE_CPUMEMHISTORY_SUPPORT="yes"
fi

if test x"$enable_gnomeui" = "xyes" ; then
  AC_DEFINE(USE_GNOMEUI,,[Use GNOME UI.])
fi

AM_CONDITIONAL(GNOMEUI, test x"$enable_gnomeui" = "xyes")

if test x"$with_cocoa" = "xyes" ; then
  AC_DEFINE(MACOSX_COCOA,,[Use Cocoa on Macs.])
fi

AM_CONDITIONAL(MACOSX_COCOA, test x"$with_cocoa" = "xyes")

AM_CONDITIONAL(VICE_QUIET, test x"$verbose" != "xyes")

if test x"$enable_textfield" != "xno"; then
  AC_DEFINE(ENABLE_TEXTFIELD,,[Enable support for the TextField widget.])
  echo "using TextField widget."
else
  echo "using ugly Athena text widget."
fi

user_cflags=$CFLAGS
AC_PROG_CC([gcc clang cc])
AC_LIB_PROG_LD


dnl Set proper mkfontdir path for QNX6
case "$host_os" in
  nto*)
    if test -d "/opt/X11R6"; then
      AC_SUBST(MKFONTDIR_BIN, "/opt/X11R6/bin/mkfontdir")
    else
      if test -d "/opt/X11R7"; then
        AC_SUBST(MKFONTDIR_BIN, "/opt/X11R7/bin/mkfontdir")
      fi
    fi
    ;;
  *)
    AC_SUBST(MKFONTDIR_BIN, "mkfontdir")
    ;;
esac


dnl Add runtime/linker paths for OpenIndiana
case "$host_os" in
  solaris*)
    CPPFLAGS="$CPPFLAGS -I/usr/gnu/include"
    solrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" /usr/gnu/bin/ld yes "$host" "/usr/gnu/lib"`
    LDFLAGS="$LDFLAGS $solrtp -L/usr/gnu/lib"
    if test -d "/opt/csw"; then
      CPPFLAGS="$CPPFLAGS -I/opt/csw/include"
      solrtp_csw=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" /usr/gnu/bin/ld yes "$host" "/opt/csw/lib"`
      LDFLAGS="$LDFLAGS $solrtp_csw -L/opt/csw/lib"
    fi
    ;;
esac


dnl Add runtime/linker paths for *BSD
case "$host_os" in
  freebsd*)
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
    fbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/local/lib"`
    LDFLAGS="$LDFLAGS $fbsdrtp -L/usr/local/lib"
    ;;
  netbsd*)
    CPPFLAGS="$CPPFLAGS -I/usr/pkg/include -I/usr/include"
    nbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/pkg/lib"`
    LDFLAGS="$LDFLAGS $nbsdrtp -L/usr/pkg/lib"
    if test -d "/usr/X11R7/lib"; then
      rtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/X11R7/lib"`
      LDFLAGS="$LDFLAGS $rtp"
    else
      if test -d "/usr/X11R6/lib"; then
        rtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/X11R6/lib"`
        LDFLAGS="$LDFLAGS $rtp"
      fi
    fi
    ;;
  dragonfly*)
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
    dfbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/local/lib"`
    LDFLAGS="$LDFLAGS $dfbsdrtp -L/usr/local/lib"
    ;;
  *)
    ;;
esac


AC_HEADER_TIOCGWINSZ

dnl --- setup Objective-C ---
OBJC="${CC}"
if test -z "x${OBJCFLAGS}"; then
  OBJCFLAGS="${CFLAGS}"
fi
OBJCDEPMODE="depmode=${CC}"
AC_SUBST(OBJC)
AC_SUBST(OBJCFLAGS)
dnl AC_SUBST(OBJCDEPMODE)
_AM_DEPENDENCIES([OBJC])

if test x"$host_os" = "xminixvmd"; then
  AR="\$(top_srcdir)/src/arch/unix/minix/minix-ar.sh"
  AC_DEFINE(MINIXVMD,,[are we compiling under Minix-Vmd])
  CFLAGS="$CFLAGS -I/usr/include/bsdcompat"
fi

dnl check for GNU make for static/shared ffmpeg
if test x"$enable_shared_ffmpeg" = "xyes" -o x"$enable_static_ffmpeg" = "xyes"; then
  make_cmd=""
  for i in "$MAKE" make gmake gnumake
  do
    test -x "$i" && continue
      if ( sh -c "$i --version" 2>/dev/null | grep GNU >/dev/null )
      then
        make_cmd=$i;
        break;
      fi
  done
  if test x"$make_cmd" = "x"; then
    AC_MSG_ERROR([When using internal FFMPEG a GNU make command is needed])
  else
    MAKE="$make_cmd"
  fi
fi

if test x"$host_os" = "xminix"; then
  AC_DEFINE(MINIX_SUPPORT,,[do we need minix support])
  CFLAGS="$CFLAGS -D_MINIX -D_POSIX_SOURCE"
  MINIX_RELEASE=`uname -r | cut -c1`
  MINIX_VERSION=`uname -v`
  if test x"$MINIX_RELEASE" != "x3"; then
    AC_MSG_ERROR([VICE works only on minix 3 and up])
  fi
  case "$MINIX_VERSION" in
    1.3*)
      AC_DEFINE(MINIX_HAS_RECV_SEND,,[Define if this version of minix has the recv and send prototypes])
      ;;
  esac  
  AM_CONDITIONAL(MINIX_SUPPORT, true)
else
  AM_CONDITIONAL(MINIX_SUPPORT, false)
fi

if test x"$host_os" = "xcygwin32" -o x"$host_os" = "xcygwin"; then
  if test x"$with_x" = "xyes"; then
    host_os=cygwin-x11
    is_win32_x11=yes
  fi
fi

if test x"$host_os" = "xbeos" -o x"$host_os" = "xhaiku"; then
  if test x"$with_x" = "xyes"; then
    host_os=x11beos
    is_beos_x11=yes
    is_unix=yes
    AC_DEFINE(BEOS_COMPILE,,[Are we compiling for either BeOS or Haiku?])
  fi
fi

dnl disable toolchain and ar checking for ppc-beos
if test x"$host_os" = "xbeos" -a x"$host_cpu" = "xpowerpc"; then
  toolchain_check=no
  ar_check=no
fi

dnl disable ar checking for nextstep, openstep and rhapsody
case "$host_os" in
  nextstep*|openstep*|rhapsody*)
    ar_check=no
    posix_check=yes
    ;;
esac

dnl Enable the SDL UI by default for syllable.
if test x"$host_os" = "xsyllable"; then
  enable_sdlui=yes
fi

dnl Disable nls for the SDL UI
if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
  enable_nls=no
fi


if test "x$CC" = "xgcc"; then
  GCC=yes
fi

dnl test for openwatcom CC for library conversion
if test x"$CC" = "xowcc"; then
  CFLAGS="$CFLAGS -O2"
  AM_CONDITIONAL(OWCC, true)
  AC_DEFINE(WATCOM_COMPILE,,[owcc is being used.])
  toolchain_check=no
  ar_check=no
  nowarnings=yes
else
  AM_CONDITIONAL(OWCC, false)
fi

if test x"$enable_arch" = "xno"; then
  march=""
  ENABLE_ARCH=no
else
  if test x"$enable_arch" = "xyes"; then
    AC_MSG_CHECKING([if the compiler supports -march=native])
    ORIG_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -march=native"
    AC_TRY_COMPILE([],
                   [int test;],
                   [ AC_MSG_RESULT(yes)
                     ENABLE_ARCH=yes
                     march="-march=native" ],
                   [ AC_MSG_RESULT(no)
                     ENABLE_ARCH=no
                     march="" ])
    CFLAGS=$ORIG_CFLAGS
  else
    AC_MSG_CHECKING([if the compiler supports -march=$enable_arch])
    ORIG_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -march=$enable_arch"
    AC_TRY_COMPILE([],
                   [int test;],
                   [ AC_MSG_RESULT(yes)
                     ENABLE_ARCH=yes
                     march="-march=$enable_arch" ],
                   [ AC_MSG_RESULT(no)
                     ENABLE_ARCH=no
                     march="" ])
    CFLAGS=$ORIG_CFLAGS
  fi
fi

AC_SUBST(ENABLE_ARCH)

dnl check if the compiler supports -posix
if test x"$posix_check" = "xyes"; then
  AC_MSG_CHECKING([if the compiler supports -posix])
  ORIG_CFLAGS=$CFLAGS
  CFLAGS="$CFLAGS -posix"
  AC_TRY_COMPILE([],
                 [int test;],
                 [ AC_MSG_RESULT(yes)],
                 [ AC_MSG_RESULT(no)
                   CFLAGS=$ORIG_CFLAGS ])
fi

dnl Check for needed external programs.
AC_PROG_CPP
AC_CHECK_PROG(AR, ar, ar, ar)
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(STRIP, strip, :)
AC_CHECK_PROG(SVN, svn, svn, :)
AC_CHECK_PROG(TAR, tar, tar, :)
AC_CHECK_PROG(SVNVERSION, svnversion, svnversion, :)
AC_PROG_INSTALL
AC_PROG_LN_S

dnl Check for large file support
AC_SYS_LARGEFILE

if test x"$enable_static_ffmpeg" = "xyes" -o x"$enable_shared_ffmpeg" = "xyes"; then
  AC_CHECK_PROG(YASM, yasm, yasm, no)
  if test x"$YASM" = "xno"; then
    AC_MSG_ERROR([yasm needed for ffmpeg compile])
  fi
  dnl Check minimum yasm version required
  yasm_ver=`$YASM --version | head -n 1 | cut -d ' ' -f 2`
  yasm_maj=`echo "$yasm_ver" | cut -d '.' -f 1`
  yasm_min=`echo "$yasm_ver" | cut -d '.' -f 2`
  yasm_rev=`echo "$yasm_ver" | cut -d '.' -f 3`
  yasm_ok=false

  if test $yasm_maj -gt $YASM_VERSION_MAJOR; then
    yasm_ok=true
  elif test $yasm_maj -eq $YASM_VERSION_MAJOR; then
    if test $yasm_min -gt $YASM_VERSION_MINOR; then
      yasm_ok=true
    elif test $yasm_min -eq $YASM_VERSION_MINOR; then
      if test $yasm_rev -ge $YASM_VERSION_BUILD; then
        yasm_ok=true
      fi
    fi
  fi

  if test x"$yasm_ok" != x"true"; then
    AC_MSG_ERROR([yasm 1.2.0 or higher required])
  fi
fi

AC_CHECK_PROGS(YACC, byacc yacc 'bison -y', [no])
if test x"$YACC" = "xno"; then
  AC_MSG_ERROR([Could not find byacc, yacc or bison!])
fi

dnl do not use --noyywrap option with flex as older versions do not support
dnl it. FIXME: We should really have a compatibility test here.
dnl AC_CHECK_PROGS(LEX, 'flex --noyywrap', [no])

dnl if test x"$LEX" = "xno"; then
dnl   unset LEX
dnl fi

AC_PROG_LEX

if test x"$LEX" = "x:"; then
  AC_MSG_ERROR([Could not find either flex or lex!])
fi

AM_PROG_AS

dnl check if ar truncates object names
if test x"$ar_check" != "xno"; then
  AC_MSG_CHECKING(if ar truncates object names)
  rm -f vicetest.c
  touch vicetest.c
  $CC -c vicetest.c -o some_long_object_name.o
  rm -f vicetest.c
  rm -f libvicetest.a
  $AR cru libvicetest.a some_long_object_name.o
  rm -f some_long_object_name.o
  $AR x libvicetest.a
  if test -f some_long_object_name.o; then
    AC_MSG_RESULT(no)
    rm -f some_long_object_name.o libvicetest.a
  else
    AC_MSG_RESULT(yes)
    rm -f some*.o libvicetest.a
    AC_MSG_ERROR([ar is too old, upgrade your ar])
  fi
fi

dnl check if ar needs a wrapper to get rid of the 'u' option
if test x"$ar_check" != "xno"; then
  AC_MSG_CHECKING(if ar complains about the 'u' option)
  rm -f vicetest.c
  touch vicetest.c
  $CC -c vicetest.c -o vicetest.o
  rm -f vicetest.c
  rm -f libvicetest.a
  complains=`$AR cru libvicetest.a vicetest.o 2>&1`
  if test x"$complains" != "x"; then
    AC_MSG_RESULT(yes)
    echo "using ar wrapper instead of ar directly"
    AR_WRAP="$AR"
    AR="\$(top_srcdir)/src/wrap-u-ar.sh \"$AR_WRAP\""
  else
    AC_MSG_RESULT(no)
  fi
fi

AC_CHECK_PROGS(MAKEINFO, makeinfo, no)

AC_CHECK_PROGS(TEXI2DVI, texi2dvi, no)
AC_CHECK_PROGS(PDFTEX, pdftex, no)
if test x"$TEXI2DVI" = "xno" -o x"$PDFTEX" = "xno"; then
  AM_CONDITIONAL(BUILD_PDF, false)
else
  AM_CONDITIONAL(BUILD_PDF, true)
fi

AC_CHECK_PROGS(DOS2UNIX, dos2unix, dos2unix)

if test x"$SVN" != "x:"; then
  svnrevision=`$SVN 2>dummy.tmp info $ac_dir | grep Revision | cut -d " " -f 2`
  rm dummy.tmp
  if test x"$svnrevision" != "x"; then
    AM_CONDITIONAL(USE_SVN_REVISION, true)
    AC_DEFINE(USE_SVN_REVISION,,[define when using the svn revision in addition to the version])
  else
    AM_CONDITIONAL(USE_SVN_REVISION, false)
  fi
else
  AM_CONDITIONAL(USE_SVN_REVISION, false)
fi

dnl Setup crosscompiling.
if test x"$host_vendor" = "xgo32" -o x"$host_vendor" = "xmsdos" -o x"$host_os" = "xmsdosdjgpp"; then

  dnl Some GCC cross-compilers are installed with a different name
  dnl instead of using the GCC architecture targeting features.
  dnl Check for the most common ones.

  dnl This is used by subsequent tests.
  ac_cv_prog_gcc=yes
  GCC=yes

  is_dos=yes

  if test x"$with_midas" = "xyes" ; then
      USE_MIDAS_SOUND_SUPPORT="yes"
      USE_ALLEGRO_SOUND_SUPPORT="no "
      AC_DEFINE(USE_MIDAS_SOUND,,
                [Use MIDAS Sound System instead of the Allegro library.])
      LIBMIDAS="-lmidas"
      echo "configuring support for MIDAS Sound System"
  else
      LIBMIDAS=""
      echo "using Allegro sound driver"
  fi

  AM_CONDITIONAL(HAVE_RAWDRIVE, false)

  dnl We always have a joystick and mouse on MSDOS.
  AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
  HAS_JOYSTICK_SUPPORT="yes"
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"
  AC_DEFINE(HAS_SINGLE_CANVAS,,[Is only one canvas supported?])

  if test x"$enable_catweasel" != "xno"; then
    AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
    HAVE_CATWEASELMKIII_SUPPORT="yes"
  fi

  if test x"$enable_hardsid" != "xno"; then
    AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
    HAVE_HARDSID_SUPPORT="yes"
  fi

  if test x"$enable_parsid" != "xno"; then
    AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
    HAVE_PARSID_SUPPORT="yes"
  fi

  if test x"$enable_ssi2001" != "xno"; then
    AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
    HAVE_SSI2001_SUPPORT="yes"
  fi

  dnl disable resid
  dnl with_resid=no

elif test x"$host_os" = "xamigaos" -o x"$host_os" = "xamigaos4" -o x"$host_os" = "xamithlon" -o x"$host_os" = "xaros" -o x"$host_os" = "xmorphos" -o x"$host_os" = "xwarpos" -o x"$host_os" = "xpowerup"; then
  AM_CONDITIONAL(HAVE_RAWDRIVE, true)

  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
      if test x"$enable_rs232" != "xno"; then
        AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
        HAVE_RS232DEV_SUPPORT="yes"
      fi
      AC_DEFINE(HAVE_RAWDRIVE,,[Support for block device disk image access.])
      HAVE_RAWDRIVE_SUPPORT="yes"
      AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
      HAS_JOYSTICK_SUPPORT="yes"
      AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
      HAVE_MOUSE_SUPPORT="yes"
  fi

  AC_DEFINE(AMIGA_SUPPORT,,[Should we enable Amigaos support.])

  is_amigaos4=yes
  is_amigaos3=no
  is_amiga_aros=no
  is_amiga_morphos=no
  openpci_present=no

  if test x"$host_os" = "xmorphos"; then
    AC_DEFINE(AMIGA_MORPHOS,,[Should we enable Amiga Morphos support.])
    CFLAGS="$CFLAGS -noixemul"
    AC_DEFINE(HAVE_HTONL,,[Define to 1 if you have the htonl function.])
    AC_DEFINE(HAVE_HTONS,,[Define to 1 if you have the htons function.])
    AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
    HAVE_NETWORK_SUPPORT="yes"
    AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
    HAVE_RS232NET_SUPPORT="yes"
    AC_CHECK_HEADERS(proto/openpci.h, openpci_present=yes,,)
    if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
        AC_DEFINE(HAVE_XVIDEO,,[Enable XVideo (overlay) support.])
        HAVE_XVIDEO_SUPPORT="yes"
    fi
    if test x"$openpci_present" = "xyes"; then
      if test x"$enable_catweasel" != "xno"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
      if test x"$enable_hardsid" != "xno"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
    fi
    is_amiga_morphos=yes
    is_amigaos4=no
  fi

  if test x"$host_os" = "xaros"; then
    AC_DEFINE(AMIGA_AROS,,[Should we enable AROS support.])
    AC_DEFINE(HAVE_HTONL,,[Define to 1 if you have the htonl function.])
    AC_DEFINE(HAVE_HTONS,,[Define to 1 if you have the htons function.])
    AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
    HAVE_NETWORK_SUPPORT="yes"
    AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
    HAVE_RS232NET_SUPPORT="yes"
    AC_CHECK_HEADERS(aros/_timeval.h)
    AC_MSG_CHECKING(if common library bases are auto resolved)
    aros_common_resolve=no
    AC_TRY_LINK([#include <proto/asl.h>],
                [AbortAslRequest(0)],
                aros_common_resolve=yes)
    if test x"$aros_common_resolve" = "xyes"; then
       AC_MSG_RESULT(yes)
       AC_DEFINE(WORKING_AROS_AUTO,,[Define to 1 if aros can handle auto resolving of library bases.])
    else
       AC_MSG_RESULT(no)
    fi
    is_amigaos4=no
    is_amiga_aros=yes
  fi

  if test x"$host_os" = "xamigaos" -a x"$host_cpu" = "xm68k"; then
    CFLAGS="$CFLAGS -mc68020 -noixemul"
    AC_DEFINE(AMIGA_M68K,,[Should we enable M68K AmigaOS support.])
    AC_DEFINE(HAVE_HTONL,,[Define to 1 if you have the htonl function.])
    AC_DEFINE(HAVE_HTONS,,[Define to 1 if you have the htons function.])
    AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
    HAVE_NETWORK_SUPPORT="yes"
    AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
    HAVE_RS232NET_SUPPORT="yes"
    AC_CHECK_HEADERS(proto/openpci.h, openpci_present=yes,,)
    if test x"$openpci_present" = "xyes"; then
      if test x"$enable_catweasel" != "xno"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
      if test x"$enable_hardsid" != "xno"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
      if test x"$enable_ssi2001" != "xno"; then
        AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001.])
        HAVE_SSI2001_SUPPORT="yes"
      fi
    fi
    is_amigaos4=no
    is_amigaos3=yes
  fi

  if test x"$is_amigaos4" = "xyes"; then
    AC_DEFINE(AMIGA_OS4,,[Should we enable AmigaOS4 support.])
    if test x"$enable_catweasel" != "xno"; then
      AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
      HAVE_CATWEASELMKIII_SUPPORT="yes"
    fi
    if test x"$enable_hardsid" != "xno"; then
      AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
      HAVE_HARDSID_SUPPORT="yes"
    fi
    with_picasso96=yes
    LIBS="$LIBS -lsupc++ -lgcc_eh"
  fi

  is_amiga=yes

  CFLAGS="$CFLAGS -finline-functions"

  if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes" -a x"is_amigaos4" = "xyes"; then
    LIBS="$LIBS -lunix"
  fi

elif test x"$host_os" = "xcygwin32" -o x"$host_os" = "xcygwin" -o x"$host_os" = "xmingw32" -o x"$host_os" = "xmingw32msvc"; then

  dnl This is used by subsequent tests.
  ac_cv_prog_gcc=yes
  GCC=yes

  is_win32=yes

  AC_CHECK_HEADERS([commctrl.h shlobj.h winioctl.h], [], [], [#include <windows.h>])

  AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
  HAS_JOYSTICK_SUPPORT="yes"
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"
  AC_DEFINE(HAVE_HTONL,,[Define to 1 if you have the htonl function.])
  AC_DEFINE(HAVE_HTONS,,[Define to 1 if you have the htons function.])
  AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
  HAVE_NETWORK_SUPPORT="yes"
  AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
  HAVE_RS232NET_SUPPORT="yes"
  if test x"$enable_catweasel" != "xno"; then
    AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
    HAVE_CATWEASELMKIII_SUPPORT="yes"
  fi
  if test x"$enable_hardsid" != "xno"; then
    AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
    HAVE_HARDSID_SUPPORT="yes"
  fi
  if test x"$enable_parsid" != "xno"; then
    AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
    HAVE_PARSID_SUPPORT="yes"

    LIBIEEE1284_HEADERS_PRESENT=yes

    dnl Check for needed io headers
    AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)

    if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
      AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
      if test x"$PARSID_SUPPORT" != "xno"; then
        AC_DEFINE(HAVE_LIBIEEE1284,,[Define to 1 if you have the `ieee1284' library (-lieee1284).])
      fi
    fi
  fi
  if test x"$enable_ssi2001" != "xno"; then
    AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
    HAVE_SSI2001_SUPPORT="yes"
  fi
  if test x"$enable_midi" != "xno"; then
    AC_DEFINE(HAVE_MIDI,,[Enable support for MIDI.])
    HAVE_MIDI_SUPPORT="yes"
  fi
  AC_DEFINE(HAVE_PCAP,,[Support for CS8900A ethernet controller.])
  HAVE_PCAP_SUPPORT="yes"
  if test x"$enable_rs232" != "xno"; then
    AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
    HAVE_RS232DEV_SUPPORT="yes"
  fi

  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    AC_TRY_LINK([#include <windows.h>],
                [LARGE_INTEGER li; return (int) li.QuadPart],
                AC_DEFINE(HAS_LONGLONG_INTEGER,,
                  [Support 64bit integer for Win32 performance counter]),)
    AC_TRY_LINK([#include <windows.h>],
                [HGLOBAL hGlobal; UnlockResource(hGlobal); return 0],
                AC_DEFINE(HAS_UNLOCKRESOURCE,,[Do we have UnlockResource()?]),)
  fi

  AM_CONDITIONAL(HAVE_RAWDRIVE, false)

  dinput_header_no_lib="no"

  dnl don't use dinput for owcc
  if test x"$CC" != "xowcc"; then
    AC_CHECK_HEADER(dinput.h,
                [ HAVE_DINPUT_SUPPORT="yes";
                  AC_DEFINE(HAVE_DINPUT,,[Use DirectInput joystick driver]) ]
                [ AC_MSG_CHECKING(for -ldinput) ]
                [SAVELIBS="$LIBS"] [ LIBS="-ldinput $LIBS" ]
                [ AC_LINK_IFELSE([
                                 AC_LANG_PROGRAM([#include <dinput.h>],[return DirectInputCreateA(0,0,0,0);])
                                 ],
                              [ AC_DEFINE(HAVE_DINPUT_LIB, [], [dinput.lib or libdinput.a are present]) ]
     	                        [ AC_MSG_RESULT(yes) ],
                              [ dinput_header_no_lib="yes" ]
                              [ LIBS="$SAVELIBS" ]
                              [ AC_MSG_RESULT(no) ]
                )]
	  	 )
  fi

  dnl warnings_cxx="-Wall -W -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare"
  if test x"$nowarnings" != "xyes"; then
      warnings_cxx="-Wall -Wno-unused-parameter -Wno-sign-compare"
      CFLAGS="$CFLAGS $warnings_cxx"
      CXXFLAGS="$CXXFLAGS $warnings_cxx"
  fi

elif test x"$host_os" = "xbeos" -o x"$host_os" = "xhaiku"; then

  dnl This is used by subsequent tests.
  ac_cv_prog_gcc=yes
  GCC=yes

  is_beos=yes
  AC_DEFINE(BEOS_COMPILE,,[Are we compiling for either BeOS or Haiku?])

  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    AC_DEFINE(USE_BEOS_UI,,[Are we using the BeOS native UI?])
    AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
    HAS_JOYSTICK_SUPPORT="yes"
    AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
    HAVE_MOUSE_SUPPORT="yes"
  fi
  AM_CONDITIONAL(HAVE_RAWDRIVE, false)

  if test x"$enable_catweasel" != "xno"; then
    AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
    HAVE_CATWEASELMKIII_SUPPORT="yes"
  fi

  if test x"$enable_hardsid" != "xno"; then
    AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
    HAVE_HARDSID_SUPPORT="yes"
  fi

  if test x"$enable_parsid" != "xno"; then
    AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
    HAVE_PARSID_SUPPORT="yes"

    LIBIEEE1284_HEADERS_PRESENT=yes

    dnl Check for needed io headers
    AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)

    if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
      AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
      if test x"$PARSID_SUPPORT" != "xno"; then
        AC_DEFINE(HAVE_LIBIEEE1284,,[Define to 1 if you have the `ieee1284' library (-lieee1284).])
      fi
    fi
  fi

  if test x"$enable_ssi2001" != "xno"; then
    AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
    HAVE_SSI2001_SUPPORT="yes"
  fi

else

dnl check for darwin first.
case "$host_os" in
darwin*)
  dnl check for needed CoreVideo header
  AC_CHECK_HEADERS(CoreVideo/CVHostTime.h)

  dnl check for needed CoreServices header
  AC_CHECK_HEADERS(CoreServices/CoreServices.h)

  dnl change the host_os to puredarwin to make the configure think it is
  dnl just another unix.
  if test x"$ac_cv_header_CoreServices_CoreServices_h" != "xyes"; then
    host_os=puredarwin;
    AC_DEFINE(DARWIN_COMPILE,,[Enable plain darwin compilation])
  fi
  ;;
*)
  ;;
esac

dnl Check for host os with version attached. Typically on UN*X like systems.
case "$host_os" in

dnl Mac OS X Host
darwin*)

  is_unix=yes
  is_unix_macosx=yes

  dnl disable toolchain checking for macosx
  toolchain_check=no

  if test x"$with_cocoa" = "xyes" ; then
    is_unix_x11=no
  else
    is_unix_x11=yes
  fi

  if test -z "$user_cflags" ; then
    if test x"$GCC" = "xyes" ; then
      warnings_cxx="-Wall -Winline"
      warnings_c="-Wstrict-prototypes $warnings_cxx"
      optimization_c="-O3 $march"
      optimization_cxx="-fno-exceptions $optimization_c"
      if test x"$ac_cv_prog_cc_g" = "xyes" ; then
        CFLAGS="-g $optimization_c $warnings_c"
        CXXFLAGS="-g $optimization_cxx $warnings_cxx"
      else
        CFLAGS="$optimization_c $warnings_c"
        CXXFLAGS="$optimization_cxx $warnings_cxx"
      fi 
    fi
  fi

  if test "$GCC" = yes -a "$enable_no_pic" != "no" ; then
    CFLAGS="$CFLAGS -mdynamic-no-pic"
    CXXFLAGS="$CXXFLAGS -mdynamic-no-pic"
  fi

  AM_CONDITIONAL(HAVE_RAWDRIVE, true)
  if test x"$enable_rs232" != "xno"; then
    AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
    HAVE_RS232DEV_SUPPORT="yes"
  fi

  AC_DEFINE(HAVE_RAWDRIVE,,[Support for block device disk image access.])
  HAVE_RAWDRIVE_SUPPORT="yes"
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"

  AC_DEFINE(MACOSX_SUPPORT,,[Enable Mac OS X specific code.])
  if test "x$enable_bundle" != "xno" -o "x$enable_sdlui" = "xyes" -o "x$enable_sdlui2" = "xyes"; then
    echo "enabled Mac application bundles"
    AC_DEFINE(MACOSX_BUNDLE,,[Enable Mac OS X application bundles.])
  else
    echo "disabled Mac application bundles"
  fi
  ;;

dnl All other UN*X systems
*)

  dnl special handling of sco unixware 7.x
  case "$host_os" in
    sco3.2v7*)
      LIBS="-lxti -lsocket -lnsl $LIBS"
      ;;
  esac

  case "$host" in
    *x11beos*)
      LIBS="$LIBS -lbe -ltracker -ldevice -lgame"
      ;;
    alpha*-*-linux*)
      if test x"$CC" = "xccc"; then
        echo "Using Compaq C Compiler cflags."
        CFLAGS="-w0 -g3 -migrate -fast -inline speed -unroll 0 -arch host -tune host"
        AC_DEFINE(__DECALPHA__,1,[define when using the alpha compaq compiler])
      fi
      ;;

    sparc-*-sunos4*)
      if test x"$CC" = "xcc"; then
        echo "Using Sun C Compiler cflags."
        CFLAGS="-O -xCC"
      fi
      ;;

    *-sgi-irix*)
      if test x"$CC" = "xcc"; then
        echo "Using SGI C Compiler cflags."
        CFLAGS="-O2 -woff all"
      fi
      ;;

    alpha*-dec-osf*)
      if test x"$CC" = "xcc"; then
        echo "Using Tru64 C Compiler cflags."
        CFLAGS="-fast -O2 -std -g3 -non_shared"
      fi
      ;;
  esac

  is_unix=yes
  is_unix_x11=yes

  if test -z "$user_cflags" ; then

    dnl Check for the type of compiler first.
    if test x"$GCC" = "xyes" ; then

      AC_MSG_CHECKING([if the compiler supports -Wno-missing-field-initializers])
      ORIG_CFLAGS=$CFLAGS
      CFLAGS="$CFLAGS -Wno-missing-field-initializers"
      AC_TRY_COMPILE([],
                     [int test;],
                     [ AC_MSG_RESULT(yes)
                       warn_no_mfi="-Wno-missing-field-initializers" ],
                     [ AC_MSG_RESULT(no)
                       warn_no_mfi="" ])
      AC_MSG_CHECKING([if the compiler supports -Wno-unused-parameter])
      CFLAGS="$ORIG_CFLAGS -Wno-unused-parameter"
      AC_TRY_COMPILE([],
                     [int test;],
                     [ AC_MSG_RESULT(yes)
                       warn_no_up="-Wno-unused-parameter" ],
                     [ AC_MSG_RESULT(no)
                       warn_no_up="" ])
      AC_MSG_CHECKING([if the compiler supports -Wno-sign-compare])
      CFLAGS="$ORIG_CFLAGS -Wno-sign-compare"
      AC_TRY_COMPILE([],
                     [int test;],
                     [ AC_MSG_RESULT(yes)
                       warn_no_sc="-Wno-sign-compare" ],
                     [ AC_MSG_RESULT(no)
                       warn_no_sc="" ])
      CFLAGS=$ORIG_CFLAGS

      warnings_cxx="-Wall -W $warn_no_up $warn_no_mfi $warn_no_sc"
      if test x"$enable_gnomeui" != "xyes" ; then
          warnings_c="-Wstrict-prototypes $warnings_cxx"
      else
	  dnl "-Wstrict-prototypes" gives zillions of warnings in gtk headers
	  dnl warnings_gnome="-DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGNOME_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED"
	  warnings_c="$warnings_gnome $warnings_cxx"
      fi

      dnl Set appropriate optimization options (better than the default -g -O)
      dnl if using GCC.
      dnl If the user has specified her own `CFLAGS', we do not override them.

      optimization_c="-O3 $march"
      optimization_cxx="-fno-exceptions $optimization_c"
      dnl Use -g if available.
      if test x"$ac_cv_prog_cc_g" = "xyes" ; then
         CFLAGS="-g $optimization_c $warnings_c"
         CXXFLAGS="-g $optimization_cxx $warnings_cxx"
      else
         CFLAGS="$optimization_c $warnings_c"
         CXXFLAGS="$optimization_cxx $warnings_cxx"
      fi

      dnl Check whether the options are OK.
      AC_PROG_CC

    fi

    dnl (If not on GCC, just keep the defaults, which are very conservative).

  fi

  AM_CONDITIONAL(HAVE_RAWDRIVE, true)

  AC_DEFINE(HAVE_RAWDRIVE,,[Support for block device disk image access.])
  HAVE_RAWDRIVE_SUPPORT="yes"
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"
  if test x"$is_beos_x11" != "xyes"; then
    if test x"$enable_midi" != "xno"; then
      AC_DEFINE(HAVE_MIDI,,[Enable support for MIDI.])
      HAVE_MIDI_SUPPORT="yes"
    fi
    if test x"$enable_rs232" != "xno"; then
      AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
      HAVE_RS232DEV_SUPPORT="yes"
    fi
  fi
  ;;
esac
fi


dnl check for debug build
if test x"$enable_debug" = "xyes"; then
  DEBUGBUILD=1
  DEBUG_SUPPORT="yes"
  dnl PCBSD/FreeBSD needs -lexecinfo for debug builds
  AC_CHECK_FUNC(backtrace_symbols,
                have_backtrace_symbols="yes",
                have_backtrace_symbols="no")

  if test x"$have_backtrace_symbols" != "xyes"; then
    AC_CHECK_LIB(execinfo,
                 backtrace_symbols,
                 LIBS="$LIBS -lexecinfo",
                 AC_MSG_ERROR([libexecinfo is required for debug builds.]))
  fi
else
  DEBUGBUILD=0
fi

AC_SUBST(DEBUGBUILD)



dnl This enables the embedded data files feature, which should
dnl only be used for developing new ports or for ports for which
dnl the loading of the datafiles is hard/impossible.
if test x"$enable_embedded" = "xyes"; then
  AC_DEFINE(USE_EMBEDDED,,[Use embedded data files.])
  USE_EMBEDDED_SUPPORT="yes"
  AM_CONDITIONAL(EMBEDDED, true)
else
  AM_CONDITIONAL(EMBEDDED, false)
fi

AM_CONDITIONAL(USE_MIDAS_SOUND, test x"$with_midas" = "xyes")

dnl check for texi to amigaguide program
AC_CHECK_PROGS(MAKEGUIDE, makeguide, no)
if test x"$MAKEGUIDE" != "xno"; then
  AM_CONDITIONAL(BUILD_AMIGAGUIDE, true)
else
  if test x"$MAKEINFO" != "xno"; then
    AC_MSG_CHECKING([if the makeinfo supports amigaguide])
    agresult=`$MAKEINFO --help 2>&1 | grep amiga`
    if test x"$agresult" != "x"; then
      AC_MSG_RESULT([yes])
      MAKEGUIDE=$MAKEINFO
      AM_CONDITIONAL(BUILD_AMIGAGUIDE, true)
    else
      AC_MSG_RESULT([no])
      AM_CONDITIONAL(BUILD_AMIGAGUIDE, false)
    fi
  else
    AM_CONDITIONAL(BUILD_AMIGAGUIDE, false)
  fi
fi
AC_SUBST(MAKEGUIDE)

dnl check for windows chm compiler
AC_CHECK_PROGS(HHC, hhc, no)
if test x"$HHC" = "xno"; then
  AM_CONDITIONAL(BUILD_CHM, false)
else
  AM_CONDITIONAL(BUILD_CHM, true)
fi

dnl check for windows hlp compiler programs
AC_CHECK_PROGS(MAKERTF, makertf, no)
AC_CHECK_PROGS(HCRTF, hcrtf, no)
if test x"$MAKERTF" = "xno" -o x"$HCRTF" = "xno"; then
  AM_CONDITIONAL(BUILD_HLP, false)
else
  AM_CONDITIONAL(BUILD_HLP, true)
fi

dnl check for os/2 ipf compiler programs
AC_CHECK_PROGS(TEXI2IPF, texi2ipf, no)
AC_CHECK_PROGS(IPFC, wipfc, no)
if test x"$TEXI2IPF" != "xno"; then
  if test x"$IPFC" = "xno"; then
    AC_CHECK_PROGS(IPFC, ipfc, no)
  fi
  if test x"$IPFC" != "xno"; then
    AM_CONDITIONAL(BUILD_IPF, true)
  else
    AM_CONDITIONAL(BUILD_IPF, false)
  fi
else
  AM_CONDITIONAL(BUILD_IPF, false)
fi

dnl Extension for executable files in this system
AC_EXEEXT

dnl NLS stuff
dnl Its has been rejected to use the full GNU gettext package 
dnl delivered within the source. This is a minimum replacement implementing
dnl a simple check to find `libintl.h' and `gettext'.
dnl

dnl Add new languages here
ALL_LINGUAS="da de es fr hu it ko nl pl ru sv tr"

dnl These rules are solely for the distribution goal.  While doing this
dnl we only have to keep exactly one list of the available catalogs
dnl in configure.in.
for lang in $ALL_LINGUAS; do
  GMOFILES="$GMOFILES $lang.gmo"
  POFILES="$POFILES $lang.po"
done
AC_SUBST(GMOFILES)
AC_SUBST(POFILES)

AC_CHECK_LIB(iconv, libiconv_open,,)

if test x"$enable_nls" != "xno" -a x"$is_unix" = "xyes"; then
  AC_CHECK_HEADER(libintl.h,
    [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
      [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
  	 gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])

     AC_CACHE_CHECK([for gettext in libintl], gt_cv_func_gettext_libintl,
      [save_libs="$LIBS"
       LIBS="-lintl $LIBS"
       AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
  	 INTLLIBS=-lintl gt_cv_func_gettext_libintl=yes, gt_cv_func_gettext_libintl=no)
       LIBS="$save_libs"])

     if test "$gt_cv_func_gettext_libc" = "yes" \
  	|| test "$gt_cv_func_gettext_libintl" = "yes"; then
  	AC_DEFINE(HAVE_GETTEXT,,[Define if gettext if available.])
  	AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
  	  [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
  	if test "$MSGFMT" != "no"; then
  	  AC_CHECK_FUNCS(dcgettext)
  	  AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
  	  AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
  	    [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
  	  AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
  			 return _nl_msg_cat_cntr],
  	    [CATOBJEXT=.gmo
  	     DATADIRNAME=share],
  	    [CATOBJEXT=.mo
  	     DATADIRNAME=lib])
  	  INSTOBJEXT=.mo
  	fi
        USE_NLS=yes
	AC_DEFINE(ENABLE_NLS,,[Define if NLS support is enabled.])
     ENABLE_NLS_SUPPORT="yes"
	AC_DEFINE(HAVE_LIBINTL_H,,[use libintl for NLS.])
	AC_DEFINE_UNQUOTED(DATADIRNAME, "$DATADIRNAME",[NLS datadirname.])
	dnl this is prefixed with PREFIX
	AC_DEFINE(NLS_LOCALEDIR, [PREFIX "/" DATADIRNAME "/locale"],[NLS local directory.])
      else
        AC_MSG_WARN([libintl.h not found, disabling NLS])
        USE_NLS=no
      fi
  ])
  dnl Test whether we really found GNU xgettext.
  if test "$XGETTEXT" != ":"; then
    dnl If it is no GNU xgettext we define it as : so that the
    dnl Makefiles still can work.
    if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
      : ;
    else
      AC_MSG_RESULT(
    	[found xgettext program is not GNU xgettext; ignore it])
      XGETTEXT=":"
    fi
  fi

  dnl Test wether GMSGFMT is there. Should fix `make dist'.
  if test "$GMSGFMT" = "" ; then
    GMSGFMT=":"
  fi

  # We need to process the po/ directory.
  POSUB=po
  
  AC_OUTPUT_COMMANDS(
    [case "$CONFIG_FILES" in *po/Makefile.in*)
      sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
    esac])
  
  dnl Make all variables we use known to autoconf.
  AC_SUBST(USE_INCLUDED_LIBINTL)
  AC_SUBST(CATALOGS)
  AC_SUBST(DATADIRNAME)
  AC_SUBST(INSTOBJEXT)
  AC_SUBST(INTLDEPS)
  AC_SUBST(INTLLIBS)
  AC_SUBST(INTLOBJS)
  AC_SUBST(POSUB)
  AC_SUBST(GENCAT)

  dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
  dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
  dnl Try to locate is.
  MKINSTALLDIRS=
  if test -n "$ac_aux_dir"; then
    MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
  fi
  if test -z "$MKINSTALLDIRS"; then
    MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
  fi
  AC_SUBST(MKINSTALLDIRS)

  dnl currently no catgets support, can't check it.
  GENCAT=
  AC_SUBST(GENCAT)
else
  if test x"$is_unix" = "xyes"; then
    AC_MSG_WARN([disabling NLS on user request])
  fi
  USE_NLS=no
fi

if test x"$USE_NLS" = "x" ; then
  USE_NLS=no
fi
if test "$MSGFMT" = "no" ; then
  dnl Fallback to shipped .gmo 
  dnl Those should work on x86 linux systems.
  AC_MSG_WARN([msgfmt not found, falling back to default catalogs (x86/Linux)])
  CATOBJEXT=".gmo"
fi
AC_SUBST(CATOBJEXT)
AC_SUBST(USE_NLS)
AC_SUBST(NLS_LOCALEDIR)

dnl Check for a perl interpreter.
AC_PATH_PROG(PERL, perl)
AC_SUBST(PERL)
 
if test x"$POSUB" = "xpo"; then
  AM_CONDITIONAL(PO_SUBDIR_USED, true)
else
  AM_CONDITIONAL(PO_SUBDIR_USED, false)
fi

dnl Check if --param inline-unit-growth=60 can be used.
old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS --param inline-unit-growth=60"
AC_MSG_CHECKING([if the compiler accepts --param inline-unit-growth=60])
AC_TRY_COMPILE([],
               [int test;],
               [ AC_MSG_RESULT(yes)
                 INLINE_UNIT_GROWTH="--param inline-unit-growth=60"
                ],
               [ AC_MSG_RESULT(no)
                INLINE_UNIT_GROWTH=""
                ])
CFLAGS=$old_CFLAGS
AC_SUBST(INLINE_UNIT_GROWTH)

dnl Check if --param max-inline-insns-single=600 can be used.
old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS --param max-inline-insns-single=600"
AC_MSG_CHECKING([if the compiler accepts --param max-inline-insns-single=600])
AC_TRY_COMPILE([],
               [int test;],
               [ AC_MSG_RESULT(yes)
                 MAX_INLINE_INSN_SINGLE="--param max-inline-insns-single=600"
                ],
               [ AC_MSG_RESULT(no)
                MAX_INLINE_INSN_SINGLE=""
                ])
CFLAGS=$old_CFLAGS
AC_SUBST(MAX_INLINE_INSN_SINGLE)

dnl Check and setup aRts compilation.
if test x"$with_arts" = "xyes"; then
	AC_CHECK_PROGS(artsc_config, artsc-config, no)
	if test x"$artsc_config" = "xno"; then
		AC_MSG_WARN([artsc-config not found. aRts will not be configured])
                with_arts=no
        fi
else
	with_arts=no
fi

dnl Set output drivers to none
SOUND_DRIVERS=""
GFXOUTPUT_DRIVERS=""

RESID_DIR=
RESID_LIBS=
RESID_INCLUDES=
RESID_DEP=

RESID_DTV_DIR=
RESID_DTV_LIBS=
RESID_DTV_INCLUDES=
RESID_DTV_DEP=


LINKCC='$(CC)'

dnl disable reSID for certain platforms

RESIDSUB=""
RESIDDTVSUB=""

if test x"$with_resid" = "xno"; then
  dnl Do not attempt to configure reSID.
  dnl NOTE: no_recursion is set because directories specified with
  dnl AC_CONFIG_SUBDIRS are always recursed into regardless of where the
  dnl macro is used.
  dnl Another workaround must be found if other self-contained packages go
  dnl into VICE.
  if test x"$enable_shared_ffmpeg" != "xyes" -a x"$enable_static_ffmpeg" != "xyes"; then
    no_recursion=yes
  fi
  dnl A workaround for an autoconf bug when not using/checking the C++
  dnl compiler, we'll define am__fastdepCXX_TRUE as #
  am__fastdepCXX_TRUE=#
  am__fastdepCXX_FALSE=
else
  AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  AC_PROG_CXX([g++ clang++ cc])

  dnl when using --host=, check if the C++ compiler is the intended cross compiler
  if [[ x"$ac_cv_prog_cc_cross" != "xno" -a x"$toolchain_check" != "xno" ]]; then
    if test x"$CXX" != "x" ; then
      if test -n "$ac_tool_prefix"; then
        valid_cxx=no
        for cxx_compiler in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
        do
          if test x"$ac_tool_prefix$cxx_compiler" = x"$CXX"; then
            valid_cxx=yes
          fi
        done

        if test x"$valid_cxx" = "xno"; then
          AC_MSG_WARN([$CXX is not the intended cross-compiler, ReSID will not be configured])
          with_resid=no
          CXX=""
        fi
      fi
    fi
  fi

  dnl disable resid when no C++ compiler is found
  if test x"$CXX" != "x" ; then
    LINKCC='$(CXX)'

    dnl Set CXXFLAGS. Use -fno-exceptions for G++ if supported.
    if test "$ac_test_CXXFLAGS" != set; then
      if test "$GXX" = yes; then
        CXXFLAGS="$CFLAGS -fno-exceptions"
        AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
        AC_TRY_COMPILE([],
                       [ int test; ],
                       [ AC_MSG_RESULT(yes) ],
                       [ AC_MSG_RESULT(no)
                         CXXFLAGS="$CFLAGS"
                         ])
      else
        CXXFLAGS="$CFLAGS"
      fi
    fi
    AC_PROG_CXXCPP
  fi

  if test x"$with_resid" = "xyes" -o x"$with_resid" = "x"; then
    AC_DEFINE(HAVE_RESID,,[This version provides ReSID support.])
    HAVE_RESID_SUPPORT="yes"
    AC_CONFIG_SUBDIRS(src/resid)
    RESID_DIR=resid
    RESID_LIBS="\$(top_builddir)/src/resid/libresid.a"
    RESID_INCLUDES="-I\$(top_builddir)/src/resid"
    RESID_DEP=libresid
    RESIDSUB=resid

    AC_DEFINE(HAVE_RESID_DTV,,[This version provides ReSID-DTV support.])
    AC_CONFIG_SUBDIRS(src/resid-dtv)
    RESID_DTV_DIR=resid-dtv
    RESID_DTV_LIBS="\$(top_builddir)/src/resid-dtv/libresiddtv.a"
    RESID_DTV_INCLUDES="-I\$(top_builddir)/src/resid-dtv"
    RESID_DTV_DEP=libresiddtv
    RESIDDTVSUB=resid-dtv
  fi
  AC_LANG_RESTORE
fi

AC_SUBST(RESIDSUB)
AC_SUBST(RESIDDTVSUB)

if test x"$RESIDSUB" = "xresid"; then
  AM_CONDITIONAL(RESID_DIR_USED, true)
else
  AM_CONDITIONAL(RESID_DIR_USED, false)
fi

AC_SUBST(LINKCC)

AM_CONDITIONAL(HAVE_RESID, test x"$with_resid" != "xno")

AC_SUBST(RESID_DIR)
AC_SUBST(RESID_LIBS)
AC_SUBST(RESID_INCLUDES)
AC_SUBST(RESID_DEP)

AM_CONDITIONAL(HAVE_RESID_DTV, test x"$with_resid" != "xno")
AC_SUBST(RESID_DTV_DIR)
AC_SUBST(RESID_DTV_LIBS)
AC_SUBST(RESID_DTV_INCLUDES)
AC_SUBST(RESID_DTV_DEP)

dnl Check for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADERS(sys/types.h)

AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T

dnl Check whether inline functions are available.
AC_C_INLINE
if test x"$ac_cv_c_inline" = "xno" ; then
  CFLAGS="$CFLAGS -DNO_INLINE"
fi

dnl fix endian for interix
case "$host_os" in
  interix*)
      ac_cv_c_bigendian=no
    ;;
esac

dnl Define the type sizes.
if [[ x"$ac_cv_prog_cc_cross" != "xyes" ]]; then
  AC_C_BIGENDIAN
else
  dnl if cross-compiling, we have to do this by hand
  echo "warning: assuming sizeof(unsigned short) == 2,"
  echo "                  sizeof(unsigned int) == 4,"
  echo "                  sizeof(unsigned long) == 4"
fi

if test x"$cross_compiling" = "xyes"; then
  AM_CONDITIONAL(CROSS, true)
  CROSS=true
  if test x"$enable_native_tools" = "xno" -o x"$enable_native_tools" = "x"; then
    AC_MSG_WARN([Cross compiling and no 'enable-native-tools' specified, using slow scripts for generation tasks])
    NATIVE_TOOLS_COMPILER=""
    AM_CONDITIONAL(NATIVE_TOOLS, false)
  else
    if test x"$enable_native_tools" = "xyes"; then
      NATIVE_TOOLS_COMPILER="gcc"
      AC_MSG_WARN([No native tools compiler given, using 'gcc'])
      AM_CONDITIONAL(NATIVE_TOOLS, true)
    else
      NATIVE_TOOLS_COMPILER="$enable_native_tools"
      AM_CONDITIONAL(NATIVE_TOOLS, true)
    fi
  fi
else
  AM_CONDITIONAL(CROSS, false)
  CROSS=false
  NATIVE_TOOLS_COMPILER="$CC"
  AM_CONDITIONAL(NATIVE_TOOLS, true)
fi
AC_SUBST(CROSS)
AC_SUBST(NATIVE_TOOLS_COMPILER)

AC_CHECK_SIZEOF(unsigned short, 2)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(unsigned long, 4)


dnl Check whether gcc needs -traditional.
AC_PROG_GCC_TRADITIONAL


dnl Check for header files.
AC_HEADER_DIRENT
AC_CHECK_HEADERS(direct.h errno.h fcntl.h limits.h regex.h unistd.h strings.h \
sys/dirent.h sys/stat.h inttypes.h libgen.h sys/ioctl.h \
dir.h io.h process.h signal.h alloca.h wchar.h stdint.h sys/time.h)

AC_CHECK_HEADER(regexp.h,,,[#define	INIT		register char *sp = instring;
#define	GETC()		(*sp++)
#define	PEEKC()		(*sp)
#define	UNGETC(c)	-- sp
#define	RETURN(ptr)	return NULL;
#define	ERROR(val)	_RegExpError(val)
])
AC_DECL_SYS_SIGLIST

AC_MSG_CHECKING(for time_t in time.h)
AC_CACHE_VAL(bu_cv_decl_time_t_time_h,
[AC_TRY_COMPILE([#include <time.h>], [time_t i;],
bu_cv_decl_time_t_time_h=yes, bu_cv_decl_time_t_time_h=no)])
AC_MSG_RESULT($bu_cv_decl_time_t_time_h)
if test $bu_cv_decl_time_t_time_h = yes; then
  AC_DEFINE([HAVE_TIME_T_IN_TIME_H],,
	    [Is the type time_t defined in <time.h>?])
fi

AC_MSG_CHECKING(for time_t in sys/types.h)
AC_CACHE_VAL(bu_cv_decl_time_t_types_h,
[AC_TRY_COMPILE([#include <sys/types.h>], [time_t i;],
bu_cv_decl_time_t_types_h=yes, bu_cv_decl_time_t_types_h=no)])
AC_MSG_RESULT($bu_cv_decl_time_t_types_h)
if test $bu_cv_decl_time_t_types_h = yes; then
  AC_DEFINE([HAVE_TIME_T_IN_TYPES_H],,
	    [Is the type time_t defined in <sys/types.h>?])
fi

if test $bu_cv_decl_time_t_time_h = yes; then
  AC_CHECK_SIZEOF([time_t],[],[#include <time.h>])
else
  AC_CHECK_SIZEOF([time_t],[],[#include <sys/types.h>])
fi

if test "x$ac_cv_sizeof_time_t" = "x4"; then
  AC_MSG_RESULT([time_t is 32 bit])
  AC_DEFINE([TIME_T_IS_32BIT],,[time_t is 32 bit])
elif test "x$ac_cv_sizeof_time_t" = "x8"; then
  AC_MSG_RESULT([time_t is 64 bit])
  AC_DEFINE([TIME_T_IS_64BIT],,[time_t is 64 bit])
else
  AC_MSG_ERROR([can not figure type of time_t])
fi

dnl ----- Dynamic Lib Loading Support -----
dynlib_support=no
DYNLIB_LIBS=
dnl check for dlopen support on unix and beos/haiku systems
if test x"$is_unix" = "xyes" -o x"$is_beos" = "xyes"; then
  AC_CHECK_HEADER(dlfcn.h,,)
  if test x"$ac_cv_header_dlfcn_h" = "xyes" ; then
    AC_CHECK_FUNC(dlopen,
                 [ DYNLIB_LIBS="";
                   AC_DEFINE(HAVE_DYNLIB_SUPPORT,,
                             [Support for dynamic library loading.])
                   dynlib_support=yes;
                   HAVE_DYNLIB_SUPPORT_TOO="yes"
                 ])
    if test x"$dynlib_support" != "xyes" ; then
      AC_CHECK_LIB(dl, dlopen,
                 [ DYNLIB_LIBS="-ldl";
                   AC_DEFINE(HAVE_DYNLIB_SUPPORT,,
                             [Support for dynamic library loading.])
                   dynlib_support=yes;
                   HAVE_DYNLIB_SUPPORT_TOO="yes";
                   LIBS="-ldl $LIBS"
                 ],,)
    fi
  fi
elif test x"$is_win32" = "xyes" ; then
  AC_DEFINE(HAVE_DYNLIB_SUPPORT,,[Support for dynamic library loading.])
  HAVE_DYNLIB_SUPPORT_TOO="yes"
fi
AC_SUBST(DYNLIB_LIBS)

dnl ----- Joystick support -----
JOY_LIBS=
if test x"$is_unix_x11" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
  AC_CHECK_HEADER(linux/joystick.h,
                  [ AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
                    HAS_JOYSTICK_SUPPORT="yes";
                    LINUX_JOYSTICK_SUPPORT="yes";
                    AC_DEFINE(LINUX_JOYSTICK,,
                              [Enable support for Linux style joysticks.])],)
  if test x"$ac_cv_header_linux_joystick_h" = "xyes" ; then
    AC_MSG_CHECKING(whether linux/joystick.h supports digital joysticks)
    AC_TRY_COMPILE([ #include <linux/joystick.h> ],
                   [ struct DJS_DATA_TYPE djs; ],
                   [ HAS_DIGITAL_JOYSTICK_SUPPORT="yes";
                     AC_DEFINE(HAS_DIGITAL_JOYSTICK,,
                               [Enable emulation for digital joysticks.])
                     AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
  fi

  AC_CHECK_HEADER(machine/joystick.h,
                  [ AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
                    HAS_JOYSTICK_SUPPORT="yes";
                    BSD_JOYSTICK_SUPPORT="yes";
                    AC_DEFINE(HAVE_MACHINE_JOYSTICK_H,,
                              [Define to 1 if you have the <machine/joystick.h> header file.])
                    AC_DEFINE(BSD_JOYSTICK,,
                              [Enable support for BSD style joysticks.])],)

  if test x"$ac_cv_header_machine_joystick_h" != "xyes"; then
    AC_CHECK_HEADER(sys/joystick.h,
                    [ AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
                      HAS_JOYSTICK_SUPPORT="yes";
                      BSD_JOYSTICK_SUPPORT="yes";
                      AC_DEFINE(HAVE_SYS_JOYSTICK_H,,
                                [Define to 1 if you have the <sys/joystick.h> header file.])
                      AC_DEFINE(BSD_JOYSTICK,,
                                [Enable support for BSD style joysticks.])],)
  fi

  dnl NetBSD/FreeBSD USB joystick support
  usbhid_header=no
  usbhid_lib=no
  usb_lib=no
  AC_CHECK_LIB(usbhid, hid_get_report_desc, usbhid_lib=yes)
  if test x"$usbhid_lib" = "xyes" ; then
    AC_CHECK_HEADER(usbhid.h,
                    [AC_DEFINE(HAVE_USBHID_H,1,
                      [Define to 1 if you have the <usbhid.h> header file.])
                    usb_header=yes])
    AC_CHECK_HEADER(libusbhid.h,
                    [AC_DEFINE(HAVE_LIBUSBHID_H,1,
                      [Define to 1 if you have the <libusbhid.h> header file.])
                    usb_header=yes])
 
    if test x"$usb_header" = "xyes" ; then
      AC_DEFINE(HAS_USB_JOYSTICK,,[Enable emulation for USB joysticks.])
      JOY_LIBS="-lusbhid"
      HAS_USB_JOYSTICK_SUPPORT="yes"
    fi
  else
    AC_CHECK_LIB(usb, hid_get_report_desc, usb_lib=yes)
    if test x"$usb_lib" = "xyes"; then
      AC_CHECK_HEADER(usb.h,
                      [AC_DEFINE(HAVE_USB_H,1,
                        [Define to 1 if you have the <usb.h> header file.])
                      usb_header=yes])
      AC_CHECK_HEADER(libusb.h,
                      [AC_DEFINE(HAVE_LIBUSB_H,1,
                        [Define to 1 if you have the <libusb.h> header file.])
                      usb_header=yes])
      if test x"$usb_header" = "xyes" ; then
        AC_DEFINE(HAS_USB_JOYSTICK,,[Enable emulation for USB joysticks.])
        JOY_LIBS="-lusb"
        HAS_USB_JOYSTICK_SUPPORT="yes"
      fi
    fi
  fi
fi

if test x"$is_unix_macosx" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
  dnl --- Mac joystick support ---
  
  dnl check for HID Manager
  if test x"$enable_hidmgr" != "xno" ; then
    AC_CHECK_HEADER(IOKit/hid/IOHIDManager.h,,)
    if test x"$ac_cv_header_IOKit_hid_IOHIDManager_h" = "xyes" ; then
      AC_MSG_CHECKING(whether we can link the (mac) IOHIDManager)
      old_LIBS="${LIBS}"
      LIBS="$LIBS -framework IOKit -framework CoreServices"
      AC_TRY_LINK([#include <IOKit/hid/IOHIDManager.h>],
                  [IOHIDManagerCreate(NULL,0)],
                  [AC_MSG_RESULT(yes);
                   JOY_LIBS="-framework IOKit -framework CoreServices";
                   AC_DEFINE(HAS_JOYSTICK,,[Enable Joystick emulation.])
                   HAS_JOYSTICK_SUPPORT="yes";
                   MAC_JOYSTICK_SUPPORT="yes";
                   HAS_HIDMGR_SUPPORT="yes";
                   AC_DEFINE(MAC_JOYSTICK,,[Enable Mac Joystick support.])
                   AC_DEFINE(HAS_HIDMGR,,[Enable Mac IOHIDManager Joystick driver.])
                   enable_hidutils=no
                   ],
                  [AC_MSG_RESULT(no);
                   LIBS=${old_LIBS}])
      LIBS="${old_LIBS}"
    fi
  fi
  
  dnl check for HID utility library
  if test x"$enable_hidutils" != "xno" ; then
    AC_CHECK_HEADER(HID_Utilities_External.h,,)
    if test x"$ac_cv_header_HID_Utilities_External_h" = "xyes" ; then
      AC_MSG_CHECKING(whether we can link the (mac) HIDUtilities library)
      old_LIBS="${LIBS}"
      LIBS="$LIBS -lHIDUtilities -framework IOKit -framework CoreServices"
      AC_TRY_LINK([#include <HID_Utilities_External.h>],
                  [HIDCountDevices()],
                  [AC_MSG_RESULT(yes);
                   JOY_LIBS="-lHIDUtilities -framework IOKit -framework CoreServices";
                   AC_DEFINE(HAS_JOYSTICK,,[Enable Joystick emulation.])
                   HAS_JOYSTICK_SUPPORT="yes";
                   MAC_JOYSTICK_SUPPORT="yes";
                   AC_DEFINE(MAC_JOYSTICK,,[Enable Mac Joystick support.])],
                  [AC_MSG_RESULT(no);
                   LIBS=${old_LIBS}])
      LIBS="${old_LIBS}"
    fi
  fi
fi
AC_SUBST(JOY_LIBS)

dnl Check for math library
AC_CHECK_HEADERS(math.h)
AC_CHECK_LIB(m, sqrt,,,$LIBS)


dnl ----- ZLib -----
ZLIB_LIBS=

if test x"$with_zlib" != "xno" ; then
  AC_CHECK_HEADER(zlib.h,,)
  if test x"$ac_cv_header_zlib_h" = "xyes" ; then
    ac_cv_lib_z_zlibVersion=yes
    AC_CHECK_LIB(z, zlibVersion,
               [ ZLIB_LIBS="-lz";
                 HAVE_ZLIB_SUPPORT="yes";
                 AC_DEFINE(HAVE_ZLIB,,
                 [Can we use the ZLIB compression library?]) ],,)
  fi
fi

AC_SUBST(ZLIB_LIBS)


dnl ----- Netplay Support -----
NETPLAY_LIBS=
old_LIBS="$LIBS"
if test x"$is_unix_x11" = "xyes" -o x"$is_dos" = "xyes" -o x"$is_unix_macosx" = "xyes"; then

  if test x"$host_os" != "xqnx"; then
    dnl Check for needed network headers
    UNIX_NETWORK_HEADERS_PRESENT=yes
    case "$host_os" in
      nextstep*|openstep*|rhapsody*)
        AC_CHECK_HEADERS(sys/types.h unistd.h sys/socket.h sys/time.h netinet/in.h arpa/inet.h netdb.h,,
                         [UNIX_NETWORK_HEADERS_PRESENT=no],)
        if test x"$UNIX_NETWORK_HEADERS_PRESENT" = "xyes"; then
          AC_CHECK_HEADERS(sys/select.h,,[sys_select_present=no],)
          if test x"$sys_select_present" = "xno"; then
            AC_CHECK_HEADERS(libc.h,,[UNIX_NETWORK_HEADERS_PRESENT=no],)
          fi
        fi
        ;;
      *)
        AC_CHECK_HEADERS(sys/types.h unistd.h sys/socket.h sys/time.h sys/select.h netinet/in.h arpa/inet.h netdb.h,,
                         [UNIX_NETWORK_HEADERS_PRESENT=no],)
        ;;
    esac
  else
    LIBS="-lsocket -lunix $LIBS"
  fi

  if test x"$UNIX_NETWORK_HEADERS_PRESENT" = "xyes"; then

    dnl Check for possible extra needed network libraries
    AC_CHECK_LIB(intl, dgettext,[ NETPLAY_LIBS="-lintl $NETPLAY_LIBS";
                                  LIBS="-lintl $LIBS"],,)
    AC_CHECK_LIB(nsl, gethostbyname,[ NETPLAY_LIBS="-lnsl $NETPLAY_LIBS";
                                      LIBS="-lnsl $LIBS"],,)
    AC_CHECK_LIB(socket, gethostbyname,[ NETPLAY_LIBS="-lsocket $NETPLAY_LIBS";
                                         LIBS="-lsocket $LIBS"],,)
    AC_CHECK_LIB(bsd, gethostbyname,[ NETPLAY_LIBS="-lbsd $NETPLAY_LIBS";
                                      LIBS="-lbsd $LIBS"],,)
    AC_CHECK_LIB(net, gethostbyname,[ NETPLAY_LIBS="-lnet $NETPLAY_LIBS";
                                      LIBS="-lnet $LIBS"],,)
    AC_CHECK_LIB(inet, gethostbyname,[ NETPLAY_LIBS="-linet $NETPLAY_LIBS";
                                       LIBS="-linet $LIBS"],,)
    AC_CHECK_LIB(watt, gethostbyname,[ NETPLAY_LIBS="-lwatt $NETPLAY_LIBS";
                                       LIBS="-lwatt $LIBS"],,)

    dnl Check for needed functions
    UNIX_NETWORK_FUNCS_PRESENT=yes

    dnl Check for netinet/tcp.h
    AC_CHECK_HEADERS([netinet/tcp.h])

    AC_CHECK_FUNCS(socket send bind listen gethostbyname connect recv accept,,
                   [UNIX_NETWORK_FUNCS_PRESENT=no],)

    if test x"$UNIX_NETWORK_FUNCS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
      HAVE_NETWORK_SUPPORT="yes"
      AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
      HAVE_RS232NET_SUPPORT="yes"
      AC_CHECK_FUNCS(htons htonl)
      AC_CHECK_FUNCS(getdtablesize getrlimit)
      AC_MSG_CHECKING([For socklen_t])
      AC_TRY_COMPILE([#include <sys/types.h>
                      #include <sys/socket.h>],
                     [socklen_t foo; foo = 1235;],
                     [AC_DEFINE(HAVE_SOCKLEN_T,,[Define if the socklen_t type is present.])
                      AC_MSG_RESULT(yes)],
                     [AC_MSG_RESULT(no)])

      AC_MSG_CHECKING([for in_addr_t])
      AC_TRY_COMPILE([#include <sys/types.h>
                      #include <stdlib.h>
                      #include <stddef.h>
                      #include <netinet/in.h>], [in_addr_t foo;],
                      [AC_DEFINE(HAVE_IN_ADDR_T,,[Define if the in_addr_t type is present.])
                       AC_MSG_RESULT(yes)],
                      [AC_MSG_RESULT(no)])
    fi
  fi
elif test x"$is_beos" = "xyes"; then

  dnl Check for needed network headers
  BEOS_NETWORK_HEADERS_PRESENT=yes
  AC_CHECK_HEADERS(sys/socket.h netdb.h ByteOrder.h,,
                   [BEOS_NETWORK_HEADERS_PRESENT=no],)

  if test x"$BEOS_NETWORK_HEADERS_PRESENT" = "xyes"; then

    dnl Check for possible extra needed network libraries

    AC_CHECK_LIB(network, gethostbyname,[ NETPLAY_LIBS="-lnetwork $NETPLAY_LIBS";
                                      LIBS="-lnetwork $LIBS"],,)

    AC_CHECK_LIB(net, gethostbyname,[ NETPLAY_LIBS="-lnet -lnetapi $NETPLAY_LIBS";
                                      LIBS="-lnet -lnetapi $LIBS"],,)

    dnl Check for needed functions

    BEOS_NETWORK_FUNCS_PRESENT=yes

    AC_CHECK_FUNCS(socket send bind listen gethostbyname connect recv accept,,
                   [BEOS_NETWORK_FUNCS_PRESENT=no],)

    if test x"$BEOS_NETWORK_FUNCS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
      HAVE_NETWORK_SUPPORT="yes"
      AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
      HAVE_RS232NET_SUPPORT="yes"
      AC_CHECK_FUNCS(getdtablesize getrlimit)
    fi
  fi
fi

dnl Check for availability of IPV6
if test x"$is_unix_x11" = "xyes" -o x"$is_dos" = "xyes" -o x"$is_unix_macosx" = "xyes" ; then
  if test x"$UNIX_NETWORK_FUNCS_PRESENT" = "xyes"; then
    AC_MSG_CHECKING([if IPV6 should be enabled])
    if test x"$enable_ipv6" != "xno"; then
      have_ipv6=no
      AC_TRY_COMPILE([
        #include <sys/socket.h>
        #include <sys/types.h>
        #include <netinet/in.h>], [
        struct sockaddr_storage ss;
        struct in6_addr in6;
        socket(AF_INET6, SOCK_STREAM, 0);
        in6 = in6addr_any;
        ],
        have_ipv6=yes,
        have_ipv6=no
      )
      AC_MSG_RESULT($have_ipv6)

      if test $have_ipv6 = yes; then
        have_broken_ss_family=no

        dnl on some platforms, the structure sockaddr doesn't have a
        dnl ss_family, but __ss_family. If we find no ss_family then we
        dnl check for __ss_family, and if found define NEED_PREFIXED_SS_FAMILY.
        AC_MSG_CHECKING([struct sockaddr::ss_family])
        AC_TRY_COMPILE([
          #include <sys/socket.h>
          #include <sys/types.h>], [
          struct sockaddr_storage ss ;
          ss.ss_family = 0 ;
          ],
          have_ss_family=yes,
          have_ss_family=no
        )
        AC_MSG_RESULT($have_ss_family)
        if test x"$have_ss_family" = "xno" ; then
          AC_MSG_CHECKING([broken struct sockaddr::ss_family])
          AC_TRY_COMPILE([
            #include <sys/socket.h>
            #include <sys/types.h>], [
            struct sockaddr_storage ss ;
            ss.__ss_family = 0 ;
            ],
            have_broken_ss_family=yes,
            have_broken_ss_family=no
          )
          AC_MSG_RESULT($have_broken_ss_family)
          if test x$have_broken_ss_family = xyes ; then
            AC_DEFINE(NEED_PREFIXED_SS_FAMILY, [],
            [Whether struct sockaddr::__ss_family exists]) 
            AC_DEFINE(ss_family, __ss_family,
            [ss_family is not defined here, use __ss_family instead])
          else
            AC_MSG_WARN(ss_family and __ss_family not found)
          fi
        fi

        have_gethostbyname2=no
        AC_CHECK_FUNC(gethostbyname2, have_gethostbyname2=yes)
        if test $have_gethostbyname2 = yes; then
          AC_DEFINE([HAVE_GETHOSTBYNAME2], [], [Define if gethostbyname2 can be used])
          AC_DEFINE([HAVE_IPV6], [], [Define if ipv6 can be used])
          HAVE_IPV6_SUPPORT="yes"
        else
          have_getipnodebyname=no
          AC_CHECK_FUNC(getipnodebyname, have_getipnodebyname=yes)
          if test $have_getipnodebyname = yes; then
            AC_DEFINE([HAVE_GETIPNODEBYNAME], [], [Define if getipnodebyname can be used])
            AC_DEFINE([HAVE_IPV6], [], [Define if ipv6 can be used])
            HAVE_IPV6_SUPPORT="yes"
          fi
        fi
      fi
    else
      AC_MSG_RESULT("no")
    fi
  fi
fi
LIBS="$old_LIBS"
AC_SUBST(NETPLAY_LIBS)

dnl ----- FFMPEG -----
PKG_PROG_PKG_CONFIG
FFMPEG_DIR=
FFMPEG_LIBS=
FFMPEG_INCLUDES=
FFMPEG_DEP=

HAVE_SHARED_FFMPEG=no
HAVE_STATIC_FFMPEG=no
HAVE_EXTERNAL_FFMPEG=no

AC_MSG_CHECKING([for FFMPEG support])

dnl shared vice included ffmpeg
if test x"$enable_shared_ffmpeg" = "xyes"; then
  if test x"$is_win32" = "xyes" -o x"$is_unix" = "xyes" -a x"$dynlib_support" = "xyes" ; then
    FFMPEG_DEP=libffmpeg
    FFMPEG_LIBS="\$(top_builddir)/src/libffmpeg.a"
    FFMPEG_DIR="$FFMPEG_DIR liblame libx264 libffmpeg"
    AC_DEFINE([HAVE_FFMPEG],,[Have FFMPEG av* libs available])
    HAVE_FFMPEG_SUPPORT="yes"
    AC_DEFINE([SHARED_FFMPEG],,[FFMPEG libraries are shared])
    SHARED_FFMPEG_SUPPORT="yes"
    FFMPEG_INCLUDES="-I\$(top_srcdir)/src/lib/libffmpeg"

    FFMPEG_DO_SUBDIRS=yes
    HAVE_SHARED_FFMPEG=yes

    dnl --- define obsolete variables as long as they are not removed from driver code ---
    AC_DEFINE([HAVE_FFMPEG_SWSCALE],,[Have FFMPEG swscale lib available])
    HAVE_FFMPEG_SWSCALE_SUPPORT="yes"
    AC_DEFINE([HAVE_FFMPEG_HEADER_SUBDIRS],,[FFMPEG uses subdirs for headers])
    AC_MSG_RESULT([yes (shared internal)])
    GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS ffmpegdrv.o ffmpeglib.o"
  else
    AC_MSG_RESULT([shared not available])
  fi
fi

dnl static vice included ffmpeg
if test x"$enable_static_ffmpeg" = "xyes"; then
  FFMPEG_DEP=libffmpeg
  FFMPEG_LIBS="\$(top_builddir)/src/lib/libffmpeg/libavformat/libavformat.a \$(top_builddir)/src/lib/libffmpeg/libavcodec/libavcodec.a \$(top_builddir)/src/lib/libffmpeg/libavutil/libavutil.a \$(top_builddir)/src/lib/libffmpeg/libswscale/libswscale.a \$(top_builddir)/src/lib/libffmpeg/libswresample/libswresample.a \$(top_builddir)/src/lib/libffmpeg/lib/libmp3lame.a \$(top_builddir)/src/lib/libffmpeg/lib/libx264.a"
  FFMPEG_DIR="$FFMPEG_DIR liblame libx264 libffmpeg"
  AC_DEFINE([HAVE_FFMPEG],,[Have FFMPEG av* libs available])
  HAVE_FFMPEG_SUPPORT="yes"
  AC_DEFINE([STATIC_FFMPEG],,[FFMPEG libraries are static])
  STATIC_FFMPEG_SUPPORT="yes"
  FFMPEG_INCLUDES="-I\$(top_srcdir)/src/lib/libffmpeg"

  AC_MSG_RESULT([yes (static internal)])

  AC_CHECK_LIB(rt, clock_gettime,,)
  AC_CHECK_LIB(bz2, BZ2_bzDecompressInit,,)
  AC_CHECK_LIB(lzma, lzma_code,,)
  AC_CHECK_LIB(va, vaBeginPicture,,)

  if test x"$is_win32" = "xyes"; then
    win32_pthreads=no
    AC_CHECK_LIB(pthreadGC2, _imp__pthread_self, [ win32_pthreads=yes ])
    if test x"$win32_pthreads" = "xno"; then
      AC_CHECK_LIB(pthreadGC2, pthread_self, [ win32_pthreads=yes ])
    fi
    if test x"$win32_pthreads" = "xno"; then
      AC_CHECK_LIB(pthread, _imp__pthread_self, [ win32_pthreads=yes ])
    else
      LIBS="$LIBS -lpthreadGC2"
    fi
    if test x"$win32_pthreads" = "xno"; then
      AC_MSG_ERROR([Needed pthread lib missing])
    else
      LIBS="$LIBS -lpthread"
    fi
    dnl Add -lws2_32
    LIBS="$LIBS -lws2_32"
  else
    AC_CHECK_LIB(pthread, pthread_create,,)
  fi

  FFMPEG_DO_SUBDIRS=yes
  HAVE_STATIC_FFMPEG=yes

  dnl --- define obsolete variables as long as they are not removed from driver code ---
  AC_DEFINE([HAVE_FFMPEG_SWSCALE],,[Have FFMPEG swscale lib available])
  HAVE_FFMPEG_SWSCALE_SUPPORT="yes"
  AC_DEFINE([HAVE_FFMPEG_HEADER_SUBDIRS],,[FFMPEG uses subdirs for headers])

  GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS ffmpegdrv.o ffmpeglib.o"
fi

dnl external ffmpeg
if test x"$enable_external_ffmpeg" = "xyes"; then
  PKG_PROG_PKG_CONFIG

  valid_ffmpeg_platform="no"

  if test x"$is_unix" = "xyes"; then
    dnl --- unix (requires dynlib support) ---
    if test x"$dynlib_support" = "xyes"; then
      valid_ffmpeg_platform="yes"
    fi
  else
    valid_ffmpeg_platform="yes"
  fi

  if test x"$valid_ffmpeg_platform" = "xyes"; then
    AC_MSG_RESULT([via pkg-config])
    PKG_CHECK_MODULES(FFMPEG_AV,  [libavcodec libavformat libavutil], 
      [old_CFLAGS=$CFLAGS
       old_CPPFLAGS=$CPPFLAGS
       CFLAGS="$CFLAGS $FFMPEG_AV_CFLAGS"
       CPPFLAGS="$CPPFLAGS $FFMPEG_AV_CFLAGS"

       AC_CHECK_HEADER(libavformat/avformat.h,
        [AC_DEFINE([HAVE_FFMPEG_HEADER_SUBDIRS],,[FFMPEG uses subdirs for headers])],
        [AC_CHECK_HEADER(avformat.h,,
          [AC_MSG_ERROR([No suitable FFMPEG header found!])])])

       CFLAGS=$old_CFLAGS
       CPPFLAGS=$old_CPPFLAGS

      PKG_CHECK_MODULES(FFMPEG_SWSCALE, [libswscale],
        [have_swscale=yes],
        [echo "no. trying img_convert"]
        [old_LIBS=$LIBS]
        [AC_CHECK_LIB(avcodec, img_convert,[have_imgconvert=yes])]
        [LIBS=$old_LIBS]
      )
      if (test x"${have_swscale}" = x"yes") || (test x"${have_imgconvert}" = x"yes") ; then
        AC_DEFINE([HAVE_FFMPEG],,[Have FFMPEG av* libs available])
        HAVE_FFMPEG_SUPPORT="yes"
        FFMPEG_INCLUDES="$FFMPEG_AV_CFLAGS"
        GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS ffmpegdrv.o ffmpeglib.o"
	dlopen_pthread=yes
      fi
      if (test x"${have_swscale}" = x"yes") ; then
        AC_DEFINE([HAVE_FFMPEG_SWSCALE],,[Have FFMPEG swscale lib available])
        HAVE_FFMPEG_SWSCALE_SUPPORT="yes"
        FFMPEG_INCLUDES="$FFMPEG_INCLUDES $FFMPEG_SWSCALE_CFLAGS"
	dlopen_pthread=yes
      fi
       ],
      [echo "no. disabled."]
    )
    HAVE_EXTERNAL_FFMPEG=yes
    PKG_CHECK_MODULES(FFMPEG_SWRESAMPLE, [libswresample], [have_swresample=yes], [have_swresample=no])
    if test x"$have_swresample" = "xyes"; then
      AC_DEFINE([HAVE_FFMPEG_SWRESAMPLE],,[Have FFMPEG swresample lib available])
      HAVE_FFMPEG_SWRESAMPLE_SUPPORT="yes"
    else
      PKG_CHECK_MODULES(FFMPEG_AVRESAMPLE, [libavresample], [have_avresample=yes], [have_avresample=no])
      if test x"$have_avresample" = "xyes"; then
        AC_DEFINE([HAVE_FFMPEG_AVRESAMPLE],,[Have FFMPEG avresample lib available])
        HAVE_FFMPEG_AVRESAMPLE_SUPPORT="yes"
      else
        AC_MSG_ERROR([No swresample or avresample library available!])
      fi
    fi
  else
    AC_MSG_RESULT([not available])
  fi
fi

AC_SUBST(FFMPEG_INCLUDES)
AC_SUBST(FFMPEG_LIBS)
AC_SUBST(FFMPEG_DIR)
AC_SUBST(FFMPEG_DEP)

if test x"$HAVE_SHARED_FFMPEG" != "xyes" -a x"$HAVE_STATIC_FFMPEG" != "xyes" -a x"$HAVE_EXTERNAL_FFMPEG" != "xyes"; then
  AC_MSG_RESULT([disabled])
fi

if test x"$FFMPEG_DO_SUBDIRS" = "xyes"; then
  if test x"$is_win32" = "xyes"; then
      ac_configure_args="$ac_configure_args --enable-yasm-command=${YASM} --enable-make-command=${MAKE-make} --enable-w32threads --enable-full-host=${ac_cv_host} --enable-compiler=${CC} --prefix=${prefix}"
  else
      ac_configure_args="$ac_configure_args --enable-yasm-command=${YASM} --enable-make-command=${MAKE-make} --enable-full-host=${ac_cv_host} --enable-compiler=${CC} --prefix=${prefix}"
  fi
  AC_CONFIG_SUBDIRS(src/lib/ffmpeg)
fi

if test x"$HAVE_SHARED_FFMPEG" = "xyes"; then
  AM_CONDITIONAL(HAVE_SHARED_FFMPEG, true)
else
  AM_CONDITIONAL(HAVE_SHARED_FFMPEG, false)
fi

if test x"$HAVE_STATIC_FFMPEG" = "xyes"; then
  AM_CONDITIONAL(HAVE_STATIC_FFMPEG, true)
else
  AM_CONDITIONAL(HAVE_STATIC_FFMPEG, false)
fi

if test x"$enable_shared_ffmpeg" = "xyes" -o x"$enable_static_ffmpeg" = "xyes"; then
  LAMEMP3SUB=liblame
  LIBX264SUB=libx264
  LIBFFMPEGSUB=libffmpeg
  FFMPEGSUB=ffmpeg
else
  LAMEMP3SUB=""
  LIBX264SUB=""
  LIBFFMPEGSUB=""
  FFMPEGSUB=""
fi

AC_SUBST(LAMEMP3SUB)
AC_SUBST(LIBX264SUB)
AC_SUBST(LIBFFMPEGSUB)
AC_SUBST(FFMPEGSUB)

if test x"$LAMEMP3SUB" = "xliblame"; then
  AM_CONDITIONAL(LAMEMP3_DIR_USED, true)
else
  AM_CONDITIONAL(LAMEMP3_DIR_USED, false)
fi

dnl ----- Apple QuickTime -----
QUICKTIME_INCLUDES=
QUICKTIME_LIBS=
if test x"$enable_quicktime" = "xyes" -o x"$is_unix_macosx" = "xyes"; then

  dnl ---- Mac OS X -----
  if test x"$is_unix_macosx" = x"yes" ; then
    AC_CHECK_HEADER(QuickTime/QuickTime.h,,)
    if test x"$ac_cv_header_QuickTime_QuickTime_h" = "xyes" ; then
      AC_CHECK_HEADER(CoreVideo/CVPixelBuffer.h,,)
      if test x"$ac_cv_header_CoreVideo_CVPixelBuffer_h" = "xyes" ; then
        AC_MSG_CHECKING(whether we can link the QuickTime framework)
        old_LIBS="${LIBS}"
        LIBS="${LIBS} -framework QuickTime -framework CoreVideo"
        AC_TRY_LINK([#include <QuickTime/Movies.h>
                     #include <CoreVideo/CVPixelBuffer.h>],
                    [EnterMovies(); CVPixelBufferGetTypeID();],
                    [AC_MSG_RESULT(yes);
                     GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS quicktimedrv.o"
                     QUICKTIME_LIBS="-framework QuickTime -framework CoreVideo"
                     HAVE_QUICKTIME_SUPPORT="yes"
                     AC_DEFINE(HAVE_QUICKTIME,,[Enable QuickTime support.])],
                    [AC_MSG_RESULT(no)])
        LIBS=${old_LIBS}
      fi
    fi
  fi
  dnl ----- Windows -----
  if test x"$is_win32" = x"yes" ; then
    echo "TODO"
  fi

fi
AC_SUBST(QUICKTIME_INCLUDES)
AC_SUBST(QUICKTIME_LIBS)

dnl check for glibc 2.20+
linux_glibc_220_and_up=yes
AC_MSG_CHECKING(if we are using glibc-2.20 and up)
AC_TRY_LINK([#ifdef __linux
             #  include <ctype.h>
             #  ifdef __GLIBC__
             #    if (__GLIBC__>=2)
             #      if ((__GLIBC__==2 && __GLIBC_MINOR__>=20) || __GLIBC__>=3)
             #        error GLIBC2.20+
             #      endif
             #    endif
             #  endif
             #endif],
             [int a=0],
             linux_glibc_220_and_up=no)
AC_MSG_RESULT($linux_glibc_220_and_up)

dnl ----- Ethernet -----
TFE_LIBS=""
DOS_TFE_PCAP_LIB=""
if test x"$enable_ethernet" = "xyes"; then
  if test x"$is_dos" = "xyes" ; then
    old_LIBS="$LIBS"
    AC_CHECK_LIB(watt, gethostbyname,[ AC_DEFINE(DOS_TCP,,[Can we use the dos WATTCP library?])
                                       TFE_LIBS="-lwatt $TFE_LIBS";
                                       LIBS="-lwatt $LIBS"],,)

    AC_CHECK_LIB(pcap, pcap_open_live,[ AC_DEFINE(DOS_TFE,,[Can we use the dos PCAP library?])
                                        AC_DEFINE(HAVE_PCAP,,[Support for The Final Ethernet])
                                        HAVE_PCAP_SUPPORT="yes";
                                        TFE_LIBS="arch/msdos/libpcap_nodma.a $TFE_LIBS";
                                        DOS_TFE_PCAP_LIB="libpcap_nodma.a";
                                        LIBS="-lpcap $LIBS"],,)

    AC_CHECK_LIB(net, libnet_write_link_layer,[ AC_DEFINE(HAVE_DOS_LIBNET,,[Can we use the dos NET library?])
                                        TFE_LIBS="-lnet $TFE_LIBS"],,)
    LIBS=$old_LIBS
  else
    if test x"$is_win32" = "xno"; then
    dnl libpcap.a
      AC_CHECK_LIB(nsl, gethostbyname,[ LIBS="-lnsl $LIBS" ],,)
      AC_CHECK_LIB(socket, gethostbyname,[ LIBS="-lsocket $LIBS" ],,)
      AC_CHECK_LIB(pcap, pcap_inject,[
        AC_DEFINE(HAVE_PCAP,,[Support for The Final Ethernet])
        HAVE_PCAP_SUPPORT="yes";
        AC_DEFINE(HAVE_PCAP_INJECT,,[A libpcap version with pcap_inject is available])
        TFE_LIBS="-lpcap"
      ],,$LIBS)
      AC_CHECK_LIB(pcap, pcap_sendpacket,[
        AC_DEFINE(HAVE_PCAP,,[Support for The Final Ethernet])
        HAVE_PCAP_SUPPORT="yes";
        AC_DEFINE(HAVE_PCAP_SENDPACKET,,[A libpcap version with pcap_sendpacket is available])
        TFE_LIBS="-lpcap"
      ],,$LIBS)
    dnl libpcap.a
    dnl libnet.a
      AC_CHECK_LIB(pcap, pcap_open_live,[
        AC_CHECK_LIB(net, libnet_init,[
          AC_DEFINE(HAVE_PCAP,,[Support for The Final Ethernet])
          HAVE_PCAP_SUPPORT="yes";
          AC_DEFINE(VICE_USE_LIBNET_1_1,,[Support for The Final Ethernet])
          TFE_LIBS="-lpcap `libnet-config --libs`"
          libnet_cflags="`libnet-config --defines`"
      ],,$LIBS)],,$LIBS)
    dnl libpcap.a
    dnl libnet.a
      AC_CHECK_LIB(pcap, pcap_open_live,[
        AC_CHECK_LIB(net, libnet_write_link_layer,[
          AC_DEFINE(HAVE_PCAP,,[Support for The Final Ethernet])
          HAVE_PCAP_SUPPORT="yes";
          TFE_LIBS="-lpcap `libnet-config --libs`"
          libnet_cflags="`libnet-config --defines`"
      ],,$LIBS)],,$LIBS)
      if test x"$libnet_cflags" != "x"; then
        if test x"$linux_glibc_220_and_up" = "xyes"; then
          new_libnet_cflags=""
          for i in $libnet_cflags
          do
            if test x"$i" = "x-D_BSD_SOURCE"; then
              new_libnet_cflags="$new_libnet_cflags -D_DEFAULT_SOURCE"
            else
              new_libnet_cflags="$new_libnet_cflags $i"
            fi
          done
          CFLAGS="$CFLAGS $new_libnet_cflags"
        else
          CFLAGS="$CFLAGS $libnet_cflags"
        fi
      fi
    fi
  fi
  if test x"$TFE_LIBS" = "x" -a x"$is_win32" = "xno"; then
    AC_MSG_ERROR([Needed pcap library not found, please install libpcap-dev or equivalent])
  fi
fi
AC_SUBST(DOS_TFE_PCAP_LIB)
AC_SUBST(TFE_LIBS)

dnl Check and setup SDL compilation.
if test x"$with_sdlsound" = "xyes" -o x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then

    if test x"$is_unix_macosx" = "xyes"; then
        if test x"$enable_sdlui2" = "xyes"; then
          AC_MSG_ERROR([SDL2 framework not implemented (yet) for the Mac OS X port]) 
        fi
        LIBS="$LIBS -lSDLmain -framework SDL -framework Cocoa -framework OpenGL -framework CoreVideo"
        CFLAGS="$CFLAGS -I/Library/Frameworks/SDL.framework/Headers -I/System/Library/Frameworks/OpenGL.framework/Headers"
        CXXFLAGS="$CXXFLAGS -I/Library/Frameworks/SDL.framework/Headers -I/System/Library/Frameworks/OpenGL.framework/Headers"
        SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o"
        USE_SDL_AUDIO_SUPPORT="yes"
        AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])
        if test x"$enable_sdlui" = "xyes"; then
            AC_DEFINE(USE_SDLUI,,[Enable SDL UI support.])
        fi
        AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
        HAVE_HWSCALE_SUPPORT="yes"
        AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
        HAVE_FULLSCREEN_SUPPORT="yes"
        AC_CHECK_FUNCS(SDL_NumJoysticks)
    elif test x"$host_os" = "xmingw32ce" -o x"$host_os" = "xcegcc"; then
        if test x"$enable_sdlui2" = "xyes"; then
          AC_MSG_ERROR([SDL2 not supported on windows ce])
        fi
        LIBS="$LIBS -lSDL -lwinsock"
        SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o"
        USE_SDL_AUDIO_SUPPORT="yes"
        AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])
        if test x"$enable_sdlui" = "xyes"; then
            AC_DEFINE(USE_SDLUI,,[Enable SDL UI support.])
        fi
        AC_DEFINE(CEGCC_COMPILE,,[Enable cegcc support.])
    elif test x"$is_amiga" = "xyes"; then
        if test x"$enable_sdlui2" = "xyes"; then
          AC_MSG_ERROR([SDL2 not supported on amiga])
        fi
        if test x"$enable_sdlui" = "xyes"; then
            AC_DEFINE(USE_SDLUI,,[Enable SDL UI support.])
        fi
        AC_CHECK_HEADER(inline/SDL.h,[SDL_AMIGA_INLINE=yes], [SDL_AMIGA_INLINE=no],)
        AC_CHECK_HEADER(ppcinline/powersdl.h,[POWERSDL_AMIGA_INLINE=yes], [POWERSDL_AMIGA_INLINE=no],)
        AC_CHECK_LIB(debug, kprintf, [LIBS="$LIBS -ldebug"])
        AC_CHECK_LIB(GL, AROSMesaCreateContext, [LIBS="$LIBS -lGL"])
        if test x"$SDL_AMIGA_INLINE" = "xyes"; then
            AC_DEFINE(SDL_AMIGA_INLINE,,[Enable amiga shared SDL library support.])
            AC_DEFINE(HAVE_SDL_NUMJOYSTICKS,, [Define to 1 if you have the `SDL_NumJoysticks' function.])
            HAVE_SDL_NUMJOYSTICKS_SUPPORT="yes";
        elif test x"$POWERSDL_AMIGA_INLINE" = "xyes"; then
            AC_DEFINE(POWERSDL_AMIGA_INLINE,,[Enable morphos shared SDL library support.])
            AC_DEFINE(HAVE_SDL_NUMJOYSTICKS,, [Define to 1 if you have the `SDL_NumJoysticks' function.])
            HAVE_SDL_NUMJOYSTICKS_SUPPORT="yes";
        else
            AC_CHECK_LIB(SDL, SDL_SetVideoMode, [found_sdl_lib=yes], [found_sdl_lib=no])
            if test x"$found_sdl_lib" = "xno"; then
                AC_MSG_ERROR([static SDL lib missing])
            else
                LIBS="-lSDL $LIBS"
            fi
            AC_CHECK_LIB(SDL, SDL_OpenAudio, [found_sdl_sound=yes], [found_sdl_sound=no])
            if test x"$found_sdl_sound" = "xyes"; then
                SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o";
                USE_SDL_AUDIO_SUPPORT="yes";
                AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])
            fi
            AC_CHECK_FUNCS(SDL_NumJoysticks)
        fi
        AC_CHECK_HEADER(SDL/SDL.h, [found_sdl_h=yes], [found_sdl_h=no],)
        if test x"$found_sdl_h" = "xyes"; then
            AC_DEFINE(USE_SDL_PREFIX,,[Enable SDL prefix for header inclusion.])
            if test x"$found_sdl_sound" = "xyes"; then
                AC_CHECK_HEADER(SDL/SDL_audio.h, [], [AC_MSG_ERROR([SDL headers missing])],)
            fi
        else
            AC_CHECK_HEADER(SDL.h, [found_sdl_h=yes], [found_sdl_h=no],)
            if test x"$found_sdl_h" = "xno"; then
                AC_MSG_ERROR([SDL headers missing])
            fi
            if test x"$found_sdl_sound" = "xyes"; then
                AC_CHECK_HEADER(SDL_audio.h, [], [AC_MSG_ERROR([SDL headers missing])],)
            fi
        fi
    else

        if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
            dnl check for sdl-config and sdl2-config
            AC_CHECK_TOOL(sdl_config, sdl-config, no)
            AC_CHECK_TOOL(sdl2_config, sdl2-config, no)
        else
          if test x"$enable_sdlui" = "xyes"; then
            dnl check for sdl-config
            AC_CHECK_TOOL(sdl_config, sdl-config, no)
          else
            dnl check for sdl2-config
            AC_CHECK_TOOL(sdl2_config, sdl2-config, no)
          fi
        fi

        if test x"$sdl_config" = "x"; then
          sdl_config=no
        fi

        if test x"$sdl2_config" = "x"; then
          sdl2_config=no;
        fi

        old_cflags=$CFLAGS
        old_cxxflags=$CXXFLAGS
        old_libs=$LIBS

        dnl if no sdl-config and no sdl2-config was found we assume that
        dnl there are no extra CFLAGS and that libSDL can be found in the
        dnl default lib search path, if libSDL2 is needed, sdl2-config has
        dnl to be present at compile time!
        if test x"$sdl_config" = "xno" -a x"$sdl2_config" = "xno"; then
            LIBS="$LIBS -lSDL"
        else
            if test x"$sdl_config" != "xno"; then
                CFLAGS="$CFLAGS `$sdl_config --cflags`"
                CXXFLAGS="$CXXFLAGS `$sdl_config --cflags`"
                LIBS="$LIBS `$sdl_config --libs`"
            else
                CFLAGS="$CFLAGS `$sdl2_config --cflags`"
                CXXFLAGS="$CXXFLAGS `$sdl2_config --cflags`"
                LIBS="$LIBS `$sdl2_config --libs`"
            fi
        fi

        if test x"$enable_sdlui2" != "xyes"; then
            AC_CHECK_HEADERS(SDL/SDL_audio.h,[AC_CHECK_LIB(SDL, SDL_OpenAudio,
                             [SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o";
                              use_sdl_prefix=yes;
                              use_sdl2_prefix=no;
                              USE_SDL_AUDIO_SUPPORT="yes";
                              AC_DEFINE(USE_SDL_PREFIX,,[Enable SDL prefix for header inclusion.])
                              AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                             [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$SOUND_LIBS $EXTRA_SDL_LIBS)],
                             [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])

            if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes"; then
                unset ac_cv_lib_SDL_SDL_OpenAudio
                AC_CHECK_HEADERS(SDL_audio.h,[AC_CHECK_LIB(SDL, SDL_OpenAudio,
                                 [SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o";
                                  use_sdl_prefix=no;
                                  use_sdl2_prefix=no;
                                  USE_SDL_AUDIO_SUPPORT="yes";
                                  AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$SOUND_LIBS $EXTRA_SDL_LIBS)],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])
            fi
        fi

        if test x"$enable_sdlui" != "xyes"; then
            if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes"; then
                AC_CHECK_HEADERS(SDL2/SDL_audio.h,[AC_CHECK_LIB(SDL2, SDL_OpenAudio,
                                 [SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o";
                                  use_sdl_prefix=no;
                                  use_sdl2_prefix=yes;
                                  USE_SDL_AUDIO_SUPPORT="yes";
                                  AC_DEFINE(USE_SDL2_PREFIX,,[Enable SDL2 prefix for header inclusion.])
                                  AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$SOUND_LIBS $EXTRA_SDL_LIBS)],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])

                if test x"$ac_cv_lib_SDL2_SDL_OpenAudio" != "xyes"; then
                    unset ac_cv_lib_SDL2_SDL_OpenAudio
                    AC_CHECK_HEADERS(SDL_audio.h,[AC_CHECK_LIB(SDL2, SDL_OpenAudio,
                                     [SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o";
                                      use_sdl_prefix=no;
                                      use_sdl2_prefix=no;
                                      USE_SDL_AUDIO_SUPPORT="yes";
                                      AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$SOUND_LIBS $EXTRA_SDL_LIBS)],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])
                fi
            fi
        fi

        if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes" -a x"$ac_cv_lib_SDL2_SDL_OpenAudio" != "xyes"; then
            with_sdlsound=no
        else
            SOUND_LIBS="$SOUND_LIBS $EXTRA_SDL_LIBS"
        fi

        if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then

            if test x"$enable_sdlui2" != "xyes"; then
                AC_CHECK_HEADERS(SDL/SDL.h,[AC_CHECK_LIB(SDL, SDL_SetVideoMode,
                                 [use_sdl_prefix=yes;
                                  use_sdl2_prefix=no;
                                  AC_DEFINE(USE_SDL_PREFIX,,[Enable SDL prefix for header inclusion.])
                                  AC_DEFINE(USE_SDLUI,,[Enable SDL UI support.])],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])

                if test x"$ac_cv_lib_SDL_SDL_SetVideoMode" != "xyes"; then
                    unset ac_cv_lib_SDL_SDL_SetVideoMode
                    AC_CHECK_HEADERS(SDL.h,[AC_CHECK_LIB(SDL, SDL_SetVideoMode,
                                     [use_sdl_prefix=no;
                                      use_sdl2_prefix=no;
                                      AC_DEFINE(USE_SDLUI,,[Enable SDL UI support.])],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])
                fi
            fi

            if test x"$enable_sdlui" != "xyes"; then
                AC_CHECK_HEADERS(SDL2/SDL.h,[AC_CHECK_LIB(SDL2, SDL_CreateWindow,
                                 [use_sdl_prefix=no;
                                  use_sdl2_prefix=yes;
                                  AC_DEFINE(USE_SDL2_PREFIX,,[Enable SDL2 prefix for header inclusion.])
                                  AC_DEFINE(USE_SDLUI2,,[Enable SDL2 UI support.])],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                                 [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])

                if test x"$ac_cv_lib_SDL2_SDL_CreateWindow" != "xyes"; then
                    unset ac_cv_lib_SDL2_SDL_CreateWindow
                    AC_CHECK_HEADERS(SDL.h,[AC_CHECK_LIB(SDL2, SDL_CreateWindow,
                                     [use_sdl_prefix=no;
                                      use_sdl2_prefix=no;
                                      AC_DEFINE(USE_SDLUI2,,[Enable SDL2 UI support.])],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                                     [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])
                fi
            fi

            if test x"$ac_cv_lib_SDL_SDL_SetVideoMode" != "xyes" -a x"$ac_cv_lib_SDL2_SDL_CreateWindow" != "xyes"; then
                AC_MSG_ERROR([SDL headers and/or libraries missing])
            else
                AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
                HAVE_FULLSCREEN_SUPPORT="yes"
            fi

            AC_CHECK_FUNCS(SDL_NumJoysticks)

            if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes" -a x"$ac_cv_lib_SDL2_SDL_OpenAudio" != "xyes"; then
                LIBS="$LIBS $EXTRA_SDL_LIBS"
            fi

            dnl check for opengl libs.
            AC_MSG_CHECKING(whether we can use the GL library)

            old_LIBS="$LIBS"
            LIBS="$LIBS -lGL"
            if test x"$use_sdl2_prefix" = "xyes"; then
                AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
                HAVE_HWSCALE_SUPPORT="yes"
                LIBS="$old_LIBS"
            else
                if test x"$use_sdl_prefix" = "xyes"; then
                    AC_TRY_LINK([#include <SDL/SDL_opengl.h>],
                                [glViewport(1,2,3,4)],
                                [AC_MSG_RESULT(yes);
                                 have_opengl_lib=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                else
                    AC_TRY_LINK([#include <SDL_opengl.h>],
                                [glViewport(1,2,3,4)],
                                [AC_MSG_RESULT(yes);
                                 have_opengl_lib=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                fi
            fi

            if test x"$have_opengl_lib" != "xyes"; then
                AC_MSG_CHECKING(whether we can use the opengl32 library)
                old_LIBS="$LIBS"
                LIBS="$LIBS -lopengl32"
                if test x"$use_sdl2_prefix" = "xyes"; then
                    AC_TRY_LINK([#include <SDL2/SDL_opengl.h>],
                                [glViewport(1,2,3,4)],
                                [AC_MSG_RESULT(yes);
                                 have_opengl_lib=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                else
                    if test x"$use_sdl_prefix" = "xyes"; then
                        AC_TRY_LINK([#include <SDL/SDL_opengl.h>],
                                    [glViewport(1,2,3,4)],
                                    [AC_MSG_RESULT(yes);
                                     have_opengl_lib=yes],
                                    [AC_MSG_RESULT(no);
                                     LIBS="$old_LIBS"])
                    else
                        AC_TRY_LINK([#include <SDL_opengl.h>],
                                    [glViewport(1,2,3,4)],
                                    [AC_MSG_RESULT(yes);
                                     have_opengl_lib=yes],
                                    [AC_MSG_RESULT(no);
                                     LIBS="$old_LIBS"])
                    fi
                fi
            fi

            if test x"$have_opengl_lib" = "xyes"; then
                AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
                HAVE_HWSCALE_SUPPORT="yes"
            fi

            dnl check for the SDL_main.h header
            if test x"$use_sdl2_prefix" = "xyes"; then
                AC_CHECK_HEADERS(SDL2/SDL_main.h)
            else
                if test x"$use_sdl_prefix" = "xyes"; then
                    AC_CHECK_HEADERS(SDL/SDL_main.h)
                else
                    AC_CHECK_HEADERS(SDL_main.h)
                fi
            fi

            AC_MSG_CHECKING(whether we can use the SDLmain library)
            old_LIBS="$LIBS"
            if test x"$enable_sdlui2" = "xyes"; then
                LIBS="$LIBS -lSDL2main -lSDL2 $EXTRA_SDL_LIBS"
            else
                LIBS="$LIBS -lSDLmain -lSDL $EXTRA_SDL_LIBS"
            fi
            if test x"$use_sdl2_prefix" = "xyes"; then
                AC_TRY_LINK([#include <SDL2/SDL_main.h>
                             int main(int argc, char *argv[])
                             { return 0; }
                             #undef main
                             #define main something_else],
                            [return 0;],
                            [AC_MSG_RESULT(yes);
                             have_sdlmain=yes],
                            [AC_MSG_RESULT(no);
                             LIBS="$old_LIBS"])
            else
                if test x"$use_sdl_prefix" = "xyes"; then
                    AC_TRY_LINK([#include <SDL/SDL_main.h>
                                 int main(int argc, char *argv[])
                                 { return 0; }
                                 #undef main
                                 #define main something_else],
                                [return 0;],
                                [AC_MSG_RESULT(yes);
                                 have_sdlmain=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                else
                    AC_TRY_LINK([#include <SDL_main.h>
                                 int main(int argc, char *argv[])
                                 { return 0; }
                                 #undef main
                                 #define main something_else],
                                [return 0;],
                                [AC_MSG_RESULT(yes);
                                 have_sdlmain=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                fi
            fi

            if test x"$have_sdlmain" != "xyes"; then
                AC_MSG_CHECKING(whether we can use the SDLmain library when adding -lmingw32)
                old_LIBS="$LIBS"
                if test x"$enable_sdlui2" = "xyes"; then
                    LIBS="$LIBS -lmingw32 -lSDL2main -lSDL2"
                else
                    LIBS="$LIBS -lmingw32 -lSDLmain -lSDL"
                fi
                if test x"$use_sdl2_prefix" = "xyes"; then
                    AC_TRY_LINK([#include <SDL2/SDL_main.h>
                                 int main(int argc, char *argv[])
                                 { return 0; }
                                 #undef main
                                 #define main something_else],
                                [return 0;],
                                [AC_MSG_RESULT(yes);
                                 have_sdlmain=yes],
                                [AC_MSG_RESULT(no);
                                 LIBS="$old_LIBS"])
                else
                    if test x"$use_sdl_prefix" = "xyes"; then
                        AC_TRY_LINK([#include <SDL/SDL_main.h>
                                     int main(int argc, char *argv[])
                                     { return 0; }
                                     #undef main
                                     #define main something_else],
                                    [return 0;],
                                    [AC_MSG_RESULT(yes);
                                     have_sdlmain=yes],
                                    [AC_MSG_RESULT(no);
                                     LIBS="$old_LIBS"])
                    else
                        AC_TRY_LINK([#include <SDL_main.h>
                                     int main(int argc, char *argv[])
                                     { return 0; }
                                     #undef main
                                     #define main something_else],
                                     [return 0;],
                                    [AC_MSG_RESULT(yes);
                                     have_sdlmain=yes],
                                    [AC_MSG_RESULT(no);
                                     LIBS="$old_LIBS"])
                    fi
                fi
            fi

            if test x"$have_sdlmain" = "xyes"; then
                AC_DEFINE(HAVE_SDLMAIN,,[Enable SDLmain replacement])
            fi
        fi
    fi
fi

dnl ----- Sound Drivers -----
if test x"$is_unix" = "xyes"; then
  if test x"$with_pulse" != "xno"; then
    AC_CHECK_HEADERS(pulse/simple.h,[AC_CHECK_LIB(pulse-simple, pa_simple_new,
                     [SOUND_DRIVERS="$SOUND_DRIVERS soundpulse.o";
                      SOUND_LIBS="$SOUND_LIBS -lpulse-simple -lpulse";
                      USE_PULSE_SUPPORT="yes";
                      AC_DEFINE(USE_PULSE,,[Enable pulseaudio support.])],,$SOUND_LIBS)])
  fi

  if test x"$with_arts" = "xyes"; then
    old_cflags=$CFLAGS
    old_libs=$LIBS
    CFLAGS="$CFLAGS `artsc-config --cflags`"
    LIBS="$LIBS `artsc-config --libs`"
    AC_CHECK_HEADERS(artsc.h,[AC_CHECK_LIB(artsc, arts_init,
                     [SOUND_DRIVERS="$SOUND_DRIVERS soundarts.o"; break],
                     [CFLAGS=$old_cflags; LIBS=$old_libs; with_arts=no; break],$SOUND_LIBS)],
                     [CFLAGS=$old_cflags; LIBS=$old_libs; with_arts=no; break])
  fi

  if test x"$with_arts" = "xyes"; then
    AC_DEFINE(USE_ARTS,,[Enable aRts support.])
    USE_ARTS_SUPPORT="yes"
  fi

  if test x"$with_alsa" != "xno"; then
    AC_CHECK_HEADERS(alsa/asoundlib.h,[AC_CHECK_LIB(asound, snd_pcm_open,
                     [SOUND_DRIVERS="$SOUND_DRIVERS soundalsa.o";
                      SOUND_LIBS="$SOUND_LIBS -lasound";
                      USE_ALSA_SUPPORT="yes";
                      AC_DEFINE(USE_ALSA,,[Enable alsa support.])],,$SOUND_LIBS)])
    AC_CHECK_LIB(asound, snd_pcm_avail,
                 [AC_DEFINE(HAVE_SND_PCM_AVAIL,,[Use more accurate buffer fill reporting])])
  fi

  if test x"$with_oss" != "xno" -a x"$host_os" != "uwin"; then
    AC_CHECK_HEADERS(linux/soundcard.h machine/soundcard.h sys/soundcard.h soundcard.h,
                     [SOUND_DRIVERS="$SOUND_DRIVERS sounduss.o";
                      USE_OSS_SUPPORT="yes";
                      AC_DEFINE(USE_OSS,,[Enable oss support.])])
    AC_CHECK_LIB(ossaudio, _oss_ioctl,,,$SOUND_LIBS)
  fi

  AC_CHECK_HEADERS(dmedia/audio.h, [AC_CHECK_LIB(audio, ALseterrorhandler,
                   [SOUND_DRIVERS="$SOUND_DRIVERS soundsgi.o";
                    SOUND_LIBS="$SOUND_LIBS -laudio";
                    USE_DMEDIA_SUPPORT="yes";
                    AC_DEFINE(USE_DMEDIA,,[Enable sgi sound support.])],,$SOUND_LIBS)])

  AC_CHECK_HEADERS(sys/audioio.h,
                   [SOUND_DRIVERS="$SOUND_DRIVERS soundsun.o"; break])

  case "$host_os" in
    hpux*)
      AC_CHECK_HEADERS(sys/audio.h,
                       [SOUND_DRIVERS="$SOUND_DRIVERS soundhpux.o"; break])
      ;;
    *)
      ;;
  esac

  AC_CHECK_HEADERS(UMS/UMSAudioDevice.h,[AC_CHECK_HEADERS(UMS/UMSBAUDDevice.h,
                   [AC_CHECK_LIB(UMSobj, UMSAudioDevice_initialize,
                    [SOUND_DRIVERS="$SOUND_DRIVERS soundaix.o";
                     SOUND_LIBS="$SOUND_LIBS -lUMSobj";
                     USE_AIX_AUDIO_SUPPORT="yes";
                     AC_DEFINE(USE_AIX_AUDIO,,[Enable aix sound support.])],,$SOUND_LIBS)])])
fi

if test x"$is_amiga" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
  AC_CHECK_HEADERS(devices/ahi.h,
                   [SOUND_DRIVERS="$SOUND_DRIVERS soundahi.o"; break])
fi

dnl --- Lame ---
if test x"$enable_lame" != "xno" ; then

  AC_CHECK_HEADER(lame/lame.h,,)
  
  dnl the header is available!
  if test "$ac_cv_header_lame_lame_h" != "no" ; then
    AC_MSG_CHECKING([for lame lib linking])
    if test x"$dynlib_support" = "xyes" -a x"$enable_static_lame" != "xyes" ; then
      dnl dynlib linking
      SOUND_DRIVERS="$SOUND_DRIVERS soundmp3.o lamelib.o"
      AC_DEFINE(USE_LAMEMP3,,[Enable lamemp3 support.])
      USE_LAMEMP3_SUPPORT="yes"
      AC_MSG_RESULT([dynlib])
    else
      dnl try static linking
      AC_MSG_RESULT([trying static])
      AC_CHECK_LIB(mp3lame, lame_encode_buffer,[ADD_MPGDECODER=0],,)
      if test "$ac_cv_lib_mp3lame_lame_encode_buffer" = "no"; then
        unset ac_cv_lib_mp3lame_lame_encode_buffer
        AC_CHECK_LIB(mp3lame, lame_encode_buffer,[ADD_MPGDECODER=1],,[-lmpgdecoder])
      fi
      if test "$ac_cv_lib_mp3lame_lame_encode_buffer" != "no"; then
        SOUND_DRIVERS="$SOUND_DRIVERS soundmp3.o";
        SOUND_LIBS="$SOUND_LIBS -lmp3lame";
        if test "$ADD_MPGDECODER" = "1" ; then
          SOUND_LIBS="$SOUND_LIBS -lmpgdecoder";
        fi
        AC_DEFINE(USE_LAMEMP3,,[Enable lamemp3 support.])
        USE_LAMEMP3_SUPPORT="yes"
        AC_DEFINE(HAVE_STATIC_LAME,,[Static linking for lame libs])
      fi
    fi
  fi

fi

AC_PATH_PROGS(FCCACHE, fc-cache, false)
if test x"$FCCACHE" = "xfalse"; then
  AM_CONDITIONAL(HAVE_FC_CACHE, false)
else
  AM_CONDITIONAL(HAVE_FC_CACHE, true)
fi

if test x"$is_amigaos4" = "xyes"; then
  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
      AC_MSG_CHECKING(whether devices/timer.h defines TimeVal)
      AC_TRY_COMPILE([ #include <devices/timer.h> ],
                     [ struct TimeVal djs; ],
                     [ AC_DEFINE(AMIGA_OS4_ALT,,
                                 [Enable alternate OS4 includes.])
                       AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
  fi

  dnl for AmigaOS4 native resid needs to be configured without dependency tracking
    if test x"$cross_compiling" != "xyes"; then
    ac_configure_args="$ac_configure_args --disable-dependency-tracking"
  fi
fi

if test x"$is_dos" = "xyes"; then
    if test x"$with_midas" = "xyes"; then
        AC_CHECK_HEADERS(midasdll.h,
                         [SOUND_DRIVERS="$SOUND_DRIVERS soundmidas.o"; break])
    else
        AC_CHECK_HEADERS(allegro.h,
                         [SOUND_DRIVERS="$SOUND_DRIVERS soundallegro.o"; break])
    fi
fi

dsound_header_no_lib="no"

if test x"$is_win32" = "xyes"; then
    if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
        SOUND_DRIVERS="$SOUND_DRIVERS soundwmm.o"
        AC_MSG_CHECKING(whether we can use directx sound)
        AC_CHECK_HEADER(dsound.h,
              [ AC_DEFINE(USE_DXSOUND,,[Enable directx sound support.])
                USE_DXSOUND_SUPPORT="yes" ]
              [ SOUND_DRIVERS="$SOUND_DRIVERS sounddx.o" ]
              [ AC_MSG_CHECKING(for -ldsound) ]
              [ old_LIBS="$LIBS" ]
              [ LIBS="$LIBS -ldsound" ]
              [ AC_LINK_IFELSE([
                               AC_LANG_PROGRAM(
                                               [#define DIRECTSOUND_VERSION 0x500
                                                #include <dsound.h>],
                                               [LPDIRECTSOUNDBUFFER buffer=NULL;
                                                IDirectSoundBuffer_Restore(buffer);]
                                              )
                               ],
                            [ AC_DEFINE(HAVE_DSOUND_LIB, [], [dsound.lib or libdsound.a are present]) ]
                            [ AC_MSG_RESULT(yes) ]
                            [ SOUND_LIBS="$SOUND_LIBS -ldsound" ],
                            [ AC_MSG_RESULT(no) ]
                            [ dsound_header_no_lib="yes" ]
              )]
              [ LIBS="$old_LIBS" ]
        )

        if test x"$dsound_header_no_lib" = "xyes" -o x"$dinput_header_no_lib" = "xyes"; then
              AC_MSG_CHECKING(if CoInitialize can be linked)
              LIBS="$LIBS -lole32"
              AC_LINK_IFELSE([
                               AC_LANG_PROGRAM(
                                               [#include <objbase.h>],
                                               [CoInitialize(NULL);]
                                              )
                               ],
                               [ AC_MSG_RESULT(yes) ],
                               [ AC_MSG_ERROR(no) ]
                              )
        fi

        AC_PATH_TOOL(WINDRES, windres, windres)
        AC_PATH_PROGS(WRC, wrc , windres)
        if test x"$WRC" != "xwindres"; then
            WRC_VERSION=`($WRC --version) 2>/dev/null`
            case "$WRC_VERSION" in
                Wine*)
                    winerc=yes
                    ;;
                *)
                    winerc=no
                    AC_MSG_WARN([WRC found, but is not the Wine Resource Compiler])
                    WRC="$WINDRES"
                    ;;
            esac
        else
            AC_MSG_WARN([WRC not found, WRC is required for propper internationalization support])
            WRC="$WINDRES"
        fi
        dnl if windres is used, test for propper ISO codepage support
        if test x"$WRC" = x"$WINDRES"; then
          AC_MSG_CHECKING(if windres supports iso codepages)
          rm -f test.rc test.res
          echo >test.rc "#pragma code_page(29852)"
          echo >>test.rc "STRINGTABLE"
          echo >>test.rc "BEGIN"
          echo >>test.rc "1, \"test\""
          echo >>test.rc "END"
          $WINDRES test.rc -o test.res 2>/dev/null
          if test -e "test.res"; then
            AC_MSG_RESULT(yes)
          else
            AC_DEFINE(WINDRES_CP_IGNORE,,[Have windres ignore code page pragmas])
            AC_MSG_RESULT(no)
          fi
          rm -f test.rc test.res
        fi
    else
        SOUND_DRIVERS="$SOUND_DRIVERS soundwmm.o"
    fi
fi

if test x"$is_beos" = "xyes" -o x"$is_beos_x11" = "xyes"; then
    SOUND_DRIVERS="$SOUND_DRIVERS soundbeos.o soundbsp.o"
fi

VORBIS_PRESENT=yes
AC_CHECK_HEADERS(vorbis/vorbisfile.h,,[VORBIS_PRESENT=no],)

if test x"$VORBIS_PRESENT" = "xyes"; then
  AC_CHECK_LIB(ogg, ogg_stream_flush,, [VORBIS_PRESENT=no])
fi

if test x"$VORBIS_PRESENT" = "xyes"; then
  AC_CHECK_LIB(vorbis, vorbis_info_clear,, [VORBIS_PRESENT=no])
fi

if test x"$VORBIS_PRESENT" = "xyes"; then
  AC_CHECK_LIB(vorbisfile, ov_open_callbacks,, [VORBIS_PRESENT=no])
fi

if test x"$VORBIS_PRESENT" = "xyes"; then
  AC_CHECK_LIB(vorbisenc, vorbis_encode_init_vbr,, [VORBIS_PRESENT=no])
fi

if test x"$VORBIS_PRESENT" = "xyes"; then
  SOUND_DRIVERS="$SOUND_DRIVERS soundvorbis.o";
  LIBS="$LIBS -lvorbisfile -logg -lvorbis -lvorbisenc"
  USE_VORBIS_SUPPORT="yes"
  AC_DEFINE(USE_VORBIS,,[Enable ogg/vorbis support.])
fi

FLAC_PRESENT=yes

AC_CHECK_HEADERS(FLAC/stream_decoder.h,,[FLAC_PRESENT=no],)

if test x"$FLAC_PRESENT" = "xyes"; then
  AC_CHECK_LIB(FLAC, FLAC__stream_decoder_get_channels,, [FLAC_PRESENT=no])
fi

if test x"$FLAC_PRESENT" = "xno"; then
  unset ac_cv_lib_FLAC_FLAC__stream_decoder_get_channels
  AC_CHECK_LIB(FLAC, FLAC__stream_decoder_get_channels,, [FLAC_PRESENT=no], [-lwinmm])
  if test x"$FLAC_PRESENT" = "xyes"; then
    LIBS="$LIBS -lwinmm"
  fi
fi

if test x"$FLAC_PRESENT" = "xyes"; then
    LIBS="$LIBS -lFLAC"
    SOUND_DRIVERS="$SOUND_DRIVERS soundflac.o"
    USE_FLAC_SUPPORT="yes"
    AC_DEFINE(USE_FLAC,,[Enable FLAC support.])
fi

if test x"$is_unix_macosx" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then

  dnl --- check for CoreAudio ---
  AC_CHECK_HEADER(CoreAudio/CoreAudio.h,,)
  if test x"$ac_cv_header_CoreAudio_CoreAudio_h" = "xyes" ; then
    AC_CHECK_HEADER(AudioToolbox/AudioToolbox.h,,)
    if test x"$ac_cv_header_AudioToolbox_AudioToolbox_h" = "xyes" ; then
      AC_MSG_CHECKING(whether we can link the CoreAudio framework)
      old_LIBS="${LIBS}"
      LIBS="${LIBS} -framework CoreAudio -framework AudioToolbox"
      AC_TRY_LINK([#include <CoreAudio/CoreAudio.h>],
                  [AudioDeviceStart(0,0);],
                  [AC_MSG_RESULT(yes);
                   SOUND_DRIVERS="$SOUND_DRIVERS soundcoreaudio.o";
                   SOUND_LIBS="$SOUND_LIBS -framework CoreAudio -framework AudioToolbox";
                   USE_COREAUDIO_SUPPORT="yes";
                   AC_DEFINE(USE_COREAUDIO,,[Enable CoreAudio support.])],
                  [AC_MSG_RESULT(no)])
      LIBS=${old_LIBS}
    
      AC_CHECK_HEADER(AudioUnit/AudioUnit.h,,)
      if test x"$ac_cv_header_AudioUnit_AudioUnit_h" = "xyes" ; then
        AC_MSG_CHECKING(whether we can link the AudioUnit framework)
        old_LIBS="${LIBS}"
        LIBS="${LIBS} -framework AudioUnit"
        AC_TRY_LINK([#include <AudioUnit/AudioUnit.h>],
                    [AudioOutputUnitStart(NULL);],
                    [AC_MSG_RESULT(yes);
                     SOUND_LIBS="$SOUND_LIBS -framework AudioUnit";
                     HAVE_AUDIO_UNIT_SUPPORT="yes";
                     AC_DEFINE(HAVE_AUDIO_UNIT,,[Enable AudioUnit support.])],
                    [AC_MSG_RESULT(no)])
        LIBS=${old_LIBS}
      fi  
    fi
  fi

  dnl --- check for CoreMIDI ---
  if test x"$enable_midi" != "xno"; then
    AC_MSG_CHECKING(whether we can link the CoreMIDI framework)
    old_LIBS="${LIBS}"
    LIBS="$LIBS -framework CoreMidi -framework CoreServices"
    AC_TRY_LINK([#include <CoreMIDI/MIDIServices.h>],
                [MIDIGetNumberOfDevices()],
                [AC_MSG_RESULT(yes);
                 AC_DEFINE(HAVE_MIDI,,[Enable MIDI emulation.])
                 HAVE_MIDI_SUPPORT="yes"],
               [AC_MSG_RESULT(no);
                 LIBS=${old_LIBS}])
  fi
fi

AC_SUBST(SOUND_DRIVERS)
AC_SUBST(SOUND_LIBS)

dnl Check for ParSID/SSI2001/HardSID/CW support
if test x"$is_unix" = "xyes"; then

  dnl Check cpu first
  case "$host_cpu" in
  i*86 | x86_64* | amd64*)
      ;;
  *)
      enable_parsid=no
      enable_ssi2001=no
      enable_hardsid=no
      enable_catweasel=no
      ;;
  esac

  if test x"$enable_parsid" != "xno" -o x"$enable_ssi2001" != "xno" -o x"$enable_hardsid" != "xno" -o x"$enable_catweasel" != "xno"; then

    LIBIEEE1284_HEADERS_PRESENT=yes
    LINUX_HARDSID_HEADER_PRESENT=yes
    LINUX_PARPORT_HEADERS_PRESENT=yes
    CATWEASEL_HEADER_PRESENT=yes
    QNX_MMAN_HEADERS_PRESENT=yes
    BSD_SET_IOPERM_HEADERS_PRESENT=yes
    PARSID_SUPPORT=no
    IOSID_SUPPORT=no
    PORTSID_SUPPORT=no
    PCIUTILS_HEADER_PRESENT=yes
    PCIUTILS_LIB_PRESENT=no

    dnl Check for needed io headers
    AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(linux/hardsid.h,,[LINUX_HARDSID_HEADER_PRESENT=no],)
    AC_CHECK_HEADERS(linux/ppdev.h linux/parport.h,,[LINUX_PARPORT_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(dev/ppbus/ppi.h dev/ppbus/ppbconf.h,,[FREEBSD_PARPORT_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(cwsid.h,,[CATWEASEL_HEADER_PRESENT=no],)
    AC_CHECK_HEADERS(sys/mman.h hw/inout.h,,[QNX_MMAN_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(machine/sysarch.h,,[BSD_SET_IOPERM_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(unistd.h sys/io.h machine/pio.h machine/cpufunc.h)
    AC_CHECK_HEADERS(pci/pci.h,,[PCIUTILS_HEADER_PRESENT=no],)

    case "$host_os" in
    solaris*)
      PORTSID_SUPPORT=yes
      ;;
    esac

    if test x"$PCIUTILS_HEADER_PRESENT" = "xyes"; then
      AC_CHECK_LIB(pciutils, pci_fill_info,[LIBS="-lpciutils $LIBS"; PCIUTILS_LIB_PRESENT=yes],,)
      if test x"$PCIUTILS_LIB_PRESENT" = "xno"; then
        AC_CHECK_LIB(pci, pci_fill_info,[LIBS="-lpci $LIBS"; PCIUTILS_LIB_PRESENT=yes],,)
      fi
      if test x"$PCIUTILS_LIB_PRESENT" != "xno"; then
        AC_DEFINE(HAVE_LIBPCI,,[Define to 1 if you have the 'pciutils' library.])
        HAVE_PCIUTILS_SUPPORT=yes
      fi
    fi

    if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
      AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
      if test x"$PARSID_SUPPORT" != "xno"; then
        AC_DEFINE(HAVE_LIBIEEE1284,,[Define to 1 if you have the `ieee1284' library (-lieee1284).])
        HAVE_LIBIEEE1284_SUPPORT="yes"
      fi
    fi

    if test x"$PARSID_SUPPORT" != "xno" -a x"$enable_ssi2001" = "xno" -a x"$enable_hardsid" = "xno"; then
      IOSID_SUPPORT=yes
      HAVE_IOSID_SUPPORT=yes
    fi

    if test x"$LINUX_PARPORT_HEADERS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_LINUX_PARPORT_HEADERS,,[Support for Linux par port device file.])
      PORTSID_SUPPORT=yes
      HAVE_PORTSID_SUPPORT=yes
    fi

    if test x"$FREEBSD_PARPORT_HEADERS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_FREEBSD_PARPORT_HEADERS,,[Support for FreeBSD par port device file.])
      PORTSID_SUPPORT=yes
      HAVE_PORTSID_SUPPORT=yes
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      if test x"$QNX_MMAN_HEADERS_PRESENT" = "xyes"; then
        QNX_MMAN_FUNCS_PRESENT=yes
        AC_CHECK_FUNCS(mmap_device_io in8 out8,,[QNX_MMAN_FUNCS_PRESENT=no])
        if test x"$QNX_MMAN_FUNCS_PRESENT" = "xyes"; then
          IOSID_SUPPORT=yes
          HAVE_IOSID_SUPPORT=yes
        fi
      fi
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      if test x"$BSD_SET_IOPERM_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(amd64, amd64_set_ioperm,[LIBS="-lamd64 $LIBS"; IOSID_SUPPORT=yes],,)
        if test x"$IOSID_SUPPORT" = "xyes"; then
          AC_DEFINE(HAVE_LIBAMD64,,[Define to 1 if you have the `amd64' library (-lamd64).])
        fi
      fi
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      if test x"$BSD_SET_IOPERM_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(i386, i386_get_ioperm,[LIBS="-li386 $LIBS"],,)
        AC_CHECK_FUNCS(i386_set_ioperm,[IOSID_SUPPORT=yes],)
      fi
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      AC_CHECK_FUNCS(ioperm,[IOSID_SUPPORT=yes],)
      AC_CHECK_FUNCS(inb outb outb_p inb_p)
    fi

    if test x"$IOSID_SUPPORT" = "xyes"; then
      if test x"$enable_parsid" != "xno"; then
        AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
        HAVE_PARSID_SUPPORT="yes"
      fi
      if test x"$enable_ssi2001" != "xno"; then
        AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
        HAVE_SSI2001_SUPPORT="yes"
      fi
      if test x"$enable_catweasel" != "xno"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        AC_DEFINE(HAVE_CATWEASELMKIII_IO,,[Support for direct PCI I/O access Catweasel MKIII.])
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
      if test x"$enable_hardsid" != "xno"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        AC_DEFINE(HAVE_HARDSID_IO,,[Support for PCI/ISA HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
    else
      if test x"$enable_hardsid" != "xno" -a x"$LINUX_HARDSID_HEADER_PRESENT" = "xyes"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
      if test x"$enable_catweasel" != "xno" -a x"$CATWEASEL_HEADER_PRESENT" = "xyes"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
    fi

    if test x"$PORTSID_SUPPORT" = "xyes"; then
      if test x"$enable_parsid" != "xno" -a x"HAVE_PARSID_SUPPORT" != "xyes"; then
        AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
        AC_DEFINE(HAVE_PORTSID,,[Support for file device based access to ParSID.])
        HAVE_PARSID_SUPPORT="yes"
      fi
    fi
  fi
fi

AC_TYPE_SIGNAL
AC_FUNC_VFORK
AC_CHECK_TYPES(u_short)
AC_CHECK_TYPES(socklen_t, [], [], [[#include <sys/socket.h>]])

dnl some platforms have some of the functions in libbsd,
dnl so we check it out first.
AC_CHECK_LIB(bsd,gettimeofday,,,$LIBS)

dnl some platforms have some of the functions in libposix,
dnl so we check it out second.
AC_CHECK_LIB(posix,gettimeofday,,,$LIBS)

AC_CHECK_FUNCS(gettimeofday memmove atexit strerror strcasecmp strncasecmp dirname mkstemp swab getcwd getpwuid random rewinddir strtok strtok_r strtoul snprintf vsnprintf ltoa ultoa stpcpy strlcpy strlwr strrev fseeko)
AC_CHECK_FUNCS(strdup, [have_strdup_func=yes], [have_strdup_func=no])

if test x"$have_strdup_func" = "xno"; then
  AC_MSG_CHECKING(whether strdup is defined as a macro)
  AC_TRY_LINK([#include <string.h>],
               [char *something = strdup("something")],
               [AC_MSG_RESULT(yes); have_strdup_func=yes],
               [AC_MSG_RESULT(no); have_strdup_func=no])

  if test x"$have_strdup_func" = "xyes"; then
    AC_DEFINE(HAVE_STRDUP,,[Define to 1 if you have the `strdup' function.])
  fi
fi

AC_SUBST(LIBS)

dnl check for usleep
if test x"$is_win32" != "xyes" -a x"$is_amiga_aros" != "xyes"; then
  AC_REPLACE_FUNCS(usleep)
fi

AC_CHECK_FUNC(nanosleep,
              [ AC_DEFINE(HAVE_NANOSLEEP,,[Use nanosleep instead of usleep]) ])

dnl Check time.h.

dnl AC_HEADER_TIME
dnl AC_STRUCT_TM

dnl ----- Readline -----
dnl Check whether we have GNU readline.  If not, use our replacement.
dnl The user can force us to use the replacement with `--without-readline'.
READLINE_LIBS=
EDITLINE_LIBS=
if test x"$is_unix_x11" = "xyes"; then
  if test x"$with_readline" != "xno" ; then
    READLINE_HEADER_PRESENT=yes
    AC_CHECK_HEADERS(readline/readline.h,,[READLINE_HEADER_PRESENT=no],)
    READLINE=""
    unset ac_cv_lib_readline_readline
    old_LIBS="$LIBS"
    AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline"],
               [],,)

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline -ltermcap"],
               [], [-ltermcap],)
    fi

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline -lncurses"],
               [], [-lncurses],)
    fi

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
             [ READLINE="" READLINE_LIBS="-lreadline -lcurses"],
             [ READLINE="\$(top_builddir)/src/arch/unix/readline/libreadline.a" ],
              [-lcurses],)
    fi

    if test x"$enable_sdlui" != "xno" -o x"$enable_sdlui2" != "xno"; then
      READLINE=""
    fi

    if test "$ac_cv_lib_readline_readline" = "yes"; then
      AC_CHECK_LIB(readline, rl_readline_name,
             [ AC_DEFINE(HAVE_RLNAME,,
             [Does the `readline' library support `rl_readline_name'?]) ],,)
    fi
    LIBS="${old_LIBS}"
  else
    if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
      READLINE="\$(top_builddir)/src/arch/unix/readline/libreadline.a"
    fi
  fi
dnl ----- editline support for Cocoa -----
elif test x"$enable_editline" != "xno" -a x"$with_cocoa" = "xyes" ; then

   AC_CHECK_HEADER(histedit.h,
    [AC_MSG_CHECKING(whether we can link the editline library)
      old_LIBS="${LIBS}"
      LIBS="${LIBS} -ledit"
      AC_TRY_LINK([#include <histedit.h>],
                  [history_init();],
                  [AC_MSG_RESULT(yes);
                   AC_DEFINE(HAVE_EDITLINE,,[Have editline library])
                   EDITLINE_LIBS="-ledit"],
                  [AC_MSG_RESULT(no)])
      LIBS="$old_LIBS"],)

else
  READLINE=""
fi
AM_CONDITIONAL(NEED_READLINE, test x"$READLINE" != "x")
AC_SUBST(READLINE)
AC_SUBST(READLINE_LIBS)
AC_SUBST(EDITLINE_LIBS)

dnl check Amiga graphics support
if test x"$is_amiga" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
  cgx_present=no
  p96_present=no
  if test x"$with_picasso96" != "xyes"; then
    AC_CHECK_HEADERS(proto/cybergraphics.h,[cgx_present=yes],,)
  fi

  if test x"$cgx_present" = "xno"; then
    AC_CHECK_HEADERS(proto/Picasso96.h,[p96_present=yes],,)
    if test x"$p96_present" = "xno"; then
      AC_CHECK_HEADERS(proto/Picasso96API.h,[p96_present=yes],,)
      if test x"$p96_present" = "xno"; then
        AC_MSG_ERROR([No CGX or P96 headers found])
      fi
    fi
  fi
fi


dnl Configure graphics output drivers
old_LIBS="$LIBS"
GFXOUTPUT_LIBS=

if test x"$with_png" != "xno" ; then
  dnl Check for the PNG library.
  AC_CHECK_HEADER(png.h,,)
  if test x"$ac_cv_header_png_h" = "xyes" ; then
    unset ac_cv_lib_png_png_sig_cmp
    AC_CHECK_LIB(png, png_sig_cmp,
                 [ GFXOUTPUT_LIBS="-lpng $GFXOUTPUT_LIBS";
                   GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS pngdrv.o";
                   HAVE_PNG_SUPPORT="yes";
                   AC_DEFINE(HAVE_PNG,,[Can we use the PNG library?]) ],,)
    if test "$ac_cv_lib_png_png_sig_cmp" = "no"; then
      unset ac_cv_lib_png_png_sig_cmp
      AC_CHECK_LIB(png, png_sig_cmp,
                   [ GFXOUTPUT_LIBS="-lpng -lz $GFXOUTPUT_LIBS";
                     GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS pngdrv.o";
                     HAVE_PNG_SUPPORT="yes";
                     AC_DEFINE(HAVE_PNG,,
                               [Can we use the PNG library?]) ],,"-lz")
    fi
  fi
fi

dnl Check for the GIF or UNGIF library.
AC_CHECK_HEADER(gif_lib.h,,)
if test x"$ac_cv_header_gif_lib_h" = "xyes" ; then
  AC_CHECK_LIB(ungif, EGifPutLine, [ 
               GFXOUTPUT_LIBS="-lungif $GFXOUTPUT_LIBS";
               GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS gifdrv.o";
               HAVE_GIF_SUPPORT="yes";
               AC_DEFINE(HAVE_GIF,,[Can we use the GIF or UNGIF library?]) ],,)
  if test "$ac_cv_lib_ungif_EGifPutLine" = "no"; then
    AC_CHECK_LIB(gif, EGifPutLine, [ 
                 GFXOUTPUT_LIBS="-lgif $GFXOUTPUT_LIBS";
                 GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS gifdrv.o";
                 HAVE_GIF_SUPPORT="yes";
                 AC_DEFINE(HAVE_GIF,,[Can we use the GIF or UNGIF library?]) ],,)
  fi
fi

if test x"$with_jpeg" != "xno" ; then
  dnl Check for the JPEG library.
  AC_CHECK_HEADER(jpeglib.h,,)
  if test x"$ac_cv_header_jpeglib_h" = "xyes" ; then
    AC_CHECK_LIB(jpeg, jpeg_CreateCompress, [ 
                 GFXOUTPUT_LIBS="-ljpeg $GFXOUTPUT_LIBS";
                 GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS jpegdrv.o";
                 HAVE_JPEG_SUPPORT="yes";
                 AC_DEFINE(HAVE_JPEG,,[Can we use the JPEG library?]) ],,)
  fi
fi

LIBS="$old_LIBS"
AC_SUBST(GFXOUTPUT_DRIVERS)
AC_SUBST(GFXOUTPUT_LIBS)

AC_CHECK_HEADERS(portaudio.h, PA_HEADERS="yes", PA_HEADERS="no")

if test x"$PA_HEADERS" = "xyes"; then
  AC_CHECK_LIB(portaudio, Pa_Initialize,
               [LIBS="$LIBS -lportaudio";
                USE_PORTAUDIO_SUPPORT="yes";
                AC_DEFINE(USE_PORTAUDIO,,[Enable portaudio sampling support.])],,)

  if test x"$USE_PORTAUDIO_SUPPORT" != "xyes" -a x"$is_win32" = "xyes"; then
    unset ac_cv_lib_portaudio_Pa_Initialize
    AC_CHECK_LIB(portaudio, Pa_Initialize,
                 [LIBS="$LIBS -lportaudio -lwinmm";
                  USE_PORTAUDIO_SUPPORT="yes";
                  AC_DEFINE(USE_PORTAUDIO,,[Enable portaudio sampling support.])],,-lwinmm)
  fi
fi


AC_CHECK_HEADERS(mpg123.h,[AC_CHECK_LIB(mpg123, mpg123_init,
                     [LIBS="$LIBS -lmpg123";
                      USE_MPG123_SUPPORT="yes";
                      AC_DEFINE(USE_MPG123,,[Enable mpg123 mp3 decoding support.])],,)])

dnl Check for libraries and header files
if test x"$is_unix_x11" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
  X_LIBS=""
  AC_PATH_XTRA

  PATH_X_LIBS="$X_LIBS"
  LINK_X_LIBS=""
  dnl This is necessary because CPP tests use `CPPFLAGS' instead.
  dnl FIXME: Are we sure `AC_PATH_XTRA' will always put only X11
  dnl include paths in?  Let's hope so.
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"

  have_xvideo_header="no"
  have_xvideo_lib="no"

  if [[ x"${enable_gnomeui}" = "xyes" ]] ; then

    have_vte=no

    if test x"$enable_gnomeui3" = "xyes"; then
      PKG_CHECK_MODULES(GTK, [gtk+-3.0])
      AC_DEFINE(HAVE_CAIRO,,[Enable Cairo rendering support])
      HAVE_CAIRO_SUPPORT="yes"
      if test x"$enable_vte" != "xno"; then
        PKG_CHECK_MODULES(VTE, [vte-2.91], have_vte=yes,
           PKG_CHECK_MODULES(VTE, [vte-2.90], have_vte=yes, AC_MSG_RESULT(no)))
      fi
    else
      PKG_CHECK_MODULES(GTK, [gtk+-2.0])
      if test x"$enable_vte" != "xno"; then
        PKG_CHECK_MODULES(VTE, [vte], have_vte=yes, AC_MSG_RESULT(no))
      fi
    fi

    if test x"$have_vte" = "xyes"; then
      HAVE_VTE_SUPPORT="yes"
      AC_DEFINE(HAVE_VTE,,[Enable VTE support])
    fi

    PKG_CHECK_MODULES(PANGO, [pango],
        [AC_DEFINE(HAVE_PANGO,,[Enable support for Pango])
        HAVE_PANGO_SUPPORT="yes"],
        AC_MSG_RESULT(no)
      )

    if test x"$enable_gnomeui3" != "xyes"; then
      PKG_CHECK_MODULES(CAIRO, [cairo >= 0.5.1],
          [AC_DEFINE(HAVE_CAIRO,,[Enable Cairo rendering support])
          HAVE_CAIRO_SUPPORT="yes"],
          AC_MSG_RESULT(no)
        )
      PKG_CHECK_MODULES(GTKGL, [gtkglext-1.0],
          have_gtkglext1=yes;
          HAVE_HWSCALE_SUPPORT="yes";
          AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling]),
          AC_MSG_RESULT(no)
        )
    fi
    X_LIBS="$GTK_LIBS $GTKGL_LIBS $X_LIBS $VTE_LIBS"
    LINK_X_LIBS="$GTK_LIBS $GTKGL_LIBS $LINK_X_LIBS $VTE_LIBS"
    if test x"$ac_cv_lib_readline_readline" = "xyes" -a x"READLINE_HEADER_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_READLINE,,[Enable the readline library])
    fi
  else
    if test x"$ac_cv_lib_readline_readline" = "xno" -o x"READLINE_HEADER_PRESENT" = "xno"; then
      AC_MSG_ERROR(The Xaw port needs Readline)
    fi
    LINK_X_LIBS=${READLINE_LIBS} ${LINK_X_LIBS}
    AC_DEFINE(USE_COLOR_MANAGEMENT,,[Enable new color management code.])

    AC_CHECK_LIB(w, wslen,[ X_LIBS="-lw $X_LIBS";
                 LINK_X_LIBS="-lw $LINK_X_LIBS"],,$X_LIBS)

    AC_CHECK_LIB(intl, dgettext,[ X_LIBS="-lintl $X_LIBS";
                 LINK_X_LIBS="-lintl $LINK_X_LIBS"],,$X_LIBS)

    dnl instead of assuming that libsocket needs libnsl, we
    dnl will check the existance of libnsl first.
    AC_CHECK_LIB(nsl, gethostbyname,[ X_LIBS="-lnsl $X_LIBS";
                 LINK_X_LIBS="-lnsl $LINK_X_LIBS"],,$X_LIBS)
    AC_CHECK_LIB(socket, gethostbyname,[ X_LIBS="-lsocket $X_LIBS";
                 LINK_X_LIBS="-lsocket $LINK_X_LIBS"],,$X_LIBS)
    AC_CHECK_LIB(bsd, gethostbyname,[ X_LIBS="-lbsd $X_LIBS";
                 LINK_X_LIBS="-lbsd $LINK_X_LIBS"],,$X_LIBS)
    if test x"$ac_cv_lib_ICE_IceConnectionNumber" != "xyes"; then
      unset ac_cv_lib_ICE_IceConnectionNumber
    fi
    AC_CHECK_LIB(ICE, IceConnectionNumber,[ X_LIBS="-lICE $X_LIBS";
                 LINK_X_LIBS="-lICE $LINK_X_LIBS"],,$X_LIBS)
    AC_CHECK_LIB(SM, SmFreeProperty,[ X_LIBS="-lSM $X_LIBS";
                 LINK_X_LIBS="-lSM $LINK_X_LIBS"],,$X_LIBS)

    MISSING_X_LIBS=""

    AC_CHECK_LIB(X11, XCreateWindow,
                 [ X_LIBS="-lX11 $X_LIBS";
                   LINK_X_LIBS="-lX11 $LINK_X_LIBS"],,$X_LIBS)

    if test x"$ac_cv_lib_X11_XCreateWindow" != "xyes"; then
      unset ac_cv_lib_X11_XCreateWindow
      AC_CHECK_LIB(X11, XCreateWindow,
                   [ X_LIBS="-lX11 -lXext $X_LIBS";
                     LINK_X_LIBS="-lX11 -lXext $LINK_X_LIBS"],
                   [ MISSING_X_LIBS="$MISSING_X_LIBS X11" ],$X_LIBS -lXext)
    fi

    AC_CHECK_LIB(Xext, XQueryExtension,
                 [ X_LIBS="-lXext $X_LIBS";
                   LINK_X_LIBS="-lXext $LINK_X_LIBS"],,$X_LIBS)

    dnl the solution to the X_ShmAttach prototype split can be much simpler
    dnl without involving the pkgconfig requirement, relying on pkgconfig
    dnl for simple header checks could lead to the 'problem' not being 'caught'
    dnl if pkgconfig is not installed.

    dnl since xext 7.1 and up have the shmproto.h file and lower versions
    dnl don't have the file we just check for the header and set the define
    dnl when the header is present.

    AC_CHECK_HEADERS(X11/IntrinsicI.h)
    AC_CHECK_HEADERS(X11/XKlib.h)

    AC_CHECK_HEADER(X11/extensions/shmproto.h,
            [ AC_DEFINE(HAVE_X11_EXTENSIONS_SHMPROTO_H,,[Use new XShm header]) ]
            ,,[#include <X11/Xlibint.h>])

    AC_MSG_CHECKING(for X11/extensions/Xvlib.h)
    AC_TRY_LINK([#include <X11/Xlib.h>
                 #include <X11/extensions/Xvlib.h>],
                [return 0;],
                [AC_MSG_RESULT(yes); have_xvideo_header="yes"],
                [AC_MSG_RESULT(no); have_xvideo_header="no"])

    AC_CHECK_LIB(Xv, XvQueryExtension,
                 [ X_LIBS="-lXv $X_LIBS";
                   LINK_X_LIBS="-lXv $LINK_X_LIBS";
                  have_xvideo_lib="yes" ],,$X_LIBS)

    if test x"$have_xvideo_header" != "xno" -a x"$have_xvideo_lib" != "xno"; then
       AC_DEFINE(HAVE_XVIDEO,,[Enable XVideo support.])
       HAVE_XVIDEO_SUPPORT="yes"
       AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
       HAVE_HWSCALE_SUPPORT="yes"
    fi

    AC_CHECK_LIB(Xt, XtToolkitInitialize,
                 [ X_LIBS="-lXt $X_LIBS";
                   LINK_X_LIBS="-lXt $LINK_X_LIBS"],
                 [ MISSING_X_LIBS="$MISSING_X_LIBS Xt" ],$X_LIBS)

    AC_CHECK_LIB(Xmu, XInternAtom,
                 [ X_LIBS="-lXmu $X_LIBS";
                   LINK_X_LIBS="-lXmu $LINK_X_LIBS"],
                 [ MISSING_X_LIBS="$MISSING_X_LIBS Xmu" ],$X_LIBS)

    dnl check for Xpm, on some systems Xpm is required for correct Xaw usage.
    AC_CHECK_LIB(Xpm, XpmCreatePixmapFromData,
                 [ X_LIBS="-lXpm $X_LIBS";
                   LINK_X_LIBS="-lXpm $LINK_X_LIBS";
                   HAVE_LIBXPM_SUPPORT="yes";
                   AC_DEFINE(HAVE_LIBXPM,,[Is libXpm available?]) ],,$X_LIBS)

    dnl Check for Xaw.  Use Xaw3d if requested.
    if test x"$with_xaw3d" != "xyes" ; then
      AC_CHECK_LIB(Xaw, XawFormDoLayout,
                   [ X_LIBS="-lXaw $X_LIBS";
                     LINK_X_LIBS="-lXaw $LINK_X_LIBS"],
                   [ MISSING_X_LIBS="$MISSING_X_LIBS Xaw" ],
                   $X_LIBS $X_PRE_LIBS)
      AC_CHECK_HEADER(X11/Xaw/Tip.h,,)
      if test x"$ac_cv_header_X11_Xaw_Tip_h" != "xyes" ; then
        AC_MSG_ERROR([X11/Xaw/Tip.h is missing.])
      fi
    else
      AC_CHECK_LIB(Xaw3d, XawFormDoLayout,
                   [ X_LIBS="-lXaw3d $X_LIBS";
                     LINK_X_LIBS="-lXaw3d $LINK_X_LIBS";
                     AC_DEFINE(USE_XAW3D,,[Enable Xaw3d.])],
                   [ MISSING_X_LIBS="$MISSING_X_LIBS Xaw3d" ],
                   $X_LIBS $X_PRE_LIBS)
      AC_CHECK_HEADER(X11/Xaw3d/Tip.h,,)
      if test x"$ac_cv_header_X11_Xaw3d_Tip_h" != "xyes" ; then
        AC_MSG_ERROR([X11/Xaw3d/Tip.h is missing.])
      fi
    fi

    dnl We use a relatively "new" feature of Xaw, check for it.
    dnl Also, in Xaw3d, the menus are buggy and remain inverted a lot.
    AC_MSG_CHECKING([if XawNdisplayList is defined])
    AC_TRY_COMPILE([
        /* Xaw or Xaw3d */
        #ifdef USE_XAW3D
        #include <X11/Xaw3d/Simple.h>
        #else
        #include <X11/Xaw/Simple.h>
        #endif
      ],
      [ char *c = XawNdisplayList ],
      [AC_MSG_RESULT(yes)],
      [AC_MSG_RESULT(no)
       AC_MSG_WARN([[X11/{Xaw or Xaw3d}/Simple.h does not #define XawNdisplayList. It is recommended to use at least version 7 of Xaw. Xaw3d based on older versions is buggy and incomplete. This warning will turn into an error soon.]])]
    )

    AC_CHECK_HEADER(X11/extensions/XShm.h,,,[#include <X11/Xlib.h>])
    if test x"$ac_cv_header_X11_extensions_XShm_h" = "xyes" ; then
      AC_CHECK_LIB(Xext, XShmAttach,
                   [ AC_DEFINE(USE_MITSHM,,
                   [Enable MITSHM extensions.])
                   USE_MITSHM_SUPPORT="yes"],,$X_LIBS)
    fi


    if test x"$MISSING_X_LIBS" != "x"; then
      AC_MSG_ERROR([The following important X11 libraries were not found: $MISSING_X_LIBS])
    fi

    AC_CHECK_HEADERS(X11/Sunkeysym.h X11/xpm.h xpm.h)
  fi

  AC_CHECK_HEADER(GL/glx.h,,,[#include <GL/gl.h>])
  if test x"$ac_cv_header_GL_glx_h" = "xyes" ; then
    AC_CHECK_LIB(GL, glXWaitVideoSyncSGI,
                 [ X_LIBS="-lGL $X_LIBS";
                   LINK_X_LIBS="-lGL $LINK_X_LIBS";
		   VICE_SYNC="openGL_sync.o $VICE_SYNC";
              HAVE_OPENGL_SYNC_SUPPORT="yes";
              USE_XF86_EXTENSIONS_SUPPORT="yes";
              AC_DEFINE(USE_XF86_EXTENSIONS,,[Enable XF86 extensions.])
              AC_DEFINE(HAVE_OPENGL_SYNC,,
		   [Enable openGL synchronization])
              ],,$X_LIBS)
  fi
  AC_SUBST(VICE_SYNC)

  if test x"$with_uithreads" = "xyes" ; then
    if test x"$have_gtkglext1" != "xyes" -a x"$have_gtkglext3" != "xyes" ; then
      AC_MSG_WARN([no suitable GL hardware scaling support found, disabling --with-uithreads])
    else
      AC_CHECK_HEADER(pthread.h,,,[#include <pthread.h>])
      if test x"$ac_cv_header_pthread_h" = "xyes" ; then
        AC_CHECK_HEADER(semaphore.h,,,[#include <semaphore.h>])
        if test x"$ac_cv_header_semaphore_h" = "xyes" ; then
           AC_CHECK_LIB(pthread, pthread_create,
                     [ is_threaded=yes;
                       VICE_UI_THREADS="ui-threads.o";
                       USE_UI_THREADS_SUPPORT="yes";
                       AC_DEFINE(USE_UI_THREADS,,[Enable multithreaded UI.])
    		 ],,$X_LIBS)
        fi
      fi
      AC_SUBST(VICE_UI_THREADS)
    fi
  fi

  # Some systems can't dynamically open (dlopen(3)) a shared library which is
  # threaded unless the main program is threaded too (or at least compiled
  # with the options for that) due to the invasiveness of libpthread.
  # The FFMPEG libraries are threaded, so they trigger this difficulty.
  # So make sure -pthread is added when one of those may be dlopen()ed.

  case "$host_os" in
    netbsd*)
      cant_dlopen_libpthread=yes
      ;;
  esac

  if test x"$cant_dlopen_libpthread" = xyes -a x"$dlopen_pthread" = xyes ; then
      is_threaded=yes
  fi

  if test x"$is_threaded" = xyes ; then
      CFLAGS="$CFLAGS -pthread"
      LDFLAGS="$LDFLAGS -pthread"
  fi

  dnl Check for XFree86 header and library extensions.
  FULLSCREEN_DRIVERS=""

  if test x"$enable_fullscreen" != "xno"; then

    dnl currently fullscreen gnomeui is done with X11 dependent libs,
    dnl so check for X11
    if test x"$enable_gnomeui" = "xyes"; then
        AC_CHECK_LIB(X11, XCreateWindow,
                     [ X_LIBS="-lX11 $X_LIBS";
                       LINK_X_LIBS="-lX11 $LINK_X_LIBS"],,$X_LIBS)
    fi
    AC_CHECK_HEADER(X11/extensions/xf86vmode.h,,,[#include <X11/Xlib.h>])
    if test x"$ac_cv_header_X11_extensions_xf86vmode_h" = "xyes" ; then
      AC_CHECK_LIB(Xxf86vm, XF86VidModeQueryVersion,
                   [ X_LIBS="-lXxf86vm $X_LIBS";
                     LINK_X_LIBS="-lXxf86vm $LINK_X_LIBS";
                     FULLSCREEN_DRIVERS="$FULLSCREEN_DRIVERS vidmode.o";
                     USE_XF86_VIDMODE_EXT_SUPPORT="yes";
                     AC_DEFINE(USE_XF86_VIDMODE_EXT,,
                               [Enable XF86 VidMode extensions.])
                     AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
                     HAVE_FULLSCREEN_SUPPORT="yes";
                     USE_XF86_EXTENSIONS_SUPPORT="yes";
                     AC_DEFINE(USE_XF86_EXTENSIONS,,
                               [Enable XF86 extensions.])],,$X_LIBS)
    fi
    AC_CHECK_HEADER(X11/extensions/Xrandr.h,,,[#include <X11/Xlib.h>])
    if test x"$ac_cv_header_X11_extensions_Xrandr_h" = "xyes" ; then
      AC_CHECK_LIB(Xrandr, XRRConfigCurrentRate,
                   [ X_LIBS="-lXrandr $X_LIBS";
                     LINK_X_LIBS="-lXrandr $LINK_X_LIBS";
                     FULLSCREEN_DRIVERS="$FULLSCREEN_DRIVERS xrandr.o";
                     USE_XF86_EXTENSIONS_SUPPORT="yes";
                     AC_DEFINE(USE_XF86_EXTENSIONS,,[Enable XF86 extensions.])
                     AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
                     HAVE_FULLSCREEN_SUPPORT="yes";
                     HAVE_XRANDR_SUPPORT="yes";
                     AC_DEFINE(HAVE_XRANDR,,
                     [Enable XRandR extension.])],,$X_LIBS)
    fi
  fi

  X_LIBS="$PATH_X_LIBS $LINK_X_LIBS"
  AC_SUBST(FULLSCREEN_DRIVERS)

  OLD_LIBS=$LIBS
  LIBS="$LIBS $X_LIBS"
  AC_CHECK_FUNCS(_XlcConvert _XlcCurrentLC _XlcOpenConverter _XlcCloseConverter,,[xlc_funcs_present=no],)
  LIBS=$OLD_LIBS
  if test x"$xlc_funcs_present" != "xno"; then
    AC_DEFINE(XLC_FUNCS_PRESENT,,[Enable _Xlc_* functions.])
  fi

elif test x"$is_dos" = "xyes"; then

  dnl On MS-DOS, we already know what we want.

  if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
    LIBS="$LIBS $LIBMIDAS"
  else
    LIBS="$LIBS -lalleg $LIBMIDAS"
  fi
  AC_SUBST(LDFLAGS)

elif test x"$is_amiga" = "xyes"; then

  dnl On Amiga, we already know what we want.
  if test x"$is_amiga_aros" != "xyes"; then
    if test x"$host_os" != "xmorphos" -a x"$host_os" != "xwarpos" -a x"$host_os" != "xpowerup"; then
      LIBS="$LIBS -lauto"
    fi
  else
    if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
      LIBS="$LIBS -lmui"
    fi
  fi
  AC_SUBST(LDFLAGS)

  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    AC_DEFINE(HAS_TRANSLATION,,[Enable internationalization support])
  fi

elif test x"$is_beos" = "xyes"; then

  dnl On BEOS, we already know what we want.

  LIBS="$LIBS -lbe -ltracker -ldevice -lmedia -lgame"
  AC_SUBST(LDFLAGS)

elif test x"$is_win32" = "xyes" -a x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then

  dnl On Windows, we already know what we want.

  if test x"$host_cpu" = "xx86_64" -o x"$host_cpu" = "xamd64"; then
    LIBS="$LIBS -lkernel32 -luser32 -lgdi32 -lwinmm -lcomdlg32 -lcomctl32 -lws2_32 -lversion"
  else
    LIBS="$LIBS -lkernel32 -luser32 -lgdi32 -lwinmm -lcomdlg32 -lcomctl32 -lwsock32 -lversion"
  fi

  AC_CHECK_HEADER(d3d9.h,
      [ AC_DEFINE(HAVE_D3D9_H,,[Support for DirectX9.])
        HAVE_D3D9_H_SUPPORT="yes" ],)
  AC_CHECK_LIB(dxguid, GUID_SysMouse,[LIBS="$LIBS -ldxguid";
               AC_DEFINE(HAVE_GUIDLIB,,
                         [Is the GUID lib of DX SDK present?])],,$LIBS)

  if test x"$enable_unicode" = "xyes"; then
    AC_DEFINE(WIN32_UNICODE_SUPPORT,,[Use WinNT Unicode API calls.])
    ENABLE_UNICODE_API_SUPPORT="yes"
  fi

  AC_MSG_CHECKING([if we have an ISO C99 compliant vswprintf function])
  AC_TRY_COMPILE([#include <stdarg.h>
                  #include <wchar.h>],
                 [va_list args;
                  wchar_t buf[10];
                  vswprintf(buf, 10, L"%d", args)],
                 [AC_DEFINE(HAVE_STDC_VSWPRINTF,,[Do we have an ISO C99 compliant vswprintf function?])
                  AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))

  AC_MSG_CHECKING([whether DWORD is defined as unsigned long or unsigned int in the Mingw32 headers])
  AC_TRY_COMPILE([#include <windows.h>
                  extern DWORD test;
                  unsigned long test; ],
                 ,
                 [ AC_DEFINE(DWORD_IS_LONG,,
                   [Is DWORD defined as long or int in the Windows header files?])
                   AC_MSG_RESULT(unsigned long) ], AC_MSG_RESULT(unsigned int))

  vsid_LDFLAGS="-mwindows"
  x64_LDFLAGS="-mwindows"
  x128_LDFLAGS="-mwindows"
  xscpu64_LDFLAGS="-mwindows"
  xvic_LDFLAGS="-mwindows"
  xpet_LDFLAGS="-mwindows"
  xplus4_LDFLAGS="-mwindows"
  xcbm2_LDFLAGS="-mwindows"

  if test x"$CC" != "xowcc"; then
    VSID_WINRES="\$(top_builddir)/src/arch/win32/resvsid.o"
    X64_WINRES="\$(top_builddir)/src/arch/win32/resc64.o"
    X64DTV_WINRES="\$(top_builddir)/src/arch/win32/resc64dtv.o"
    XSCPU64_WINRES="\$(top_builddir)/src/arch/win32/resscpu64.o"
    X128_WINRES="\$(top_builddir)/src/arch/win32/resc128.o"
    XVIC_WINRES="\$(top_builddir)/src/arch/win32/resvic20.o"
    XPET_WINRES="\$(top_builddir)/src/arch/win32/respet.o"
    XPLUS4_WINRES="\$(top_builddir)/src/arch/win32/resplus4.o"
    XCBM2_WINRES="\$(top_builddir)/src/arch/win32/rescbm2.o"
    XCBM5X0_WINRES="\$(top_builddir)/src/arch/win32/rescbm5x0.o"
  fi

  AC_SUBST(LDFLAGS)

  if test -z "$WINDRES" ; then
    WINDRES="windres"
  fi

  AC_SUBST(WINDRES)

  AC_DEFINE(HAS_TRANSLATION,,[Enable internationalization support])
fi

dnl CBM4Linux/OpenCBM
AC_MSG_CHECKING([for OpenCBM support])
if test x"$enable_realdevice" != "xno"; then
  if test x"$host_os" = "xcygwin32" -o x"$host_os" = "xcygwin" -o x"$host_os" = "xmingw32" -o x"$host_os" = "xmingw32msvc"; then
    AC_DEFINE(HAVE_OPENCBM,,[Support for OpenCBM (former CBM4Linux).])
    HAVE_OPENCBM_SUPPORT="yes"
    AM_CONDITIONAL(HAVE_REALDEVICE, true)
    AC_MSG_RESULT([yes])
  else
    if test x"$dynlib_support" = "xyes"; then
      if test x"$is_beos" != "xyes"; then 
        AC_DEFINE(HAVE_OPENCBM,,[Support for OpenCBM (former CBM4Linux).])
        HAVE_OPENCBM_SUPPORT="yes"
        AM_CONDITIONAL(HAVE_REALDEVICE, true)
        AC_MSG_RESULT([yes])
      else
        AM_CONDITIONAL(HAVE_REALDEVICE, false)
        AC_MSG_RESULT([no (not supported on current host)])
      fi
    else
      AM_CONDITIONAL(HAVE_REALDEVICE, false)
      AC_MSG_RESULT([no (dynamic lib support missing)])
    fi
  fi
else
  AM_CONDITIONAL(HAVE_REALDEVICE, false)
  AC_MSG_RESULT([no (realdevice disabled)])
fi

AC_SUBST(vsid_LDFLAGS)
AC_SUBST(x64_LDFLAGS)
AC_SUBST(x128_LDFLAGS)
AC_SUBST(xscpu64_LDFLAGS)
AC_SUBST(xvic_LDFLAGS)
AC_SUBST(xpet_LDFLAGS)
AC_SUBST(xplus4_LDFLAGS)
AC_SUBST(xcbm2_LDFLAGS)

AC_SUBST(VSID_WINRES)
AC_SUBST(X64_WINRES)
AC_SUBST(X64DTV_WINRES)
AC_SUBST(XSCPU64_WINRES)
AC_SUBST(X128_WINRES)
AC_SUBST(XVIC_WINRES)
AC_SUBST(XPET_WINRES)
AC_SUBST(XPLUS4_WINRES)
AC_SUBST(XCBM2_WINRES)
AC_SUBST(XCBM5X0_WINRES)

AM_CONDITIONAL(SUPPORT_X64DTV, true)
AM_CONDITIONAL(SUPPORT_X64SC, true)

dnl xscpu64 should be supported on all platforms
AM_CONDITIONAL(SUPPORT_XSCPU64, true)

dnl Setup the system-specific object files.
if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
  ARCH_DIR="\$(top_builddir)/src/arch/sdl"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/sdl"
  ARCH_LIBS="$ARCH_DIR/libarch.a"
  if test x"$is_win32" = "xyes"; then
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/win32/msvc/wpcap"
  else
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch"
  fi
  if test x"$ac_cv_lib_readline_readline" = "xyes"; then
    AC_DEFINE(HAVE_READLINE,,[Enable the readline library])
  fi
  AC_DEFINE(HAS_JOYSTICK,,[Enable joystick emulation.])
  HAS_JOYSTICK_SUPPORT="yes"
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"
  AM_CONDITIONAL(SDL_COMPILE, true)
  if test x"$enable_sdlui2" = "xyes"; then
    SDL_VERSION=2
  else
    SDL_VERSION=1
  fi
  AC_SUBST(SDL_VERSION)
else
  AM_CONDITIONAL(SDL_COMPILE, false)
fi

SDL_EXTRA_LIBS=""

AM_CONDITIONAL(MAKE_BINDIST, false)

if test x"$is_unix" = "xyes"; then

  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    ARCH_DIR="\$(top_builddir)/src/arch/unix"
    ARCH_SRC_DIR="\$(top_srcdir)/src/arch/unix"
    ARCH_EXTRA_SUBDIR="gui x11"

    if test x"$is_unix_x11" = "xyes" ; then
      if test x"$enable_gnomeui" != "xyes" ; then
        ARCH_LIBS="$ARCH_DIR/libarch.a $ARCH_DIR/gui/libarchgui.a $ARCH_DIR/x11/libx11ui.a $ARCH_DIR/x11/xaw/libxawui.a $ARCH_DIR/x11/xaw/widgets/libwidgets.a $ARCH_DIR/libarch.a $ARCH_DIR/gui/libarchgui.a $ARCH_DIR/x11/libx11ui.a"
        ARCH_INCLUDES="-I$ARCH_SRC_DIR"
        AC_DEFINE(USE_XAWUI,,[Are we using the Unix/X11/Xaw ui?])
      else
        ARCH_LIBS="$ARCH_DIR/libarch.a $ARCH_DIR/gui/libarchgui.a $ARCH_DIR/x11/gnome/libgnomeui.a $ARCH_DIR/x11/libx11ui.a"
        ARCH_INCLUDES="-I$ARCH_SRC_DIR $GTK_CFLAGS $GTKGL_CFLAGS $VTE_CFLAGS"
      fi

      AC_DEFINE(HAVE_READLINE,,[Are we using the readline library replacement?])

      AC_CHECK_HEADERS(stdlib.h,AC_DEFINE(HAVE_STDLIB,,[We are using stdlib.h]))

      if test x"$READLINE" != "x"; then
        ARCH_EXTRA_SUBDIR="$ARCH_EXTRA_SUBDIR readline"
      fi
    fi
  else
    AC_DEFINE(UNIX_COMPILE,,[Are we compiling for unix?])
  fi

  if test x"$is_unix_macosx" = "xyes" ; then
    ARCH_MAKE_BINDIST_DIR="\$(top_srcdir)/src/arch/unix/macosx"
    if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
      UNIX_MACOSX_UITYPE=sdl
    elif test x"$with_cocoa" = "xyes" ; then
      ARCH_LIBS="$ARCH_DIR/macosx/cocoa/menu/libarchmacosxcocoamenu.a $ARCH_DIR/macosx/cocoa/dialog/libarchmacosxcocoadialog.a $ARCH_DIR/macosx/cocoa/libarchmacosxcocoa.a $ARCH_DIR/macosx/cocoa/view/libarchmacosxcocoaview.a $ARCH_DIR/macosx/libarchmacosx.a $ARCH_DIR/libarch.a $ARCH_LIBS"
      ARCH_INCLUDES="-I$ARCH_SRC_DIR/macosx/cocoa/menu -I$ARCH_SRC_DIR/macosx/cocoa/dialog -I$ARCH_SRC_DIR/macosx/cocoa/view -I$ARCH_SRC_DIR/macosx/cocoa -I$ARCH_SRC_DIR/macosx -I$ARCH_SRC_DIR $ARCH_INCLUDES"
      ARCH_EXTRA_SUBDIR="macosx macosx/cocoa macosx/cocoa/view macosx/cocoa/menu macosx/cocoa/dialog"
      UI_LIBS="-framework Cocoa -framework OpenGL -framework Carbon -framework CoreVideo"
      UNIX_MACOSX_UITYPE=cocoa
    else
      ARCH_LIBS="$ARCH_DIR/macosx/libarchmacosx.a $ARCH_LIBS"
      ARCH_INCLUDES="-I$ARCH_SRC_DIR/macosx $ARCH_INCLUDES"
      ARCH_EXTRA_SUBDIR="$ARCH_EXTRA_SUBDIR macosx"
      UI_LIBS="$UI_LIBS -framework CoreVideo"
      if test x"$enable_gnomeui" != "xyes" ; then
        UNIX_MACOSX_UITYPE=x11
      else
        UNIX_MACOSX_UITYPE=gtk
      fi
    fi
  fi
  AC_SUBST(UNIX_MACOSX_UITYPE)

  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(UNIX_COMPILE, true)
  AM_CONDITIONAL(WIN32_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, false)
  AM_CONDITIONAL(OS2_COMPILE, false)
  AM_CONDITIONAL(BEOS_COMPILE, false)
  AM_CONDITIONAL(AMIGA_COMPILE, false)
  AM_CONDITIONAL(HAVE_TRANSLATION, false)
  scounixcompile=no
  openserver5compile=no
  openserver6compile=no
  unixwarecompile=no
  qnx4compile=no
  qnx6compile=no
  solariscompile=no
  hpuxcompile=no
  skyoscompile=no
  syllablecompile=no
  nextstepcompile=no
  openstepcompile=no
  rhapsodycompile=no
  case "$host_os" in
    rhapsody*)
      rhapsodycompile=yes
      AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, true)
      AC_DEFINE(RHAPSODY_COMPILE,,[Enable Rhapsody 5.x support])
      ;;
    openstep*)
      openstepcompile=yes
      AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, true)
      AC_DEFINE(OPENSTEP_COMPILE,,[Enable OpenStep 4.x support])
      ;;
    nextstep*)
      nextstepcompile=yes
      AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, true)
      AC_DEFINE(NEXTSTEP_COMPILE,,[Enable NextStep 3.x support])
      ;;
    skyos*)
      skyoscompile=yes
      AM_CONDITIONAL(UNIX_SKYOS_COMPILE, true)
      ;;
    qnx*)
      qnx4compile=yes
      AM_CONDITIONAL(UNIX_QNX4_COMPILE, true)
      ;;
    nto*)
      qnx6compile=yes
      AM_CONDITIONAL(UNIX_QNX6_COMPILE, true)
      ;;
    solaris*)
      solariscompile=yes
      AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, true)
      sol_version=`uname -r`
      if test x"$sol_version" = "x5.7"; then
        ac_configure_args="$ac_configure_args"
      fi
      ;;
    sco3.2v4*)
      scounixcompile=yes
      AM_CONDITIONAL(UNIX_SCO4_COMPILE, true)
      AC_DEFINE(SCO4UNIX_COMPILE,,[Enable SCO Unix 4.x support])
      ;;
    sco3.2v5*)
      openserver5compile=yes
      AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, true)
      AC_DEFINE(OPENSERVER5_COMPILE,,[Enable SCO Openserver 5.x support])
      ;;
    sco3.2v6*)
      openserver6compile=yes
      AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, true)
      AC_DEFINE(OPENSERVER6_COMPILE,,[Enable SCO Openserver 6.x support])
      ;;
    sco3.2v7*)
      unixwarecompile=yes
      AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, true)
      AC_DEFINE(UNIXWARE_COMPILE,,[Enable SCO Unixware 7.x support])
      ;;
    hpux*)
      hpuxcompile=yes
      AM_CONDITIONAL(UNIX_HPUX_COMPILE, true)
      ;;
    syllable*)
      syllablecompile=yes
      AM_CONDITIONAL(SYLLABLE_COMPILE, true)
      ;;
    *)
      ;;  
  esac

  if test x"$skyoscompile" = "xno"; then
    AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  fi

  if test x"$qnx4compile" = "xno"; then
    AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  fi

  if test x"$qnx6compile" = "xno"; then
    AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  fi

  if test x"$nextstepcompile" = "xno"; then
    AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  fi

  if test x"$openstepcompile" = "xno"; then
    AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  fi

  if test x"$rhapsodycompile" = "xno"; then
    AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  fi

  if test x"$solariscompile" = "xno"; then
    AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  fi

  if test x"$scounixcompile" = "xno"; then
    AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  fi

  if test x"$openserver5compile" = "xno"; then
    AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  fi

  if test x"$openserver6compile" = "xno"; then
    AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)
  fi

  if test x"$unixwarecompile" = "xno"; then
    AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)
  fi

  if test x"$hpuxcompile" = "xno"; then
    AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  fi

  if test x"$syllablecompile" = "xno"; then
    AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  fi

  if test x"$is_unix_macosx" = "xyes" ; then
    AM_CONDITIONAL(UNIX_MACOSX_COMPILE, true)
    if test x"$enable_bundle" != "xno" ; then
      AM_CONDITIONAL(MAKE_BINDIST, true)
    else
      AM_CONDITIONAL(MAKE_BINDIST, false)
    fi
  else
    AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  fi


elif test x"$is_win32" = "xyes"; then
  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    ARCH_DIR="\$(top_builddir)/src/arch/win32"
    ARCH_SRC_DIR="\$(top_srcdir)/src/arch/win32"
    ARCH_LIBS="$ARCH_DIR/libarch.a"
    ARCH_INCLUDES="-I\$(top_srcdir)/src/arch/win32"
    if test x"$host_os" = "xcygwin32" -o x"$host_os" = "xcygwin"; then
      AC_DEFINE([PLATFORM], ["win32 x86 cygwin"],[The current arch, cpu and compiler used.])
    else
      if test x"$host_cpu" = "xx86_64" -o x"$host_cpu" = "xamd64"; then
        AC_DEFINE([PLATFORM], ["win64 x64 mingw"], [The current arch, cpu and compiler used.])
      else
        if test x"$CC" = "xowcc"; then
          AC_DEFINE([PLATFORM], ["win32 x86 owcc"], [The current arch, cpu and compiler used.])
        else
          AC_DEFINE([PLATFORM], ["win32 x86 mingw"], [The current arch, cpu and compiler used.])
        fi
      fi
    fi
  fi
  AC_DEFINE(WIN32_COMPILE,,[Are we compiling for win32?])

  if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
    if test x"$host_cpu" = "xx86_64" -o x"$host_cpu" = "xamd64"; then
      SDL_EXTRA_LIBS="$UI_LIBS -lwinmm -lws2_32"
    else
      SDL_EXTRA_LIBS="$UI_LIBS -lwinmm -lwsock32"
    fi
  fi

  AM_CONDITIONAL(WIN32_COMPILE, true)
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)
  AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)
  AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, false)
  AM_CONDITIONAL(OS2_COMPILE, false)
  AM_CONDITIONAL(BEOS_COMPILE, false)
  AM_CONDITIONAL(AMIGA_COMPILE, false)
  AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(HAVE_TRANSLATION, true)
  AM_CONDITIONAL(MAKE_BINDIST, true)
elif test x"$is_amiga" = "xyes"; then
  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    ARCH_DIR="\$(top_builddir)/src/arch/amigaos"
    ARCH_SRC_DIR="\$(top_srcdir)/src/arch/amigaos"
    ARCH_LIBS="$ARCH_DIR/libarch.a $ARCH_DIR/mui/libarchmui.a"
    ARCH_INCLUDES="-I\$(top_srcdir)/src/arch/amigaos"
  fi
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)
  AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)
  AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  AM_CONDITIONAL(WIN32_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, false)
  AM_CONDITIONAL(OS2_COMPILE, false)
  AM_CONDITIONAL(BEOS_COMPILE, false)
  AM_CONDITIONAL(AMIGA_COMPILE, true)
  AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(HAVE_TRANSLATION, true)
  AM_CONDITIONAL(MAKE_BINDIST, true)
elif test x"$is_dos" = "xyes"; then
  ARCH_INCLUDES="-I\$(top_srcdir)/src/arch/msdos"
  ARCH_DIR="\$(top_builddir)/src/arch/msdos"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/msdos"
  if test x"$ac_cv_lib_pcap_pcap_open_live" = "xyes"; then
    ARCH_LIBS="$ARCH_DIR/libarch.a $ARCH_DIR/libpcap_nodma.a"
  else
    ARCH_LIBS="$ARCH_DIR/libarch.a"
  fi
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)
  AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)
  AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  AM_CONDITIONAL(WIN32_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, true)
  AM_CONDITIONAL(OS2_COMPILE, false)
  AM_CONDITIONAL(BEOS_COMPILE, false)
  AM_CONDITIONAL(AMIGA_COMPILE, false)
  AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(HAVE_TRANSLATION, false)
  AM_CONDITIONAL(MAKE_BINDIST, true)
elif test x"$is_os2" = "xyes"; then
  ARCH_INCLUDES="-I\$(top_srcdir)/src/arch/os2"
  ARCH_DIR="\$(top_builddir)/src/arch/os2"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/os2"
  ARCH_LIBS="$ARCH_DIR/libarch.a"
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)
  AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)
  AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  AM_CONDITIONAL(WIN32_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, false)
  AM_CONDITIONAL(OS2_COMPILE, true)
  AM_CONDITIONAL(BEOS_COMPILE, false)
  AM_CONDITIONAL(AMIGA_COMPILE, false)
  AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(HAVE_TRANSLATION, false)
  AM_CONDITIONAL(MAKE_BINDIST, true)
elif test x"$is_beos" = "xyes"; then
  if test x"$enable_sdlui" != "xyes" -a x"$enable_sdlui2" != "xyes"; then
    ARCH_INCLUDES="-I\$(top_srcdir)/src/arch/beos"
    ARCH_DIR="\$(top_builddir)/src/arch/beos"
    ARCH_SRC_DIR="\$(top_srcdir)/src/arch/beos"
    ARCH_LIBS="$ARCH_DIR/libarch.a"
  fi
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(UNIX_SKYOS_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX4_COMPILE, false)
  AM_CONDITIONAL(UNIX_QNX6_COMPILE, false)
  AM_CONDITIONAL(UNIX_SOLARIS_COMPILE, false)
  AM_CONDITIONAL(UNIX_RHAPSODY_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_NEXTSTEP_COMPILE, false)
  AM_CONDITIONAL(UNIX_SCO4_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER5_COMPILE, false)
  AM_CONDITIONAL(UNIX_OPENSERVER6_COMPILE, false)  
  AM_CONDITIONAL(UNIX_UNIXWARE_COMPILE, false)  
  AM_CONDITIONAL(UNIX_HPUX_COMPILE, false)
  AM_CONDITIONAL(SYLLABLE_COMPILE, false)
  AM_CONDITIONAL(WIN32_COMPILE, false)
  AM_CONDITIONAL(MSDOS_COMPILE, false)
  AM_CONDITIONAL(OS2_COMPILE, false)
  AM_CONDITIONAL(BEOS_COMPILE, true)
  AM_CONDITIONAL(AMIGA_COMPILE, false)
  AM_CONDITIONAL(UNIX_MACOSX_COMPILE, false)
  AM_CONDITIONAL(SUPPORT_CMDLINE_TOOLS, true)
  AM_CONDITIONAL(HAVE_TRANSLATION, false)
  AM_CONDITIONAL(MAKE_BINDIST, true)
else
  AC_MSG_WARN([No architecture defined!])
fi

dnl Check wether we have gcc
if test x"$GCC" = "xyes" ; then
  AC_DEFINE(USE_GCC,, [Define when using gcc] )
fi

dnl Check wether we have gcc and solaris /usr/openwin stuff.
dnl The headers there give zillions of warnings because of implicit int 
dnl declarations. gcc's >= 2.6.3 know the `-Wno-implicit-int' option so I 
dnl don't care about checking it out. MP

if test x"$GCC" = "xyes" ; then
  case "$host_os" in
    solaris2.3*)
      LIBS="$LIBS -lthread"
      ;;
    solaris*)
      if echo ${CFLAGS} ${ARCH_INCLUDES} | grep "I/usr/openwin/include" > /dev/null 2>&1 ; then
          CFLAGS="${CFLAGS} -Wno-implicit-int"
      fi
      ;;
    *)
      ;;  
  esac
fi

AC_SUBST(HAVE_READLINE)
AC_SUBST(ARCH_INCLUDES)
AC_SUBST(ARCH_LIBS)
AC_SUBST(ARCH_DIR)
AC_SUBST(ARCH_SRC_DIR)
AC_SUBST(ARCH_MAKE_BINDIST_DIR)
AC_SUBST(ARCH_EXTRA_SUBDIR)
AC_SUBST(UI_LIBS)
AC_SUBST(SDL_EXTRA_LIBS)
AC_SUBST(SOUND_USS_OBJ)
AC_SUBST(SOUND_SGI_OBJ)
AC_SUBST(SOUND_HPUX_OBJ)
AC_SUBST(SOUND_AIX_OBJ)
AC_SUBST(SOUND_MIDAS_OBJ)
AC_SUBST(SOUND_SDL_OBJ)

PLATFORM_DOX_FLAGS=""
if test x"$enable_platformdox" = "xyes"; then
  if test x"$enable_sdlui" = "xyes" -o x"$enable_sdlui2" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformsdl"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$enable_gnomeui3" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformgtk3"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$enable_gnomeui" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformgtk2"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x"; then
    if test x"$is_unix_x11" = "xyes" -o x"$is_win32_x11" = "xyes" -o x"$is_beos_x11" = "xyes"; then
      PLATFORM_DOX_FLAGS="platformxaw"
    fi
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_amigaos3" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformamigaos3"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_amigaos4" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformamigaos4"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_amiga_morphos" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformmorphos"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_amiga_aros" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformaros"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_unix_macosx" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformosx"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_beos" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformbeos"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_dos" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformdos"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_os2" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformos2"
  fi

  if test x"$PLATFORM_DOX_FLAGS" = "x" -a x"$is_win32" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformwindows"
  fi
fi
if test x"$PLATFORM_DOX_FLAGS" = "x"; then
  PLATFORM_DOX_FLAGS="platformall"
fi
AC_SUBST(PLATFORM_DOX_FLAGS)

if test "$prefix" = NONE && test "$exec_prefix" = NONE; then
  PREFIX="$ac_default_prefix"
elif test "$prefix" = NONE; then
  PREFIX="$exec_prefix"
else
  PREFIX="$prefix"
fi

AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX",
		   [Where do we want to install the executable?])

dnl Fix for po directory Makefile
case "$host_os" in
  freebsd*)
    AM_CONDITIONAL(PO_SRCDIR_PREFIX, false)
    ;;
  *)
    AM_CONDITIONAL(PO_SRCDIR_PREFIX, true)
    ;;
esac

dnl Path for keymaps, ROMs etc.
case "$host_os" in
  netbsd*)
    VICEDIR="$PREFIX/share/vice"
    AM_CONDITIONAL(ALTERNATE_DOCDIR, true)
    ;;
  freebsd*)
    VICEDIR="$PREFIX/lib/vice"
    AM_CONDITIONAL(ALTERNATE_DOCDIR, true)
    ;;
  linux*)
    if test x"$host_cpu" = "xx86_64"; then
      VICEDIR="$PREFIX/lib64/vice"
      AM_CONDITIONAL(ALTERNATE_DOCDIR, false)
    else
      VICEDIR="$PREFIX/lib/vice"
      AM_CONDITIONAL(ALTERNATE_DOCDIR, false)
    fi
    ;;
  *)
    VICEDIR="$PREFIX/lib/vice"
    AM_CONDITIONAL(ALTERNATE_DOCDIR, false)
    ;;  
esac
AC_SUBST(VICEDIR)
AC_DEFINE_UNQUOTED(VICEDIR, "$VICEDIR",
		   [Where should we lookup for data files?])


# Add path with private dynamic ffmpeg libs to the search path
rpath_line=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$LDFLAGS" "$LD" "$with_gnu_ld" "$host" "$VICEDIR/lib"`
LDFLAGS="$LDFLAGS $rpath_line"

AC_OUTPUT([Makefile
           vice.spec
           vice-gtk.spec
           vice-mint.spec
           vice-mint-sdl.spec
           build/Makefile
           build/amigaos/Makefile
           build/android/Makefile
           build/beos/Makefile
           build/macosx/Makefile
           build/mingw32/Makefile
           build/minix3/Makefile
           build/nextstep/Makefile
           build/openstep/Makefile
           build/openwatcom/Makefile
           build/qnx4/Makefile
           build/rhapsody/Makefile
           data/Makefile
           data/C128/Makefile
           data/C64/Makefile
           data/C64DTV/Makefile
           data/CBM-II/Makefile
           data/DRIVES/Makefile
           data/PET/Makefile
           data/PLUS4/Makefile
           data/SCPU64/Makefile
           data/PRINTER/Makefile
           data/VIC20/Makefile
           data/fonts/Makefile
           doc/Makefile
           doc/building/Makefile
           doc/html/Makefile
           doc/readmes/Makefile
           man/Makefile
           src/Makefile
           src/debug.h
           src/arch/Makefile
           src/arch/amigaos/Makefile
           src/arch/amigaos/info-files/Makefile
           src/arch/amigaos/info-files/morphos/Makefile
           src/arch/amigaos/mui/Makefile
           src/arch/android/Makefile
           src/arch/android/AnVICE/AndroidManifest.xml
           src/arch/android/AnVICE/Makefile
           src/arch/android/AnVICE/.settings/Makefile
           src/arch/android/AnVICE/assets-proto/Makefile
           src/arch/android/AnVICE/jni/Makefile
           src/arch/android/AnVICE/jni/locnet/Makefile
           src/arch/android/AnVICE/jni/locnet_x64/Makefile
           src/arch/android/AnVICE/jni/locnet_x64dtv/Makefile
           src/arch/android/AnVICE/jni/locnet_x64sc/Makefile
           src/arch/android/AnVICE/jni/locnet_x128/Makefile
           src/arch/android/AnVICE/jni/locnet_xcbm2/Makefile
           src/arch/android/AnVICE/jni/locnet_xcbm5x0/Makefile
           src/arch/android/AnVICE/jni/locnet_xpet/Makefile
           src/arch/android/AnVICE/jni/locnet_xplus4/Makefile
           src/arch/android/AnVICE/jni/locnet_xscpu64/Makefile
           src/arch/android/AnVICE/jni/locnet_xvic/Makefile
           src/arch/android/AnVICE/jni/locnet_al/Makefile
           src/arch/android/AnVICE/jni/sdl/Makefile
           src/arch/android/AnVICE/jni/vice_x64/Makefile
           src/arch/android/AnVICE/jni/vice_x64_128_5x0/Makefile
           src/arch/android/AnVICE/jni/vice_x64_dtv_128_5x0/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_128/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_128_2_5x0_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_128_2_5x0_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_2_5x0_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_2_5x0_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_2_5x0_pet_4/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_2_5x0_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_2_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_dtv_scpu_128_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_2/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_2_5x0_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_2_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_2_pet_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_4/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64_sc_scpu_128_5x0_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x64dtv/Makefile
           src/arch/android/AnVICE/jni/vice_x64sc/Makefile
           src/arch/android/AnVICE/jni/vice_x64sc_scpu/Makefile
           src/arch/android/AnVICE/jni/vice_x64sc_scpu_128_2_pet_4_20/Makefile
           src/arch/android/AnVICE/jni/vice_x128/Makefile
           src/arch/android/AnVICE/jni/vice_x128_2_5x0_pet/Makefile
           src/arch/android/AnVICE/jni/vice_xcbm2/Makefile
           src/arch/android/AnVICE/jni/vice_xcbm2_5x0/Makefile
           src/arch/android/AnVICE/jni/vice_xcbm2_pet/Makefile
           src/arch/android/AnVICE/jni/vice_xcbm5x0/Makefile
           src/arch/android/AnVICE/jni/vice_xpet/Makefile
           src/arch/android/AnVICE/jni/vice_xplus4/Makefile
           src/arch/android/AnVICE/jni/vice_xscpu64/Makefile
           src/arch/android/AnVICE/jni/vice_xvic/Makefile
           src/arch/android/AnVICE/res-proto/Makefile
           src/arch/android/AnVICE/res-proto/layout/Makefile
           src/arch/android/AnVICE/res-proto/values/Makefile
           src/arch/android/AnVICE/src-proto/Makefile
           src/arch/android/AnVICE/src-proto/com/Makefile
           src/arch/android/AnVICE/src-proto/com/locnet/Makefile
           src/arch/android/AnVICE/src-proto/com/locnet/vice/Makefile
           src/arch/beos/Makefile
           src/arch/msdos/Makefile
           src/arch/os2/Makefile
           src/arch/os2/dialogs/Makefile
           src/arch/os2/doc/Makefile
           src/arch/os2/fonts/Makefile
           src/arch/os2/icons/Makefile
           src/arch/os2/kbd/Makefile
           src/arch/os2/snippets/Makefile
           src/arch/os2/unused/Makefile
           src/arch/os2/unused/pm/Makefile
           src/arch/os2/watcom/Makefile
           src/arch/sdl/Makefile
           src/arch/sdl/msvc-files/Makefile
           src/arch/sdl/qnx4/Makefile
           src/arch/sdl/syllable-files/Makefile
           src/arch/sdl/win32-watcom/Makefile
           src/arch/unix/Makefile
           src/arch/unix/gui/Makefile
           src/arch/unix/minix/Makefile
           src/arch/unix/next_open_rhap/Makefile
           src/arch/unix/next_open_rhap/vice.info
           src/arch/unix/qnx4/Makefile
           src/arch/unix/qnx6/Makefile
           src/arch/unix/readline/Makefile
           src/arch/unix/sco_sol/Makefile
           src/arch/unix/skyos/Makefile
           src/arch/unix/skyos/icons/Makefile
           src/arch/unix/x11/Makefile
           src/arch/unix/x11/gnome/Makefile
           src/arch/unix/x11/xaw/Makefile
           src/arch/unix/x11/xaw/widgets/Makefile
           src/arch/unix/macosx/Makefile
           src/arch/unix/macosx/cocoa/Makefile
           src/arch/unix/macosx/cocoa/view/Makefile
           src/arch/unix/macosx/cocoa/menu/Makefile
           src/arch/unix/macosx/cocoa/dialog/Makefile
           src/arch/unix/macosx/Resources/Makefile
           src/arch/unix/macosx/Resources/English.lproj/Makefile
           src/arch/watcom-source-wrappers/Makefile
           src/arch/win32/Makefile
           src/arch/win32/vice-version.bat
           src/arch/win32/evc/Makefile
           src/arch/win32/mingw32/Makefile
           src/arch/win32/msvc/Makefile
           src/arch/win32/msvc/wpcap/Makefile
           src/arch/win32/msvc/wpcap/net/Makefile
           src/arch/win32/utils/Makefile
           src/arch/win32/vs_tmpl/Makefile
           src/arch/win32/watcom/Makefile
           src/c128/Makefile
           src/c64/Makefile
           src/c64/cart/Makefile
           src/c64dtv/Makefile
           src/scpu64/Makefile
           src/cbm2/Makefile
           src/core/Makefile
           src/crtc/Makefile
           src/diag/Makefile
           src/diskimage/Makefile
           src/drive/Makefile
           src/drive/iec/Makefile
           src/drive/iec/c64exp/Makefile
           src/drive/iec/plus4exp/Makefile
           src/drive/iec128dcr/Makefile
           src/drive/iecieee/Makefile
           src/drive/ieee/Makefile
           src/drive/tcbm/Makefile
           src/fileio/Makefile
           src/fsdevice/Makefile
           src/gfxoutputdrv/Makefile
           src/iecbus/Makefile
           src/imagecontents/Makefile
           src/joyport/Makefile
           src/lib/Makefile
           src/lib/ffmpeg/Makefile
           src/lib/p64/Makefile
           src/monitor/Makefile
           src/parallel/Makefile
           src/pet/Makefile
           src/platform/Makefile
           src/plus4/Makefile
           src/printerdrv/Makefile
           src/raster/Makefile
           src/rs232drv/Makefile
           src/rtc/Makefile
           src/samplerdrv/Makefile
           src/serial/Makefile
           src/sid/Makefile
           src/sounddrv/Makefile
           src/tape/Makefile
           src/tapeport/Makefile
           src/userport/Makefile
           src/vdc/Makefile
           src/vdrive/Makefile
           src/vic20/Makefile
           src/vic20/cart/Makefile
           src/vicii/Makefile
           src/viciisc/Makefile
           src/viciivsid/Makefile
           src/video/Makefile
           src/version.h
           src/vice-version.sh
           po/Makefile.in
           ])

dnl Local Variables:
dnl mode: autoconf
dnl compile-command: "autoconf"
dnl End:

dnl construct show_arch
if test x"$is_dos" != "xyes" -a x"$is_amiga" != "xyes" -a x"$is_beos" != "xyes" -a x"$is_os2" != "xyes" -a x"$is_unix_macosx" != "xyes" -a x"$is_win32" != "xyes"; then
    show_arch="Unix"
    real_arch="Unix"
else
    if test x"$is_amiga" = "xyes"; then
        show_arch="Amiga"
        real_arch="Amiga"
    fi
    if test x"$is_beos" = "xyes"; then
        if test x"$is_beos_x11" = "xyes"; then
            show_arch="BeOS-X11 (treated as Unix)"
            real_arch="Unix"
        else
            show_arch="BeOS"
            real_arch="BeOS"
        fi
    fi
    if test x"$is_dos" = "xyes"; then
        show_arch="DOS"
        real_arch="DOS"
    fi
    if test x"$is_os2" = "xyes"; then
        show_arch="OS/2"
        real_arch="OS/2"
    fi
    if test x"$is_unix_macosx" = "xyes"; then
        show_arch="Mac OS X"
        real_arch="OSX"
    fi
    if test x"$is_win32" = "xyes"; then
        if test x"$is_win32_x11" = "xyes"; then
            show_arch="Win32-X11 (treated as Unix)"
            real_arch="Unix"
        else
            show_arch="Win32"
            real_arch="Win32"
        fi
    fi
fi

dnl construct show_gui
show_gui="XAW"
if test x"$enable_gnomeui" = "xyes"; then
    show_gui="GTK2"
fi
if test x"$enable_gnomeui3" = "xyes"; then
    show_gui="GTK3"
fi
if test x"$with_cocoa" = "xyes"; then
    show_gui="COCOA"
fi
if test x"$show_arch" = "xAmiga"; then
    if test "x$ac_cv_header_proto_cybergraphics_h" = xyes; then
        show_gui="CyberGFX (MUI)"
    else
        show_gui="P96 (MUI)"
    fi
fi
if test x"$is_beos" = "xyes"; then
    if test x"$is_beos_x11" != "xyes"; then
        show_gui="BeOS"
    fi
fi
if test x"$is_dos" = "xyes"; then
    show_gui="Allegro"
fi
if test x"$is_os2" = "xyes"; then
    show_gui="DIVE (PM)"
fi
if test x"$is_win32" = "xyes"; then
    if test x"$is_win32_x11" != "xyes"; then
        show_gui="Win32"
    fi
fi
if test "x$ac_cv_lib_Xaw3d_XawFormDoLayout" = xyes; then
    show_gui="XAW3D"
fi

if test x"$enable_sdlui" = "xyes" -o x"$show_arch" = "xDingux"; then
    show_gui="SDL"
fi

if test x"$enable_sdlui2" = "xyes"; then
    show_gui="SDL2"
fi

if test "x$ac_cv_header_sys_audio_h" = xyes; then
    HAVE_SYS_AUDIO_H_SUPPORT="yes"
fi

if test "x$ac_cv_header_sys_audioio_h" = xyes; then
    HAVE_SYS_AUDIOIO_H_SUPPORT="yes"
fi

if test "x$ac_cv_header_devices_ahi_h" = xyes; then
    HAVE_DEVICES_AHI_H_SUPPORT="yes"
fi

if test "x$ac_cv_func_SDL_NumJoysticks" = xyes; then
    HAVE_SDL_NUMJOYSTICKS_SUPPORT="yes"
fi

if test "x$ac_cv_header_proto_openpci_h" = xyes; then
    HAVE_PROTO_OPENPCI_H_SUPPORT="yes"
fi

echo "----------------------------------------------------------------------"
echo ""
echo "configure summary:"
echo ""

echo "Platform canonical: $ac_cv_host"
echo "Architecture      : $show_arch"
echo "GUI               : $show_gui"
echo ""

echo "SCREEN/UI"
echo "---------"

if test x"$real_arch" != "xAmiga" -a x"$real_arch" != "xDOS" -a x"$real_arch" != "xWin32"; then
    echo "Fullscreen support             : $HAVE_FULLSCREEN_SUPPORT (--enable/disable-fullscreen)"
fi

if test x"$real_arch" != "xDOS" -a x"$real_arch" != "xWin32" -a x"$real_arch" != "xBeOS"; then
    echo "Hardware scaling support       : $HAVE_HWSCALE_SUPPORT"
fi

if test x"$real_arch" = "xUnix" -o x"$show_gui" = "xSDL" -o x"$show_gui" = "xSDL2"; then
    echo "OpenGL sync support            : $HAVE_OPENGL_SYNC_SUPPORT"
fi

if test x"$real_arch" = "xWin32" -a x"$show_gui" = "xWin32"; then
    echo "Direct3D support               : $HAVE_D3D9_H_SUPPORT"
fi

if test x"$real_arch" = "xWin32"; then
    echo "Unicode support                : $ENABLE_UNICODE_API_SUPPORT (--enable/disable-unicode)"
fi

if test x"$real_arch" = "xUnix"; then
    echo "Cairo rendering support        : $HAVE_CAIRO_SUPPORT"
    echo "Pango support                  : $HAVE_PANGO_SUPPORT"
    echo "XF86 extensions support        : $USE_XF86_EXTENSIONS_SUPPORT"
    echo "MITSHM extensions support      : $USE_MITSHM_SUPPORT"
    echo "XF86 VidMode extensions support: $USE_XF86_VIDMODE_EXT_SUPPORT"
    echo "XVideo support                 : $HAVE_XVIDEO_SUPPORT"
    echo "XRandR support                 : $HAVE_XRANDR_SUPPORT"
    echo "Multithreaded UI support       : $USE_UI_THREADS_SUPPORT (--with/without-uithreads)"
    echo "LibXpm support                 : $HAVE_LIBXPM_SUPPORT"
    echo "VTE support                    : $HAVE_VTE_SUPPORT (--enable/disable-vte)"
fi

echo ""
echo "SOUND"
echo "-----"

if test x"$real_arch" != "xAmiga"; then
    echo "PortAudio sound input support: $USE_PORTAUDIO_SUPPORT"
fi

if test x"$real_arch" = "xUnix"; then
    echo "OSS sound support            : $USE_OSS_SUPPORT (--with/without-oss)"
    echo "ALSA sound support           : $USE_ALSA_SUPPORT (--with/without-alsa)"
    echo "ARTS sound support           : $USE_ARTS_SUPPORT (--with/without-arts)"
    echo "Pulseaudio sound support     : $USE_PULSE_SUPPORT (--with/without-pulse)"
fi

if test x"$real_arch" = "xOSX"; then
    echo "CoreAudio sound support      : $USE_COREAUDIO_SUPPORT"
    echo "AudioUnit sound support      : $HAVE_AUDIO_UNIT_SUPPORT"
fi

if test x"$real_arch" = "xDOS"; then
    echo "Allegro sound support        : $USE_ALLEGRO_SOUND_SUPPORT (--without-midas)"
    echo "Midas sound support          : $USE_MIDAS_SOUND_SUPPORT (--with-midas)"
fi

if test x"$real_arch" = "xAmiga"; then
    echo "AHI sound support            : $HAVE_DEVICES_AHI_H_SUPPORT"
fi

if test x"$real_arch" = "xWin32"; then
    echo "DirectX sound support        : $USE_DXSOUND_SUPPORT"
fi

if test x"$real_arch" != "xDOS"; then
    echo "SDL sound support            : $USE_SDL_AUDIO_SUPPORT (--with/without-sdlsound)"
fi

if test x"$real_arch" = "xUnix"; then
    echo "NetBSD/Solaris sound support : $HAVE_SYS_AUDIOIO_H_SUPPORT"
    echo "AIX sound support            : $USE_AIX_AUDIO_SUPPORT"
    echo "HPUX sound support           : $HAVE_SYS_AUDIO_H_SUPPORT"
    echo "SGI sound support            : $USE_DMEDIA_SUPPORT"
fi

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xOSX" -o x"$real_arch" = "xWin32"; then
    echo "MIDI support                 : $HAVE_MIDI_SUPPORT (--enable/disable-midi)"
fi

if test x"$real_arch" != "xOSX" -a x"$real_arch" != "xBeOS"; then
    echo "Catweasel MK3 support        : $HAVE_CATWEASELMKIII_SUPPORT"
    echo "HardSID support              : $HAVE_HARDSID_SUPPORT"
fi

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xDOS" -o x"$real_arch" = "xWin32"; then
    echo "ParSID support               : $HAVE_PARSID_SUPPORT (--enable/disable-parsid)"
    echo "SSI2001 support              : $HAVE_SSI2001_SUPPORT (--enable/disable-ssi2001)"
    echo "direct I/O access support    : $HAVE_IOSID_SUPPORT"
    echo "lpt port access              : $HAVE_PORTSID_SUPPORT"
fi

echo "PCI utils support            : $HAVE_PCIUTILS_SUPPORT"

echo "MP3 encoding support         : $USE_LAMEMP3_SUPPORT (--enable/disable-lame)"
echo "MP3 decoding support         : $USE_MPG123_SUPPORT"
echo "FLAC en/de-coding support    : $USE_FLAC_SUPPORT"
echo "OGG en/de-coding support     : $USE_VORBIS_SUPPORT"

echo ""
echo "SCREENSHOTS"
echo "-----------"

echo "GIF encoding support : $HAVE_GIF_SUPPORT"
echo "JPEG encoding support: $HAVE_JPEG_SUPPORT (--with/without-jpeg)"
echo "PNG encoding support : $HAVE_PNG_SUPPORT (--with/without-png)"

echo ""
echo "VIDEO RECORDING"
echo "---------------"

echo "FFMPEG support                : $HAVE_FFMPEG_SUPPORT (--enable-shared-ffmpeg/--enable-static-ffmpeg/--enable-external-ffmpeg)"
echo "FFMPEG swscale support        : $HAVE_FFMPEG_SWSCALE_SUPPORT"
echo "FFMPEG swresample support     : $HAVE_FFMPEG_SWRESAMPLE_SUPPORT"
echo "FFMPEG avresample support     : $HAVE_FFMPEG_AVRESAMPLE_SUPPORT"
echo "included shared FFMPEG support: $SHARED_FFMPEG_SUPPORT (--enable-shared-ffmpeg)"
echo "included static FFMPEG support: $STATIC_FFMPEG_SUPPORT (--enable-static-ffmpeg)"

if test x"$real_arch" = "xOSX" -o x"$real_arch" = "xWin32"; then
    echo "QuickTime support             : $HAVE_QUICKTIME_SUPPORT (--enable/disable-quicktime)"
fi

echo ""
echo "INPUT"
echo "-----"

echo "Joystick support            : $HAS_JOYSTICK_SUPPORT"
echo "Mouse support               : $HAVE_MOUSE_SUPPORT"

if test x"$real_arch" = "xAmiga" -o x"$real_arch" = "xBeOS"; then
    if test x"$show_gui" = "xSDL" -o x"$show_gui" = "xSDL2"; then
        echo "Lightpen support            : $HAVE_LIGHTPEN_SUPPORT"
    fi
else
    echo "Lightpen support            : $HAVE_LIGHTPEN_SUPPORT"
fi

if test x"$real_arch" = "xUnix"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "Linux style joystick support: $LINUX_JOYSTICK_SUPPORT"
        echo "BSD style joystick support  : $BSD_JOYSTICK_SUPPORT"
        echo "Digital joystick support    : $HAS_DIGITAL_JOYSTICK_SUPPORT"
        echo "USB joystick support        : $HAS_USB_JOYSTICK_SUPPORT"
    fi
fi

if test x"$real_arch" = "xOSX"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "Mac joystick support         : $MAC_JOYSTICK_SUPPORT"
        echo "IOHIDManager joystick support: $HAS_HIDMGR_SUPPORT (--enable/disable-hidmgr)"
    fi
fi

if test x"$real_arch" = "xWin32"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "DirectInput joystick support: $HAVE_DINPUT_SUPPORT"
    fi
fi

if test x"$show_gui" = "xSDL" -o x"$show_gui" = "xSDL2"; then
    echo "SDL joystick support        : $HAVE_SDL_NUMJOYSTICKS_SUPPORT"
fi

echo ""
echo "MODEM/NETWORK"
echo "-------------"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xWin32"; then
    echo "RS232 device support             : $HAVE_RS232DEV_SUPPORT (--enable/disable-rs232)"
fi

echo "Network support                  : $HAVE_NETWORK_SUPPORT"
echo "RS232 network support            : $HAVE_RS232NET_SUPPORT"
echo "IPv6 network support             : $HAVE_IPV6_SUPPORT (--enable/disable-ipv6)"
echo "Network capture/injection support: $HAVE_PCAP_SUPPORT (--enable/disable-ethernet)"

echo ""
echo "DRIVE"
echo "-----"

echo "Raw drive support: $HAVE_RAWDRIVE_SUPPORT"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xWin32"; then
    echo "OpenCBM support  : $HAVE_OPENCBM_SUPPORT (--enable/disable-realdevice)"
fi

echo ""
echo "LIBS"
echo "----"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xOSX" -o x"$real_arch" = "xWin32"; then
    echo "Dynamic linking support: $HAVE_DYNLIB_SUPPORT_TOO"
fi

echo "Zlib support           : $HAVE_ZLIB_SUPPORT (--with/without-zlib)"

if test x"$real_arch" = "xUnix"; then
    echo "Libieee1284 support    : $HAVE_LIBIEEE1284_SUPPORT"
fi

if test x"$real_arch" = "xUnix"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "NLS support            : $ENABLE_NLS_SUPPORT (--enable/disable-nls)"
    fi
fi

if test x"$real_arch" = "xAmiga"; then
    echo "OpenPCI support        : $HAVE_PROTO_OPENPCI_H_SUPPORT"
fi

echo ""
echo "MISC"
echo "----"

echo "ReSID support              : $HAVE_RESID_SUPPORT (--with/without-resid)"
echo "Memmap support             : $FEATURE_CPUMEMHISTORY_SUPPORT (--enable/disable-memmap)"
echo "Debug support              : $DEBUG_SUPPORT (--enable/disable-debug)"
echo "Embedded data files support: $USE_EMBEDDED_SUPPORT (--enable/disable-embedded)"

echo ""
echo "----------------------------------------------------------------------"
