Bug 1036894 part 8 - Move most in-tree library linkage information to moz.build, as USE_LIBS. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 23 Jul 2014 13:30:52 +0900
changeset 206668 562e8494fb471eec5fd9df66a0f7fca6bea1811d
parent 206667 8679d6be0eb560a3b1f02ce296d19a9079eedb4b
child 206669 a0988e587a903665b114f95519d3083219e65087
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs1036894
milestone34.0a1
Bug 1036894 part 8 - Move most in-tree library linkage information to moz.build, as USE_LIBS. r=gps
b2g/app/Makefile.in
b2g/app/moz.build
browser/app/Makefile.in
browser/app/moz.build
browser/components/build/Makefile.in
browser/components/build/moz.build
config/config.mk
config/rules.mk
configure.in
content/base/test/moz.build
content/canvas/compiledtest/moz.build
content/media/compiledtest/moz.build
content/media/webaudio/compiledtest/moz.build
dom/audiochannel/tests/moz.build
editor/txmgr/tests/moz.build
embedding/tests/winEmbed/Makefile.in
embedding/tests/winEmbed/moz.build
extensions/gnomevfs/Makefile.in
extensions/gnomevfs/moz.build
gfx/angle/src/libEGL/moz.build
intl/lwbrk/tests/moz.build
intl/unicharutil/tests/Makefile.in
intl/unicharutil/tests/moz.build
ipc/app/Makefile.in
ipc/app/moz.build
ipc/ipdl/test/cxx/app/Makefile.in
ipc/ipdl/test/cxx/app/moz.build
js/src/Makefile.in
js/src/configure.in
js/src/gdb/Makefile.in
js/src/gdb/moz.build
js/src/jsapi-tests/Makefile.in
js/src/jsapi-tests/moz.build
js/src/moz.build
js/src/shell/Makefile.in
js/src/shell/moz.build
js/xpconnect/shell/Makefile.in
js/xpconnect/shell/moz.build
js/xpconnect/tests/Makefile.in
js/xpconnect/tests/components/native/Makefile.in
js/xpconnect/tests/components/native/moz.build
js/xpconnect/tests/moz.build
layout/media/Makefile.in
layout/media/moz.build
media/libcubeb/tests/Makefile.in
media/libcubeb/tests/moz.build
media/mtransport/test/Makefile.in
media/mtransport/test/moz.build
media/omx-plugin/Makefile.in
media/omx-plugin/froyo/Makefile.in
media/omx-plugin/froyo/moz.build
media/omx-plugin/gb/Makefile.in
media/omx-plugin/gb/moz.build
media/omx-plugin/gb235/Makefile.in
media/omx-plugin/gb235/moz.build
media/omx-plugin/hc/Makefile.in
media/omx-plugin/hc/moz.build
media/omx-plugin/kk/Makefile.in
media/omx-plugin/kk/moz.build
media/omx-plugin/lib/froyo/libstagefright/Makefile.in
media/omx-plugin/lib/froyo/libstagefright/moz.build
media/omx-plugin/lib/gb/libstagefright/Makefile.in
media/omx-plugin/lib/gb/libstagefright/moz.build
media/omx-plugin/lib/gb235/libstagefright/Makefile.in
media/omx-plugin/lib/gb235/libstagefright/moz.build
media/omx-plugin/lib/hc/libstagefright/Makefile.in
media/omx-plugin/lib/hc/libstagefright/moz.build
media/omx-plugin/lib/ics/libstagefright/Makefile.in
media/omx-plugin/lib/ics/libstagefright/moz.build
media/omx-plugin/moz.build
media/webrtc/signaling/test/Makefile.in
media/webrtc/signaling/test/moz.build
memory/build/Makefile.in
memory/build/moz.build
memory/mozalloc/tests/moz.build
memory/mozjemalloc/moz.build
memory/replace/jemalloc/Makefile.in
memory/replace/jemalloc/moz.build
mfbt/tests/Makefile.in
mfbt/tests/moz.build
modules/libmar/tool/Makefile.in
modules/libmar/tool/moz.build
mozglue/build/Makefile.in
mozglue/build/moz.build
mozglue/tests/Makefile.in
mozglue/tests/moz.build
netwerk/streamconv/test/Makefile.in
netwerk/streamconv/test/moz.build
netwerk/test/Makefile.in
netwerk/test/moz.build
rdf/tests/rdfcat/Makefile.in
rdf/tests/rdfcat/moz.build
rdf/tests/rdfpoll/Makefile.in
rdf/tests/rdfpoll/moz.build
rdf/tests/triplescat/Makefile.in
rdf/tests/triplescat/moz.build
security/build/Makefile.in
security/build/moz.build
security/manager/ssl/tests/compiled/moz.build
security/manager/ssl/tests/unit/tlsserver/cmd/Makefile.in
security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
security/sandbox/win/src/sandboxbroker/Makefile.in
security/sandbox/win/src/sandboxbroker/moz.build
startupcache/test/Makefile.in
startupcache/test/moz.build
storage/test/Makefile.in
storage/test/moz.build
testing/mochitest/ssltunnel/Makefile.in
testing/mochitest/ssltunnel/moz.build
toolkit/components/ctypes/tests/Makefile.in
toolkit/components/ctypes/tests/moz.build
toolkit/components/maintenanceservice/Makefile.in
toolkit/components/maintenanceservice/moz.build
toolkit/components/places/tests/cpp/Makefile.in
toolkit/components/places/tests/cpp/moz.build
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/client/moz.build
toolkit/crashreporter/test/Makefile.in
toolkit/crashreporter/test/moz.build
toolkit/library/Makefile.in
toolkit/library/libxul.mk
toolkit/library/libxul.mozbuild
toolkit/mozapps/update/tests/Makefile.in
toolkit/mozapps/update/tests/moz.build
toolkit/mozapps/update/updater/Makefile.in
toolkit/mozapps/update/updater/moz.build
toolkit/system/dbus/Makefile.in
toolkit/system/dbus/moz.build
toolkit/system/gnome/Makefile.in
toolkit/system/gnome/moz.build
tools/trace-malloc/Makefile.in
tools/trace-malloc/moz.build
webapprt/gtk/Makefile.in
webapprt/gtk/moz.build
webapprt/mac/Makefile.in
webapprt/mac/moz.build
webapprt/win/Makefile.in
webapprt/win/moz.build
widget/tests/moz.build
widget/xremoteclient/Makefile.in
xpcom/reflect/xptcall/tests/Makefile.in
xpcom/reflect/xptcall/tests/moz.build
xpcom/reflect/xptinfo/tests/Makefile.in
xpcom/reflect/xptinfo/tests/moz.build
xpcom/sample/Makefile.in
xpcom/sample/moz.build
xpcom/sample/program/Makefile.in
xpcom/sample/program/moz.build
xpcom/tests/Makefile.in
xpcom/tests/bug656331_component/Makefile.in
xpcom/tests/bug656331_component/moz.build
xpcom/tests/component/Makefile.in
xpcom/tests/component/moz.build
xpcom/tests/component_no_aslr/Makefile.in
xpcom/tests/component_no_aslr/moz.build
xpcom/tests/external/Makefile.in
xpcom/tests/external/moz.build
xpcom/tests/moz.build
xpcom/tests/windows/moz.build
xpcom/typelib/xpt/tests/Makefile.in
xpcom/typelib/xpt/tests/moz.build
xulrunner/app/Makefile.in
xulrunner/app/moz.build
xulrunner/examples/simple/components/src/Makefile.in
xulrunner/examples/simple/components/src/moz.build
xulrunner/stub/Makefile.in
xulrunner/stub/moz.build
xulrunner/tools/redit/Makefile.in
xulrunner/tools/redit/moz.build
--- a/b2g/app/Makefile.in
+++ b/b2g/app/Makefile.in
@@ -11,34 +11,26 @@ ifndef LIBXUL_SDK
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 LIBS += \
   -lui \
   -lEGL \
   -lhardware_legacy \
   -lhardware \
   -lcutils \
-  $(DEPTH)/media/libpng/$(LIB_PREFIX)mozpng.$(LIB_SUFFIX) \
-  $(DEPTH)/widget/gonk/libdisplay/$(LIB_PREFIX)display.$(LIB_SUFFIX) \
   $(MOZ_ZLIB_LIBS) \
   $(NULL)
 ifeq ($(ANDROID_VERSION),$(findstring $(ANDROID_VERSION),17 18 19))
 LIBS += \
   -lgui \
   -lsuspend \
   $(NULL)
 endif
 endif
 
-LIBS += $(JEMALLOC_LIBS)
-
-LIBS += \
-  $(XPCOM_STANDALONE_GLUE_LDOPTS) \
-  $(NULL)
-
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 LIBS += \
   -lbinder \
   -lutils \
   $(NULL)
 endif
 
 ifeq ($(OS_ARCH),WINNT)
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -12,16 +12,21 @@ if not CONFIG['LIBXUL_SDK']:
     SOURCES += [
         'nsBrowserApp.cpp',
     ]
     if CONFIG['_MSC_VER']:
         # Always enter a Windows program through wmain, whether or not we're
         # a console application.
         WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
+    if not CONFIG['MOZ_NATIVE_ZLIB'] and not CONFIG['ZLIB_IN_MOZCONFIG']:
+        USE_LIBS += [
+            'mozz',
+        ]
+
 DEFINES['XPCOM_GLUE'] = True
 
 for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION', 'MOZ_UPDATER'):
     DEFINES[var] = CONFIG[var]
 
 GENERATED_INCLUDES += [
     '/build',
 ]
@@ -34,9 +39,22 @@ LOCAL_INCLUDES += [
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     LOCAL_INCLUDES += [
         '/widget/gonk/libdisplay',
     ]
 
     LDFLAGS += ['-Wl,--export-dynamic']
 
+    USE_LIBS += [
+        'display',
+        'mozpng',
+    ]
+    if not CONFIG['MOZ_NATIVE_ZLIB']:
+        USE_LIBS += [
+            'mozz',
+        ]
+
+USE_LIBS += [
+    'xpcomglue',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -20,20 +20,16 @@ DEFINES += \
   $(NULL)
 
 ifdef LIBXUL_SDK #{
 PREF_JS_EXPORTS += $(srcdir)/profile/channel-prefs.js
 endif #} LIBXUL_SDK
 
 # Build a binary bootstrapping with XRE_main
 
-LIBS += \
-	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
-	$(NULL)
-
 ifdef MOZ_LINKER
 LIBS += $(MOZ_ZLIB_LIBS)
 endif
 
 ifdef HAVE_CLOCK_MONOTONIC
 LIBS += $(REALTIME_LIBS)
 endif
 
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -45,9 +45,13 @@ if CONFIG['OS_ARCH'] == 'WINNT':
 #
 # The default heap size is 1MB on Win32.
 # The heap will grow if need be.
 #
 # Set it to 256k.  See bug 127069.
 if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
     LDFLAGS += ['/HEAP:0x40000']
 
+USE_LIBS += [
+    'xpcomglue',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/browser/components/build/Makefile.in
+++ b/browser/components/build/Makefile.in
@@ -6,18 +6,17 @@ ifeq ($(OS_ARCH),WINNT)
 OS_LIBS	+= $(call EXPAND_LIBNAME,ole32 shell32 shlwapi)
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 OS_LIBS += $(call EXPAND_LIBNAME,version)
 endif
 
 EXTRA_DSO_LDOPTS += \
-	$(XPCOM_GLUE_LDOPTS) \
-	$(MOZ_COMPONENT_LIBS) \
+	$(NSPR_LIBS) \
 	$(NULL)
 
 # Mac: Need to link with CoreFoundation for Mac Migrators (PList reading code)
 # GTK2: Need to link with glib for GNOME shell service
 ifneq (,$(filter cocoa gtk2 gtk3,$(MOZ_WIDGET_TOOLKIT)))
 EXTRA_DSO_LDOPTS += \
   $(TK_LIBS) \
   $(NULL)
--- a/browser/components/build/moz.build
+++ b/browser/components/build/moz.build
@@ -18,8 +18,14 @@ IS_COMPONENT = True
 
 LOCAL_INCLUDES += [
     '../about',
     '../dirprovider',
     '../feeds/src',
     '../migration/src',
     '../shell/src',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/config/config.mk
+++ b/config/config.mk
@@ -259,18 +259,16 @@ ifneq (,$(MOZ_DEBUG)$(MOZ_DEBUG_SYMBOLS)
     endif
   else
     _DEBUG_ASFLAGS += $(MOZ_DEBUG_FLAGS)
   endif
   _DEBUG_CFLAGS += $(MOZ_DEBUG_FLAGS)
   _DEBUG_LDFLAGS += $(MOZ_DEBUG_LDFLAGS)
 endif
 
-MOZALLOC_LIB = $(call EXPAND_LIBNAME_PATH,mozalloc,$(DIST)/lib)
-
 ASFLAGS += $(_DEBUG_ASFLAGS)
 OS_CFLAGS += $(_DEBUG_CFLAGS)
 OS_CXXFLAGS += $(_DEBUG_CFLAGS)
 OS_LDFLAGS += $(_DEBUG_LDFLAGS)
 
 # XXX: What does this? Bug 482434 filed for better explanation.
 ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
 ifdef MOZ_DEBUG
@@ -581,18 +579,16 @@ IDL_PARSER_DIR = $(LIBXUL_SDK)/sdk/bin
 IDL_PARSER_CACHE_DIR = $(LIBXUL_SDK)/sdk/bin
 endif
 
 SDK_LIB_DIR = $(DIST)/sdk/lib
 SDK_BIN_DIR = $(DIST)/sdk/bin
 
 DEPENDENCIES	= .md
 
-MOZ_COMPONENT_LIBS=$(XPCOM_LIBS) $(MOZ_COMPONENT_NSPR_LIBS)
-
 ifdef MACOSX_DEPLOYMENT_TARGET
 export MACOSX_DEPLOYMENT_TARGET
 endif # MACOSX_DEPLOYMENT_TARGET
 
 ifdef MOZ_USING_CCACHE
 ifdef CLANG_CXX
 export CCACHE_CPP2=1
 endif
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -78,17 +78,17 @@ DIRS += $(TEST_DIRS)
 ifdef CPP_UNIT_TESTS
 ifdef COMPILE_ENVIRONMENT
 
 # Compile the tests to $(DIST)/bin.  Make lots of niceties available by default
 # through TestHarness.h, by modifying the list of includes and the libs against
 # which stuff links.
 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS)
 INCLUDES += -I$(DIST)/include/testing
-LIBS += $(XPCOM_GLUE_LDOPTS) $(NSPR_LIBS)
+LIBS += $(NSPR_LIBS)
 
 ifndef MOZ_PROFILE_GENERATE
 libs:: $(CPP_UNIT_TESTS) $(call mkdir_deps,$(DIST)/cppunittests)
 	$(NSINSTALL) $(CPP_UNIT_TESTS) $(DIST)/cppunittests
 endif
 
 run-cppunittests::
 	@$(PYTHON) $(topsrcdir)/testing/runcppunittests.py --xre-path=$(DIST)/bin --symbols-path=$(DIST)/crashreporter-symbols $(CPP_UNIT_TESTS)
--- a/configure.in
+++ b/configure.in
@@ -954,47 +954,20 @@ DLL_SUFFIX=.so
 OBJ_SUFFIX=o
 LIB_SUFFIX=a
 ASM_SUFFIX=s
 IMPORT_LIB_SUFFIX=
 TARGET_MD_ARCH=unix
 DIRENT_INO=d_ino
 MOZ_USER_DIR=".mozilla"
 
-MOZ_JPEG_CFLAGS=
-MOZ_JPEG_LIBS='$(call EXPAND_LIBNAME_PATH,mozjpeg,$(DEPTH)/media/libjpeg)'
-MOZ_BZ2_CFLAGS=
-MOZ_BZ2_LIBS='$(call EXPAND_LIBNAME_PATH,bz2,$(DEPTH)/modules/libbz2/src)'
-MOZ_PNG_CFLAGS="-I$_objdir/dist/include" # needed for freetype compilation
-MOZ_PNG_LIBS='$(call EXPAND_LIBNAME_PATH,mozpng,$(DEPTH)/media/libpng)'
-
-MOZ_JS_STATIC_LIBS='$(call EXPAND_LIBNAME_PATH,js_static,$(LIBXUL_DIST)/lib)'
-MOZ_JS_SHARED_LIBS='$(call EXPAND_LIBNAME_PATH,mozjs,$(LIBXUL_DIST)/lib)'
 MOZ_FIX_LINK_PATHS='-Wl,-rpath-link,$(LIBXUL_DIST)/bin -Wl,-rpath-link,$(prefix)/lib'
-XPCOM_FROZEN_LDOPTS='$(call EXPAND_LIBNAME_PATH,xul mozalloc,$(LIBXUL_DIST)/bin)'
-LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS)'
-XPCOM_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) $(XPCOM_FROZEN_LDOPTS)'
-XPCOM_STANDALONE_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX)'
-
-# These are specially defined on Windows only
-case "$target" in
-*-mingw*)
-  XPCOM_STATICRUNTIME_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_staticruntime_s.$(LIB_SUFFIX) $(XPCOM_FROZEN_LDOPTS)'
-  XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_staticruntime.$(LIB_SUFFIX)'
-  ;;
-*)
-  XPCOM_STATICRUNTIME_GLUE_LDOPTS=$XPCOM_GLUE_LDOPTS
-  XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS=$XPCOM_STANDALONE_GLUE_LDOPTS
-  ;;
-esac
 
 MOZ_FS_LAYOUT=unix
 
-MOZ_COMPONENT_NSPR_LIBS='-L$(LIBXUL_DIST)/bin $(NSPR_LIBS)'
-
 USE_DEPENDENT_LIBS=1
 
 _PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2
 
 if test -n "$CROSS_COMPILE"; then
     OS_TARGET="${target_os}"
     OS_ARCH=`echo $target_os | sed -e 's|/|_|g'`
     OS_RELEASE=
@@ -2056,17 +2029,16 @@ ia64*-hpux*)
 *-mingw*)
     DSO_CFLAGS=
     DSO_PIC_CFLAGS=
     DLL_SUFFIX=.dll
     RC=rc.exe
     MC=mc.exe
     # certain versions of cygwin's makedepend barf on the
     # #include <string> vs -I./dist/include/string issue so don't use it
-    XPCOM_FROZEN_LDOPTS='$(call EXPAND_LIBNAME_PATH,xul mozalloc,$(LIBXUL_DIST)/lib)'
     if test -n "$GNU_CC" -o -n "$CLANG_CC"; then
         CC="$CC -mwindows"
         CXX="$CXX -mwindows"
         CPP="$CPP -mwindows"
         CFLAGS="$CFLAGS -mms-bitfields"
         CXXFLAGS="$CXXFLAGS -mms-bitfields"
         DSO_LDOPTS='-shared'
         MKSHLIB='$(CXX) $(DSO_LDOPTS) -o $@'
@@ -3018,26 +2990,28 @@ if test "$ac_cv_func_res_ninit" = "yes";
 dnl must add the link line we do something as foolish as this... dougt
 dnl else
 dnl    AC_CHECK_LIB(bind, res_ninit, AC_DEFINE(HAVE_RES_NINIT),
 dnl        AC_CHECK_LIB(resolv, res_ninit, AC_DEFINE(HAVE_RES_NINIT)))
 fi
 
 AC_LANG_CPLUSPLUS
 
+ICONV_LIBS=
+
 case $target_os in
     darwin*|mingw*)
         ;;
     *)
 
-AC_CHECK_LIB(c, iconv, [_ICONV_LIBS="$_ICONV_LIBS"],
-    AC_CHECK_LIB(iconv, iconv, [_ICONV_LIBS="$_ICONV_LIBS -liconv"],
-        AC_CHECK_LIB(iconv, libiconv, [_ICONV_LIBS="$_ICONV_LIBS -liconv"])))
+AC_CHECK_LIB(c, iconv, [ICONV_LIBS=],
+    AC_CHECK_LIB(iconv, iconv, [ICONV_LIBS="-liconv"],
+        AC_CHECK_LIB(iconv, libiconv, [ICONV_LIBS="-liconv"])))
 _SAVE_LIBS=$LIBS
-LIBS="$LIBS $_ICONV_LIBS"
+LIBS="$LIBS $ICONV_LIBS"
 AC_CACHE_CHECK(
     [for iconv()],
     ac_cv_func_iconv,
     [AC_TRY_LINK([
         #include <stdlib.h>
         #include <iconv.h>
         ],
         [
@@ -3046,18 +3020,17 @@ AC_CACHE_CHECK(
             iconv_close(h);
         ],
         [ac_cv_func_iconv=yes],
         [ac_cv_func_iconv=no]
         )]
     )
 if test "$ac_cv_func_iconv" = "yes"; then
     AC_DEFINE(HAVE_ICONV)
-    LIBXUL_LIBS="$LIBXUL_LIBS $_ICONV_LIBS"
-    LIBICONV="$_ICONV_LIBS"
+    LIBICONV="$ICONV_LIBS"
     AC_CACHE_CHECK(
         [for iconv() with const input],
         ac_cv_func_const_iconv,
         [AC_TRY_COMPILE([
             #include <stdlib.h>
             #include <iconv.h>
             ],
             [
@@ -3074,16 +3047,18 @@ if test "$ac_cv_func_iconv" = "yes"; the
         AC_DEFINE(HAVE_ICONV_WITH_CONST_INPUT)
     fi
 fi
 LIBS=$_SAVE_LIBS
 
     ;;
 esac
 
+AC_SUBST(ICONV_LIBS)
+
 AM_LANGINFO_CODESET
 
 AC_LANG_C
 
 dnl **********************
 dnl *** va_copy checks ***
 AC_CACHE_CHECK([for an implementation of va_copy()],
                ac_cv_va_copy,
@@ -3620,21 +3595,16 @@ if test -n "${JPEG_DIR}" -a -d "${JPEG_D
     MOZ_JPEG_LIBS="-L${JPEG_DIR}/lib ${MOZ_JPEG_LIBS}"
 fi
 fi # SKIP_LIBRARY_CHECKS
 
 dnl system ZLIB support
 dnl ========================================================
 MOZ_ZLIB_CHECK([1.2.3])
 
-if test "$MOZ_NATIVE_ZLIB" != 1; then
-    MOZ_ZLIB_CFLAGS="-I${_topsrcdir}/modules/zlib/src"
-    MOZ_ZLIB_LIBS='$(call EXPAND_LIBNAME_PATH,mozz,'"$MOZ_BUILD_ROOT"'/modules/zlib/src)'
-fi
-
 if test "$MOZ_LINKER" = 1 -a "$MOZ_NATIVE_ZLIB" != 1; then
     AC_MSG_ERROR([Custom dynamic linker requires --with-system-zlib])
 fi
 
 MOZ_PNG_ARM_NEON=
 
 if test -z "$SKIP_LIBRARY_CHECKS"; then
 dnl system BZIP2 Support
@@ -3755,20 +3725,16 @@ fi
 
 AC_SUBST(MOZ_NATIVE_HUNSPELL)
 
 dnl ========================================================
 dnl system libffi Support
 dnl ========================================================
 MOZ_CONFIG_FFI()
 
-if test -n "$MOZ_NATIVE_FFI"; then
-    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.],
@@ -4242,48 +4208,45 @@ cairo-qt)
 cairo-cocoa)
     MOZ_WIDGET_TOOLKIT=cocoa
     AC_DEFINE(MOZ_WIDGET_COCOA)
     LDFLAGS="$LDFLAGS -framework Cocoa -lobjc"
     TK_LIBS='-framework CoreLocation -framework QuartzCore -framework Carbon -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework AddressBook -framework OpenGL'
     TK_CFLAGS="-DNO_X11"
     CFLAGS="$CFLAGS $TK_CFLAGS"
     CXXFLAGS="$CXXFLAGS $TK_CFLAGS"
-    XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/bin/XUL $(call EXPAND_LIBNAME_PATH,mozalloc,$(LIBXUL_DIST)/bin)'
     MOZ_USER_DIR="Mozilla"
     MOZ_FS_LAYOUT=bundle
     MOZ_WEBGL=1
     MOZ_INSTRUMENT_EVENT_LOOP=1
     ;;
 
 cairo-uikit)
     MOZ_WIDGET_TOOLKIT=uikit
     AC_DEFINE(MOZ_WIDGET_UIKIT)
     LDFLAGS="$LDFLAGS -framework UIKit -lobjc"
     TK_CFLAGS="-DNO_X11"
     TK_LIBS='-framework Foundation -framework CoreFoundation -framework CoreGraphics -framework CoreText'
     CFLAGS="$CFLAGS $TK_CFLAGS"
     CXXFLAGS="$CXXFLAGS $TK_CFLAGS"
-    XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/bin/XUL $(call EXPAND_LIBNAME_PATH,mozalloc,$(LIBXUL_DIST)/bin)'
     MOZ_USER_DIR="Mozilla"
     MOZ_FS_LAYOUT=bundle
     ;;
 
 cairo-android)
     AC_DEFINE(MOZ_WIDGET_ANDROID)
     MOZ_WIDGET_TOOLKIT=android
     TK_CFLAGS='$(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS)'
     TK_LIBS='$(MOZ_CAIRO_LIBS) $(MOZ_PIXMAN_LIBS)'
     MOZ_WEBGL=1
     MOZ_PDF_PRINTING=1
     MOZ_INSTRUMENT_EVENT_LOOP=1
     ;;
 
 cairo-gonk)
-    XPCOM_FROZEN_LDOPTS='$(call EXPAND_LIBNAME_PATH,xul mozalloc,$(LIBXUL_DIST)/lib)'
     AC_DEFINE(MOZ_WIDGET_GONK)
     AC_DEFINE(MOZ_TOUCH)
     MOZ_WIDGET_TOOLKIT=gonk
     TK_CFLAGS='$(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS)'
     TK_LIBS='$(MOZ_CAIRO_LIBS) $(MOZ_PIXMAN_LIBS)'
     MOZ_WEBGL=1
     MOZ_PDF_PRINTING=1
     MOZ_TOUCH=1
@@ -6470,21 +6433,18 @@ dnl Check for sqlite
 dnl ========================================================
 
 MOZ_NATIVE_SQLITE=
 MOZ_ARG_ENABLE_BOOL(system-sqlite,
 [  --enable-system-sqlite  Use system sqlite (located with pkgconfig)],
 MOZ_NATIVE_SQLITE=1,
 MOZ_NATIVE_SQLITE= )
 
-if test -z "$MOZ_NATIVE_SQLITE"
+if test -n "$MOZ_NATIVE_SQLITE"
 then
-    SQLITE_CFLAGS=
-    SQLITE_LIBS='$(call EXPAND_LIBNAME_PATH,mozsqlite3,$(DIST)/lib)'
-else
     dnl ============================
     dnl === SQLite Version check ===
     dnl ============================
     dnl Check to see if the system SQLite package is new enough.
     PKG_CHECK_MODULES(SQLITE, sqlite3 >= $SQLITE_VERSION)
 
     dnl ==================================
     dnl === SQLITE_SECURE_DELETE check ===
@@ -7839,19 +7799,16 @@ fi
 
 dnl ========================================================
 dnl =
 dnl = Static Build Options
 dnl =
 dnl ========================================================
 MOZ_ARG_HEADER(Static build options)
 
-AC_SUBST(LIBXUL_LIBS)
-XPCOM_LIBS="$LIBXUL_LIBS"
-
 if test "$OS_ARCH" = "WINNT"; then
   GKMEDIAS_SHARED_LIBRARY=1
   AC_DEFINE(GKMEDIAS_SHARED_LIBRARY)
 fi
 AC_SUBST(GKMEDIAS_SHARED_LIBRARY)
 
 if test -z "$MOZ_NATIVE_ZLIB"; then
 if test -n "$JS_SHARED_LIBRARY" -o "$GKMEDIAS_SHARED_LIBRARY"; then
@@ -8014,18 +7971,16 @@ if test "$MOZ_TREE_PIXMAN" = "force"; th
         MOZ_TREE_PIXMAN=1
     fi
 elif test -z "$MOZ_TREE_CAIRO"; then
     MOZ_TREE_PIXMAN=
 fi
 
 if test "$MOZ_TREE_PIXMAN"; then
     AC_DEFINE(MOZ_TREE_PIXMAN)
-    MOZ_PIXMAN_CFLAGS=""
-    MOZ_PIXMAN_LIBS='$(call EXPAND_LIBNAME_PATH,mozlibpixman,$(DEPTH)/gfx/cairo/libpixman/src)'
 else
     PKG_CHECK_MODULES(PIXMAN, pixman-1 >= 0.19.2)
     MOZ_PIXMAN_CFLAGS="$PIXMAN_CFLAGS"
     MOZ_PIXMAN_LIBS="$PIXMAN_LIBS"
 fi
 AC_SUBST(MOZ_PIXMAN_CFLAGS)
 AC_SUBST(MOZ_PIXMAN_LIBS)
 
@@ -8392,17 +8347,16 @@ AC_SUBST(WINDRES)
 AC_SUBST(IMPLIB)
 AC_SUBST(FILTER)
 AC_SUBST(BIN_FLAGS)
 AC_SUBST(MOZ_WIDGET_TOOLKIT)
 AC_SUBST(MOZ_UPDATE_XTERM)
 AC_SUBST(MOZ_AUTH_EXTENSION)
 AC_SUBST(MOZ_PERMISSIONS)
 AC_SUBST(MOZ_PREF_EXTENSIONS)
-AC_SUBST(MOZ_JS_LIBS)
 AC_SUBST(MOZ_DEBUG)
 AC_SUBST(MOZ_DEBUG_SYMBOLS)
 AC_SUBST(MOZ_DEBUG_ENABLE_DEFS)
 AC_SUBST(MOZ_DEBUG_DISABLE_DEFS)
 AC_SUBST(MOZ_DEBUG_LDFLAGS)
 AC_SUBST(WARNINGS_AS_ERRORS)
 AC_SUBST(MOZ_EXTENSIONS)
 AC_SUBST(MOZ_ENABLE_PROFILER_SPS)
@@ -8468,22 +8422,16 @@ AC_SUBST(ENABLE_STRIP)
 AC_SUBST(PKG_SKIP_STRIP)
 AC_SUBST(STRIP_FLAGS)
 AC_SUBST(USE_ELF_HACK)
 AC_SUBST(INCREMENTAL_LINKER)
 AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
 AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
 
 AC_SUBST(MOZ_FIX_LINK_PATHS)
-AC_SUBST(XPCOM_LIBS)
-AC_SUBST(XPCOM_FROZEN_LDOPTS)
-AC_SUBST(XPCOM_GLUE_LDOPTS)
-AC_SUBST(XPCOM_STANDALONE_GLUE_LDOPTS)
-AC_SUBST(XPCOM_STATICRUNTIME_GLUE_LDOPTS)
-AC_SUBST(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS)
 
 AC_SUBST(USE_DEPENDENT_LIBS)
 
 AC_SUBST(MOZ_BUILD_ROOT)
 
 AC_SUBST(MOZ_POST_DSO_LIB_COMMAND)
 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
 AC_SUBST(MOZ_LINKER_EXTRACT)
@@ -8929,24 +8877,17 @@ if test "$MOZ_WIDGET_TOOLKIT" = "android
    test "$MOZ_BUILD_APP" = "b2g"; then
     _INTL_API=no
 else
     _INTL_API=yes
 fi
 
 MOZ_CONFIG_ICU()
 
-if test -n "$MOZ_NATIVE_ICU"; then
-    MOZ_JS_STATIC_LIBS="$MOZ_JS_STATIC_LIBS $MOZ_ICU_LIBS"
-fi
-
-if test -n "$JS_SHARED_LIBRARY"; then
-  MOZ_JS_LIBS="$MOZ_JS_SHARED_LIBS"
-else
-  MOZ_JS_LIBS="$MOZ_JS_STATIC_LIBS"
+if test -z "$JS_SHARED_LIBRARY"; then
   AC_DEFINE(MOZ_STATIC_JS)
 fi
 AC_SUBST(JS_SHARED_LIBRARY)
 
 AC_SUBST(UPLOAD_EXTRA_FILES)
 
 MOZ_CREATE_CONFIG_STATUS()
 
@@ -9050,17 +8991,21 @@ fi
 
 if test "$MOZ_TREE_FREETYPE"; then
    export CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS -std=c99"
    export CPPFLAGS="$CPPFLAGS $MOZ_DEBUG_FLAGS"
    export CXXFLAGS="$CXXFLAGS $MOZ_DEBUG_FLAGS"
    export LDFLAGS="$LDFLAGS $MOZ_DEBUG_LDFLAGS"
    # Spaces in the *_CFLAGS and *_LIBS variables are intentionally placed
    # to force freetype to use our settings rather than autodetecting
-   export LIBPNG_CFLAGS="$MOZ_PNG_CFLAGS "
+   if test -n "$MOZ_NATIVE_PNG"; then
+     export LIBPNG_CFLAGS="$MOZ_PNG_CFLAGS "
+   else
+     export LIBPNG_CFLAGS="-I$_objdir/dist/include"
+   fi
    export LIBPNG_LIBS="$MOZ_PNG_LIBS "
    export ZLIB_CFLAGS="$MOZ_ZLIB_CFLAGS "
    export ZLIB_LIBS="$MOZ_ZLIB_LIBS "
    export CONFIG_FILES="unix-cc.mk:unix-cc.in unix-def.mk:unix-def.in freetype-config freetype2.pc:freetype2.in"
    ac_configure_args="$ac_configure_args --host=$target --disable-shared --with-pic=yes --with-zlib=yes --without-bzip2 --with-png=yes --without-harfbuzz"
 
    if ! test -e modules; then
      mkdir modules
--- a/content/base/test/moz.build
+++ b/content/base/test/moz.build
@@ -38,8 +38,13 @@ if CONFIG['MOZ_CHILD_PERMISSIONS']:
 
 MOCHITEST_CHROME_MANIFESTS += [
     'chrome.ini',
     'chrome/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/content/canvas/compiledtest/moz.build
+++ b/content/canvas/compiledtest/moz.build
@@ -11,8 +11,13 @@ CPP_UNIT_TESTS += [
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '../src',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/content/media/compiledtest/moz.build
+++ b/content/media/compiledtest/moz.build
@@ -11,8 +11,13 @@ CPP_UNIT_TESTS += [
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/content/media/webaudio/compiledtest/moz.build
+++ b/content/media/webaudio/compiledtest/moz.build
@@ -11,8 +11,13 @@ CPP_UNIT_TESTS += [
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/dom/audiochannel/tests/moz.build
+++ b/dom/audiochannel/tests/moz.build
@@ -12,8 +12,13 @@ SOURCES += sorted('%s.cpp' % t for t in 
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['NOMINMAX'] = True
 
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 
 FAIL_ON_WARNINGS = True
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/editor/txmgr/tests/moz.build
+++ b/editor/txmgr/tests/moz.build
@@ -7,8 +7,13 @@
 CPP_UNIT_TESTS += [
     'TestTXMgr',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/embedding/tests/winEmbed/Makefile.in
+++ b/embedding/tests/winEmbed/Makefile.in
@@ -22,16 +22,11 @@
 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 #
 # Contributor(s):
 #
 # ***** END LICENSE BLOCK *****
 
-LIBS = \
-	$(DEPTH)/profile/dirserviceprovider/src/$(LIB_PREFIX)profdirserviceprovidersa_s.$(LIB_SUFFIX) \
-	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
-	$(NULL)
-
 OS_LIBS		+= $(call EXPAND_LIBNAME,ole32 comdlg32 shell32 version)
 
 include $(topsrcdir)/config/rules.mk
--- a/embedding/tests/winEmbed/moz.build
+++ b/embedding/tests/winEmbed/moz.build
@@ -28,8 +28,13 @@ else:
     #
     # The default heap size is 1MB on Win32.
     # The heap will grow if need be.
     #
     # Set it to 256k.  See bug 127069.
     LDFLAGS += ['/HEAP:0x40000']
 
 DISABLE_STL_WRAPPING = True
+
+USE_LIBS += [
+    'profdirserviceprovidersa_s',
+    'xpcomglue',
+]
--- a/extensions/gnomevfs/Makefile.in
+++ b/extensions/gnomevfs/Makefile.in
@@ -1,12 +1,11 @@
 # vim:set ts=8 sw=8 sts=8 noet:
 # 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/.
 
 LOCAL_INCLUDES	= $(MOZ_GNOMEVFS_CFLAGS)
 
-EXTRA_DSO_LDOPTS = \
-		   $(XPCOM_GLUE_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
 		   $(NSPR_LIBS) \
 		   $(MOZ_GNOMEVFS_LIBS) \
 		   $(NULL)
--- a/extensions/gnomevfs/moz.build
+++ b/extensions/gnomevfs/moz.build
@@ -11,8 +11,14 @@ SOURCES += [
 LIBRARY_NAME = 'nkgnomevfs'
 
 IS_COMPONENT = True
 
 # make sure this component is never statically linked into the main
 # application.  this is necessary since we don't want to force users
 # to install gnome-vfs2 in order to use the rest of mozilla ;-)
 FORCE_SHARED_LIB = True
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/gfx/angle/src/libEGL/moz.build
+++ b/gfx/angle/src/libEGL/moz.build
@@ -47,15 +47,15 @@ DEFINES['GL_APICALL'] = ""
 DEFINES['GL_GLEXT_PROTOTYPES'] = ""
 DEFINES['EGLAPI'] = ""
 
 # ANGLE uses the STL, so we can't use our derpy STL wrappers.
 DISABLE_STL_WRAPPING = True
 
 
 LOCAL_INCLUDES += [ '../../include', '../../src' ]
-EXTRA_DSO_LDOPTS += [ '../libGLESv2/libGLESv2.lib' ]
+USE_LIBS += [ 'libGLESv2' ]
 
 LIBRARY_NAME = 'libEGL'
 FORCE_SHARED_LIB = True
 
 RCFILE = SRCDIR + '/libEGL.rc'
 DEFFILE = SRCDIR + '/libEGL.def'
--- a/intl/lwbrk/tests/moz.build
+++ b/intl/lwbrk/tests/moz.build
@@ -9,8 +9,13 @@ CPP_UNIT_TESTS += [
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 LOCAL_INCLUDES += [
     '../public',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/intl/unicharutil/tests/Makefile.in
+++ b/intl/unicharutil/tests/Makefile.in
@@ -1,11 +1,8 @@
 #
 # 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		= \
-	$(XPCOM_STATICRUNTIME_GLUE_LDOPTS) \
-	$(DIST)/lib/$(LIB_PREFIX)unicharutil_external_s.$(LIB_SUFFIX) \
-	$(XPCOM_LIBS) \
+LIBS		+= \
 	$(NSPR_LIBS) \
 	$(NULL)
--- a/intl/unicharutil/tests/moz.build
+++ b/intl/unicharutil/tests/moz.build
@@ -15,8 +15,23 @@ SIMPLE_PROGRAMS += [
     "%s" % (fyl[0:-4]) for fyl in SOURCES
 ]
 
 LOCAL_INCLUDES += [
     '../public',
 ]
 
 USE_STATIC_LIBS = True
+
+USE_LIBS += [
+    'mozalloc',
+    'unicharutil_external_s',
+    'xul-shared',
+]
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    USE_LIBS += [
+        'xpcomglue_staticruntime_s',
+    ]
+else:
+    USE_LIBS += [
+        'xpcomglue_s',
+    ]
--- a/ipc/app/Makefile.in
+++ b/ipc/app/Makefile.in
@@ -5,17 +5,16 @@
 ifneq ($(dir $(PROGRAM)),./)
   GENERATED_DIRS = $(dir $(PROGRAM))
 endif
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 WRAP_LDFLAGS =
 else
 LIBS += \
-  $(XPCOM_LIBS) \
   $(NSPR_LIBS) \
   $(NULL)
 endif
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 LIBS += \
   -lbinder \
   -lutils \
@@ -35,17 +34,16 @@ endif
 NSDISTMODE = copy
 
 include $(topsrcdir)/config/config.mk
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(OS_ARCH),WINNT) #{
 
-LIBS += ../../security/sandbox/$(LIB_PREFIX)sandbox_s.$(LIB_SUFFIX)
 LIBS += $(NSPR_LIBS)
 
 # Note the manifest file exists in the tree, so we use the explicit filename
 # here.
 EXTRA_DEPS += plugin-container.exe.manifest
 endif #}
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) #{
--- a/ipc/app/moz.build
+++ b/ipc/app/moz.build
@@ -10,30 +10,38 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
     SOURCES += [
         'MozillaRuntimeMainAndroid.cpp',
     ]
     FINAL_TARGET = 'dist/bin/lib'
 else:
     SOURCES += [
         'MozillaRuntimeMain.cpp',
     ]
+    USE_LIBS += [
+        'mozalloc',
+        'xul-shared',
+    ]
+
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     # For sandbox includes and the include dependencies those have
     LOCAL_INCLUDES += [
         '/security',
         '/security/sandbox',
         '/security/sandbox/chromium',
     ]
+    USE_LIBS += [
+        'sandbox_s',
+    ]
 
 if CONFIG['_MSC_VER']:
     # Always enter a Windows program through wmain, whether or not we're
     # a console application.
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 LDFLAGS += [CONFIG['MOZ_ALLOW_HEAP_EXECUTE_FLAGS']]
 
--- a/ipc/ipdl/test/cxx/app/Makefile.in
+++ b/ipc/ipdl/test/cxx/app/Makefile.in
@@ -1,15 +1,13 @@
 # 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/.
 
 NSDISTMODE = copy
 
-LIBS = \
-  $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-  $(LIBXUL_LIBS) \
+LIBS += \
   $(NSPR_LIBS) \
   $(NULL)
 
 include $(topsrcdir)/config/config.mk
 
 include $(topsrcdir)/config/rules.mk
--- a/ipc/ipdl/test/cxx/app/moz.build
+++ b/ipc/ipdl/test/cxx/app/moz.build
@@ -13,8 +13,14 @@ include('/ipc/chromium/chromium-config.m
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
 ]
 
 if CONFIG['_MSC_VER']:
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -10,27 +10,20 @@ endif
 make_min_ver := 3.81
 ifneq ($(make_min_ver),$(firstword $(sort $(make_min_ver) $(MAKE_VERSION))))
 $(error GNU Make $(make_min_ver) or higher is required)
 endif
 
 TOPLEVEL_BUILD := 1
 
 run_for_side_effects := $(shell echo 'MAKE: $(MAKE)')
-LIBS		= $(NSPR_LIBS)
+LIBS		+= $(NSPR_LIBS)
 
 DIST_INSTALL = 1
 
-ifdef JS_STANDALONE
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
-ifndef MOZ_NATIVE_ZLIB
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mozz,$(DEPTH)/modules/zlib/src)
-endif
-endif
-
 ifdef JS_HAS_CTYPES
 ifdef MOZ_NATIVE_FFI
 LOCAL_INCLUDES = $(MOZ_FFI_CFLAGS)
 endif
 
 ifdef MOZ_NATIVE_FFI
 EXTRA_DSO_LDOPTS += $(MOZ_FFI_LIBS)
 else
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -762,18 +762,16 @@ LIB_SUFFIX=a
 ASM_SUFFIX=s
 IMPORT_LIB_SUFFIX=
 TARGET_MD_ARCH=unix
 DIRENT_INO=d_ino
 MOZ_USER_DIR=".mozilla"
 
 MOZ_FIX_LINK_PATHS='-Wl,-rpath-link,$(LIBXUL_DIST)/bin -Wl,-rpath-link,$(prefix)/lib'
 
-MOZ_COMPONENT_NSPR_LIBS='-L$(LIBXUL_DIST)/bin $(NSPR_LIBS)'
-
 USE_DEPENDENT_LIBS=1
 
 _PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2
 
 if test -n "$CROSS_COMPILE"; then
     OS_TARGET="${target_os}"
     OS_ARCH=`echo $target_os | sed -e 's|/|_|g'`
     OS_RELEASE=
@@ -1674,17 +1672,16 @@ ia64*-hpux*)
         # make 'foo == bar;' error out
         CFLAGS="$CFLAGS -we4553"
         CXXFLAGS="$CXXFLAGS -we4553"
         LIBS="$LIBS kernel32.lib user32.lib gdi32.lib winmm.lib wsock32.lib advapi32.lib psapi.lib"
         MOZ_DEBUG_LDFLAGS='-DEBUG -DEBUGTYPE:CV'
         WARNINGS_AS_ERRORS='-WX'
         MOZ_OPTIMIZE_FLAGS="-O2"
         MOZ_FIX_LINK_PATHS=
-        MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
         # Disable these flags on clang-cl since it doesn't ignore unknown arguments by default, and
         # autoconf insists on passing $LDFLAGS to the compiler.
         if test -z "$CLANG_CL"; then
             LDFLAGS="$LDFLAGS -LARGEADDRESSAWARE -NXCOMPAT"
             if test -z "$DEVELOPER_OPTIONS"; then
                 LDFLAGS="$LDFLAGS -RELEASE"
             fi
         fi
@@ -1948,17 +1945,17 @@ dnl ====================================
 dnl = Flags to strip unused symbols from .so components
 dnl ========================================================
 case "$target" in
     *-linux*|*-kfreebsd*-gnu|*-gnu*)
         MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script'
         ;;
     *-solaris*)
         if test -z "$GNU_CC"; then
-         MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-M $(BUILD_TOOLS)/gnu-ld-scripts/components-mapfile'
+         eOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-M $(BUILD_TOOLS)/gnu-ld-scripts/components-mapfile'
         else
          if test -z "$GCC_USE_GNU_LD"; then
           MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,-M -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-mapfile'
          else
           MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS='-Wl,--version-script -Wl,$(BUILD_TOOLS)/gnu-ld-scripts/components-version-script'
          fi
         fi
         ;;
@@ -2767,23 +2764,26 @@ JS_THREADSAFE_CONFIGURED=$JS_THREADSAFE
 AC_SUBST(JS_THREADSAFE_CONFIGURED)
 
 MOZ_CONFIG_NSPR(js)
 
 dnl ========================================================
 dnl system zlib Support
 dnl ========================================================
 dnl Standalone js defaults to system zlib
-ZLIB_DIR=yes
+if test -n "$JS_STANDALONE"; then
+    ZLIB_DIR=yes
+fi
 
 MOZ_ZLIB_CHECK([1.2.3])
 
 if test -n "$ZLIB_IN_MOZGLUE"; then
     AC_DEFINE(ZLIB_IN_MOZGLUE)
 fi
+AC_SUBST(ZLIB_IN_MOZGLUE)
 
 dnl ========================================================
 dnl system libffi Support
 dnl ========================================================
 MOZ_CONFIG_FFI()
 
 dnl ========================================================
 dnl =
@@ -3610,17 +3610,17 @@ fi
 dnl ========================================================
 dnl = Link js shell to system readline
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(readline,
 [  --enable-readline       Link js shell to system readline library],
     JS_WANT_READLINE=1,
     JS_WANT_READLINE= )
 
-JS_NATIVE_EDITLINE=
+JS_BUNDLED_EDITLINE=
 EDITLINE_LIBS=
 JS_DISABLE_SHELL=
 
 case "$target" in
 *-mingw*)
     NO_EDITLINE=1
     ;;
 *)
@@ -3629,24 +3629,23 @@ esac
 
 if test -z "$SKIP_LIBRARY_CHECKS" -a -z "$NO_EDITLINE"; then
   if test -n "$JS_WANT_READLINE"; then
     AC_CHECK_LIB(readline, readline,
                  EDITLINE_LIBS="-lreadline",
                  AC_MSG_ERROR([No system readline library found.]))
   else
     dnl By default, we use editline
-    JS_NATIVE_EDITLINE=1
-    EDITLINE_LIBS='$(DEPTH)/js/src/editline/$(LIB_PREFIX)editline.$(LIB_SUFFIX)'
+    JS_BUNDLED_EDITLINE=1
   fi
 
   dnl Either way, we want to build with line editing support.
   AC_DEFINE(EDITLINE)
 fi
-AC_SUBST(JS_NATIVE_EDITLINE)
+AC_SUBST(JS_BUNDLED_EDITLINE)
 AC_SUBST(JS_DISABLE_SHELL)
 AC_SUBST(EDITLINE_LIBS)
 
 dnl ========================================================
 dnl =
 dnl = Standalone module options
 dnl =
 dnl ========================================================
@@ -3726,17 +3725,16 @@ AC_SUBST(MOZ_PROFILING)
 AC_SUBST(LIBICONV)
 
 AC_SUBST(ENABLE_TESTS)
 
 AC_SUBST(ENABLE_STRIP)
 AC_SUBST(PKG_SKIP_STRIP)
 AC_SUBST(INCREMENTAL_LINKER)
 AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
-AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
 
 AC_SUBST(MOZ_FIX_LINK_PATHS)
 
 AC_SUBST(USE_DEPENDENT_LIBS)
 
 AC_SUBST(MOZ_BUILD_ROOT)
 
 AC_SUBST(MOZ_POST_DSO_LIB_COMMAND)
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -1,15 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # 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 = ../$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
+LIBS += $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 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
--- a/js/src/gdb/moz.build
+++ b/js/src/gdb/moz.build
@@ -20,8 +20,12 @@ UNIFIED_SOURCES += [
 
 # Building against js_static requires that we declare mfbt sybols "exported"
 # on its behalf.
 for var in ('EXPORT_JS_API', 'IMPL_MFBT'):
     DEFINES[var] = True
 
 LOCAL_INCLUDES += ['..']
 GENERATED_INCLUDES += ['..']
+
+USE_LIBS += [
+    'static:js',
+]
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -1,15 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # 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      = ../$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
+LIBS      += $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 ifdef MOZ_SHARED_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 
 ifdef QEMU_EXE
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -88,8 +88,12 @@ if CONFIG['ENABLE_ION']:
 
 DEFINES['EXPORT_JS_API'] = True
 # Building against js_static requires that we declare mfbt sybols "exported"
 # on its behalf.
 DEFINES['IMPL_MFBT'] = True
 
 LOCAL_INCLUDES += ['..']
 GENERATED_INCLUDES += ['..']
+
+USE_LIBS += [
+    'static:js',
+]
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -2,38 +2,39 @@
 # vim: set filetype=python:
 # 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/.
 
 if CONFIG['DEHYDRA_PATH']:
     DIRS += ['analysis-tests']
 
-if CONFIG['JS_NATIVE_EDITLINE']:
+if CONFIG['JS_BUNDLED_EDITLINE']:
     DIRS += ['editline']
 
 # editline needs to get built before the shell
 if not CONFIG['JS_DISABLE_SHELL']:
     DIRS += ['shell']
 
 TEST_DIRS += ['jsapi-tests', 'tests', 'gdb']
 
 LOCAL_INCLUDES += ['../../mfbt/double-conversion']
 
-LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
-
 CONFIGURE_SUBST_FILES += [
     'devtools/rootAnalysis/Makefile',
     'js-confdefs.h',
     'js-config',
     'js.pc',
 ]
 
 if CONFIG['JS_STANDALONE']:
     DEFINES['IMPL_MFBT'] = True
+    USE_LIBS += [
+        'mfbt',
+    ]
 else:
     CONFIGURE_SUBST_FILES += [
         '../../config/autoconf-js.mk',
         '../../config/emptyvars-js.mk',
     ]
 
 CONFIGURE_DEFINE_FILES += [
     'js-config.h',
@@ -421,23 +422,31 @@ HOST_SIMPLE_PROGRAMS += [
 # JavaScript must be built shared, even for static builds, as it is used by
 # other modules which are always built shared. Failure to do so results in
 # the js code getting copied into xpinstall and jsd as well as mozilla-bin,
 # and then the static data cells used for locking no longer work.
 #
 # In fact, we now build both a static and a shared library, as the
 # JS shell would like to link to the static library.
 
+LIBRARY_NAME = 'js'
+
 if CONFIG['JS_SHARED_LIBRARY']:
     FORCE_SHARED_LIB = True
+    SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
     SDK_LIBRARY = True
 
 FORCE_STATIC_LIB = True
 STATIC_LIBRARY_NAME = 'js_static'
 
+if not CONFIG['MOZ_NATIVE_ZLIB'] and not CONFIG['ZLIB_IN_MOZGLUE']:
+    USE_LIBS += [
+        'mozz',
+    ]
+
 if CONFIG['MOZ_ETW']:
     GENERATED_FILES = [
         'ETWProvider.h',
     ]
     # This will get the ETW provider resources into the library mozjs.dll
     RESFILE = 'ETWProvider.res'
 
 if CONFIG['NIGHTLY_BUILD']:
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -1,15 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # 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      = $(NSPR_LIBS) $(EDITLINE_LIBS) ../$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(MOZ_ZLIB_LIBS)
+LIBS      += $(NSPR_LIBS) $(EDITLINE_LIBS) $(MOZ_ZLIB_LIBS)
 ifdef MOZ_NATIVE_FFI
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 endif
 ifdef MOZ_SHARED_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 ifeq ($(OS_ARCH),Darwin)
--- a/js/src/shell/moz.build
+++ b/js/src/shell/moz.build
@@ -1,16 +1,19 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 if CONFIG['JS_SHELL_NAME']:
     PROGRAM = CONFIG['JS_SHELL_NAME']
+    if CONFIG['JS_BUNDLED_EDITLINE']:
+        USE_LIBS += ['editline']
+    USE_LIBS += ['static:js']
 
 UNIFIED_SOURCES += [
     'js.cpp',
     'jsheaptools.cpp',
     'jsoptparse.cpp',
 ]
 
 # Building against js_static requires that we declare mfbt sybols "exported"
--- a/js/xpconnect/shell/Makefile.in
+++ b/js/xpconnect/shell/Makefile.in
@@ -1,22 +1,12 @@
 #
 # 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/.
 
 SDK_BINARY	= $(PROGRAM)
 
-LIBS		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(LIBXUL_LIBS) \
-		$(XPCOM_LIBS) \
-		$(NULL)
-
 LIBS +=	$(NSPR_LIBS)
 
 NSDISTMODE = copy
 
-ifeq ($(OS_TEST),ia64)
-LIBS += $(JEMALLOC_LIBS)
-endif
-
 include $(topsrcdir)/config/rules.mk
--- a/js/xpconnect/shell/moz.build
+++ b/js/xpconnect/shell/moz.build
@@ -32,8 +32,14 @@ LOCAL_INCLUDES += [
 
 if CONFIG['_MSC_VER']:
     # Always enter a Windows program through wmain, whether or not we're
     # a console application.
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     RCINCLUDE = 'xpcshell.rc'
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/js/xpconnect/tests/Makefile.in
+++ b/js/xpconnect/tests/Makefile.in
@@ -1,9 +1,8 @@
 #
 # 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 = \
-  $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-  $(MOZ_COMPONENT_LIBS) \
+LIBS += \
+  $(NSPR_LIBS) \
   $(NULL)
--- a/js/xpconnect/tests/components/native/Makefile.in
+++ b/js/xpconnect/tests/components/native/Makefile.in
@@ -5,15 +5,14 @@
 
 componentdir = js/xpconnect/tests/components/native
 
 MANIFEST = xpctest.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(componentdir)
 PP_TARGETS += MANIFEST
 
 EXTRA_DSO_LDOPTS += \
-  $(XPCOM_GLUE_LDOPTS) \
-  $(MOZ_COMPONENT_LIBS) \
+  $(NSPR_LIBS) \
   $(NULL)
 
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(componentdir)
 INSTALL_TARGETS += LIB
--- a/js/xpconnect/tests/components/native/moz.build
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -18,8 +18,14 @@ IS_COMPONENT = True
 
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
 
 FAIL_ON_WARNINGS = True
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/js/xpconnect/tests/moz.build
+++ b/js/xpconnect/tests/moz.build
@@ -10,8 +10,13 @@ TEST_TOOL_DIRS += [
     'chrome',
     'browser',
     'components/native',
     'components/js',
 ]
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/layout/media/Makefile.in
+++ b/layout/media/Makefile.in
@@ -1,15 +1,15 @@
 #
 # 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/.
 
 ifeq (WINNT,$(OS_TARGET))
-EXTRA_DSO_LDOPTS = $(MOZALLOC_LIB) $(NSPR_LIBS)
+EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
 OS_LIBS += $(call EXPAND_LIBNAME,usp10 ole32)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq (WINNT,$(OS_TARGET))
 symbols.def: symbols.def.in $(GLOBAL_DEPS)
 	$(call py_action,preprocessor,$(ACDEFINES) $< -o $@)
--- a/layout/media/moz.build
+++ b/layout/media/moz.build
@@ -3,14 +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/.
 
 LIBRARY_NAME = 'gkmedias'
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     FORCE_SHARED_LIB = True
+    USE_LIBS += [
+        'mozalloc',
+    ]
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += ['webrtc']
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     DEFFILE = 'symbols.def'
--- a/media/libcubeb/tests/Makefile.in
+++ b/media/libcubeb/tests/Makefile.in
@@ -1,31 +1,15 @@
 # -*- Mode: makefile; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- #
 # 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/.
 
-ifeq ($(OS_ARCH),WINNT)
-  # On windows, the WASAPI backend needs the resampler we have in
-  # /media/libspeex_resampler, so we can't get away with just linking cubeb's .o
-  LIBS = $(call EXPAND_LIBNAME_PATH,gkmedias,$(DEPTH)/layout/media) \
-         $(NULL)
+ifeq ($(OS_TARGET),Darwin)
+  LIBS += -framework AudioUnit -framework CoreAudio
 else
-  # Otherwise, we can just grab all the compiled .o and compile against that,
-  # linking the appriopriate libraries.
-  LIBS = $(call EXPAND_LIBNAME_PATH,cubeb,$(DEPTH)/media/libcubeb/src)
-  # Don't link gkmedias for it introduces dependencies on Android.
-  ifeq ($(OS_TARGET),Android)
-    LIBS += $(call EXPAND_LIBNAME_PATH,speex,$(DEPTH)/media/libspeex_resampler/src)
+  ifeq ($(OS_TARGET), OpenBSD)
+    LIBS += -lsndio
+  else
+    LIBS += $(MOZ_ALSA_LIBS) \
+            $(MOZ_PULSEAUDIO_LIBS)
   endif
-
-  ifeq ($(OS_TARGET),Darwin)
-    LIBS += -framework AudioUnit -framework CoreAudio
-  else
-    ifeq ($(OS_TARGET), OpenBSD)
-      LIBS += -lsndio
-    else
-      LIBS += $(MOZ_ALSA_LIBS) \
-              $(MOZ_PULSEAUDIO_LIBS)
-    endif
-  endif
-  LIBS += $(NULL)
 endif
--- a/media/libcubeb/tests/moz.build
+++ b/media/libcubeb/tests/moz.build
@@ -18,8 +18,32 @@ if CONFIG['OS_TARGET'] != 'Android':
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 LOCAL_INCLUDES += [
     '../include'
 ]
 
 FAIL_ON_WARNINGS = True
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    # On windows, the WASAPI backend needs the resampler we have in
+    # /media/libspeex_resampler, so we can't get away with just linking cubeb's
+    # .o
+    USE_LIBS += [
+        'gkmedias',
+    ]
+else:
+    # Otherwise, we can just grab all the compiled .o and compile against that,
+    # linking the appriopriate libraries.
+    USE_LIBS += [
+        'cubeb',
+    ]
+    # Don't link gkmedias for it introduces dependencies on Android.
+    if CONFIG['OS_TARGET'] == 'Android':
+        USE_LIBS += [
+            'speex',
+        ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/media/mtransport/test/Makefile.in
+++ b/media/mtransport/test/Makefile.in
@@ -1,37 +1,28 @@
 # -*- Mode: makefile; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- #
 # 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 = \
-  $(XPCOM_LIBS) \
+LIBS += \
   $(NSPR_LIBS) \
-  $(DEPTH)/media/mtransport/standalone/$(LIB_PREFIX)mtransport_s.$(LIB_SUFFIX) \
-  $(DEPTH)/media/mtransport/third_party/nICEr/nicer_nicer/$(LIB_PREFIX)nicer.$(LIB_SUFFIX) \
-  $(DEPTH)/media/mtransport/third_party/nrappkit/nrappkit_nrappkit/$(LIB_PREFIX)nrappkit.$(LIB_SUFFIX) \
-  $(DEPTH)/media/webrtc/trunk/testing/gtest_gtest/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) \
   $(NULL)
 
 ifdef MOZ_NATIVE_NSS
 LIBS += $(NSS_LIBS)
 else
 # Statically linking NSS libssl ensures that we can debug NSS too
 LIBS += \
   $(DEPTH)/dist/lib/$(LIB_PREFIX)ssl.$(LIB_SUFFIX) \
   $(DEPTH)/dist/lib/$(LIB_PREFIX)nss3.$(LIB_SUFFIX) \
   $(DEPTH)/dist/lib/$(LIB_PREFIX)nssutil3.$(LIB_SUFFIX) \
   $(NULL)
 endif
 
-ifdef MOZ_SCTP
-LIBS += $(DEPTH)/netwerk/sctp/src/$(LIB_PREFIX)nksctp_s.$(LIB_SUFFIX)
-endif
-
 ifeq ($(OS_TARGET), Android)
 LIBS += \
   $(STLPORT_LDFLAGS) \
   $(STLPORT_LIBS) \
   $(NULL)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
--- a/media/mtransport/test/moz.build
+++ b/media/mtransport/test/moz.build
@@ -78,8 +78,22 @@ LOCAL_INCLUDES += [
     '/media/mtransport/third_party/nrappkit/src/share',
     '/media/mtransport/third_party/nrappkit/src/stats',
     '/media/mtransport/third_party/nrappkit/src/util/',
     '/media/mtransport/third_party/nrappkit/src/util/libekr',
     '/media/webrtc/trunk/testing/gtest/include/',
     '/netwerk/sctp/src/',
 ]
 
+USE_LIBS += [
+    '/media/webrtc/trunk/testing/gtest_gtest/gtest',
+    'mozalloc',
+    'mtransport_s',
+    'nicer',
+    'nrappkit',
+    'xpcomglue_s',
+    'xul-shared',
+]
+
+if CONFIG['MOZ_SCTP']:
+    USE_LIBS += [
+        'nksctp_s',
+    ]
--- a/media/omx-plugin/Makefile.in
+++ b/media/omx-plugin/Makefile.in
@@ -14,18 +14,9 @@
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
 EXTRA_DSO_LDOPTS += \
                -lutils -lstagefright -lmedia -lstagefright_omx -lbinder -lui \
                -lhardware -lcutils \
 		$(NULL)
-else
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libstagefright \
-		-lstagefright \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libvideoeditorplayer \
-		-lvideoeditorplayer \
-		$(NULL)
 endif
deleted file mode 100644
--- a/media/omx-plugin/froyo/Makefile.in
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/froyo/libstagefright \
-		-lstagefright \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libstagefright_color_conversion \
-		-lstagefright_color_conversion \
-		$(NULL)
-
--- a/media/omx-plugin/froyo/moz.build
+++ b/media/omx-plugin/froyo/moz.build
@@ -13,14 +13,20 @@ LIBRARY_NAME = 'omxpluginfroyo'
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '../../../content/media/plugins',
     '../include/froyo',
     '../include/froyo/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/froyo/libstagefright/stagefright',
+    '/media/omx-plugin/lib/gb/libutils/utils',
+    'stagefright_color_conversion',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
 
 # Suppress warnings in third-party code.
 CXXFLAGS += ['-Wno-multichar']
deleted file mode 100644
--- a/media/omx-plugin/gb/Makefile.in
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libstagefright \
-		-lstagefright \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libstagefright_color_conversion \
-		-lstagefright_color_conversion \
-		$(NULL)
-
--- a/media/omx-plugin/gb/moz.build
+++ b/media/omx-plugin/gb/moz.build
@@ -13,14 +13,20 @@ LIBRARY_NAME = 'omxplugingb'
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '../../../content/media/plugins',
     '../include/gb',
     '../include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libstagefright/stagefright',
+    '/media/omx-plugin/lib/gb/libutils/utils',
+    'stagefright_color_conversion',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
 
 # Suppress warnings in third-party code.
 CXXFLAGS += ['-Wno-multichar']
deleted file mode 100644
--- a/media/omx-plugin/gb235/Makefile.in
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/gb235/libstagefright \
-		-lstagefright \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libstagefright_color_conversion \
-		-lstagefright_color_conversion \
-		$(NULL)
-
--- a/media/omx-plugin/gb235/moz.build
+++ b/media/omx-plugin/gb235/moz.build
@@ -13,14 +13,20 @@ LIBRARY_NAME = 'omxplugingb235'
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '../../../content/media/plugins',
     '../include/gb',
     '../include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+    '/media/omx-plugin/lib/gb235/libstagefright/stagefright',
+    'stagefright_color_conversion',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
 
 # Suppress warnings in third-party code.
 CXXFLAGS += ['-Wno-multichar']
deleted file mode 100644
--- a/media/omx-plugin/hc/Makefile.in
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/hc/libstagefright \
-		-lstagefright \
-		$(NULL)
-
--- a/media/omx-plugin/hc/moz.build
+++ b/media/omx-plugin/hc/moz.build
@@ -13,14 +13,19 @@ LIBRARY_NAME = 'omxpluginhc'
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '../../../content/media/plugins',
     '../include/gb',
     '../include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+    '/media/omx-plugin/lib/hc/libstagefright/stagefright',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
 
 # Suppress warnings in third-party code.
 CXXFLAGS += ['-Wno-multichar']
deleted file mode 100644
--- a/media/omx-plugin/kk/Makefile.in
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libutils \
-		-lutils \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libstagefright \
-		-lstagefright \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libvideoeditorplayer \
-		-lvideoeditorplayer \
-		$(NULL)
-
--- a/media/omx-plugin/kk/moz.build
+++ b/media/omx-plugin/kk/moz.build
@@ -13,14 +13,20 @@ LIBRARY_NAME = 'omxpluginkk'
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '../../../content/media/plugins',
     '../include/ics',
     '../include/ics/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/ics/libstagefright/stagefright',
+    '/media/omx-plugin/lib/ics/libutils/utils',
+    'videoeditorplayer',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
 
 # Suppress warnings in third-party code.
 CXXFLAGS += ['-Wno-multichar']
deleted file mode 100644
--- a/media/omx-plugin/lib/froyo/libstagefright/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		$(NULL)
--- a/media/omx-plugin/lib/froyo/libstagefright/moz.build
+++ b/media/omx-plugin/lib/froyo/libstagefright/moz.build
@@ -14,11 +14,15 @@ LIBRARY_NAME = 'stagefright'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/media/omx-plugin/include/froyo',
     '/media/omx-plugin/include/froyo/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
deleted file mode 100644
--- a/media/omx-plugin/lib/gb/libstagefright/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		$(NULL)
--- a/media/omx-plugin/lib/gb/libstagefright/moz.build
+++ b/media/omx-plugin/lib/gb/libstagefright/moz.build
@@ -14,11 +14,15 @@ LIBRARY_NAME = 'stagefright'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/media/omx-plugin/include/gb',
     '/media/omx-plugin/include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
deleted file mode 100644
--- a/media/omx-plugin/lib/gb235/libstagefright/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		$(NULL)
--- a/media/omx-plugin/lib/gb235/libstagefright/moz.build
+++ b/media/omx-plugin/lib/gb235/libstagefright/moz.build
@@ -14,11 +14,15 @@ LIBRARY_NAME = 'stagefright'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/media/omx-plugin/include/gb',
     '/media/omx-plugin/include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
deleted file mode 100644
--- a/media/omx-plugin/lib/hc/libstagefright/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/gb/libutils \
-		-lutils \
-		$(NULL)
--- a/media/omx-plugin/lib/hc/libstagefright/moz.build
+++ b/media/omx-plugin/lib/hc/libstagefright/moz.build
@@ -14,11 +14,15 @@ LIBRARY_NAME = 'stagefright'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/media/omx-plugin/include/gb',
     '/media/omx-plugin/include/gb/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/gb/libutils/utils',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
deleted file mode 100644
--- a/media/omx-plugin/lib/ics/libstagefright/Makefile.in
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2012 Mozilla Foundation and Mozilla contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-include $(topsrcdir)/config/rules.mk
-
-EXTRA_DSO_LDOPTS += \
-		-L$(DEPTH)/media/omx-plugin/lib/ics/libutils \
-		-lutils \
-		$(NULL)
--- a/media/omx-plugin/lib/ics/libstagefright/moz.build
+++ b/media/omx-plugin/lib/ics/libstagefright/moz.build
@@ -14,11 +14,15 @@ LIBRARY_NAME = 'stagefright'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/media/omx-plugin/include/ics',
     '/media/omx-plugin/include/ics/media/stagefright/openmax',
 ]
 
+USE_LIBS += [
+    '/media/omx-plugin/lib/ics/libutils/utils',
+]
+
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
--- a/media/omx-plugin/moz.build
+++ b/media/omx-plugin/moz.build
@@ -48,12 +48,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
              'frameworks/base/include/media/',
              'frameworks/base/include/media/stagefright/openmax',
              'frameworks/base/media/libstagefright/include',
              'frameworks/base/native/include',
              'system/core/include',
              'hardware/libhardware/include',
          ]
     ]
+else:
+    USE_LIBS += [
+        '/media/omx-plugin/lib/ics/libstagefright/stagefright',
+        '/media/omx-plugin/lib/ics/libutils/utils',
+        'videoeditorplayer',
+    ]
 
 # Don't use STL wrappers; this isn't Gecko code
 DISABLE_STL_WRAPPING = True
 NO_VISIBILITY_FLAGS = True
--- a/media/webrtc/signaling/test/Makefile.in
+++ b/media/webrtc/signaling/test/Makefile.in
@@ -1,37 +1,19 @@
 # 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 = \
-  $(XPCOM_LIBS) \
+LIBS += \
   $(NSPR_LIBS) \
   $(NSS_LIBS) \
   $(MOZ_WEBRTC_X11_LIBS) \
   $(REALTIME_LIBS) \
-  $(DEPTH)/xpcom/glue/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-  $(DEPTH)/media/mtransport/standalone/$(LIB_PREFIX)mtransport_s.$(LIB_SUFFIX) \
-  $(DEPTH)/media/webrtc/signalingtest/signaling_ecc/$(LIB_PREFIX)ecc.$(LIB_SUFFIX) \
-  $(DEPTH)/media/webrtc/signalingtest/signaling_sipcc/$(LIB_PREFIX)sipcc.$(LIB_SUFFIX) \
-  $(DEPTH)/layout/media/webrtc/$(LIB_PREFIX)webrtc.$(LIB_SUFFIX) \
-  $(DEPTH)/layout/media/$(LIB_PREFIX)gkmedias.$(LIB_SUFFIX) \
-  $(DEPTH)/media/webrtc/trunk/testing/gtest_gtest/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) \
-  $(DEPTH)/media/libyuv/libyuv_libyuv/$(LIB_PREFIX)yuv.$(LIB_SUFFIX) \
-  $(DEPTH)/netwerk/srtp/src/$(LIB_PREFIX)nksrtp_s.$(LIB_SUFFIX) \
   $(NULL)
 
-ifdef BUILD_ARM_NEON
-LIBS += $(DEPTH)/media/libyuv/libyuv_libyuv_neon/$(LIB_PREFIX)yuv_neon.$(LIB_SUFFIX)
-endif
-
-ifdef JS_SHARED_LIBRARY
-LIBS += $(MOZ_JS_LIBS)
-endif
-
 ifdef MOZ_ALSA
 LIBS += \
   $(MOZ_ALSA_LIBS) \
   $(NULL)
 endif
 
 ifeq ($(OS_TARGET),Android)
 LIBS += \
@@ -91,21 +73,15 @@ LIBS += \
 endif
 
 ifeq ($(OS_TARGET),Darwin)
 LIBS += \
   $(TK_LIBS) \
   $(NULL)
 endif
 
-ifeq ($(OS_TARGET),WINNT)
-LIBS += \
-  $(DEPTH)/staticlib/components/$(LIB_PREFIX)windowsproxy.$(LIB_SUFFIX) \
-  $(NULL)
-endif
-
-ifndef ZLIB_IN_MOZGLUE
+ifdef MOZ_NATIVE_ZLIB
 LIBS += $(MOZ_ZLIB_LIBS)
 endif
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/media/webrtc/webrtc-config.mk
 include $(topsrcdir)/config/rules.mk
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -87,8 +87,37 @@ if CONFIG['OS_TARGET'] == 'Darwin':
         '-framework CoreUI',
     ]
 
 if CONFIG['OS_TARGET'] in ('DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD'):
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/darwin/include',
         '/media/mtransport/third_party/nrappkit/src/port/generic/include',
     ]
+
+USE_LIBS += [
+    '/media/webrtc/signalingtest/signaling_ecc/ecc',
+    '/media/webrtc/signalingtest/signaling_sipcc/sipcc',
+    '/media/webrtc/trunk/testing/gtest_gtest/gtest',
+    'gkmedias',
+    'mozalloc',
+    'mtransport_s',
+    'nksrtp_s',
+    'webrtc',
+    'xpcomglue_s',
+    'xul-shared',
+    'yuv',
+]
+
+if CONFIG['BUILD_ARM_NEON']:
+    USE_LIBS += [
+        'yuv_neon',
+    ]
+
+if not CONFIG['MOZ_NATIVE_ZLIB'] and not CONFIG['ZLIB_IN_MOZGLUE']:
+    USE_LIBS += [
+        'mozz',
+    ]
+
+if CONFIG['JS_SHARED_LIBRARY']:
+    USE_LIBS += [
+        'js',
+    ]
--- a/memory/build/Makefile.in
+++ b/memory/build/Makefile.in
@@ -1,16 +1,8 @@
 # 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/.
 
 STLFLAGS =
 ifdef MOZ_GLUE_PROGRAM_LDFLAGS
 DIST_INSTALL = 1
 endif
-
-ifdef MOZ_JEMALLOC3
-ifndef MOZ_NATIVE_JEMALLOC
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
-endif
-else
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/mozjemalloc)
-endif
--- a/memory/build/moz.build
+++ b/memory/build/moz.build
@@ -33,16 +33,26 @@ if CONFIG['MOZ_JEMALLOC3']:
 
 if CONFIG['MOZ_REPLACE_MALLOC']:
     SOURCES += [
         'replace_malloc.c',
     ]
 
 LIBRARY_NAME = 'memory'
 
+if CONFIG['MOZ_JEMALLOC3']:
+    if not CONFIG['MOZ_NATIVE_JEMALLOC']:
+        USE_LIBS += [
+            'jemalloc',
+        ]
+else:
+    USE_LIBS += [
+        'mozjemalloc',
+    ]
+
 if CONFIG['MOZ_GLUE_PROGRAM_LDFLAGS']:
     SDK_LIBRARY = True
 
 # Keep jemalloc separated when mozglue is statically linked
 if CONFIG['MOZ_MEMORY'] and (CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android') or
                              CONFIG['MOZ_NATIVE_JEMALLOC']):
     FINAL_LIBRARY = 'mozglue'
 
--- a/memory/mozalloc/tests/moz.build
+++ b/memory/mozalloc/tests/moz.build
@@ -4,8 +4,14 @@
 # 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/.
 
 CPP_UNIT_TESTS += [
     'TestVolatileBuffer',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/memory/mozjemalloc/moz.build
+++ b/memory/mozjemalloc/moz.build
@@ -7,17 +7,18 @@
 EXPORTS += [
     'jemalloc_types.h',
 ]
 
 if not CONFIG['MOZ_JEMALLOC3']:
     SOURCES += [
         'jemalloc.c',
     ]
-    LIBRARY_NAME = 'jemalloc'
+    LIBRARY_NAME = 'mozjemalloc'
+    STATIC_LIBRARY_NAME = 'jemalloc'
     FORCE_STATIC_LIB = True
 
 # For non release/esr builds, enable (some) fatal jemalloc assertions.  This
 # helps us catch memory errors.
 if CONFIG['MOZ_UPDATE_CHANNEL'] not in ('release', 'esr'):
     DEFINES['MOZ_JEMALLOC_HARD_ASSERTS'] = True
 
 DEFINES['abort'] = 'moz_abort'
--- a/memory/replace/jemalloc/Makefile.in
+++ b/memory/replace/jemalloc/Makefile.in
@@ -1,8 +1,6 @@
 # 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/.
 
-SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
-
 MOZ_GLUE_LDFLAGS = # Don't link against mozglue
 WRAP_LDFLAGS = # Never wrap malloc function calls with -Wl,--wrap
--- a/memory/replace/jemalloc/moz.build
+++ b/memory/replace/jemalloc/moz.build
@@ -14,16 +14,20 @@ SOURCES += [
 # Android.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     SOURCES += [
         'pthread_atfork.c',
     ]
 
 LIBRARY_NAME = 'replace_jemalloc'
 
+USE_LIBS += [
+    'jemalloc',
+]
+
 FORCE_SHARED_LIB = True
 
 DEFINES['MOZ_JEMALLOC3'] = True
 DEFINES['MOZ_REPLACE_JEMALLOC'] = True
 
 GENERATED_INCLUDES += ['../../jemalloc/src/include']
 if CONFIG['_MSC_VER']:
     LOCAL_INCLUDES += ['/memory/jemalloc/src/include/msvc_compat']
--- a/mfbt/tests/Makefile.in
+++ b/mfbt/tests/Makefile.in
@@ -6,11 +6,12 @@
 # not available to MFBT, we have to reset these MOZ_GLUE*_LDFLAGS before including it
 # and LIBS_ after including it. For WRAP_LDFLAGS, it shouldn't matter.
 # See later comments in bug 732875.
 
 MOZ_GLUE_PROGRAM_LDFLAGS=
 MOZ_GLUE_LDFLAGS =
 WRAP_LDFLAGS=
 
-include $(topsrcdir)/config/rules.mk
+# Prevent those tests linking against libxpcom, libxul, and nspr.
+NSPR_LIBS=
 
-LIBS= $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
+include $(topsrcdir)/config/rules.mk
--- a/mfbt/tests/moz.build
+++ b/mfbt/tests/moz.build
@@ -43,8 +43,12 @@ DISABLE_STL_WRAPPING = True
 
 if CONFIG['_MSC_VER']:
   CXXFLAGS += [
     '-wd4275', # non dll-interface class used as base for dll-interface class
     '-wd4530', # C++ exception handler used, but unwind semantics are not enabled
   ]
 
 FAIL_ON_WARNINGS = True
+
+USE_LIBS += [
+    'mfbt',
+]
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -12,22 +12,18 @@
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
 HOST_CFLAGS += \
   -DNO_SIGN_VERIFY \
   $(DEFINES) \
   $(NULL)
 
-LIBS = $(DEPTH)/modules/libmar/src/$(LIB_PREFIX)mar.$(LIB_SUFFIX)
-
 ifdef MOZ_ENABLE_SIGNMAR
 LIBS += \
-  $(DEPTH)/modules/libmar/sign/$(LIB_PREFIX)signmar.$(LIB_SUFFIX) \
-  $(DEPTH)/modules/libmar/verify/$(LIB_PREFIX)verifymar.$(LIB_SUFFIX) \
   $(DIST)/lib/$(LIB_PREFIX)nss3.$(LIB_SUFFIX) \
   $(DIST)/lib/$(LIB_PREFIX)nssutil3.$(LIB_SUFFIX) \
   $(NSPR_LIBS) \
   $(NULL)
 endif
 
 ifeq ($(HOST_OS_ARCH),WINNT)
 HOST_EXTRA_LIBS += $(call EXPAND_LIBNAME,ws2_32)
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -25,8 +25,18 @@ if not CONFIG['MOZ_ENABLE_SIGNMAR']:
     DEFINES['NO_SIGN_VERIFY'] = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_STATIC_LIBS = True
 elif CONFIG['OS_ARCH'] == 'Darwin':
     LDFLAGS += [
       '-framework Security',
     ]
+
+USE_LIBS += [
+    'mar',
+]
+
+if CONFIG['MOZ_ENABLE_SIGNMAR']:
+    USE_LIBS += [
+        'signmar',
+        'verifymar',
+    ]
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -5,23 +5,19 @@
 
 DIST_INSTALL = 1
 
 # For FORCE_SHARED_LIB
 include $(topsrcdir)/config/config.mk
 
 MOZ_GLUE_LDFLAGS = # Don't link against ourselves
 
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
-
 ifneq (,$(ZLIB_IN_MOZGLUE)$(MOZ_LINKER))
 ifdef MOZ_NATIVE_ZLIB
 EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
-else
-SHARED_LIBRARY_LIBS += $(MOZ_ZLIB_LIBS)
 endif
 endif
 
 ifeq (WINNT,$(OS_TARGET))
 mozglue.def: mozglue.def.in
 	$(call py_action,preprocessor,$(if $(MOZ_REPLACE_MALLOC),-DMOZ_REPLACE_MALLOC) $(ACDEFINES) $< -o $@)
 
 GARBAGE += mozglue.def
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -63,14 +63,23 @@ if CONFIG['CPU_ARCH'] == 'arm':
 if CONFIG['MOZ_ASAN']:
     SOURCES += [
         'AsanOptions.cpp',
     ]
 
 
 LIBRARY_NAME = 'mozglue'
 
+USE_LIBS += [
+    'mfbt',
+]
+
+if CONFIG['ZLIB_IN_MOZGLUE'] and not CONFIG['MOZ_NATIVE_ZLIB']:
+    USE_LIBS += [
+        'mozz',
+    ]
+
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     SOURCES += [
         'cpuacct.c',
     ]
 
 DEFINES['IMPL_MFBT'] = True
--- a/mozglue/tests/Makefile.in
+++ b/mozglue/tests/Makefile.in
@@ -1,18 +1,16 @@
 # 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/.
 
 ifdef MOZ_LINKER
 # Only link against the linker, not mozglue
 MOZ_GLUE_PROGRAM_LDFLAGS =
 MOZ_GLUE_LDFLAGS =
-LIBS += $(call EXPAND_LIBNAME_PATH,linker,../linker)
-
 EXTRA_LIBS = $(MOZ_ZLIB_LIBS)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_LINKER
 check::
 	@$(EXIT_ON_ERROR) ./TestZip$(BIN_SUFFIX) $(srcdir)
--- a/mozglue/tests/moz.build
+++ b/mozglue/tests/moz.build
@@ -10,9 +10,12 @@ if CONFIG['MOZ_LINKER']:
     SOURCES += [
         'ShowSSEConfig.cpp',
         'TestZip.cpp',
     ]
     SIMPLE_PROGRAMS += [
         'TestZip',
     ]
     LOCAL_INCLUDES += ['../linker']
+    USE_LIBS += [
+        'linker',
+    ]
     DISABLE_STL_WRAPPING = True
--- a/netwerk/streamconv/test/Makefile.in
+++ b/netwerk/streamconv/test/Makefile.in
@@ -1,12 +1,10 @@
 #
 # 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		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_LIBS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/netwerk/streamconv/test/moz.build
+++ b/netwerk/streamconv/test/moz.build
@@ -14,8 +14,14 @@ UNIFIED_SOURCES += [
 FAIL_ON_WARNINGS = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['NGPREFS'] = True
     if CONFIG['GNU_CXX']:
         LDFLAGS += ['-mconsole']
     else:
         LDFLAGS += ['-SUBSYSTEM:CONSOLE']
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/netwerk/test/Makefile.in
+++ b/netwerk/test/Makefile.in
@@ -1,17 +1,17 @@
 # vim: noexpandtab ts=8 sw=8
 #
 # 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		= $(XPCOM_LIBS) \
+LIBS	+= \
 		  $(NSPR_LIBS) \
 		  $(NULL)
 
 DEFINES += $(TK_CFLAGS)
 
 include $(topsrcdir)/config/rules.mk
 
 check::
--- a/netwerk/test/moz.build
+++ b/netwerk/test/moz.build
@@ -57,8 +57,14 @@ CPP_UNIT_TESTS += [
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 RESOURCE_FILES += [
     'urlparse.dat',
     'urlparse_unx.dat',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/rdf/tests/rdfcat/Makefile.in
+++ b/rdf/tests/rdfcat/Makefile.in
@@ -1,14 +1,12 @@
 #
 # 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		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_LIBS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS += $(TK_CFLAGS)
--- a/rdf/tests/rdfcat/moz.build
+++ b/rdf/tests/rdfcat/moz.build
@@ -4,8 +4,14 @@
 # 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/.
 
 PROGRAM = 'rdfcat'
 
 SOURCES += [
     'rdfcat.cpp',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/rdf/tests/rdfpoll/Makefile.in
+++ b/rdf/tests/rdfpoll/Makefile.in
@@ -1,10 +1,8 @@
 #
 # 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		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_LIBS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
--- a/rdf/tests/rdfpoll/moz.build
+++ b/rdf/tests/rdfpoll/moz.build
@@ -4,8 +4,14 @@
 # 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/.
 
 PROGRAM = 'rdfpoll'
 
 SOURCES += [
     'rdfpoll.cpp',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/rdf/tests/triplescat/Makefile.in
+++ b/rdf/tests/triplescat/Makefile.in
@@ -1,14 +1,12 @@
 #
 # 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		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_LIBS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS += $(TK_CFLAGS)
--- a/rdf/tests/triplescat/moz.build
+++ b/rdf/tests/triplescat/moz.build
@@ -4,8 +4,14 @@
 # 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/.
 
 PROGRAM = 'triplescat'
 
 SOURCES += [
     'triplescat.cpp',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/security/build/Makefile.in
+++ b/security/build/Makefile.in
@@ -324,21 +324,18 @@ else
 SUFFIX = .$(LIB_SUFFIX)
 endif
 
 # Fold NSPR libs
 EXTRA_DSO_LDOPTS += $(DEPTH)/nsprpub/pr/src/$(LIB_PREFIX)nspr4$(SUFFIX)
 EXTRA_DSO_LDOPTS += $(DEPTH)/nsprpub/lib/ds/$(LIB_PREFIX)plds4$(SUFFIX)
 EXTRA_DSO_LDOPTS += $(DEPTH)/nsprpub/lib/libc/src/$(LIB_PREFIX)plc4$(SUFFIX)
 
-# Fold SQLite
-EXTRA_DSO_LDOPTS += $(DEPTH)/db/sqlite3/src/$(LIB_PREFIX)mozsqlite3.$(LIB_SUFFIX)
-
 # Add all static libraries for nss, smime, ssl and nssutil
-SHARED_LIBRARY_LIBS = $(addprefix ../,$(NSS_STATIC_LIBS))
+SHARED_LIBRARY_LIBS += $(addprefix ../,$(NSS_STATIC_LIBS))
 
 nss_def_file := $(srcdir)/nss.def
 
 ifeq (WINNT,$(OS_TARGET))
 # Create a .def file based on the various .def files for nss, smime, ssl and
 # nssutil.
 nss3.def: $(nss_def_file) $(DEPTH)/db/sqlite3/src/sqlite-processed.def
 	echo LIBRARY nss3$(DLL_SUFFIX) > $@.tmp
@@ -364,17 +361,17 @@ endif # WINNT
 endif # MOZ_FOLD_LIBS
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_FOLD_LIBS
 # Force the linker to include everything from the static libraries.
 EXPAND_LIBS_EXEC += --extract
 
-$(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS)
+$(SHARED_LIBRARY): $(addprefix ../,$(NSS_STATIC_LIBS))
 
 EXTRA_DSO_LDOPTS += $(REALTIME_LIBS)
 
 ifdef IMPORT_LIB_SUFFIX
 IMPORT_PREFIX = $(LIB_PREFIX)
 IMPORT_SUFFIX = .$(IMPORT_LIB_SUFFIX)
 else
 IMPORT_PREFIX = $(DLL_PREFIX)
--- a/security/build/moz.build
+++ b/security/build/moz.build
@@ -6,15 +6,19 @@
 
 if CONFIG['MOZ_FOLD_LIBS']:
     # TODO: The library name can be changed when bug 845217 is fixed.
     LIBRARY_NAME = 'nss3'
 
     FORCE_SHARED_LIB = True
     SDK_LIBRARY = True
 
+    USE_LIBS += [
+        'mozsqlite3',
+    ]
+
 if CONFIG['OS_TARGET'] == 'WINNT':
     DEFFILE = 'nss3.def'
 
 if CONFIG['OS_ARCH'] == 'Linux' and \
    CONFIG['MOZ_FOLD_LIBS'] and \
    CONFIG['GCC_USE_GNU_LD']:
     LD_VERSION_SCRIPT = 'nss3.def'
--- a/security/manager/ssl/tests/compiled/moz.build
+++ b/security/manager/ssl/tests/compiled/moz.build
@@ -4,8 +4,14 @@
 # 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/.
 
 CPP_UNIT_TESTS += [
   'TestCertDB',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/Makefile.in
+++ b/security/manager/ssl/tests/unit/tlsserver/cmd/Makefile.in
@@ -1,18 +1,14 @@
 # vim: noexpandtab ts=8 sw=8
 #
 # 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/.
 
 include $(topsrcdir)/config/config.mk
 
-LIBS = \
+LIBS += \
   $(NSPR_LIBS) \
   $(NSS_LIBS) \
-  $(MOZALLOC_LIB) \
-  ../../../../../../pkix/$(LIB_PREFIX)mozillapkix.$(LIB_SUFFIX) \
-  ../../../../../../pkix/test/lib/$(LIB_PREFIX)pkixtestutil.$(LIB_SUFFIX) \
-  ../lib/$(LIB_PREFIX)tlsserver.$(LIB_SUFFIX) \
   $(NULL)
 
 DEFINES += $(TK_CFLAGS)
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
+++ b/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
@@ -15,8 +15,14 @@ SIMPLE_PROGRAMS = [
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
 
 LOCAL_INCLUDES += [
     '../lib',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'mozillapkix',
+    'pkixtestutil',
+    'tlsserver',
+]
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ b/security/sandbox/win/src/sandboxbroker/Makefile.in
@@ -1,12 +1,11 @@
 # 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/.
 #
 MOZ_GLUE_LDFLAGS =
 
 SHARED_LIBRARY_LIBS += \
-	../../../$(LIB_PREFIX)sandbox_s.$(LIB_SUFFIX) \
 	$(NSPR_LIBS) \
 	$(NULL)
 
 OS_LIBS += $(call EXPAND_LIBNAME,dbghelp)
--- a/security/sandbox/win/src/sandboxbroker/moz.build
+++ b/security/sandbox/win/src/sandboxbroker/moz.build
@@ -1,16 +1,20 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 LIBRARY_NAME = 'sandboxbroker'
 
+USE_LIBS += [
+    'sandbox_s',
+]
+
 SOURCES += [
     'sandboxBroker.cpp',
 ]
 
 EXPORTS += [
     'sandboxBroker.h',
 ]
 
--- a/startupcache/test/Makefile.in
+++ b/startupcache/test/Makefile.in
@@ -1,6 +1,6 @@
 #
 # 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 += $(MOZ_COMPONENT_LIBS)
+LIBS += $(NSPR_LIBS)
--- a/startupcache/test/moz.build
+++ b/startupcache/test/moz.build
@@ -9,8 +9,14 @@ CPP_UNIT_TESTS += [
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 EXTRA_COMPONENTS += [
     'TestStartupCacheTelemetry.js',
     'TestStartupCacheTelemetry.manifest',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/storage/test/Makefile.in
+++ b/storage/test/Makefile.in
@@ -1,9 +1,9 @@
 #
 # 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 = \
-	$(MOZ_COMPONENT_LIBS) \
+LIBS += \
+	$(NSPR_LIBS) \
 	$(SQLITE_LIBS) \
 	$(NULL)
--- a/storage/test/moz.build
+++ b/storage/test/moz.build
@@ -30,8 +30,19 @@ if CONFIG['MOZ_DEBUG'] and CONFIG['OS_AR
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 LOCAL_INCLUDES += [
     '../src',
 ]
 
 FAIL_ON_WARNINGS = True
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
+
+if not CONFIG['MOZ_NATIVE_SQLITE'] and not CONFIG['MOZ_FOLD_LIBS']:
+    USE_LIBS += [
+        'mozsqlite3',
+    ]
--- a/testing/mochitest/ssltunnel/Makefile.in
+++ b/testing/mochitest/ssltunnel/Makefile.in
@@ -1,10 +1,9 @@
 #
 # 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 = \
   $(NSPR_LIBS) \
   $(NSS_LIBS) \
-  $(MOZALLOC_LIB) \
   $(NULL)
--- a/testing/mochitest/ssltunnel/moz.build
+++ b/testing/mochitest/ssltunnel/moz.build
@@ -5,11 +5,15 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 PROGRAM = 'ssltunnel'
 
 SOURCES += [
     'ssltunnel.cpp',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+]
+
 # This isn't XPCOM code, but it wants to use STL, so disable the STL
 # wrappers
 DISABLE_STL_WRAPPING = True
--- a/toolkit/components/ctypes/tests/Makefile.in
+++ b/toolkit/components/ctypes/tests/Makefile.in
@@ -1,13 +1,11 @@
 # 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/.
 
-EXTRA_DSO_LDOPTS += $(MOZALLOC_LIB)
-
 LIB_1_FILES = $(SHARED_LIBRARY)
 LIB_1_DEST = $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit
 INSTALL_TARGETS += LIB_1
 
 LIB_3_FILES = $(SHARED_LIBRARY)
 LIB_3_DEST = $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)/chrome
 INSTALL_TARGETS += LIB_3
--- a/toolkit/components/ctypes/tests/moz.build
+++ b/toolkit/components/ctypes/tests/moz.build
@@ -17,8 +17,11 @@ UNIFIED_SOURCES += [
 LIBRARY_NAME = 'jsctypes-test'
 
 FORCE_SHARED_LIB = True
 
 LOCAL_INCLUDES += [
     '/js/src/ctypes',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+]
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -4,22 +4,16 @@
 
 DIST_PROGRAM = maintenanceservice$(BIN_SUFFIX)
 
 # Don't link the maintenanceservice against mozglue.dll. See bug 687139 and
 # bug 725876
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
-ifeq ($(OS_ARCH),WINNT)
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon-standalone,../../mozapps/update/common-standalone)
-else
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon,../../mozapps/update/common)
-endif
-
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32)
 
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
--- a/toolkit/components/maintenanceservice/moz.build
+++ b/toolkit/components/maintenanceservice/moz.build
@@ -10,16 +10,25 @@ SOURCES += [
     'certificatecheck.cpp',
     'maintenanceservice.cpp',
     'registrycertificates.cpp',
     'servicebase.cpp',
     'serviceinstall.cpp',
     'workmonitor.cpp',
 ]
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    USE_LIBS += [
+        'updatecommon-standalone',
+    ]
+else:
+    USE_LIBS += [
+        'updatecommon',
+    ]
+
 # For debugging purposes only
 #DEFINES['DISABLE_UPDATER_AUTHENTICODE_CHECK'] = True
 
 DEFINES['UNICODE'] = True
 DEFINES['_UNICODE'] = True
 DEFINES['NS_NO_XPCOM'] = True
 
 # Pick up nsWindowsRestart.cpp
deleted file mode 100644
--- a/toolkit/components/places/tests/cpp/Makefile.in
+++ /dev/null
@@ -1,7 +0,0 @@
-# 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/. */
-
-ifdef JS_SHARED_LIBRARY
-LIBS += $(MOZ_JS_LIBS)
-endif
--- a/toolkit/components/places/tests/cpp/moz.build
+++ b/toolkit/components/places/tests/cpp/moz.build
@@ -7,8 +7,18 @@
 CPP_UNIT_TESTS += [
     'test_IHistory',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
+
+if CONFIG['JS_SHARED_LIBRARY']:
+    USE_LIBS += [
+        'js',
+    ]
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -7,43 +7,26 @@ ifneq ($(OS_TARGET),Android)
 DIST_PROGRAM = crashreporter$(BIN_SUFFIX)
 
 # Don't link the updater against libmozglue.
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 endif
 
 ifeq ($(OS_ARCH),WINNT)
-LIBS += \
-  $(DEPTH)/toolkit/crashreporter/breakpad-windows-libxul/$(LIB_PREFIX)google_breakpad_libxul_s.$(LIB_SUFFIX)
-  $(NULL)
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 shell32 wininet shlwapi)
 MOZ_WINCONSOLE = 0
 endif
 
-ifeq ($(OS_ARCH),Darwin)
-LIBS += \
-  $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/$(LIB_PREFIX)breakpad_common_s.$(LIB_SUFFIX) \
-  $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/mac/$(LIB_PREFIX)breakpad_mac_common_s.$(LIB_SUFFIX) \
-  $(NULL)
-endif
-
 ifdef MOZ_WIDGET_GTK
-
-LIBS += \
-  $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/linux/$(LIB_PREFIX)breakpad_linux_common_s.$(LIB_SUFFIX) \
-  $(NULL)
 OS_CXXFLAGS += $(TK_CFLAGS) $(MOZ_GTHREAD_CFLAGS)
 OS_LIBS += $(TK_LIBS) $(MOZ_GTHREAD_LIBS)
 endif
 
 ifeq ($(OS_ARCH),SunOS)
-LIBS += \
-  $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/solaris/$(LIB_PREFIX)breakpad_solaris_common_s.$(LIB_SUFFIX) \
-  $(NULL)
 OS_CXXFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_GTHREAD_CFLAGS)
 OS_LIBS += $(MOZ_GTK2_LIBS) $(MOZ_GTHREAD_LIBS)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(OS_ARCH),Darwin)
 libs::
--- a/toolkit/crashreporter/client/moz.build
+++ b/toolkit/crashreporter/client/moz.build
@@ -17,37 +17,50 @@ LOCAL_INCLUDES += [
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     UNIFIED_SOURCES += [
         'crashreporter_win.cpp',
     ]
     DEFINES['UNICODE'] = True
     DEFINES['_UNICODE'] = True
+    USE_LIBS += [
+        'google_breakpad_libxul_s',
+    ]
 elif CONFIG['OS_ARCH'] == 'Darwin':
     UNIFIED_SOURCES += [
         'crashreporter_osx.mm',
         'crashreporter_unix_common.cpp',
     ]
     LOCAL_INCLUDES += [
         '../google-breakpad/src/common/mac',
     ]
     LDFLAGS += ['-framework Cocoa']
+    USE_LIBS += [
+        'breakpad_common_s',
+        'breakpad_mac_common_s',
+    ]
 elif CONFIG['OS_ARCH'] == 'SunOS':
     SOURCES += [
         'crashreporter_linux.cpp',
         'crashreporter_unix.cpp',
     ]
+    USE_LIBS += [
+        'breakpad_solaris_common_s',
+    ]
 
 if CONFIG['MOZ_ENABLE_GTK']:
     UNIFIED_SOURCES += [
         'crashreporter_gtk_common.cpp',
         'crashreporter_linux.cpp',
         'crashreporter_unix_common.cpp'
     ]
+    USE_LIBS += [
+        'breakpad_linux_common_s',
+    ]
 
 RCINCLUDE = 'crashreporter.rc'
 
 # Don't use the STL wrappers in the crashreporter clients; they don't
 # link with -lmozalloc, and it really doesn't matter here anyway.
 DISABLE_STL_WRAPPING = True
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
--- a/toolkit/crashreporter/test/Makefile.in
+++ b/toolkit/crashreporter/test/Makefile.in
@@ -1,14 +1,14 @@
 #
 # 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/.
 
-EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) $(XPCOM_GLUE_LDOPTS)
+EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
 
 UNIT_FILES = $(SHARED_LIBRARY) $(EXTRA_JS_MODULES)
 UNIT_DEST = $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/
 INSTALL_TARGETS += UNIT
 
 UNIT_IPC_FILES = $(UNIT_FILES)
 UNIT_IPC_DEST = $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit_ipc/
 INSTALL_TARGETS += UNIT_IPC
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -33,8 +33,14 @@ DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
 
 DEFINES['NOMINMAX'] = True
 
 LOCAL_INCLUDES += [
     '../google-breakpad/src/',
 ]
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -1,16 +1,12 @@
 # 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/.
 
-ifeq ($(OS_ARCH),WINNT)
-  SHARED_LIBRARY_LIBS += ../../security/sandbox/win/src/sandboxbroker/$(LIB_PREFIX)sandboxbroker.$(LIB_SUFFIX)
-endif
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 CXXFLAGS += $(TK_CFLAGS)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 .PHONY: gtestxul
 gtestxul:
--- a/toolkit/library/libxul.mk
+++ b/toolkit/library/libxul.mk
@@ -1,14 +1,12 @@
 # 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/.
 
-SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,xul,$(DEPTH)/toolkit/library)
-
 EXTRA_DEPS += $(topsrcdir)/toolkit/library/libxul.mk
 
 # dependent libraries
 ifdef MOZ_B2G_BT_BLUEZ #{
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 OS_LIBS += -ldbus
 endif
 endif #}
@@ -30,39 +28,42 @@ EXTRA_DEPS += symverscript
 endif
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 OS_LIBS += -lcups
 endif
 
 EXTRA_DSO_LDOPTS += \
-  $(MOZ_JS_LIBS) \
   $(NSS_LIBS) \
   $(MOZ_CAIRO_OSLIBS) \
   $(MOZ_WEBRTC_X11_LIBS) \
   $(MOZ_APP_EXTRA_LIBS) \
   $(SQLITE_LIBS) \
   $(NULL)
 
 ifdef ENABLE_INTL_API
-ifdef JS_SHARED_LIBRARY
+ifneq (,$(JS_SHARED_LIBRARY)$(MOZ_NATIVE_ICU))
 EXTRA_DSO_LDOPTS += $(MOZ_ICU_LIBS)
 endif
 endif
 
+ifdef MOZ_NATIVE_FFI
+EXTRA_DSO_LDOPTS += $(MOZ_FFI_LIBS)
+endif
+
 ifdef MOZ_NATIVE_JPEG
 EXTRA_DSO_LDOPTS += $(MOZ_JPEG_LIBS)
 endif
 
 ifdef MOZ_NATIVE_PNG
 EXTRA_DSO_LDOPTS += $(MOZ_PNG_LIBS)
 endif
 
-ifndef ZLIB_IN_MOZGLUE
+ifdef MOZ_NATIVE_ZLIB
 EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
 endif
 
 ifdef MOZ_NATIVE_HUNSPELL
 EXTRA_DSO_LDOPTS += $(MOZ_HUNSPELL_LIBS)
 endif
 
 ifdef MOZ_NATIVE_LIBEVENT
@@ -72,22 +73,16 @@ endif
 ifdef MOZ_NATIVE_LIBVPX
 EXTRA_DSO_LDOPTS += $(MOZ_LIBVPX_LIBS)
 endif
 
 ifndef MOZ_TREE_PIXMAN
 EXTRA_DSO_LDOPTS += $(MOZ_PIXMAN_LIBS)
 endif
 
-ifdef MOZ_DMD
-EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME_PATH,dmd,$(DIST)/lib)
-endif
-
-EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME_PATH,gkmedias,$(DEPTH)/layout/media)
-
 ifdef MOZ_WEBRTC
 ifeq (WINNT,$(OS_TARGET))
 ifndef MOZ_HAS_WINSDK_WITH_D3D
 EXTRA_DSO_LDOPTS += \
   -LIBPATH:'$(MOZ_DIRECTX_SDK_PATH)/lib/$(MOZ_D3D_CPU_SUFFIX)' \
   $(NULL)
 endif
 OS_LIBS += $(call EXPAND_LIBNAME,secur32 crypt32 iphlpapi strmiids dmoguids wmcodecdspuuid amstrmid msdmo wininet)
@@ -133,17 +128,19 @@ endif
 ifdef MOZ_WMF
 OS_LIBS += $(call EXPAND_LIBNAME,mfuuid wmcodecdspuuid strmiids)
 endif
 
 ifdef MOZ_DIRECTSHOW
 OS_LIBS += $(call EXPAND_LIBNAME,dmoguids wmcodecdspuuid strmiids msdmo)
 endif
 
-EXTRA_DSO_LDOPTS += $(NSPR_LIBS) $(MOZALLOC_LIB)
+EXTRA_DSO_LDOPTS += $(ICONV_LIBS)
+
+EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 OS_LIBS += \
   $(TK_LIBS) \
   $(NULL)
 endif
 
 ifeq (OpenBSD,$(OS_ARCH))
@@ -151,17 +148,17 @@ EXTRA_DSO_LDOPTS += -lsndio
 endif
 
 ifdef MOZ_ENABLE_DBUS
 EXTRA_DSO_LDOPTS += $(MOZ_DBUS_GLIB_LIBS)
 endif
 
 ifdef MOZ_WIDGET_GTK
 ifdef MOZ_ENABLE_GTK3
-EXTRA_DSO_LDOPTS += $(filter-out -lgtk-3 -lgdk-3,$(TK_LIBS)) -lmozgtk_stub
+EXTRA_DSO_LDOPTS += $(filter-out -lgtk-3 -lgdk-3,$(TK_LIBS))
 else
 EXTRA_DSO_LDOPTS += $(TK_LIBS)
 endif
 EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS) $(XCOMPOSITE_LIBS) $(MOZ_PANGO_LIBS) $(XT_LIBS) -lgthread-2.0
 EXTRA_DSO_LDOPTS += $(FT2_LIBS)
 endif
 
 ifeq (qt,$(MOZ_WIDGET_TOOLKIT))
@@ -198,20 +195,16 @@ OS_LIBS += $(call EXPAND_LIBNAME,shell32
 ifdef ACCESSIBILITY
 OS_LIBS += $(call EXPAND_LIBNAME,oleacc)
 endif
 ifdef MOZ_METRO
 OS_LIBS += $(call EXPAND_LIBNAME,uiautomationcore runtimeobject)
 endif
 endif # WINNT
 
-ifdef MOZ_JPROF
-EXTRA_DSO_LDOPTS += -ljprof
-endif
-
 ifdef MOZ_ENABLE_QT
 EXTRA_DSO_LDOPTS += $(MOZ_QT_LDFLAGS) $(XEXT_LIBS)
 endif
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 ifdef MOZ_GSTREAMER
 EXTRA_DSO_LDOPTS += $(GSTREAMER_LIBS)
 endif
@@ -229,18 +222,16 @@ LIBXUL_AUTOLOAD_FLAGS := -Dtopsrcdir=$(a
 endif
 
 OS_LIBS += $(LIBICONV)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 OS_LIBS += $(call EXPAND_LIBNAME,usp10 oleaut32)
 endif
 
-EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME_PATH,StaticXULComponentsEnd,$(DEPTH)/toolkit/library/StaticXULComponentsEnd)
-
 # BFD ld doesn't create multiple PT_LOADs as usual when an unknown section
 # exists. Using an implicit linker script to make it fold that section in
 # .data.rel.ro makes it create multiple PT_LOADs. That implicit linker
 # script however makes gold misbehave, first because it doesn't like that
 # the linker script is given after crtbegin.o, and even past that, replaces
 # the default section rules with those from the script instead of
 # supplementing them. Which leads to a lib with a huge load of sections.
 ifdef LD_IS_BFD
--- a/toolkit/library/libxul.mozbuild
+++ b/toolkit/library/libxul.mozbuild
@@ -52,8 +52,56 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
 
 if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
     LOCAL_INCLUDES += [
         '/widget/windows',
         '/xpcom/base',
     ]
     # This file is (only) included from subdirectories, and the file is here.
     RCINCLUDE = '../xulrunner.rc'
+
+USE_LIBS += [
+    'xul',
+]
+
+# js needs to come after xul for now, because it is an archive and its content
+# is discarded when it comes first.
+USE_LIBS += [
+    'js',
+]
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    USE_LIBS += [
+        'sandboxbroker',
+    ]
+
+if CONFIG['MOZ_DMD']:
+    USE_LIBS += [
+        'dmd',
+    ]
+
+if not CONFIG['MOZ_NATIVE_ZLIB'] and not CONFIG['ZLIB_IN_MOZGLUE']:
+    USE_LIBS += [
+        'mozz',
+    ]
+
+if not CONFIG['MOZ_NATIVE_SQLITE'] and not CONFIG['MOZ_FOLD_LIBS']:
+    USE_LIBS += [
+        'mozsqlite3',
+    ]
+
+USE_LIBS += [
+    'gkmedias',
+    'mozalloc',
+]
+
+if CONFIG['MOZ_WIDGET_GTK'] and CONFIG['MOZ_ENABLE_GTK3']:
+    USE_LIBS += [
+        'mozgtk_stub',
+    ]
+
+if CONFIG['MOZ_JPROF']:
+    USE_LIBS += [
+        'jprof',
+    ]
+
+# This needs to be last
+USE_LIBS += ['StaticXULComponentsEnd']
--- a/toolkit/mozapps/update/tests/Makefile.in
+++ b/toolkit/mozapps/update/tests/Makefile.in
@@ -65,20 +65,17 @@ INI_TEST_FILES = \
   TestAUSReadStrings2.ini \
   TestAUSReadStrings3.ini \
   $(NULL)
 
 MOZ_GLUE_LDFLAGS =
 MOZ_WINCONSOLE = 1
 
 ifeq ($(OS_ARCH),WINNT)
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon-standalone,../common-standalone)
 OS_LIBS += $(call EXPAND_LIBNAME,wintrust shlwapi)
-else
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon,../common)
 endif
 
 endif # Not Android
 
 include $(topsrcdir)/config/rules.mk
 
 ifneq (android,$(MOZ_WIDGET_TOOLKIT))
 # TestAUSReadStrings runs during check in the following directory with a Unicode
--- a/toolkit/mozapps/update/tests/moz.build
+++ b/toolkit/mozapps/update/tests/moz.build
@@ -22,16 +22,25 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'andr
         '%s.cpp' % s for s in SIMPLE_PROGRAMS
     ]
 
     LOCAL_INCLUDES += [
         '/toolkit/mozapps/update',
         '/toolkit/mozapps/update/common',
     ]
 
+    if CONFIG['OS_ARCH'] == 'WINNT':
+        USE_LIBS += [
+            'updatecommon-standalone',
+        ]
+    else:
+        USE_LIBS += [
+            'updatecommon',
+        ]
+
 for var in ('MOZ_APP_NAME', 'MOZ_APP_BASENAME', 'MOZ_APP_DISPLAYNAME',
             'MOZ_APP_VENDOR', 'BIN_SUFFIX', 'MOZ_DEBUG'):
     DEFINES[var] = CONFIG[var]
 
 DEFINES['NS_NO_XPCOM'] = True
 
 if CONFIG['MOZ_MAINTENANCE_SERVICE'] and not CONFIG['HAVE_64BIT_BUILD']:
     DEFINES['MOZ_MAINTENANCE_SERVICE'] = CONFIG['MOZ_MAINTENANCE_SERVICE']
--- a/toolkit/mozapps/update/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -2,29 +2,23 @@
 # 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/.
 
 # Don't link the updater against libmozglue. See bug 687139
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
-ifeq ($(OS_ARCH),WINNT)
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon-standalone,../common-standalone)
-else
-LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon,../common)
+ifdef MOZ_NATIVE_BZ2
+LIBS += \
+  $(MOZ_BZ2_LIBS) \
+  $(NULL)
 endif
 
-LIBS += \
-  $(call EXPAND_LIBNAME_PATH,mar,$(DEPTH)/modules/libmar/src) \
-  $(MOZ_BZ2_LIBS) \
-  $(NULL)
-
 ifeq ($(OS_ARCH),WINNT)
-LIBS += $(call EXPAND_LIBNAME_PATH,verifymar,$(DEPTH)/modules/libmar/verify)
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32 shlwapi)
 endif
 
 ifdef MOZ_WIDGET_GTK
 OS_CXXFLAGS += $(TK_CFLAGS)
 OS_LIBS += $(TK_LIBS)
 endif
 
--- a/toolkit/mozapps/update/updater/moz.build
+++ b/toolkit/mozapps/update/updater/moz.build
@@ -25,16 +25,33 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['_UNICODE'] = True
     DEFINES['NOMINMAX'] = True
     USE_STATIC_LIBS = True
 
     # Pick up nsWindowsRestart.cpp
     LOCAL_INCLUDES += [
         '/toolkit/xre',
     ]
+    USE_LIBS += [
+        'updatecommon-standalone',
+        'verifymar',
+    ]
+else:
+    USE_LIBS += [
+        'updatecommon',
+    ]
+
+USE_LIBS += [
+    'mar',
+]
+
+if not CONFIG['MOZ_NATIVE_BZ2']:
+    USE_LIBS += [
+        'bz2',
+    ]
 
 if CONFIG['MOZ_ENABLE_GTK']:
     have_progressui = 1
     SOURCES += [
         'progressui_gtk.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
--- a/toolkit/system/dbus/Makefile.in
+++ b/toolkit/system/dbus/Makefile.in
@@ -1,13 +1,12 @@
 # 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/.
 
-EXTRA_DSO_LDOPTS = \
-	$(XPCOM_GLUE_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
 	$(NSPR_LIBS) \
 	$(MOZ_DBUS_GLIB_LIBS) \
 	$(NULL)
                 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS)
--- a/toolkit/system/dbus/moz.build
+++ b/toolkit/system/dbus/moz.build
@@ -8,8 +8,14 @@ SOURCES += [
     'nsDBusModule.cpp',
     'nsDBusService.cpp',
     'nsNetworkManagerListener.cpp',
 ]
 
 LIBRARY_NAME = 'dbusservice'
 
 IS_COMPONENT = True
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/toolkit/system/gnome/Makefile.in
+++ b/toolkit/system/gnome/Makefile.in
@@ -1,15 +1,13 @@
 # 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/.
 
 EXTRA_DSO_LDOPTS += \
-		$(XPCOM_GLUE_LDOPTS) \
-		$(XPCOM_FROZEN_LDOPTS) \
 		$(NSPR_LIBS) \
 		$(MOZ_GCONF_LIBS) \
 		$(MOZ_GNOMEVFS_LIBS) \
 		$(GLIB_LIBS) \
 		$(MOZ_GIO_LIBS) \
 		$(MOZ_DBUS_GLIB_LIBS) \
 		$(NULL)
 
--- a/toolkit/system/gnome/moz.build
+++ b/toolkit/system/gnome/moz.build
@@ -28,8 +28,13 @@ LIBRARY_NAME = 'mozgnome'
 
 FAIL_ON_WARNINGS = True
 IS_COMPONENT = True
 
 LOCAL_INCLUDES += [
     '/toolkit/components/build/',
 ]
 
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/tools/trace-malloc/Makefile.in
+++ b/tools/trace-malloc/Makefile.in
@@ -19,24 +19,19 @@ endif
 
 CPPSRCS += $(EXTRACPPSRCS)
 
 include $(topsrcdir)/config/config.mk
 
 LIBS		+= \
 		tmreader.$(OBJ_SUFFIX) \
 		adreader.$(OBJ_SUFFIX) \
-		$(XPCOM_GLUE_LDOPTS) \
 		$(NSPR_LIBS) \
 		$(NULL)
 
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-LIBS += $(DIST)/bin/XUL
-endif
-
 ifdef HAVE_BOUTELL_GD
 ifeq ($(OS_ARCH),WINNT)
 LOCAL_INCLUDES	+= \
 		-I'$(HAVE_BOUTELL_GD)' \
 		$(NULL)
 LIBS		+= \
 		-lmozz_s \
 		'$(HAVE_BOUTELL_GD)/gd.lib' \
--- a/tools/trace-malloc/moz.build
+++ b/tools/trace-malloc/moz.build
@@ -38,8 +38,14 @@ SOURCES += [
     '%s.cpp' % s for s in simple_cpp_sources
 ]
 
 SIMPLE_PROGRAMS += simple_cpp_sources
 
 RESOURCE_FILES += [
     'spacetrace.css'
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/webapprt/gtk/Makefile.in
+++ b/webapprt/gtk/Makefile.in
@@ -1,14 +1,13 @@
 # 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 = \
-  $(XPCOM_STANDALONE_GLUE_LDOPTS) \
+LIBS += \
   $(TK_LIBS) \
   $(NULL)
 
 NSDISTMODE = copy
 
 PROGRAMS_DEST = $(DIST)/bin
 
 include $(topsrcdir)/config/rules.mk
--- a/webapprt/gtk/moz.build
+++ b/webapprt/gtk/moz.build
@@ -16,9 +16,13 @@ DEFINES['XPCOM_GLUE'] = True
 
 GENERATED_INCLUDES += ['/build']
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
 ]
 
+USE_LIBS += [
+    'xpcomglue',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/webapprt/mac/Makefile.in
+++ b/webapprt/mac/Makefile.in
@@ -6,20 +6,16 @@
 # shouldn't get 755 perms need $(IFLAGS1) for either way of calling nsinstall.
 NSDISTMODE = copy
 
 # Don't create a dependency on mozglue, which is impossible (difficult?)
 # to dynamically link into our executable, as we copy it to arbitrary locations.
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
-LIBS = \
-  $(XPCOM_STANDALONE_GLUE_LDOPTS) \
-  $(NULL)
-
 PROGRAMS_DEST = $(DIST)/bin
 
 include $(topsrcdir)/config/rules.mk
 
 GRE_BUILDID := $(shell cat $(DEPTH)/config/buildid)
 DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 webapprt.$(OBJ_SUFFIX): $(DEPTH)/config/buildid
--- a/webapprt/mac/moz.build
+++ b/webapprt/mac/moz.build
@@ -14,9 +14,13 @@ DEFINES['XPCOM_GLUE'] = True
 
 GENERATED_INCLUDES += ['/build']
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
 ]
 
+USE_LIBS += [
+    'xpcomglue',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/Makefile.in
@@ -1,20 +1,16 @@
 # 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/.
 
 # Don't create a dependency on mozglue, which is impossible (difficult?)
 # to dynamically link into our executable, as we copy it to arbitrary locations.
 MOZ_GLUE_LDFLAGS =
 
-LIBS = \
-  $(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS) \
-  $(NULL)
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/webapprt/win/moz.build
+++ b/webapprt/win/moz.build
@@ -37,9 +37,13 @@ if CONFIG['_MSC_VER']:
 # The heap will grow if need be.
 #
 # Set it to 256k.  See bug 127069.
 if not CONFIG['GNU_CC']:
     LDFLAGS += ['/HEAP:0x40000']
 
 RCINCLUDE = 'webapprt.rc'
 
+USE_LIBS += [
+    'xpcomglue_staticruntime',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/widget/tests/moz.build
+++ b/widget/tests/moz.build
@@ -20,8 +20,14 @@ FAIL_ON_WARNINGS = True
 #         (see bug 582863)
 #         CPP_UNIT_TESTS += ['TestWinTSF']
 #
 #     Test disabled because it requires the internal API. Re-enabling this test
 #     is bug 652123.
 #     CPP_UNIT_TESTS += ['TestChromeMargin']
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/widget/xremoteclient/Makefile.in
+++ b/widget/xremoteclient/Makefile.in
@@ -6,21 +6,16 @@
 # NOTE: This directory is part of tier 50, and is linked directly into
 # the application binaries. The fact that it's under mozilla/widget is a fluke
 # of tree history.
 
 LIBCPPSRCS = XRemoteClient.cpp
 
 OBJS = $(LIBCPPSRCS:.cpp=.$(OBJ_SUFFIX))
 
-EXTRA_DSO_LDOPTS = \
-		$(XLIBS) $(XLDFLAGS)  \
-		$(MOZ_COMPONENT_LIBS) \
-		$(NULL)
-
 PROGCPPSRCS = \
   mozilla-xremote-client.cpp \
   XRemoteClient.cpp \
   $(NULL)
 
 PROGOBJS = $(PROGCPPSRCS:.cpp=.$(OBJ_SUFFIX))
 
 CPPSRCS += \
--- a/xpcom/reflect/xptcall/tests/Makefile.in
+++ b/xpcom/reflect/xptcall/tests/Makefile.in
@@ -1,9 +1,8 @@
 #
 # 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		= \
-		$(XPCOM_GLUE_LDOPTS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
--- a/xpcom/reflect/xptcall/tests/moz.build
+++ b/xpcom/reflect/xptcall/tests/moz.build
@@ -6,8 +6,14 @@
 
 SIMPLE_PROGRAMS = [
     'TestXPTCInvoke',
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/reflect/xptinfo/tests/Makefile.in
+++ b/xpcom/reflect/xptinfo/tests/Makefile.in
@@ -1,9 +1,8 @@
 #
 # 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		= \
-		$(XPCOM_GLUE_LDOPTS) \
+LIBS		+= \
 		$(NSPR_LIBS) \
 		$(NULL)
--- a/xpcom/reflect/xptinfo/tests/moz.build
+++ b/xpcom/reflect/xptinfo/tests/moz.build
@@ -6,8 +6,14 @@
 
 SOURCES += [
     'TestInterfaceInfo.cpp',
 ]
 
 SIMPLE_PROGRAMS += [
     'TestInterfaceInfo'
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/sample/Makefile.in
+++ b/xpcom/sample/Makefile.in
@@ -1,19 +1,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/.
 
 # EXTRA_DSO_LDOPTS specifies linker flags when building a shared library
 # from this Makefile. We link against the "dependent glue" and against the
 # frozen XPCOM shared library.
-EXTRA_DSO_LDOPTS = \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_FROZEN_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
 		$(TK_LIBS) \
 		$(NULL)
--- a/xpcom/sample/moz.build
+++ b/xpcom/sample/moz.build
@@ -34,8 +34,14 @@ EXTRA_COMPONENTS += [
 LIBRARY_NAME = 'xpcomsample'
 
 # IS_COMPONENT indicates that this makefile builds a component shared library.
 IS_COMPONENT = True
 
 RESOURCE_FILES.samples += [
     'xpconnect-sample.html',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/sample/program/Makefile.in
+++ b/xpcom/sample/program/Makefile.in
@@ -1,19 +1,11 @@
 #
 # 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 specifies linker flags when building an executable program from
-# this Makefile. We link against the "standalone glue" which does not require
-# that the application be linked against the XPCOM dynamic library or the NSPR
-# dynamic libraries.
-LIBS            = \
-		$(XPCOM_STANDALONE_GLUE_LDOPTS) \
-		$(NULL)
-
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 LIBS            += \
 		$(TK_LIBS) \
 		$(NULL)
 endif
--- a/xpcom/sample/program/moz.build
+++ b/xpcom/sample/program/moz.build
@@ -13,8 +13,16 @@ SOURCES += [
 # SIMPLE_PROGRAMS compiles a single .cpp file into an executable
 SIMPLE_PROGRAMS += [
     'nsTestSample'
 ]
 
 # Whatever code is going to be linked with the *standalone* glue must be
 # built with the XPCOM_GLUE define set.
 DEFINES['XPCOM_GLUE'] = True
+
+# USE_LIBS specifies the in-tree  libraries to link when building an executable
+# program from this directory. We link against the "standalone glue" which does
+# not require# that the application be linked against the XPCOM dynamic library
+# or the NSPR dynamic libraries.
+USE_LIBS += [
+    'xpcomglue',
+]
--- a/xpcom/tests/Makefile.in
+++ b/xpcom/tests/Makefile.in
@@ -1,14 +1,12 @@
 # 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 += $(XPCOM_LIBS)
-
 # Make sure we have symbols in case we need to debug these.
 MOZ_DEBUG_SYMBOLS = 1
 
 include $(topsrcdir)/config/rules.mk
 
 ifneq (,$(SIMPLE_PROGRAMS))
 libs::
 	$(INSTALL) $(SIMPLE_PROGRAMS) $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit
--- a/xpcom/tests/bug656331_component/Makefile.in
+++ b/xpcom/tests/bug656331_component/Makefile.in
@@ -6,19 +6,17 @@
 # Blatantly copied from xpcom/tests/component.
 
 unittestlocation = xpcom/tests/unit
 
 MANIFEST = bug656331.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
-EXTRA_DSO_LDOPTS = \
-  $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-  $(XPCOM_FROZEN_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
   $(NSPR_LIBS) \
   $(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
   $(TK_LIBS) \
   $(NULL)
--- a/xpcom/tests/bug656331_component/moz.build
+++ b/xpcom/tests/bug656331_component/moz.build
@@ -14,8 +14,14 @@ LIBRARY_NAME = 'test656331'
 
 IS_COMPONENT = True
 
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/tests/component/Makefile.in
+++ b/xpcom/tests/component/Makefile.in
@@ -4,19 +4,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 unittestlocation = xpcom/tests/unit
 
 MANIFEST = testcomponent.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
-EXTRA_DSO_LDOPTS = \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_FROZEN_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
 		$(TK_LIBS) \
 		$(NULL)
--- a/xpcom/tests/component/moz.build
+++ b/xpcom/tests/component/moz.build
@@ -14,8 +14,14 @@ LIBRARY_NAME = 'testcomponent'
 
 IS_COMPONENT = True
 
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/tests/component_no_aslr/Makefile.in
+++ b/xpcom/tests/component_no_aslr/Makefile.in
@@ -5,18 +5,16 @@
 
 unittestlocation = xpcom/tests/unit
 
 MANIFEST = testcompnoaslr.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
 EXTRA_DSO_LDOPTS = \
-		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-		$(XPCOM_FROZEN_LDOPTS) \
 		$(NSPR_LIBS) \
 		$(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
 		$(TK_LIBS) \
 		$(NULL)
--- a/xpcom/tests/component_no_aslr/moz.build
+++ b/xpcom/tests/component_no_aslr/moz.build
@@ -14,8 +14,14 @@ LIBRARY_NAME = 'testcompnoaslr'
 
 IS_COMPONENT = True
 
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/tests/external/Makefile.in
+++ b/xpcom/tests/external/Makefile.in
@@ -1,10 +1,9 @@
 # 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/.
 
 include $(topsrcdir)/config/rules.mk
 
 LIBS += \
-	$(XPCOM_GLUE_LDOPTS) \
 	$(NSPR_LIBS) \
 	$(NULL)
--- a/xpcom/tests/external/moz.build
+++ b/xpcom/tests/external/moz.build
@@ -6,8 +6,14 @@
 
 SIMPLE_PROGRAMS = [
     'TestMinStringAPI',
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -118,8 +118,14 @@ SOURCES += sorted('%s.cpp' % t for t in 
 
 LOCAL_INCLUDES += [
     '../ds',
 ]
 
 RESOURCE_FILES += [
     'test.properties',
 ]
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/tests/windows/moz.build
+++ b/xpcom/tests/windows/moz.build
@@ -5,8 +5,14 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 CPP_UNIT_TESTS += [
     'TestCOM',
     'TestNtPathToDosPath',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xpcom/typelib/xpt/tests/Makefile.in
+++ b/xpcom/typelib/xpt/tests/Makefile.in
@@ -1,13 +1,8 @@
 #
 # 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		= \
-		$(DIST)/lib/$(LIB_PREFIX)xpt.$(LIB_SUFFIX) \
-		$(XPCOM_LIBS) \
-		$(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 DEFINES += -DIMPL_LIBXUL
--- a/xpcom/typelib/xpt/tests/moz.build
+++ b/xpcom/typelib/xpt/tests/moz.build
@@ -9,8 +9,14 @@ SIMPLE_PROGRAMS = [
     'SimpleTypeLib',
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
 
 FAIL_ON_WARNINGS = True
+
+USE_LIBS += [
+    'mozalloc',
+    'xpt',
+    'xul-shared',
+]
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -7,20 +7,16 @@ PREF_JS_EXPORTS = $(srcdir)/xulrunner.js
 GARBAGE += $(addprefix $(DIST)/bin/defaults/pref/,xulrunner.js)
 
 DEFINES += -DAB_CD=$(AB_CD)
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 TK_LIBS := -framework Cocoa $(TK_LIBS)
 endif
 
-LIBS += \
-  $(XPCOM_STANDALONE_GLUE_LDOPTS) \
-  $(NULL)
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/xulrunner/app/moz.build
+++ b/xulrunner/app/moz.build
@@ -38,9 +38,13 @@ if CONFIG['_MSC_VER']:
 #
 # Set it to 256k.  See bug 127069.
 if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
     LDFLAGS += ['/HEAP:0x40000']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     RCINCLUDE = 'splash.rc'
 
+USE_LIBS += [
+    'xpcomglue',
+]
+
 DISABLE_STL_WRAPPING = True
--- a/xulrunner/examples/simple/components/src/Makefile.in
+++ b/xulrunner/examples/simple/components/src/Makefile.in
@@ -1,9 +1,8 @@
 # vim:set ts=8 sw=8 sts=8 noet:
 # 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/.
 
-EXTRA_DSO_LDOPTS = \
-	$(XPCOM_GLUE_LDOPTS) \
+EXTRA_DSO_LDOPTS += \
 	$(NSPR_LIBS) \
 	$(NULL)
--- a/xulrunner/examples/simple/components/src/moz.build
+++ b/xulrunner/examples/simple/components/src/moz.build
@@ -13,8 +13,14 @@ LIBRARY_NAME = 'simpletest'
 EXTRA_COMPONENTS += [
     'SimpleTest.js',
     'SimpleTest.manifest',
 ]
 
 IS_COMPONENT = True
 
 XPI_NAME = 'simple'
+
+USE_LIBS += [
+    'mozalloc',
+    'xpcomglue_s',
+    'xul-shared',
+]
--- a/xulrunner/stub/Makefile.in
+++ b/xulrunner/stub/Makefile.in
@@ -1,19 +1,15 @@
 # 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/.
 
 # Don't create a dependency on mozglue
 MOZ_GLUE_LDFLAGS =
 
-LIBS = \
-  $(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS) \
-  $(NULL)
-
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 LIBS            += \
 		$(TK_LIBS) \
 		$(NULL)
 endif
 
 ifndef MOZ_WINCONSOLE
--- a/xulrunner/stub/moz.build
+++ b/xulrunner/stub/moz.build
@@ -33,9 +33,18 @@ if CONFIG['OS_ARCH'] == 'WINNT':
 
 if CONFIG['_MSC_VER']:
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['MOZ_XULRUNNER'] = True
     RCINCLUDE = 'xulrunner-stub.rc'
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    USE_LIBS += [
+        'xpcomglue_staticruntime',
+    ]
+else:
+    USE_LIBS += [
+        'xpcomglue',
+    ]
+
 DISABLE_STL_WRAPPING = True
--- a/xulrunner/tools/redit/Makefile.in
+++ b/xulrunner/tools/redit/Makefile.in
@@ -3,13 +3,9 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ifeq ($(OS_ARCH),WINNT)
 
 SDK_BINARY =  \
 	$(PROGRAM) \
 	$(NULL)
 
-LIBS = \
-  $(XPCOM_STANDALONE_GLUE_LDOPTS) \
-  $(NULL)
-
 endif
--- a/xulrunner/tools/redit/moz.build
+++ b/xulrunner/tools/redit/moz.build
@@ -8,8 +8,12 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     PROGRAM  = 'redit'
     SOURCES += [
         'redit.cpp',
     ]
     for var in ('WIN32_LEAN_AND_MEAN', 'UNICODE', '_UNICODE', 'XPCOM_GLUE'):
         DEFINES[var] = True
     if CONFIG['GNU_CC']:
         WIN32_EXE_LDFLAGS += ['-municode']
+
+    USE_LIBS += [
+        'xpcomglue',
+    ]