Bug 1047267 - Move remaining OS_LIBS and EXTRA_LIBS to moz.build. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 07 Aug 2014 14:21:03 +0900
changeset 212598 6b285759568cb0b743cb9497e021f6552cc7e349
parent 212597 698ae2f2c8bf4d4205cb8d8683595b30a840db51
child 212599 af7e67f1af51574477b4abc8bc7df2b7e35a3059
push id6741
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:57:58 +0000
treeherdermozilla-aurora@aed50d3edf33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1047267
milestone34.0a1
Bug 1047267 - Move remaining OS_LIBS and EXTRA_LIBS to moz.build. r=gps * * * Bug 1047267 - To fold with "Move remaining OS_LIBS and EXTRA_LIBS to moz.build"
b2g/app/moz.build
browser/components/build/Makefile.in
browser/components/build/moz.build
build/autoconf/icu.m4
config/baseconfig.mk
config/external/ffi/Makefile.in
config/external/ffi/moz.build
config/external/freetype2/Makefile.in
config/external/freetype2/moz.build
config/external/icu/Makefile.in
config/external/icu/moz.build
config/external/moz.build
config/external/nspr/Makefile.in
config/external/nspr/moz.build
config/external/nss/Makefile.in
config/external/nss/crmf/moz.build
config/external/nss/moz.build
config/external/nss/nss.def
config/external/sqlite/Makefile.in
config/external/sqlite/moz.build
config/external/zlib/moz.build
config/rules.mk
configure.in
content/base/test/moz.build
content/media/compiledtest/moz.build
content/media/webaudio/compiledtest/moz.build
db/sqlite3/src/Makefile.in
db/sqlite3/src/moz.build
dom/audiochannel/tests/moz.build
dom/canvas/compiledtest/moz.build
editor/txmgr/tests/moz.build
extensions/gnomevfs/Makefile.in
extensions/gnomevfs/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/gdb/Makefile.in
js/src/jsapi-tests/Makefile.in
js/src/moz.build
js/src/shell/Makefile.in
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/moz.build
media/mtransport/test/Makefile.in
media/mtransport/test/moz.build
media/webrtc/signaling/test/Makefile.in
media/webrtc/signaling/test/moz.build
memory/mozalloc/tests/moz.build
mfbt/tests/Makefile.in
modules/libmar/tool/Makefile.in
modules/libmar/tool/moz.build
modules/zlib/src/moz.build
moz.build
mozglue/build/Makefile.in
mozglue/build/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/manager/ssl/src/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/places/tests/cpp/moz.build
toolkit/crashreporter/test/Makefile.in
toolkit/crashreporter/test/moz.build
toolkit/library/Makefile.in
toolkit/library/libxul.mk
toolkit/library/moz.build
toolkit/system/dbus/Makefile.in
toolkit/system/dbus/moz.build
toolkit/system/gnome/Makefile.in
toolkit/system/gnome/moz.build
toolkit/toolkit.mozbuild
tools/trace-malloc/Makefile.in
tools/trace-malloc/moz.build
uriloader/exthandler/tests/Makefile.in
uriloader/exthandler/tests/moz.build
widget/tests/moz.build
widget/xremoteclient/Makefile.in
widget/xremoteclient/moz.build
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/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
xulrunner/examples/simple/components/src/Makefile.in
xulrunner/examples/simple/components/src/moz.build
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -17,20 +17,19 @@ 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',
-        ]
+    USE_LIBS += [
+        'zlib',
+    ]
 
 DEFINES['XPCOM_GLUE'] = True
 
 for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION', 'MOZ_UPDATER'):
     DEFINES[var] = CONFIG[var]
 
 GENERATED_INCLUDES += [
     '/build',
@@ -48,21 +47,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
     ]
 
     LDFLAGS += ['-Wl,--export-dynamic']
 
     USE_LIBS += [
         'display',
         'mozpng',
     ]
-    if not CONFIG['MOZ_NATIVE_ZLIB']:
-        USE_LIBS += [
-            'mozz',
-        ]
-
     OS_LIBS += [
         'ui',
         'EGL',
         'hardware_legacy',
         'hardware',
         'cutils',
     ]
     OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/browser/components/build/Makefile.in
+++ b/browser/components/build/Makefile.in
@@ -1,12 +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/.
 
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 # Ensure that we don't embed a manifest referencing the CRT.
 EMBED_MANIFEST_AT =
--- a/browser/components/build/moz.build
+++ b/browser/components/build/moz.build
@@ -21,16 +21,17 @@ LOCAL_INCLUDES += [
     '../dirprovider',
     '../feeds',
     '../migration',
     '../shell',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     OS_LIBS += [
         'ole32',
         'shell32',
--- a/build/autoconf/icu.m4
+++ b/build/autoconf/icu.m4
@@ -83,44 +83,29 @@ if test -n "$ENABLE_INTL_API"; then
     if test -z "$MOZ_NATIVE_ICU"; then
         case "$OS_TARGET" in
             WINNT)
                 ICU_LIB_NAMES="icuin icuuc icudt"
                 MOZ_ICU_DBG_SUFFIX=
                 if test -n "$MOZ_DEBUG" -a -z "$MOZ_NO_DEBUG_RTL"; then
                     MOZ_ICU_DBG_SUFFIX=d
                 fi
-                if test -n "$MOZ_SHARED_ICU"; then
-                    MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(LIB_PREFIX)$(lib)$(MOZ_ICU_DBG_SUFFIX).$(LIB_SUFFIX))'
-                fi
                 ;;
-            Darwin)
+            Darwin|Linux|DragonFly|FreeBSD|NetBSD|OpenBSD|GNU/kFreeBSD)
                 ICU_LIB_NAMES="icui18n icuuc icudata"
-                if test -n "$MOZ_SHARED_ICU"; then
-                   MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(DLL_PREFIX)$(lib).$(MOZ_ICU_VERSION)$(DLL_SUFFIX))'
-                fi
-                ;;
-            Linux|DragonFly|FreeBSD|NetBSD|OpenBSD|GNU/kFreeBSD)
-                ICU_LIB_NAMES="icui18n icuuc icudata"
-                if test -n "$MOZ_SHARED_ICU"; then
-                   MOZ_ICU_LIBS='$(foreach lib,$(ICU_LIB_NAMES),$(DEPTH)/intl/icu/target/lib/$(DLL_PREFIX)$(lib)$(DLL_SUFFIX).$(MOZ_ICU_VERSION))'
-                fi
                 ;;
             *)
                 AC_MSG_ERROR([ECMAScript Internationalization API is not yet supported on this platform])
         esac
-        if test -z "$MOZ_SHARED_ICU"; then
-            MOZ_ICU_LIBS='$(call EXPAND_LIBNAME_PATH,$(addsuffix $(MOZ_ICU_DBG_SUFFIX),$(ICU_LIB_NAMES)),$(DEPTH)/intl/icu/target/lib)'
-        fi
     fi
 fi
 
 AC_SUBST(MOZ_ICU_DBG_SUFFIX)
 AC_SUBST(ENABLE_INTL_API)
-AC_SUBST(ICU_LIB_NAMES)
+AC_SUBST_LIST(ICU_LIB_NAMES)
 
 if test -n "$ENABLE_INTL_API" -a -z "$MOZ_NATIVE_ICU"; then
     dnl We build ICU as a static library for non-shared js builds and as a shared library for shared js builds.
     if test -z "$MOZ_SHARED_ICU"; then
         AC_DEFINE(U_STATIC_IMPLEMENTATION)
     fi
     dnl Source files that use ICU should have control over which parts of the ICU
     dnl namespace they want to use.
--- a/config/baseconfig.mk
+++ b/config/baseconfig.mk
@@ -83,16 +83,17 @@ else
   JAVA_JAR_TARGETS \
   LD_VERSION_SCRIPT \
   LIBRARY_NAME \
   LIBS \
   MAKE_FRAMEWORK \
   MODULE \
   MSVC_ENABLE_PGO \
   NO_DIST_INSTALL \
+  OS_LIBS \
   PARALLEL_DIRS \
   PROGRAM \
   PYTHON_UNIT_TESTS \
   RESOURCE_FILES \
   SDK_HEADERS \
   SDK_LIBRARY \
   SHARED_LIBRARY_LIBS \
   SHARED_LIBRARY_NAME \
@@ -104,16 +105,17 @@ else
   TOOL_DIRS \
   XPCSHELL_TESTS \
   XPIDL_MODULE \
   $(NULL)
 
 _DEPRECATED_VARIABLES := \
   ANDROID_RESFILES \
   EXPORT_LIBRARY \
+  EXTRA_LIBS \
   HOST_LIBS \
   LIBXUL_LIBRARY \
   MOCHITEST_A11Y_FILES \
   MOCHITEST_BROWSER_FILES \
   MOCHITEST_BROWSER_FILES_PARTS \
   MOCHITEST_CHROME_FILES \
   MOCHITEST_FILES \
   MOCHITEST_FILES_PARTS \
--- a/config/external/ffi/Makefile.in
+++ b/config/external/ffi/Makefile.in
@@ -1,6 +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/.
 
-target::
+ifndef MOZ_NATIVE_FFI
+
+include $(topsrcdir)/config/config.mk
+
+$(STATIC_LIBS):
 	$(MAKE) -C $(DEPTH)/js/src/ctypes/libffi
+
+endif
--- a/config/external/ffi/moz.build
+++ b/config/external/ffi/moz.build
@@ -1,5 +1,18 @@
 # -*- 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 = 'ffi'
+
+if CONFIG['MOZ_NATIVE_FFI']:
+    OS_LIBS += CONFIG['MOZ_FFI_LIBS']
+else:
+    if CONFIG['OS_ARCH'] == 'WINNT':
+        prefix = 'lib'
+    else:
+        prefix = ''
+    USE_LIBS += [
+        'static:/js/src/ctypes/libffi/.libs/%sffi' % prefix,
+    ]
--- a/config/external/freetype2/Makefile.in
+++ b/config/external/freetype2/Makefile.in
@@ -1,6 +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/.
 
-target::
+ifdef MOZ_TREE_FREETYPE
+
+include $(topsrcdir)/config/config.mk
+
+$(STATIC_LIBS):
 	$(MAKE) -C $(DEPTH)/modules/freetype2
+
+endif
--- a/config/external/freetype2/moz.build
+++ b/config/external/freetype2/moz.build
@@ -1,5 +1,14 @@
 # -*- 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 = 'freetype'
+
+if CONFIG['MOZ_TREE_FREETYPE']:
+    USE_LIBS += [
+        'static:/modules/freetype2/.libs/freetype',
+    ]
+else:
+    OS_LIBS += CONFIG['FT2_LIBS']
--- a/config/external/icu/Makefile.in
+++ b/config/external/icu/Makefile.in
@@ -38,16 +38,17 @@ ifdef ENABLE_INTL_API
   endif # !MOZ_NATIVE_ICU
 endif # ENABLE_INTL_API
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef ENABLE_INTL_API
 ifndef MOZ_NATIVE_ICU
 target:: buildicu
+$(STATIC_LIBS): buildicu
 
 # - Force ICU to use the standard suffix for object files because expandlibs
 #   will discard all files with a non-standard suffix (bug 857450).
 # - Options for genrb: -k strict parsing; -R omit collation tailoring rules.
 buildicu::
 # ICU's build system is full of races, so force non-parallel build.
 # Msys screws up GENRBOPTS when it contains spaces, so all genrb flags need
 # to be stuck together. See https://bugzilla.mozilla.org/show_bug.cgi?id=1034594#c34
--- a/config/external/icu/moz.build
+++ b/config/external/icu/moz.build
@@ -1,5 +1,18 @@
 # -*- 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 = 'icu'
+
+if CONFIG['MOZ_NATIVE_ICU']:
+    OS_LIBS += CONFIG['MOZ_ICU_LIBS']
+else:
+    USE_LIBS += sorted(
+        '%s/intl/icu/target/lib/%s%s' % (
+            'static:' if not CONFIG['MOZ_SHARED_ICU'] else '',
+            l,
+            CONFIG['MOZ_ICU_DBG_SUFFIX']
+        ) for l in CONFIG['ICU_LIB_NAMES']
+    )
--- a/config/external/moz.build
+++ b/config/external/moz.build
@@ -1,18 +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/.
 
 external_dirs = []
-if not CONFIG['MOZ_NATIVE_SQLITE']:
-    external_dirs += ['db/sqlite3/src']
 
+DIRS += [
+    'sqlite',
+]
 if not CONFIG['MOZ_NATIVE_JPEG']:
     external_dirs += ['media/libjpeg']
 
 if CONFIG['MOZ_UPDATER']:
     if not CONFIG['MOZ_NATIVE_BZ2']:
         external_dirs += ['modules/libbz2']
 
 if CONFIG['MOZ_VORBIS']:
--- a/config/external/nspr/Makefile.in
+++ b/config/external/nspr/Makefile.in
@@ -3,19 +3,17 @@
 # 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
 
 ifdef LIBXUL_SDK
 $(error config/external/nspr/Makefile.in is not compatible with --enable-libxul-sdk=)
 endif
-ifdef MOZ_NATIVE_NSPR
-$(error config/external/nspr/Makefile.in is not compatible with MOZ_NATIVE_NSPR)
-endif
+ifdef MOZ_BUILD_NSPR
 
 # Copy NSPR to the SDK
 ABS_DIST = $(abspath $(DIST))
 
 ifdef MOZ_FOLD_LIBS
 # Trick the nspr build system into not building shared libraries.
 # bug #851869.
 EXTRA_MAKE_FLAGS := SHARED_LIBRARY= IMPORT_LIBRARY= SHARED_LIB_PDB=
@@ -41,8 +39,10 @@ target::
 	$(INSTALL) $(DEPTH)/nsprpub/config/nspr-config $(DIST)/sdk/bin
 	$(RM) -rf $(DIST)/sdk/dummy
 ifneq (,$(filter WINNT,$(OS_ARCH))) # {
 	$(RM) -f $(DIST)/sdk/lib/$(DLL_PREFIX)nspr4$(DLL_SUFFIX) $(DIST)/sdk/lib/$(DLL_PREFIX)plc4$(DLL_SUFFIX) $(DIST)/sdk/lib/$(DLL_PREFIX)plds4$(DLL_SUFFIX)
 	$(RM) -f $(DIST)/sdk/lib/$(LIB_PREFIX)nspr4_s.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plc4_s.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plds4_s.$(LIB_SUFFIX)
 else # } {
 	$(RM) -f $(DIST)/sdk/lib/$(LIB_PREFIX)nspr4.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plc4.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plds4.$(LIB_SUFFIX)
 endif # }
+
+endif
--- a/config/external/nspr/moz.build
+++ b/config/external/nspr/moz.build
@@ -1,6 +1,21 @@
 # -*- 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 = 'nspr'
+
+if CONFIG['MOZ_FOLD_LIBS']:
+    # When folding libraries, nspr is actually in the nss library.
+    USE_LIBS += [
+        'nss',
+    ]
+elif CONFIG['MOZ_BUILD_NSPR']:
+    USE_LIBS += [
+        '/nsprpub/lib/ds/plds4',
+        '/nsprpub/lib/libc/src/plc4',
+        '/nsprpub/pr/src/nspr4',
+    ]
+else:
+    OS_LIBS += CONFIG['NSPR_LIBS']
--- a/config/external/nss/Makefile.in
+++ b/config/external/nss/Makefile.in
@@ -1,13 +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/.
 
+ifndef MOZ_NATIVE_NSS
+
 CC_WRAPPER =
 CXX_WRAPPER =
 
 default::
 
 include $(topsrcdir)/config/makefiles/functions.mk
 
 NSS_LIBS = \
@@ -315,29 +317,18 @@ NSS_SDK_LIB_FILES := \
   $(addprefix $(DIST)/lib/$(LIB_PREFIX),$(addsuffix .$(LIB_SUFFIX),$(SDK_LIBS))) \
   $(addprefix $(DIST)/bin/$(DLL_PREFIX),$(addsuffix $(DLL_SUFFIX),$(NSS_DLLS))) \
   $(NULL)
 NSS_SDK_LIB_DEST := $(DIST)/sdk/lib
 NSS_SDK_LIB_TARGET := target
 INSTALL_TARGETS += NSS_SDK_LIB
 
 ifdef MOZ_FOLD_LIBS
-ifeq (WINNT,$(OS_TARGET))
-SUFFIX = _s.$(LIB_SUFFIX)
-else
-SUFFIX = .$(LIB_SUFFIX)
-endif
-
-# Fold NSPR libs
-EXTRA_LIBS += $(DEPTH)/nsprpub/pr/src/$(LIB_PREFIX)nspr4$(SUFFIX)
-EXTRA_LIBS += $(DEPTH)/nsprpub/lib/ds/$(LIB_PREFIX)plds4$(SUFFIX)
-EXTRA_LIBS += $(DEPTH)/nsprpub/lib/libc/src/$(LIB_PREFIX)plc4$(SUFFIX)
-
 # Add all static libraries for nss, smime, ssl and nssutil
-EXTRA_LIBS += $(addprefix $(DEPTH)/security/,$(NSS_STATIC_LIBS))
+STATIC_LIBS += $(addprefix $(DEPTH)/security/,$(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
@@ -414,17 +405,17 @@ libs-nss/lib/softoken: libs-nss/lib/dbm
 endif
 libs-nss/lib/softoken: $(DIST)/lib/$(IMPORT_PREFIX)nssutil3$(IMPORT_SUFFIX)
 libs-nss/lib/freebl: $(DIST)/lib/$(IMPORT_PREFIX)nssutil3$(IMPORT_SUFFIX) $(NSPR_IMPORT_LIBS)
 
 # For each directory where we build static libraries, force the NSS build system
 # to only build static libraries.
 $(addprefix libs-,$(NSS_STATIC_DIRS)): DEFAULT_GMAKE_FLAGS += SHARED_LIBRARY= IMPORT_LIBRARY=
 else
-$(NSS_DIST_DLL_FILES) $(NSS_SDK_LIB_FILES): libs-nss/lib
+$(STATIC_LIBS) $(NSS_DIST_DLL_FILES) $(NSS_SDK_LIB_FILES): libs-nss/lib
 endif # MOZ_FOLD_LIBS
 
 ifeq ($(NSINSTALL_PY),$(NSINSTALL))
 DEFAULT_GMAKE_FLAGS += PYTHON='$(PYTHON)'
 DEFAULT_GMAKE_FLAGS += NSINSTALL_PY='$(abspath $(topsrcdir)/config/nsinstall.py)'
 DEFAULT_GMAKE_FLAGS += NSINSTALL='$$(PYTHON) $$(NSINSTALL_PY)'
 else
 DEFAULT_GMAKE_FLAGS += NSINSTALL='$(abspath $(NSINSTALL))'
@@ -464,8 +455,10 @@ endif
 $(NSS_CMD_TARGETS): libs-nss/cmd/lib
 else
 $(NSS_CMD_TARGETS): libs-nss/lib libs-nss/cmd/lib
 endif # MOZ_FOLD_LIBS
 
 # Work around NSS build system race condition creating certdata.c in
 # security/nss/lib/ckfw/builtins. See bug #836220.
 libs-nss/lib$(if $(MOZ_FOLD_LIBS),/ckfw): $(call mkdir_deps,$(DEPTH)/security/nss/lib/ckfw/builtins)
+
+endif
new file mode 100644
--- /dev/null
+++ b/config/external/nss/crmf/moz.build
@@ -0,0 +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 = 'crmf'
+
+if CONFIG['MOZ_NATIVE_NSS']:
+    OS_LIBS += [l for l in CONFIG['NSS_LIBS'] if l.startswith('-L')]
+    OS_LIBS += '-lcrmf'
+else:
+    USE_LIBS += [
+        # The dependency on nss is not real, but is required to force the
+        # parent directory being built before this one. This has no
+        # practical effect on linkage, since the only thing linking crmf
+        # will need nss anyways.
+        'nss',
+        'static:/security/nss/lib/crmf/crmf',
+    ]
--- a/config/external/nss/moz.build
+++ b/config/external/nss/moz.build
@@ -1,26 +1,47 @@
 # -*- 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['MOZ_FOLD_LIBS']:
+LIBRARY_NAME = 'nss'
+
+DIRS += ['crmf']
+
+if CONFIG['MOZ_NATIVE_NSS']:
+    OS_LIBS += CONFIG['NSS_LIBS']
+elif CONFIG['MOZ_FOLD_LIBS']:
     # TODO: The library name can be changed when bug 845217 is fixed.
-    LIBRARY_NAME = 'nss3'
+    SHARED_LIBRARY_NAME = 'nss3'
 
     FORCE_SHARED_LIB = True
     SDK_LIBRARY = True
 
+    # Normally, there should be /something/ to ensure nspr is built
+    # before this directory, but since nspr is built during "export",
+    # it actually doesn't matter.
+    if CONFIG['OS_TARGET'] == 'WINNT':
+        suffix = '_s'
+    else:
+        suffix = ''
     USE_LIBS += [
-        'mozsqlite3',
+        'static:/nsprpub/lib/ds/plds4%s' % suffix,
+        'static:/nsprpub/lib/libc/src/plc4%s' % suffix,
+        'static:/nsprpub/pr/src/nspr4%s' % suffix,
     ]
 
     OS_LIBS += CONFIG['REALTIME_LIBS']
 
-if CONFIG['OS_TARGET'] == 'WINNT':
-    DEFFILE = 'nss3.def'
+    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'
+    if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['GCC_USE_GNU_LD']:
+        LD_VERSION_SCRIPT = 'nss3.def'
+else:
+    USE_LIBS += [
+        '/security/nss/lib/nss/nss3',
+        '/security/nss/lib/smime/smime3',
+        '/security/nss/lib/ssl/ssl3',
+        '/security/nss/lib/util/nssutil3',
+        'sqlite',
+    ]
--- a/config/external/nss/nss.def
+++ b/config/external/nss/nss.def
@@ -630,17 +630,19 @@ SSL_CipherPrefSetDefault
 SSL_ClearSessionCache
 SSL_ConfigSecureServer
 SSL_ConfigServerSessionIDCache
 SSL_ExportKeyingMaterial
 SSL_ForceHandshake
 SSL_GetChannelInfo
 SSL_GetCipherSuiteInfo
 SSL_GetClientAuthDataHook
+SSL_GetImplementedCiphers
 SSL_GetNextProto
+SSL_GetNumImplementedCiphers
 SSL_GetSRTPCipher
 SSL_HandshakeCallback
 SSL_HandshakeNegotiatedExtension
 SSL_ImplementedCiphers DATA
 SSL_ImportFD
 SSL_NumImplementedCiphers DATA
 SSL_OptionSet
 SSL_OptionSetDefault
new file mode 100644
--- /dev/null
+++ b/config/external/sqlite/Makefile.in
@@ -0,0 +1,35 @@
+# 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/.
+
+LIB_IS_C_ONLY    = 1
+
+include $(topsrcdir)/config/config.mk
+
+ifeq ($(OS_ARCH),WINNT)
+# This needs to stay there for now
+DEFFILE = $(DEPTH)/db/sqlite3/src/sqlite-processed.def
+
+else
+ifndef MOZ_FOLD_LIBS
+ifdef GCC_USE_GNU_LD
+
+GARBAGE += \
+  $(LD_VERSION_SCRIPT) \
+  $(NULL)
+
+# Convert to the format we need for ld.
+$(LD_VERSION_SCRIPT): $(topsrcdir)/db/sqlite3/src/sqlite.def
+	@$(call py_action,convert_def_file, \
+	  $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) -o $@ $^)
+
+endif
+endif
+endif
+
+
+ifeq (Darwin,$(OS_TARGET))
+# On OSX, with jemalloc enabled, having sqlite linked against mozglue
+# causes crashes in NSS standalone tools.
+MOZ_GLUE_LDFLAGS =
+endif
new file mode 100644
--- /dev/null
+++ b/config/external/sqlite/moz.build
@@ -0,0 +1,23 @@
+# -*- 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 = 'sqlite'
+
+if CONFIG['MOZ_NATIVE_SQLITE']:
+    OS_LIBS += CONFIG['SQLITE_LIBS']
+else:
+    DIRS += ['../../../db/sqlite3/src']
+    if CONFIG['MOZ_FOLD_LIBS']:
+        # When folding libraries, sqlite is actually in the nss library.
+        USE_LIBS += [
+            'nss',
+        ]
+    else:
+        FORCE_SHARED_LIB = True
+        SHARED_LIBRARY_NAME = 'mozsqlite3'
+
+        if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['GCC_USE_GNU_LD']:
+            LD_VERSION_SCRIPT = 'sqlite-processed.def'
new file mode 100644
--- /dev/null
+++ b/config/external/zlib/moz.build
@@ -0,0 +1,21 @@
+# -*- 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 = 'zlib'
+
+if CONFIG['MOZ_NATIVE_ZLIB']:
+    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+else:
+    if CONFIG['ZLIB_IN_MOZGLUE']:
+        # Can't do this until mozglue is handled by moz.build instead of
+        # config/rules.mk.
+        # USE_LIBS += [
+        #     'mozglue'
+        # ]
+        pass
+    DIRS += [
+        '../../../modules/zlib',
+    ]
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -77,17 +77,16 @@ 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
-EXTRA_LIBS += $(NSPR_LIBS)
 
 ifndef MOZ_PROFILE_GENERATE
 CPP_UNIT_TESTS_FILES = $(CPP_UNIT_TESTS)
 CPP_UNIT_TESTS_DEST = $(DIST)/cppunittests
 CPP_UNIT_TESTS_TARGET = target
 INSTALL_TARGETS += CPP_UNIT_TESTS
 endif
 
@@ -560,17 +559,18 @@ ECHO := true
 QUIET := -q
 endif
 
 # Do everything from scratch
 everything::
 	$(MAKE) clean
 	$(MAKE) all
 
-STATIC_LIBS_DEPS := $(wildcard $(addsuffix .$(LIBS_DESC_SUFFIX),$(STATIC_LIBS)))
+STATIC_LIB_DEP = $(if $(wildcard $(1).$(LIBS_DESC_SUFFIX)),$(1).$(LIBS_DESC_SUFFIX),$(1))
+STATIC_LIBS_DEPS := $(foreach l,$(STATIC_LIBS),$(call STATIC_LIB_DEP,$(l)))
 
 # Dependencies which, if modified, should cause everything to rebuild
 GLOBAL_DEPS += Makefile $(DEPTH)/config/autoconf.mk $(topsrcdir)/config/config.mk
 
 ##############################################
 ifdef COMPILE_ENVIRONMENT
 OBJ_TARGETS = $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS)
 
--- a/configure.in
+++ b/configure.in
@@ -6119,17 +6119,16 @@ if test -n "$MOZ_TREE_FREETYPE"; then
       AC_ERROR("building with in-tree freetype is not supported on MSVC")
    fi
    AC_DEFINE(MOZ_TREE_FREETYPE)
    AC_SUBST(MOZ_TREE_FREETYPE)
    MOZ_ENABLE_CAIRO_FT=1
    FT_FONT_FEATURE="#define CAIRO_HAS_FT_FONT 1"
    FT2_CFLAGS='-I$(topsrcdir)/modules/freetype2/include'
    CAIRO_FT_CFLAGS='-I$(topsrcdir)/modules/freetype2/include'
-   FT2_LIBS='$(call EXPAND_LIBNAME_PATH,freetype,$(DEPTH)/modules/freetype2/.libs)'
    CAIRO_FT_OSLIBS=''
    AC_DEFINE(HAVE_FT_BITMAP_SIZE_Y_PPEM)
    AC_DEFINE(HAVE_FT_GLYPHSLOT_EMBOLDEN)
    AC_DEFINE(HAVE_FT_LOAD_SFNT_TABLE)
    AC_SUBST_LIST(CAIRO_FT_CFLAGS)
 fi
 
 dnl ========================================================
--- a/content/base/test/moz.build
+++ b/content/base/test/moz.build
@@ -38,11 +38,12 @@ MOCHITEST_CHROME_MANIFESTS += [
     'chrome/chrome.ini',
     'csp/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/content/media/compiledtest/moz.build
+++ b/content/media/compiledtest/moz.build
@@ -13,11 +13,12 @@ SOURCES += sorted('%s.cpp' % t for t in 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/content/media/webaudio/compiledtest/moz.build
+++ b/content/media/webaudio/compiledtest/moz.build
@@ -13,11 +13,12 @@ SOURCES += sorted('%s.cpp' % t for t in 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/db/sqlite3/src/Makefile.in
+++ b/db/sqlite3/src/Makefile.in
@@ -1,58 +1,32 @@
 #
 # 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/.
 
-LIB_IS_C_ONLY    = 1
-
 include $(topsrcdir)/config/config.mk
 
 ifeq ($(OS_ARCH),WINNT)
 DEFFILE = $(CURDIR)/sqlite-processed.def
 
 GARBAGE += \
   $(DEFFILE) \
   $(NULL)
 
 # We have to preprocess our def file because we need different symbols in debug
 # builds exposed that are not built in non-debug builds.
 $(DEFFILE): sqlite.def
 	@$(call py_action,preprocessor,$(DEFINES) $(XULPPFLAGS) \
 	  $(srcdir)/sqlite.def -o $(DEFFILE))
-
-else
-ifndef MOZ_FOLD_LIBS
-ifdef GCC_USE_GNU_LD
-
-GARBAGE += \
-  $(LD_VERSION_SCRIPT) \
-  $(NULL)
-
-# Convert to the format we need for ld.
-$(LD_VERSION_SCRIPT): $(srcdir)/sqlite.def
-	@$(call py_action,convert_def_file, \
-	  $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) -o $@ $^)
-
-endif
-endif
-endif
-
-ifeq (Darwin,$(OS_TARGET))
-# On OSX, with jemalloc enabled, having sqlite linked against mozglue
-# causes crashes in NSS standalone tools.
-MOZ_GLUE_LDFLAGS =
 endif
 
 # XXX Force -O2 optimisation on Mac because using the default -O3 causes
 # crashes. See bug 676499.
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 MODULE_OPTIMIZE_FLAGS = -O2
 endif
 
 # Force /O2 optimisation on Windows because using the default /O1 causes
 # crashes with MSVC2005 and PGO. See bug 719584.
 ifeq ($(OS_ARCH),WINNT)
 MODULE_OPTIMIZE_FLAGS = -O2
 endif
-
-include $(topsrcdir)/config/rules.mk
--- a/db/sqlite3/src/moz.build
+++ b/db/sqlite3/src/moz.build
@@ -4,27 +4,27 @@
 # 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/.
 NO_VISIBILITY_FLAGS = True
 
 EXPORTS += [
     'sqlite3.h',
 ]
 
-LIBRARY_NAME = 'mozsqlite3'
+if CONFIG['MOZ_FOLD_LIBS']:
+    # When folding libraries, sqlite is actually in the nss library.
+    FINAL_LIBRARY = 'nss'
+else:
+    # The final library is in config/external/sqlite
+    FINAL_LIBRARY = 'sqlite'
 
 SOURCES += [
     'sqlite3.c',
 ]
 
-if CONFIG['MOZ_FOLD_LIBS']:
-    FORCE_STATIC_LIB = True
-else:
-    FORCE_SHARED_LIB = True
-
 # -DSQLITE_SECURE_DELETE=1 will cause SQLITE to 0-fill delete data so we
 # don't have to vacuum to make sure the data is not visible in the file.
 # -DSQLITE_ENABLE_FTS3=1 enables the full-text index module.
 # -DSQLITE_CORE=1 statically links that module into the SQLite library.
 # -DSQLITE_DEFAULT_PAGE_SIZE=32768 and SQLITE_MAX_DEFAULT_PAGE_SIZE=32768
 # increases the page size from 1k, see bug 416330.  It must be kept in sync with
 # the value of PREF_TS_PAGESIZE_DEFAULT in mozStorageService.cpp.  The value can
 # be overridden on a per-platform basis through the use of the PREF_TS_PAGESIZE
@@ -65,19 +65,14 @@ if CONFIG['OS_TARGET'] == 'Android':
 if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_MEMORY']:
     DEFINES['HAVE_MALLOC_USABLE_SIZE'] = True
     DEFINES['SQLITE_WITHOUT_MSIZE'] = True
 
 # disable PGO for Sun Studio
 if CONFIG['SOLARIS_SUNPRO_CC']:
     NO_PGO = True
 
-if CONFIG['OS_ARCH'] == 'Linux' and \
-   not CONFIG['MOZ_FOLD_LIBS'] and \
-   CONFIG['GCC_USE_GNU_LD']:
-    LD_VERSION_SCRIPT = 'sqlite-processed.def'
-
 # Suppress warnings in third-party code.
 if CONFIG['GNU_CC']:
     CFLAGS += [
         '-Wno-sign-compare',
         '-Wno-type-limits',
     ]
--- a/dom/audiochannel/tests/moz.build
+++ b/dom/audiochannel/tests/moz.build
@@ -14,11 +14,12 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['NOMINMAX'] = True
 
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/dom/canvas/compiledtest/moz.build
+++ b/dom/canvas/compiledtest/moz.build
@@ -13,11 +13,12 @@ SOURCES += sorted('%s.cpp' % t for t in 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '../',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/editor/txmgr/tests/moz.build
+++ b/editor/txmgr/tests/moz.build
@@ -9,11 +9,12 @@ CPP_UNIT_TESTS += [
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/extensions/gnomevfs/Makefile.in
+++ /dev/null
@@ -1,8 +0,0 @@
-# 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_LIBS += \
-		   $(NSPR_LIBS) \
-		   $(NULL)
--- a/extensions/gnomevfs/moz.build
+++ b/extensions/gnomevfs/moz.build
@@ -13,15 +13,16 @@ 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 ;-)
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['MOZ_GNOMEVFS_CFLAGS']
 
 OS_LIBS += CONFIG['MOZ_GNOMEVFS_LIBS']
--- a/intl/lwbrk/tests/moz.build
+++ b/intl/lwbrk/tests/moz.build
@@ -11,11 +11,12 @@ CPP_UNIT_TESTS += [
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 LOCAL_INCLUDES += [
     '../public',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/intl/unicharutil/tests/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS		+= \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/intl/unicharutil/tests/moz.build
+++ b/intl/unicharutil/tests/moz.build
@@ -18,16 +18,17 @@ SIMPLE_PROGRAMS += [
 LOCAL_INCLUDES += [
     '../public',
 ]
 
 USE_STATIC_LIBS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'unicharutil_external_s',
     'xul',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_LIBS += [
         'xpcomglue_staticruntime_s',
     ]
--- a/ipc/app/Makefile.in
+++ b/ipc/app/Makefile.in
@@ -3,20 +3,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 ifneq ($(dir $(PROGRAM)),./)
   GENERATED_DIRS = $(dir $(PROGRAM))
 endif
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 WRAP_LDFLAGS =
-else
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NULL)
 endif
 
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
--- a/ipc/app/moz.build
+++ b/ipc/app/moz.build
@@ -12,16 +12,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
     ]
     FINAL_TARGET = 'dist/bin/lib'
 else:
     SOURCES += [
         'MozillaRuntimeMain.cpp',
     ]
     USE_LIBS += [
         'mozalloc',
+        'nspr',
         'xul',
     ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
--- a/ipc/ipdl/test/cxx/app/Makefile.in
+++ b/ipc/ipdl/test/cxx/app/Makefile.in
@@ -1,9 +1,5 @@
 # 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
-
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NULL)
--- a/ipc/ipdl/test/cxx/app/moz.build
+++ b/ipc/ipdl/test/cxx/app/moz.build
@@ -16,11 +16,12 @@ LOCAL_INCLUDES += [
     '/xpcom/base',
 ]
 
 if CONFIG['_MSC_VER']:
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -10,34 +10,25 @@ 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)')
-EXTRA_LIBS		+= $(NSPR_LIBS)
 
 DIST_INSTALL = 1
 NO_EXPAND_LIBS = 1
 
 ifdef JS_HAS_CTYPES
 ifdef MOZ_NATIVE_FFI
 LOCAL_INCLUDES = $(MOZ_FFI_CFLAGS)
 endif
 
-ifdef MOZ_NATIVE_FFI
-OS_LIBS += $(MOZ_FFI_LIBS)
-else
-EXTRA_LIBS += \
-    ctypes/libffi/.libs/libffi.$(LIB_SUFFIX) \
-    $(NULL)
-endif
-
 # Windows needs this to be linked with a static library.
 ifndef MOZ_NATIVE_FFI
 DEFINES += -DFFI_BUILDING
 endif
 
 endif # JS_HAS_CTYPES
 
 DASH_R		= -r
@@ -189,26 +180,18 @@ DIST_GARBAGE = config.cache config.log c
    backend.mk config/backend.mk devtools/backend.mk editline/backend.mk \
    gdb/backend.mk jsapi-tests/backend.mk shell/backend.mk tests/backend.mk \
    backend.RecursiveMakeBackend backend.RecursiveMakeBackend.pp \
    devtools/rootAnalysis/Makefile
 
 distclean::
 	$(RM) $(DIST_GARBAGE)
 
-ifneq ($(findstring -L,$(NSPR_LIBS)),)
-NSPR_STATIC_PATH = $(subst -L,,$(findstring -L,$(NSPR_LIBS)))
-else
-NSPR_STATIC_PATH = $(DIST)/lib
-endif
-
 CFLAGS += $(MOZ_ZLIB_CFLAGS)
 
-EXTRA_LIBS += $(MOZ_ICU_LIBS)
-
 # Silence warnings on AIX/HP-UX from non-GNU compilers
 ifndef GNU_CC
 ifeq ($(OS_ARCH),AIX)
 # Suppress warnings from xlC
 # 1540-1281: offsetof() on null non-POD types
 # 1540-1608: anonymous unions using static data members
 CFLAGS		+= -qsuppress=1540-1281 -qsuppress=1540-1608
 CXXFLAGS	+= -qsuppress=1540-1281 -qsuppress=1540-1608
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -1,22 +1,14 @@
 # -*- 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/.
 
-EXTRA_LIBS += $(NSPR_LIBS)
-
-ifdef MOZ_SHARED_ICU
-OS_LIBS += $(MOZ_ICU_LIBS)
-endif
-
-OS_LIBS += $(MOZ_FFI_LIBS)
-
 # Place a GDB Python auto-load file next to the gdb-tests executable, both
 # in the build directory and in the dist/bin directory.
 PP_TARGETS += GDB_AUTOLOAD
 GDB_AUTOLOAD := gdb-tests-gdb.py.in
 GDB_AUTOLOAD_FLAGS := -Dtopsrcdir=$(abspath $(srcdir)/..)
 
 INSTALL_TARGETS += GDB_INSTALL_AUTOLOAD
 GDB_INSTALL_AUTOLOAD_FILES := $(CURDIR)/gdb-tests-gdb.py
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -1,22 +1,14 @@
 # -*- 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/.
 
-EXTRA_LIBS      += $(NSPR_LIBS)
-
-ifdef MOZ_SHARED_ICU
-OS_LIBS += $(MOZ_ICU_LIBS)
-endif
-
-OS_LIBS += $(MOZ_FFI_LIBS)
-
 ifdef QEMU_EXE
 MOZ_POST_PROGRAM_COMMAND = $(topsrcdir)/build/qemu-wrap --qemu $(QEMU_EXE) --libdir $(CROSS_LIB)
 endif
 
 # Place a GDB Python auto-load file next to the jsapi-tests executable in
 # the build directory.
 PP_TARGETS += JSAPI_TESTS_AUTOLOAD
 JSAPI_TESTS_AUTOLOAD := jsapi-tests-gdb.py.in
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -433,21 +433,31 @@ 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']:
+if CONFIG['JS_HAS_CTYPES']:
+    USE_LIBS += [
+        'ffi',
+    ]
+
+if CONFIG['ENABLE_INTL_API']:
     USE_LIBS += [
-        'mozz',
+        'icu',
     ]
 
+USE_LIBS += [
+    'nspr',
+    'zlib',
+]
+
 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']:
@@ -482,18 +492,16 @@ if CONFIG['_MSC_VER']:
 DEFINES['USE_SYSTEM_MALLOC'] = 1
 DEFINES['ENABLE_ASSEMBLER'] = 1
 
 if CONFIG['OS_ARCH'] not in ('WINNT', 'HP-UX'):
     OS_LIBS += [
         'm',
     ]
 
-OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
-
 if CONFIG['OS_ARCH'] == 'FreeBSD':
     OS_LIBS += [
         '-pthread',
     ]
 
 if CONFIG['OS_ARCH'] == 'Linux':
     OS_LIBS += [
         'dl',
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -1,22 +1,14 @@
 # -*- 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/.
 
-EXTRA_LIBS      += $(NSPR_LIBS)
-ifdef MOZ_NATIVE_FFI
-OS_LIBS += $(MOZ_FFI_LIBS)
-endif
-ifdef MOZ_SHARED_ICU
-OS_LIBS += $(MOZ_ICU_LIBS)
-endif
-
 ifeq ($(OS_ARCH),Darwin)
 ifeq ($(TARGET_CPU),x86_64)
 DARWIN_EXE_LDFLAGS += -pagezero_size 10000 -image_base 100000000
 endif
 endif
 
 ifdef QEMU_EXE
 MOZ_POST_PROGRAM_COMMAND = $(topsrcdir)/build/qemu-wrap --qemu $(QEMU_EXE) --libdir $(CROSS_LIB)
--- a/js/xpconnect/shell/Makefile.in
+++ b/js/xpconnect/shell/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/.
 
 SDK_BINARY	= $(PROGRAM)
 
-EXTRA_LIBS +=	$(NSPR_LIBS)
-
 NSDISTMODE = copy
--- a/js/xpconnect/shell/moz.build
+++ b/js/xpconnect/shell/moz.build
@@ -33,11 +33,12 @@ if CONFIG['_MSC_VER']:
     # a console application.
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     RCINCLUDE = 'xpcshell.rc'
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/js/xpconnect/tests/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NULL)
--- a/js/xpconnect/tests/components/native/Makefile.in
+++ b/js/xpconnect/tests/components/native/Makefile.in
@@ -4,15 +4,11 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 componentdir = js/xpconnect/tests/components/native
 
 MANIFEST = xpctest.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(componentdir)
 PP_TARGETS += MANIFEST
 
-EXTRA_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
@@ -21,11 +21,12 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' %
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/js/xpconnect/tests/moz.build
+++ b/js/xpconnect/tests/moz.build
@@ -12,11 +12,12 @@ TEST_DIRS += [
     'components/native',
     'components/js',
 ]
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/layout/media/Makefile.in
+++ b/layout/media/Makefile.in
@@ -1,15 +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/.
 
-ifeq (WINNT,$(OS_TARGET))
-EXTRA_LIBS += $(NSPR_LIBS)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifeq (WINNT,$(OS_TARGET))
 symbols.def: symbols.def.in $(GLOBAL_DEPS)
 	$(call py_action,preprocessor,$(ACDEFINES) $< -o $@)
 endif
--- a/layout/media/moz.build
+++ b/layout/media/moz.build
@@ -5,16 +5,17 @@
 # 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',
+        'nspr',
     ]
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += ['webrtc']
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     DEFFILE = 'symbols.def'
     OS_LIBS += [
--- a/media/libcubeb/tests/moz.build
+++ b/media/libcubeb/tests/moz.build
@@ -43,16 +43,17 @@ else:
     # Don't link gkmedias for it introduces dependencies on Android.
     if CONFIG['OS_TARGET'] == 'Android':
         USE_LIBS += [
             'speex',
         ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     OS_LIBS += [
         '-framework AudioUnit',
         '-framework CoreAudio',
--- a/media/mtransport/test/Makefile.in
+++ b/media/mtransport/test/Makefile.in
@@ -1,25 +1,10 @@
 # -*- 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/.
 
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NULL)
-
-ifdef MOZ_NATIVE_NSS
-EXTRA_LIBS += $(NSS_LIBS)
-else
-# Statically linking NSS libssl ensures that we can debug NSS too
-EXTRA_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
-
 ifeq ($(OS_TARGET), Android)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
 endif
--- a/media/mtransport/test/moz.build
+++ b/media/mtransport/test/moz.build
@@ -84,16 +84,24 @@ LOCAL_INCLUDES += [
 ]
 
 USE_LIBS += [
     '/media/webrtc/trunk/testing/gtest_gtest/gtest',
     'mozalloc',
     'mtransport_s',
     'nicer',
     'nrappkit',
+    'nspr',
+    'nss',
     'xpcomglue_s',
     'xul',
 ]
 
+if not CONFIG['MOZ_NATIVE_NSS'] and not CONFIG['MOZ_FOLD_LIBS']:
+    USE_LIBS += [
+        # Statically linking NSS libssl ensures that we can debug NSS too
+        'static:/security/nss/lib/ssl/ssl',
+    ]
+
 if CONFIG['MOZ_SCTP']:
     USE_LIBS += [
         'nksctp_s',
     ]
--- a/media/webrtc/signaling/test/Makefile.in
+++ b/media/webrtc/signaling/test/Makefile.in
@@ -1,17 +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_LIBS += \
-  $(NSPR_LIBS) \
-  $(NSS_LIBS) \
-  $(NULL)
-
 ifeq ($(OS_TARGET),Android)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
 endif
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/media/webrtc/webrtc-config.mk
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -96,32 +96,30 @@ if CONFIG['OS_TARGET'] in ('DragonFly', 
 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',
+    'nspr',
+    'nss',
     'webrtc',
     'xpcomglue_s',
     'xul',
     'yuv',
+    'zlib',
 ]
 
 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',
     ]
 
 OS_LIBS += CONFIG['MOZ_WEBRTC_X11_LIBS']
 OS_LIBS += CONFIG['REALTIME_LIBS']
 
@@ -142,24 +140,23 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2
     OS_LIBS += CONFIG['MOZ_GTK2_LIBS']
     OS_LIBS += [
         'gmodule-2.0',
         'gthread-2.0',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
     OS_LIBS += CONFIG['MOZ_GTK3_LIBS']
-    OS_LIBS += CONFIG['FT2_LIBS']
+    USE_LIBS += [
+        'freetype',
+    ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
     OS_LIBS += CONFIG['XLIBS']
     OS_LIBS += CONFIG['TK_LIBS']
     OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
 
 if CONFIG['OS_TARGET'] in ('Linux', 'DragonFly', 'FreeBSD', 'NetBSD',
         'OpenBSD'):
     OS_LIBS += CONFIG['MOZ_CAIRO_OSLIBS']
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     OS_LIBS += CONFIG['TK_LIBS']
-
-if CONFIG['MOZ_NATIVE_ZLIB']:
-    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/memory/mozalloc/tests/moz.build
+++ b/memory/mozalloc/tests/moz.build
@@ -7,11 +7,12 @@
 CPP_UNIT_TESTS += [
     'TestVolatileBuffer',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/mfbt/tests/Makefile.in
+++ b/mfbt/tests/Makefile.in
@@ -5,13 +5,8 @@
 # in order to prevent rules.mk from trying to link to libraries that are
 # 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=
-
-# Prevent those tests linking against libxpcom, libxul, and nspr.
-NSPR_LIBS=
-
-include $(topsrcdir)/config/rules.mk
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -12,27 +12,16 @@
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
 HOST_CFLAGS += \
   -DNO_SIGN_VERIFY \
   $(DEFINES) \
   $(NULL)
 
-ifdef MOZ_ENABLE_SIGNMAR
-# Please don't remove the following comment, because it does some magic:
-# We don't want to use NSS_LIBS, presumably to avoid useless dependencies
-# on parts of nss that don't matter.
-EXTRA_LIBS += \
-  $(DIST)/lib/$(LIB_PREFIX)nss3.$(LIB_SUFFIX) \
-  $(DIST)/lib/$(LIB_PREFIX)nssutil3.$(LIB_SUFFIX) \
-  $(NSPR_LIBS) \
-  $(NULL)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef CROSS_COMPILE
 ifdef HOST_NSPR_MDCPUCFG
 HOST_CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
 CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
 endif
 endif
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -23,17 +23,22 @@ if CONFIG['MOZ_ENABLE_SIGNMAR']:
         'mar',
         'signmar',
         'verifymar',
     ]
 
 for var in ('MAR_CHANNEL_ID', 'MOZ_APP_VERSION'):
     DEFINES[var] = '"%s"' % CONFIG[var]
 
-if not CONFIG['MOZ_ENABLE_SIGNMAR']:
+if CONFIG['MOZ_ENABLE_SIGNMAR']:
+    USE_LIBS += [
+        'nspr',
+        'nss',
+    ]
+else:
     DEFINES['NO_SIGN_VERIFY'] = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_STATIC_LIBS = True
 
     OS_LIBS += [
         'ws2_32',
     ]
--- a/modules/zlib/src/moz.build
+++ b/modules/zlib/src/moz.build
@@ -5,17 +5,22 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS += [
     'mozzconf.h',
     'zconf.h',
     'zlib.h',
 ]
 
-LIBRARY_NAME = 'mozz'
+if CONFIG['ZLIB_IN_MOZGLUE']:
+    FINAL_LIBRARY = 'mozglue'
+    DEFINES['IMPL_MFBT'] = True
+else:
+    # The final library is in config/external/zlib
+    FINAL_LIBRARY = 'zlib'
 
 SOURCES += [
     'adler32.c',
     'compress.c',
     'crc32.c',
     'deflate.c',
     'gzclose.c',
     'gzlib.c',
@@ -24,11 +29,8 @@ SOURCES += [
     'infback.c',
     'inffast.c',
     'inflate.c',
     'inftrees.c',
     'trees.c',
     'uncompr.c',
     'zutil.c',
 ]
-
-if CONFIG['ZLIB_IN_MOZGLUE']:
-    DEFINES['IMPL_MFBT'] = True
--- a/moz.build
+++ b/moz.build
@@ -19,47 +19,39 @@ if not CONFIG['JS_STANDALONE']:
         'tools/update-packaging/Makefile',
     ]
 
     add_tier_dir('base', ['build', 'probes'])
 
 if not CONFIG['LIBXUL_SDK']:
     add_tier_dir('base', ['mfbt'])
 
-    if not CONFIG['MOZ_NATIVE_ZLIB']:
-        add_tier_dir('base', ['modules/zlib'])
+    add_tier_dir('base', ['config/external/zlib'])
 
     if not CONFIG['JS_STANDALONE']:
         if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
             add_tier_dir('base', ['other-licenses/android'])
 
         if CONFIG['MOZ_MEMORY']:
             add_tier_dir('base', ['memory'])
 
         add_tier_dir('base', ['mozglue', 'memory/mozalloc'])
 
 
 if not CONFIG['JS_STANDALONE']:
     add_tier_dir('precompile', 'xpcom/xpidl')
 
 if CONFIG['COMPILE_ENVIRONMENT'] and not CONFIG['LIBXUL_SDK']:
-    if CONFIG['MOZ_BUILD_NSPR']:
-        add_tier_dir('nspr', 'config/external/nspr', trigger='NSPR_LIBS')
+    add_tier_dir('nspr', 'config/external/nspr')
 
     if not CONFIG['JS_STANDALONE']:
         add_tier_dir('external', 'config/external')
-        if not CONFIG['MOZ_NATIVE_NSS']:
-            # We want security/build to be built before anything using
-            # NSPR_LIBS when MOZ_FOLD_LIBS is set, because that's where NSPR
-            # actually ends up being linked. All places using NSS_LIBS also
-            # use NSPR_LIBS so it's safe to use the latter.
-            add_tier_dir('nss', 'config/external/nss',
-                trigger='NSPR_LIBS' if CONFIG['MOZ_FOLD_LIBS'] else 'NSS_LIBS')
+        add_tier_dir('nss', 'config/external/nss')
 
-    if CONFIG['BUILD_CTYPES'] and not CONFIG['MOZ_NATIVE_FFI']:
-        add_tier_dir('js', ['config/external/ffi'], trigger='MOZ_FFI_LIBS')
-    if CONFIG['ENABLE_INTL_API'] and not CONFIG['MOZ_NATIVE_ICU']:
-        add_tier_dir('js', ['config/external/icu'], trigger='MOZ_ICU_LIBS')
+    if CONFIG['BUILD_CTYPES']:
+        add_tier_dir('js', ['config/external/ffi'])
+    if CONFIG['ENABLE_INTL_API']:
+        add_tier_dir('js', ['config/external/icu'])
     add_tier_dir('js', ['js/src'])
 
 if not CONFIG['JS_STANDALONE']:
     # Bring in the configuration for the configured application.
     include('/' + CONFIG['MOZ_BUILD_APP'] + '/app.mozbuild')
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -5,22 +5,16 @@
 
 DIST_INSTALL = 1
 
 # For FORCE_SHARED_LIB
 include $(topsrcdir)/config/config.mk
 
 MOZ_GLUE_LDFLAGS = # Don't link against ourselves
 
-ifneq (,$(ZLIB_IN_MOZGLUE)$(MOZ_LINKER))
-ifdef MOZ_NATIVE_ZLIB
-EXTRA_LIBS += $(MOZ_ZLIB_LIBS)
-endif
-endif
-
 ifeq (WINNT,$(OS_TARGET))
 mozglue.def: mozglue.def.in $(GLOBAL_DEPS)
 	$(call py_action,preprocessor,$(if $(MOZ_REPLACE_MALLOC),-DMOZ_REPLACE_MALLOC) $(ACDEFINES) $< -o $@)
 
 GARBAGE += mozglue.def
 
 ifneq (,$(filter -DEFAULTLIB:mozcrt,$(MOZ_GLUE_LDFLAGS)))
 # Don't install the import library if we use mozcrt
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -70,19 +70,19 @@ if CONFIG['MOZ_ASAN']:
 
 
 LIBRARY_NAME = 'mozglue'
 
 USE_LIBS += [
     'mfbt',
 ]
 
-if CONFIG['ZLIB_IN_MOZGLUE'] and not CONFIG['MOZ_NATIVE_ZLIB']:
+if CONFIG['MOZ_LINKER']:
     USE_LIBS += [
-        'mozz',
+        'zlib',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     SOURCES += [
         'cpuacct.c',
     ]
 
 DEFINES['IMPL_MFBT'] = True
deleted file mode 100644
--- a/netwerk/streamconv/test/Makefile.in
+++ /dev/null
@@ -1,10 +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/.
-
-EXTRA_LIBS		+= \
-		$(NSPR_LIBS) \
-		$(NULL)
-
-include $(topsrcdir)/config/rules.mk
--- a/netwerk/streamconv/test/moz.build
+++ b/netwerk/streamconv/test/moz.build
@@ -17,11 +17,12 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     DEFINES['NGPREFS'] = True
     if CONFIG['GNU_CXX']:
         LDFLAGS += ['-mconsole']
     else:
         LDFLAGS += ['-SUBSYSTEM:CONSOLE']
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/netwerk/test/Makefile.in
+++ b/netwerk/test/Makefile.in
@@ -1,20 +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/.
 
-
-
-EXTRA_LIBS	+= \
-		  $(NSPR_LIBS) \
-		  $(NULL)
-
 DEFINES += $(TK_CFLAGS)
 
 include $(topsrcdir)/config/rules.mk
 
 # One of the xpcshell unit tests needs this file, so make sure it winds
 #  up in the test directory.
 libs::
 	$(NSINSTALL) -D $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/data
--- a/netwerk/test/moz.build
+++ b/netwerk/test/moz.build
@@ -60,11 +60,12 @@ SOURCES += sorted('%s.cpp' % t for t in 
 
 RESOURCE_FILES += [
     'urlparse.dat',
     'urlparse_unx.dat',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/rdf/tests/rdfcat/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS	+= \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/rdf/tests/rdfcat/moz.build
+++ b/rdf/tests/rdfcat/moz.build
@@ -7,13 +7,14 @@
 PROGRAM = 'rdfcat'
 
 SOURCES += [
     'rdfcat.cpp',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
deleted file mode 100644
--- a/rdf/tests/rdfpoll/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS	+= \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/rdf/tests/rdfpoll/moz.build
+++ b/rdf/tests/rdfpoll/moz.build
@@ -7,11 +7,12 @@
 PROGRAM = 'rdfpoll'
 
 SOURCES += [
     'rdfpoll.cpp',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/rdf/tests/triplescat/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS	+= \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/rdf/tests/triplescat/moz.build
+++ b/rdf/tests/triplescat/moz.build
@@ -7,13 +7,14 @@
 PROGRAM = 'triplescat'
 
 SOURCES += [
     'triplescat.cpp',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/security/manager/ssl/src/moz.build
+++ b/security/manager/ssl/src/moz.build
@@ -98,8 +98,12 @@ LOCAL_INCLUDES += [
 
 if CONFIG['NSS_DISABLE_DBM']:
     DEFINES['NSS_DISABLE_DBM'] = '1'
 
 DEFINES['SSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES'] = 'True'
 DEFINES['NSS_ENABLE_ECC'] = 'True'
 for var in ('DLL_PREFIX', 'DLL_SUFFIX'):
     DEFINES[var] = '"%s"' % CONFIG[var]
+
+USE_LIBS += [
+    'crmf',
+]
--- a/security/manager/ssl/tests/compiled/moz.build
+++ b/security/manager/ssl/tests/compiled/moz.build
@@ -7,11 +7,12 @@
 CPP_UNIT_TESTS += [
   'TestCertDB',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/Makefile.in
+++ /dev/null
@@ -1,12 +0,0 @@
-# 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
-
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NSS_LIBS) \
-  $(NULL)
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
+++ b/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
@@ -18,13 +18,15 @@ SOURCES += [
 
 LOCAL_INCLUDES += [
     '../lib',
 ]
 
 USE_LIBS += [
     'mozalloc',
     'mozillapkix',
+    'nspr',
+    'nss',
     'pkixtestutil',
     'tlsserver',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ b/security/sandbox/win/src/sandboxbroker/Makefile.in
@@ -1,9 +1,5 @@
 # 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 =
-
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/security/sandbox/win/src/sandboxbroker/moz.build
+++ b/security/sandbox/win/src/sandboxbroker/moz.build
@@ -2,16 +2,17 @@
 # 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 += [
+    'nspr',
     'sandbox_s',
 ]
 
 SOURCES += [
     'sandboxBroker.cpp',
 ]
 
 EXPORTS += [
deleted file mode 100644
--- a/startupcache/test/Makefile.in
+++ /dev/null
@@ -1,6 +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/.
-
-EXTRA_LIBS += $(NSPR_LIBS)
--- a/startupcache/test/moz.build
+++ b/startupcache/test/moz.build
@@ -12,11 +12,12 @@ SOURCES += sorted('%s.cpp' % t for t in 
 
 EXTRA_COMPONENTS += [
     'TestStartupCacheTelemetry.js',
     'TestStartupCacheTelemetry.manifest',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/storage/test/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/storage/test/moz.build
+++ b/storage/test/moz.build
@@ -33,18 +33,13 @@ SOURCES += sorted('%s.cpp' % t for t in 
 LOCAL_INCLUDES += [
     '../src',
 ]
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
+    'sqlite',
     'xpcomglue_s',
     'xul',
 ]
-
-if not CONFIG['MOZ_NATIVE_SQLITE'] and not CONFIG['MOZ_FOLD_LIBS']:
-    USE_LIBS += [
-        'mozsqlite3',
-    ]
-
-OS_LIBS += CONFIG['SQLITE_LIBS']
deleted file mode 100644
--- a/testing/mochitest/ssltunnel/Makefile.in
+++ /dev/null
@@ -1,9 +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/.
-
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NSS_LIBS) \
-  $(NULL)
--- a/testing/mochitest/ssltunnel/moz.build
+++ b/testing/mochitest/ssltunnel/moz.build
@@ -7,13 +7,15 @@
 PROGRAM = 'ssltunnel'
 
 SOURCES += [
     'ssltunnel.cpp',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
+    'nss',
 ]
 
 # This isn't XPCOM code, but it wants to use STL, so disable the STL
 # wrappers
 DISABLE_STL_WRAPPING = True
--- a/toolkit/components/places/tests/cpp/moz.build
+++ b/toolkit/components/places/tests/cpp/moz.build
@@ -9,16 +9,17 @@ CPP_UNIT_TESTS += [
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 if CONFIG['JS_SHARED_LIBRARY']:
     USE_LIBS += [
         'js',
     ]
--- a/toolkit/crashreporter/test/Makefile.in
+++ b/toolkit/crashreporter/test/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/.
 
-EXTRA_LIBS += $(NSPR_LIBS)
-
 UNIT_FILES = $(SHARED_LIBRARY) CrashTestUtils.jsm
 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
@@ -36,11 +36,12 @@ DEFINES['NOMINMAX'] = True
 LOCAL_INCLUDES += [
     '../google-breakpad/src/',
 ]
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -1,16 +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/.
 
 include $(topsrcdir)/toolkit/library/libxul.mk
-# Please don't remove the following comment, because it does some magic:
-# libxul.mk adds FT2_LIBS, NSS_LIBS and NSPR_LIBS, but we want to have the
-# string in this file to trigger a dependency on freetype2, nss and nspr.
 
 ifeq (WINNT_1,$(OS_TARGET)_$(MOZ_PROFILE_USE))
 # Wrap linker to measure peak virtual memory usage.
 LD := $(PYTHON) $(topsrcdir)/build/link.py linker-vsize $(LD)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
--- a/toolkit/library/libxul.mk
+++ b/toolkit/library/libxul.mk
@@ -11,46 +11,26 @@ OS_LDFLAGS += -Wl,-version-script,symver
 symverscript: $(topsrcdir)/toolkit/library/symverscript.in
 	$(call py_action,preprocessor, \
 		-DVERSION='xul$(MOZILLA_SYMBOLVERSION)' $< -o $@)
 
 EXTRA_DEPS += symverscript
 endif
 endif
 
-EXTRA_LIBS += \
-  $(NSS_LIBS) \
-  $(NULL)
-
-ifdef ENABLE_INTL_API
-ifneq (,$(JS_SHARED_LIBRARY)$(MOZ_NATIVE_ICU))
-OS_LIBS += $(MOZ_ICU_LIBS)
-endif
-endif
-
-ifdef MOZ_NATIVE_FFI
-OS_LIBS += $(MOZ_FFI_LIBS)
-endif
-
 ifdef MOZ_WEBRTC
 ifeq (WINNT,$(OS_TARGET))
 ifndef MOZ_HAS_WINSDK_WITH_D3D
 OS_LDFLAGS += \
   -LIBPATH:'$(MOZ_DIRECTX_SDK_PATH)/lib/$(MOZ_D3D_CPU_SUFFIX)' \
   $(NULL)
 endif
 endif
 endif
 
-EXTRA_LIBS += $(NSPR_LIBS)
-
-ifdef MOZ_TREE_FREETYPE
-OS_LIBS += $(FT2_LIBS)
-endif
-
 # Generate GDB pretty printer-autoload files only on Linux. OSX's GDB is
 # too old to support Python pretty-printers; if this changes, we could make
 # this 'ifdef GNU_CC'.
 ifeq (Linux,$(OS_ARCH))
 # Create a GDB Python auto-load file alongside the libxul shared library in
 # the build directory.
 PP_TARGETS += LIBXUL_AUTOLOAD
 LIBXUL_AUTOLOAD = $(topsrcdir)/toolkit/library/libxul.so-gdb.py.in
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -55,43 +55,45 @@ if CONFIG['OS_ARCH'] == 'WINNT':
         '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',
+    'nspr',
+    'nss',
+    'sqlite',
+    'zlib',
 ]
 
+if CONFIG['ENABLE_INTL_API']:
+    USE_LIBS += [
+        'icu',
+    ]
+
 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']
+if CONFIG['MOZ_WIDGET_GTK'] or CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt' or \
+        CONFIG['MOZ_TREE_FREETYPE']:
+    USE_LIBS += [
+        'freetype',
+    ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     CXXFLAGS += CONFIG['TK_CFLAGS']
 
 if CONFIG['MOZ_WEBRTC']:
     if CONFIG['OS_TARGET'] == 'WINNT':
         OS_LIBS += [
             'secur32',
@@ -158,27 +160,23 @@ if CONFIG['MOZ_B2G_CAMERA']:
 if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['OS_TARGET'] != 'Android':
     OS_LIBS += [
         'rt',
     ]
 
 OS_LIBS += CONFIG['MOZ_CAIRO_OSLIBS']
 OS_LIBS += CONFIG['MOZ_WEBRTC_X11_LIBS']
 OS_LIBS += CONFIG['MOZ_APP_EXTRA_LIBS']
-OS_LIBS += CONFIG['SQLITE_LIBS']
 
 if CONFIG['MOZ_NATIVE_JPEG']:
     OS_LIBS += CONFIG['MOZ_JPEG_LIBS']
 
 if CONFIG['MOZ_NATIVE_PNG']:
     OS_LIBS += CONFIG['MOZ_PNG_LIBS']
 
-if CONFIG['MOZ_NATIVE_ZLIB']:
-    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
-
 if CONFIG['MOZ_NATIVE_HUNSPELL']:
     OS_LIBS += CONFIG['MOZ_HUNSPELL_LIBS']
 
 if CONFIG['MOZ_NATIVE_LIBEVENT']:
     OS_LIBS += CONFIG['MOZ_LIBEVENT_LIBS']
 
 if CONFIG['MOZ_NATIVE_LIBVPX']:
     OS_LIBS += CONFIG['MOZ_LIBVPX_LIBS']
@@ -243,24 +241,22 @@ if CONFIG['MOZ_WIDGET_GTK']:
     OS_LIBS += CONFIG['XLDFLAGS']
     OS_LIBS += CONFIG['XLIBS']
     OS_LIBS += CONFIG['XEXT_LIBS']
     OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
     OS_LIBS += CONFIG['XT_LIBS']
     OS_LIBS += [
         'gthread-2.0',
     ]
-    OS_LIBS += CONFIG['FT2_LIBS']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
     OS_LIBS += CONFIG['XLDFLAGS']
     OS_LIBS += CONFIG['XLIBS']
     OS_LIBS += CONFIG['XT_LIBS']
     OS_LIBS += CONFIG['MOZ_QT_LIBS']
-    OS_LIBS += CONFIG['FT2_LIBS']
     OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
 
 if CONFIG['MOZ_ENABLE_STARTUP_NOTIFICATION']:
     OS_LIBS += CONFIG['MOZ_STARTUP_NOTIFICATION_LIBS']
 
 if CONFIG['MOZ_ENABLE_LIBPROXY']:
     OS_LIBS += CONFIG['MOZ_LIBPROXY_LIBS']
 
@@ -321,8 +317,11 @@ if CONFIG['MOZ_ENABLE_QT']:
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa' and CONFIG['MOZ_GSTREAMER']:
     OS_LIBS += CONFIG['GSTREAMER_LIBS']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     OS_LIBS += [
         'usp10',
         'oleaut32',
     ]
+
+# This needs to be last
+USE_LIBS += ['StaticXULComponentsEnd']
deleted file mode 100644
--- a/toolkit/system/dbus/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/.
-
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-    $(NULL)
--- a/toolkit/system/dbus/moz.build
+++ b/toolkit/system/dbus/moz.build
@@ -11,16 +11,17 @@ SOURCES += [
 ]
 
 LIBRARY_NAME = 'dbusservice'
 
 IS_COMPONENT = True
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
 
 OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS']
deleted file mode 100644
--- a/toolkit/system/gnome/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/.
-
-EXTRA_LIBS += \
-		$(NSPR_LIBS) \
-        $(NULL)
--- a/toolkit/system/gnome/moz.build
+++ b/toolkit/system/gnome/moz.build
@@ -30,16 +30,17 @@ FAIL_ON_WARNINGS = True
 IS_COMPONENT = True
 
 LOCAL_INCLUDES += [
     '/toolkit/components/build/',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['MOZ_GCONF_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_GNOMEVFS_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_GIO_CFLAGS']
 CXXFLAGS += CONFIG['GLIB_CFLAGS']
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -21,18 +21,17 @@ if CONFIG['MOZ_UPDATER']:
     add_tier_dir('platform', 'modules/libmar')
 
 if CONFIG['NS_TRACE_MALLOC']:
     add_tier_dir('platform', 'tools/trace-malloc/lib')
 
 if CONFIG['MOZ_DMD']:
     add_tier_dir('platform', 'memory/replace/dmd')
 
-if CONFIG['MOZ_TREE_FREETYPE']:
-    add_tier_dir('platform', 'config/external/freetype2', trigger='FT2_LIBS')
+add_tier_dir('platform', 'config/external/freetype2')
 
 add_tier_dir('platform', 'xpcom')
 
 add_tier_dir('platform', [
     'modules/libpref',
     'intl',
     'netwerk',
 ])
--- a/tools/trace-malloc/Makefile.in
+++ b/tools/trace-malloc/Makefile.in
@@ -16,20 +16,23 @@ PROGCSRCS = \
 
 PROGOBJS = $(PROGCSRCS:.c=.$(OBJ_SUFFIX))
 endif
 
 CPPSRCS += $(EXTRACPPSRCS)
 
 include $(topsrcdir)/config/config.mk
 
+# This is the last use of EXTRA_LIBS, and it would be sad to not have an
+# error if it's used in other Makefiles just because of it. So hack around
+# the check.
+_DEPRECATED_VARIABLES := $(filter-out EXTRA_LIBS,$(_DEPRECATED_VARIABLES))
 EXTRA_LIBS	+= \
 		tmreader.$(OBJ_SUFFIX) \
 		adreader.$(OBJ_SUFFIX) \
-		$(NSPR_LIBS) \
 		$(NULL)
 
 EXTRA_DEPS = $(EXTRACSRCS:.c=.$(OBJ_SUFFIX)) $(EXTRACPPSRCS:.cpp=.$(OBJ_SUFFIX))
 
 include $(topsrcdir)/config/rules.mk
 
 # install rules.txt along with spacetrace executable
 libs:: rules.txt
--- a/tools/trace-malloc/moz.build
+++ b/tools/trace-malloc/moz.build
@@ -41,11 +41,12 @@ SOURCES += [
 SIMPLE_PROGRAMS += simple_cpp_sources
 
 RESOURCE_FILES += [
     'spacetrace.css'
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/uriloader/exthandler/tests/Makefile.in
+++ b/uriloader/exthandler/tests/Makefile.in
@@ -1,15 +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_LIBS +=		\
-		$(NSPR_LIBS) \
-		$(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 # need the executable for running the xpcshell unit tests
 ifneq (,$(SIMPLE_PROGRAMS))
 libs::
 	$(INSTALL) $(SIMPLE_PROGRAMS) $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit
 endif
--- a/uriloader/exthandler/tests/moz.build
+++ b/uriloader/exthandler/tests/moz.build
@@ -18,8 +18,12 @@ if CONFIG['OS_ARCH'] != 'Darwin':
 
 SIMPLE_PROGRAMS = [
     'WriteArgument',
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
+
+USE_LIBS += [
+    'nspr',
+]
--- a/widget/tests/moz.build
+++ b/widget/tests/moz.build
@@ -23,11 +23,12 @@ FAIL_ON_WARNINGS = True
 #     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',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/widget/xremoteclient/Makefile.in
+++ b/widget/xremoteclient/Makefile.in
@@ -17,12 +17,8 @@ PROGCPPSRCS = \
   $(NULL)
 
 PROGOBJS = $(PROGCPPSRCS:.cpp=.$(OBJ_SUFFIX))
 
 CPPSRCS += \
   $(filter-out $(LIBCPPSRCS),$(PROGCPPSRCS)) \
   $(LIBCPPSRCS) \
   $(NULL)
-
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/widget/xremoteclient/moz.build
+++ b/widget/xremoteclient/moz.build
@@ -7,8 +7,12 @@
 PROGRAM = 'mozilla-xremote-client'
 
 FINAL_LIBRARY = 'xul'
 
 DEFINES['XPCOM_GLUE'] = True
 
 OS_LIBS += CONFIG['XLDFLAGS']
 OS_LIBS += CONFIG['XLIBS']
+
+USE_LIBS += [
+    'nspr',
+]
deleted file mode 100644
--- a/xpcom/reflect/xptcall/tests/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS		+= \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/xpcom/reflect/xptcall/tests/moz.build
+++ b/xpcom/reflect/xptcall/tests/moz.build
@@ -9,11 +9,12 @@ SIMPLE_PROGRAMS = [
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/xpcom/reflect/xptinfo/tests/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS		+= \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/xpcom/reflect/xptinfo/tests/moz.build
+++ b/xpcom/reflect/xptinfo/tests/moz.build
@@ -9,11 +9,12 @@ SOURCES += [
 ]
 
 SIMPLE_PROGRAMS += [
     'TestInterfaceInfo'
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
deleted file mode 100644
--- a/xpcom/sample/Makefile.in
+++ /dev/null
@@ -1,8 +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/.
-
-EXTRA_LIBS += \
-		$(NSPR_LIBS) \
-		$(NULL)
--- a/xpcom/sample/moz.build
+++ b/xpcom/sample/moz.build
@@ -37,15 +37,16 @@ LIBRARY_NAME = 'xpcomsample'
 IS_COMPONENT = True
 
 RESOURCE_FILES.samples += [
     'xpconnect-sample.html',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/bug656331_component/Makefile.in
+++ b/xpcom/tests/bug656331_component/Makefile.in
@@ -6,15 +6,11 @@
 # Blatantly copied from xpcom/tests/component.
 
 unittestlocation = xpcom/tests/unit
 
 MANIFEST = bug656331.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
-EXTRA_LIBS += \
-  $(NSPR_LIBS) \
-  $(NULL)
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
--- a/xpcom/tests/bug656331_component/moz.build
+++ b/xpcom/tests/bug656331_component/moz.build
@@ -17,15 +17,16 @@ IS_COMPONENT = True
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/component/Makefile.in
+++ b/xpcom/tests/component/Makefile.in
@@ -4,15 +4,11 @@
 # 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_LIBS += \
-		$(NSPR_LIBS) \
-		$(NULL)
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
--- a/xpcom/tests/component/moz.build
+++ b/xpcom/tests/component/moz.build
@@ -17,15 +17,16 @@ IS_COMPONENT = True
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/component_no_aslr/Makefile.in
+++ b/xpcom/tests/component_no_aslr/Makefile.in
@@ -4,19 +4,15 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 unittestlocation = xpcom/tests/unit
 
 MANIFEST = testcompnoaslr.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
-EXTRA_LIBS += \
-		$(NSPR_LIBS) \
-		$(NULL)
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
 
 include $(topsrcdir)/config/rules.mk
 
 LDFLAGS := $(filter-out -DYNAMICBASE,$(LDFLAGS)) -DYNAMICBASE:NO
--- a/xpcom/tests/component_no_aslr/moz.build
+++ b/xpcom/tests/component_no_aslr/moz.build
@@ -17,15 +17,16 @@ IS_COMPONENT = True
 DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
deleted file mode 100644
--- a/xpcom/tests/external/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/.
-
-EXTRA_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/xpcom/tests/external/moz.build
+++ b/xpcom/tests/external/moz.build
@@ -9,11 +9,12 @@ SIMPLE_PROGRAMS = [
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -121,16 +121,17 @@ LOCAL_INCLUDES += [
 ]
 
 RESOURCE_FILES += [
     'test.properties',
 ]
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 if CONFIG['MOZ_DMD']:
     USE_LIBS += [
         'dmd'
     ]
--- a/xpcom/tests/windows/moz.build
+++ b/xpcom/tests/windows/moz.build
@@ -8,16 +8,17 @@ CPP_UNIT_TESTS += [
     'TestCOM',
     'TestNtPathToDosPath',
 ]
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]
 
 OS_LIBS += [
     'rpcrt4',
     'uuid',
     'mpr',
deleted file mode 100644
--- a/xulrunner/examples/simple/components/src/Makefile.in
+++ /dev/null
@@ -1,8 +0,0 @@
-# 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_LIBS += \
-	$(NSPR_LIBS) \
-	$(NULL)
--- a/xulrunner/examples/simple/components/src/moz.build
+++ b/xulrunner/examples/simple/components/src/moz.build
@@ -16,11 +16,12 @@ EXTRA_COMPONENTS += [
 ]
 
 IS_COMPONENT = True
 
 XPI_NAME = 'simple'
 
 USE_LIBS += [
     'mozalloc',
+    'nspr',
     'xpcomglue_s',
     'xul',
 ]