]> git.sesse.net Git - vlc/blobdiff - configure.ac
Fix realaudio linking on Linux without the Win32 loader
[vlc] / configure.ac
index df3d5d6b8420e89720314ae7789c46558b5c5204..e5e1b018a437c4ae7a89a9dc094890fc7c122b6b 100644 (file)
@@ -8,6 +8,7 @@ VERSION_EXTRA="svn"
 
 CONFIGURE_LINE="`echo "$0 $ac_configure_args" | sed -e 's/\\\/\\\\\\\/g'`"
 CODENAME="Grishenko"
+COPYRIGHT_YEARS="1996-2008"
 
 AC_PREREQ(2.59) dnl this really should be 2.59c
 AC_CONFIG_SRCDIR(src/libvlc.c)
@@ -15,7 +16,7 @@ AC_CONFIG_AUX_DIR(autotools)
 AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 
-AM_INIT_AUTOMAKE([1.9 check-news dist-bzip2 no-dist-gzip -Wall])
+AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(config.h)
 
 dnl Too many people are not aware of maintainer mode:
@@ -75,10 +76,10 @@ AC_ARG_WITH(contrib,
    if test "`grep HOST ${topdir}/extras/contrib/config.mak 2>/dev/null|awk '{print $3}'`" != "`$CC -dumpmachine`"; then
       if test "${with_contrib}" = "yes"; then
         AC_MSG_RESULT([no])
-       AC_MSG_ERROR([ not using the libs in extras/contrib as it is not the same host])
+        AC_MSG_ERROR([ not using the libs in extras/contrib as it is not the same host])
       else
         AC_MSG_RESULT([no])
-       AC_MSG_WARN([ not using the libs in extras/contrib as it is not the same host])
+        AC_MSG_WARN([ not using the libs in extras/contrib as it is not the same host])
       fi
      else
   if test -d ${topdir}/extras/contrib/lib; then
@@ -93,22 +94,18 @@ AC_ARG_WITH(contrib,
     OBJCFLAGS="${OBJCFLAGS} -I${topdir}/extras/contrib/include"
     OBJCFLAGS_save="${OBJCFLAGS_save} -I${topdir}/extras/contrib/include"
     if test $build = $host -o "$PKG_CONFIG_LIBDIR"; then
-       export PKG_CONFIG_PATH=${topdir}/extras/contrib/lib/pkgconfig:$PKG_CONFIG_PATH
+        export PKG_CONFIG_PATH=${topdir}/extras/contrib/lib/pkgconfig:$PKG_CONFIG_PATH
     else
-       export PKG_CONFIG_LIBDIR=${topdir}/extras/contrib/lib/pkgconfig
+        export PKG_CONFIG_LIBDIR=${topdir}/extras/contrib/lib/pkgconfig
     fi
     LDFLAGS="${LDFLAGS} -L${topdir}/extras/contrib/lib"
     LDFLAGS_save="${LDFLAGS_save} -L${topdir}/extras/contrib/lib"
 
-dnl kludge because only the debian package provides a ffmpeg-config
-    if test -z $with_ffmpeg_config_path; then 
-       with_ffmpeg_config_path=${topdir}/extras/contrib/bin;
-    fi
     if test -z $with_live555_tree; then
        with_live555_tree=${topdir}/extras/contrib/src/live
     fi
     if test -z $with_goom_tree; then
-      with_goom_tree=${topdir}/extras/contrib/src/goom
+       with_goom_tree=${topdir}/extras/contrib/src/goom
     fi
     if test -z $with_mozilla_sdk_path; then
        with_mozilla_sdk_path=${topdir}/extras/contrib/gecko-sdk
@@ -117,7 +114,10 @@ dnl kludge because only the debian package provides a ffmpeg-config
        with_cyberlink_tree=${topdir}/extras/contrib/src/clinkcc
     fi
     if test -z $with_libmpeg2_tree; then
-       with_libmpeg2_tree=${topdir}/extras/contrib/src/mpeg2dec
+       with_libmpeg2_tree=${topdir}/extras/contrib/src/mpeg2dec
+    fi
+    if test -z $with_a52_tree; then
+       with_a52_tree=${topdir}/extras/contrib/src/a52dec
     fi
 
     if test ".`uname -s`" = ".Darwin"; then
@@ -150,7 +150,7 @@ case "${host_os}" in
   bsdi*)
     SYS=bsdi
     CFLAGS_save="${CFLAGS_save} -pthread"; CFLAGS="${CFLAGS_save}"
-    VLC_ADD_LDFLAGS([dvd dvdcss vcd cdda vcdx cddax],[-ldvd])
+    VLC_ADD_LIBS([dvd dvdcss vcd cdda vcdx cddax],[-ldvd])
     ;;
   *bsd*)
     SYS="${host_os}"
@@ -169,18 +169,28 @@ case "${host_os}" in
     CFLAGS_save="${CFLAGS_save} -D_INTL_REDIRECT_MACROS"; CFLAGS="${CFLAGS_save}"
     CXXFLAGS_save="${CXXFLAGS_save} -D_INTL_REDIRECT_MACROS"; CXXFLAGS="${CXXFLAGS_save}"
     OBJCFLAGS_save="${OBJCFLAGS_save} -D_INTL_REDIRECT_MACROS -std=gnu99"; OBJCFLAGS="${OBJCFLAGS_save}"
-    VLC_ADD_LDFLAGS([mp4], [-framework IOKit -framework CoreFoundation])
-    VLC_ADD_LDFLAGS([mkv mp4], [-framework IOKit -framework CoreFoundation])
-    VLC_ADD_CFLAGS([libvlc vlc],[-x objective-c])
-    VLC_ADD_LDFLAGS([vlc],[-undefined dynamic_lookup])
+    LDFLAGS_save="${LDFLAGS_save} -Wl,-headerpad_max_install_names"; LDFLAGS="${LDFLAGS_save}"
+    VLC_ADD_LDFLAGS([mp4], [-Wl,-framework,IOKit,-framework,CoreFoundation])
+    VLC_ADD_LDFLAGS([mkv mp4], [-Wl,-framework,IOKit,-framework,CoreFoundation])
+    VLC_ADD_LDFLAGS([vlc],[-Wl,-undefined,dynamic_lookup])
+    VLC_ADD_LDFLAGS([libvlc_control],[-Wl,dynamic_lookup])
+    VLC_ADD_LDFLAGS([ffmpeg i420_rgb_mmx],[-Wl,-read_only_relocs,suppress])
     VLC_ADD_CFLAGS([motion],[-fconstant-cfstrings])
-    VLC_ADD_LDFLAGS([motion],[-framework IOKit -framework CoreFoundation])
+    VLC_ADD_LDFLAGS([libvlc],[-Wl,-framework,Cocoa,-framework,CoreFoundation])
+    VLC_ADD_LDFLAGS([motion],[-Wl,-framework,IOKit,-framework,CoreFoundation])
     AC_ARG_ENABLE(macosx-defaults,
         [  --enable-macosx-defaults Build the default configuration on Mac OS X (default enabled)])
     if test "x${enable_macosx_defaults}" != "xno"
     then
         echo ""
         echo "Building with Mac OS X defaults:"
+        with_macosx_version_min="10.4"
+        echo "  Assuming --with-macosx-version-min=10.4"
+        build_dir=`pwd`
+        echo "  Assuming --prefix=${build_dir}/vlc_install_dir"
+        ac_default_prefix="${build_dir}/vlc_install_dir"
+        enable_macosx="yes"
+        echo "  Assuming --enable-macosx"
         enable_faad="yes"
         echo "  Assuming --enable-faad"
         enable_flac="yes"
@@ -213,14 +223,56 @@ case "${host_os}" in
         enable_xvideo="no"
         echo "  Assuming --disable-xvideo"
 
-        enable_libtool="no"
-        echo "  Assuming --disable-libtool"
-        echo ""
+        with_macosx_sdk=""
+        echo "  Compiling with default SDK"
+    fi
+    if test ".`uname -p`" = ".i386"; then
+        dnl Due to a ld(64) bug in 10.5 we cannot use our mmx code
+        dnl without hacking it a lot, we disable mmx and sse.
+        dnl (that bug is about ld being unable to handle
+        dnl text relocation)
+        save_cflags="$CFLAGS"
+        CFLAGS="$CFLAGS -dynamiclib -single_module -read_only_relocs suppress"
+        AC_TRY_LINK(
+            [int a;], [asm("movq _a,%mm0\n");],
+            ac_ld_does_not_support_text_reloc=no,
+            ac_ld_does_not_support_text_reloc=yes)
+        CFLAGS="$save_cflags"
+
+        if test "x$ac_ld_does_not_support_text_reloc" = "xyes"; then
+            enable_mmx="no"
+            echo "  Assuming --disable-mmx (due to a bug in ld)"
+            enable_sse="no"
+            echo "  Assuming --disable-sse (due to a bug in ld)"
+        fi
+    fi
+    dnl
+    dnl  Check for Mac OS X SDK settings
+    dnl
+    AC_ARG_WITH(macosx-sdk,
+       [  --with-macosx-sdk=DIR   compile using the SDK in DIR])
+    if test "${with_macosx_sdk}" != "" ; then
+        CC="${CC} -isysroot ${with_macosx_sdk}" 
+        CXX="${CXX} -isysroot ${with_macosx_sdk}"
+        OBJC="${OBJC} -isysroot ${with_macosx_sdk}"
+        LD="${LD} -syslibroot ${with_macosx_sdk}"
+    fi
+    AC_ARG_WITH(macosx-version-min,
+       [  --with-macosx-version-min=VERSION  compile for MacOSX VERSION and above])
+    if test "${with_macosx_version_min}" != "" ; then
+        CC="${CC} -mmacosx-version-min=${with_macosx_version_min}" 
+        CXX="${CXX} -mmacosx-version-min=${with_macosx_version_min}"
+        OBJC="${OBJC} -mmacosx-version-min=${with_macosx_version_min}"
+        LD="${LD} -macosx_version_min=${with_macosx_version_min}"
+        CFLAGS_save="${CFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=${with_macosx_version_min}"; CFLAGS="${CFLAGS_save}"
+        CXXFLAGS_save="${CXXFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=${with_macosx_version_min}"; CXXFLAGS="${CXXFLAGS_save}"
+        OBJCFLAGS_save="${OBJCFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=${with_macosx_version_min}"; OBJCFLAGS="${OBJCFLAGS_save}"
+        MACOSX_DEPLOYMENT_TARGET=${with_macosx_version_min}
+        export MACOSX_DEPLOYMENT_TARGET
     fi
     ;;
   *mingw32* | *cygwin* | *wince* | *mingwce* | *pe*)
     AC_CHECK_TOOL(WINDRES, windres, :)
-    enable_libtool="no"
 
     case "${host_os}" in
       *mingw32*)
@@ -242,23 +294,22 @@ case "${host_os}" in
 
     if test "${SYS}" = "mingw32"; then
         # add ws2_32 for closesocket, select, recv
-        CPPFLAGS_save="${CPPFLAGS_save} -D_OFF_T_ -D_off_t=long"; CPPFLAGS="${CPPFLAGS_save}"
-        VLC_ADD_LDFLAGS([libvlc],[-lws2_32 -lnetapi32 -lwinmm])
-        VLC_ADD_LDFLAGS([vlc activex mozilla],[-mwindows])
-        VLC_ADD_LDFLAGS([cdda vcdx cddax],[-lwinmm])
-        VLC_ADD_LDFLAGS([access_http access_mms access_udp access_tcp access_ftp access_output_udp sap slp http stream_out_standard stream_out_rtp vod_rtsp access_realrtsp telnet rc netsync growl flac ts audioscrobbler],[-lws2_32])
+        VLC_ADD_LIBS([libvlc],[-lws2_32 -lnetapi32 -lwinmm])
+        VLC_ADD_LDFLAGS([vlc],[-mwindows])
+        VLC_ADD_LIBS([activex mozilla],[-lgdi32])
+        VLC_ADD_LIBS([cdda vcdx cddax sdl_image],[-lwinmm])
+        VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp access_output_udp access_output_shout sap slp http stream_out_standard stream_out_rtp vod_rtsp access_realrtsp telnet rc netsync gnutls growl flac ts audioscrobbler lua],[-lws2_32])
     fi
     if test "${SYS}" = "mingwce"; then
         # add ws2 for closesocket, select, recv
-        CPPFLAGS_save="${CPPFLAGS_save} -D_OFF_T_ -D_off_t=long"; CPPFLAGS="${CPPFLAGS_save}"
         VLC_ADD_CPPFLAGS([libvlc vlc],[-Dmain(a,b)=maince(a,b)])
-        VLC_ADD_LDFLAGS([libvlc vlc],[-lws2 -e WinMainCRTStartup])
-        VLC_ADD_LDFLAGS([access_http access_mms access_udp access_tcp access_ftp access_output_udp sap http netsync],[-lws2])
+        VLC_ADD_LDFLAGS([libvlc vlc],[-e WinMainCRTStartup])
+        VLC_ADD_LIBS([libvlc access_http access_mms access_udp access_tcp access_ftp access_output_udp sap http netsync],[-lws2])
    fi
     ;;
   *nto*)
     SYS=nto
-    VLC_ADD_LDFLAGS([x11 xvideo],[-lsocket])
+    VLC_ADD_LIBS([x11 xvideo],[-lsocket])
     ;;
   solaris*)
     SYS=solaris
@@ -274,21 +325,21 @@ case "${host_os}" in
     CFLAGS_save="${CFLAGS_save} -Wno-multichar"; CFLAGS="${CFLAGS_save}"
     CXXFLAGS_save="${CXXFLAGS_save} -Wno-multichar"; CXXFLAGS="${CXXFLAGS_save}"
     VLC_ADD_CXXFLAGS([beos],[])
-    VLC_ADD_LDFLAGS([vlc libvlc logger],[-lbe])
-    VLC_ADD_LDFLAGS([beos],[-lbe -lmedia -ltranslation -ltracker -lgame])
-    VLC_ADD_LDFLAGS([dvdnav dvdread],[-ldl])
-    VLC_ADD_LDFLAGS([access_file],[-lpoll])
+    VLC_ADD_LIBS([vlc libvlc logger],[-lbe])
+    VLC_ADD_LIBS([beos],[-lbe -lmedia -ltranslation -ltracker -lgame])
+    VLC_ADD_LIBS([dvdnav dvdread],[-ldl])
+    VLC_ADD_LIBS([access_file],[-lpoll])
     LDFLAGS_save="${LDFLAGS_save} -lintl"; LDFLAGS="${LDFLAGS_save}"
     dnl Check for BONE
     if test -f /boot/beos/system/lib/libbind.so; then
-        VLC_ADD_LDFLAGS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lbind -lsocket])
+        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lbind -lsocket])
     else
-        VLC_ADD_LDFLAGS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lnet])
+        VLC_ADD_LIBS([access_file access_ftp access_mms access_output_udp telnet netsync sap libvlc growl],[-lnet])
     fi
 
     dnl Ugly check for Zeta
     if test -f /boot/beos/system/lib/libzeta.so; then
-        VLC_ADD_LDFLAGS([beos],[-lzeta])
+        VLC_ADD_LIBS([beos],[-lzeta])
     fi
     ;;
   *)
@@ -307,9 +358,9 @@ dnl for program foo on win32
 case "${build_os}" in
     cygwin|msys)
         ac_executable_extensions=".exe"
-       ;;
+    ;;
     *)
-       ;;
+    ;;
 esac
 
 dnl 
@@ -317,81 +368,53 @@ dnl  Libtool
 dnl  It's very bad, but our former custom system was worst
 dnl  -- Courmisch
 dnl
+
+dnl override platform specific check for dependent libraries
+dnl otherwise libtool linking of shared libraries will
+dnl fail on anything other than pass_all.
+AC_CACHE_VAL(lt_cv_deplibs_check_method,
+    [lt_cv_deplibs_check_method=pass_all])
+
 AC_DISABLE_STATIC
+AC_DISABLE_FAST_INSTALL
 AC_LIBTOOL_DLOPEN
-dnl AC_LIBTOOL_WIN32_DLL - couldn't get libtool to work on Win32 so far
+AC_LIBTOOL_WIN32_DLL
 m4_undefine([AC_PROG_F77])
 m4_defun([AC_PROG_F77],[])
 AC_PROG_LIBTOOL
 
-AC_ARG_ENABLE(libtool,
-    [  --enable-libtool        use libtool (default enabled)])
-AS_IF([test "x{enable_libtool}" = "xno"], [
-       AC_MSG_WARN([Disabling libtool is strongly discouraged. There are known bugs.])
-])
-AM_CONDITIONAL(USE_LIBTOOL, [test "x${enable_libtool}" != "xno"] )
+m4_undefine([AC_DEPLIBS_CHECK_METHOD])
+m4_defun([AC_DEPLIBS_CHECK_METHOD],[])
 
+lt_cv_deplibs_check_method=pass_all
 
-dnl
-dnl  Check for Mac OS X SDK settings
-dnl
-AC_ARG_WITH(macosx-sdk,
-   [  --with-macosx-sdk       compile with the Mac OS X 10.4u SDK],[], with_macosx_sdk=no)
-if test "${with_macosx_sdk}" != "no" ; then
-    CC="${CC} -isysroot /Developer/SDKs/MacOSX10.4u.sdk" 
-    CXX="${CXX} -isysroot /Developer/SDKs/MacOSX10.4u.sdk" 
-    OBJC="${OBJC} -isysroot /Developer/SDKs/MacOSX10.4u.sdk" 
-    LD="${LD} -syslibroot /Developer/SDKs/MacOSX10.4u.sdk"
-    CFLAGS_save="${CFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=10.4 -mmacosx-version-min=10.4"; CFLAGS="${CFLAGS_save}"
-    CXXFLAGS_save="${CXXFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=10.4 -mmacosx-version-min=10.4"; CXXFLAGS="${CXXFLAGS_save}"
-    OBJCFLAGS_save="${OBJCFLAGS_save} -DMACOSX_DEPLOYMENT_TARGET=10.4 -mmacosx-version-min=10.4"; OBJCFLAGS="${OBJCFLAGS_save}"
-    MACOSX_DEPLOYMENT_TARGET="10.4"
-    export MACOSX_DEPLOYMENT_TARGET
-fi
 
 dnl
 dnl Gettext stuff
 dnl
-ALL_LINGUAS="af ar bn ca co cs da de el en_GB es eu fa fr fur gl he hi hu it ja ka ko lt lv ms my ne nl no oc pa pl ps pt_BR pt_PT ro ru sk sl sq sv tet th tl tr zh_CN zh_TW"
-AM_GNU_GETTEXT_VERSION(0.11.5)
+AM_GNU_GETTEXT_VERSION(0.16.1)
 AM_GNU_GETTEXT
 AS_IF([test "${nls_cv_force_use_gnu_gettext}" = "yes"], [
   AC_DEFINE(HAVE_INCLUDED_GETTEXT, 1, [Define if we use the local libintl])
   AM_CPPFLAGS="${AM_CPPFLAGS} -I\$(top_builddir)/intl"
-  AS_IF([test "${enable_libtool}" != "no"], [
-    INCLUDED_LIBINTL="${LTLIBINTL}"
-  ],[
-    INCLUDED_LIBINTL="${LIBINTL}"
-  ])
 ], [
-  AS_IF([test "${enable_libtool}" != "no"], [
-    VLC_ADD_LDFLAGS([libvlc vlc], [${LTLIBINTL}])
-  ], [
-    VLC_ADD_LDFLAGS([libvlc vlc], [${LIBINTL}])
-  ])
+  VLC_ADD_LIBS([libvlc vlc], [${LTLIBINTL}])
 ])
-AC_SUBST(INCLUDED_LIBINTL)
 
 dnl
 dnl Iconv stuff
 dnl
-if test "${SYS}" != "mingwce"; then
 AS_IF([test "$am_cv_func_iconv" != "yes"],
        [AC_MSG_ERROR([libiconv is needed for VLC to work properly])])
-fi
 VLC_ADD_CFLAGS([libvlc],[${INCICONV}])
-AS_IF([test "${enable_libtool}" != "no"], [
-  VLC_ADD_LDFLAGS([libvlc vlc],[${LIBICONV}])
-],[
-  VLC_ADD_LDFLAGS([libvlc vlc],[${LTLIBICONV}])
-])
+VLC_ADD_LIBS([libvlc],[${LTLIBICONV}])
 
 dnl Check for the need to include the mingwex lib for mingw32
 if test "${SYS}" = "mingw32"
 then
     AC_CHECK_LIB(mingwex,opendir,
-        AC_CHECK_LIB(mingw32,opendir,VLC_ADD_LDFLAGS([libvlc],[]),
-            [VLC_ADD_LDFLAGS([libvlc gtk],[-lmingwex])])
+        AC_CHECK_LIB(mingw32,opendir,,
+            [VLC_ADD_LIBS([libvlc gtk],[-lmingwex])])
     )
 fi
 
@@ -443,38 +466,24 @@ VLC_LIBRARY_SUFFIX
 VLC_SYMBOL_PREFIX
 AC_SUBST(SYMPREF)
 
-AS_IF([test "${enable_libtool}" = "no"], [
-case "${SYS}" in
-  mingw32|cygwin)
-    VLC_ADD_CFLAGS([pic plugin mozilla activex],[${CFLAGS_mingw32_special}])
-    VLC_ADD_CXXFLAGS([pic plugin mozilla activex],[${CFLAGS_mingw32_special} ${CXXFLAGS_mingw32_special}])
-    VLC_ADD_OBJCFLAGS([pic plugin mozilla activex],[${CFLAGS_mingw32_special}])
-    ;;
-  mingwce)
-    ;;
-  *)
-    VLC_ADD_CFLAGS([pic plugin mozilla],[-fpic -fPIC])
-    VLC_ADD_CXXFLAGS([pic plugin mozilla],[-fpic -fPIC])
-    VLC_ADD_OBJCFLAGS([pic plugin mozilla],[-fpic -fPIC])
-    VLC_ADD_LDFLAGS([plugin mozilla],[-fpic -fPIC])
-    ;;
-esac
-])
-
 dnl The -DSYS_FOO flag
 CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcdefghijklmnopqrstuvwxyz.' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'`"; CPPFLAGS="${CPPFLAGS_save}"
 
 dnl Check for system libs needed
 need_libc=false
 
-AC_CHECK_FUNCS(gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy)
-
 dnl Check for usual libc functions
-AC_CHECK_FUNCS(strdup strndup strnlen atof)
+AC_CHECK_FUNCS([gettimeofday strtod strtol strtof strtoll strtoull strsep isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon scandir fork bsearch lstat strlcpy strdup strndup strnlen atof lldiv])
 AC_CHECK_FUNCS(strcasecmp,,[AC_CHECK_FUNCS(stricmp)])
 AC_CHECK_FUNCS(strncasecmp,,[AC_CHECK_FUNCS(strnicmp)])
 AC_CHECK_FUNCS(strcasestr,,[AC_CHECK_FUNCS(stristr)])
 
+AH_BOTTOM([#include <vlc_fixups.h>])
+
+AS_IF([test "${SYS}" = "linux"], [
+  AC_CHECK_FUNCS(tee)
+])
+
 dnl Check for setlocal and langinfo
 AC_CHECK_FUNCS(setlocale)
 AC_CHECK_HEADERS(langinfo.h)
@@ -493,38 +502,47 @@ fi
 
 AC_CHECK_FUNCS(connect,,[
   AC_CHECK_LIB(socket,connect,[
-    VLC_ADD_LDFLAGS([libvlc cdda cddax],-lsocket)
+    VLC_ADD_LIBS([libvlc cdda cddax],-lsocket)
     LIBS_socket="-lsocket"
   ])
 ])
 
 AC_CHECK_FUNCS(send,,[
   AC_CHECK_LIB(socket,send,[
-    VLC_ADD_LDFLAGS([access_http access_mms access_udp access_tcp access_ftp sap access_output_udp stream_out_standard growl],[-lsocket])
+    VLC_ADD_LIBS([access_http access_mms access_udp access_tcp access_ftp sap access_output_udp stream_out_standard growl],[-lsocket])
   ])
 ])
 
 AC_CHECK_FUNCS(gethostbyname,,[
   AC_CHECK_LIB(nsl,gethostbyname,[
-    VLC_ADD_LDFLAGS([cdda cddax libvlc],[-lnsl])
+    VLC_ADD_LIBS([cdda cddax libvlc],[-lnsl])
   ],[
     AC_CHECK_LIB(bind,gethostbyname,[
-      VLC_ADD_LDFLAGS([access_mms],[-lbind])
+      VLC_ADD_LIBS([access_mms],[-lbind])
     ])
   ])
 ])
 
+AC_CHECK_HEADERS(zlib.h, [
+  VLC_ADD_LIBS([access_http],[-lz])
+])
+
 dnl Check for socklen_t
-AC_CACHE_CHECK([for socklen_t], ac_cv_type_socklen_t,
-  [AC_TRY_COMPILE(
-     [#include <sys/types.h>
-      #include <sys/socket.h>],
-     [socklen_t len = 42; return len;],
-     ac_cv_type_socklen_t=yes,
-     ac_cv_type_socklen_t=no)])
-if test "${ac_cv_type_socklen_t}" != "no"; then
-  AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define if <sys/socket.h> defines socklen_t.])
-fi
+AH_TEMPLATE(socklen_t, [Define to `int' if <sys/socket.h> does not define.])
+AC_CACHE_CHECK([for socklen_t in sys/socket.h],
+ac_cv_type_socklen_t,
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+[#include <sys/types.h>
+#ifdef WIN32
+# include <winsock2.h>
+# include <ws2tcpip.h>
+#else
+# include <sys/socket.h>
+#endif]], [[socklen_t len; len = 0;]])],
+ac_cv_type_socklen_t=yes,
+ac_cv_type_socklen_t=no)])
+AS_IF([test "$ac_cv_type_socklen_t" = no],
+ [AC_DEFINE(socklen_t, int)])
 
 dnl Check for struct sockaddr_storage
 AH_TEMPLATE(sockaddr_storage, [Define to `sockaddr' if <sys/socket.h> does not define.])
@@ -594,7 +612,7 @@ fi
 
 AC_CHECK_FUNCS(inet_aton,,[
   AC_CHECK_LIB(resolv,inet_aton,[
-    VLC_ADD_LDFLAGS([libvlc],[-lresolv])
+    VLC_ADD_LIBS([libvlc],[-lresolv])
   ])
 ])
 
@@ -607,7 +625,7 @@ AC_CHECK_FUNCS(getopt_long,[AC_DEFINE(HAVE_GETOPT_LONG,1,long getopt support)],
 [ # FreeBSD has a gnugetopt library for this:
   AC_CHECK_LIB([gnugetopt],[getopt_long],
     [AC_DEFINE(HAVE_GETOPT_LONG,1,getopt support)
-     VLC_ADD_LDFLAGS([libvlc],[-lgnugetopt])],
+     VLC_ADD_LIBS([libvlc],[-lgnugetopt])],
     [need_getopt=:])])
 fi
 AM_CONDITIONAL(BUILD_GETOPT, ${need_getopt})
@@ -615,22 +633,22 @@ AM_CONDITIONAL(BUILD_GETOPT, ${need_getopt})
 if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"; then
 AC_TYPE_SIGNAL
 AC_CHECK_LIB(m,cos,[
-  VLC_ADD_LDFLAGS([adjust wave ripple psychedelic gradient a52tofloat32 dtstofloat32 x264 goom visual panoramix rotate noise],[-lm])
+  VLC_ADD_LIBS([adjust wave ripple psychedelic gradient a52tofloat32 dtstofloat32 x264 goom visual panoramix rotate noise grain],[-lm])
 ])
 AC_CHECK_LIB(m,pow,[
-  VLC_ADD_LDFLAGS([ffmpeg ffmpegaltivec stream_out_transrate i420_rgb faad twolame equalizer param_eq libvlc vorbis freetype mod mpc dmo quicktime realaudio galaktos opengl],[-lm])
+  VLC_ADD_LIBS([ffmpeg ffmpegaltivec stream_out_transrate i420_rgb faad twolame equalizer spatializer param_eq libvlc vorbis freetype mod mpc dmo quicktime realaudio galaktos opengl],[-lm])
 ])
 AC_CHECK_LIB(m,sqrt,[
-  VLC_ADD_LDFLAGS([headphone_channel_mixer normvol speex mono colorthres extract],[-lm])
+  VLC_ADD_LIBS([headphone_channel_mixer normvol speex mono colorthres extract],[-lm])
 ])
 AC_CHECK_LIB(m,ceil,[
-  VLC_ADD_LDFLAGS([mosaic],[-lm])
+  VLC_ADD_LIBS([mosaic],[-lm])
 ])
 AC_CHECK_LIB(m,exp,[
-  VLC_ADD_LDFLAGS([gaussianblur],[-lm])
+  VLC_ADD_LIBS([gaussianblur],[-lm])
 ])
 AC_CHECK_LIB(mx,sqrtf,[
-  VLC_ADD_LDFLAGS([x264],[-lmx])
+  VLC_ADD_LIBS([x264],[-lmx])
 ])
 fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"
 
@@ -651,7 +669,7 @@ if test "${ac_cv_have_plugins}" = "no"; then
    [ac_cv_my_have_shl_load=yes,
     AC_CHECK_LIB(dld, shl_load,
      [ac_cv_my_have_shl_load=yes
-      VLC_ADD_LDFLAGS([libvlc],[-ldld])])])
+      VLC_ADD_LIBS([libvlc],[-ldld])])])
   if test "${ac_cv_my_have_shl_load}" = "yes"; then
     AC_DEFINE(HAVE_DL_SHL_LOAD, 1, [Define if you have the shl_load API])
     ac_cv_have_plugins=yes
@@ -661,7 +679,7 @@ fi
 # Whatever style
 if test "${ac_cv_have_plugins}" = "no"; then
   AC_CHECK_LIB(dld, dld_link,
-   [VLC_ADD_LDFLAGS([libvlc],[-ldld])
+   [VLC_ADD_LIBS([libvlc],[-ldld])
     AC_DEFINE(HAVE_DL_DLD_LINK, 1, [Define if you have the GNU dld library])
     ac_cv_have_plugins=yes])
 fi
@@ -670,7 +688,7 @@ fi
 if test "${ac_cv_have_plugins}" = "no"; then
   if test "${SYS}" = "mingw32" -o "${SYS}" = "cygwin"; then
     AC_CHECK_LIB(kernel32, main,
-     [VLC_ADD_LDFLAGS([libvlc],[-lkernel32])
+     [VLC_ADD_LIBS([libvlc],[-lkernel32])
       AC_DEFINE(HAVE_DL_WINDOWS, 1, [Define if you have Windows' LoadLibrary])
       ac_cv_have_plugins=yes])
   fi
@@ -700,10 +718,10 @@ if test "${ac_cv_have_plugins}" = "no"; then
     ac_cv_my_have_dlopen=yes,
     AC_CHECK_LIB(dl, dlopen,
       ac_cv_my_have_dlopen=yes
-      VLC_ADD_LDFLAGS([libvlc],[-ldl]),
+      VLC_ADD_LIBS([libvlc realaudio],[-ldl]),
       AC_CHECK_LIB(svld, dlopen,
         ac_cv_my_have_dlopen=yes
-        VLC_ADD_LDFLAGS([libvlc],[-lsvld]))))
+        VLC_ADD_LIBS([libvlc],[-lsvld]))))
   if test "${ac_cv_my_have_dlopen}" = "yes"; then
     AC_DEFINE(HAVE_DL_DLOPEN, 1, [Define if you have the dlopen API])
     ac_cv_have_plugins=yes
@@ -727,89 +745,30 @@ if test "${THREAD_LIB}" = "error"; then
   THREAD_LIB=""
 fi
 
-dnl Check for cthreads under GNU/Hurd for instance
-AC_CHECK_LIB(threads,cthread_fork,THREAD_LIB="-lthreads")
+VLC_ADD_LIBS([libvlc plugin],[${THREAD_LIB}])
 
-dnl
-dnl  GNU portable threads
-dnl
-AC_ARG_ENABLE(pth,
-  [  --enable-pth            GNU Pth support (default disabled)],
-  [ if test "${enable_pth}" = "yes"; then
-    AC_CHECK_LIB(pth,pth_init)
-    AC_MSG_CHECKING(for pth_init in pth.h)
-    AC_EGREP_HEADER(pth_init,pth.h,[
-      AC_MSG_RESULT(yes)
-      AC_DEFINE(PTH_INIT_IN_PTH_H, 1,
-                Define if <pth.h> defines pth_init)
-      THREAD_LIB="-lpth"
-    ],[
-      AC_MSG_RESULT(no)
-    ])
-    fi
+AC_CHECK_LIB(rt, clock_nanosleep, [
+  VLC_ADD_LIBS([libvlc],[-lrt])
+  AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1, [Define to 1 if you have clock_nanosleep.])
+], [
+  dnl HP/UX port
+  AC_CHECK_LIB(rt,sem_init, [VLC_ADD_LIBS([libvlc],[-lrt])])
 ])
 
-dnl
-dnl  State Threads
-dnl
-AC_ARG_ENABLE(st,
-  [  --enable-st             State Threads (default disabled)],
-  [ if test "${enable_st}" = "yes"; then
-    AC_CHECK_LIB(st,st_init)
-    AC_MSG_CHECKING(for st_init in st.h)
-    AC_EGREP_HEADER(st_init,st.h,[
-      AC_MSG_RESULT(yes)
-      AC_DEFINE(ST_INIT_IN_ST_H, 1,
-                Define if <st.h> defines st_init)
-      THREAD_LIB="-lst"
-    ],[
-      AC_MSG_RESULT(yes)
-    ])
-    fi
+have_nanosleep=false
+AC_CHECK_FUNCS(nanosleep,have_nanosleep=:,[
+  AC_CHECK_LIB(rt,nanosleep,
+    [VLC_ADD_LIBS([libvlc],[-lrt]) have_nanosleep=:],
+    [AC_CHECK_LIB(posix4,nanosleep,
+        [VLC_ADD_LIBS([libvlc],[-lposix4]) have_nanosleep=:])]
+  )
 ])
-
-VLC_ADD_LDFLAGS([libvlc plugin],[${THREAD_LIB}])
-
-dnl Don't link with rt when using GNU-pth
-if test "${THREAD_LIB}" != "-lpth" && test "${THREAD_LIB}" != "-lst"; then
-  AC_CHECK_LIB(rt, clock_nanosleep, [
-    VLC_ADD_LDFLAGS([libvlc],[-lrt])
-    AC_DEFINE(HAVE_CLOCK_NANOSLEEP, 1, [Define to 1 if you have clock_nanosleep.])
-  ], [
-    dnl HP/UX port
-    AC_CHECK_LIB(rt,sem_init, [VLC_ADD_LDFLAGS([libvlc],[-lrt])])
-  ])
-
-  have_nanosleep=false
-  AC_CHECK_FUNCS(nanosleep,have_nanosleep=:,[
-    AC_CHECK_LIB(rt,nanosleep,
-      [VLC_ADD_LDFLAGS([libvlc],[-lrt]) have_nanosleep=:],
-      [AC_CHECK_LIB(posix4,nanosleep,
-          [VLC_ADD_LDFLAGS([libvlc],[-lposix4]) have_nanosleep=:])]
-    )
-  ])
-  if ${have_nanosleep}; then
-    AC_DEFINE(HAVE_NANOSLEEP, 1,
-              Define if nanosleep is available.)
-  fi
+if ${have_nanosleep}; then
+  AC_DEFINE(HAVE_NANOSLEEP, 1, [Define if nanosleep is available.])
 fi
+fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce" 
 
 dnl Check for misc headers
-AC_MSG_CHECKING(for pthread_cond_t in pthread.h)
-AC_EGREP_HEADER(pthread_cond_t,pthread.h,[
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(PTHREAD_COND_T_IN_PTHREAD_H, 1,
-            Define if <pthread.h> defines pthread_cond_t.)],[
-  AC_MSG_RESULT(no)])
-
-AC_MSG_CHECKING(for pthread_once in pthread.h)
-AC_EGREP_HEADER(pthread_once,pthread.h,[
-  AC_MSG_RESULT(yes)
-  AC_DEFINE(PTHREAD_ONCE_IN_PTHREAD_H, 1,
-            Define if <pthread.h> defines pthread_once.)],[
-  AC_MSG_RESULT(no)])
-fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"
-
 AC_MSG_CHECKING(for strncasecmp in strings.h)
 AC_EGREP_HEADER(strncasecmp,strings.h,[
   AC_MSG_RESULT(yes)
@@ -818,18 +777,27 @@ AC_EGREP_HEADER(strncasecmp,strings.h,[
   AC_MSG_RESULT(no)])
 
 dnl Check for headers
-AC_CHECK_HEADERS(signal.h time.h errno.h stdint.h stdbool.h getopt.h strings.h inttypes.h sys/int_types.h wchar.h)
+AC_CHECK_HEADERS(signal.h time.h errno.h stdint.h stdbool.h getopt.h strings.h inttypes.h sys/int_types.h wchar.h locale.h)
 AC_CHECK_HEADERS(sys/sockio.h fcntl.h sys/types.h sys/time.h sys/times.h sys/ioctl.h sys/stat.h)
-AC_CHECK_HEADERS([arpa/inet.h net/if.h netinet/in.h sys/socket.h netinet/udplite.h])
+AC_CHECK_HEADERS([arpa/inet.h netinet/in.h netinet/udplite.h])
+AC_CHECK_HEADERS([net/if.h], [], [],
+  [
+    #include <sys/socket.h>
+  ])
 if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"; then
 AC_CHECK_HEADERS(machine/param.h sys/shm.h)
-AC_CHECK_HEADERS(linux/version.h)
+AC_CHECK_HEADERS([linux/version.h linux/dccp.h])
 AC_CHECK_HEADERS(syslog.h)
 fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"
 
 AC_HEADER_TIME
 
-AC_CHECK_TYPE(ssize_t, int)
+dnl LP64 adn LLP64 architectures had better define ssize_t by themselves...
+AH_TEMPLATE(ssize_t, [Define to `int' if <stddef.h> does not define.])
+AC_CHECK_TYPE(ssize_t,, [
+  AC_DEFINE(ssize_t, int)
+])
+
 AC_SEARCH_LIBS(poll, [poll], [AC_DEFINE(HAVE_POLL, 1, [Define to 1 if the OS is usabl... err, has poll().])])
 
 dnl Check for dirent
@@ -861,7 +829,7 @@ AC_EGREP_HEADER(timespec,sys/time.h,[
 
 dnl Check for threads library
 if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"; then
-AC_CHECK_HEADERS(cthreads.h pthread.h kernel/scheduler.h kernel/OS.h)
+AC_CHECK_HEADERS(pthread.h kernel/scheduler.h kernel/OS.h)
 fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"
 
 dnl Find where are the X headers and libraries
@@ -878,16 +846,16 @@ AC_ARG_ENABLE(hal,
 if test "${enable_hal}" != "no"
 then
   PKG_CHECK_MODULES(HAL, hal >= 0.5.0,
-    [ AC_DEFINE( HAVE_HAL_1, [] , [Define if you have the new HAL library API])
-      AC_DEFINE( HAVE_HAL, [], [Define if you have the HAL library] )
+    [ AC_DEFINE( HAVE_HAL_1, 1 , [Define if you have the new HAL library API])
+      AC_DEFINE( HAVE_HAL, 1, [Define if you have the HAL library] )
       VLC_ADD_PLUGINS([hal probe_hal]) 
-      VLC_ADD_LDFLAGS([libvlc hal probe_hal],[$HAL_LIBS])
+      VLC_ADD_LIBS([libvlc hal probe_hal],[$HAL_LIBS])
       VLC_ADD_CFLAGS([libvlc hal probe_hal],[$HAL_CFLAGS])],   
     dnl No hal 0.5 Test for 0.2
     [ PKG_CHECK_MODULES( HAL, hal >= 0.2.97, 
-       [AC_DEFINE(HAVE_HAL, [], [Define if you have the HAL library])
+       [AC_DEFINE(HAVE_HAL, 1, [Define if you have the HAL library])
         VLC_ADD_PLUGINS([hal])
-        VLC_ADD_LDFLAGS([libvlc hal],[$HAL_LIBS])
+        VLC_ADD_LIBS([libvlc hal],[$HAL_LIBS])
         VLC_ADD_CFLAGS([libvlc hal],[$HAL_CFLAGS])],
        [AC_MSG_WARN(HAL library not found)])
     ]
@@ -907,21 +875,32 @@ then
       AC_DEFINE( HAVE_DBUS_2, 1, [Define if you have the D-BUS library API >= 0.92] )
       AC_DEFINE( HAVE_DBUS_1, 1, [Define if you have the D-BUS library API >= 0.30] )
       AC_DEFINE( HAVE_DBUS, 1, [Define if you have the D-BUS library] )
-      VLC_ADD_LDFLAGS([screensaver libvlc],[$DBUS_LIBS])
+      VLC_ADD_LIBS([screensaver libvlc],[$DBUS_LIBS])
       VLC_ADD_CFLAGS([screensaver libvlc],[$DBUS_CFLAGS])
       dnl Check for dbus control interface
-        AC_ARG_ENABLE(dbus-control, [  --enable-dbus-control   D-BUS control interface (default disabled)])
-        if test "${enable_dbus_control}" = "yes"
+        AC_ARG_ENABLE(dbus-control, [  --disable-dbus-control  D-BUS control interface (default enabled)])
+        if test "${enable_dbus_control}" != "no"
         then
           VLC_ADD_PLUGINS([dbus])
-          VLC_ADD_LDFLAGS([dbus],[$DBUS_LIBS])
+          VLC_ADD_LIBS([dbus],[$DBUS_LIBS])
           VLC_ADD_CFLAGS([dbus],[$DBUS_CFLAGS])
-        fi],
-
+        fi
+      dnl Check for Telepathy
+        AC_ARG_ENABLE(telepathy, [  --enable-telepathy      Telepathy Presence plugin through DBus(default enabled)])
+        if test "${enable_telepathy}" != "no"; then
+          VLC_ADD_PLUGINS([telepathy])
+          VLC_ADD_LIBS([telepathy],[$DBUS_LIBS])
+          VLC_ADD_CFLAGS([telepathy],[$DBUS_CFLAGS])
+        fi
+        dnl Power Management Inhibiter
+        VLC_ADD_PLUGINS([inhibit])
+        VLC_ADD_LIBS([inhibit],[$DBUS_LIBS])
+        VLC_ADD_CFLAGS([inhibit],[$DBUS_CFLAGS])
+        ],
     if ${PKG_CONFIG} --exists dbus-1
     then
       [AC_ARG_ENABLE(old-dbus,
-        [  --enable-old-dbus      Deprecated D-Bus support (default disabled)])]
+        [  --enable-old-dbus       Deprecated D-Bus support (default disabled)])]
 
       if test "${enable_old_dbus}" != "yes"
       then
@@ -941,18 +920,18 @@ then
           [ AC_DEFINE( HAVE_DBUS_2, 1, [Define if you have the D-BUS library API >= 0.92] )
             AC_DEFINE( HAVE_DBUS_1, 1, [Define if you have the D-BUS library API >= 0.30] )
             AC_DEFINE( HAVE_DBUS, 1, [Define if you have the D-BUS library] )
-            VLC_ADD_LDFLAGS([screensaver],[$DBUS_LIBS])
+            VLC_ADD_LIBS([screensaver],[$DBUS_LIBS])
             VLC_ADD_CFLAGS([screensaver],[$DBUS_CFLAGS])],
           dnl older dbus
           [ PKG_CHECK_MODULES(DBUS, dbus-1 >= 0.30,
             [ AC_DEFINE( HAVE_DBUS_1, 1, [Define if you have the D-BUS library API >= 0.30 ] )
               AC_DEFINE( HAVE_DBUS, 1, [Define if you have the D-BUS library] )
-              VLC_ADD_LDFLAGS([screensaver],[$DBUS_LIBS])
+              VLC_ADD_LIBS([screensaver],[$DBUS_LIBS])
               VLC_ADD_CFLAGS([screensaver],[$DBUS_CFLAGS])],
             dnl much older dbus
             [ PKG_CHECK_MODULES( DBUS, dbus-1, 
                [AC_DEFINE(HAVE_DBUS, 1, [Define if you have the D-BUS library])
-                VLC_ADD_LDFLAGS([screensaver],[$DBUS_LIBS])
+                VLC_ADD_LIBS([screensaver],[$DBUS_LIBS])
                 VLC_ADD_CFLAGS([screensaver],[$DBUS_CFLAGS])],
                [AC_MSG_WARN(DBUS library not found)])
             ]
@@ -986,53 +965,67 @@ if test "${ac_cv_c_ntohl_sys_param_h}" != "no"; then
 fi
 CFLAGS="${CFLAGS_save}"
 
-RDC_PROG_CC_WFLAGS([all extra no-unused-parameter sign-compare undef pointer-arith bad-function-cast cast-align write-strings old-style-definition missing-prototypes volatile-register-var])
+RDC_PROG_CC_WFLAGS([all extra sign-compare undef pointer-arith bad-function-cast cast-align write-strings missing-prototypes volatile-register-var])
 RDC_PROG_CC_FLAGS_IFELSE([-pipe])
 
 dnl This helps detect broken plugins with undefined symbols
 dnl Better fail loudly at build-time than silenty at run-time.
 dnl Unfortunately, this sucks on FreeBSD (won't even link with -lc)
-dnl RDC_PROG_LINK_FLAGS_IFELSE([-Wl,-z,defs], [
-dnl   VLC_ADD_LDFLAGS([plugin],[-Wl,-z,defs])
-dnl ])
+if test `uname -s` != FreeBSD; then
+  RDC_PROG_LINK_FLAGS_IFELSE([-Wl,-z,defs], [
+    VLC_ADD_LDFLAGS([plugin],[-Wl,-z,defs])
+  ])
+fi
 
 dnl Check for various optimization flags
 AC_CACHE_CHECK([if \$CC accepts -Os],
     [ac_cv_c_os],
     [CFLAGS="${CFLAGS_save} -Os"
      AC_TRY_COMPILE([],,ac_cv_c_os=yes, ac_cv_c_os=no)])
-if test "${ac_cv_c_os}" != "no" -a "${host_cpu}" = "mipsel"; then
-    CFLAGS_OPTIM="${CFLAGS_OPTIM} -Os"
+if test "${ac_cv_c_os}" != "no"; then
+    CFLAGS_OPTIM_SIZE="${CFLAGS_OPTIM_SIZE} -Os"
+else 
+    AC_CACHE_CHECK([if \$CC accepts -O],
+        [ac_cv_c_o],
+        [CFLAGS="${CFLAGS_save} -O"
+         AC_TRY_COMPILE([],,ac_cv_c_o=yes, ac_cv_c_o=no)])
+    if test "${ac_cv_c_o}" != "no"; then
+        if test "${ac_cv_c_o3}" = "no"; then
+            CFLAGS_OPTIM_SIZE="${CFLAGS_OPTIM_SIZE} -O"
+        fi
+    fi
 fi
 
 AC_CACHE_CHECK([if \$CC accepts -O3],
     [ac_cv_c_o3],
     [CFLAGS="${CFLAGS_save} -O3"
      AC_TRY_COMPILE([],,ac_cv_c_o3=yes, ac_cv_c_o3=no)])
-if test "${ac_cv_c_o3}" != "no" -a "${host_cpu}" != "mipsel"; then
-    CFLAGS_OPTIM="${CFLAGS_OPTIM} -O3"
+if test "${ac_cv_c_o3}" != "no" -a "x${enable_debug}" = "xno"; then
+    CFLAGS_OPTIM_SPEED="${CFLAGS_OPTIM_SPEED} -O3"
+else
+    AC_CACHE_CHECK([if \$CC accepts -O2],
+        [ac_cv_c_o2],
+        [CFLAGS="${CFLAGS_save} -O2"
+         AC_TRY_COMPILE([],,ac_cv_c_o2=yes, ac_cv_c_o2=no)])
+    if test "${ac_cv_c_o2}" != "no"; then
+        CFLAGS_OPTIM_SPEED="${CFLAGS_OPTIM_SPEED} -O2"
+    else
+        AC_CACHE_CHECK([if \$CC accepts -O],
+            [ac_cv_c_o],
+            [CFLAGS="${CFLAGS_save} -O"
+             AC_TRY_COMPILE([],,ac_cv_c_o=yes, ac_cv_c_o=no)])
+        if test "${ac_cv_c_o}" != "no"; then
+            CFLAGS_OPTIM_SPEED="${CFLAGS_OPTIM_SPEED} -O"
+        fi
+    fi
 fi
 
-AC_CACHE_CHECK([if \$CC accepts -O2],
-    [ac_cv_c_o2],
-    [CFLAGS="${CFLAGS_save} -O2"
-     AC_TRY_COMPILE([],,ac_cv_c_o2=yes, ac_cv_c_o2=no)])
-if test "${ac_cv_c_o2}" != "no" -a "${host_cpu}" != "mipsel"; then
-    if test "${ac_cv_c_o3}" = "no"; then
-        CFLAGS_OPTIM="${CFLAGS_OPTIM} -O2"
-    fi
-    CFLAGS_NOOPTIM="${CFLAGS_NOOPTIM} -O2"
-else 
-    AC_CACHE_CHECK([if \$CC accepts -O],
-        [ac_cv_c_o],
-        [CFLAGS="${CFLAGS_save} -O"
-         AC_TRY_COMPILE([],,ac_cv_c_o=yes, ac_cv_c_o=no)])
-    if test "${ac_cv_c_o}" != "no" -a "${host_cpu}" != "mipsel"; then
-        if test "${ac_cv_c_o3}" = "no"; then
-            CFLAGS_OPTIM="${CFLAGS_OPTIM} -O"
-       fi
-        CFLAGS_NOOPTIM="${CFLAGS_NOOPTIM} -O"
-    fi
+AC_CACHE_CHECK([if \$CC accepts -O0],
+    [ac_cv_c_o0],
+    [CFLAGS="${CFLAGS_save} -O0"
+     AC_TRY_COMPILE([],,ac_cv_c_o0=yes, ac_cv_c_o0=no)])
+if test "${ac_cv_c_o0}" != "no"; then
+    CFLAGS_NOOPTIM="${CFLAGS_NOOPTIM} -O0"
 fi
 
 dnl Check for -ffast-math
@@ -1041,7 +1034,7 @@ AC_CACHE_CHECK([if \$CC accepts -ffast-math],
     [CFLAGS="${CFLAGS_save} -ffast-math"
      AC_TRY_COMPILE([],,ac_cv_c_fast_math=yes, ac_cv_c_fast_math=no)])
 if test "${ac_cv_c_fast_math}" != "no"; then
-    CFLAGS_OPTIM="${CFLAGS_OPTIM} -ffast-math"
+    CFLAGS_OPTIM_SPEED="${CFLAGS_OPTIM_SPEED} -ffast-math"
 fi
 
 dnl Check for -funroll-loops
@@ -1053,7 +1046,7 @@ then
       [CFLAGS="${CFLAGS_save} -funroll-loops"
        AC_TRY_COMPILE([],,ac_cv_c_unroll_loops=yes, ac_cv_c_unroll_loops=no)])
   if test "${ac_cv_c_unroll_loops}" != "no"; then
-      CFLAGS_OPTIM="${CFLAGS_OPTIM} -funroll-loops"
+      CFLAGS_OPTIM_SPEED="${CFLAGS_OPTIM_SPEED} -funroll-loops"
   fi
 fi
 
@@ -1064,8 +1057,6 @@ AC_CACHE_CHECK([if \$CC accepts -fomit-frame-pointer],
      AC_TRY_COMPILE([],,ac_cv_c_omit_frame_pointer=yes, ac_cv_c_omit_frame_pointer=no)])
 if test "${ac_cv_c_omit_frame_pointer}" != "no"; then
     CFLAGS_OPTIM_NODEBUG="${CFLAGS_OPTIM_NODEBUG} -fomit-frame-pointer"
-    # these plugins do not compile without -fomit-frame-pointer, damn gcc!
-    VLC_ADD_CFLAGS([i420_yuy2_mmx i420_yuy2_sse2],[-fomit-frame-pointer])
 fi
 
 dnl Check for -fvisibility=hidden
@@ -1077,6 +1068,8 @@ if test "${ac_cv_c_visibility_hidden}" != "no"; then
     VLC_ADD_CFLAGS([libvlc plugin],[-fvisibility=hidden])
 fi
 
+AM_CONDITIONAL(HAVE_COMPILER_EXPORT, [test "$SYS" = "mingw32" -o "${ac_cv_c_visibility_hidden}" != "no"])
+
 dnl Check for -fvisibility-inlines-hidden (breaks x86_64 linkers)
 dnl AC_LANG_PUSH(C++)
 dnl     AC_CACHE_CHECK([if \$CXX accepts -fvisibility-inlines-hidden],
@@ -1090,14 +1083,14 @@ dnl     CXXFLAGS="${CXXFLAGS_save}"
 dnl AC_LANG_POP(C++)
 
 dnl Check for -mdynamic-no-pic
-AC_CACHE_CHECK([if \$CC accepts -mdynamic-no-pic],
-    [ac_cv_c_dynamic_no_pic],
-    [CFLAGS="${CFLAGS_save} -mdynamic-no-pic"
-     AC_TRY_COMPILE([],,ac_cv_c_dynamic_no_pic=yes, ac_cv_c_dynamic_no_pic=no)])
-AS_IF([test "${enable_libtool}" = "no" && test "${ac_cv_c_dynamic_no_pic}" != "no"], [
-    VLC_ADD_CFLAGS([builtin],[-mdynamic-no-pic])
-    VLC_ADD_CFLAGS([libvlc],[-mdynamic-no-pic])
-])
+dnl AC_CACHE_CHECK([if \$CC accepts -mdynamic-no-pic],
+dnl     [ac_cv_c_dynamic_no_pic],
+dnl     [CFLAGS="${CFLAGS_save} -mdynamic-no-pic"
+dnl      AC_TRY_COMPILE([],,ac_cv_c_dynamic_no_pic=yes, ac_cv_c_dynamic_no_pic=no)])
+dnl AS_IF([test "${ac_cv_c_dynamic_no_pic}" != "no"], [
+dnl     VLC_ADD_CFLAGS([builtin],[-mdynamic-no-pic])
+dnl     VLC_ADD_CFLAGS([libvlc],[-mdynamic-no-pic])
+dnl ])
 
 dnl Check for Darwin plugin linking flags
 AC_CACHE_CHECK([if \$CC accepts -bundle -undefined error],
@@ -1110,33 +1103,17 @@ fi
 
 dnl Check for standard plugin linking flags
 dnl BeOS' gcc needs -nostart instead of -shared, even if -shared isn't harmful (just a warning)
-AS_IF([test "${enable_libtool}" = "no"], [
-  AS_IF([test "${SYS}" = "beos"], [
-    VLC_ADD_LDFLAGS([plugin mozilla],[-nostart])
-  ], [
-    AC_CACHE_CHECK([if \$CC accepts -shared],
-          [ac_cv_ld_plugins],
-          [CFLAGS="${CFLAGS_save} -shared"
-         AC_TRY_COMPILE([],, ac_cv_ld_plugins=yes, ac_cv_ld_plugins=no)])
-    AS_IF([test "${ac_cv_ld_plugins}" != "no"], [
-      VLC_ADD_LDFLAGS([plugin mozilla],[-shared])
-    ])
-  ])
-])
-
-dnl Check for variadic macros
-AC_CACHE_CHECK([for variadic cpp macros],
-    [ac_cv_cpp_variadic_macros],
-    [CFLAGS="${CFLAGS_save}"
-     AC_TRY_COMPILE(
-         [#include <stdio.h>
-          #define a(b,c...) printf(b,##c)],
-         [a("foo");a("%s","bar");a("%s%s","baz","quux");],
-         ac_cv_cpp_variadic_macros=yes,
-         ac_cv_cpp_variadic_macros=no)])
-if test "${ac_cv_cpp_variadic_macros}" != "no"; then
-    AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for variadic macros)
-fi
+dnl AS_IF([test "${SYS}" = "beos"], [
+dnl   VLC_ADD_LDFLAGS([plugin mozilla],[-nostart])
+dnl ], [
+dnl   AC_CACHE_CHECK([if \$CC accepts -shared],
+dnl         [ac_cv_ld_plugins],
+dnl         [CFLAGS="${CFLAGS_save} -shared"
+dnl        AC_TRY_COMPILE([],, ac_cv_ld_plugins=yes, ac_cv_ld_plugins=no)])
+dnl   AS_IF([test "${ac_cv_ld_plugins}" != "no"], [
+dnl     VLC_ADD_LDFLAGS([plugin mozilla],[-shared])
+dnl   ])
+dnl ])
 
 dnl Checks for __attribute__(aligned()) directive
 AC_CACHE_CHECK([__attribute__ ((aligned ())) support],
@@ -1213,15 +1190,15 @@ dnl
 dnl  default modules
 dnl
 VLC_ADD_PLUGINS([dummy logger memcpy])
-VLC_ADD_PLUGINS([mpgv mpga m4v m4a h264 vc1 ps pva avi asf mp4 rawdv rawvid nsv real aiff mjpeg demuxdump flacsys tta])
-VLC_ADD_PLUGINS([cvdsub svcdsub spudec telx subsdec dvbsub mpeg_audio lpcm a52 dts cinepak flac])
-VLC_ADD_PLUGINS([deinterlace invert adjust transform wave ripple psychedelic gradient motionblur rv32 rotate noise extract sharpen])
+VLC_ADD_PLUGINS([mpgv mpga m4v m4a h264 vc1 demux_cdg cdg ps pva avi asf mp4 rawdv rawvid nsv real aiff mjpeg demuxdump flacsys tta])
+VLC_ADD_PLUGINS([cvdsub svcdsub spudec subsdec subsusf t140 dvbsub cc mpeg_audio lpcm a52 dts cinepak flac])
+VLC_ADD_PLUGINS([deinterlace invert adjust transform wave ripple psychedelic gradient motionblur rv32 rotate noise grain extract sharpen seamcarving])
 VLC_ADD_PLUGINS([converter_fixed mono])
 VLC_ADD_PLUGINS([trivial_resampler ugly_resampler])
 VLC_ADD_PLUGINS([trivial_channel_mixer trivial_mixer])
-VLC_ADD_PLUGINS([playlist export sgimb nsc xtag])
-VLC_ADD_PLUGINS([i420_rgb rawvideo blend scale image logo magnify puzzle colorthres])
-VLC_ADD_PLUGINS([wav araw subtitle vobsub adpcm a52sys dtssys au ty voc xa nuv])
+VLC_ADD_PLUGINS([playlist export nsc xtag])
+VLC_ADD_PLUGINS([i420_rgb grey_yuv rawvideo blend scale image logo magnify puzzle colorthres])
+VLC_ADD_PLUGINS([wav araw subtitle vobsub adpcm a52sys dtssys au ty voc xa nuv smf])
 VLC_ADD_PLUGINS([access_directory access_file access_udp access_tcp])
 VLC_ADD_PLUGINS([access_http access_mms access_ftp])
 VLC_ADD_PLUGINS([access_filter_bandwidth])
@@ -1229,26 +1206,25 @@ VLC_ADD_PLUGINS([packetizer_mpegvideo packetizer_h264])
 VLC_ADD_PLUGINS([packetizer_mpeg4video packetizer_mpeg4audio])
 VLC_ADD_PLUGINS([packetizer_vc1])
 
+ALIASES="${ALIASES} cvlc"
+
+dnl
+dnl default modules that need g++
+dnl
+AC_LANG_PUSH(C++)
+VLC_ADD_PLUGINS([spatializer])
+AC_LANG_POP(C++)
 
 if test "${SYS}" != "mingwce"; then
   VLC_ADD_PLUGINS([access_fake access_filter_timeshift access_filter_record access_filter_dump])
-  VLC_ADD_PLUGINS([gestures rc telnet hotkeys netsync showintf marq podcast shout sap fake folder])
+  VLC_ADD_PLUGINS([gestures rc telnet hotkeys showintf marq podcast shout sap fake folder])
   VLC_ADD_PLUGINS([rss mosaic wall motiondetect clone crop erase bluescreen alphamask gaussianblur])
-  VLC_ADD_PLUGINS([i420_yuy2 i422_yuy2 i420_ymga])
+  VLC_ADD_PLUGINS([i420_yuy2 i422_yuy2 i420_ymga i422_i420 yuy2_i422 yuy2_i420 chroma_chain])
   VLC_ADD_PLUGINS([aout_file linear_resampler bandlimited_resampler])
   VLC_ADD_PLUGINS([float32_mixer spdif_mixer simple_channel_mixer])
   VLC_ADD_PLUGINS([dolby_surround_decoder headphone_channel_mixer normvol equalizer param_eq])
   VLC_ADD_PLUGINS([converter_float a52tospdif dtstospdif audio_format])
-fi
-
-dnl
-dnl  Switch to enable a version of VLC where most modules will be builtin
-dnl
-AC_ARG_ENABLE(mostly-builtin,
-[  --enable-mostly-builtin most modules will be built-in (default disabled)])
-if test "${enable_mostly_builtin}" = "yes"; then
-  VLC_ADD_BUILTINS([${PLUGINS}])
-  PLUGINS=""
+  ALIASES="${ALIASES} rvlc"
 fi
 
 dnl
@@ -1258,13 +1234,13 @@ if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"; then
     VLC_ADD_PLUGINS([screensaver motion])
 elif test "${SYS}" != "mingwce"; then
     VLC_ADD_PLUGINS([ntservice access_smb dmo msn])
-    VLC_ADD_LDFLAGS([dmo],[-lole32])
+    VLC_ADD_LIBS([dmo],[-lole32 -luuid])
 else
     VLC_ADD_PLUGINS([win32text])
 fi
 if test "${SYS}" = "darwin"; then
     VLC_ADD_PLUGINS([quartztext])
-    VLC_ADD_LDFLAGS([quartztext],[-framework Carbon -framework ApplicationServices])
+    VLC_ADD_LDFLAGS([quartztext],[-Wl,-framework,Carbon,-framework,ApplicationServices])
 fi
 
 dnl
@@ -1276,7 +1252,7 @@ MMXEXT_MODULES="memcpymmxext"
 #MMXEXT_MODULES="${MMXEXT_MODULES} idctmmxext motionmmxext"
 THREEDNOW_MODULES="memcpy3dn"
 SSE_MODULES=""
-SSE2_MODULES="i420_rgb_sse2 i420_yuy2_sse2"
+SSE2_MODULES="i420_rgb_sse2 i420_yuy2_sse2 i422_yuy2_sse2"
 ALTIVEC_MODULES="memcpyaltivec i420_yuy2_altivec"
 #ALTIVEC_MODULES="${ALTIVEC_MODULES} idctaltivec motionaltivec"
 
@@ -1302,7 +1278,7 @@ AC_CACHE_CHECK([if \$CC groks MMX intrinsics],
                     [ac_cv_c_mmx_intrinsics=no])])
 if test "${ac_cv_c_mmx_intrinsics}" != "no"; then
   AC_DEFINE(HAVE_MMX_INTRINSICS, 1, Define if MMX intrinsics are available.)
-  VLC_ADD_CFLAGS([i420_rgb_mmx],[-mmmx])
+  VLC_ADD_CFLAGS([${MMX_MODULES}],[-mmmx])
 fi
 
 dnl  Check for fully workin SSE2 intrinsics
@@ -1327,7 +1303,7 @@ AC_CACHE_CHECK([if \$CC groks SSE2 intrinsics],
                     [ac_cv_c_sse2_intrinsics=no])])
 if test "${ac_cv_c_sse2_intrinsics}" != "no"; then
   AC_DEFINE(HAVE_SSE2_INTRINSICS, 1, Define if SSE2 intrinsics are available.)
-  VLC_ADD_CFLAGS([i420_rgb_sse2],[-msse2])
+  VLC_ADD_CFLAGS([${SSE2_MODULES}],[-msse2])
 fi
 
 AC_CACHE_CHECK([if \$CC groks MMX inline assembly],
@@ -1474,12 +1450,12 @@ AS_IF( test "${enable_altivec}" != "no",
 
 AC_CACHE_CHECK([if linker needs -framework vecLib],
     [ac_cv_ld_altivec],
-    [LDFLAGS="${LDFLAGS_vlc} -framework vecLib"
+    [LDFLAGS="${LDFLAGS_vlc} -Wl,-framework,vecLib"
      AC_TRY_LINK([],,ac_cv_ld_altivec=yes,ac_cv_ld_altivec=no)
      LDFLAGS="${LDFLAGS_save}"
     ])
 if test "${ac_cv_ld_altivec}" != "no"; then
-  VLC_ADD_LDFLAGS([libvlc idctaltivec motionaltivec memcpyaltivec],[-framework vecLib])
+  VLC_ADD_LDFLAGS([libvlc idctaltivec motionaltivec memcpyaltivec],[-Wl,-framework,vecLib])
 fi
 fi # end "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"
 
@@ -1497,7 +1473,7 @@ if test -n "${with_tuning}"; then
         CFLAGS_TUNING="-mtune=${with_tuning}"
     fi
 else
-    if test "${SYS}" = "darwin" -a "${host_cpu}" = "i686"; then
+    if test "${SYS}" = "darwin" -a "${host_cpu}" != "powerpc"; then
         CFLAGS_TUNING="-march=pentium-m -mtune=prescott"
     elif test "${host_cpu}" = "i686" -o "${host_cpu}" = "i586" -o "${host_cpu}" = "i486" -o "${host_cpu}" = "i386"; then
         CFLAGS_TUNING="-mtune=pentium2"
@@ -1527,22 +1503,26 @@ AS_IF([test "${CFLAGS_TUNING}"],
 dnl
 dnl  x86 accelerations
 dnl
-if test "${host_cpu}" = "i686" -o "${host_cpu}" = "i586" -o "${host_cpu}" = "x86" -o "${host_cpu}" = "i386" -o "${host_cpu}"="i486" -o "${host_cpu}" = "x86_64"
-then
+AC_ARG_ENABLE(mmx,
+[  --disable-mmx       disable MMX optimizations (default enabled on x86)],
+[ if test "${enable_mmx}" = "yes"; then ARCH="${ARCH} mmx";
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ],
+[ if test "${host_cpu}" = "i686" -o "${host_cpu}" = "i586" -o "${host_cpu}" = "x86" -o "${host_cpu}" = "i386" -o "${host_cpu}" = "i486" -o "${host_cpu}" = "x86_64"; then
     ARCH="${ARCH} mmx"
-    VLC_ADD_BUILTINS([${ACCEL_MODULES}])
-fi
-if test "${host_cpu}" = "i686" -o "${host_cpu}" = "x86_64"
-then
-    ARCH="${ARCH} sse sse2"
-    VLC_ADD_BUILTINS([${ACCEL_MODULES}])
-fi
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ])
+
+AC_ARG_ENABLE(sse,
+[  --disable-sse       disable SSE (1 and 2) optimizations (default enabled on i686 and x86_64)],
+[ if test "${enable_sse}" = "yes"; then ARCH="${ARCH} sse sse2";
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ],
+[ if test "${host_cpu}" = "i686" -o "${host_cpu}" = "x86_64"; then ARCH="${ARCH} sse sse2";
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ])
 
 dnl
 dnl  Memory usage
 dnl
 AC_ARG_ENABLE(optimize-memory,
-[  --enable-optimize-memory      optimize memory usage over performance])
+[  --enable-optimize-memory optimize memory usage over performance])
 if test "${enable_optimize_memory}" = "yes"; then
   AC_DEFINE(OPTIMIZE_MEMORY, 1, Define if you want to optimize memory usage over performance)
 fi
@@ -1552,7 +1532,13 @@ dnl  Enable/disable optimizations
 dnl
 AC_ARG_ENABLE(optimizations,
 [  --disable-optimizations disable compiler optimizations (default enabled)])
-test "${enable_optimizations}" != "no" && enable_optimizations="yes"
+if test "${enable_optimizations}" != "no"; then
+   if test "${enable_optimize_memory}" = "yes"; then
+      enable_optimizations="size"
+   else
+      enable_optimizations="speed"
+   fi
+fi
 
 dnl
 dnl  AltiVec acceleration
@@ -1560,9 +1546,9 @@ dnl
 AC_ARG_ENABLE(altivec,
 [  --disable-altivec       disable AltiVec optimizations (default enabled on PPC)],
 [ if test "${enable_altivec}" = "yes"; then ARCH="${ARCH} altivec";
-    VLC_ADD_BUILTINS([${ACCEL_MODULES}]) fi ],
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ],
 [ if test "${host_cpu}" = "powerpc"; then ARCH="${ARCH} altivec";
-    VLC_ADD_BUILTINS([${ACCEL_MODULES}]) fi ])
+    VLC_ADD_PLUGINS([${ACCEL_MODULES}]) fi ])
 
 dnl
 dnl  Debugging mode
@@ -1626,16 +1612,16 @@ AC_ARG_ENABLE(shout,
   [  --enable-shout          libshout output plugin (default disabled)])
 if test "${enable_shout}" = "yes"; then
   PKG_CHECK_MODULES(SHOUT, shout >= 2.1,
-    [AC_DEFINE(HAVE_SHOUT, [], [Define if you have the libshout library])
+    [AC_DEFINE(HAVE_SHOUT, 1, [Define if you have the libshout library])
      VLC_ADD_PLUGINS([access_output_shout])
-     VLC_ADD_LDFLAGS([access_output_shout],[$SHOUT_LIBS])
+     VLC_ADD_LIBS([access_output_shout],[$SHOUT_LIBS])
      VLC_ADD_CFLAGS([access_output_shout],[$SHOUT_CFLAGS])],
     [AC_MSG_WARN(libshout library not found)])
 fi
 
-dnl Lua playlist demux
-AC_ARG_ENABLE(luaplaylist,
-  [  --enable-lua            lua playlist demux plugin (default enabled)])
+dnl Lua modules
+AC_ARG_ENABLE(lua,
+  [  --enable-lua            lua playlist and metafetcher plugins (default enabled)])
 if test "${enable_lua}" != "no"
 then
   PKG_CHECK_MODULES(LUA, lua5.1,
@@ -1663,10 +1649,10 @@ then
       ])
     ])
   if test "x${have_lua}" = "xyes" ;  then
-     AC_DEFINE(HAVE_LUA, [], [Define if you have the lua library])
-     VLC_ADD_PLUGINS([luaplaylist])
-     VLC_ADD_LDFLAGS([luaplaylist],[$LUA_LIBS])
-     VLC_ADD_CFLAGS([luaplaylist],[$LUA_CFLAGS])
+     AC_DEFINE(HAVE_LUA, 1, [Define if you have the lua library])
+     VLC_ADD_PLUGINS([lua])
+     VLC_ADD_LIBS([lua],[$LUA_LIBS])
+     VLC_ADD_CFLAGS([lua],[$LUA_CFLAGS])
   fi
 fi
 
@@ -1712,10 +1698,10 @@ AS_IF([test "${enable_notify}" != "no" -a "${SYS}" != "mingw32"], [
       [
         VLC_ADD_PLUGINS([notify])
         VLC_ADD_CFLAGS(notify, [$NOTIFY_CFLAGS])
-       VLC_ADD_LDFLAGS(notify, [$NOTIFY_LIBS])
+        VLC_ADD_LIBS(notify, [$NOTIFY_LIBS])
       ],[
-       AS_IF([test "${enable_notify}" = "yes"],[
-              AC_MSG_WARN( libnotify not found) ])
+    AS_IF([test "${enable_notify}" = "yes"],[
+        AC_MSG_WARN( libnotify not found) ])
       ])
   ])
 
@@ -1736,9 +1722,9 @@ AC_ARG_ENABLE(musicbrainz,
   [  --enable-musicbrainz    MusicBrainz support (default disabled) ])
   AS_IF([test "${enable_musicbrainz}" = "yes"],[
       PKG_CHECK_MODULES(MUSICBRAINZ, libmusicbrainz,
-       [ VLC_ADD_PLUGINS([musicbrainz])
-         VLC_ADD_LDFLAGS([musicbrainz],[$MUSICBRAINZ_LIBS]) 
-         VLC_ADD_CFLAGS([musicbrainz],[$MUSICBRAINZ_CFLAGS])  ],
+    [ VLC_ADD_PLUGINS([musicbrainz])
+      VLC_ADD_LIBS([musicbrainz],[$MUSICBRAINZ_LIBS])
+      VLC_ADD_CFLAGS([musicbrainz],[$MUSICBRAINZ_CFLAGS])  ],
        [AC_MSG_WARN(MusicBrainz library not found)])
    ])
 
@@ -1747,11 +1733,12 @@ dnl
 dnl Taglibplugin
 dnl
 AC_ARG_ENABLE(taglib,
-  [  --enable-taglib Taglib support (default disabled) ])
-  AS_IF([test "${enable_taglib}" = "yes"],[
+  [  --disable-taglib Taglib support (default enabled) ])
+  AS_IF([test "${enable_taglib}" != "no"],[
     PKG_CHECK_MODULES(TAGLIB, taglib,
-      [ VLC_ADD_PLUGINS([taglib])
-        VLC_ADD_LDFLAGS([taglib],[$TAGLIB_LIBS])
+      [ AC_DEFINE( HAVE_TAGLIB, 1, [Define if you have taglib plugin built] )
+        VLC_ADD_PLUGINS([taglib])
+        VLC_ADD_LIBS([taglib],[$TAGLIB_LIBS -lz])
        VLC_ADD_CXXFLAGS([taglib],[$TAGLIB_CFLAGS]) ],
       [AC_MSG_WARN(TagLib library not found)])
   ])
@@ -1802,17 +1789,17 @@ if test "${enable_live555}" != "no"; then
       AC_CHECK_LIB(liveMedia_pic, main, [
         # We have -lliveMedia_pic, build plugins
         VLC_ADD_PLUGINS([live555])
-        VLC_ADD_LDFLAGS([live555], [-lliveMedia_pic -lgroupsock_pic -lBasicUsageEnvironment_pic -lUsageEnvironment_pic])
+        VLC_ADD_LIBS([live555], [-lliveMedia_pic -lgroupsock_pic -lBasicUsageEnvironment_pic -lUsageEnvironment_pic])
       ], [
         AC_CHECK_LIB(liveMedia, main, [
           # We only have -lliveMedia, do builtins
           VLC_ADD_BUILTINS([live555])
-          VLC_ADD_LDFLAGS([live555], [-lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment])
+          VLC_ADD_LIBS([live555], [-lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment])
         ])
       ])
       if test "${SYS}" = "mingw32"; then
         # add ws2_32 for closesocket, select, recv
-        VLC_ADD_LDFLAGS([live555],[-lws2_32])
+        VLC_ADD_LIBS([live555],[-lws2_32])
       fi
     ])
     CPPFLAGS="${CPPFLAGS_save}"
@@ -1832,13 +1819,13 @@ if test "${enable_live555}" != "no"; then
 
       if test "${SYS}" = "mingw32"; then
         # add ws2_32 for closesocket, select, recv
-        VLC_ADD_LDFLAGS([live555],[-lws2_32])
+        VLC_ADD_LIBS([live555],[-lws2_32])
       fi
 
-      VLC_ADD_LDFLAGS([live555],[-L${real_live555_tree}/liveMedia -lliveMedia])
-      VLC_ADD_LDFLAGS([live555],[-L${real_live555_tree}/BasicUsageEnvironment -lBasicUsageEnvironment])
-      VLC_ADD_LDFLAGS([live555],[-L${real_live555_tree}/groupsock -lgroupsock])
-      VLC_ADD_LDFLAGS([live555],[-L${real_live555_tree}/UsageEnvironment -lUsageEnvironment])
+      VLC_ADD_LIBS([live555],[-L${real_live555_tree}/liveMedia -lliveMedia])
+      VLC_ADD_LIBS([live555],[-L${real_live555_tree}/BasicUsageEnvironment -lBasicUsageEnvironment])
+      VLC_ADD_LIBS([live555],[-L${real_live555_tree}/groupsock -lgroupsock])
+      VLC_ADD_LIBS([live555],[-L${real_live555_tree}/UsageEnvironment -lUsageEnvironment])
 
       VLC_ADD_CXXFLAGS([live555],[-I${real_live555_tree}/BasicUsageEnvironment/include])
       VLC_ADD_CXXFLAGS([live555],[-I${real_live555_tree}/groupsock/include])
@@ -1861,7 +1848,7 @@ dnl
 dnl  special access module for dc1394 input
 dnl
 AC_ARG_ENABLE(dc1394,
-  [  --enable-dc1394       dc1394 access module (default disabled)])
+  [  --enable-dc1394         dc1394 access module (default disabled)])
 if test "${enable_dc1394}" = "yes"
 then
   AC_CHECK_HEADERS(libraw1394/raw1394.h, [
@@ -1869,7 +1856,7 @@ then
         AC_CHECK_HEADERS(libdc1394/dc1394_control.h , [
 dnl         AC_CHECK_LIB( dc1394_control, dc1394_setup_capture, [
               VLC_ADD_PLUGINS([dc1394])
-              VLC_ADD_LDFLAGS([dc1394],[-ldc1394_control -lraw1394])
+              VLC_ADD_LIBS([dc1394],[-ldc1394_control -lraw1394])
 dnl         ],
 dnl         [
 dnl           AC_MSG_ERROR([libdc1394 is mandatory for the dc1394 input module. try --disable-dc1394 or install this library])
@@ -1908,7 +1895,7 @@ then
       dnl  Use ${with_dv_raw1394}/include/libraw1394/raw1394.h
       AC_MSG_RESULT(yes)
       VLC_ADD_PLUGINS([access_dv])
-      VLC_ADD_LDFLAGS([access_dv],[-L${with_dv_raw1394}/lib -lraw1394 -lpthread])
+      VLC_ADD_LIBS([access_dv],[-L${with_dv_raw1394}/lib -lraw1394 -lpthread])
       VLC_ADD_CPPFLAGS([access_dv],[-I${with_dv_raw1394}/include])
     else
       dnl  No libraw1394 could be found, sorry
@@ -1918,7 +1905,7 @@ then
   else
     AC_CHECK_HEADERS(libraw1394/raw1394.h,
     [ VLC_ADD_PLUGINS([access_dv])
-        VLC_ADD_LDFLAGS([access_dv],[-lraw1394 -lavc1394])
+        VLC_ADD_LIBS([access_dv],[-lraw1394 -lavc1394])
     ],[
         if test -n "${enable_dv}"
         then
@@ -1943,7 +1930,7 @@ then
       dnl  Use a custom libraw1394
       AC_MSG_RESULT(${real_dv_raw1394_tree}/src/.libs/libraw1394.a)
       VLC_ADD_BUILTINS([access_dv])
-      VLC_ADD_LDFLAGS([access_dv],[-L${real_dv_raw1394_tree}/src/.libs -lraw1394])
+      VLC_ADD_LIBS([access_dv],[-L${real_dv_raw1394_tree}/src/.libs -lraw1394])
       VLC_ADD_CPPFLAGS([access_dv],[-I${real_dv_raw1394_tree}])
     else
       dnl  The given libraw1394 wasn't built
@@ -1968,7 +1955,7 @@ then
     then
       dnl  Use ${with_dv_avc1394}/include/libavc1394/avc1394.h
       AC_MSG_RESULT(yes)
-      VLC_ADD_LDFLAGS([access_dv],[-L${with_dv_avc1394}/lib -lavc1394 -lrom1394 -lpthread])
+      VLC_ADD_LIBS([access_dv],[-L${with_dv_avc1394}/lib -lavc1394 -lrom1394 -lpthread])
       VLC_ADD_CPPFLAGS([access_dv],[-I${with_avc1394}/include])
     else
       dnl  No libavc1394 could be found, sorry
@@ -1977,7 +1964,7 @@ then
     fi
   else
     AC_CHECK_HEADERS(libavc1394/avc1394.h,
-    [ VLC_ADD_LDFLAGS([access_dv],[-lavc1394 -lrom1394 -lpthread])
+    [ VLC_ADD_LIBS([access_dv],[-lavc1394 -lrom1394 -lpthread])
     ],[
         if test -n "${enable_dv}"
         then
@@ -2001,7 +1988,7 @@ then
     then
       dnl  Use a custom libavc1394
       AC_MSG_RESULT(${real_dv_avc1394_tree}/src/.libs/libavc1394.a)
-      VLC_ADD_LDFLAGS([access_dv],[-L${real_dv_avc1394_tree}/src/.libs -lavc1394 -lrom1394 -lpthread])
+      VLC_ADD_LIBS([access_dv],[-L${real_dv_avc1394_tree}/src/.libs -lavc1394 -lrom1394 -lpthread])
       VLC_ADD_CPPFLAGS([access_dv],[-I${real_dv_avc1394_tree}])
     else
       dnl  The given libavc1394 wasn't built
@@ -2025,7 +2012,7 @@ then
 
   dnl Temporary hack (yeah, sure ;)
   if test "${SYS}" = "mingw32" || test "${SYS}" = "darwin" || test "${SYS}" = "beos" ; then
-      VLC_ADD_LDFLAGS([dvdread],[-ldvdcss])
+      VLC_ADD_LIBS([dvdread],[-ldvdcss])
   fi
 
   if test -z "${with_dvdread}"
@@ -2034,7 +2021,7 @@ then
     then
       AC_CHECK_HEADERS(dvdread/dvd_reader.h,
         [ VLC_ADD_PLUGINS([dvdread])
-          VLC_ADD_LDFLAGS([dvdread],[-ldvdread ${LDFLAGS_dvdcss}])
+          VLC_ADD_LIBS([dvdread],[-ldvdread ${LIBS_dvdcss}])
         ],[
           if test -n "${enable_dvdread}"
           then
@@ -2055,7 +2042,7 @@ then
         dnl  Use a custom libdvdread
         AC_MSG_RESULT(${real_dvdread_tree}/dvdread/.libs/libdvdread.a)
         VLC_ADD_BUILTINS([dvdread])
-        VLC_ADD_LDFLAGS([dvdread],[-L${real_dvdread_tree}/dvdread/.libs -ldvdread ${LDFLAGS_dvdcss}])
+        VLC_ADD_LIBS([dvdread],[-L${real_dvdread_tree}/dvdread/.libs -ldvdread ${LIBS_dvdcss}])
         VLC_ADD_CPPFLAGS([dvdread],[-I${real_dvdread_tree}])
       else
         dnl  The given libdvdread wasn't built
@@ -2070,7 +2057,7 @@ then
       dnl  Use ${with_dvdread}/include/dvdread/dvd_reader.h
       AC_MSG_RESULT(yes)
       VLC_ADD_PLUGINS([dvdread])
-      VLC_ADD_LDFLAGS([dvdread],[-L${with_dvdread}/lib -ldvdread ${LDFLAGS_dvdcss}])
+      VLC_ADD_LIBS([dvdread],[-L${with_dvdread}/lib -ldvdread ${LIBS_dvdcss}])
       VLC_ADD_CPPFLAGS([dvdread],[-I${with_dvdread}/include])
     else
       dnl  No libdvdread could be found, sorry
@@ -2089,7 +2076,7 @@ if test "${enable_dvdnav}" != "no"
 then
   dnl Same hack than dvdread
   if test "${SYS}" = "mingw32" || test "${SYS}" = "darwin" || test "${SYS}" = "beos" ; then
-      VLC_ADD_LDFLAGS([dvdnav],[-ldvdcss])
+      VLC_ADD_LIBS([dvdnav],[-ldvdcss])
   fi
 
   DVDNAV_PATH="${PATH}"
@@ -2104,7 +2091,7 @@ then
   then
     VLC_ADD_PLUGINS([dvdnav])
     VLC_ADD_CFLAGS([dvdnav],[`${DVDNAV_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([dvdnav],[`${DVDNAV_CONFIG} --libs`])
+    VLC_ADD_LIBS([dvdnav],[`${DVDNAV_CONFIG} --libs`])
   fi
 fi
 
@@ -2121,7 +2108,7 @@ then
       AC_CHECK_HEADERS(dshow.h,
       [ VLC_ADD_PLUGINS([dshow])
         VLC_ADD_CXXFLAGS([dshow],[])
-        VLC_ADD_LDFLAGS([dshow],[-lole32 -loleaut32 -luuid]) ])
+        VLC_ADD_LIBS([dshow],[-lole32 -loleaut32 -luuid]) ])
     AC_LANG_POP(C++)
   fi
 fi
@@ -2130,7 +2117,7 @@ dnl
 dnl  Windows DirectShow BDA access module
 dnl
 AC_ARG_ENABLE(bda,
-  [  --enable-bda          Win32 DirectShow BDA support (default enabled on Win32)])
+  [  --enable-bda            Win32 DirectShow BDA support (default enabled on Win32)])
 if test "${enable_bda}" != "no"
 then
   if test "${SYS}" = "mingw32" -o "${SYS}" = "cygwin"
@@ -2138,7 +2125,7 @@ then
       AC_CHECK_HEADERS(dshow.h,
       [ VLC_ADD_PLUGINS([bda])
         VLC_ADD_CXXFLAGS([bda],[])
-        VLC_ADD_LDFLAGS([bda],[-lstrmiids -lole32 -loleaut32 -luuid]) ])
+        VLC_ADD_LIBS([bda],[-lstrmiids -lole32 -loleaut32 -luuid]) ])
   fi
 fi
 
@@ -2147,7 +2134,7 @@ dnl
 dnl  OpenCV wrapper and example filters
 dnl
 AC_ARG_ENABLE(opencv,
-  [  --enable-opencv            OpenCV (computer vision) filter (default disabled)])
+  [  --enable-opencv         OpenCV (computer vision) filter (default disabled)])
 if test "${enable_opencv}" = "yes" -a "${CXX}" != "";
 then
   AC_ARG_WITH(opencv-tree,
@@ -2162,11 +2149,11 @@ then
       then
         AC_MSG_RESULT(yes)
         VLC_ADD_PLUGINS([opencv_wrapper])
-        VLC_ADD_LDFLAGS([opencv_wrapper],[-L${with_opencv_tree}/lib -lcv -lcxcore -lcvaux -lhighgui])
+        VLC_ADD_LIBS([opencv_wrapper],[-L${with_opencv_tree}/lib -lcv -lcxcore -lcvaux -lhighgui])
         VLC_ADD_CFLAGS([opencv_wrapper],[-I${with_opencv_tree}/cv/include -I${with_opencv_tree}/cxcore/include -I${with_opencv_tree}/cvaux/include -I${with_opencv_tree}/otherlibs/highgui])
         AC_LANG_PUSH(C++)
         VLC_ADD_PLUGINS([opencv_example])
-        VLC_ADD_LDFLAGS([opencv_example],[-L${with_opencv_tree}/lib -lcv -lcxcore -lcvaux -lhighgui])
+        VLC_ADD_LIBS([opencv_example],[-L${with_opencv_tree}/lib -lcv -lcxcore -lcvaux -lhighgui])
         VLC_ADD_CXXFLAGS([opencv_example],[-I${with_opencv_tree}/cv/include -I${with_opencv_tree}/cxcore/include -I${with_opencv_tree}/cvaux/include -I${with_opencv_tree}/otherlibs/highgui])
         AC_LANG_POP(C++)        
          else
@@ -2189,12 +2176,12 @@ AC_ARG_ENABLE(smb,
 if test "${enable_smb}" != "no"; then
   AC_CHECK_HEADERS(libsmbclient.h,
     [ VLC_ADD_PLUGINS([access_smb])
-      VLC_ADD_LDFLAGS([access_smb],[-lsmbclient]) ],
+      VLC_ADD_LIBS([access_smb],[-lsmbclient]) ],
     [ if test -n "${enable_smb}"; then
         AC_MSG_ERROR([cannot find libsmbclient headers])
      fi ])
   AC_CHECK_MEMBER([struct _SMBCCTX.close_fn],
-    AC_DEFINE([HAVE__SMBCCTX_CLOSE_FN], [1], [Define if samba has _SMBCCTX.close_fn]),,
+    AC_DEFINE([HAVE__SMBCCTX_CLOSE_FN], 1, [Define if samba has _SMBCCTX.close_fn]),,
     [#include <libsmbclient.h>])
 fi
 
@@ -2218,7 +2205,7 @@ then
           if test "${enable_sout}" != "no"; then
             VLC_ADD_PLUGINS([mux_ts])
           fi
-          VLC_ADD_LDFLAGS([mux_ts ts dvb],[-ldvbpsi]) ],
+          VLC_ADD_LIBS([mux_ts ts dvb],[-ldvbpsi]) ],
         [  AC_MSG_WARN([cannot find libdvbpsi headers]) ],
         [#if defined( HAVE_STDINT_H )
 #   include <stdint.h>
@@ -2247,7 +2234,7 @@ then
           VLC_ADD_BUILTINS([mux_ts])
         fi
         VLC_ADD_CPPFLAGS([mux_ts ts dvb],[-I${real_dvbpsi_tree}/src])
-        VLC_ADD_LDFLAGS([mux_ts ts dvb],[${real_dvbpsi_tree}/src/.libs/libdvbpsi.a])
+        VLC_ADD_LIBS([mux_ts ts dvb],[${real_dvbpsi_tree}/src/.libs/libdvbpsi.a])
       else
         dnl  The given libdvbpsi wasn't built
         AC_MSG_RESULT(no)
@@ -2275,7 +2262,7 @@ then
         VLC_ADD_PLUGINS([mux_ts])
       fi
       VLC_ADD_CPPFLAGS([mux_ts ts dvb],[${CPPFLAGS_test}])
-      VLC_ADD_LDFLAGS([mux_ts ts dvb],[${LDFLAGS_test} -ldvbpsi])
+      VLC_ADD_LIBS([mux_ts ts dvb],[${LDFLAGS_test} -ldvbpsi])
 
     ],[
       if test -n "${enable_dvbpsi}"
@@ -2288,7 +2275,7 @@ then
   esac
   AC_CHECK_LIB(dvbpsi, dvbpsi_GenSDTSections, [
     AC_DEFINE(HAVE_DVBPSI_SDT, 1, [Define if you have dvbpsi_GenSDTSections.])
-  ], [], [${LDFLAGS_ts}])
+  ], [], [${LIBS_ts}])
 
 fi
 
@@ -2314,10 +2301,10 @@ then
 fi
 
 dnl
-dnl  Video4Linux plugin
+dnl  Video4Linux2 plugin
 dnl
 AC_ARG_ENABLE(v4l2,
-  [  --enable-v4l2            Video4Linux2 input support (default disabled)])
+  [  --enable-v4l2           Video4Linux2 input support (default disabled)])
 if test "${enable_v4l2}" = "yes"
 then
   AC_ARG_WITH(v4l2,
@@ -2327,6 +2314,19 @@ then
     VLC_ADD_CPPFLAGS([v4l2],[-I${with_v4l2}/include])
   fi
 
+  AC_CHECK_HEADER(alsa/asoundlib.h, AC_CHECK_LIB(asound, main, have_v4l2_alsa="true", have_v4l2_alsa="false"),have_v4l2_alsa="false")
+  if test "${have_v4l2_alsa}" = "true"
+  then
+    CFLAGS="${CFLAGS_save}"
+    AC_TRY_COMPILE([#define ALSA_PCM_NEW_HW_PARAMS_API
+                    #define ALSA_PCM_NEW_SW_PARAMS_API
+                    #include <alsa/asoundlib.h>],
+       [snd_pcm_hw_params_get_period_time(0,0,0);],
+        AC_DEFINE(HAVE_ALSA_NEW_API, 1, Define if ALSA is at least rc4))
+    VLC_ADD_LDFLAGS([v4l2],[-lasound -lm -ldl])
+    AC_DEFINE(HAVE_ALSA, 1, Define if ALSA is present.)
+  fi
+
   CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_v4l2}"
   AC_CHECK_HEADERS(linux/videodev2.h, [
     VLC_ADD_PLUGINS([v4l2])
@@ -2348,15 +2348,19 @@ then
   if test "${with_videodev2}" != "no" -a -n "${with_videodev2}"
   then
     AC_DEFINE_UNQUOTED(VIDEODEV2_H_FILE, "${with_videodev2}", [Location of videodev2.h])
-  else
-    AC_DEFINE(VIDEODEV2_H_FILE, <linux/videodev2.h>, [Location of videodev2.h])
   fi
     
 
   AC_CACHE_CHECK([for new linux/videodev2.h],
       [new_linux_videodev2_h],
-      [AC_TRY_COMPILE([#include <sys/types.h>
-          #include VIDEODEV2_H_FILE],
+      [AC_TRY_COMPILE([
+          #include <sys/types.h>
+          #   ifdef VIDEODEV2_H_FILE
+         #   include VIDEODEV2_H_FILE
+         #   else
+         #   include <linux/videodev2.h>
+         #   endif
+         ],
           [struct v4l2_ext_controls ctrls; ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; ],
           new_linux_videodev2_h=yes,
           new_linux_videodev2_h=no)])
@@ -2373,7 +2377,7 @@ AC_ARG_ENABLE(gnomevfs,
 if test "${enable_gnomevfs}" = "yes" 
 then
   PKG_CHECK_MODULES(GNOMEVFS, gnome-vfs-2.0,
-    VLC_ADD_LDFLAGS([access_gnomevfs],[$GNOMEVFS_LIBS])
+    VLC_ADD_LIBS([access_gnomevfs],[$GNOMEVFS_LIBS])
     VLC_ADD_CPPFLAGS([access_gnomevfs],[$GNOMEVFS_CPPFLAGS])
     VLC_ADD_CFLAGS([access_gnomevfs],[$GNOMEVFS_CFLAGS])
     VLC_ADD_PLUGINS([access_gnomevfs]),
@@ -2391,13 +2395,13 @@ if test "${enable_libcdio}" != "no"
 then
   PKG_CHECK_MODULES(LIBCDIO, libcdio >= 0.78.2,
      have_libcdio=yes
-     AC_DEFINE(HAVE_LIBCDIO, []
+     AC_DEFINE(HAVE_LIBCDIO, 1
      [Define if you have libcdio 0.78.2 or greater installed]),
      [AC_MSG_WARN(CD Reading and information library not found)])
 
   PKG_CHECK_MODULES(VCDINFO, libvcdinfo >= 0.7.22,
      [have_libvcdinfo=yes
-     AC_DEFINE(HAVE_VCDINFO, []
+     AC_DEFINE(HAVE_VCDINFO, 1
      [Define if you have libvcdinfo 0.7.22 or greater installed])],
      [AC_MSG_WARN(VCD information library not found)])
 fi
@@ -2415,12 +2419,12 @@ if test "${enable_cddax}" = "yes"
 then
   if test "$have_libcdio" = "yes"
   then
-    AC_DEFINE(HAVE_CDDAX, [], [Define for the audio CD plugin using libcdio])
-    VLC_ADD_LDFLAGS([cddax],[$LIBCDIO_LIBS])
+    AC_DEFINE(HAVE_CDDAX, 1, [Define for the audio CD plugin using libcdio])
+    VLC_ADD_LIBS([cddax],[$LIBCDIO_LIBS])
     VLC_ADD_CFLAGS([cddax],[$LIBCDIO_CFLAGS])
     VLC_ADD_PLUGINS([cddax])
     PKG_CHECK_MODULES(LIBCDIO_PARANOIA, libcdio_paranoia >= 0.72, [
-    VLC_ADD_LDFLAGS([cddax],[$LIBCDIO_CDDA_LIBS $LIBCDIO_CDDA_LIBS $LIBCDIO_PARANOIA_LIBS])],
+    VLC_ADD_LIBS([cddax],[$LIBCDIO_CDDA_LIBS $LIBCDIO_CDDA_LIBS $LIBCDIO_PARANOIA_LIBS])],
     AC_MSG_WARN([CD Paranoia support disabled because no libcdio >= 0.72 found]))
   else 
     AC_MSG_WARN([cddax plugin disabled because ok libcdio library not found or disabled])
@@ -2430,8 +2434,8 @@ then
   if test "$enable_libcddb" != "no"; then
     PKG_CHECK_MODULES(LIBCDDB, libcddb >= 0.9.5, [
       HAVE_LIBCDDB=yes 
-      AC_DEFINE(HAVE_LIBCDDB, [], [Define this if you have libcddb installed])
-      VLC_ADD_LDFLAGS([cddax],[$LIBCDDB_LIBS])
+      AC_DEFINE(HAVE_LIBCDDB, 1, [Define this if you have libcddb installed])
+      VLC_ADD_LIBS([cddax],[$LIBCDDB_LIBS])
       VLC_ADD_CFLAGS([cddax],[$LIBCDDB_CFLAGS])
       ],
       [AC_MSG_WARN(new enough libcddb not found. CDDB access disabled) 
@@ -2447,7 +2451,7 @@ if test "${enable_vcdx}" = "yes"
 then
   if test "${have_libvcdinfo}" = "yes"
   then
-    VLC_ADD_LDFLAGS([vcdx],[$VCDINFO_LIBS])
+    VLC_ADD_LIBS([vcdx],[$VCDINFO_LIBS])
     VLC_ADD_CFLAGS([vcdx],[$VCDINFO_CFLAGS])
   else 
     AC_MSG_WARN([vcdx plugin disabled because ok libvcdinfo library not found or disabled])
@@ -2455,16 +2459,16 @@ then
   fi
 
   PKG_CHECK_MODULES(LIBCDIO, libiso9660 >= 0.72,
-   [VLC_ADD_LDFLAGS([vcdx],[$LIBISO9660_LIBS])
+   [VLC_ADD_LIBS([vcdx],[$LIBISO9660_LIBS])
     VLC_ADD_CFLAGS([vcdx],[$LIBISO9660_CFLAGS])],
     [AC_MSG_WARN([vcdx plugin disabled because ok libiso9660 library not found])
     HAVE_VCDX=no])
 
   if test "$have_libvcdinfo" = "yes"
   then
-    AC_DEFINE(HAVE_VCDX, []
+    AC_DEFINE(HAVE_VCDX, 1
     [Define for the VCD plugin using libcdio/libvcdinfo])
-    VLC_ADD_LDFLAGS([vcdx],[$VCDINFO_LIBS])
+    VLC_ADD_LIBS([vcdx],[$VCDINFO_LIBS])
     VLC_ADD_CFLAGS([vcdx],[$VCDINFO_CFLAGS])
     VLC_ADD_PLUGINS([vcdx])
   else 
@@ -2518,15 +2522,15 @@ then
   if test "${SYS}" = "darwin"
   then
     VLC_ADD_PLUGINS([vcd cdda])
-    VLC_ADD_LDFLAGS([vcd vcdx cdda cddax],[-framework IOKit -framework CoreFoundation])
-    VLC_ADD_LDFLAGS([vcdx cddax cdda],[-liconv])
+    VLC_ADD_LDFLAGS([vcd vcdx cdda cddax],[-Wl,-framework,IOKit,-framework,CoreFoundation])
+    VLC_ADD_LIBS([vcdx cddax cdda],[-liconv])
   fi
 
   if test "$enable_libcddb" != "no"; then
     PKG_CHECK_MODULES(LIBCDDB, libcddb >= 0.9.5, [
       HAVE_LIBCDDB=yes 
-      AC_DEFINE(HAVE_LIBCDDB, [], [Define this if you have libcddb installed])
-      VLC_ADD_LDFLAGS([cdda],[$LIBCDDB_LIBS])
+      AC_DEFINE(HAVE_LIBCDDB, 1, [Define this if you have libcddb installed])
+      VLC_ADD_LIBS([cdda],[$LIBCDDB_LIBS])
       VLC_ADD_CFLAGS([cdda],[$LIBCDDB_CFLAGS])
       ],:
       [AC_MSG_WARN(new enough libcddb not found. CDDB access disabled) 
@@ -2569,22 +2573,22 @@ if test "${enable_screen}" != "no"; then
   if test "${SYS}" = "darwin"; then
     AC_CHECK_HEADERS(ApplicationServices/ApplicationServices.h, [
       VLC_ADD_PLUGINS([screen])
-      VLC_ADD_LDFLAGS([screen],[-framework ApplicationServices])
+      VLC_ADD_LDFLAGS([screen],[-Wl,-framework,ApplicationServices])
     ])
   elif test "${SYS}" = "mingw32"; then
     VLC_ADD_PLUGINS([screen])
-    VLC_ADD_LDFLAGS([screen],[-lgdi32])
+    VLC_ADD_LIBS([screen],[-lgdi32])
   elif test "${SYS}" = "mingwce"; then
     CPPFLAGS="${CPPFLAGS_save}"
   elif test "${SYS}" = "beos"; then
     VLC_ADD_PLUGINS([screen])
     VLC_ADD_CXXFLAGS([screen],[])
-    VLC_ADD_LDFLAGS([screen],[-lbe])
+    VLC_ADD_LIBS([screen],[-lbe])
   else
     CPPFLAGS="${CPPFLAGS_save} ${X_CFLAGS}"
     AC_CHECK_HEADERS(X11/Xlib.h, [
       VLC_ADD_PLUGINS([screen])
-      VLC_ADD_LDFLAGS([screen],[${X_LIBS} ${X_PRE_LIBS} -lX11])
+      VLC_ADD_LIBS([screen],[${X_LIBS} ${X_PRE_LIBS} -lX11])
       VLC_ADD_CPPFLAGS([screen],[${X_CFLAGS}])
     ])
     CPPFLAGS="${CPPFLAGS_save}"
@@ -2634,7 +2638,7 @@ then
       if test "${enable_sout}" != "no"; then
         VLC_ADD_PLUGINS([mux_ogg])
       fi
-      VLC_ADD_LDFLAGS([ogg mux_ogg speex vorbis],[${real_ogg_tree}/src/.libs/libogg.a])
+      VLC_ADD_LIBS([ogg mux_ogg speex vorbis],[${real_ogg_tree}/src/.libs/libogg.a])
       VLC_ADD_CFLAGS([ogg mux_ogg speex vorbis],[-I${real_ogg_tree}/include])
     else
       dnl  The given ogg wasn't built
@@ -2648,7 +2652,7 @@ then
         if test "${enable_sout}" != "no"; then
           VLC_ADD_PLUGINS([mux_ogg])
         fi
-        VLC_ADD_LDFLAGS([ogg mux_ogg],[-logg])])
+        VLC_ADD_LIBS([ogg mux_ogg],[-logg])])
      ],[])
   fi
 fi
@@ -2687,11 +2691,11 @@ if test "${enable_mkv}" != "no" -a "${CXX}" != ""; then
               fi
               AC_CHECK_LIB(ebml_pic, main, [
                 VLC_ADD_PLUGINS([mkv])
-                VLC_ADD_LDFLAGS([mkv],[-lmatroska -lebml_pic])
+                VLC_ADD_LIBS([mkv],[-lmatroska -lebml_pic])
               ],
                 AC_CHECK_LIB(ebml, main, [
                   VLC_ADD_PLUGINS([mkv])
-                  VLC_ADD_LDFLAGS([mkv],[-lmatroska -lebml])
+                  VLC_ADD_LIBS([mkv],[-lmatroska -lebml])
                 ]) 
              )
             ],
@@ -2731,7 +2735,7 @@ then
       dnl  Use a custom mod
       AC_MSG_RESULT(${real_mod_tree}/src/.libs/libmodplug.a)
       VLC_ADD_PLUGINS([mod])
-      VLC_ADD_LDFLAGS([mod],[${real_mod_tree}/src/.libs/libmodplug.a -lstdc++])
+      VLC_ADD_LIBS([mod],[${real_mod_tree}/src/.libs/libmodplug.a -lstdc++])
       VLC_ADD_CXXFLAGS([mod],[-I${real_mod_tree}/include])
     else
       dnl  The given mod wasn't built
@@ -2742,7 +2746,7 @@ then
     AC_CHECK_HEADERS(libmodplug/modplug.h, [
       VLC_ADD_PLUGINS([mod])
       VLC_ADD_CXXFLAGS([mod],[])
-      VLC_ADD_LDFLAGS([mod],[-lmodplug -lstdc++])])
+      VLC_ADD_LIBS([mod],[-lmodplug -lstdc++])])
   fi
 fi
 
@@ -2755,7 +2759,7 @@ if test "${enable_mpc}" != "no"
 then
   AC_CHECK_HEADERS(mpcdec/mpcdec.h, [
     VLC_ADD_PLUGINS([mpc])
-    VLC_ADD_LDFLAGS([mpc],[-lmpcdec])])
+    VLC_ADD_LIBS([mpc],[-lmpcdec])])
 fi
 
 dnl
@@ -2783,7 +2787,7 @@ then
       dnl  Use a custom gme
       AC_MSG_RESULT(${real_gme_tree}/gme/libgme.a)
       VLC_ADD_PLUGINS([gme])
-      VLC_ADD_LDFLAGS([gme],[${real_gme_tree}/gme/libgme.a])
+      VLC_ADD_LIBS([gme],[${real_gme_tree}/gme/libgme.a])
       VLC_ADD_CXXFLAGS([gme],[-I${real_gme_tree}/gme])
     else
       dnl  The given gme wasn't built
@@ -2814,7 +2818,7 @@ then
   if test "${with_mad}" != "no" -a -n "${with_mad}"
   then
     VLC_ADD_CPPFLAGS([mpgatofixed32],[-I${with_mad}/include])
-    VLC_ADD_LDFLAGS([mpgatofixed32],[-L${with_mad}/lib])
+    VLC_ADD_LIBS([mpgatofixed32],[-L${with_mad}/lib])
   fi
 
   AC_ARG_WITH(mad-tree,
@@ -2834,11 +2838,11 @@ then
     then
       AC_MSG_RESULT(yes)
       VLC_ADD_CPPFLAGS([mpgatofixed32],[-I${real_mad_tree}])
-      VLC_ADD_LDFLAGS([mpgatofixed32],[-L${real_mad_tree}/.libs])
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_mpgatofixed32}"
+      VLC_ADD_LIBS([mpgatofixed32],[-L${real_mad_tree}/.libs])
+      LDFLAGS="${LDFLAGS_save} ${LIBS_mpgatofixed32}"
       AC_CHECK_LIB(mad, mad_bit_init, [
         VLC_ADD_BUILTINS([mpgatofixed32])
-        VLC_ADD_LDFLAGS([mpgatofixed32],[-lmad])
+        VLC_ADD_LIBS([mpgatofixed32],[-lmad])
         ],[ AC_MSG_ERROR([the specified tree hasn't been compiled ])
       ],[])
       LDFLAGS="${LDFLAGS_save}"
@@ -2848,12 +2852,12 @@ then
     fi
   else
     CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_mpgatofixed32}"
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_mpgatofixed32}"
+    LDFLAGS="${LDFLAGS_save} ${LIBS_mpgatofixed32}"
     AC_CHECK_HEADERS(mad.h, ,
       [ AC_MSG_ERROR([Could not find libmad on your system: you may get it from http://www.underbit.com/products/mad/. Alternatively you can use --disable-mad to disable the mad plugin.]) ])
     AC_CHECK_LIB(mad, mad_bit_init, [
       VLC_ADD_PLUGINS([mpgatofixed32])
-      VLC_ADD_LDFLAGS([mpgatofixed32],[-lmad])],
+      VLC_ADD_LIBS([mpgatofixed32],[-lmad])],
       [ AC_MSG_ERROR([Cannot find libmad library...]) ])
     CPPFLAGS="${CPPFLAGS_save}"
     LDFLAGS="${LDFLAGS_save}"
@@ -2863,16 +2867,22 @@ fi
 dnl
 dnl   libid3tag support (FIXME!!! doesn't work with new input)
 dnl
-AC_CHECK_HEADERS(id3tag.h, [
-  AC_CHECK_HEADERS(zlib.h, [
-    VLC_ADD_LDFLAGS([id3tag],[-lid3tag -lz])
-    VLC_ADD_PLUGINS([id3tag])]) ])
+AC_ARG_ENABLE( id3tag,
+  [  --disable-id3tag id3tag metadata reader plugin (default enabled)])
+AS_IF([test "${enable_id3tag}" != "no"], [
+  AC_CHECK_HEADERS(id3tag.h, [
+    AC_CHECK_HEADERS(zlib.h, [
+      VLC_ADD_LIBS([id3tag],[-lid3tag -lz])
+      VLC_ADD_PLUGINS([id3tag])
+    ])
+  ])
+])
 
 dnl
 dnl  ffmpeg decoder/demuxer plugin
 dnl
-dnl we try to find ffmpeg using : 1- given tree 2- ffmpeg-config, 3- pkg-config
-dnl                            4- default place, 
+dnl we try to find ffmpeg using : 1- given tree, 2- pkg-config
+dnl                               3- default place,
 
 AC_ARG_ENABLE(ffmpeg,
 [  --enable-ffmpeg         ffmpeg codec (default enabled)])
@@ -2885,24 +2895,24 @@ dnl Those options have to be here because the .pc can be bogus for ffmpeg previo
    [    --with-ffmpeg-mp3lame specify if ffmpeg has been compiled with mp3lame support],
    [
      if test "$with_ffmpeg_mp3lame" = "yes";   then
-       VLC_ADD_LDFLAGS([ffmpeg],[-lmp3lame])
+        VLC_ADD_LIBS([ffmpeg],[-lmp3lame])
      fi])
 
  AC_ARG_WITH(ffmpeg-faac,
    [    --with-ffmpeg-faac    specify if ffmpeg has been compiled with faac support],
    [
      if test "$with_ffmpeg_faac" = "yes"; then
-       VLC_ADD_LDFLAGS([ffmpeg],[-lfaac])
+        VLC_ADD_LIBS([ffmpeg],[-lfaac])
      fi])
 
  AC_ARG_WITH(ffmpeg-dts,
    [    --with-ffmpeg-dts     specify if ffmpeg has been compiled with dts support],
    [
      if test "$with_ffmpeg_dts" = "yes"; then
-             LDFLAGS="${LDFLAGS_save} ${LDFLAGS_ffmpeg}"
+             LDFLAGS="${LDFLAGS_save} ${LDFLAGS_ffmpeg} ${LIBS_ffmpeg}"
              AC_CHECK_LIB(dts_pic, dts_free, 
-               [ VLC_ADD_LDFLAGS([ffmpeg],[-ldts_pic]) ],
-               [ VLC_ADD_LDFLAGS([ffmpeg],[-ldts]) ])
+               [ VLC_ADD_LIBS([ffmpeg],[-ldts_pic]) ],
+               [ VLC_ADD_LIBS([ffmpeg],[-ldts]) ])
              LDFLAGS="${LDFLAGS_save}"
      fi])
 
@@ -2910,28 +2920,56 @@ dnl Those options have to be here because the .pc can be bogus for ffmpeg previo
    [    --with-ffmpeg-vorbis    specify if ffmpeg has been compiled with vorbis support],
    [
      if test "$with_ffmpeg_vorbis" = "yes"; then
-        VLC_ADD_LDFLAGS([ffmpeg],[-lvorbisenc -lvorbis])
+        VLC_ADD_LIBS([ffmpeg],[-lvorbisenc -lvorbis])
      fi])
 
  AC_ARG_WITH(ffmpeg-theora,
    [    --with-ffmpeg-theora    specify if ffmpeg has been compiled with theora support],
    [
      if test "$with_ffmpeg_theora" = "yes"; then
-        VLC_ADD_LDFLAGS([ffmpeg],[-ltheora])
+        VLC_ADD_LIBS([ffmpeg],[-ltheora])
      fi])
 
  AC_ARG_WITH(ffmpeg-ogg,
    [    --with-ffmpeg-ogg    specify if ffmpeg has been compiled with ogg support],
    [
      if test "$with_ffmpeg_ogg" = "yes"; then
-        VLC_ADD_LDFLAGS([ffmpeg],[-logg])
+        VLC_ADD_LIBS([ffmpeg],[-logg])
      fi])
 
  AC_ARG_WITH(ffmpeg-zlib,
    [    --with-ffmpeg-zlib    specify if ffmpeg has been compiled with zlib support],
    [
      if test "$with_ffmpeg_zlib" = "yes"; then
-               VLC_ADD_LDFLAGS([ffmpeg],[-lz])
+        VLC_ADD_LIBS([ffmpeg],[-lz])
+     fi])
+
+ AC_ARG_WITH(ffmpeg-amrnb,
+   [    --with-ffmpeg-amrnb specify if ffmpeg has been compiled with libamrnb support],
+   [
+     if test "$with_ffmpeg_amrnb" = "yes";     then
+        VLC_ADD_LIBS([ffmpeg],[-lamrnb])
+     fi])
+
+ AC_ARG_WITH(ffmpeg-amrwb,
+   [    --with-ffmpeg-amrwb specify if ffmpeg has been compiled with libamrwb support],
+   [
+     if test "$with_ffmpeg_amrwb" = "yes";     then
+        VLC_ADD_LIBS([ffmpeg],[-lamrwb])
+     fi])
+
+ AC_ARG_WITH(ffmpeg-x264,
+   [    --with-ffmpeg-x264 specify if ffmpeg has been compiled with libx264 support],
+   [
+     if test "$with_ffmpeg_x264" = "yes";      then
+        VLC_ADD_LIBS([ffmpeg],[-lx264])
+     fi])
+
+ AC_ARG_WITH(ffmpeg-a52,
+   [    --with-ffmpeg-a52 specify if ffmpeg has been compiled with liba52 support],
+   [
+     if test "$with_ffmpeg_a52" = "yes";       then
+        VLC_ADD_LIBS([ffmpeg],[-la52])
      fi])
 
  dnl
@@ -2955,9 +2993,9 @@ dnl Those options have to be here because the .pc can be bogus for ffmpeg previo
    fi
    if ! fgrep -s "pp_get_context" "${real_ffmpeg_tree}/libavcodec/libavcodec.a"; then
      if test -f "${real_ffmpeg_tree}/libavcodec/libpostproc/libpostproc.a"; then
-       VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavcodec/libpostproc ${real_ffmpeg_tree}/libavcodec/libpostproc/libpostproc.a])       
+       VLC_ADD_LIBS([ffmpeg],[-L${real_ffmpeg_tree}/libavcodec/libpostproc ${real_ffmpeg_tree}/libavcodec/libpostproc/libpostproc.a])  
      elif test -f "${real_ffmpeg_tree}/libpostproc/libpostproc.a"; then 
-       VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libpostproc ${real_ffmpeg_tree}/libpostproc/libpostproc.a])
+        VLC_ADD_LIBS([ffmpeg],[-L${real_ffmpeg_tree}/libpostproc ${real_ffmpeg_tree}/libpostproc/libpostproc.a])
         VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}])
      else
        dnl  The given libavcodec wasn't built with --enable-pp
@@ -2968,90 +3006,45 @@ dnl Those options have to be here because the .pc can be bogus for ffmpeg previo
    dnl  Use a custom libffmpeg
    AC_MSG_RESULT(${real_ffmpeg_tree}/libavcodec/libavcodec.a)
 
-   if fgrep -s "CONFIG_ZLIB=yes" "${real_ffmpeg_tree}/config.mak"; then
-     if test "${with_ffmpeg_zlib}" != "yes"; then
-       VLC_ADD_LDFLAGS([ffmpeg],[-lz])
-     fi
-   fi
-   if fgrep -s "CONFIG_MP3LAME=yes" "${real_ffmpeg_tree}/config.mak"; then
-     if test "${with_ffmpeg_mp3lame}" != "yes"; then
-       VLC_ADD_LDFLAGS([ffmpeg],[-lmp3lame])
-     fi
-   fi
-   if fgrep -s "CONFIG_FAAC=yes" "${real_ffmpeg_tree}/config.mak"; then
-     if test "${with_ffmpeg_faac}" != "yes"; then
-       VLC_ADD_LDFLAGS([ffmpeg],[-lfaac])
-     fi
-   fi
-   if fgrep -s "CONFIG_DTS=yes" "${real_ffmpeg_tree}/config.mak"; then
-     if test "${with_ffmpeg_dts}" != "yes"; then
-       LDFLAGS="${LDFLAGS_save} ${LDFLAGS_ffmpeg}"
-       AC_CHECK_LIB(dts_pic, dts_free, 
-         [ VLC_ADD_LDFLAGS([ffmpeg],[-ldts_pic]) ],
-         [ VLC_ADD_LDFLAGS([ffmpeg],[-ldts]) ])
-       LDFLAGS="${LDFLAGS_save}"
-     fi
-   fi
-   if fgrep -s "CONFIG_VORBIS=yes" "${real_ffmpeg_tree}/config.mak"; then
-     VLC_ADD_LDFLAGS([ffmpeg],[-lvorbis -lvorbisenc])
-   fi
-   if fgrep -s "CONFIG_FAAD=yes" "${real_ffmpeg_tree}/config.mak"; then
-     VLC_ADD_LDFLAGS([ffmpeg],[-lfaad])
-   fi
-   if fgrep -s "CONFIG_XVID=yes" "${real_ffmpeg_tree}/config.mak"; then
-     VLC_ADD_LDFLAGS([ffmpeg],[-lxvidcore])
-   fi
+   dnl Use pkg-config to look for the ldflags in libav*-uninstalled.pc
+   PKG_CONFIG_PATH_save="$PKG_CONFIG_PATH"
+   PKG_CONFIG_LIBDIR_save="$PKG_CONFIG_LIBDIR"
+   export PKG_CONFIG_PATH=""
+   export PKG_CONFIG_LIBDIR="${real_ffmpeg_tree}"
+
+   PKG_CHECK_MODULES( [FFMPEG],[libavcodec libavformat libpostproc], [
+        VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher], ${FFMPEG_CFLAGS})
+        VLC_ADD_LIBS([ffmpeg stream_out_switcher], ${FFMPEG_LIBS})]
+      ,[])
+   AS_IF([test -n "${PKG_CONFIG_PATH_save}"],[
+         export PKG_CONFIG_PATH="${PKG_CONFIG_PATH_save}"
+   ],[
+        unset PKG_CONFIG_PATH
+   ])
+   AS_IF([test -n "${PKG_CONFIG_LIBDIR_save}"],[
+        export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR_save}"
+   ],[
+        unset PKG_CONFIG_LIBDIR
+   ])
 
    VLC_ADD_BUILTINS([ffmpeg])
    if test "${enable_sout}" != "no" -a "${enable_switcher}" = "yes" ; then
      VLC_ADD_BUILTINS([stream_out_switcher])
    fi
 
-   if test -f "${real_ffmpeg_tree}/libavutil/libavutil.a"; then
-     VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavutil ${real_ffmpeg_tree}/libavutil/libavutil.a])
-     VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libavutil])
-   fi
-
-   VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavcodec ${real_ffmpeg_tree}/libavcodec/libavcodec.a])
-   VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libavcodec])
-
-   if test -f "${real_ffmpeg_tree}/libavformat/libavformat.a"; then
-     AC_DEFINE(HAVE_LIBAVFORMAT_TREE, 1, [Define if you have ffmpeg's libavformat.])
-     VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavformat ${real_ffmpeg_tree}/libavformat/libavformat.a])
-     VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libavformat])
-   fi
-
    if test -f "${real_ffmpeg_tree}/libswscale/libswscale.a"; then
      AC_DEFINE(HAVE_LIBSWSCALE_TREE, 1, [Define if you have ffmpeg's libswscale.])
-     VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libswscale ${real_ffmpeg_tree}/libswscale/libswscale.a])
+     VLC_ADD_LIBS([ffmpeg],[-L${real_ffmpeg_tree}/libswscale ${real_ffmpeg_tree}/libswscale/libswscale.a])
      VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libswscale])
    fi
-else    
-    
-dnl Look for a ffmpeg-config (we are on debian )
-  FFMPEG_PATH="${PATH}"
-  AC_ARG_WITH(ffmpeg-config-path,
-    [    --with-ffmpeg-config-path=PATH ffmpeg-config path (default search in \$PATH)],
-    [ if test "${with_ffmpeg_config_path}" != "no"
-      then
-        FFMPEG_PATH="${with_ffmpeg_config_path}"
-      fi ])
-  AC_PATH_PROG(FFMPEG_CONFIG, ffmpeg-config, no, ${FFMPEG_PATH})
-  if test "${FFMPEG_CONFIG}" != "no"
-  then
-    AC_CHECK_HEADERS(ffmpeg/avcodec.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avcodec.h.])] )
-    AC_CHECK_HEADERS(ffmpeg/avformat.h)
-    AC_CHECK_HEADERS(ffmpeg/avutil.h)
-    AC_CHECK_HEADERS(postproc/postprocess.h, [], [AC_MSG_ERROR([Missing header file postproc/postprocess.h.])] )
-    VLC_ADD_PLUGINS([ffmpeg])
-    if test "${enable_sout}" != "no" -a "${enable_switcher}" = "yes"; then
-        VLC_ADD_PLUGINS([stream_out_switcher])
+
+    if test -f "${real_ffmpeg_tree}/libavformat/libavformat.a"; then
+      AC_DEFINE(HAVE_LIBAVFORMAT_TREE, 1, [Define if you have ffmpeg's libavformat.])
+      VLC_ADD_LIBS([ffmpeg],[-L${real_ffmpeg_tree}/libavformat -lavformat -lz])
+      VLC_ADD_CPPFLAGS([ffmpeg],[-I${real_ffmpeg_tree}/libavformat])
     fi
-    VLC_ADD_CFLAGS([ffmpeg stream_out_switcher],[`${FFMPEG_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([ffmpeg stream_out_switcher],[`${FFMPEG_CONFIG} --plugin-libs avcodec avformat postproc`])
- else
+else
+
 
 dnl Trying with pkg-config
    PKG_CHECK_MODULES(FFMPEG,[libavcodec, libavformat],
@@ -3060,12 +3053,12 @@ dnl Trying with pkg-config
      CPPFLAGS="${CPPFLAGS} ${FFMPEG_CFLAGS}"
      CFLAGS="${CFLAGS} ${FFMPEG_CFLAGS}"
      AC_CHECK_HEADERS(ffmpeg/avcodec.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avcodec.h.])] )
-     AC_CHECK_HEADERS(ffmpeg/avformat.h)
-     AC_CHECK_HEADERS(ffmpeg/avutil.h)
+     AC_CHECK_HEADERS(ffmpeg/avformat.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avformat.h.])] )
+     AC_CHECK_HEADERS(ffmpeg/avutil.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avutil.h.])] )
      dnl newer ffmpeg have a separate libpostproc
      PKG_CHECK_MODULES(POSTPROC, libpostproc,[
        VLC_ADD_CFLAGS([ffmpeg],[${POSTPROC_CFLAGS}]) 
-       VLC_ADD_LDFLAGS([ffmpeg],[${POSTPROC_LIBS}]) 
+       VLC_ADD_LIBS([ffmpeg],[${POSTPROC_LIBS}]) 
        ],[ true ])
      CPPFLAGS="${CPPFLAGS} ${POSTPROC_CFLAGS}"
      CFLAGS="${CFLAGS} ${POSTPROC_CFLAGS}"
@@ -3083,58 +3076,58 @@ dnl Trying with pkg-config
         fi
      fi
      VLC_ADD_CFLAGS([ffmpeg stream_out_switcher],[${FFMPEG_CFLAGS}])
-     VLC_ADD_LDFLAGS([ffmpeg stream_out_switcher],[${FFMPEG_LIBS}])
+     VLC_ADD_LIBS([ffmpeg stream_out_switcher],[${FFMPEG_LIBS}])
+
      dnl even newer ffmpeg has a libswscale
-     PKG_CHECK_MODULES(SWSCALE, libswscale,[
-       VLC_ADD_CFLAGS([ffmpeg],[${SWSCALE_CFLAGS}]) 
-       VLC_ADD_LDFLAGS([ffmpeg],[${SWSCALE_LIBS}]) 
+     PKG_CHECK_MODULES(SWSCALE,[libswscale],[
+       VLC_ADD_CFLAGS([ffmpeg],[${SWSCALE_CFLAGS}])
+       VLC_ADD_LIBS([ffmpeg],[${SWSCALE_LIBS}])
+dnl    AC_CHECK_HEADERS(ffmpeg/swscale.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/swscale.h.])])
        AC_CHECK_LIB(swscale, sws_getContext,
-         [AC_CHECK_HEADERS(ffmpeg/swscale.h)],[])
+         [AC_CHECK_HEADERS([ffmpeg/avutil.h, ffmpeg/swscale.h])],[],[-lavutil -lm])
        ],[ true ])
      VLC_RESTORE_FLAGS
     ],[
-     
+
     dnl
     dnl last chance: at the default place
     dnl
       CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_ffmpeg}"
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_ffmpeg}"
+      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_ffmpeg} ${LIBS_ffmpeg}"
       AC_CHECK_HEADERS(ffmpeg/avcodec.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avcodec.h.])] )
       AC_CHECK_HEADERS(ffmpeg/avformat.h)
       AC_CHECK_HEADERS(ffmpeg/avutil.h)
       AC_CHECK_HEADERS(postproc/postprocess.h, [], [AC_MSG_ERROR([Missing header file postproc/postprocess.h.])] )
 
       AC_CHECK_LIB(avutil, av_crc_init, [
-        VLC_ADD_LDFLAGS([ffmpeg],[-lavutil])
+        VLC_ADD_LIBS([ffmpeg],[-lavutil])
         LDAVUTIL="-lavutil"])
 
       AC_CHECK_LIB(avcodec, avcodec_init, [
         VLC_ADD_BUILTINS([ffmpeg])
-        VLC_ADD_LDFLAGS([ffmpeg],[-lavcodec])
+        VLC_ADD_LIBS([ffmpeg],[-lavcodec])
         if test "${enable_sout}" != "no" -a "${enable_switcher}" = "yes"; then
             VLC_ADD_BUILTINS([stream_out_switcher])
         fi],
          [ AC_MSG_ERROR([Could not find ffmpeg on your system: you may get it from http://ffmpeg.sf.net/ (svn version is recommended). Alternatively you can use --disable-ffmpeg to disable the ffmpeg plugins.]) ], [$LDAVUTIL])
 
-      
       AC_CHECK_LIB(postproc, pp_postprocess, [
-        VLC_ADD_LDFLAGS([ffmpeg],[-lpostproc])],
-       AC_MSG_ERROR([Could not find libpostproc inside FFmpeg. You should configure FFmpeg with --enable-gpl --enable-pp.]),
-       [$LDAVUTIL])
+        VLC_ADD_LIBS([ffmpeg],[-lpostproc])],
+      AC_MSG_ERROR([Could not find libpostproc inside FFmpeg. You should configure FFmpeg with --enable-gpl --enable-pp.]),
+        [$LDAVUTIL])
 
       AC_CHECK_LIB(avformat, av_open_input_stream, [
-        VLC_ADD_LDFLAGS([ffmpeg],[-lavformat -lz]) ], [], [-lavcodec -lz $LDAVUTIL])
+        VLC_ADD_LIBS([ffmpeg],[-lavformat -lz]) ], [], [-lavcodec -lz $LDAVUTIL])
       LDFLAGS="${LDFLAGS_save}"
       CPPFLAGS="${CPPFLAGS_save}"
 
       AC_CHECK_LIB(swscale, sws_getContext, [
         AC_CHECK_HEADERS(ffmpeg/swscale.h)
-        VLC_ADD_LDFLAGS([ffmpeg],[-lswscale]) ], [], [-lavcodec $LDAVUTIL])
+        VLC_ADD_LIBS([ffmpeg],[-lswscale]) ], [], [-lavcodec $LDAVUTIL])
       LDFLAGS="${LDFLAGS_save}"
       CPPFLAGS="${CPPFLAGS_save}"
     ])
   fi
- fi 
 fi
 
 dnl
@@ -3165,16 +3158,16 @@ then
     dnl  Use a custom libffmpeg
     AC_MSG_RESULT(${real_ffmpeg_tree}/libavcodec/libavcodecaltivec.a)
     VLC_ADD_BUILTINS([ffmpegaltivec])
-    VLC_ADD_LDFLAGS([ffmpegaltivec],[-L${real_ffmpeg_tree}/libavcodec -lavcodecaltivec])
+    VLC_ADD_LIBS([ffmpegaltivec],[-L${real_ffmpeg_tree}/libavcodec -lavcodecaltivec])
     VLC_ADD_CPPFLAGS([ffmpeg],[-DNO_ALTIVEC_IN_FFMPEG])
     VLC_ADD_CPPFLAGS([ffmpegaltivec],[-I${real_ffmpeg_tree}/libavcodec -I${real_ffmpeg_tree}/libavformat])
 
     if test -f "${real_ffmpeg_tree}/libavformat/libavformat.a"; then
       AC_DEFINE(HAVE_LIBAVFORMAT_TREE, 1, [Define if you have ffmpeg's libavformat.])
-      VLC_ADD_LDFLAGS([ffmpegaltivec],[-L${real_ffmpeg_tree}/libavformat -lavformataltivec -lz])
+      VLC_ADD_LIBS([ffmpegaltivec],[-L${real_ffmpeg_tree}/libavformat -lavformataltivec -lz])
       VLC_ADD_CPPFLAGS([ffmpegaltivec],[-I${real_ffmpeg_tree}/libavformat])
     fi
-    VLC_ADD_LDFLAGS([stream_out_switcher],[-L${real_ffmpeg_tree}/libavcodec])
+    VLC_ADD_LIBS([stream_out_switcher],[-L${real_ffmpeg_tree}/libavcodec])
     VLC_ADD_CPPFLAGS([stream_out_switcher],[-I${real_ffmpeg_tree}/libavcodec -I${real_ffmpeg_tree}/libavformat])
   fi
 fi
@@ -3203,7 +3196,7 @@ then
       dnl  Use a custom faad
       AC_MSG_RESULT(${real_faad_tree}/libfaad/.libs/libfaad.a)
       VLC_ADD_BUILTINS([faad])
-      VLC_ADD_LDFLAGS([faad],[${real_faad_tree}/libfaad/.libs/libfaad.a])
+      VLC_ADD_LIBS([faad],[${real_faad_tree}/libfaad/.libs/libfaad.a])
       VLC_ADD_CPPFLAGS([faad],[-I${real_faad_tree}/include])
     else
       dnl  The given libfaad wasn't built
@@ -3212,15 +3205,15 @@ then
     fi
   else
     CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_faad}"
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_faad}"
+    LDFLAGS="${LDFLAGS_save} ${LIBS_faad}"
     AC_CHECK_HEADERS(faad.h, ,
       [ AC_MSG_ERROR([Cannot find development headers for libfaad...]) ])
     AC_CHECK_LIB(faad, faacDecOpen, [
       VLC_ADD_PLUGINS([faad])
-      VLC_ADD_LDFLAGS([faad],[-lfaad]) ],
+      VLC_ADD_LIBS([faad],[-lfaad]) ],
       AC_CHECK_LIB(faad, NeAACDecOpen, [
         VLC_ADD_PLUGINS([faad])
-        VLC_ADD_LDFLAGS([faad],[-lfaad]) ],
+        VLC_ADD_LIBS([faad],[-lfaad]) ],
         [ AC_MSG_ERROR([Cannot find libfaad library...]) ]))
     LDFLAGS="${LDFLAGS_save}"
     CPPFLAGS="${CPPFLAGS_save}"
@@ -3251,7 +3244,7 @@ then
       dnl  Use a custom twolame
       AC_MSG_RESULT(${real_twolame_tree}/libtwolame/.libs/libtwolame.a)
       VLC_ADD_BUILTINS([twolame])
-      VLC_ADD_LDFLAGS([twolame],[${real_twolame_tree}/libtwolame/.libs/libtwolame.a])
+      VLC_ADD_LIBS([twolame],[${real_twolame_tree}/libtwolame/.libs/libtwolame.a])
       VLC_ADD_CPPFLAGS([twolame],[-I${real_twolame_tree}/libtwolame -DLIBTWOLAME_STATIC])
     else
       dnl  The given libtwolame wasn't built
@@ -3260,13 +3253,13 @@ then
     fi
   else
     CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_twolame} -DLIBTWOLAME_STATIC"
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_twolame}"
+    LDFLAGS="${LDFLAGS_save} ${LIBS_twolame}"
     AC_CHECK_HEADERS(twolame.h, ,
       [ AC_MSG_ERROR([Cannot find development header for libtwolame...]) ])
     AC_CHECK_LIB(twolame, twolame_init, [
       VLC_ADD_PLUGINS([twolame])
       VLC_ADD_CPPFLAGS([twolame],[-DLIBTWOLAME_STATIC])
-      VLC_ADD_LDFLAGS([twolame],[-ltwolame]) ],
+      VLC_ADD_LIBS([twolame],[-ltwolame]) ],
         [ AC_MSG_ERROR([Cannot find libtwolame library...]) ])
     LDFLAGS="${LDFLAGS_save}"  
     CPPFLAGS="${CPPFLAGS_save}"
@@ -3286,7 +3279,7 @@ then
   else
   AC_CHECK_HEADERS(QuickTime/QuickTime.h,
     [ VLC_ADD_BUILTINS([quicktime])
-      VLC_ADD_LDFLAGS([quicktime],[-framework QuickTime -framework Carbon])
+      VLC_ADD_LDFLAGS([quicktime],[-Wl,-framework,QuickTime,-framework,Carbon])
     ], [ AC_MSG_ERROR([cannot find QuickTime headers]) ])
   fi
 fi
@@ -3313,11 +3306,11 @@ dnl
 dnl MP4 module
 dnl
 AC_CHECK_HEADERS(zlib.h, [
-  VLC_ADD_LDFLAGS([mp4 skins2 sap mkv gme],[-lz])
+  VLC_ADD_LIBS([mp4 skins2 sap mkv gme],[-lz])
 ] )
 
 AC_CHECK_HEADERS(sysfs/libsysfs.h, [
-  VLC_ADD_LDFLAGS([mp4 mkv],[-lsysfs])
+  VLC_ADD_LIBS([mp4 mkv],[-lsysfs])
 ] )
 
 dnl
@@ -3328,7 +3321,7 @@ AC_ARG_ENABLE(libtar,
 
 AS_IF([test "${enable_libtar}" != "no"],[
   AC_CHECK_HEADERS(libtar.h, [
-    VLC_ADD_LDFLAGS([skins2],[-ltar])
+    VLC_ADD_LIBS([skins2],[-ltar])
   ] )
 ])
 
@@ -3358,16 +3351,16 @@ then
     then
       AC_MSG_RESULT(yes)
       VLC_ADD_CPPFLAGS([a52tofloat32],[-I${real_a52_tree}])
-      VLC_ADD_LDFLAGS([a52tofloat32],[-L${real_a52_tree}/liba52/.libs])
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_a52tofloat32}"
+      VLC_ADD_LIBS([a52tofloat32],[-L${real_a52_tree}/liba52/.libs])
+      LDFLAGS="${LDFLAGS_save} ${LIBS_a52tofloat32}"
       AC_CHECK_LIB(a52, a52_free, [
         VLC_ADD_BUILTINS([a52tofloat32])
         VLC_ADD_CPPFLAGS([a52tofloat32],[-DUSE_A52DEC_TREE])
-        VLC_ADD_LDFLAGS([a52tofloat32],[-la52])
+        VLC_ADD_LIBS([a52tofloat32],[-la52])
         ],[
         if test -f ${real_a52_tree}/liba52/.libs/liba52.a
         then
-          AC_MSG_ERROR([make sure you have at least a52dec-0.7.3])
+          AC_MSG_ERROR([make sure you have at least a52dec-0.7.3 ($real_a52_tree)])
         else
           AC_MSG_ERROR([the specified tree hasn't been compiled])
         fi
@@ -3387,11 +3380,11 @@ then
       CPPFLAGS_test="-I${with_a52}/include"
     fi
     CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_test} ${CPPFLAGS_a52tofloat32}"
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_test} ${LDFLAGS_a52tofloat32}"
+    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_test} ${LIBS_a52tofloat32}"
     AC_CHECK_HEADERS(a52dec/a52.h, [
       AC_CHECK_LIB(a52, a52_free, [
         VLC_ADD_PLUGINS([a52tofloat32])
-        VLC_ADD_LDFLAGS([a52tofloat32],[${LDFLAGS_test} -la52])
+        VLC_ADD_LIBS([a52tofloat32],[${LDFLAGS_test} -la52])
         VLC_ADD_CPPFLAGS([a52tofloat32],[${CPPFLAGS_test}])
       ],[
         AC_MSG_ERROR([Could not find liba52 on your system: you may get it from http://liba52.sf.net/. Alternatively you can use --disable-a52 to disable the a52 plugin.])
@@ -3436,7 +3429,7 @@ AS_IF([test "${enable_dca}" != "no"], [
     AC_MSG_CHECKING(for libdca in ${real_dca_tree})
     AS_IF([test -f "${real_dca_tree}/libdca/.libs/libdca.a"], [
       AC_MSG_RESULT(yes)
-      VLC_ADD_LDFLAGS([dtstofloat32],[${real_dca_tree}/libdca/.libs/libdca.a])
+      VLC_ADD_LIBS([dtstofloat32],[${real_dca_tree}/libdca/.libs/libdca.a])
       AS_IF([test -f "${real_dca_tree}/include/dca.h"], [
         VLC_ADD_CPPFLAGS([dtstofloat32],[-I${real_dca_tree}/include])
       ], [
@@ -3450,7 +3443,7 @@ AS_IF([test "${enable_dca}" != "no"], [
     PKG_CHECK_MODULES([DCA], [libdca >= 0.0.5], [
       VLC_ADD_PLUGINS([dtstofloat32])
       VLC_ADD_CPPFLAGS([dtstofloat32], [${DCA_CFLAGS}])
-      VLC_ADD_LDFLAGS([dtstofloat32], [${DCA_LIBS}])
+      VLC_ADD_LIBS([dtstofloat32], [${DCA_LIBS}])
     ], [
       AS_IF([test "x${enable_dca}" != "x"], [
         AC_MSG_ERROR([${DCA_PKG_ERRORS}])
@@ -3482,7 +3475,7 @@ then
     then
       dnl  Use a custom flac
       AC_MSG_RESULT(${real_flac_tree}/src/libFLAC/.libs/libFLAC.a)
-      VLC_ADD_LDFLAGS([flac],[${real_flac_tree}/src/libFLAC/.libs/libFLAC.a])
+      VLC_ADD_LIBS([flac],[${real_flac_tree}/src/libFLAC/.libs/libFLAC.a])
       VLC_ADD_CFLAGS([flac],[-I${real_flac_tree}/include])
       AC_DEFINE(HAVE_FLAC_STREAM_DECODER_H, 1, [Define if you have FLAC])
     else
@@ -3492,7 +3485,7 @@ then
     fi
   else
     AC_CHECK_HEADERS(FLAC/stream_decoder.h, [
-      VLC_ADD_LDFLAGS([flac],[-lFLAC])
+      VLC_ADD_LIBS([flac],[-lFLAC -logg])
      ],[])
   fi
 fi
@@ -3521,7 +3514,7 @@ then
       dnl  Use a custom libmpeg2
       AC_MSG_RESULT(${real_libmpeg2_tree}/libmpeg2/.libs/libmpeg2.a)
       VLC_ADD_BUILTINS([libmpeg2])
-      VLC_ADD_LDFLAGS([libmpeg2],[-L${real_libmpeg2_tree}/libmpeg2/.libs -lmpeg2])
+      VLC_ADD_LIBS([libmpeg2],[-L${real_libmpeg2_tree}/libmpeg2/.libs -lmpeg2])
       VLC_ADD_CFLAGS([libmpeg2],[-I${real_libmpeg2_tree}/include])
       eval "`cd ${real_libmpeg2_tree}/include && ln -sf . mpeg2dec 2>/dev/null`"
     else
@@ -3541,7 +3534,7 @@ then
          #endif],
         [AC_MSG_RESULT([yes])
           VLC_ADD_PLUGINS([libmpeg2])
-          VLC_ADD_LDFLAGS([libmpeg2],[-lmpeg2])],
+          VLC_ADD_LIBS([libmpeg2],[-lmpeg2])],
         [AC_MSG_RESULT([no])
           AC_MSG_ERROR([Your libmpeg2 is too old (you need the cvs version): you may get a more recent one from http://libmpeg2.sf.net/. Alternatively you can use --disable-libmpeg2 to disable the libmpeg2 plugin.])])],
 
@@ -3574,7 +3567,7 @@ then
       dnl  Use a custom vorbis 
       AC_MSG_RESULT(${real_vorbis_tree}/lib/.libs/libvorbis.a)
       VLC_ADD_PLUGINS([vorbis])
-      VLC_ADD_LDFLAGS([vorbis],[${real_vorbis_tree}/lib/.libs/libvorbis.a ${real_vorbis_tree}/lib/.libs/libvorbisenc.a])
+      VLC_ADD_LIBS([vorbis],[${real_vorbis_tree}/lib/.libs/libvorbis.a ${real_vorbis_tree}/lib/.libs/libvorbisenc.a])
       VLC_ADD_CFLAGS([vorbis],[-I${real_vorbis_tree}/include])
     else
       dnl  The given vorbis wasn't built
@@ -3584,10 +3577,10 @@ then
   else
     AC_CHECK_HEADERS(vorbis/codec.h, [
       VLC_ADD_PLUGINS([vorbis])
-      VLC_ADD_LDFLAGS([vorbis],[-lvorbis -logg -lm]) ],[])
+      VLC_ADD_LIBS([vorbis],[-lvorbis -logg -lm]) ],[])
 
     AC_CHECK_HEADERS(vorbis/vorbisenc.h, [
-      VLC_ADD_LDFLAGS([vorbis],[-lvorbisenc -lm]) ],[])
+      VLC_ADD_LIBS([vorbis],[-lvorbisenc -lm]) ],[])
   fi
 fi
 
@@ -3600,7 +3593,7 @@ if test "${enable_tremor}" = "yes"
 then
   AC_CHECK_HEADERS(tremor/ivorbiscodec.h, [
     VLC_ADD_PLUGINS([tremor])
-    VLC_ADD_LDFLAGS([tremor],[-lvorbisidec -logg])
+    VLC_ADD_LIBS([tremor],[-lvorbisidec -logg])
    ],[])
 fi
 
@@ -3628,7 +3621,7 @@ then
       dnl  Use a custom speex
       AC_MSG_RESULT(${real_speex_tree}/libspeex/.libs/libspeex.a)
       VLC_ADD_PLUGINS([speex])
-      VLC_ADD_LDFLAGS([speex],[${real_speex_tree}/libspeex/.libs/libspeex.a])
+      VLC_ADD_LIBS([speex],[${real_speex_tree}/libspeex/.libs/libspeex.a])
       VLC_ADD_CFLAGS([speex],[-I${real_speex_tree}/include])
     else
       dnl  The given speex wasn't built
@@ -3637,10 +3630,10 @@ then
     fi
   else
     AC_CHECK_HEADERS(speex/speex.h, [
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_speex}"
+      LDFLAGS="${LDFLAGS_save} ${LIBS_speex}"
       AC_CHECK_LIB(speex, speex_decode_int, [
         VLC_ADD_PLUGINS([speex])
-        VLC_ADD_LDFLAGS([speex],[-lspeex]) ],
+        VLC_ADD_LIBS([speex],[-lspeex]) ],
         [ AC_MSG_RESULT([no])
           AC_MSG_WARN([Your libspeex is too old, please get the development
                        version.]) ],[])
@@ -3666,7 +3659,7 @@ then
     then
       VLC_ADD_BUILTINS([tarkin])
       VLC_ADD_CPPFLAGS([tarkin],[-I${real_tarkin_tree}])
-      VLC_ADD_LDFLAGS([tarkin],[${real_tarkin_tree}/mem.o ${real_tarkin_tree}/pnm.o ${real_tarkin_tree}/wavelet.o ${real_tarkin_tree}/wavelet_xform.o ${real_tarkin_tree}/wavelet_coeff.o ${real_tarkin_tree}/yuv.o ${real_tarkin_tree}/tarkin.o ${real_tarkin_tree}/info.o -logg])
+      VLC_ADD_LIBS([tarkin],[${real_tarkin_tree}/mem.o ${real_tarkin_tree}/pnm.o ${real_tarkin_tree}/wavelet.o ${real_tarkin_tree}/wavelet_xform.o ${real_tarkin_tree}/wavelet_coeff.o ${real_tarkin_tree}/yuv.o ${real_tarkin_tree}/tarkin.o ${real_tarkin_tree}/info.o -logg])
       AC_MSG_RESULT(yes)
     else
       dnl  The given tarkin tree wasn't built
@@ -3688,7 +3681,7 @@ then
     AC_CHECK_LIB(theora, theora_granule_time, [
       VLC_ADD_PLUGINS([theora])
       theora_libs="-ltheora -logg"
-      VLC_ADD_LDFLAGS([theora],[${theora_libs}]) ],[
+      VLC_ADD_LIBS([theora],[${theora_libs}]) ],[
       AC_MSG_ERROR([libtheora doesn't appear to be installed on your system.
 You also need to check that you have a libogg posterior to the 1.0 release.])],
       [-logg])
@@ -3701,10 +3694,10 @@ dnl
 AC_ARG_ENABLE(dirac,
 [  --enable-dirac          experimental dirac codec (default disabled)])
 if test "${enable_dirac}" = "yes"; then
-  PKG_CHECK_MODULES(DIRAC,[dirac >= 0.6.0], [
+  PKG_CHECK_MODULES(DIRAC,[dirac >= 0.9.0], [
       VLC_ADD_PLUGINS([dirac])
       VLC_ADD_CFLAGS([dirac],[$DIRAC_CFLAGS])
-      VLC_ADD_LDFLAGS([dirac],[$DIRAC_LIBS -lstdc++]) ],[
+      VLC_ADD_LIBS([dirac],[$DIRAC_LIBS -lstdc++]) ],[
       AC_MSG_ERROR([libdirac doesn't appear to be installed on you system.])
   ])
 fi
@@ -3718,10 +3711,10 @@ if test "${enable_png}" != "no"; then
 AC_CHECK_HEADERS(png.h, [
   LDFLAGS="${LDFLAGS_save} -lz"
   AC_CHECK_LIB(png, png_set_rows, [
-    VLC_ADD_LDFLAGS([png],[-lpng -lz])
+    VLC_ADD_LIBS([png],[-lpng -lz])
     VLC_ADD_PLUGINS([png])
-    VLC_ADD_PLUGINS([osdmenu])
-    AC_DEFINE(HAVE_LIBPNG, [], [Define if you have the PNG library: libpng])],
+    VLC_ADD_PLUGINS([osdmenu osd_parser])
+    AC_DEFINE(HAVE_LIBPNG, 1, [Define if you have the PNG library: libpng])],
     [],[-lz])
   LDFLAGS="${LDFLAGS_save}"
   ])
@@ -3750,11 +3743,11 @@ if test "${enable_x264}" != "no"; then
     then
       AC_MSG_RESULT(yes)
       VLC_ADD_CPPFLAGS([x264],[-I${real_x264_tree}])
-      VLC_ADD_LDFLAGS([x264],[-L${real_x264_tree}])
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_x264} ${THREAD_LIB}"
+      VLC_ADD_LIBS([x264],[-L${real_x264_tree}])
+      LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}"
       AC_CHECK_LIB(x264, x264_encoder_open, [
         VLC_ADD_BUILTINS([x264])
-        VLC_ADD_LDFLAGS([x264],[-lx264])
+        VLC_ADD_LIBS([x264],[-lx264])
       ],[
         AC_MSG_ERROR([the specified tree hasn't been compiled])
       ])
@@ -3764,11 +3757,11 @@ if test "${enable_x264}" != "no"; then
       AC_MSG_ERROR([the specified tree doesn't have x264.h])
     fi
   else
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_x264} ${THREAD_LIB}"
+    LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}"
     AC_CHECK_HEADERS(x264.h, [
       AC_CHECK_LIB(x264, x264_encoder_open, [
         VLC_ADD_PLUGINS([x264])
-        VLC_ADD_LDFLAGS([x264],[-lx264])
+        VLC_ADD_LIBS([x264],[-lx264])
       ],[
         if test "${enable_x264}" = "yes"; then
             AC_MSG_ERROR([Could not find libx264 on your system: you may get it from http://www.videolan.org/x264.html])
@@ -3779,6 +3772,55 @@ if test "${enable_x264}" != "no"; then
   fi
 fi
 
+dnl
+dnl libfluidsynth (MIDI synthetizer) plugin
+dnl
+AC_ARG_ENABLE(fluidsynth,
+  [  --enable-fluidsynth     MIDI synthesisr with libfluidsynth (default enabled)])
+AS_IF([test "x${enable_fluidsynth}" != "xno"], [
+  PKG_CHECK_MODULES(FLUIDSYNTH, fluidsynth, [
+    VLC_ADD_PLUGINS(fluidsynth)
+    VLC_ADD_CFLAGS(fluidsynth, [${FLUIDSYNTH_CFLAGS}])
+    VLC_ADD_LIBS(fluidsynth, [${FLUIDSYNTH_LIBS}])
+  ], [
+    AS_IF([test "x${enable_fluidsynth}" != "x"], [
+      AC_MSG_ERROR([${FLUIDSYNTH_PKG_ERRORS}])
+    ])
+  ])
+])
+
+dnl
+dnl Teletext Modules
+dnl vbi decoder plugin (using libzbvi)
+dnl telx module
+dnl uncompatible
+dnl
+AC_ARG_ENABLE(zvbi,
+  [  --enable-zvbi           VBI (inc. Teletext) decoding support with libzvbi (default enabled)])
+AC_ARG_ENABLE(telx,
+  [  --enable-telx,          Teletext decoding module (conflicting with zvbi) (default disabled)])
+
+AS_IF( [test "${enable_zvbi}" != "no"],[
+  AS_IF( [test "${enable_telx}" = "yes"],[
+    AC_MSG_ERROR([The zvbi and telx modules are uncompatibles. Disable the other if you enable one.])
+  ],[
+    PKG_CHECK_MODULES(ZVBI,
+       zvbi-0.2 >= 0.2.25,
+       [
+         VLC_ADD_LIBS([zvbi],[$ZVBI_LIBS])
+         VLC_ADD_CFLAGS([zvbi],[$ZVBI_CFLAGS])
+         VLC_ADD_PLUGINS([zvbi])
+         AC_DEFINE(ZVBI_COMPILED, 1, [Define if the zvbi module is built]) 
+       ],[
+         AC_MSG_WARN(ZVBI library not found. Enabling the telx module instead)
+         enable_telx="yes"
+       ])
+    ])  
+  ])
+AS_IF( [test "${enable_telx}" = "yes"],[
+  VLC_ADD_PLUGINS([telx])
+  ])
+
 dnl
 dnl  CMML plugin
 dnl
@@ -3826,11 +3868,11 @@ if test "${enable_x11}" != "no" &&
   CPPFLAGS="${CPPFLAGS_save} ${X_FLAGS}"
   AC_CHECK_HEADERS(X11/Xlib.h, [
     VLC_ADD_PLUGINS([panoramix])
-    VLC_ADD_LDFLAGS([panoramix],[${X_LIBS} ${X_PRE_LIBS} -lX11])
+    VLC_ADD_LIBS([panoramix],[${X_LIBS} ${X_PRE_LIBS} -lX11])
     VLC_ADD_CPPFLAGS([panoramix],[${X_CFLAGS}])
     AC_CHECK_LIB(Xext, XShmAttach, [
       VLC_ADD_PLUGINS([x11])
-      VLC_ADD_LDFLAGS([x11],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext])
+      VLC_ADD_LIBS([x11],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext])
       VLC_ADD_CPPFLAGS([x11],[${X_CFLAGS}])
     ])
   ])
@@ -3855,15 +3897,15 @@ if test "${enable_xvideo}" != "no" &&
       if test -f /usr/X11R6/lib/libXv.so -o -f /usr/lib/libXv.so -o -f "${x_libraries}"/libXv.so; then
         VLC_ADD_PLUGINS([xvideo])
         VLC_ADD_CPPFLAGS([xvideo],[${X_CFLAGS}])
-        VLC_ADD_LDFLAGS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv])
+        VLC_ADD_LIBS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv])
       else
         AC_CHECK_LIB(Xv_pic,XvPutImage,[
           VLC_ADD_PLUGINS([xvideo])
           VLC_ADD_CPPFLAGS([xvideo],[${X_CFLAGS}])
-          VLC_ADD_LDFLAGS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv_pic])
+          VLC_ADD_LIBS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv_pic])
         ],[
           VLC_ADD_BUILTINS([xvideo])
-          VLC_ADD_LDFLAGS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv])
+          VLC_ADD_LIBS([xvideo],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lXv])
           VLC_ADD_CPPFLAGS([xvideo],[${X_CFLAGS}])
         ])
       fi
@@ -3890,7 +3932,7 @@ if test "${enable_glx}" != "no" &&
     #endif]]),
     [
       VLC_ADD_PLUGINS([glx])
-      VLC_ADD_LDFLAGS([glx],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lGL -lGLU])
+      VLC_ADD_LIBS([glx],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext -lGL -lGLU])
       VLC_ADD_CPPFLAGS([glx],[${X_CFLAGS}])
     ],[AC_MSG_ERROR([Please install GL development package. Alternatively you can also configure with --disable-glx.])])
   CPPFLAGS="${CPPFLAGS_save}"
@@ -3901,14 +3943,14 @@ dnl  XVMC module
 dnl  (enabled by default except on win32)
 dnl
 AC_ARG_ENABLE(xvmc,
-  [  --enable-xvmc            XVMC support (default disabled)])
+  [  --enable-xvmc           XVMC support (default disabled)])
 if test "${enable_xvmc}" = "yes" &&
   (test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce" ||
    test "${enable_xvmc}" = "yes"); then
   CPPFLAGS="${CPPFLAGS_save} ${X_FLAGS}"
   AC_CHECK_HEADERS(X11/extensions/vldXvMC.h, [
     VLC_ADD_PLUGINS([xvmc])
-    VLC_ADD_LDFLAGS([xvmc],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext])
+    VLC_ADD_LIBS([xvmc],[${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext])
     VLC_ADD_CPPFLAGS([xvmc],[${X_CFLAGS}])
   ])
   CPPFLAGS="${CPPFLAGS_save}"
@@ -3927,15 +3969,15 @@ if test "${enable_xvideo}" != "no" && test "${enable_xinerama}" != "no" &&
   CFLAGS="${CFLAGS_save} ${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext"
   AC_CHECK_HEADERS(X11/extensions/Xinerama.h,[
     AC_CHECK_LIB(Xinerama_pic, XineramaQueryExtension,[
-      VLC_ADD_LDFLAGS([xvideo],[-lXinerama_pic])
-      VLC_ADD_LDFLAGS([x11],[-lXinerama_pic])
-      VLC_ADD_LDFLAGS([glx],[-lXinerama_pic])
+      VLC_ADD_LIBS([xvideo],[-lXinerama_pic])
+      VLC_ADD_LIBS([x11],[-lXinerama_pic])
+      VLC_ADD_LIBS([glx],[-lXinerama_pic])
       ac_cv_have_xinerama="yes"
     ],[
       AC_CHECK_LIB(Xinerama, XineramaQueryExtension,[
-        VLC_ADD_LDFLAGS([xvideo],[-lXinerama])
-        VLC_ADD_LDFLAGS([x11],[-lXinerama])
-        VLC_ADD_LDFLAGS([glx],[-lXinerama])
+        VLC_ADD_LIBS([xvideo],[-lXinerama])
+        VLC_ADD_LIBS([x11],[-lXinerama])
+        VLC_ADD_LIBS([glx],[-lXinerama])
         ac_cv_have_xinerama="yes"
       ])
     ])
@@ -3954,15 +3996,15 @@ dnl
   CFLAGS="${CFLAGS_save} ${X_LIBS} ${X_PRE_LIBS} -lX11 -lXext"
   AC_CHECK_HEADERS(X11/extensions/xf86vmode.h,[
     AC_CHECK_LIB(Xxf86vm_pic, XF86VidModeGetViewPort,[
-      VLC_ADD_LDFLAGS([xvideo],[-lXxf86vm_pic])
-      VLC_ADD_LDFLAGS([x11],[-lXxf86vm_pic])
-      VLC_ADD_LDFLAGS([glx],[-lXxf86vm_pic])
+      VLC_ADD_LIBS([xvideo],[-lXxf86vm_pic])
+      VLC_ADD_LIBS([x11],[-lXxf86vm_pic])
+      VLC_ADD_LIBS([glx],[-lXxf86vm_pic])
       ac_cv_have_xf86vidmode="yes"
     ],[
       AC_CHECK_LIB(Xxf86vm, XF86VidModeGetViewPort,[
-        VLC_ADD_LDFLAGS([xvideo],[-lXxf86vm])
-        VLC_ADD_LDFLAGS([x11],[-lXxf86vm])
-        VLC_ADD_LDFLAGS([glx],[-lXxf86vm])
+        VLC_ADD_LIBS([xvideo],[-lXxf86vm])
+        VLC_ADD_LIBS([x11],[-lXxf86vm])
+        VLC_ADD_LIBS([glx],[-lXxf86vm])
         ac_cv_have_xf86vidmode="yes"
       ])
     ])
@@ -3991,15 +4033,15 @@ if test "${enable_opengl}" != "no" &&
     AC_CHECK_HEADERS(GL/gl.h GL/glu.h, [
       VLC_ADD_PLUGINS([opengl])
       if test "${SYS}" != "mingw32"; then
-        VLC_ADD_LDFLAGS([opengl],[${X_LIBS} -lGL -lGLU])
+        VLC_ADD_LIBS([opengl],[${X_LIBS} -lGL -lGLU])
       else
-        VLC_ADD_LDFLAGS([opengl],[-lopengl32 -lglu32])
+        VLC_ADD_LIBS([opengl],[-lopengl32 -lglu32])
       fi
     ])
   else
     dnl OS X special case (no GL/gl.h but OpenGL/gl.h)
     VLC_ADD_PLUGINS([opengl])
-    VLC_ADD_LDFLAGS([opengl],[-framework OpenGL])
+    VLC_ADD_LIBS([opengl],[-Wl,-framework,OpenGL])
   fi
 fi
 
@@ -4009,7 +4051,7 @@ dnl
 AC_ARG_ENABLE(sdl,
   [  --enable-sdl            SDL support (default enabled)])
 AC_ARG_ENABLE(sdl-image,
-  [  --enable-sdl-image            SDL image support (default enabled)])
+  [  --enable-sdl-image      SDL image support (default enabled)])
 if test "${enable_sdl}" != "no"
 then
   SDL_PATH="${PATH}"
@@ -4053,7 +4095,7 @@ then
       VLC_ADD_PLUGINS([vout_sdl aout_sdl])
     fi
     VLC_ADD_CFLAGS([vout_sdl aout_sdl sdl_image],[`${SDL_CONFIG} ${SDL_PREFIX} --cflags | sed 's,SDL,,'`])
-    VLC_ADD_LDFLAGS([vout_sdl aout_sdl sdl_image],[`${SDL_CONFIG} ${SDL_PREFIX} --libs | sed 's,-rdynamic,,'`])
+    VLC_ADD_LIBS([vout_sdl aout_sdl sdl_image],[`${SDL_CONFIG} ${SDL_PREFIX} --libs | sed 's,-rdynamic,,'`])
     CPPFLAGS="${CPPFLAGS_save} ${CFLAGS_vout_sdl}"
     AC_CHECK_HEADERS(${SDL_HEADER}, AC_DEFINE_UNQUOTED(SDL_INCLUDE_FILE,
       <${SDL_HEADER}>, Indicate whether we should use SDL/SDL.h or SDL11/SDL.h),
@@ -4068,12 +4110,12 @@ Please install it and try again. Alternatively you can also configure with
         <${SDL_IMAGE}>, Indicate the path of SDL_image.h)
         VLC_ADD_PLUGINS([sdl_image])
         AC_CHECK_LIB(png, png_set_rows,
-          [VLC_ADD_LDFLAGS([sdl_image],[-lpng -lz])],[],[-lz])
+          [VLC_ADD_LIBS([sdl_image],[-lpng -lz])],[],[-lz])
         AC_CHECK_LIB(jpeg, jpeg_start_decompress,
-          [VLC_ADD_LDFLAGS([sdl_image],[-ljpeg])])
+          [VLC_ADD_LIBS([sdl_image],[-ljpeg])])
         AC_CHECK_LIB(tiff, TIFFClientOpen,
-          [VLC_ADD_LDFLAGS([sdl_image],[-ltiff])])
-        VLC_ADD_LDFLAGS([sdl_image], [-lSDL_image])],
+          [VLC_ADD_LIBS([sdl_image],[-ltiff])])
+        VLC_ADD_LIBS([sdl_image], [-lSDL_image])],
         [ AC_CHECK_HEADERS(SDL_image.h, AC_DEFINE(SDL_IMAGE_INCLUDE_FILE, <SDL_image.h>,
             As a last resort we also test for SDL_image.h presence),
         [ AC_MSG_WARN([The development package for SDL_image is not installed.
@@ -4105,52 +4147,36 @@ AC_ARG_ENABLE(fribidi,
   [  --enable-fribidi        fribidi support (default enabled)])
 if test "${enable_freetype}" != "no"
 then
-  FREETYPE_PATH="${PATH}"
-  AC_ARG_WITH(freetype-config-path,
-    [    --with-freetype-config-path=PATH freetype-config path (default search in \$PATH)],
-    [ if test "${with_freetype_config_path}" != "no"
-      then
-        FREETYPE_PATH="${with_freetype_config_path}:${PATH}"
-      fi ])
-  AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no, ${FREETYPE_PATH})
-
-  if test "${FREETYPE_CONFIG}" != "no"
-  then
-    VLC_ADD_PLUGINS([freetype])
-    VLC_ADD_CFLAGS([freetype],[`${FREETYPE_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([freetype],[`${FREETYPE_CONFIG} --libs`])
+   PKG_CHECK_MODULES(FREETYPE, freetype2,[  
+      VLC_ADD_PLUGINS([freetype])
+      have_freetype=yes     
+      VLC_ADD_CPPFLAGS([freetype skins2],[${FREETYPE_CFLAGS}])
+      VLC_ADD_LIBS([freetype skins2],[${FREETYPE_LIBS}])
+      if test "${SYS}" = "mingw32"; then
+        VLC_ADD_LIBS([freetype skins2],[-lxml2])
+     fi
     AC_CHECK_HEADERS(fontconfig/fontconfig.h,
-      [VLC_ADD_CFLAGS([freetype],[-DHAVE_FONTCONFIG])
-       VLC_ADD_LDFLAGS([freetype],[-lfontconfig])])
+      [VLC_ADD_CPPFLAGS([freetype],[-DHAVE_FONTCONFIG])
+       VLC_ADD_LIBS([freetype],[-lfontconfig])])
     AC_CHECK_HEADERS(Carbon/Carbon.h,
-      [VLC_ADD_LDFLAGS([freetype],[-framework Carbon])])
-  elif test "${enable_freetype}" =  "yes"
-  then
+      [VLC_ADD_LDFLAGS([freetype],[-Wl,-framework,Carbon])])
+  ],[
+  have_freetype=no
+  AS_IF([ test "${enable_freetype}" =  "yes"],[
     AC_MSG_ERROR([I couldn't find the freetype package. You can download libfreetype2
 from http://www.freetype.org/, or configure with --disable-freetype. Have a nice day.
+      ])
     ])
-  fi
+  ])
 
   dnl fribidi support
   if test "${enable_fribidi}" != "no"
   then
-    FRIBIDI_PATH="${PATH}"
-    AC_ARG_WITH(fribidi-config-path,
-      [    --with-fribidi-config-path=PATH fribidi-config path (default search in \$PATH)],
-      [ if test "${with_fribidi_config_path}" != "no"
-        then
-          FRIBIDI_PATH="${with_fribidi_config_path}:${PATH}"
-        fi ])
-    AC_PATH_PROG(FRIBIDI_CONFIG, fribidi-config, no, ${FRIBIDI_PATH})
-
-    if test "${FRIBIDI_CONFIG}" != "no"
-    then
-      VLC_ADD_CFLAGS([freetype], [`${FRIBIDI_CONFIG} --cflags` -DHAVE_FRIBIDI])
-      VLC_ADD_CPPFLAGS([skins2], [`${FRIBIDI_CONFIG} --cflags` -DHAVE_FRIBIDI])
-      VLC_ADD_LDFLAGS([freetype], [`${FRIBIDI_CONFIG} --libs`])
-      VLC_ADD_LDFLAGS([skins2], [`${FRIBIDI_CONFIG} --libs`])
+    PKG_CHECK_MODULES(FRIBIDI, fribidi, [
+      VLC_ADD_CPPFLAGS([freetype skins2], [${FRIBIDI_CFLAGS} -DHAVE_FRIBIDI])
+      VLC_ADD_LIBS([freetype skins2], [${FRIBIDI_LIBS}])
+    ])
     fi
-  fi
 fi
 
 dnl
@@ -4169,10 +4195,10 @@ then
   AC_PATH_PROG(XML2_CONFIG, xml2-config, no, ${XML2_PATH})
   if test "${XML2_CONFIG}" != "no"; then
     VLC_ADD_CPPFLAGS([xml],[`${XML2_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([xml],[`${XML2_CONFIG} --libs`])
+    VLC_ADD_LIBS([xml],[`${XML2_CONFIG} --libs`])
     dnl depends on the xmlTextReader extension
     CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_xml}"
-    LDFLAGS="${LDFLAGS_save} ${LDFLAGS_xml}"
+    LDFLAGS="${LDFLAGS_save} ${LIBS_xml}"
     AC_CHECK_LIB(xml2,xmlTextReaderConstName,[
       AC_EGREP_HEADER(xmlTextReaderConstName,libxml/xmlreader.h,[
         VLC_ADD_PLUGINS([xml]) ],[
@@ -4204,7 +4230,7 @@ then
   PKG_CHECK_MODULES(SVG, 
        librsvg-2.0 >= 2.9.0,
        [
-         VLC_ADD_LDFLAGS([svg],[$SVG_LIBS])
+         VLC_ADD_LIBS([svg],[$SVG_LIBS])
          VLC_ADD_CFLAGS([svg],[$SVG_CFLAGS])
           VLC_ADD_PLUGINS([svg]) ],
         [AC_MSG_WARN(SVG library not found)])
@@ -4232,10 +4258,10 @@ then
   [    --with-qte=PATH       Qt Embedded headers and libraries])
   if test "${with_qte}" != "no" -a -n "${with_qte}"
   then
-    VLC_ADD_LDFLAGS([qte],[-L${with_qte}/lib `echo -L${with_qte}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
+    VLC_ADD_LIBS([qte],[-L${with_qte}/lib `echo -L${with_qte}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
     VLC_ADD_CXXFLAGS([qte],[-I${with_qte}/include `echo -I${with_qte}/include | sed 's,opt/QtPalmtop,usr,'` -DQT_QWS_IPAQ -DQWS -fno-exceptions -fno-rtti])
   else
-    VLC_ADD_LDFLAGS([qte],[-L${QTDIR}/lib `echo -L${QTDIR}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
+    VLC_ADD_LIBS([qte],[-L${QTDIR}/lib `echo -L${QTDIR}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
     VLC_ADD_CXXFLAGS([qte],[-I${QTDIR}/include `echo -I${QTDIR}/include | sed 's,opt/QtPalmtop,usr,'` -DQT_QWS_IPAQ -DQWS -fno-exceptions -fno-rtti])
   fi
   VLC_ADD_PLUGINS([qte])
@@ -4256,13 +4282,13 @@ dnl   [  --enable-qt_video            QT Video Output support (default disabled)
 dnl if test "${enable_qt_video}" = "yes"
 dnl then
 dnl  VLC_ADD_PLUGINS([qt_video])
-dnl  VLC_ADD_LDFLAGS([qt_video],[-L${QTDIR}/lib])
+dnl  VLC_ADD_LIBS([qt_video],[-L${QTDIR}/lib])
 dnl  LDFLAGS="${LDFLAGS_save} ${LDFLAGS_qt_video}"
 dnl   AC_CHECK_LIB(qt-mt,main,[
-dnl    VLC_ADD_LDFLAGS([qt_video],[-lqt-mt])
+dnl    VLC_ADD_LIBS([qt_video],[-lqt-mt])
 dnl  ],[
 dnl    AC_CHECK_LIB(qt,main,[
-dnl      VLC_ADD_LDFLAGS([qt_video],[-lqt])
+dnl      VLC_ADD_LIBS([qt_video],[-lqt])
 dnl    ])
 dnl  ])
 dnl  NEED_QTE_MAIN=yes
@@ -4290,7 +4316,7 @@ if test "${enable_hd1000v}" != "no" -a "${CXX}" != "" &&
   if test "$can_build_roku" = "yes"
   then
     VLC_ADD_PLUGINS([hd1000v])
-    VLC_ADD_LDFLAGS([hd1000v],[-lCascade -ldvbpsi -lmad])
+    VLC_ADD_LIBS([hd1000v],[-lCascade -ldvbpsi -lmad])
   fi
   AC_LANG_POP([C++])
 fi
@@ -4316,15 +4342,15 @@ then
     then
       AC_CHECK_HEADERS(ddraw.h,
       [ VLC_ADD_PLUGINS([vout_directx aout_directx])
-        VLC_ADD_LDFLAGS([vout_directx],[-lgdi32])
+        VLC_ADD_LIBS([vout_directx],[-lgdi32])
       ])
       AC_CHECK_HEADERS(GL/gl.h,
       [ VLC_ADD_PLUGINS([glwin32])
-        VLC_ADD_LDFLAGS([glwin32],[-lopengl32 -lgdi32])
+        VLC_ADD_LIBS([glwin32],[-lopengl32 -lgdi32])
       ])
       AC_CHECK_HEADERS(d3d9.h,
       [ VLC_ADD_PLUGINS([direct3d])
-        VLC_ADD_LDFLAGS([direct3d],[-lgdi32])
+        VLC_ADD_LIBS([direct3d],[-lgdi32])
       ])
     else
       AC_MSG_CHECKING(for directX headers in ${with_directx})
@@ -4332,7 +4358,7 @@ then
       then
         VLC_ADD_PLUGINS([vout_directx aout_directx])
         VLC_ADD_CPPFLAGS([vout_directx aout_directx],[-I${with_directx}])
-        VLC_ADD_LDFLAGS([vout_directx],[-lgdi32])
+        VLC_ADD_LIBS([vout_directx],[-lgdi32])
         AC_MSG_RESULT(yes)
       else
         AC_MSG_RESULT(no)
@@ -4372,43 +4398,78 @@ AC_ARG_ENABLE(svgalib,
 if test "${enable_svgalib}" = "yes"
 then
   VLC_ADD_PLUGINS([svgalib])
-  VLC_ADD_LDFLAGS([svgalib],[-lvgagl -lvga])
+  VLC_ADD_LIBS([svgalib],[-lvgagl -lvga])
 fi
 
 dnl
 dnl  DirectFB module
+dnl  try to find using: 1 - given location; 2 - directfb-config; 3 - pkg-config
+dnl  TODO: support for static linking
 dnl
 AC_ARG_ENABLE(directfb,
   [  --enable-directfb       DirectFB support (default disabled)])
-if test "${enable_directfb}" = "yes"
-then
-  if test "${with_directfb}" = "no"
-  then
-    AC_CHECK_HEADER(directfb.h, have_directfb="true", have_directfb="false")
-    if test "${have_directfb}"= "true"
-    then
+AC_ARG_WITH(directfb, 
+  [    --with-directfb=PATH  path to DirectFB headers and libraries])
+
+if test "${enable_directfb}" = "yes"; then
+    have_directfb="false"
+    CPPFLAGS_mydirectfb=
+    LIBS_mydirectfb=
+    if test "${with_directfb}" != "no" -a -n "${with_directfb}"; then
+        dnl Trying the given location
+        CPPFLAGS_save="${CPPFLAGS}"
+        LIBS_save="${LIBS}"
+
+        CPPFLAGS_new="-I${with_directfb}/include -D_REENTRANT -D_GNU_SOURCE"
+        LIBS_new="-L${with_directfb}/lib/fusion/.libs/ -L${with_directfb}/lib/direct/.libs/"
+        LIBS_new="${LIBS_new} -L${with_directfb}/src/.libs/"
+
+        CPPFLAGS="${CPPFLAGS} ${CPPFLAGS_new}"
+        LIBS="${LIBS} ${LIBS_new}"
+
+        dnl FIXME: too obscure
+        AC_CHECK_HEADER([directfb.h], [
+            AC_CHECK_LIB([direct],[direct_initialize], [
+                AC_CHECK_LIB([fusion], [fusion_enter], [
+                    AC_CHECK_LIB([directfb], [DirectFBInit], have_directfb="true", have_directfb="false")
+                ], have_directfb="false")
+            ], have_directfb="false")
+        ], have_directfb="false")
+
+        dnl Restore flags
+        CPPFLAGS="${CPPFLAGS_save}"
+        LIBS="${LIBS_save}"
+
+        if test "${have_directfb}" = "true"; then
+            LIBS_mydirectfb="${LIBS_new} -lz -ldl -ldirectfb -lfusion -ldirect -lpthread"
+            CPPFLAGS_mydirectfb="${CPPFLAGS_new}"
+        fi
+    else 
+        dnl Look for directfb-config
+        AC_PATH_PROG(DIRECTFB_CONFIG, directfb-config, no, ${PATH})
+        if test "${DIRECTFB_CONFIG}" != "no"; then
+            CPPFLAGS_mydirectfb="`${DIRECTFB_CONFIG} --cflags`"
+            LIBS_mydirectfb="`${DIRECTFB_CONFIG} --libs`"
+            have_directfb="true"
+        else 
+            dnl Trying with pkg-config
+            PKG_CHECK_MODULES(DIRECTFB, directfb, [
+                CPPFLAGS_mydirectfb="${DIRECTFB_CFLAGS}"
+                LIBS_mydirectfb="${DIRECTFB_LIBS}"
+                have_directfb="true"
+                ], [have_directfb="false"])
+        fi
+    fi
+    if test "${have_directfb}" = "true"; then
         VLC_ADD_PLUGINS([directfb])
-        VLC_ADD_LDFLAGS([directfb],[-ldirectfb -lfusion -ldirect -lpthread -ljpeg -lz -ldl])
-        VLC_ADD_CPPFLAGS([directfb],[-I/usr/include/directfb -D_REENTRANT])
-    else
-        AC_MSG_ERROR([cannot find /usr/include/directfb headers, make sure directfb is installed on your system or use --disable-directfb])
+        VLC_ADD_CPPFLAGS([directfb],[${CPPFLAGS_mydirectfb}])
+        VLC_ADD_LIBS([directfb],[${LIBS_mydirectfb}])
+    else 
+        AC_MSG_ERROR([cannot find directfb headers and/or libraries ])
     fi
-  else
-    CPPFLAGS_save="${CPPFLAGS}"
-    CPPFLAGS="${CPPFLAGS} -I${with_directfb}/include"
-    AC_CHECK_HEADER(directfb.h, have_directfb="true", have_directfb="false")
-    CPPFLAGS="${CPPFLAGS_save}"
-    AC_ARG_WITH(directfb,
-        [    --with-directfb=PATH  path to directfb],
-        [ if test "${with_directfb}" != "no" -a -n "${with_directfb}"
-        then
-            VLC_ADD_PLUGINS([directfb])
-            VLC_ADD_CPPFLAGS([directfb],[-I${with_directfb}/include -D_REENTRANT])
-            VLC_ADD_LDFLAGS([directfb],[-L${with_directfb}/lib -ldirectfb -lfusion -ldirect -lpthread -ljpeg -lz -ldl])
-        fi ],
-        [ AC_MSG_ERROR([cannot find directfb headers in ${with_directfb}/include]) ])
-  fi
 fi
+
 
 dnl
 dnl  GGI module
@@ -4418,13 +4479,13 @@ AC_ARG_ENABLE(ggi,
 if test "${enable_ggi}" = "yes"
 then
   VLC_ADD_PLUGINS([ggi])
-  VLC_ADD_LDFLAGS([ggi],[-lggi])
+  VLC_ADD_LIBS([ggi],[-lggi])
   AC_ARG_WITH(ggi,
     [    --with-ggi=PATH       path to libggi],
     [ if test "${with_ggi}" != "no" -a -n "${with_ggi}"
       then
         VLC_ADD_CPPFLAGS([ggi],[-I${with_ggi}/include])
-        VLC_ADD_LDFLAGS([ggi],[-L${with_ggi}/lib])
+        VLC_ADD_LIBS([ggi],[-L${with_ggi}/lib])
       fi ])
 fi
 
@@ -4441,13 +4502,13 @@ then
     [ if test "${with_glide}" != "no" -a -n "${with_glide}"
       then
         VLC_ADD_CPPFLAGS([glide],[-I${with_glide}/include])
-        VLC_ADD_LDFLAGS([glide],[-L${with_glide}/lib])
+        VLC_ADD_LIBS([glide],[-L${with_glide}/lib])
         CFLAGS="$CFLAGS -I${with_glide}/include"
     fi ])
    CFLAGS="$CFLAGS -I/usr/include/glide"
    AC_CHECK_HEADER(glide.h,[   
       VLC_ADD_PLUGINS([glide])
-      VLC_ADD_LDFLAGS([glide],[-lglide2x -lm])
+      VLC_ADD_LIBS([glide],[-lglide2x -lm])
       VLC_ADD_CPPFLAGS([glide],[-I/usr/include/glide])
     ],[
       AC_MSG_ERROR([You don't have libglide. Install it or do not use --enable-glide])
@@ -4466,7 +4527,7 @@ then
   if test "${have_aa}" = "true"
   then
     VLC_ADD_PLUGINS([aa])
-    VLC_ADD_LDFLAGS([aa],[-laa])
+    VLC_ADD_LIBS([aa],[-laa])
   fi
 fi
 
@@ -4489,7 +4550,14 @@ then
   then
     VLC_ADD_PLUGINS([caca])
     VLC_ADD_CFLAGS([caca],[`${CACA_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([caca],[`${CACA_CONFIG} --plugin-libs`])
+    VLC_ADD_LIBS([caca],[`${CACA_CONFIG} --plugin-libs`])
+    AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[#include <caca.h>
+                                        caca_event_t ev;]],
+                                        [[ev.type = 0;]]
+                       )],
+                       [],
+      [AC_DEFINE(CACA_EVENT_OPAQUE, [1], ["Define if struct caca_event is opaque and must not be accessed directly"])]
+    )
   fi
 fi
 
@@ -4501,7 +4569,7 @@ AC_ARG_ENABLE(wingdi,
 if test "${enable_wingdi}" != "no"; then
   if test "${SYS}" = "mingw32" -o "${SYS}" = "cygwin"; then
     VLC_ADD_PLUGINS([wingdi])
-    VLC_ADD_LDFLAGS([wingdi],[-lgdi32])
+    VLC_ADD_LIBS([wingdi],[-lgdi32])
   fi
   if test "${SYS}" = "mingwce"; then
     VLC_ADD_PLUGINS([wingdi wingapi])
@@ -4526,7 +4594,7 @@ if test "${enable_oss}" != "no" &&
 then
   AC_CHECK_HEADERS(soundcard.h sys/soundcard.h machine/soundcard.h, [
     VLC_ADD_PLUGINS([oss])
-    AC_CHECK_LIB(ossaudio,main,VLC_ADD_LDFLAGS([oss],[-lossaudio]))
+    AC_CHECK_LIB(ossaudio,main,VLC_ADD_LIBS([oss],[-lossaudio]))
   ])
 fi
 
@@ -4542,7 +4610,7 @@ AC_ARG_ENABLE(esd,
      then
        VLC_ADD_PLUGINS([esd])
        VLC_ADD_CFLAGS([esd],[`${ESD_CONFIG} --cflags`])
-       VLC_ADD_LDFLAGS([esd],[`${ESD_CONFIG} --libs`])
+       VLC_ADD_LIBS([esd],[`${ESD_CONFIG} --libs`])
      fi
    fi])
 
@@ -4556,9 +4624,9 @@ AC_ARG_ENABLE(portaudio,
      VLC_ADD_PLUGINS([portaudio])
      VLC_ADD_CXXFLAGS([portaudio],[])
      if test "${SYS}" = "mingw32"; then
-        VLC_ADD_LDFLAGS([portaudio],[-lportaudio -lwinmm -lole32])
+        VLC_ADD_LIBS([portaudio],[-lportaudio -lwinmm -lole32])
      else
-        VLC_ADD_LDFLAGS([portaudio],[-lportaudio])
+        VLC_ADD_LIBS([portaudio],[-lportaudio])
      fi
    fi])
 
@@ -4574,7 +4642,7 @@ AC_ARG_ENABLE(arts,
     then
       VLC_ADD_PLUGINS([arts])
       VLC_ADD_CFLAGS([arts],[`${ARTS_CONFIG} --cflags`])
-      VLC_ADD_LDFLAGS([arts],[`${ARTS_CONFIG} --libs `])
+      VLC_ADD_LIBS([arts],[`${ARTS_CONFIG} --libs `])
     fi
   fi])
 
@@ -4595,7 +4663,7 @@ then
        [snd_pcm_hw_params_get_period_time(0,0,0);],
         AC_DEFINE(HAVE_ALSA_NEW_API, 1, Define if ALSA is at least rc4))
     VLC_ADD_PLUGINS([alsa])
-    VLC_ADD_LDFLAGS([alsa],[-lasound -lm -ldl])
+    VLC_ADD_LIBS([alsa],[-lasound -lm -ldl])
   else
     if test "${enable_alsa}" = "yes"; then
       AC_MSG_ERROR([Could not find ALSA development headers])
@@ -4611,7 +4679,7 @@ AC_ARG_ENABLE(waveout,
 if test "${enable_waveout}" != "no"; then
   if test "${SYS}" = "mingw32" -o "${SYS}" = "cygwin"; then
     VLC_ADD_PLUGINS([waveout])
-    VLC_ADD_LDFLAGS([waveout],[-lwinmm])
+    VLC_ADD_LIBS([waveout],[-lwinmm])
   fi
   if test "${SYS}" = "mingwce"; then
     VLC_ADD_PLUGINS([waveout])
@@ -4628,7 +4696,7 @@ if test "${enable_macosx-audio}" != "no" &&
 then
   AC_CHECK_HEADERS(CoreAudio/CoreAudio.h, 
     [ VLC_ADD_BUILTINS([auhal])
-      VLC_ADD_LDFLAGS([auhal],[-framework CoreAudio -framework AudioUnit -framework AudioToolbox])
+      VLC_ADD_LDFLAGS([auhal],[-Wl,-framework,CoreAudio,-framework,AudioUnit,-framework,AudioToolbox,-framework,Carbon])
     ], [ AC_MSG_ERROR([cannot find CoreAudio headers]) ])
 fi
 
@@ -4644,7 +4712,7 @@ then
   AC_LANG_PUSH([C++])
   AC_CHECK_HEADERS(deschutes/libraries/hdmachinex225/PCMAudioPlayer.h, [
     VLC_ADD_PLUGINS([hd1000a])
-    AC_CHECK_LIB(HDMachineX225,main,VLC_ADD_LDFLAGS([hd1000a],[-lHDMachineX225]))  ])
+    AC_CHECK_LIB(HDMachineX225,main,VLC_ADD_LIBS([hd1000a],[-lHDMachineX225]))  ])
   AC_LANG_POP([C++])
 fi
 
@@ -4658,7 +4726,7 @@ AC_ARG_ENABLE(jack,
 AS_IF([test "${enable_jack}" != "no"], [
   AC_CHECK_HEADERS(jack/jack.h, [
     VLC_ADD_PLUGINS([access_jack jack])
-    VLC_ADD_LDFLAGS([access_jack jack],[-ljack])
+    VLC_ADD_LIBS([access_jack jack],[-ljack])
   ],[AC_MSG_ERROR([cannot find JACK headers])])
 ])
 
@@ -4724,7 +4792,7 @@ class testclass : public SearchResponseListener, public MediaPlayer
       AS_IF([test "${LIBS_cclink}" = "no"],
         [AC_MSG_FAILURE([cannot find XML parser for CyberLink])])
       AC_MSG_RESULT([${LIBS_cclink}])
-      VLC_ADD_LDFLAGS([upnp_cc], [${real_cyberlink_tree}/lib/unix/libclink.a -lpthread ${LIBS_cclink}])
+      VLC_ADD_LIBS([upnp_cc], [${real_cyberlink_tree}/lib/unix/libclink.a -lpthread ${LIBS_cclink}])
     ], [
       AC_MSG_RESULT(no)
       AC_MSG_ERROR([cannot find ${real_cyberlink_tree}/lib/unix/libclink.a, make sure you compiled CyberLink for C++ in ${with_cyberlink_tree}])
@@ -4738,7 +4806,7 @@ dnl
 dnl UPnP Plugin (Intel SDK)
 dnl
 AC_ARG_ENABLE(upnp,
-  [  --enable-upnp           Intel UPnP SDK (default auto)])
+  [  --enable-upnp           Intel UPnP SDK (default enabled)])
 
 VLC_ADD_CXXFLAGS([upnp_intel], [ ])
 AS_IF([test "x${enable_upnp}" != "xno"], [
@@ -4747,7 +4815,7 @@ AS_IF([test "x${enable_upnp}" != "xno"], [
     AC_MSG_ERROR([cannot find Intel UPnP SDK (libupnp)])
   ])
   AS_IF([test "${has_upnp}" = "yes"], [
-    VLC_ADD_LDFLAGS([upnp_intel], [-lupnp -lixml])
+    VLC_ADD_LIBS([upnp_intel], [-lupnp -lixml])
   ])
 ], [
   has_upnp="no"
@@ -4783,10 +4851,7 @@ if test "${enable_skins2}" = "yes" ||
   skins2_missing_lib="no"
 
   dnl freetype
-  if test "${FREETYPE_CONFIG}" != "no"; then
-    VLC_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags`])
-    VLC_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs`])
-  else
+  if test "${have_freetype}" != "yes"; then
     skins2_missing_lib="yes"
     if test "${enable_skins2}" = "yes"; then
       AC_MSG_ERROR([Could not find freetype (required for skins2)])
@@ -4798,21 +4863,21 @@ if test "${enable_skins2}" = "yes" ||
     ALIASES="${ALIASES} svlc"
     VLC_ADD_CPPFLAGS([skins2],[-U_OFF_T_ -U_off_t -Imodules/gui/skins2 -DWIN32_SKINS])
     VLC_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
-    VLC_ADD_LDFLAGS([skins2],[-loleaut32 -lwinspool -lwinmm -lshell32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lcomdlg32 -lole32 -luuid -lcomctl32])
+    VLC_ADD_LIBS([skins2],[-loleaut32 -lwinspool -lwinmm -lshell32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lcomdlg32 -lole32 -luuid -lcomctl32])
 
   else if test "${skins2_missing_lib}" = "no" && (test "${SYS}" = "darwin"); then
     VLC_ADD_PLUGINS([skins2])
     ALIASES="${ALIASES} svlc"
     VLC_ADD_CPPFLAGS([skins2],[-Imodules/gui/skins2 -DMACOSX_SKINS])
     VLC_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
-    VLC_ADD_LDFLAGS([skins2],[-framework Carbon])
+    VLC_ADD_LDFLAGS([skins2],[-Wl,-framework,Carbon])
 
   else if test "${skins2_missing_lib}" = "no"; then
     VLC_ADD_PLUGINS([skins2])
     ALIASES="${ALIASES} svlc"
     VLC_ADD_CPPFLAGS([skins2],[-Imodules/gui/skins2 ${X_CFLAGS} -DX11_SKINS])
     VLC_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
-    VLC_ADD_LDFLAGS([skins2],[${X_LIBS} ${X_PRE_LIBS} -lXext -lX11])
+    VLC_ADD_LIBS([skins2],[${X_LIBS} ${X_PRE_LIBS} -lXext -lX11])
   fi fi fi
 fi
 
@@ -4846,10 +4911,10 @@ dnl       AC_MSG_ERROR([Your development package for Gtk+ is too old, you need a
 dnl     fi
 dnl     if test "${SYS}" != "mingw32"; then
 dnl       VLC_ADD_CFLAGS([gtk],[`${GTK_CONFIG} --cflags gtk gthread`])
-dnl       VLC_ADD_LDFLAGS([gtk],[`${GTK_CONFIG} --libs gtk gthread | sed 's,-rdynamic,,'`])
+dnl       VLC_ADD_LIBS([gtk],[`${GTK_CONFIG} --libs gtk gthread | sed 's,-rdynamic,,'`])
 dnl     else
 dnl       VLC_ADD_CFLAGS([gtk],[`${GTK_CONFIG} --cflags gtk`])
-dnl       VLC_ADD_LDFLAGS([gtk],[`${GTK_CONFIG} --libs gtk | sed 's,-rdynamic,,'`])
+dnl       VLC_ADD_LIBS([gtk],[`${GTK_CONFIG} --libs gtk | sed 's,-rdynamic,,'`])
 dnl     fi
 dnl     # now look for the gtk.h header
 dnl     CPPFLAGS="${CPPFLAGS_save} ${CFLAGS_gtk}"
@@ -4879,7 +4944,7 @@ dnl if test "${enable_gtk2}" = "yes"
 dnl then
 dnl   PKG_CHECK_MODULES(GTK2, [gtk+-2.0 >= 2.0.0, gthread-2.0])
 dnl   VLC_ADD_CFLAGS([gtk2],[${GTK2_CFLAGS}])
-dnl   VLC_ADD_LDFLAGS([gtk2],[${GTK2_LIBS}])
+dnl   VLC_ADD_LIBS([gtk2],[${GTK2_LIBS}])
 dnl   VLC_ADD_PLUGINS([gtk2])
 dnl   if test "${SYS}" != "mingw32"; then
 dnl     NEED_GTK2_MAIN=yes
@@ -4895,9 +4960,10 @@ if test "${enable_pda}" = "yes"
 then
   PKG_CHECK_MODULES(GTK2, [gtk+-2.0 >= 2.0.0, gthread-2.0])
   VLC_ADD_CFLAGS([gtk2],[${GTK2_CFLAGS}])
-  VLC_ADD_LDFLAGS([gtk2],[${GTK2_LIBS}])
+  VLC_ADD_LIBS([gtk2],[${GTK2_LIBS}])
   VLC_ADD_CFLAGS([pda],[${GTK2_CFLAGS} ${CFLAGS_pda}])
-  VLC_ADD_LDFLAGS([pda],[${GTK2_LIBS} ${LDFLAGS_pda}])
+  VLC_ADD_LIBS([pda],[${LDFLAGS_pda}])
+  VLC_ADD_LIBS([pda],[${GTK2_LIBS}])
   VLC_ADD_PLUGINS([pda])
   if test "${SYS}" != "mingw32"; then
     NEED_GTK2_MAIN=yes
@@ -4915,7 +4981,7 @@ dnl     AC_PATH_PROG(GNOME_CONFIG, gnome-config, no)
 dnl     if test -x ${GNOME_CONFIG}
 dnl     then
 dnl        VLC_ADD_CFLAGS([gnome],[`${GNOME_CONFIG} --cflags gtk gnomeui`])
-dnl        VLC_ADD_LDFLAGS([gnome],[`${GNOME_CONFIG} --libs gnomeui | sed 's,-rdynamic,,'`])
+dnl        VLC_ADD_LIBS([gnome],[`${GNOME_CONFIG} --libs gnomeui | sed 's,-rdynamic,,'`])
 dnl     fi
 dnl     # now look for the gnome.h header
 dnl     CPPFLAGS="${CPPFLAGS_save} ${CFLAGS_gnome}"
@@ -4947,7 +5013,7 @@ dnl if test "${enable_gnome2}" = "yes"
 dnl then
 dnl   PKG_CHECK_MODULES(GNOME2, [libgnomeui-2.0])
 dnl   VLC_ADD_CFLAGS([gnome2],[${GNOME2_CFLAGS}])
-dnl   VLC_ADD_LDFLAGS([gnome2],[${GNOME2_LIBS}])
+dnl   VLC_ADD_LIBS([gnome2],[${GNOME2_LIBS}])
 dnl   VLC_ADD_PLUGINS([gnome2])
 dnl   if test "${SYS}" != "mingw32"; then
 dnl     NEED_GNOME2_MAIN=yes
@@ -4997,7 +5063,7 @@ then
     if test "${ac_cv_cxx_fpermissive}" = "yes"; then
       VLC_ADD_CXXFLAGS([wxwidgets],-fpermissive)
     fi
-    VLC_ADD_LDFLAGS([wxwidgets],[`${WX_CONFIG} --libs`])
+    VLC_ADD_LIBS([wxwidgets],[`${WX_CONFIG} --libs`])
     VLC_ADD_CXXFLAGS([wxwidgets],[`${WX_CONFIG} --cxxflags`])
     # check if we must link against gtk2 libs
     # if __WXGTK20__ && __WXGTK__ are defined
@@ -5009,7 +5075,7 @@ then
 #endif
         ])],[WXGTK=no],[WXGTK=yes])
     if test "$WXGTK" = "yes"; then
-      ${PKG_CONFIG} --exists gtk+-2.0 && VLC_ADD_LDFLAGS([wxwidgets],[`$PKG_CONFIG --libs gtk+-2.0`])
+      ${PKG_CONFIG} --exists gtk+-2.0 && VLC_ADD_LIBS([wxwidgets],[`$PKG_CONFIG --libs gtk+-2.0`])
     fi
     if ${WX_CONFIG} --unicode
     then 
@@ -5021,7 +5087,7 @@ then
     fi
     if test "$have_libcdio" = "yes"
     then 
-      VLC_ADD_LDFLAGS([wxwidgets],[$LIBCDIO_LIBS])
+      VLC_ADD_LIBS([wxwidgets],[$LIBCDIO_LIBS])
       VLC_ADD_CXXFLAGS([wxwidgets],[$LIBCDIO_CFLAGS])
     else 
       AC_MSG_WARN([Probe disc disabled because ok libcdio library not found])
@@ -5029,7 +5095,7 @@ then
 
     if test "$have_libvcdinfo" = "yes"
     then 
-      VLC_ADD_LDFLAGS([wxwidgets],[$VCDINFO_LIBS])
+      VLC_ADD_LIBS([wxwidgets],[$VCDINFO_LIBS])
       VLC_ADD_CXXFLAGS([wxwidgets],[$VCDINFO_CFLAGS])
     else 
       AC_MSG_WARN([VCD information on Probe disc disabled because ok libvcdinfo not found])
@@ -5045,6 +5111,7 @@ then
     if test "${ac_cv_wx_headers}" = "yes"
     then
       VLC_ADD_PLUGINS([wxwidgets])
+      AC_DEFINE([HAVE_WX], 1, [Define to 1 if you have WxWidgets library.])
       ALIASES="${ALIASES} wxvlc"
     fi
     CPPFLAGS="${CPPFLAGS_save}"
@@ -5064,18 +5131,23 @@ AS_IF([test "${enable_qt4}" != "no" &&
   (test "${SYS}" != "darwin" || test "${enable_qt4}" = "yes")], [
   PKG_CHECK_MODULES(QT4, [QtCore QtGui >= 4.2.0],
     [ VLC_ADD_PLUGINS([qt4])
+      AC_DEFINE([HAVE_QT4], 1, [Define to 1 if you have QT4 library.])
       ALIASES="${ALIASES} qvlc"
       enableqt4=true
-      VLC_ADD_LDFLAGS([qt4],[$QT4_LIBS])
-      VLC_ADD_CXXFLAGS([qt4],[$QT4_CFLAGS])
+      if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce" -a "${SYS}" != "cygwin" -a "${SYS}" != "darwin"; then
+          VLC_ADD_LIBS([qt4],[$QT4_LIBS -lX11])
+      else
+          VLC_ADD_LIBS([qt4],[$QT4_LIBS])
+      fi
+      VLC_ADD_CXXFLAGS([qt4],[$QT4_CFLAGS -DQT4LOCALEDIR=\\\\\\\"$($PKG_CONFIG --variable=prefix QtCore)/share/qt4/translations/\\\\\\\"])
       AC_PATH_PROGS(MOC, [moc-qt4 moc], moc,`$PKG_CONFIG --variable=exec_prefix QtCore`/bin)
       AC_PATH_PROG(RCC, rcc, rcc,`$PKG_CONFIG --variable=exec_prefix QtCore`/bin)
       AC_PATH_PROGS(UIC, [uic-qt4 uic], uic,`$PKG_CONFIG --variable=exec_prefix QtCore`/bin)
       ],
       AS_IF([test "${enable_qt4}" = "yes"],[
-       AC_MSG_ERROR(QT4 library not found)
+    AC_MSG_ERROR(QT4 library not found)
       ],[
-        AC_MSG_WARN(QT4 library not found)
+    AC_MSG_WARN(QT4 library not found)
       ])
     )
 ])
@@ -5087,14 +5159,14 @@ dnl
 if test "${SYS}" = "mingwce"; then
   VLC_ADD_BUILTINS([wince])
   VLC_ADD_CXXFLAGS([wince],[])
-  VLC_ADD_LDFLAGS([wince],[-lcommctrl -lcommdlg -laygshell])
+  VLC_ADD_LIBS([wince],[-lcommctrl -lcommdlg -laygshell])
   dnl Gross hack
-  VLC_ADD_LDFLAGS([wince],[\\\${top_builddir}modules/gui/wince/wince_rc.o])
+  VLC_ADD_LIBS([wince],[\\\${top_builddir}modules/gui/wince/wince_rc.o])
 elif test "${SYS}" = "mingw32"; then
   VLC_ADD_CXXFLAGS([wince],[])
-  VLC_ADD_LDFLAGS([wince],[-lcomctl32 -lcomdlg32 -lgdi32 -lole32])
+  VLC_ADD_LIBS([wince],[-lcomctl32 -lcomdlg32 -lgdi32 -lole32])
   dnl Gross hack
-  VLC_ADD_LDFLAGS([wince],[\\\${top_builddir}modules/gui/wince/wince_rc.o])
+  VLC_ADD_LIBS([wince],[\\\${top_builddir}modules/gui/wince/wince_rc.o])
 fi
 
 dnl
@@ -5116,13 +5188,13 @@ dnl   [  --enable-qt             Qt interface support (default disabled)],
 dnl   [if test "${enable_qt}" = "yes"; then
 dnl      VLC_ADD_PLUGINS([qt])
 dnl      ALIASES="${ALIASES} qvlc"
-dnl      VLC_ADD_LDFLAGS([qt],[-L${QTDIR}/lib])
+dnl      VLC_ADD_LIBS([qt],[-L${QTDIR}/lib])
 dnl      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_qt}"
 dnl      AC_CHECK_LIB(qt-mt,main,[
-dnl        VLC_ADD_LDFLAGS([qt],[-lqt-mt])
+dnl        VLC_ADD_LIBS([qt],[-lqt-mt])
 dnl      ],[
 dnl        AC_CHECK_LIB(qt,main,[
-dnl          VLC_ADD_LDFLAGS([qt],[-lqt])
+dnl          VLC_ADD_LIBS([qt],[-lqt])
 dnl        ])
 dnl      ])
 dnl      LDFLAGS="${LDFLAGS_save}"
@@ -5143,19 +5215,19 @@ dnl   [  --enable-kde            KDE interface support (default disabled)],
 dnl   [if test "${enable_kde}" = "yes"; then
 dnl      VLC_ADD_PLUGINS([kde])
 dnl      ALIASES="${ALIASES} kvlc"
-dnl      VLC_ADD_LDFLAGS([kde],[-L${KDEDIR}/lib])
+dnl      VLC_ADD_LIBS([kde],[-L${KDEDIR}/lib])
 dnl      dnl Check for -lkfile (only in KDE 2) or -lkdeui -lkio (KDE 3)
 dnl      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_kde}"
 dnl      AC_CHECK_LIB(kfile,main,[
-dnl        VLC_ADD_LDFLAGS([kde],[-lkfile])
+dnl        VLC_ADD_LIBS([kde],[-lkfile])
 dnl      ])
 dnl      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_kde}"
 dnl      AC_CHECK_LIB(kdeui,main,[
-dnl        VLC_ADD_LDFLAGS([kde],[-lkdeui])
+dnl        VLC_ADD_LIBS([kde],[-lkdeui])
 dnl      ])
 dnl      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_kde}"
 dnl      AC_CHECK_LIB(kio,main,[
-dnl        VLC_ADD_LDFLAGS([kde],[-lkio])
+dnl        VLC_ADD_LIBS([kde],[-lkio])
 dnl      ])
 dnl      LDFLAGS="${LDFLAGS_save}"
 dnl      VLC_ADD_CXXFLAGS([kde],[-I/usr/include/kde -I/usr/include/qt3 -I/usr/include/qt])
@@ -5178,10 +5250,10 @@ AC_ARG_ENABLE(opie,
      [    --with-qte=PATH       Qt Embedded headers and libraries])
      if test "${with_qte}" != "no" -a -n "${with_qte}"
      then
-       VLC_ADD_LDFLAGS([qte],[-L${with_qte}/lib `echo -L${with_qte}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
+       VLC_ADD_LIBS([qte],[-L${with_qte}/lib `echo -L${with_qte}/lib | sed 's,opt/QtPalmtop,usr,'` -ljpeg -lqte])
        VLC_ADD_CXXFLAGS([qte],[-I${with_qte}/include `echo -I${with_qte}/include | sed 's,opt/QtPalmtop,usr,'` -DQT_QWS_IPAQ -DQWS -fno-exceptions -fno-rtti])
      else
-       VLC_ADD_LDFLAGS([qte],[-L${QTDIR}/lib `echo -L${QTDIR}/lib | sed 's,opt/QtPalmtop,usr,'`])
+       VLC_ADD_LIBS([qte],[-L${QTDIR}/lib `echo -L${QTDIR}/lib | sed 's,opt/QtPalmtop,usr,'`])
        VLC_ADD_CXXFLAGS([qte],[-I${QTDIR}/include `echo -I${QTDIR}/include | sed 's,opt/QtPalmtop,usr,'`])
      fi
      CPPFLAGS="${CPPFLAGS_save} ${CXXFLAGS_qte}"
@@ -5192,7 +5264,7 @@ AC_ARG_ENABLE(opie,
 
      VLC_ADD_PLUGINS([opie])
      NEED_QTE_MAIN=yes
-     VLC_ADD_LDFLAGS([opie],[-lqpe ${LDFLAGS_qte}])
+     VLC_ADD_LIBS([opie],[-lqpe ${LDFLAGS_qte}])
      VLC_ADD_CXXFLAGS([opie],[${CXXFLAGS_qte}])
      if test "${with_qte}" != "no" -a -n "${with_qte}"
      then
@@ -5203,27 +5275,32 @@ AC_ARG_ENABLE(opie,
    fi])
 
 dnl
-dnl  MacOS X module
+dnl  MacOS X video output/gui modules
 dnl
-ORIGCFLAGS=$CFLAGS
-CFLAGS="$CFLAGS -x objective-c"
 AC_ARG_ENABLE(macosx,
-  [  --enable-macosx         MacOS X support (default enabled on MacOS X)],
-  [if test "${enable_macosx}" = "yes"
-   then
-     VLC_ADD_PLUGINS([access_eyetv])
-     VLC_ADD_LDFLAGS([access_eyetv], [-framework CoreFoundation])
-     VLC_ADD_LDFLAGS([macosx],[-framework IOKit -framework Cocoa -framework Carbon -framework QuickTime -lobjc -ObjC -framework OpenGL -framework AGL -framework QTKit])
-     VLC_ADD_OBJCFLAGS( [macosx],[-fobjc-exceptions] )
-   fi],
-  [AC_CHECK_HEADERS(Cocoa/Cocoa.h,
-     VLC_ADD_PLUGINS([access_eyetv])
-     VLC_ADD_LDFLAGS([access_eyetv], [-framework CoreFoundation])
-     VLC_ADD_BUILTINS([macosx])
-     VLC_ADD_LDFLAGS([macosx],[-framework IOKit -framework Cocoa -framework Carbon -framework QuickTime -lobjc -ObjC -framework OpenGL -framework AGL -framework QTKit])
-     VLC_ADD_OBJCFLAGS( [macosx],[-fobjc-exceptions] )
-   )])
-CFLAGS=$ORIGCFLAGS
+  [  --enable-macosx         MacOS X support (default enabled on MacOS X)])
+if test "x${enable_macosx}" = "xyes"
+then
+  VLC_ADD_LDFLAGS([access_eyetv],                     [-Wl,-framework,Foundation])
+  VLC_ADD_LDFLAGS([macosx minimal_macosx opengllayer],[-Wl,-framework,Cocoa])
+  VLC_ADD_LDFLAGS([macosx minimal_macosx opengllayer],[-Wl,-framework,OpenGL])
+  VLC_ADD_LDFLAGS([macosx minimal_macosx],            [-Wl,-framework,Carbon])
+  VLC_ADD_LDFLAGS([macosx minimal_macosx],            [-Wl,-framework,AGL])
+  VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,IOKit])
+  VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,QuickTime])
+  VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,QTKit])
+  VLC_ADD_LDFLAGS([macosx],                           [-Wl,-framework,WebKit])
+  VLC_ADD_LDFLAGS([opengllayer],                      [-Wl,-framework,QuartzCore])
+  VLC_ADD_OBJCFLAGS([macosx minimal_macosx opengllayer], [-fobjc-exceptions] )
+
+  VLC_ADD_PLUGINS([access_eyetv])
+  VLC_ADD_BUILTINS([macosx minimal_macosx])
+  ORIGCFLAGS=$CFLAGS
+  CFLAGS="$CFLAGS -x objective-c"
+  AC_CHECK_HEADER(QuartzCore/CALayer.h, [VLC_ADD_BUILTINS([opengllayer])])
+  CFLAGS=$ORIGCFLAGS
+fi
 
 dnl
 dnl  QNX RTOS module
@@ -5234,7 +5311,7 @@ AC_ARG_ENABLE(qnx,
     then
       AC_CHECK_HEADERS(Ph.h, [
         VLC_ADD_PLUGINS([qnx])
-        VLC_ADD_LDFLAGS([qnx],[-lasound -lph])
+        VLC_ADD_LIBS([qnx],[-lasound -lph])
       ])
     fi
 
@@ -5242,11 +5319,26 @@ dnl
 dnl  ncurses module
 dnl
 AC_ARG_ENABLE(ncurses,
-  [  --enable-ncurses        ncurses interface support (default disabled)],
-  [if test "${enable_ncurses}" = "yes"; then
-     VLC_ADD_PLUGINS([ncurses])
-     VLC_ADD_LDFLAGS([ncurses],[-lncurses])
-   fi])
+  [  --disable-ncurses       ncurses interface support (default enabled)],
+  [if test "${enable_ncurses}" != "no"; then
+    AC_CHECK_HEADER(ncurses.h,
+      [AC_CHECK_LIB(ncursesw, mvprintw,
+        [VLC_ADD_PLUGINS([ncurses])
+        VLC_ADD_LIBS([ncurses],[-lncursesw])
+        ALIASES="${ALIASES} nvlc"
+        AC_DEFINE([HAVE_NCURSESW], 1, [Define to 1 if you have libncursesw.])
+        ],
+        [AC_CHECK_LIB( ncurses, mvprintw,
+          [VLC_ADD_PLUGINS([ncurses])
+          ALIASES="${ALIASES} nvlc"
+          VLC_ADD_LIBS([ncurses],[-lncurses])],
+          [AS_IF([test "x${enable_ncurses}" != "x"], [
+            AC_MSG_ERROR([libncurses not found])])]
+        )]
+      )]
+    )
+  fi]
+)
 
 dnl
 dnl  XOSD plugin
@@ -5266,10 +5358,22 @@ then
   if test "${have_xosd}" = "true"
   then
     VLC_ADD_PLUGINS([xosd])
-    VLC_ADD_LDFLAGS([xosd],[-lxosd])
+    VLC_ADD_LIBS([xosd],[-lxosd])
   fi
 fi
 
+dnl
+dnl Framebuffer (overlay) plugin
+dnl
+AC_ARG_ENABLE(fbosd,
+  [  --enable-fbosd          fbosd interface support (default disabled)])
+if test "${enable_fbosd}" = "yes"
+then
+  AC_CHECK_HEADERS(linux/fb.h, [
+    VLC_ADD_PLUGINS([fbosd])
+ ])
+fi
+
 dnl
 dnl Visualisation plugin
 dnl
@@ -5290,9 +5394,9 @@ then
   AC_CHECK_HEADERS(GL/gl.h GL/glu.h, [
     VLC_ADD_PLUGINS([galaktos])
     if test "${SYS}" != "mingw32"; then
-      VLC_ADD_LDFLAGS([galaktos],[${X_LIBS} -lGL -lGLU])
+      VLC_ADD_LIBS([galaktos],[${X_LIBS} -lGL -lGLU])
     else
-      VLC_ADD_LDFLAGS([galaktos],[-lopengl32])
+      VLC_ADD_LIBS([galaktos],[-lopengl32])
     fi
   ])
 fi
@@ -5321,7 +5425,7 @@ then
     if test -f "${real_goom_tree}/src/.libs/libgoom2.a"; then
       AC_MSG_RESULT(${real_goom_tree}/src/.libs/libgoom2.a)
       VLC_ADD_BUILTINS([goom])
-      VLC_ADD_LDFLAGS([goom],[-L${real_goom_tree}/src/.libs -lgoom2])
+      VLC_ADD_LIBS([goom],[-L${real_goom_tree}/src/.libs -lgoom2])
       VLC_ADD_CPPFLAGS([goom],[-I${real_goom_tree}/src -DUSE_GOOM_TREE])
     else
       dnl  The given libgoom2 wasn't built, try to look for the old goom
@@ -5330,7 +5434,7 @@ then
       if test -f "${real_goom_tree}/libgoom.a"; then
         AC_MSG_RESULT(${real_goom_tree}/libgoom.a)
         VLC_ADD_BUILTINS([goom])
-        VLC_ADD_LDFLAGS([goom],[-L${real_goom_tree} -lgoom])
+        VLC_ADD_LIBS([goom],[-L${real_goom_tree} -lgoom])
         VLC_ADD_CPPFLAGS([goom],[-I${real_goom_tree} -DUSE_GOOM_TREE -DOLD_GOOM])
       else
         dnl  The given libgoom wasn't built
@@ -5340,10 +5444,10 @@ then
     fi
   else
     AC_CHECK_HEADERS(goom/goom.h, [
-      LDFLAGS="${LDFLAGS_save} ${LDFLAGS_goom}"
+      LDFLAGS="${LDFLAGS_save} ${LIBS_goom}"
       AC_CHECK_LIB(goom2, goom_init, [
         VLC_ADD_PLUGINS([goom])
-        VLC_ADD_LDFLAGS([goom],[-lgoom2])
+        VLC_ADD_LIBS([goom],[-lgoom2])
       ],[
         AC_MSG_ERROR([Could not find goom on your system: you may get it from http://www.ios-software.com/.])
       ])
@@ -5361,9 +5465,9 @@ if test "${enable_bonjour}" != "no"
 then
   PKG_CHECK_MODULES(BONJOUR, avahi-client >= 0.3,
     [PKG_CHECK_MODULES(BONJOUR, avahi-client >= 0.6,
-       [AC_DEFINE(HAVE_AVAHI_06, [], [Define if you have avahi-client 0.6 or greater])],)
-      AC_DEFINE(HAVE_AVAHI_CLIENT, [], [Define if you have the avahi-client library])
-      VLC_ADD_LDFLAGS([bonjour access_output_http],[$BONJOUR_LIBS])
+       [AC_DEFINE(HAVE_AVAHI_06, 1, [Define if you have avahi-client 0.6 or greater])],)
+      AC_DEFINE(HAVE_AVAHI_CLIENT, 1, [Define if you have the avahi-client library])
+      VLC_ADD_LIBS([bonjour access_output_http],[$BONJOUR_LIBS])
       VLC_ADD_CFLAGS([bonjour access_output_http],[$BONJOUR_CFLAGS])
       VLC_ADD_PLUGINS([bonjour]) ],
     [AC_MSG_WARN(avahi-client library not found)])
@@ -5380,13 +5484,46 @@ then
   if test "${have_lirc}" = "true"
   then
     VLC_ADD_PLUGINS([lirc])
-    VLC_ADD_LDFLAGS([lirc],[-llirc_client])
+    VLC_ADD_LIBS([lirc],[-llirc_client])
   fi
 fi
 
 
 AC_ARG_WITH(,[Misc options:])
 
+dnl
+dnl libgcrypt
+dnl
+AC_ARG_ENABLE(libgcrypt,
+  [  --enable-libgcrypt      libgcrypts support (default enabled)])
+
+GCRYPT_PATH="${PATH}"
+AC_ARG_WITH(libgcrypt-config-path,
+[    --with-libgcrypt-config-path=PATH libgcrypt-config path (default search in \$PATH)],
+   [ if test "${with_libgcrypt_config_path}" != "no"
+     then
+       GCRYPT_PATH="${with_libgcrypt_config_path}:${PATH}"
+     fi ])
+
+if test "${enable_libgcrypt}" != "no"
+then
+  dnl Workaround for cross-compiling since AM_PATH_LIBGRYPT doesn't dectect
+  dnl it and looks for libgcrypt headers in the wrong place.
+  if test "${host_cpu}" = "${build_cpu}"
+  then
+    AM_PATH_LIBGCRYPT([1:1.1.94], [have_libgcrypt="yes"], [have_libgcrypt="no"])
+  else
+    AC_CHECK_HEADERS(gcrypt.h,have_libgcrypt="yes",have_libgcrypt="no")
+  fi
+fi
+AM_CONDITIONAL([HAVE_LIBGCRYPT], [test "${have_libgcrypt}" = "yes"])
+AS_IF([test "${have_libgcrypt}" = "yes"],[
+       # look for libgcrypt-config
+       AC_PATH_PROG(GCRYPT_CONFIG, "libgcrypt-config", no, ${GCRYPT_PATH})
+       GCRYPT_CFLAGS=`${GCRYPT_CONFIG} --cflags`
+       GCRYPT_LIBS=`${GCRYPT_CONFIG} --libs`
+])
+
 dnl
 dnl TLS/SSL
 dnl
@@ -5394,40 +5531,41 @@ AC_ARG_ENABLE(gnutls,
   [  --enable-gnutls         gnutls TLS/SSL support (default enabled)])
 
 AS_IF([test "${enable_gnutls}" != "no"], [
-  PKG_CHECK_MODULES(GNUTLS, [gnutls >= 1.2.9], [have_gnutls="yes"], [have_gnutls="no"])
-
-  AS_IF([test "${have_gnutls}" = "yes"], [
+  PKG_CHECK_MODULES(GNUTLS, [gnutls >= 1.3.3], [
     VLC_ADD_PLUGINS([gnutls])
     VLC_ADD_CFLAGS([gnutls], [$GNUTLS_CFLAGS])
-    VLC_ADD_LDFLAGS([gnutls], [$GNUTLS_LIBS])
+    AS_IF([test "${SYS}" = "mingw32"], [
+      dnl pkg-config --libs gnutls omits these
+      VLC_ADD_LIBS([gnutls], [-lz])
+      VLC_ADD_LIBS([gnutls], [${LTLIBINTL}])
+    ])
+    AS_IF([test "${have_libgcrypt}" = "yes"],[
+      VLC_ADD_LIBS([gnutls], ${GCRYPT_LIBS})
+      VLC_ADD_CFLAGS([gnutls], ${GCRYPT_CFLAGS})
+    ], [-lgpg-error])
+    VLC_ADD_LIBS([gnutls], [$GNUTLS_LIBS])
   ], [
     AS_IF([test "${enable_gnutls}" = "yes"], [
       AC_MSG_ERROR([gnutls not present or too old (version 1.2.9 required)])
     ])
   ])
-  AC_CHECK_LIB([gcrypt], [gcry_control], [
-    VLC_ADD_LDFLAGS([gnutls], [-lgcrypt])
-  ])
 ])
 
 dnl
-dnl libgcrypt
+dnl update checking system
 dnl
-AC_ARG_ENABLE(libgcrypt,
-  [  --enable-libgcrypt      libgcrypts support (default enabled)])
-if test "${enable_libgcrypt}" != "no" -a "${enable_gnutls}" != "no"i
+AC_ARG_ENABLE(update-check,
+  [  --enable-update-check   update checking system (default disabled)])
+if test "${enable_update_check}" = "yes"
 then
-  dnl Workaround for cross-compiling since AM_PATH_LIBGRYPT doesn't dectect
-  dnl it and looks for libgcrypt headers in the wrong place.
-  if test "${host_cpu}" = "${build_cpu}"
+  if test "${have_libgcrypt}" != "yes"
   then
-    AM_PATH_LIBGCRYPT([1:1.1.94], [have_libgcrypt="yes"], [have_libgcrypt="no"])
-  else
-    AC_CHECK_HEADERS(gcrypt.h,have_libgcrypt="yes",have_libgcrypt="no")
+    AC_MSG_ERROR([libgcrypt is required for update checking system])
   fi
+  VLC_ADD_LIBS([libvlc], ${GCRYPT_LIBS})
+  VLC_ADD_CFLAGS([libvlc], ${GCRYPT_CFLAGS})
+  AC_DEFINE([UPDATE_CHECK], 1, [Define if you want to use the VLC update mechanism])
 fi
-AM_CONDITIONAL([HAVE_LIBGCRYPT], [test "${have_libgcrypt}" = "yes"])
-
 
 dnl
 dnl  Endianness check, AC_C_BIGENDIAN doesn't work if we are cross-compiling
@@ -5498,11 +5636,11 @@ AM_CONDITIONAL(LOADER, [test "${enable_loader}" = "yes"])
 AS_IF([test "${enable_loader}" = "yes"],
   [ VLC_ADD_PLUGINS([dmo])
     VLC_ADD_CPPFLAGS([dmo],[-I../../../@top_srcdir@/libs/loader])
-    VLC_ADD_LDFLAGS([dmo],[../../../libs/loader/libloader.la -lpthread])
+    VLC_ADD_LIBS([dmo],[../../../libs/loader/libloader.la -lpthread])
     VLC_ADD_CPPFLAGS([quicktime],[-I../../@top_srcdir@/libs/loader])
-    VLC_ADD_LDFLAGS([quicktime],[../../libs/loader/libloader.la -lpthread])
+    VLC_ADD_LIBS([quicktime],[../../libs/loader/libloader.la -lpthread])
     VLC_ADD_CPPFLAGS([realaudio],[-I../../@top_srcdir@/libs/loader -DLOADER])
-    VLC_ADD_LDFLAGS([realaudio],[../../libs/loader/libloader.la -ldl -lpthread])
+    VLC_ADD_LIBS([realaudio],[../../libs/loader/libloader.la])
   ])
 
 dnl
@@ -5530,7 +5668,7 @@ then
       [AC_CHECK_HEADERS(olectl.h,
         [ VLC_ADD_CPPFLAGS([activex],[-DUNICODE -D_UNICODE -D_MIDL_USE_GUIDDEF_])
           VLC_ADD_CXXFLAGS([activex],[-fno-exceptions])
-          VLC_ADD_LDFLAGS([activex],[-lole32 -loleaut32 -luuid -lshlwapi]) 
+          VLC_ADD_LIBS([activex],[-lole32 -loleaut32 -luuid -lshlwapi]) 
           AC_CHECK_HEADERS(objsafe.h,
             VLC_ADD_CXXFLAGS([activex],[-DHAVE_OBJSAFE_HEADER]),,
             [
@@ -5612,10 +5750,12 @@ then
             MOZILLA_CONFIG_H="${firefox_include}/mozilla-config.h"
         fi
         if grep '^#define MOZ_X11 1' ${MOZILLA_CONFIG_H} 2>&1 > /dev/null ; then
-            VLC_ADD_LDFLAGS([mozilla], [${X_LIBS} ${X_PRE_LIBS} -lX11 -lXt])
+            AC_CHECK_HEADERS(X11/xpm.h,,AC_MSG_ERROR([Please install libXpm-devel library for required X11/xpm.h]))
+            VLC_ADD_LIBS([mozilla], [${X_LIBS} ${X_PRE_LIBS} -lX11 -lXt -lXpm])
         fi
         VLC_ADD_CPPFLAGS([mozilla],[${CPPFLAGS}])
-        VLC_ADD_LDFLAGS([mozilla],[${FIREFOX_LIBS} ${MOZILLA_NSPR_LIBS} ${NSPR_LIBS} ${MOZILLA_LDFLAGS}])
+        VLC_ADD_LDFLAGS([mozilla],[${MOZILLA_LDFLAGS}])
+        VLC_ADD_LIBS([mozilla],[${FIREFOX_LIBS} ${MOZILLA_NSPR_LIBS} ${NSPR_LIBS}])
         VLC_ADD_PLUGINS([mozilla])
         MOZILLA_CONFIG=
         CPPFLAGS="${CPPFLAGS_save}"
@@ -5648,11 +5788,12 @@ then
         AC_CHECK_LIB(Xt,XtStrings,
          [
            VLC_ADD_CPPFLAGS([mozilla],[${X_CFLAGS}])
-           VLC_ADD_LDFLAGS([mozilla],[${X_LIBS} ${X_PRE_LIBS} -lXt -lX11 -lSM -lICE])
+           VLC_ADD_LIBS([mozilla],[${X_LIBS} ${X_PRE_LIBS} -lXt -lX11 -lSM -lICE -lXpm])
          ],
          [],
-         [[${X_LIBS} ${X_PRE_LIBS} -lX11 -lSM -lICE]
+         [[${X_LIBS} ${X_PRE_LIBS} -lX11 -lSM -lICE -lXpm]
         ])
+        AC_CHECK_HEADERS(X11/xpm.h,,AC_MSG_ERROR([Please install libXpm-devel library for required X11/xpm.h]))
         LDFLAGS="${LDFLAGS_save}"
       fi
 
@@ -5661,9 +5802,9 @@ then
       dnl Workaround for http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=150490
       VLC_ADD_CPPFLAGS([mozilla],[[`${MOZILLA_CONFIG} --cflags plugin xpcom java | sed 's,-I\([^ ]*\)/mozilla/\([^ ]*\),-I\1/\2 -I\1/mozilla/\2,g' | xargs`]])
       if ${need_xpcom_libs}; then
-         VLC_ADD_LDFLAGS([mozilla],[`${MOZILLA_CONFIG} --libs plugin xpcom`])
+         VLC_ADD_LIBS([mozilla],[`${MOZILLA_CONFIG} --libs plugin xpcom`])
       else
-         VLC_ADD_LDFLAGS([mozilla],[`${MOZILLA_CONFIG} --libs plugin`])
+         VLC_ADD_LIBS([mozilla],[`${MOZILLA_CONFIG} --libs plugin`])
       fi
       CPPFLAGS="${CPPFLAGS_save} ${CPPFLAGS_mozilla}"
       MOZILLA_REQUIRED_HEADERS=1
@@ -5713,12 +5854,12 @@ then
     PLUGINS_BINDINGS="${PLUGINS_BINDINGS} mozilla"
     VLC_ADD_CPPFLAGS([mozilla],[-DXPCOM_GLUE -DHAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX -I${real_mozilla_sdk} -I${real_mozilla_sdk}/include -I${real_mozilla_sdk}/embedstring/include -I${real_mozilla_sdk}/xpcom/include -I${real_mozilla_sdk}/nspr/include -I${real_mozilla_sdk}/string/include -I${real_mozilla_sdk}/plugin/include -I${real_mozilla_sdk}/java/include])
     if ${need_xpcom_libs}; then
-       VLC_ADD_LDFLAGS([mozilla],[-L${real_mozilla_sdk}/embedstring/bin -L${real_mozilla_sdk}/xpcom/bin -L${real_mozilla_sdk}/nspr/bin -L${real_mozilla_sdk}/string/bin -L${real_mozilla_sdk}/lib -lnspr4 -lplds4 -lplc4 -lxpcomglue])
+       VLC_ADD_LIBS([mozilla],[-L${real_mozilla_sdk}/embedstring/bin -L${real_mozilla_sdk}/xpcom/bin -L${real_mozilla_sdk}/nspr/bin -L${real_mozilla_sdk}/string/bin -L${real_mozilla_sdk}/lib -lnspr4 -lplds4 -lplc4 -lxpcomglue])
       if test "${SYS}" = "mingw32"; then
         dnl latest gecko sdk does not have embedstring
         if test -d "${real_mozilla_sdk}/embedstring/bin"
         then
-          VLC_ADD_LDFLAGS([mozilla],[-lembedstring -Wl,--kill-at])
+          VLC_ADD_LIBS([mozilla],[-lembedstring])
         fi
       fi
     fi
@@ -5734,22 +5875,26 @@ AC_LANG_POP(C++)
 AM_CONDITIONAL(BUILD_MOZILLA,${mozilla})
 
 dnl Tests for Osso and Xsp
-AC_CHECK_LIB(osso, osso_display_blanking_pause,[
-   PKG_CHECK_MODULES(GLIB2, glib-2.0, [                                                  
-       VLC_ADD_CPPFLAGS([x11],[-DHAVE_OSSO ${DBUS_CFLAGS} ${GLIB2_CFLAGS}])
-       VLC_ADD_LDFLAGS([x11],[-losso])
+if test "${enable_x11}" != "no" &&
+  (test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce" ||
+   test "${enable_x11}" = "yes"); then
+   AC_CHECK_LIB(osso, osso_display_blanking_pause,[
+      PKG_CHECK_MODULES(GLIB2, glib-2.0, [                                               
+          VLC_ADD_CPPFLAGS([x11],[-DHAVE_OSSO ${DBUS_CFLAGS} ${GLIB2_CFLAGS}])
+          VLC_ADD_LIBS([x11],[-losso])
+      ])
    ])
-])
-AC_CHECK_LIB(Xsp, XSPSetPixelDoubling,[
-   VLC_ADD_CPPFLAGS([x11],[-DHAVE_XSP])
-   VLC_ADD_LDFLAGS([x11],[-lXsp])
-])
+   AC_CHECK_LIB(Xsp, XSPSetPixelDoubling,[
+      VLC_ADD_CPPFLAGS([x11],[-DHAVE_XSP])
+      VLC_ADD_LIBS([x11],[-lXsp])
+   ])
+fi
 
 dnl
 dnl  Mediacontrol Python bindings
 dnl
 AC_ARG_ENABLE(python-bindings,
-  [  --enable-python-bindings    Enable Python bindings (default disabled)])
+  [  --enable-python-bindings Enable Python bindings (default disabled)])
 dnl TODO: look for python dev headers
 AS_IF([test "${enable_python_bindings}" = "yes"],
       PLUGINS_BINDINGS="${PLUGINS_BINDINGS} python"
@@ -5789,10 +5934,9 @@ then
   VLC_ADD_CXXFLAGS([test2],[])
   VLC_ADD_OBJCFLAGS([test3],[])
   dnl  this one is needed until automake knows what to do
-  VLC_ADD_LDFLAGS([test3],[-lobjc])
+  VLC_ADD_LIBS([test3],[-lobjc])
 
   VLC_ADD_PLUGINS([${TESTS}])
-  #VLC_ADD_BUILTINS([${TESTS}])
 fi
 
 dnl
@@ -5853,58 +5997,44 @@ fi
 dnl
 dnl  Plugin and builtin checks
 dnl
-builtin_support=false
-plugin_support=:
-
-dnl Support for plugins - this must be AT THE END
-AC_ARG_ENABLE(plugins,
-  [  --disable-plugins       make all plugins built-in (default plugins enabled)],
-  [if test "${enable_plugins}" = "no"
-   then
-     plugin_support=false
-   fi])
+plugin_support=yes
 
 dnl Automagically disable plugins if there is no system support for
 dnl dynamically loadable files (.so, .dll, .dylib).
 dnl don't forget vlc-win32 still can load .dll as plugins
-if test "${ac_cv_have_plugins}" = "no"
-then
-  echo "*** Your system doesn't have plugin support. All plugins will be built"
-  echo "statically."
-  plugin_support=false
-fi
+AS_IF([test "${ac_cv_have_plugins}" = "no"], [
+  AC_MSG_WARN([*** No plugin support! Building statically! ***])
+  plugin_support=no
+])
+
+AS_IF([test "${enable_shared}" = "no"], [
+  plugin_support=no
+])
 
-AS_IF([${plugin_support}], [
+AS_IF([test "${plugin_support}" != "no"], [
   AC_DEFINE(HAVE_DYNAMIC_PLUGINS, 1, Define if we have support for dynamic plugins)
-], [
-  VLC_ADD_BUILTINS([${PLUGINS}])
-  PLUGINS=""
 ])
 
+AM_CONDITIONAL(HAVE_PLUGINS, [test "${plugin_support}" != "no"])
+
+dnl Temporary(?) hack for plugins/builtins transition
+VLC_ADD_PLUGINS([${BUILTINS}])
+BUILTINS=""
+
 dnl
 dnl Pic and shared libvlc stuff
 dnl
-AS_IF([test "${SYS}" = "mingw32" || test "${enable_libtool}" != "no"], [
-  AC_DEFINE(HAVE_SHARED_LIBVLC, 1, [Define to 1 if libvlc is built as a shared library.])
-  VLC_ADD_PLUGINS([${BUILTINS}])
-  AS_IF([test "${SYS}" = "mingw32"], [
-    FILE_LIBVLC_DLL="!define LIBVLC_DLL libvlc.dll"
-    VLC_ADD_CPPFLAGS([libvlc],[-DDLL_EXPORT])
-  ])
-  BUILTINS=""
-], [
-  LDFLAGS_vlc="${LDFLAGS_vlc} ${LDFLAGS_libvlc}"
-  FILE_LIBVLC_DLL=""
+AS_IF([test "${SYS}" = "mingw32"], [
+  FILE_LIBVLC_DLL="!define LIBVLC_DLL libvlc.dll"
+  FILE_LIBVLC_CONTROL_DLL="!define LIBVLC_CONTROL_DLL libvlc-control.dll"
 ])
 
- dnl Import conditional variables generated by bootstrap
-VLC_CONDITIONALS
-
 dnl
 dnl  Stuff used by the program
 dnl
 AC_DEFINE_UNQUOTED(VERSION_MESSAGE, "${VERSION} ${CODENAME}", [Simple version string])
-AC_DEFINE_UNQUOTED(COPYRIGHT_MESSAGE, "VLC media player - version ${VERSION} ${CODENAME} - (c) 1996-2007 the VideoLAN team", [Copyright string])
+AC_DEFINE_UNQUOTED(COPYRIGHT_MESSAGE, "VLC media player - version ${VERSION} ${CODENAME} - (c) ${COPYRIGHT_YEARS} the VideoLAN team", [Copyright string])
+AC_DEFINE_UNQUOTED(COPYRIGHT_YEARS, "${COPYRIGHT_YEARS}", [The copyright years])
 AC_DEFINE_UNQUOTED(CONFIGURE_LINE, "${CONFIGURE_LINE}", [The ./configure command line])
 AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MAJOR,"${VERSION_MAJOR}", [version major number])
 AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MINOR,"${VERSION_MINOR}", [version minor number])
@@ -5914,28 +6044,21 @@ AC_SUBST(VERSION_MAJOR)
 AC_SUBST(VERSION_MINOR)
 AC_SUBST(VERSION_REVISION)
 AC_DEFINE_UNQUOTED(VLC_COMPILE_BY, "`whoami`", [user who ran configure]) 
-AC_DEFINE_UNQUOTED(VLC_COMPILE_HOST, "`hostname`", [host which ran configure]) 
+if test "${SYS}" = "cygwin"
+then
+    AC_DEFINE_UNQUOTED(VLC_COMPILE_HOST, "`hostname`", [host which ran configure])
+else
+    AC_DEFINE_UNQUOTED(VLC_COMPILE_HOST, "`hostname -s`", [host which ran configure])
+fi
 AC_DEFINE_UNQUOTED(VLC_COMPILE_DOMAIN, "`dnsdomainname 2>/dev/null || domainname 2>/dev/null || echo unknown`", [domain of the host which ran configure]) 
 AC_DEFINE_UNQUOTED(VLC_COMPILER, "`$CC -v 2>&1 | tail -n 1`", [compiler]) 
 
-dnl Old definitions for version-dependant plugins
-dnl VLC_SYMBOL="`echo ${VERSION} | sed -e 'y/.-+/___/'`"
-dnl AC_DEFINE_UNQUOTED(MODULE_SUFFIX, "__${VLC_SYMBOL}", [String suffix for module functions])
-dnl AC_DEFINE_UNQUOTED(MODULE_SYMBOL, ${VLC_SYMBOL}, [Symbol suffix for module functions])
-
-dnl New definitions with value matching 0.9.0 release
-module_symbol="0_9_0b"
-AC_DEFINE_UNQUOTED(MODULE_SUFFIX, "__${module_symbol}", [String suffix for module functions])
-AC_DEFINE_UNQUOTED(MODULE_SYMBOL, $module_symbol, [Symbol suffix for module functions])
-VLC_ENTRY="vlc_entry__${module_symbol}"
-AC_SUBST(VLC_ENTRY)
-
 dnl
 dnl  Handle substvars that use $(top_srcdir)
 dnl
 VLC_CONFIG="top_builddir=\"\$(top_builddir)\" \$(top_builddir)/vlc-config"
 AC_SUBST(VLC_CONFIG)
-CPPFLAGS_save="${CPPFLAGS_save} -I\$(top_srcdir)/include"
+CPPFLAGS_save="${CPPFLAGS_save} -I\$(top_srcdir)/include -I\$(top_builddir)/include"
 
 dnl
 dnl  Restore *FLAGS
@@ -5962,12 +6085,9 @@ AC_SUBST(MOZILLA_SDK_PATH)
 AC_SUBST(WINE_SDK_PATH)
 AC_SUBST(LIBEXT)
 AC_SUBST(AM_CPPFLAGS)
-AC_SUBST(ALL_LINGUAS)
 AC_SUBST(MACOSX_DEPLOYMENT_TARGET)
 AC_SUBST(FILE_LIBVLC_DLL)
-
-dnl Import substitutions generated by bootstrap
-VLC_SUBSTS
+AC_SUBST(FILE_LIBVLC_CONTROL_DLL)
 
 dnl Create vlc-config.in
 VLC_OUTPUT_VLC_CONFIG_IN
@@ -6002,6 +6122,7 @@ AC_CONFIG_FILES([
   modules/access/mms/Makefile
   modules/access/cdda/Makefile
   modules/access/rtsp/Makefile
+  modules/access/v4l2/Makefile
   modules/access/vcd/Makefile
   modules/access/vcdx/Makefile
   modules/access/screen/Makefile
@@ -6011,12 +6132,14 @@ AC_CONFIG_FILES([
   modules/audio_filter/channel_mixer/Makefile
   modules/audio_filter/converter/Makefile
   modules/audio_filter/resampler/Makefile
+  modules/audio_filter/spatializer/Makefile
   modules/audio_mixer/Makefile
   modules/audio_output/Makefile
   modules/codec/Makefile
   modules/codec/cmml/Makefile
   modules/codec/dmo/Makefile
   modules/codec/ffmpeg/Makefile
+  modules/codec/subtitles/Makefile
   modules/codec/spudec/Makefile
   modules/codec/xvmc/Makefile
   modules/control/Makefile
@@ -6031,6 +6154,7 @@ AC_CONFIG_FILES([
   modules/gui/beos/Makefile
   modules/gui/pda/Makefile
   modules/gui/macosx/Makefile
+  modules/gui/minimal_macosx/Makefile
   modules/gui/qnx/Makefile
   modules/gui/qt4/Makefile
   modules/gui/skins2/Makefile
@@ -6039,10 +6163,12 @@ AC_CONFIG_FILES([
   modules/meta_engine/Makefile
   modules/misc/Makefile
   modules/misc/dummy/Makefile
+  modules/misc/lua/Makefile
   modules/misc/memcpy/Makefile
   modules/misc/notify/Makefile
   modules/misc/testsuite/Makefile
   modules/misc/playlist/Makefile
+  modules/misc/osd/Makefile
   modules/misc/xml/Makefile
   modules/misc/probe/Makefile
   modules/mux/Makefile
@@ -6101,7 +6227,16 @@ echo "
 vlc aliases           :${ALIASES}
 plugins/bindings      :${PLUGINS_BINDINGS}
 
+You can check which modules have been enabled 
+with \`./vlc-config --list plugin'.
 You can tune the compiler flags in vlc-config.
 To build vlc and its plugins, type \`./compile' or \`make'.
 "
-
+if test "x$ac_ld_does_not_support_text_reloc" = "xyes"; then
+   echo ""
+   echo "Warning: Due to a bug in ld, mmx/sse support has been"
+   echo "         turned off."
+   echo "         FFmpeg will be REALLY slow."
+   echo "         VLC WILL NOT PERFORM AS EXPECTED."
+   echo ""
+fi