Index: browser-plugin/Makefile.am
===================================================================
--- browser-plugin/Makefile.am	(revision 4446)
+++ browser-plugin/Makefile.am	(working copy)
@@ -145,6 +145,7 @@
 
 libtotem_basic_plugin_la_CXXFLAGS = \
 	$(BROWSER_PLUGIN_CFLAGS)	\
+	$(MOZILLA_EXTRA_CXXFLAGS)       \
 	$(MOZILLA_XPCOM_CFLAGS)		\
 	$(DBUS_CFLAGS)			\
 	$(WARN_CXXFLAGS)		\
@@ -213,6 +214,7 @@
 
 libtotem_gmp_plugin_la_CXXFLAGS = \
 	$(BROWSER_PLUGIN_CFLAGS)	\
+	$(MOZILLA_EXTRA_CXXFLAGS)       \
 	$(MOZILLA_XPCOM_CFLAGS)		\
 	$(DBUS_CFLAGS)			\
 	$(WARN_CXXFLAGS)		\
@@ -275,6 +277,7 @@
 
 libtotem_complex_plugin_la_CXXFLAGS = \
 	$(BROWSER_PLUGIN_CFLAGS)	\
+	$(MOZILLA_EXTRA_CXXFLAGS)       \
 	$(MOZILLA_XPCOM_CFLAGS)		\
 	$(DBUS_CFLAGS)			\
 	$(WARN_CXXFLAGS)		\
@@ -337,6 +340,7 @@
 
 libtotem_narrowspace_plugin_la_CXXFLAGS = \
 	$(BROWSER_PLUGIN_CFLAGS)	\
+	$(MOZILLA_EXTRA_CXXFLAGS)       \
 	$(MOZILLA_XPCOM_CFLAGS)		\
 	$(DBUS_CFLAGS)			\
 	$(WARN_CXXFLAGS)		\
@@ -399,6 +403,7 @@
 
 libtotem_mully_plugin_la_CXXFLAGS = \
 	$(BROWSER_PLUGIN_CFLAGS)	\
+	$(MOZILLA_EXTRA_CXXFLAGS)       \
 	$(MOZILLA_XPCOM_CFLAGS)		\
 	$(DBUS_CFLAGS)			\
 	$(WARN_CXXFLAGS)		\
Index: configure.in
===================================================================
--- configure.in	(revision 4446)
+++ configure.in	(working copy)
@@ -453,6 +453,46 @@
 
 AM_CONDITIONAL([ENABLE_BROWSER_PLUGINS], [test "$enable_browser_plugins" = "yes"])
 
+# Checks for -fshort-wchar compiler variable, and adds it to
+# MOZILLA_XPCOM_CFLAGS if found
+
+# **************************************************************
+# This is really gcc-only
+# Do this test using CXX only since some versions of gcc
+# 2.95-2.97 have a signed wchar_t in c++ only and some versions
+# only have short-wchar support for c++.
+# **************************************************************
+
+MOZILLA_EXTRA_CXXFLAGS=
+
+if test "$enable_browser_plugins" = "yes" ; then
+	AC_LANG_PUSH([C++])
+
+	_SAVE_CXXFLAGS=$CXXFLAGS
+	CXXFLAGS="$CXXFLAGS $_GECKO_EXTRA_CXXFLAGS -fshort-wchar"
+
+	AC_CACHE_CHECK([for compiler -fshort-wchar option],
+	        gecko_cv_have_usable_wchar_option,
+	        [AC_RUN_IFELSE([AC_LANG_SOURCE(
+	                [[#include <stddef.h>
+	                  int main () {
+	                    return (sizeof(wchar_t) != 2) || (wchar_t)-1 < (wchar_t) 0 ;
+	                  } ]])],
+	                [gecko_cv_have_usable_wchar_option="yes"],
+	                [gecko_cv_have_usable_wchar_option="no"],
+	                [gecko_cv_have_usable_wchar_option="maybe (cross-compiling)"])])
+
+	CXXFLAGS="$_SAVE_CXXFLAGS"
+
+	AC_LANG_POP([C++])
+
+	if test "$gecko_cv_have_usable_wchar_option" = "yes"; then
+	        MOZILLA_EXTRA_CXXFLAGS="-fshort-wchar"
+	fi
+fi
+
+AC_SUBST(MOZILLA_EXTRA_CXXFLAGS)
+
 # check for libxpcomglue_s
 
 LIBXPCOMGLUE_S=
@@ -467,7 +507,7 @@
 	CPPFLAGS="$CPPFLAGS -I$MOZILLA_INCLUDE_ROOT"
 	CXXFLAGS="$CXXFLAGS $MOZILLA_NOT_LINKED_CFLAGS"
 	LIBS="$LIBS -L$MOZILLA_LIBDIR -lxpcom -lxpcomglue_s"
-	LDFLAGS="$LDFLAGS -Wl,--rpath -Wl,$MOZILLA_LIBDIR"
+	LDFLAGS="$LDFLAGS $MOZILLA_EXTRA_CXXFLAGS -Wl,--rpath -Wl,$MOZILLA_LIBDIR"
 
 	AC_MSG_CHECKING([for libxpcomglue_s])
 	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
@@ -488,7 +528,7 @@
 	AC_LANG_POP([C++])
 
 	if test "$have_libxpcomglue_s" = "yes"; then
-		LIBXPCOMGLUE_S="-L$MOZILLA_LIBDIR -lxpcomglue_s"
+		LIBXPCOMGLUE_S="-L$MOZILLA_LIBDIR -lxpcom -lxpcomglue_s"
 	else
 		AC_MSG_WARN([libxpcomglue_s not available; plugins may not be portable])
 	fi
@@ -520,7 +560,7 @@
 if test "$enable_browser_plugins" = "yes"; then
 	AC_LANG_PUSH([C++])
 	__SAVE_CPPFLAGS=$CPPFLAGS
-	CPPFLAGS="$CPPFLAGS $MOZILLA_NOT_LINKED_CFLAGS -I$MOZILLA_INCLUDE_ROOT/xpcom"
+	CPPFLAGS="$CPPFLAGS $MOZILLA_NOT_LINKED_CFLAGS $MOZILLA_EXTRA_CXXFLAGS -I$MOZILLA_INCLUDE_ROOT/xpcom"
 
 	AC_CHECK_HEADERS([nsTArray.h])
 
