Bug 915735 - Build ICU as a shared library where JS is built as a shared library; r=glandium
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 06 Dec 2013 08:08:52 -0500
changeset 159196 b0678affef0368b037bd9d2c07d54c287451bacb
parent 159195 5118bd7f09548a09383473e2a5e4bb8fc68bd601
child 159197 be257c6d6d2400fa30cea3744df0f7a05fc7876f
push id3840
push userryanvm@gmail.com
push dateFri, 06 Dec 2013 21:04:37 +0000
treeherderfx-team@b3806ae5399d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs915735
milestone28.0a1
Bug 915735 - Build ICU as a shared library where JS is built as a shared library; r=glandium
CLOBBER
aclocal.m4
browser/installer/Makefile.in
browser/installer/package-manifest.in
build/autoconf/icu.m4
config/moz.build
config/system-headers
configure.in
intl/icu-patches/bug-915735
intl/icu/source/config/mh-darwin
js/src/Makefile.in
js/src/aclocal.m4
js/src/build/autoconf/icu.m4
js/src/config/moz.build
js/src/config/system-headers
js/src/configure.in
js/src/gdb/Makefile.in
js/src/jsapi-tests/Makefile.in
js/src/shell/Makefile.in
toolkit/library/Makefile.in
toolkit/mozapps/installer/packager.mk
--- a/CLOBBER
+++ b/CLOBBER
@@ -13,9 +13,9 @@
 #          |               |
 #          O <-- Clobber   O  <-- Clobber
 #
 # Note: The description below will be part of the error message shown to users.
 #
 # Modifying this file will now automatically clobber the buildbot machines \o/
 #
 
-Bug 947080 - bug 937317 required clobber on windows
+Bug 915735 requires clobber
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -25,16 +25,17 @@ builtin(include, build/autoconf/frameptr
 builtin(include, build/autoconf/compiler-opts.m4)dnl
 builtin(include, build/autoconf/expandlibs.m4)dnl
 builtin(include, build/autoconf/arch.m4)dnl
 builtin(include, build/autoconf/android.m4)dnl
 builtin(include, build/autoconf/zlib.m4)dnl
 builtin(include, build/autoconf/linux.m4)dnl
 builtin(include, build/autoconf/python-virtualenv.m4)dnl
 builtin(include, build/autoconf/winsdk.m4)dnl
+builtin(include, build/autoconf/icu.m4)dnl
 
 MOZ_PROG_CHECKMSYS()
 
 # Read the user's .mozconfig script.  We can't do this in
 # configure.in: autoconf puts the argument parsing code above anything
 # expanded from configure.in, and we need to get the configure options
 # from .mozconfig in place before that argument parsing code.
 MOZ_READ_MOZCONFIG(.)
--- a/browser/installer/Makefile.in
+++ b/browser/installer/Makefile.in
@@ -106,16 +106,21 @@ ifeq (bundle, $(MOZ_FS_LAYOUT))
 BINPATH = $(_BINPATH)
 DEFINES += -DAPPNAME=$(_APPNAME)
 else
 # Every other platform just winds up in dist/bin
 BINPATH = bin
 endif
 DEFINES += -DBINPATH=$(BINPATH)
 
+DEFINES += -DMOZ_ICU_VERSION=$(MOZ_ICU_VERSION)
+ifdef MOZ_SHARED_ICU
+DEFINES += -DMOZ_SHARED_ICU
+endif
+
 libs::
 	$(MAKE) -C $(DEPTH)/browser/locales langpack
 
 ifeq (WINNT,$(OS_ARCH))
 PKGCOMP_FIND_OPTS =
 else
 PKGCOMP_FIND_OPTS = -L
 endif
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -96,16 +96,37 @@
 @BINPATH@/msvcp120.dll
 @BINPATH@/msvcr120.dll
 #ifdef MOZ_METRO
 @BINPATH@/vccorlib120.dll
 #endif
 #endif
 #endif
 #endif
+#ifdef MOZ_SHARED_ICU
+#ifdef XP_WIN
+#ifdef MOZ_DEBUG
+@BINPATH@/icudtd@MOZ_ICU_VERSION@.dll
+@BINPATH@/icuind@MOZ_ICU_VERSION@.dll
+@BINPATH@/icuucd@MOZ_ICU_VERSION@.dll
+#else
+@BINPATH@/icudt@MOZ_ICU_VERSION@.dll
+@BINPATH@/icuin@MOZ_ICU_VERSION@.dll
+@BINPATH@/icuuc@MOZ_ICU_VERSION@.dll
+#endif
+#elif defined(XP_MACOSX)
+@BINPATH@/libicudata.@MOZ_ICU_VERSION@.dylib
+@BINPATH@/libicui18n.@MOZ_ICU_VERSION@.dylib
+@BINPATH@/libicuuc.@MOZ_ICU_VERSION@.dylib
+#elif defined(XP_UNIX)
+@BINPATH@/libicudata.so.@MOZ_ICU_VERSION@
+@BINPATH@/libicui18n.so.@MOZ_ICU_VERSION@
+@BINPATH@/libicuuc.so.@MOZ_ICU_VERSION@
+#endif
+#endif
 
 [browser]
 ; [Base Browser Files]
 #ifndef XP_UNIX
 @BINPATH@/@MOZ_APP_NAME@.exe
 #else
 @BINPATH@/@MOZ_APP_NAME@-bin
 @BINPATH@/@MOZ_APP_NAME@
new file mode 100644
--- /dev/null
+++ b/build/autoconf/icu.m4
@@ -0,0 +1,31 @@
+dnl This Source Code Form is subject to the terms of the Mozilla Public
+dnl License, v. 2.0. If a copy of the MPL was not distributed with this
+dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+dnl Set the MOZ_ICU_VERSION variable to denote the current version of the
+dnl ICU library, and also the MOZ_SHARED_ICU which would be true if we are
+dnl linking against a shared library of ICU, either one that we build from
+dnl our copy of ICU or the system provided library.
+
+AC_DEFUN([MOZ_CONFIG_ICU], [
+    icudir="$_topsrcdir/intl/icu/source"
+    if test ! -d "$icudir"; then
+        icudir="$_topsrcdir/../../intl/icu/source"
+        if test ! -d "$icudir"; then
+            AC_MSG_ERROR([Cannot find the ICU directory])
+        fi
+    fi
+
+    version=`sed -n 's/^[[:space:]]*#[[:space:]]*define[[:space:]][[:space:]]*U_ICU_VERSION_MAJOR_NUM[[:space:]][[:space:]]*\([0-9][0-9]*\)[[:space:]]*$/\1/p' "$icudir/common/unicode/uvernum.h"`
+    if test x"$version" = x; then
+       AC_MSG_ERROR([cannot determine icu version number from uvernum.h header file $lineno])
+    fi
+    MOZ_ICU_VERSION="$version"
+
+    if test -n "${JS_SHARED_LIBRARY}${MOZ_NATIVE_ICU}"; then
+        MOZ_SHARED_ICU=1
+    fi
+
+    AC_SUBST(MOZ_ICU_VERSION)
+    AC_SUBST(MOZ_SHARED_ICU)
+])
--- a/config/moz.build
+++ b/config/moz.build
@@ -22,8 +22,11 @@ if CONFIG['HOST_OS_ARCH'] != 'WINNT':
     HOST_SOURCES += [
         'nsinstall.c',
         'pathsub.c',
     ]
     HOST_PROGRAM = 'nsinstall_real'
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     DEFINES['GKMEDIAS_SHARED_LIBRARY'] = True
+
+if CONFIG['MOZ_SHARED_ICU']:
+    DEFINES['MOZ_SHARED_ICU'] = True
--- a/config/system-headers
+++ b/config/system-headers
@@ -1126,17 +1126,17 @@ gst/video/video.h
 sys/msg.h
 sys/ipc.h
 sys/thr.h
 sys/user.h
 kvm.h
 spawn.h
 err.h
 xlocale.h
-#if MOZ_NATIVE_ICU==1
+#ifdef MOZ_SHARED_ICU
 unicode/locid.h
 unicode/numsys.h
 unicode/ucal.h
 unicode/uclean.h
 unicode/ucol.h
 unicode/udat.h
 unicode/udatpg.h
 unicode/uenum.h
--- a/configure.in
+++ b/configure.in
@@ -3891,16 +3891,27 @@ if test -n "$MOZ_NATIVE_FFI"; then
     if test -z "$GNU_CC"; then
         PKG_CHECK_MODULES(MOZ_FFI, libffi > 3.0.9)
     else
         PKG_CHECK_MODULES(MOZ_FFI, libffi >= 3.0.9)
     fi
     MOZ_JS_STATIC_LIBS="$MOZ_JS_STATIC_LIBS $MOZ_FFI_LIBS"
 fi
 
+# split JS out by default to avoid VS2005 PGO crash (bug 591836).
+if test "$OS_ARCH" = "WINNT"; then
+  JS_SHARED_LIBRARY=1
+fi
+
+MOZ_ARG_ENABLE_BOOL(shared-js,
+[  --enable-shared-js
+                          Create a shared JavaScript library.],
+    JS_SHARED_LIBRARY=1,
+    JS_SHARED_LIBRARY=)
+
 dnl ========================================================
 dnl System ICU Support
 dnl ========================================================
 MOZ_NATIVE_ICU=
 MOZ_ARG_WITH_BOOL(system-icu,
 [  --with-system-icu
                           Use system ICU (located with pkgconfig)],
     MOZ_NATIVE_ICU=1)
@@ -7721,29 +7732,17 @@ fi
 
 dnl ========================================================
 dnl =
 dnl = Static Build Options
 dnl =
 dnl ========================================================
 MOZ_ARG_HEADER(Static build options)
 
-# split JS out by default to avoid VS2005 PGO crash (bug 591836).
-if test "$OS_ARCH" = "WINNT"; then
-  ENABLE_SHARED_JS=1
-fi
-
-MOZ_ARG_ENABLE_BOOL(shared-js,
-[  --enable-shared-js
-                          Create a shared JavaScript library.],
-    ENABLE_SHARED_JS=1,
-    ENABLE_SHARED_JS=)
-
-if test -n "$ENABLE_SHARED_JS"; then
-  JS_SHARED_LIBRARY=1
+if test -n "$JS_SHARED_LIBRARY"; then
   MOZ_JS_LIBS="$MOZ_JS_SHARED_LIBS"
 else
   MOZ_JS_LIBS="$MOZ_JS_STATIC_LIBS"
   AC_DEFINE(MOZ_STATIC_JS)
 fi
 AC_SUBST(JS_SHARED_LIBRARY)
 
 AC_SUBST(LIBXUL_LIBS)
@@ -8782,16 +8781,91 @@ HAVE_STATFS
 HAVE_SYS_STATVFS_H
 HAVE_SYS_STATFS_H
 HAVE_SYS_VFS_H
 HAVE_SYS_MOUNT_H
 "
 
 AC_SUBST(STLPORT_LIBS)
 
+MOZ_ARG_WITH_STRING(intl-api,
+[  --with-intl-api, --with-intl-api=build, --without-intl-api
+    Determine the status of the ECMAScript Internationalization API.  The first
+    (or lack of any of these) builds and exposes the API.  The second builds it
+    but doesn't use ICU or expose the API to script.  The third doesn't build
+    ICU at all.],
+    _INTL_API=$withval,
+    _INTL_API=yes)
+
+WITH_INTL="--with-intl-api=$_INTL_API"
+ENABLE_INTL_API=
+case "$_INTL_API" in
+no)
+    ;;
+build)
+    ENABLE_INTL_API=1
+    ;;
+yes)
+    ENABLE_INTL_API=1
+    ;;
+*)
+    AC_MSG_ERROR([Invalid value passed to --with-intl-api: $_INTL_API])
+    ;;
+esac
+
+if test -n "$ENABLE_INTL_API"; then
+if test "$MOZ_BUILD_APP" = "browser"; then
+    WITH_INTL="--with-intl-api"
+else
+    # Internationalization isn't built or exposed by default in non-desktop
+    # builds.  Bugs to enable:
+    #
+    #   Android:  bug 864843
+    #   B2G:      bug 866301
+    WITH_INTL="--without-intl-api"
+    ENABLE_INTL_API=
+fi
+fi
+
+dnl Settings for the implementation of the ECMAScript Internationalization API
+if test -n "$ENABLE_INTL_API"; then
+    AC_DEFINE(ENABLE_INTL_API)
+
+    MOZ_CONFIG_ICU()
+
+    dnl Build ICU as a shared library for shared js builds.
+    if test -z "$MOZ_NATIVE_ICU" -a -n "$JS_SHARED_LIBRARY"; then
+        case "$OS_TARGET" in
+            WINNT)
+                ICU_LIB_NAMES="icuin icuuc icudt"
+                DBG_SUFFIX=
+                if test -n "$MOZ_DEBUG"; then
+                    DBG_SUFFIX=d
+                fi
+                MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/js/src/intl/icu/target/lib/$(LIB_PREFIX)$(lib)$(DBG_SUFFIX).$(LIB_SUFFIX))'
+                ;;
+            Darwin)
+                ICU_LIB_NAMES="icui18n icuuc icudata"
+                MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/js/src/intl/icu/target/lib/$(DLL_PREFIX)$(lib).$(MOZ_ICU_VERSION)$(DLL_SUFFIX))'
+                ;;
+            Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
+                ICU_LIB_NAMES="icui18n icuuc icudata"
+                MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/js/src/intl/icu/target/lib/$(DLL_PREFIX)$(lib)$(DLL_SUFFIX).$(MOZ_ICU_VERSION))'
+                ;;
+            *)
+                AC_MSG_ERROR([ECMAScript Internationalization API is not yet supported on this platform])
+        esac
+    fi
+fi
+
+AC_SUBST(DBG_SUFFIX)
+AC_SUBST(ENABLE_INTL_API)
+AC_SUBST(ICU_LIB_NAMES)
+AC_SUBST(MOZ_ICU_LIBS)
+
 export WRITE_MOZINFO=1
 AC_OUTPUT()
 unset WRITE_MOZINFO
 
 # Hack around an Apple bug that affects the egrep that comes with OS X 10.7.
 # "env ARCHPREFERENCE=i386,x86_64 arch egrep" first tries to use the 32-bit
 # Intel part of the egrep fat binary, even on 64-bit systems, and falls back on
 # the 64-bit part if it's not a fat binary, as can happen with MacPorts. We
@@ -9155,36 +9229,16 @@ if test -n "$ENABLE_CLANG_PLUGIN"; then
 fi
 
 
 # Run the SpiderMonkey 'configure' script.
 dist=$MOZ_BUILD_ROOT/dist
 ac_configure_args="$_SUBDIR_CONFIG_ARGS"
 ac_configure_args="$ac_configure_args --enable-threadsafe"
 
-MOZ_ARG_WITH_STRING(intl-api,
-[  --with-intl-api, --with-intl-api=build, --without-intl-api
-    Determine the status of the ECMAScript Internationalization API.  The first
-    (or lack of any of these) builds and exposes the API.  The second builds it
-    but doesn't use ICU or expose the API to script.  The third doesn't build
-    ICU at all.],
-    WITH_INTL="--with-intl-api=$withval"
-)
-if test -z "$WITH_INTL"; then
-if test "$MOZ_BUILD_APP" = "browser"; then
-    WITH_INTL="--with-intl-api"
-else
-    # Internationalization isn't built or exposed by default in non-desktop
-    # builds.  Bugs to enable:
-    #
-    #   Android:  bug 864843
-    #   B2G:      bug 866301
-    WITH_INTL="--without-intl-api"
-fi
-fi
 ac_configure_args="$ac_configure_args $WITH_INTL"
 
 if test "$BUILD_CTYPES"; then
     # Build js-ctypes on the platforms we can.
     ac_configure_args="$ac_configure_args --enable-ctypes"
 fi
 if test -z "$JS_SHARED_LIBRARY" ; then
     ac_configure_args="$ac_configure_args --disable-shared-js"
new file mode 100644
--- /dev/null
+++ b/intl/icu-patches/bug-915735
@@ -0,0 +1,29 @@
+Bug 915735 - Fix linking the ICU libraries on Mac
+
+diff --git a/intl/icu/source/config/mh-darwin b/intl/icu/source/config/mh-darwin
+index 97d6bfc..fe1490e 100644
+--- a/intl/icu/source/config/mh-darwin
++++ b/intl/icu/source/config/mh-darwin
+@@ -23,21 +23,17 @@ ARFLAGS += -c
+ COMPILE.c=	$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -fno-common -c
+ COMPILE.cc=	$(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) -fno-common -c
+ 
+ ## Commands to make a shared library
+ SHLIB.c=	$(CC) -dynamiclib -dynamic $(CFLAGS) $(LDFLAGS) $(LD_SOOPTIONS)
+ SHLIB.cc=	$(CXX) -dynamiclib -dynamic $(CXXFLAGS) $(LDFLAGS) $(LD_SOOPTIONS)
+ 
+ ## Compiler switches to embed a library name and version information
+-ifeq ($(ENABLE_RPATH),YES)
+-LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(libdir)/$(notdir $(MIDDLE_SO_TARGET))
+-else
+-LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(notdir $(MIDDLE_SO_TARGET))
+-endif
++LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name @executable_path/$(notdir $(MIDDLE_SO_TARGET))
+ 
+ ## Compiler switch to embed a runtime search path
+ LD_RPATH=
+ LD_RPATH_PRE= -Wl,-rpath,
+ 
+ ## Environment variable to set a runtime search path
+ LDLIBRARYPATH_ENVVAR = DYLD_LIBRARY_PATH
+ 
--- a/intl/icu/source/config/mh-darwin
+++ b/intl/icu/source/config/mh-darwin
@@ -23,21 +23,17 @@ ARFLAGS += -c
 COMPILE.c=	$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -fno-common -c
 COMPILE.cc=	$(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) -fno-common -c
 
 ## Commands to make a shared library
 SHLIB.c=	$(CC) -dynamiclib -dynamic $(CFLAGS) $(LDFLAGS) $(LD_SOOPTIONS)
 SHLIB.cc=	$(CXX) -dynamiclib -dynamic $(CXXFLAGS) $(LDFLAGS) $(LD_SOOPTIONS)
 
 ## Compiler switches to embed a library name and version information
-ifeq ($(ENABLE_RPATH),YES)
-LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(libdir)/$(notdir $(MIDDLE_SO_TARGET))
-else
-LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(notdir $(MIDDLE_SO_TARGET))
-endif
+LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name @executable_path/$(notdir $(MIDDLE_SO_TARGET))
 
 ## Compiler switch to embed a runtime search path
 LD_RPATH=
 LD_RPATH_PRE= -Wl,-rpath,
 
 ## Environment variable to set a runtime search path
 LDLIBRARYPATH_ENVVAR = DYLD_LIBRARY_PATH
 
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -114,16 +114,54 @@ ifdef HAVE_DTRACE
 export_files += $(CURDIR)/javascript-trace.h
 endif
 
 INSTALL_TARGETS += jsconfig
 jsconfig_FILES = $(export_files)
 jsconfig_DEST = $(DIST)/include
 jsconfig_TARGET := export
 
+# Ensure that this happens before using $(MOZ_PSEUDO_DERECURSE)
+include $(topsrcdir)/config/config.mk
+
+# Ensure that this happens before including rules.mk
+ifdef ENABLE_INTL_API
+ifndef MOZ_NATIVE_ICU
+ifeq ($(OS_ARCH),WINNT)
+  # Library names: On Windows, ICU uses modified library names for static
+  # and debug libraries.
+  ifdef MOZ_DEBUG
+    ICU_LIB_SUFFIX=d
+  endif
+  ifdef JS_SHARED_LIBRARY
+    ICU_FILES := $(foreach libname,$(ICU_LIB_NAMES),intl/icu/target/lib/$(libname)$(ICU_LIB_SUFFIX)$(MOZ_ICU_VERSION).dll)
+  else
+    ICU_LIB_RENAME = $(foreach libname,$(ICU_LIB_NAMES),\
+                       cp -p intl/icu/target/lib/s$(libname)$(ICU_LIB_SUFFIX).lib intl/icu/target/lib/$(libname).lib;)
+  endif
+else
+  ifeq ($(OS_ARCH),Darwin)
+    ifdef JS_SHARED_LIBRARY
+      ICU_FILES := $(foreach libname,$(ICU_LIB_NAMES),intl/icu/target/lib/$(DLL_PREFIX)$(libname).$(MOZ_ICU_VERSION)$(DLL_SUFFIX))
+    endif
+  else
+    ifdef JS_SHARED_LIBRARY
+      ICU_FILES := $(foreach libname,$(ICU_LIB_NAMES),intl/icu/target/lib/$(DLL_PREFIX)$(libname)$(DLL_SUFFIX).$(MOZ_ICU_VERSION))
+    endif
+  endif
+endif
+ifdef ICU_FILES
+  ICU_DEST := $(DIST)/bin
+  INSTALL_TARGETS += ICU
+  $(ICU_FILES): buildicu
+  ICU_TARGET := $(if $(MOZ_PSEUDO_DERECURSE),compile,export)
+endif
+endif
+endif
+
 include $(topsrcdir)/config/rules.mk
 
 .PHONY: buildffi buildicu
 buildffi buildicu:
 $(if $(MOZ_PSEUDO_DERECURSE),compile,export):: buildffi buildicu
 
 ifdef JS_HAS_CTYPES
 ifndef MOZ_NATIVE_FFI
@@ -150,24 +188,31 @@ LOCAL_INCLUDES += \
   -I$(topsrcdir)/../../intl/icu/source/common \
   -I$(topsrcdir)/../../intl/icu/source/i18n \
   $(NULL)
 endif
 
 ifdef ENABLE_INTL_API
 ifndef MOZ_NATIVE_ICU
 
-ifeq ($(OS_ARCH),WINNT)
-  # Library names: On Windows, ICU uses modified library names for static
-  # and debug libraries.
-  ifdef MOZ_DEBUG
-    ICU_LIB_SUFFIX=d
-  endif
-  ICU_LIB_RENAME = $(foreach libname,$(ICU_LIB_NAMES),\
-                     cp -p intl/icu/target/lib/s$(libname)$(ICU_LIB_SUFFIX).lib intl/icu/target/lib/$(libname).lib;)
+ifdef _MSC_VER
+OS_LIBS += $(call EXPAND_LIBNAME,delayimp)
+ifdef MOZ_DEBUG
+EXTRA_DSO_LDOPTS += \
+  -DELAYLOAD:icudtd$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuind$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuucd$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+else
+EXTRA_DSO_LDOPTS += \
+  -DELAYLOAD:icudt$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuin$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuuc$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+endif
 endif
 
 ifdef .PYMAKE
 ICU_MAKE = $(GMAKE)
 else
 ICU_MAKE = $(MAKE)
 endif
 
@@ -318,17 +363,17 @@ CFLAGS += $(MOZ_ZLIB_CFLAGS)
 EXTRA_LIBS += $(MOZ_ZLIB_LIBS)
 # Enable zlib usage if zlib has been located. When building the browser on
 # Windows, MOZ_ZLIB_LIBS is empty because zlib is part of libmozglue. We thus
 # also enable zlib if mozglue is present.
 ifneq (,$(MOZ_ZLIB_LIBS)$(MOZ_GLUE_LDFLAGS))
 DEFINES += -DUSE_ZLIB
 endif
 
-ifdef MOZ_NATIVE_ICU
+ifdef MOZ_SHARED_ICU
 EXTRA_DSO_LDOPTS += $(MOZ_ICU_LIBS)
 else
 SHARED_LIBRARY_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 # Prevent floating point errors caused by VC++ optimizations
 ifdef _MSC_VER
 # XXX We should add this to CXXFLAGS, too?
--- a/js/src/aclocal.m4
+++ b/js/src/aclocal.m4
@@ -24,10 +24,11 @@ builtin(include, build/autoconf/frameptr
 builtin(include, build/autoconf/compiler-opts.m4)dnl
 builtin(include, build/autoconf/expandlibs.m4)dnl
 builtin(include, build/autoconf/arch.m4)dnl
 builtin(include, build/autoconf/android.m4)dnl
 builtin(include, build/autoconf/zlib.m4)dnl
 builtin(include, build/autoconf/linux.m4)dnl
 builtin(include, build/autoconf/python-virtualenv.m4)dnl
 builtin(include, build/autoconf/winsdk.m4)dnl
+builtin(include, build/autoconf/icu.m4)dnl
 
 MOZ_PROG_CHECKMSYS()
new file mode 100644
--- /dev/null
+++ b/js/src/build/autoconf/icu.m4
@@ -0,0 +1,31 @@
+dnl This Source Code Form is subject to the terms of the Mozilla Public
+dnl License, v. 2.0. If a copy of the MPL was not distributed with this
+dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+dnl Set the MOZ_ICU_VERSION variable to denote the current version of the
+dnl ICU library, and also the MOZ_SHARED_ICU which would be true if we are
+dnl linking against a shared library of ICU, either one that we build from
+dnl our copy of ICU or the system provided library.
+
+AC_DEFUN([MOZ_CONFIG_ICU], [
+    icudir="$_topsrcdir/intl/icu/source"
+    if test ! -d "$icudir"; then
+        icudir="$_topsrcdir/../../intl/icu/source"
+        if test ! -d "$icudir"; then
+            AC_MSG_ERROR([Cannot find the ICU directory])
+        fi
+    fi
+
+    version=`sed -n 's/^[[:space:]]*#[[:space:]]*define[[:space:]][[:space:]]*U_ICU_VERSION_MAJOR_NUM[[:space:]][[:space:]]*\([0-9][0-9]*\)[[:space:]]*$/\1/p' "$icudir/common/unicode/uvernum.h"`
+    if test x"$version" = x; then
+       AC_MSG_ERROR([cannot determine icu version number from uvernum.h header file $lineno])
+    fi
+    MOZ_ICU_VERSION="$version"
+
+    if test -n "${JS_SHARED_LIBRARY}${MOZ_NATIVE_ICU}"; then
+        MOZ_SHARED_ICU=1
+    fi
+
+    AC_SUBST(MOZ_ICU_VERSION)
+    AC_SUBST(MOZ_SHARED_ICU)
+])
--- a/js/src/config/moz.build
+++ b/js/src/config/moz.build
@@ -19,8 +19,11 @@ if CONFIG['HOST_OS_ARCH'] != 'WINNT':
         'nsinstall.c',
         'pathsub.c',
     ]
     HOST_PROGRAM = 'nsinstall_real'
 
 # Force wrap zlib system header if building js as a shared library.
 if CONFIG['JS_SHARED_LIBRARY'] or CONFIG['MOZ_NATIVE_ZLIB']:
     DEFINES['MOZ_NATIVE_ZLIB'] = 1
+
+if CONFIG['MOZ_SHARED_ICU']:
+    DEFINES['MOZ_SHARED_ICU'] = True
--- a/js/src/config/system-headers
+++ b/js/src/config/system-headers
@@ -1126,17 +1126,17 @@ gst/video/video.h
 sys/msg.h
 sys/ipc.h
 sys/thr.h
 sys/user.h
 kvm.h
 spawn.h
 err.h
 xlocale.h
-#if MOZ_NATIVE_ICU==1
+#ifdef MOZ_SHARED_ICU
 unicode/locid.h
 unicode/numsys.h
 unicode/ucal.h
 unicode/uclean.h
 unicode/ucol.h
 unicode/udat.h
 unicode/udatpg.h
 unicode/uenum.h
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -4202,40 +4202,65 @@ esac
 if test -n "$EXPOSE_INTL_API"; then
     AC_DEFINE(EXPOSE_INTL_API)
 fi
 
 dnl Settings for the implementation of the ECMAScript Internationalization API
 if test -n "$ENABLE_INTL_API"; then
     AC_DEFINE(ENABLE_INTL_API)
 
+    MOZ_CONFIG_ICU()
+
     if test -z "$MOZ_NATIVE_ICU"; then
         case "$OS_TARGET" in
             WINNT)
                 ICU_LIB_NAMES="icuin icuuc icudt"
+                if test "$DISABLE_SHARED_JS" != "1"; then
+                    DBG_SUFFIX=
+                    if test -n "$MOZ_DEBUG"; then
+                        DBG_SUFFIX=d
+                    fi
+                    MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(LIB_PREFIX)$(lib)$(DBG_SUFFIX).$(LIB_SUFFIX))'
+                fi
                 ;;
-            Darwin|Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
+            Darwin)
                 ICU_LIB_NAMES="icui18n icuuc icudata"
+                if test "$DISABLE_SHARED_JS" != "1"; then
+                   MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(DLL_PREFIX)$(lib).$(MOZ_ICU_VERSION)$(DLL_SUFFIX))'
+                fi
+                ;;
+            Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
+                ICU_LIB_NAMES="icui18n icuuc icudata"
+                if test "$DISABLE_SHARED_JS" != "1"; then
+                   MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(DLL_PREFIX)$(lib)$(DLL_SUFFIX).$(MOZ_ICU_VERSION))'
+                fi
                 ;;
             *)
                 AC_MSG_ERROR([ECMAScript Internationalization API is not yet supported on this platform])
         esac
-        MOZ_ICU_LIBS='$(call EXPAND_LIBNAME_PATH,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib)'
+        if test "$DISABLE_SHARED_JS" = "1"; then
+            MOZ_ICU_LIBS='$(call EXPAND_LIBNAME_PATH,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib)'
+        fi
     fi
 fi
 
+AC_SUBST(DBG_SUFFIX)
 AC_SUBST(ENABLE_INTL_API)
 AC_SUBST(ICU_LIB_NAMES)
 AC_SUBST(MOZ_ICU_LIBS)
 AC_SUBST(MOZ_NATIVE_ICU)
 
 dnl Settings for ICU
 if test -n "$ENABLE_INTL_API" -a -z "$MOZ_NATIVE_ICU"; then
-    dnl We build ICU as a static library.
-    AC_DEFINE(U_STATIC_IMPLEMENTATION)
+    dnl We build ICU as a static library for non-shared js builds and as a shared library for shared js builds.
+    if test "$DISABLE_SHARED_JS" = "1"; then
+        AC_DEFINE(U_STATIC_IMPLEMENTATION)
+    else
+        AC_DEFINE(U_COMBINED_IMPLEMENTATION)
+    fi
 
     dnl Source files that use ICU should have control over which parts of the ICU
     dnl namespace they want to use.
     AC_DEFINE(U_USING_ICU_NAMESPACE,0)
 
     # Set ICU compile options
     ICU_CPPFLAGS=""
     # don't use icu namespace automatically in client code
@@ -4317,18 +4342,22 @@ if test -n "$ENABLE_INTL_API" -a -z "$MO
         ICU_CROSS_BUILD_OPT="--with-cross-build=$ICU_HOST_PATH"
         ICU_TARGET_OPT="--build=$build --host=$target"
     else
         # CROSS_COMPILE isn't set build and target are i386 and x86-64.
         # So we must set target for --build and --host.
         ICU_TARGET_OPT="--build=$target --host=$target"
     fi
 
-    # To reduce library size, use static linking
-    ICU_LINK_OPTS="--enable-static --disable-shared"
+    if test "$DISABLE_SHARED_JS" = "1"; then
+        # To reduce library size, use static linking
+        ICU_LINK_OPTS="--enable-static --disable-shared"
+    else
+        ICU_LINK_OPTS="--disable-static --enable-shared"
+    fi
     # Force the ICU static libraries to be position independent code
     ICU_CFLAGS="$DSO_PIC_CFLAGS $CFLAGS"
     ICU_CXXFLAGS="$DSO_PIC_CFLAGS $CXXFLAGS"
 
     ICU_BUILD_OPTS=""
     if test -n "$MOZ_DEBUG" -o "MOZ_DEBUG_SYMBOLS"; then
         ICU_CFLAGS="$ICU_CFLAGS $MOZ_DEBUG_FLAGS"
         ICU_CXXFLAGS="$ICU_CXXFLAGS $MOZ_DEBUG_FLAGS"
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -3,17 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LIBS = $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
-ifdef MOZ_NATIVE_ICU
+ifdef MOZ_SHARED_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 
 # Place a GDB Python auto-load file next to the gdb-tests executable, both
 # in the build directory and in the dist/bin directory.
 PP_TARGETS += GDB_AUTOLOAD
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -3,17 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LIBS      = $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
-ifdef MOZ_NATIVE_ICU
+ifdef MOZ_SHARED_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 
 ifdef QEMU_EXE
 MOZ_POST_PROGRAM_COMMAND = $(topsrcdir)/build/qemu-wrap --qemu $(QEMU_EXE) --libdir $(CROSS_LIB)
 endif
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -10,17 +10,17 @@ ifdef _MSC_VER
 # for PGO.
 NO_PROFILE_GUIDED_OPTIMIZE := 1
 endif
 
 LIBS      = $(NSPR_LIBS) $(EDITLINE_LIBS) $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(MOZ_ZLIB_LIBS)
 ifdef MOZ_NATIVE_FFI
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 endif
-ifdef MOZ_NATIVE_ICU
+ifdef MOZ_SHARED_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
 ifeq ($(OS_ARCH),Darwin)
 ifeq ($(TARGET_CPU),x86_64)
 DARWIN_EXE_LDFLAGS += -pagezero_size 10000 -image_base 100000000
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -122,16 +122,37 @@ EXTRA_DSO_LDOPTS += \
   $(LIBS_DIR) \
   $(MOZ_JS_LIBS) \
   $(NSS_LIBS) \
   $(MOZ_CAIRO_OSLIBS) \
   $(MOZ_APP_EXTRA_LIBS) \
   $(SQLITE_LIBS) \
   $(NULL)
 
+ifdef ENABLE_INTL_API
+ifdef JS_SHARED_LIBRARY
+EXTRA_DSO_LDOPTS += $(MOZ_ICU_LIBS)
+ifdef _MSC_VER
+ifdef MOZ_DEBUG
+EXTRA_DSO_LDOPTS += \
+  -DELAYLOAD:icudtd$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuind$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuucd$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+else
+EXTRA_DSO_LDOPTS += \
+  -DELAYLOAD:icudt$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuin$(MOZ_ICU_VERSION).dll \
+  -DELAYLOAD:icuuc$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+endif
+endif
+endif
+endif
+
 ifdef MOZ_NATIVE_JPEG
 EXTRA_DSO_LDOPTS += $(MOZ_JPEG_LIBS)
 endif
 
 ifdef MOZ_NATIVE_PNG
 EXTRA_DSO_LDOPTS += $(MOZ_PNG_LIBS)
 endif
 
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -97,16 +97,49 @@ JSSHELL_BINS += $(DIST)/bin/$(DLL_PREFIX
 else
 JSSHELL_BINS += \
   $(DIST)/bin/$(DLL_PREFIX)nspr4$(DLL_SUFFIX) \
   $(DIST)/bin/$(DLL_PREFIX)plds4$(DLL_SUFFIX) \
   $(DIST)/bin/$(DLL_PREFIX)plc4$(DLL_SUFFIX) \
   $(NULL)
 endif # MOZ_FOLD_LIBS
 endif # MOZ_NATIVE_NSPR
+ifdef MOZ_SHARED_ICU
+ifdef XP_WIN
+ifdef MOZ_DEBUG
+JSSHELL_BINS += \
+  $(DIST)/bin/icudtd$(MOZ_ICU_VERSION).dll \
+  $(DIST)/bin/icuind$(MOZ_ICU_VERSION).dll \
+  $(DIST)/bin/icuucd$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+else
+JSSHELL_BINS += \
+  $(DIST)/bin/icudt$(MOZ_ICU_VERSION).dll \
+  $(DIST)/bin/icuin$(MOZ_ICU_VERSION).dll \
+  $(DIST)/bin/icuuc$(MOZ_ICU_VERSION).dll \
+  $(NULL)
+endif # MOZ_DEBUG
+else
+ifdef XP_MACOSX
+JSSHELL_BINS += \
+  $(DIST)/bin/libicudata.$(MOZ_ICU_VERSION).dylib \
+  $(DIST)/bin/libicui18n.$(MOZ_ICU_VERSION).dylib \
+  $(DIST)/bin/libicuuc.$(MOZ_ICU_VERSION).dylib \
+  $(NULL)
+else
+ifdef XP_UNIX
+JSSHELL_BINS += \
+  $(DIST)/bin/libicudata.so.$(MOZ_ICU_VERSION) \
+  $(DIST)/bin/libicui18n.so.$(MOZ_ICU_VERSION) \
+  $(DIST)/bin/libicuuc.so.$(MOZ_ICU_VERSION) \
+  $(NULL)
+endif # XP_UNIX
+endif # XP_MACOSX
+endif # XP_WIN
+endif # MOZ_STATIC_JS
 MAKE_JSSHELL  = $(ZIP) -9j $(PKG_JSSHELL) $(JSSHELL_BINS)
 endif # LIBXUL_SDK
 
 _ABS_DIST = $(abspath $(DIST))
 JARLOG_DIR = $(abspath $(DEPTH)/jarlog/)
 JARLOG_FILE_AB_CD = $(JARLOG_DIR)/$(AB_CD).log
 
 TAR_CREATE_FLAGS := --exclude=.mkdir.done $(TAR_CREATE_FLAGS)