Bug 1077148 part 4 - Add and use new moz.build templates for Gecko programs and libraries. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 30 Oct 2014 13:06:12 +0900
changeset 213033 55d15b285436576e1c5979f753e433c50fd9db3a
parent 213032 0a59d60cf8ad1dc911ae16be55b767cec0044ee4
child 213034 1c24de5c098e4a999d00a0800eac59d3da14b2e6
push id51127
push usermh@glandium.org
push dateThu, 30 Oct 2014 04:07:13 +0000
treeherdermozilla-inbound@55d15b285436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1077148
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1077148 part 4 - Add and use new moz.build templates for Gecko programs and libraries. r=gps There are, sadly, many combinations of linkage in use throughout the tree. The main differentiator, though, is between program/libraries related to Gecko or not. Kind of. Some need mozglue, some don't. Some need dependent linkage, some standalone. Anyways, these new templates remove the need to manually define the right dependencies against xpcomglue, nspr, mozalloc and mozglue in most cases. Places that build programs and were resetting MOZ_GLUE_PROGRAM_LDFLAGS or that build libraries and were resetting MOZ_GLUE_LDFLAGS can now just not use those Gecko-specific templates.
accessible/interfaces/ia2/moz.build
accessible/interfaces/msaa/moz.build
b2g/app/moz.build
b2g/gaia/Makefile.in
browser/app/moz.build
browser/metro/shell/commandexecutehandler/Makefile.in
browser/metro/shell/testing/Makefile.in
build/clang-plugin/Makefile.in
build/docs/defining-binaries.rst
build/gecko_templates.mozbuild
build/templates.mozbuild
build/unix/elfhack/Makefile.in
build/win32/Makefile.in
build/win32/crashinjectdll/Makefile.in
build/win32/vmwarerecordinghelper/Makefile.in
config/config.mk
config/external/nss/Makefile.in
config/external/nss/moz.build
config/rules.mk
configure.in
dom/audiochannel/tests/moz.build
dom/base/test/moz.build
dom/canvas/compiledtest/moz.build
dom/media/compiledtest/moz.build
dom/media/webaudio/compiledtest/moz.build
dom/plugins/ipc/hangui/Makefile.in
editor/txmgr/tests/moz.build
embedding/tests/winEmbed/moz.build
gfx/angle/src/libEGL/moz.build
gfx/angle/src/libGLESv2/moz.build
intl/lwbrk/tests/moz.build
intl/unicharutil/tests/moz.build
ipc/app/Makefile.in
ipc/app/moz.build
ipc/ipdl/test/cxx/app/moz.build
js/src/configure.in
js/src/gdb/moz.build
js/src/jsapi-tests/moz.build
js/src/moz.build
js/src/shell/moz.build
js/xpconnect/shell/moz.build
js/xpconnect/tests/moz.build
layout/media/moz.build
media/gmp-clearkey/0.1/Makefile.in
media/libcubeb/tests/moz.build
media/mtransport/test/moz.build
media/webrtc/signaling/test/moz.build
memory/build/Makefile.in
memory/build/moz.build
memory/build/replace_malloc.h
memory/jemalloc/Makefile.in
memory/jemalloc/moz.build
memory/mozalloc/moz.build
memory/mozalloc/tests/moz.build
memory/replace/dmd/Makefile.in
memory/replace/dummy/Makefile.in
memory/replace/jemalloc/Makefile.in
memory/replace/logalloc/Makefile.in
memory/replace/logalloc/replay/Makefile.in
mfbt/tests/Makefile.in
modules/libmar/tool/Makefile.in
mozglue/build/Makefile.in
mozglue/build/moz.build
mozglue/linker/tests/Makefile.in
mozglue/tests/moz.build
netwerk/streamconv/test/moz.build
netwerk/test/moz.build
python/mozbuild/mozbuild/backend/recursivemake.py
rdf/tests/rdfcat/moz.build
rdf/tests/rdfpoll/moz.build
rdf/tests/triplescat/moz.build
security/manager/ssl/tests/compiled/moz.build
security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
security/sandbox/Makefile.in
security/sandbox/win/src/sandboxbroker/Makefile.in
startupcache/test/moz.build
storage/test/moz.build
testing/mochitest/ssltunnel/moz.build
testing/tools/screenshot/Makefile.in
toolkit/components/ctypes/tests/Makefile.in
toolkit/components/maintenanceservice/Makefile.in
toolkit/components/places/tests/cpp/moz.build
toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/injector/Makefile.in
toolkit/crashreporter/test/moz.build
toolkit/library/moz.build
toolkit/mozapps/update/tests/Makefile.in
toolkit/mozapps/update/updater/Makefile.in
toolkit/webapps/tests/Makefile.in
tools/trace-malloc/moz.build
uriloader/exthandler/tests/moz.build
webapprt/gtk/moz.build
webapprt/mac/Makefile.in
webapprt/mac/moz.build
webapprt/win/Makefile.in
webapprt/win/moz.build
widget/tests/moz.build
xpcom/reflect/xptcall/tests/moz.build
xpcom/reflect/xptinfo/tests/moz.build
xpcom/sample/program/moz.build
xpcom/tests/external/moz.build
xpcom/tests/moz.build
xpcom/tests/windows/moz.build
xpcom/typelib/xpt/tests/Makefile.in
xulrunner/app/moz.build
xulrunner/stub/Makefile.in
xulrunner/stub/moz.build
xulrunner/tools/redit/moz.build
--- a/accessible/interfaces/ia2/moz.build
+++ b/accessible/interfaces/ia2/moz.build
@@ -1,15 +1,15 @@
 # -*- 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/.
 
-SharedLibrary('IA2Marshal')
+GeckoSharedLibrary('IA2Marshal', linkage=None)
 
 DEFINES['REGISTER_PROXY_DLL'] = True
 
 DEFFILE = SRCDIR + '/IA2Marshal.def'
 
 OS_LIBS += [
     'uuid',
     'kernel32',
--- a/accessible/interfaces/msaa/moz.build
+++ b/accessible/interfaces/msaa/moz.build
@@ -1,15 +1,15 @@
 # -*- 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/.
 
-SharedLibrary('AccessibleMarshal')
+GeckoSharedLibrary('AccessibleMarshal', linkage=None)
 
 GENERATED_SOURCES += [
     'dlldata.c',
     'ISimpleDOMDocument_i.c',
     'ISimpleDOMDocument_p.c',
     'ISimpleDOMNode_i.c',
     'ISimpleDOMNode_p.c',
     'ISimpleDOMText_i.c',
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -1,19 +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 not CONFIG['LIBXUL_SDK']:
     if CONFIG['GAIADIR']:
-        Program(CONFIG['MOZ_APP_NAME'] + "-bin")
+        GeckoProgram(CONFIG['MOZ_APP_NAME'] + "-bin")
     else:
-        Program(CONFIG['MOZ_APP_NAME'])
+        GeckoProgram(CONFIG['MOZ_APP_NAME'])
     if CONFIG['MOZ_B2G_LOADER']:
         SOURCES += [
             'B2GLoader.cpp',
         ]
 
     SOURCES += [
         'nsBrowserApp.cpp',
     ]
@@ -21,18 +21,16 @@ if not CONFIG['LIBXUL_SDK']:
         # Always enter a Windows program through wmain, whether or not we're
         # a console application.
         WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
     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',
 ]
 
 LOCAL_INCLUDES += [
@@ -65,18 +63,14 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
             'gui',
             'suspend',
         ]
     OS_LIBS += [
         'binder',
         'utils',
     ]
 
-USE_LIBS += [
-    'xpcomglue',
-]
-
 DISABLE_STL_WRAPPING = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     OS_LIBS += [
         'version',
     ]
--- a/b2g/gaia/Makefile.in
+++ b/b2g/gaia/Makefile.in
@@ -1,17 +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/.
 
 GAIA_PATH := gaia/profile
 
-# This is needed to avoid making run-b2g depend on mozglue
-WRAP_LDFLAGS :=
-
 GENERATED_DIRS += $(DIST)/bin/$(GAIA_PATH)
 
 include $(topsrcdir)/config/rules.mk
 
 libs::
 	+$(MAKE) -j1 -C $(GAIADIR) clean
 	+$(MAKE) -j1 -C $(GAIADIR) profile
 	(cd $(GAIADIR)/profile && tar $(TAR_CREATE_FLAGS) - .) | (cd $(abspath $(DIST))/bin/$(GAIA_PATH) && tar -xf -)
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -1,45 +1,49 @@
 # -*- 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/.
 
 DIRS += ['profile/extensions']
 
-Program(CONFIG['MOZ_APP_NAME'])
+if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_METRO']:
+    GeckoProgram(CONFIG['MOZ_APP_NAME'])
+else:
+    GeckoProgram(CONFIG['MOZ_APP_NAME'], msvcrt='static')
 
 SOURCES += [
     'nsBrowserApp.cpp',
 ]
 
 DEFINES['APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 
 for var in ('MOZILLA_OFFICIAL', 'LIBXUL_SDK'):
     if CONFIG[var]:
         DEFINES[var] = True
 
-DEFINES['XPCOM_GLUE'] = True
-
 GENERATED_INCLUDES += [
     '/build',
 ]
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
 ]
 
 if not CONFIG['MOZ_METRO']:
   DELAYLOAD_DLLS += [
       'mozglue.dll',
   ]
-  USE_STATIC_LIBS = True
+
+USE_LIBS += [
+    'mozglue',
+]
 
 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 = 'splash.rc'
@@ -51,26 +55,16 @@ 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']
 
-if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['MOZ_METRO']:
-    USE_LIBS += [
-        'mozglue',
-        'xpcomglue_staticruntime',
-    ]
-else:
-    USE_LIBS += [
-        'xpcomglue',
-    ]
-
 DISABLE_STL_WRAPPING = True
 
 if CONFIG['MOZ_LINKER']:
     OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
 
 if CONFIG['HAVE_CLOCK_MONOTONIC']:
     OS_LIBS += CONFIG['REALTIME_LIBS']
 
--- a/browser/metro/shell/commandexecutehandler/Makefile.in
+++ b/browser/metro/shell/commandexecutehandler/Makefile.in
@@ -1,16 +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/.
 
 ifndef MOZ_WINCONSOLE
 MOZ_WINCONSOLE = 0
 endif
 
-include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/config/rules.mk
 
 DIST_PROGRAM = CommandExecuteHandler$(BIN_SUFFIX)
-
-# Don't link against mozglue.dll
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
deleted file mode 100644
--- a/browser/metro/shell/testing/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/.
-
-# don't use moz glue libs
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
--- a/build/clang-plugin/Makefile.in
+++ b/build/clang-plugin/Makefile.in
@@ -1,17 +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/.
 
 # LLVM_CXXFLAGS comes with its own optimization flags.
 MOZ_OPTIMIZE =
 
-MOZ_GLUE_LDFLAGS =
-
 include $(topsrcdir)/config/config.mk
 
 # In the current moz.build world, we need to override essentially every
 # variable to limit ourselves to what we need to build the clang plugin.
 OS_CXXFLAGS := $(LLVM_CXXFLAGS) -fno-rtti -fno-exceptions
 OS_COMPILE_CXXFLAGS :=
 OS_LDFLAGS := $(LLVM_LDFLAGS) $(CLANG_LDFLAGS)
 DSO_LDOPTS := -shared
--- a/build/docs/defining-binaries.rst
+++ b/build/docs/defining-binaries.rst
@@ -114,21 +114,16 @@ On OSX, one may want to create a special
 This is done with the ``Framework`` template.
 
    Framework('foo')
 
 With a ``Framework`` name of ``foo``, the framework file name will be ``foo``.
 This template however affects the behavior on all platforms, so it needs to
 be set only on OSX.
 
-Another special kind of library, XPCOM-specific, are XPCOM components. One can
-build such a component with the ``XPCOMBinaryComponent`` template.
-
-   XPCOMBinaryComponent('foo')
-
 
 Executables
 ===========
 
 Executables, a.k.a. programs, are, in the simplest form, defined with the
 ``Program`` template.
 
    Program('foobar')
@@ -288,8 +283,33 @@ instead of the ``Library`` name. This on
           'mylib',
           'otherlib',
       ]
 
 On e.g. Linux, the above ``myprog`` will have DT_NEEDED markers for
 ``libmylib.so`` and ``libfoo.so`` instead of ``libmylib.so`` and
 ``libotherlib.so`` if there weren't a ``SONAME``. This means the runtime
 requirement for ``myprog`` is ``libfoo.so`` instead of ``libotherlib.so``.
+
+
+Gecko-related binaries
+======================
+
+Some programs or libraries are totally independent of Gecko, and can use the
+above mentioned templates. Others are Gecko-related in some way, and may
+need XPCOM linkage, mozglue. These things are tedious. A set of additional
+templates exists to ease defining such programs and libraries. They are
+essentially the same as the above mentioned templates, prefixed with "Gecko":
+
+  - ``GeckoProgram``
+  - ``GeckoSimplePrograms``
+  - ``GeckoCppUnitTests``
+  - ``GeckoSharedLibrary``
+  - ``GeckoFramework``
+
+There is also ``XPCOMBinaryComponent`` for XPCOM components, which is a
+special kind of library.
+
+All the Gecko-prefixed templates take the same arguments as their
+non-Gecko-prefixed counterparts, and can take a few more arguments
+for non-standard cases. See the definition of ``GeckoBinary`` in
+build/gecko_templates.mozbuild for more details, but most usecases
+should not require these additional arguments.
new file mode 100644
--- /dev/null
+++ b/build/gecko_templates.mozbuild
@@ -0,0 +1,155 @@
+# -*- 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/.
+
+@template
+def GeckoBinary(linkage='dependent', msvcrt='dynamic', mozglue=None):
+    '''Template for Gecko-related binaries.
+
+    This template is meant to be used in other templates.
+
+    `linkage` indicates the wanted xpcom linkage type. Valid values are
+    'dependent', 'standalone' or None. 'dependent' is the default. It is
+    used for e.g. XPCOM components and executables with direct dependencies
+    on libxul. Most executables should use the 'standalone' linkage, which
+    uses the standalone XPCOM glue to load libxul. None means no XPCOM glue
+    or libxul linkage at all.
+
+    `msvcrt` indicates which Microsoft Visual Studio CRT, for Windows build,
+    ought to be linked: 'static' or 'dynamic'.
+
+    `mozglue` indicates whether to link against the mozglue library, and if
+    so, what linkage to apply. Valid values are None (mozglue not linked),
+    'program' (mozglue linked to an executable program), or 'library' (mozglue
+    linked to a shared library).
+    '''
+    if msvcrt == 'dynamic' or CONFIG['OS_ARCH'] != 'WINNT':
+        xpcomglue = 'xpcomglue'
+    elif msvcrt == 'static':
+        USE_STATIC_LIBS = True
+        xpcomglue = 'xpcomglue_staticruntime'
+        if not CONFIG['GNU_CC']:
+            mozglue = None
+    else:
+        error('msvcrt must be "dynamic" or "static"')
+
+    if linkage == 'dependent':
+        USE_LIBS += [
+            'mozalloc',
+            'nspr',
+            '%s_s' % xpcomglue,
+            'xul',
+        ]
+    elif linkage == 'standalone':
+        DEFINES['XPCOM_GLUE'] = True
+
+        USE_LIBS += [
+            xpcomglue,
+        ]
+    elif linkage != None:
+        error('`linkage` must be "dependent", "standalone" or None')
+
+    if mozglue:
+        if CONFIG['JS_STANDALONE']:
+            pass
+        elif CONFIG['MOZ_CRT']:
+            if msvcrt == 'dynamic':
+                USE_LIBS += ['mozcrt']
+            elif msvcrt == 'static':
+                USE_LIBS += ['mozglue']
+            else:
+                error('`msvcrt` must be "dynamic" or "static"')
+        else:
+            LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
+            if mozglue == 'program':
+                USE_LIBS += ['mozglue']
+                if CONFIG['MOZ_GLUE_IN_PROGRAM']:
+                    if CONFIG['GNU_CC']:
+                        LDFLAGS += ['-rdynamic']
+                    if CONFIG['MOZ_MEMORY']:
+                        USE_LIBS += ['memory']
+                    if CONFIG['MOZ_LINKER']:
+                        OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+            elif mozglue == 'library':
+                if not CONFIG['MOZ_GLUE_IN_PROGRAM']:
+                    USE_LIBS += ['mozglue']
+            else:
+                error('`mozglue` must be "program" or "library"')
+
+
+@template
+def GeckoProgram(name, linkage='standalone', **kwargs):
+    '''Template for program executables related to Gecko.
+
+    `name` identifies the executable base name.
+
+    See the documentation for `GeckoBinary` for other possible arguments,
+    with the notable difference that the default for `linkage` is 'standalone'.
+    '''
+    Program(name)
+
+    GeckoBinary(linkage=linkage, mozglue='program', **kwargs)
+
+
+@template
+def GeckoSimplePrograms(names, **kwargs):
+    '''Template for simple program executables related to Gecko.
+
+    `names` identifies the executable base names for each executable.
+
+    See the documentation for `GeckoBinary` for other possible arguments.
+    '''
+    SimplePrograms(names)
+
+    GeckoBinary(mozglue='program', **kwargs)
+
+
+@template
+def GeckoCppUnitTests(names, **kwargs):
+    '''Template for C++ unit tests related to Gecko.
+
+    `names` identifies the executable base names for each executable.
+
+    See the documentation for `GeckoBinary` for other possible arguments.
+    '''
+    CppUnitTests(names)
+
+    GeckoBinary(mozglue='program', **kwargs)
+
+
+@template
+def GeckoSharedLibrary(name, **kwargs):
+    '''Template for shared libraries related to Gecko.
+
+    `name` identifies the library base name.
+    See the documentation for `GeckoBinary` for other possible arguments.
+    '''
+    SharedLibrary(name)
+
+    GeckoBinary(mozglue='library', **kwargs)
+
+
+@template
+def GeckoFramework(name, **kwargs):
+    '''Template for OSX frameworks related to Gecko.
+
+    `name` identifies the library base name.
+    See the documentation for `GeckoBinary` for other possible arguments.
+    '''
+    Framework(name)
+
+    GeckoBinary(mozglue='library', **kwargs)
+
+
+@template
+def XPCOMBinaryComponent(name):
+    '''Template defining an XPCOM binary component for Gecko.
+
+    `name` is the name of the component.
+    '''
+    GeckoSharedLibrary(name)
+
+    IS_COMPONENT = True
+
--- a/build/templates.mozbuild
+++ b/build/templates.mozbuild
@@ -110,33 +110,9 @@ def HostSimplePrograms(names, ext='.cpp'
 
 
 @template
 def HostLibrary(name):
     '''Template for build tools libraries.'''
     HOST_LIBRARY_NAME = name
 
 
-@template
-def GeckoBinary():
-    '''Template for binaries using Gecko.
-
-    This template is meant to be used in other templates.
-    '''
-    USE_LIBS += [
-        'mozalloc',
-        'nspr',
-        'xpcomglue_s',
-        'xul',
-    ]
-
-
-@template
-def XPCOMBinaryComponent(name):
-    '''Template defining an XPCOM binary component for Gecko.
-
-    name is the name of the component.
-    '''
-    SharedLibrary(name)
-
-    GeckoBinary()
-
-    IS_COMPONENT = True
+include('gecko_templates.mozbuild')
--- a/build/unix/elfhack/Makefile.in
+++ b/build/unix/elfhack/Makefile.in
@@ -2,18 +2,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/.
 
 INTERNAL_TOOLS = 1
 
 OS_CXXFLAGS := $(filter-out -fno-exceptions,$(OS_CXXFLAGS)) -fexceptions
 
-WRAP_LDFLAGS=
-
 include $(topsrcdir)/config/rules.mk
 
 test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX): %$(DLL_SUFFIX): %.$(OBJ_SUFFIX) elfhack
 	$(MKSHLIB) $(LDFLAGS) $< -nostartfiles
 	@echo ===
 	@echo === If you get failures below, please file a bug describing the error
 	@echo === and your environment \(compiler and linker versions\), and use
 	@echo === --disable-elf-hack until this is fixed.
--- a/build/win32/Makefile.in
+++ b/build/win32/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/.
 
-MOZ_GLUE_LDFLAGS =
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef WIN32_REDIST_DIR
 
 REDIST_FILES = \
   $(MSVC_C_RUNTIME_DLL) \
   $(MSVC_CXX_RUNTIME_DLL) \
   $(NULL)
deleted file mode 100644
--- a/build/win32/crashinjectdll/Makefile.in
+++ /dev/null
@@ -1,5 +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/.
-
-MOZ_GLUE_LDFLAGS =
deleted file mode 100644
--- a/build/win32/vmwarerecordinghelper/Makefile.in
+++ /dev/null
@@ -1,5 +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/.
-
-MOZ_GLUE_LDFLAGS =
--- a/config/config.mk
+++ b/config/config.mk
@@ -229,30 +229,20 @@ ifdef HAVE_64BIT_BUILD
 OS_LDFLAGS = -DEBUG -OPT:REF,ICF
 else
 OS_LDFLAGS = -DEBUG -OPT:REF
 endif
 endif # NS_TRACE_MALLOC || MOZ_DMD
 
 endif # MOZ_DEBUG
 
-# We don't build a static CRT when building a custom CRT,
-# it appears to be broken. So don't link to jemalloc if
-# the Makefile wants static CRT linking.
-ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_1)
-# Disable default CRT libs and add the right lib path for the linker
-MOZ_GLUE_LDFLAGS=
-endif
-
 endif # WINNT && !GNU_CC
 
-ifdef MOZ_GLUE_PROGRAM_LDFLAGS
+ifdef MOZ_GLUE_IN_PROGRAM
 DEFINES += -DMOZ_GLUE_IN_PROGRAM
-else
-MOZ_GLUE_PROGRAM_LDFLAGS=$(MOZ_GLUE_LDFLAGS)
 endif
 
 #
 # Build using PIC by default
 #
 _ENABLE_PIC=1
 
 # PGO on MSVC is opt-in
--- a/config/external/nss/Makefile.in
+++ b/config/external/nss/Makefile.in
@@ -5,22 +5,16 @@
 
 ifndef MOZ_NATIVE_NSS
 
 CC_WRAPPER =
 CXX_WRAPPER =
 
 default::
 
-# When MOZ_CRT is set, we get mozcrt from moz.build instead of
-# MOZ_GLUE_LDFLAGS
-ifdef MOZ_CRT
-MOZ_GLUE_LDFLAGS =
-endif
-
 include $(topsrcdir)/config/makefiles/functions.mk
 
 NSS_LIBS = \
   nss3 \
   nssutil3 \
   smime3 \
   ssl3 \
   $(NULL)
@@ -218,19 +212,27 @@ DEFAULT_GMAKE_FLAGS += \
 	OS_PTHREAD= \
 	$(NULL)
 
 DEFAULT_GMAKE_FLAGS += ARCHFLAG='$(CFLAGS) -DCHECK_FORK_GETPID -DRTLD_NOLOAD=0 -include $(topsrcdir)/security/manager/android_stub.h'
 endif
 endif
 
 ifdef WRAP_LDFLAGS
+NSS_EXTRA_LDFLAGS += $(WRAP_LDFLAGS)
+endif
+
+ifdef MOZ_GLUE_WRAP_LDFLAGS
+NSS_EXTRA_LDFLAGS += $(SHARED_LIBS:$(DEPTH)%=$(MOZ_BUILD_ROOT)%) $(MOZ_GLUE_WRAP_LDFLAGS)
+endif
+
+ifneq (,$(WRAP_LDFLAGS)$(MOZ_GLUE_WRAP_LDFLAGS))
 DEFAULT_GMAKE_FLAGS += \
-	LDFLAGS='$(LDFLAGS) $(WRAP_LDFLAGS)' \
-	DSO_LDOPTS='$(DSO_LDOPTS) $(LDFLAGS) $(WRAP_LDFLAGS)' \
+	LDFLAGS='$(LDFLAGS) $(NSS_EXTRA_LDFLAGS)' \
+	DSO_LDOPTS='$(DSO_LDOPTS) $(LDFLAGS) $(NSS_EXTRA_LDFLAGS)' \
 	$(NULL)
 endif
 
 DEFAULT_GMAKE_FLAGS += FREEBL_NO_DEPEND=0
 ifeq ($(OS_TARGET),Linux)
 DEFAULT_GMAKE_FLAGS += FREEBL_LOWHASH=1
 endif
 
--- a/config/external/nss/moz.build
+++ b/config/external/nss/moz.build
@@ -5,17 +5,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += ['crmf']
 
 if CONFIG['MOZ_NATIVE_NSS']:
     Library('nss')
     OS_LIBS += CONFIG['NSS_LIBS']
 elif CONFIG['MOZ_FOLD_LIBS']:
-    SharedLibrary('nss')
+    GeckoSharedLibrary('nss', linkage=None)
     # TODO: The library name can be changed when bug 845217 is fixed.
     SHARED_LIBRARY_NAME = 'nss3'
 
     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.
@@ -31,22 +31,16 @@ elif CONFIG['MOZ_FOLD_LIBS']:
 
     OS_LIBS += CONFIG['REALTIME_LIBS']
 
     if CONFIG['OS_TARGET'] == 'WINNT':
         DEFFILE = 'nss3.def'
 
     if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['GCC_USE_GNU_LD']:
         LD_VERSION_SCRIPT = 'nss3.def'
-
-    # mozcrt needs at least one reference in a moz.build for the frontend
-    # not to raise an error. Here, it allows to avoid setting DLLFLAGS in
-    # configure.in.
-    if CONFIG['MOZ_CRT']:
-        USE_LIBS += ['mozcrt']
 else:
     Library('nss')
     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/rules.mk
+++ b/config/rules.mk
@@ -636,18 +636,16 @@ ifdef GNU_CC
 # Force rebuilding libraries and programs in both passes because each
 # pass uses different object files.
 $(PROGRAM) $(SHARED_LIBRARY) $(LIBRARY): FORCE
 endif
 endif
 
 endif # NO_PROFILE_GUIDED_OPTIMIZE
 
-MOZ_PROGRAM_LDFLAGS += $(MOZ_GLUE_PROGRAM_LDFLAGS)
-
 ##############################################
 
 checkout:
 	$(MAKE) -C $(topsrcdir) -f client.mk checkout
 
 clean clobber realclean clobber_all::
 	-$(RM) $(ALL_TRASH)
 	-$(RM) -r $(ALL_TRASH_DIRS)
--- a/configure.in
+++ b/configure.in
@@ -7067,38 +7067,25 @@ MOZ_ARG_ENABLE_BOOL(jemalloc,
 [  --enable-jemalloc       Replace memory allocator with jemalloc],
     MOZ_MEMORY=1,
     MOZ_MEMORY=)
 
 if test "$NS_TRACE_MALLOC"; then
     MOZ_MEMORY=
 fi
 
-if test "${OS_TARGET}" = "Android"; then
-  dnl On Android, we use WRAP_LDFLAGS to link everything to mozglue
-  :
-elif test "${OS_TARGET}" = "WINNT" -o "${OS_TARGET}" = "Darwin"; then
-  dnl On Windows and OSX, we want to link all our binaries against mozglue
-  MOZ_GLUE_LDFLAGS='$(call EXPAND_LIBNAME_PATH,mozglue,$(LIBXUL_DIST)/lib)'
-else
-  dnl On other Unix systems, we only want to link executables against mozglue
-  MOZ_GLUE_PROGRAM_LDFLAGS='$(call EXPAND_LIBNAME_PATH,mozglue,$(LIBXUL_DIST)/lib)'
-  dnl On other Unix systems, where mozglue is a static library, jemalloc is
-  dnl separated for the SDK, so we need to add it here.
-  if test "$MOZ_MEMORY" = 1 -o \( "$LIBXUL_SDK" -a -f "$LIBXUL_SDK/lib/${LIB_PREFIX}memory.${LIB_SUFFIX}" \); then
-    MOZ_GLUE_PROGRAM_LDFLAGS="$MOZ_GLUE_PROGRAM_LDFLAGS "'$(call EXPAND_LIBNAME_PATH,memory,$(LIBXUL_DIST)/lib)'
-  fi
-  if test -n "$GNU_CC"; then
-    dnl And we need mozglue symbols to be exported.
-    MOZ_GLUE_PROGRAM_LDFLAGS="$MOZ_GLUE_PROGRAM_LDFLAGS -rdynamic"
-  fi
-  if test "$MOZ_LINKER" = 1; then
-    MOZ_GLUE_PROGRAM_LDFLAGS="$MOZ_GLUE_PROGRAM_LDFLAGS $MOZ_ZLIB_LIBS"
-  fi
-fi
+case "${OS_TARGET}" in
+Android|WINNT|Darwin)
+  MOZ_GLUE_IN_PROGRAM=
+  ;;
+*)
+  dnl On !Android !Windows !OSX, we only want to link executables against mozglue
+  MOZ_GLUE_IN_PROGRAM=1
+  ;;
+esac
 
 dnl ========================================================
 dnl = Enable dynamic replacement of malloc implementation
 dnl ========================================================
 if test -n "$NIGHTLY_BUILD" -a -n "$MOZ_MEMORY"; then
   # Enable on central for the debugging opportunities it adds.
   MOZ_REPLACE_MALLOC=1
 fi
@@ -7216,17 +7203,16 @@ else
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   *-android*|*-linuxandroid*)
     AC_DEFINE(MOZ_MEMORY_LINUX)
     AC_DEFINE(MOZ_MEMORY_ANDROID)
     if test -n "$gonkdir"; then
       AC_DEFINE(MOZ_MEMORY_GONK)
     fi
-    MOZ_GLUE_LDFLAGS=
     ;;
   *-*linux*)
     AC_DEFINE(MOZ_MEMORY_LINUX)
     ;;
   *-netbsd*)
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   *-solaris*)
@@ -7236,43 +7222,43 @@ else
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
     export MOZ_NO_DEBUG_RTL=1
     WIN32_CRT_LIBS="msvcrt.lib msvcprt.lib"
     dnl Look for a broken crtdll.obj
     WIN32_CRTDLL_FULLPATH=`lib -nologo -list $WIN32_CRT_LIBS | grep crtdll\\.obj`
     lib -NOLOGO -OUT:crtdll.obj $WIN32_CRT_LIBS -EXTRACT:$WIN32_CRTDLL_FULLPATH
     if grep -q '__imp__\{0,1\}free' crtdll.obj; then
       MOZ_CRT=1
-      MOZ_GLUE_LDFLAGS='-LIBPATH:$(DIST)/lib -NODEFAULTLIB:msvcrt -NODEFAULTLIB:msvcprt -DEFAULTLIB:mozcrt'
     fi
     rm crtdll.obj
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
   esac
 fi # MOZ_MEMORY
 AC_SUBST(MOZ_MEMORY)
 AC_SUBST(MOZ_JEMALLOC3)
 AC_SUBST(MOZ_NATIVE_JEMALLOC)
 AC_SUBST(MOZ_CRT)
 export MOZ_CRT
-AC_SUBST(MOZ_GLUE_LDFLAGS)
-AC_SUBST(MOZ_GLUE_PROGRAM_LDFLAGS)
+AC_SUBST(MOZ_GLUE_IN_PROGRAM)
 AC_SUBST_LIST(WIN32_CRT_LIBS)
 
 dnl We need to wrap dlopen and related functions on Android because we use
 dnl our own linker.
 if test "$OS_TARGET" = Android; then
-    WRAP_LDFLAGS="${WRAP_LDFLAGS} -L$_objdir/dist/lib -lmozglue"
-    WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=PR_GetEnv,--wrap=PR_SetEnv"
+    MOZ_GLUE_WRAP_LDFLAGS="${MOZ_GLUE_WRAP_LDFLAGS} -Wl,--wrap=PR_GetEnv,--wrap=PR_SetEnv"
     if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_NUWA_PROCESS"; then
-        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=pthread_create,--wrap=epoll_wait,--wrap=poll,--wrap=pthread_cond_timedwait,--wrap=__pthread_cond_timedwait,--wrap=pthread_cond_wait,--wrap=epoll_create,--wrap=epoll_ctl,--wrap=close,--wrap=pthread_key_create,--wrap=pthread_key_delete,--wrap=socketpair,--wrap=pthread_self,--wrap=pthread_mutex_lock,--wrap=pthread_join,--wrap=pipe,--wrap=pipe2,--wrap=tgkill"
-    fi
-fi
+        MOZ_GLUE_WRAP_LDFLAGS="${MOZ_GLUE_WRAP_LDFLAGS} -Wl,--wrap=pthread_create,--wrap=epoll_wait,--wrap=poll,--wrap=pthread_cond_timedwait,--wrap=__pthread_cond_timedwait,--wrap=pthread_cond_wait,--wrap=epoll_create,--wrap=epoll_ctl,--wrap=close,--wrap=pthread_key_create,--wrap=pthread_key_delete,--wrap=socketpair,--wrap=pthread_self,--wrap=pthread_mutex_lock,--wrap=pthread_join,--wrap=pipe,--wrap=pipe2,--wrap=tgkill"
+    fi
+fi
+
+AC_SUBST_LIST(MOZ_GLUE_WRAP_LDFLAGS)
+export MOZ_GLUE_WRAP_LDFLAGS
 
 dnl ========================================================
 dnl = Use JS Call tracing
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(trace-jscalls,
 [  --enable-trace-jscalls  Enable JS call enter/exit callback (default=no)],
     MOZ_TRACE_JSCALLS=1,
     MOZ_TRACE_JSCALLS= )
@@ -9292,21 +9278,18 @@ fi
 if test -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then
     ac_configure_args="$ac_configure_args --with-nspr-cflags='$NSPR_CFLAGS'"
     ac_configure_args="$ac_configure_args --with-nspr-libs='$NSPR_LIBS'"
 fi
 ac_configure_args="$ac_configure_args --prefix=$dist"
 if test "$MOZ_MEMORY"; then
    ac_configure_args="$ac_configure_args --enable-jemalloc"
 fi
-if test -n "$MOZ_GLUE_LDFLAGS"; then
-   export MOZ_GLUE_LDFLAGS
-fi
-if test -n "$MOZ_GLUE_PROGRAM_LDFLAGS"; then
-   export MOZ_GLUE_PROGRAM_LDFLAGS
+if test -n "$MOZ_GLUE_IN_PROGRAM"; then
+   export MOZ_GLUE_IN_PROGRAM
 fi
 if test -n "$ZLIB_IN_MOZGLUE"; then
    MOZ_ZLIB_LIBS=
 fi
 export MOZ_NATIVE_ZLIB
 export MOZ_ZLIB_CFLAGS
 export MOZ_ZLIB_LIBS
 export MOZ_APP_NAME
--- a/dom/audiochannel/tests/moz.build
+++ b/dom/audiochannel/tests/moz.build
@@ -1,23 +1,16 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestAudioChannelService',
 ])
 
 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/base/test/moz.build
+++ b/dom/base/test/moz.build
@@ -5,17 +5,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 # FIXME/bug 575918: out-of-process xpcshell is broken on OS X
 if CONFIG['OS_ARCH'] != 'Darwin':
     XPCSHELL_TESTS_MANIFESTS += ['unit_ipc/xpcshell.ini']
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestCSPParser',
     'TestGetURL',
     'TestNativeXMLHttpRequest',
     'TestPlainTextSerializer',
 ])
 
 MOCHITEST_MANIFESTS += [
     'chrome/mochitest.ini',
@@ -33,15 +33,8 @@ if CONFIG['MOZ_CHILD_PERMISSIONS']:
 
 MOCHITEST_CHROME_MANIFESTS += [
     'chrome.ini',
     'chrome/chrome.ini',
     'csp/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/dom/canvas/compiledtest/moz.build
+++ b/dom/canvas/compiledtest/moz.build
@@ -1,22 +1,15 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestWebGLElementArrayCache',
 ])
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '../',
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/dom/media/compiledtest/moz.build
+++ b/dom/media/compiledtest/moz.build
@@ -1,23 +1,16 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestAudioBuffers',
     'TestAudioMixer'
 ])
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/dom/media/webaudio/compiledtest/moz.build
+++ b/dom/media/webaudio/compiledtest/moz.build
@@ -1,22 +1,15 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestAudioEventTimeline',
 ])
 
 FAIL_ON_WARNINGS = True
 
 LOCAL_INCLUDES += [
     '..',
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
deleted file mode 100644
--- a/dom/plugins/ipc/hangui/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/.
-
-MOZ_GLUE_LDFLAGS =
-
-include $(topsrcdir)/config/rules.mk
--- a/editor/txmgr/tests/moz.build
+++ b/editor/txmgr/tests/moz.build
@@ -1,18 +1,11 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestTXMgr',
 ])
 
 FAIL_ON_WARNINGS = True
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/embedding/tests/winEmbed/moz.build
+++ b/embedding/tests/winEmbed/moz.build
@@ -1,26 +1,24 @@
 # -*- 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/.
 
-Program('winEmbed')
+GeckoProgram('winEmbed')
 
 SOURCES += [
     'WebBrowserChrome.cpp',
     'WindowCreator.cpp',
     'winEmbed.cpp',
 ]
 
 XPI_NAME = 'winembed'
 
-DEFINES['XPCOM_GLUE'] = True
-
 RESFILE = 'winEmbed.res'
 
 if CONFIG['GNU_CC']:
     # Get rid of console window
     LDFLAGS += ['-mwindows']
 else:
     # Control the default heap size.
     # This is the heap returned by GetProcessHeap().
@@ -31,17 +29,16 @@ else:
     #
     # Set it to 256k.  See bug 127069.
     LDFLAGS += ['/HEAP:0x40000']
 
 DISABLE_STL_WRAPPING = True
 
 USE_LIBS += [
     'profdirserviceprovidersa_s',
-    'xpcomglue',
 ]
 
 OS_LIBS += [
     'ole32',
     'comdlg32',
     'shell32',
     'version',
 ]
--- a/gfx/angle/src/libEGL/moz.build
+++ b/gfx/angle/src/libEGL/moz.build
@@ -51,12 +51,12 @@ DEFINES['EGLAPI'] = ""
 
 # ANGLE uses the STL, so we can't use our derpy STL wrappers.
 DISABLE_STL_WRAPPING = True
 
 
 LOCAL_INCLUDES += [ '../../include', '../../src' ]
 USE_LIBS += [ 'libGLESv2' ]
 
-SharedLibrary('libEGL')
+GeckoSharedLibrary('libEGL', linkage=None)
 
 RCFILE = SRCDIR + '/libEGL.rc'
 DEFFILE = SRCDIR + '/libEGL.def'
--- a/gfx/angle/src/libGLESv2/moz.build
+++ b/gfx/angle/src/libGLESv2/moz.build
@@ -218,15 +218,15 @@ LOCAL_INCLUDES += [ '../../include', '..
 if CONFIG['MOZ_HAS_WINSDK_WITH_D3D']:
   OS_LIBS += [ 'd3d9', 'dxguid' ]
 else:
   EXTRA_DSO_LDOPTS += [
     '\'%s/lib/%s/d3d9.lib\'' % (CONFIG['MOZ_DIRECTX_SDK_PATH'], CONFIG['MOZ_D3D_CPU_SUFFIX']),
     '\'%s/lib/%s/dxguid.lib\'' % (CONFIG['MOZ_DIRECTX_SDK_PATH'], CONFIG['MOZ_D3D_CPU_SUFFIX']),
   ]
 
-SharedLibrary('libGLESv2')
+GeckoSharedLibrary('libGLESv2', linkage=None)
 
 RCFILE = SRCDIR + '/libGLESv2.rc'
 DEFFILE = SRCDIR + '/libGLESv2.def'
 
 SOURCES['renderer/d3d/HLSLCompiler.cpp'].flags += ['-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES=\'{ TEXT("d3dcompiler_47.dll"), TEXT("d3dcompiler_46.dll"), TEXT("d3dcompiler_43.dll") }\'']
 
--- a/intl/lwbrk/tests/moz.build
+++ b/intl/lwbrk/tests/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestLineBreak',
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/intl/unicharutil/tests/moz.build
+++ b/intl/unicharutil/tests/moz.build
@@ -1,30 +1,16 @@
 # -*- 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/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
-SimplePrograms([
+GeckoSimplePrograms([
     'NormalizationTest',
     'UnicharSelfTest',
-])
-
-USE_STATIC_LIBS = True
+], msvcrt='static')
 
 USE_LIBS += [
-    'mozalloc',
-    'nspr',
     'unicharutil_external_s',
-    'xul',
 ]
-
-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
@@ -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/.
 
 ifneq ($(dir $(PROGRAM)),./)
   GENERATED_DIRS = $(dir $(PROGRAM))
 endif
 
-ifeq (android,$(MOZ_WIDGET_TOOLKIT))
-WRAP_LDFLAGS =
-endif
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/ipc/app/moz.build
+++ b/ipc/app/moz.build
@@ -1,21 +1,27 @@
 # -*- 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/.
 
-Program(CONFIG['MOZ_CHILD_PROCESS_NAME'])
-
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    Program(CONFIG['MOZ_CHILD_PROCESS_NAME'])
     SOURCES += [
         'MozillaRuntimeMainAndroid.cpp',
     ]
 else:
+    kwargs = {
+        'linkage': None,
+    }
+    if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_ARCH'] == 'WINNT':
+        kwargs['msvcrt'] = 'static'
+    GeckoProgram(CONFIG['MOZ_CHILD_PROCESS_NAME'], **kwargs)
+
     SOURCES += [
         'MozillaRuntimeMain.cpp',
     ]
     USE_LIBS += [
         'mozalloc',
         'nspr',
         'xul',
     ]
@@ -37,17 +43,16 @@ if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_
     USE_LIBS += [
         'sandbox_staticruntime_s',
     ]
     DELAYLOAD_DLLS += [
         'mozalloc.dll',
         'nss3.dll',
         'xul.dll'
     ]
-    USE_STATIC_LIBS = True
 
 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']]
 
@@ -57,17 +62,17 @@ LDFLAGS += [CONFIG['MOZ_ALLOW_HEAP_EXECU
 #
 # 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']
 
-# Windows builds have dll linkage warnings due to USE_STATIC_LIBS
+# Windows builds have dll linkage warnings due to msvcrt static linkage
 if CONFIG['OS_ARCH'] != 'WINNT':
     FAIL_ON_WARNINGS = True
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     OS_LIBS += [
         'binder',
         'utils',
     ]
--- a/ipc/ipdl/test/cxx/app/moz.build
+++ b/ipc/ipdl/test/cxx/app/moz.build
@@ -1,27 +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/.
 
-Program('ipdlunittest')
+GeckoProgram('ipdlunittest', linkage='dependent')
 
 SOURCES += [
     'TestIPDL.cpp',
 ]
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
 ]
 
 if CONFIG['_MSC_VER']:
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -3108,27 +3108,26 @@ if test "$MOZ_MEMORY"; then
   *-netbsd*)
     AC_DEFINE(MOZ_MEMORY_BSD)
     ;;
   *-solaris*)
     AC_DEFINE(MOZ_MEMORY_SOLARIS)
     ;;
   *-mingw*)
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
-    # the interesting bits will get passed down in MOZ_GLUE_LDFLAGS
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
   esac
 fi
 AC_SUBST(MOZ_MEMORY)
 AC_SUBST(MOZ_CRT)
-AC_SUBST(MOZ_GLUE_LDFLAGS)
-AC_SUBST(MOZ_GLUE_PROGRAM_LDFLAGS)
+AC_SUBST(MOZ_GLUE_IN_PROGRAM)
+AC_SUBST_LIST(MOZ_GLUE_WRAP_LDFLAGS)
 
 dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
     _WRAP_MALLOC= )
--- a/js/src/gdb/moz.build
+++ b/js/src/gdb/moz.build
@@ -1,15 +1,15 @@
 # -*- 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/.
 
-Program('gdb-tests')
+GeckoProgram('gdb-tests', linkage=None)
 
 UNIFIED_SOURCES += [
     'gdb-tests.cpp',
     'tests/test-jsid.cpp',
     'tests/test-JSObject.cpp',
     'tests/test-JSString.cpp',
     'tests/test-JSSymbol.cpp',
     'tests/test-jsval.cpp',
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -1,15 +1,15 @@
 # -*- 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/.
 
-Program('jsapi-tests')
+GeckoProgram('jsapi-tests', linkage=None)
 
 UNIFIED_SOURCES += [
     'selfTest.cpp',
     'testAddPropertyPropcache.cpp',
     'testArgumentsObject.cpp',
     'testArrayBuffer.cpp',
     'testArrayBufferView.cpp',
     'testBindCallable.cpp',
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -435,17 +435,17 @@ HostSimplePrograms([
 # 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.
 
 if CONFIG['JS_SHARED_LIBRARY']:
-    SharedLibrary('js')
+    GeckoSharedLibrary('js', linkage=None)
     SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
     SDK_LIBRARY = True
 else:
     Library('js')
 
 FORCE_STATIC_LIB = True
 STATIC_LIBRARY_NAME = 'js_static'
 
--- a/js/src/shell/moz.build
+++ b/js/src/shell/moz.build
@@ -1,16 +1,16 @@
 # -*- 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'])
+    GeckoProgram(CONFIG['JS_SHELL_NAME'], linkage=None)
     if CONFIG['JS_BUNDLED_EDITLINE']:
         USE_LIBS += ['editline']
     USE_LIBS += ['static:js']
 
 UNIFIED_SOURCES += [
     'js.cpp',
     'jsheaptools.cpp',
     'jsoptparse.cpp',
--- a/js/xpconnect/shell/moz.build
+++ b/js/xpconnect/shell/moz.build
@@ -1,17 +1,17 @@
 # -*- 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/.
 
 FAIL_ON_WARNINGS = True
 
-Program('xpcshell')
+GeckoProgram('xpcshell', linkage='dependent')
 
 SOURCES += [
     'xpcshell.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     SOURCES += [
         'xpcshellMacUtils.mm',
@@ -30,15 +30,8 @@ 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',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/js/xpconnect/tests/moz.build
+++ b/js/xpconnect/tests/moz.build
@@ -9,15 +9,8 @@ TEST_DIRS += [
     'mochitest',
     'chrome',
     'browser',
     'components/native',
     'components/js',
 ]
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/layout/media/moz.build
+++ b/layout/media/moz.build
@@ -1,16 +1,16 @@
 # -*- 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['GKMEDIAS_SHARED_LIBRARY']:
-    SharedLibrary('gkmedias')
+    GeckoSharedLibrary('gkmedias', linkage=None)
     USE_LIBS += [
         'mozalloc',
         'nspr',
     ]
 else:
     Library('gkmedias')
 
 
--- a/media/gmp-clearkey/0.1/Makefile.in
+++ b/media/gmp-clearkey/0.1/Makefile.in
@@ -4,12 +4,8 @@
 
 INSTALL_TARGETS += CLEARKEY_CDM
 
 CLEARKEY_CDM_DEST = $(DEPTH)/dist/bin/gmp-clearkey/0.1
 CLEARKEY_CDM_FILES = \
   $(SHARED_LIBRARY) \
   clearkey.info \
   $(NULL)
-
-MOZ_GLUE_LDFLAGS =
-
-include $(topsrcdir)/config/rules.mk
--- a/media/libcubeb/tests/moz.build
+++ b/media/libcubeb/tests/moz.build
@@ -1,20 +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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
   'test_tone'
 ])
 
 if CONFIG['OS_TARGET'] != 'Android':
-  CppUnitTests([
+  GeckoCppUnitTests([
     'test_audio',
     'test_latency',
     'test_sanity'
   ])
 
 LOCAL_INCLUDES += [
     '../include'
 ]
@@ -39,23 +39,16 @@ else:
         'cubeb',
     ]
     # 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',
     ]
 elif CONFIG['OS_TARGET'] == 'OpenBSD':
     OS_LIBS += [
         'sndio',
--- a/media/mtransport/test/moz.build
+++ b/media/mtransport/test/moz.build
@@ -1,35 +1,35 @@
 # -*- 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['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
-    CppUnitTests([
+    GeckoCppUnitTests([
         'buffered_stun_socket_unittest',
         'nrappkit_unittest',
         'rlogringbuffer_unittest',
         'runnable_utils_unittest',
         'simpletokenbucket_unittest',
         'sockettransportservice_unittest',
         'TestSyncRunnable',
         'transport_unittests',
         'turn_unittest',
     ])
 
     # Bug 1037618 - Cross-tree (network related?) failures on OSX
     if CONFIG['OS_TARGET'] != 'Darwin':
-        CppUnitTests([
+        GeckoCppUnitTests([
             'ice_unittest',
         ])
 
     if CONFIG['MOZ_SCTP']:
-        CppUnitTests([
+        GeckoCppUnitTests([
             'sctp_unittest',
         ])
 
 FAIL_ON_WARNINGS = True
 
 for var in ('HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR', 'SCTP_DEBUG', 'INET'):
     DEFINES[var] = True
 
@@ -83,24 +83,20 @@ LOCAL_INCLUDES += [
     '/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',
-    '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',
     ]
 
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -1,16 +1,16 @@
 # -*- 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['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
-    CppUnitTests([
+    GeckoCppUnitTests([
         'mediaconduit_unittests',
         'mediapipeline_unittest',
         'sdp_unittests',
         'signaling_unittests',
     ])
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
@@ -89,24 +89,20 @@ if CONFIG['OS_TARGET'] in ('DragonFly', 
         '/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',
-    'nspr',
     'nss',
     'webrtc',
-    'xpcomglue_s',
-    'xul',
     'yuv',
     'zlib',
 ]
 
 if CONFIG['BUILD_ARM_NEON']:
     USE_LIBS += [
         'yuv_neon',
     ]
--- a/memory/build/Makefile.in
+++ b/memory/build/Makefile.in
@@ -1,8 +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
+ifdef MOZ_GLUE_IN_PROGRAM
 DIST_INSTALL = 1
 endif
--- a/memory/build/moz.build
+++ b/memory/build/moz.build
@@ -43,17 +43,17 @@ if CONFIG['MOZ_JEMALLOC3']:
         USE_LIBS += [
             'jemalloc',
         ]
 else:
     USE_LIBS += [
         'mozjemalloc',
     ]
 
-if CONFIG['MOZ_GLUE_PROGRAM_LDFLAGS']:
+if CONFIG['MOZ_GLUE_IN_PROGRAM']:
     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'
 
 if CONFIG['MOZ_REPLACE_MALLOC'] and CONFIG['OS_TARGET'] == 'Darwin':
--- a/memory/build/replace_malloc.h
+++ b/memory/build/replace_malloc.h
@@ -46,20 +46,17 @@
  *
  * They don't all need to be provided.
  *
  * Building a replace-malloc library is like rocket science. It can end up
  * with things blowing up, especially when trying to use complex types, and
  * even more especially when these types come from XPCOM or other parts of the
  * Mozilla codebase.
  * It is recommended to add the following to a replace-malloc implementation's
- * Makefile.in:
- *   MOZ_GLUE_LDFLAGS = # Don't link against mozglue
- *   WRAP_LDFLAGS = # Never wrap malloc function calls with -Wl,--wrap
- * and the following to the implementation's moz.build:
+ * moz.build:
  *   DISABLE_STL_WRAPPING = True # Avoid STL wrapping
  *
  * If your replace-malloc implementation lives under memory/replace, these
  * are taken care of by memory/replace/defs.mk.
  */
 
 /* Implementing a replace-malloc library is incompatible with using mozalloc. */
 #define MOZ_NO_MOZALLOC 1
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -1,13 +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/.
 
-ifdef MOZ_GLUE_PROGRAM_LDFLAGS
+ifdef MOZ_GLUE_IN_PROGRAM
 DIST_INSTALL = 1
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef GNU_CC
 CFLAGS += -std=gnu99
 endif
--- a/memory/jemalloc/moz.build
+++ b/memory/jemalloc/moz.build
@@ -35,17 +35,17 @@ if CONFIG['OS_TARGET'] == 'Darwin' and n
     SOURCES += [
         'src/src/zone.c',
     ]
 
 Library('jemalloc')
 
 FORCE_STATIC_LIB = True
 
-if CONFIG['MOZ_GLUE_PROGRAM_LDFLAGS']:
+if CONFIG['MOZ_GLUE_IN_PROGRAM']:
     SDK_LIBRARY = True
 
 if CONFIG['_MSC_VER']:
     DEFINES['DLLEXPORT'] = True
     LOCAL_INCLUDES += ['src/include/msvc_compat']
     if not CONFIG['HAVE_INTTYPES_H']:
         LOCAL_INCLUDES += ['src/include/msvc_compat/C99']
 
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -55,17 +55,17 @@ elif CONFIG['OS_TARGET'] == 'WINNT':
 else:
     UNIFIED_SOURCES += [
         'VolatileBufferFallback.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     Library('mozalloc')
 else:
-    SharedLibrary('mozalloc')
+    GeckoSharedLibrary('mozalloc', linkage=None)
     SDK_LIBRARY = True
 
 # The strndup declaration in string.h is in an ifdef __USE_GNU section
 DEFINES['_GNU_SOURCE'] = True
 
 TEST_DIRS += ['tests']
 
 GENERATED_INCLUDES += ['/xpcom']
--- a/memory/mozalloc/tests/moz.build
+++ b/memory/mozalloc/tests/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestVolatileBuffer',
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
deleted file mode 100644
--- a/memory/replace/dmd/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/.
-
-# Disable mozglue.
-WRAP_LDFLAGS 	=
-MOZ_GLUE_LDFLAGS=
deleted file mode 100644
--- a/memory/replace/dummy/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/.
-
-MOZ_GLUE_LDFLAGS = # Don't link against mozglue
-WRAP_LDFLAGS = # Never wrap malloc function calls with -Wl,--wrap
deleted file mode 100644
--- a/memory/replace/jemalloc/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/.
-
-MOZ_GLUE_LDFLAGS = # Don't link against mozglue
-WRAP_LDFLAGS = # Never wrap malloc function calls with -Wl,--wrap
--- a/memory/replace/logalloc/Makefile.in
+++ b/memory/replace/logalloc/Makefile.in
@@ -1,10 +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/.
 
-# Disable mozglue.
-WRAP_LDFLAGS 	=
-MOZ_GLUE_LDFLAGS=
-
 # Avoid Lock_impl code depending on mozilla::Logger
 MOZ_DEBUG_ENABLE_DEFS=
--- a/memory/replace/logalloc/replay/Makefile.in
+++ b/memory/replace/logalloc/replay/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/.
 
-# Disable mozglue.
-WRAP_LDFLAGS 	=
-MOZ_GLUE_LDFLAGS=
-MOZ_GLUE_PROGRAM_LDFLAGS=
-
 include $(topsrcdir)/mozglue/build/replace_malloc.mk
 
 ifndef CROSS_COMPILE
 
 ifeq ($(OS_TARGET),WINNT)
 LOGALLOC = MOZ_REPLACE_MALLOC_LIB=$(CURDIR)/../logalloc.dll
 else
 ifeq ($(OS_TARGET),Darwin)
deleted file mode 100644
--- a/mfbt/tests/Makefile.in
+++ /dev/null
@@ -1,12 +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/.
-
-# 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=
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -3,20 +3,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/.
 
 # The mar executable is output into dist/host/bin since it is something that
 # would only be used by our build system and should not itself be included in a
 # Mozilla distribution.
 
-# Don't link the against libmozglue because we don't need it.
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
-
 HOST_CFLAGS += \
   -DNO_SIGN_VERIFY \
   $(DEFINES) \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef CROSS_COMPILE
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -3,18 +3,16 @@
 # 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/.
 
 DIST_INSTALL = 1
 
 # For FORCE_SHARED_LIB
 include $(topsrcdir)/config/config.mk
 
-MOZ_GLUE_LDFLAGS = # Don't link against ourselves
-
 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
 
 ifdef MOZ_CRT
 # Don't install the import library if we use mozcrt
@@ -26,12 +24,8 @@ endif
 include $(topsrcdir)/mozglue/build/replace_malloc.mk
 
 ifdef MOZ_LINKER
 ifeq (arm, $(TARGET_CPU))
 OS_LDFLAGS += -Wl,-version-script,$(srcdir)/arm-eabi-filter
 endif
 
 endif
-
-ifeq (Android, $(OS_TARGET))
-WRAP_LDFLAGS := $(filter -Wl%,$(WRAP_LDFLAGS))
-endif
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -78,8 +78,10 @@ if CONFIG['MOZ_LINKER']:
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     SOURCES += [
         'cpuacct.c',
     ]
 
 DEFINES['IMPL_MFBT'] = True
+
+LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
--- a/mozglue/linker/tests/Makefile.in
+++ b/mozglue/linker/tests/Makefile.in
@@ -1,16 +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/.
 
-ifdef MOZ_LINKER
-# Only link against the linker, not mozglue
-MOZ_GLUE_PROGRAM_LDFLAGS =
-MOZ_GLUE_LDFLAGS =
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_LINKER
 check::
 	@$(EXIT_ON_ERROR) ./TestZip$(BIN_SUFFIX) $(srcdir)
 endif
--- a/mozglue/tests/moz.build
+++ b/mozglue/tests/moz.build
@@ -1,11 +1,11 @@
 # -*- 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/.
 
 DISABLE_STL_WRAPPING = True
 
-CppUnitTests([
+GeckoCppUnitTests([
     'ShowSSEConfig',
-])
+], linkage=None)
--- a/netwerk/streamconv/test/moz.build
+++ b/netwerk/streamconv/test/moz.build
@@ -1,28 +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/.
 
-Program('TestStreamConv')
+GeckoProgram('TestStreamConv', linkage='dependent')
 
 UNIFIED_SOURCES += [
     'Converters.cpp',
     'TestStreamConv.cpp',
 ]
 
 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',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/netwerk/test/moz.build
+++ b/netwerk/test/moz.build
@@ -11,17 +11,17 @@ FAIL_ON_WARNINGS = True
 BROWSER_CHROME_MANIFESTS += ['browser/browser.ini']
 MOCHITEST_MANIFESTS += ['mochitests/mochitest.ini']
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
 # FIXME/bug 575918: out-of-process xpcshell is broken on OS X
 if CONFIG['OS_ARCH'] != 'Darwin':
     XPCSHELL_TESTS_MANIFESTS += ['unit_ipc/xpcshell.ini']
 
-SimplePrograms([
+GeckoSimplePrograms([
     'PropertiesTest',
     'ReadNTLM',
     'TestBlockingSocket',
     'TestCallbacks',
     'TestDNS',
     'TestIncrementalDownload',
     'TestOpen',
     'TestPageLoad',
@@ -53,16 +53,9 @@ CppUnitTests([
     'TestUDPSocket',
 ])
 
 RESOURCE_FILES += [
     'urlparse.dat',
     'urlparse_unx.dat',
 ]
 
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
-
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -1149,32 +1149,16 @@ INSTALL_TARGETS += %(prefix)s
         def pretty_relpath(lib):
             return '$(DEPTH)/%s' % mozpath.relpath(lib.objdir, topobjdir)
 
         topobjdir = mozpath.normsep(obj.topobjdir)
         # This will create the node even if there aren't any linked libraries.
         build_target = self._build_target_for_obj(obj)
         self._compile_graph[build_target]
 
-        # Until MOZ_GLUE_LDFLAGS/MOZ_GLUE_PROGRAM_LDFLAGS are properly
-        # handled in moz.build world, assume any program or shared library
-        # we build depends on it.
-        if obj.KIND == 'target' and not isinstance(obj, StaticLibrary) and \
-                build_target not in ('mozglue/build/target',
-                                     'mozglue/crt/target') and \
-                not obj.config.substs.get('JS_STANDALONE') and \
-                (not isinstance(obj, SharedLibrary) or
-                 obj.basename != 'clang-plugin'):
-            if obj.config.substs.get('MOZ_CRT'):
-                self._compile_graph[build_target].add('mozglue/crt/target')
-            else:
-                self._compile_graph[build_target].add('mozglue/build/target')
-            if obj.config.substs.get('MOZ_MEMORY'):
-                self._compile_graph[build_target].add('memory/build/target')
-
         for lib in obj.linked_libraries:
             if not isinstance(lib, ExternalLibrary):
                 self._compile_graph[build_target].add(
                     self._build_target_for_obj(lib))
             relpath = pretty_relpath(lib)
             if isinstance(obj, Library):
                 if isinstance(lib, StaticLibrary):
                     backend_file.write_once('STATIC_LIBS += %s/%s\n'
--- a/rdf/tests/rdfcat/moz.build
+++ b/rdf/tests/rdfcat/moz.build
@@ -1,20 +1,13 @@
 # -*- 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/.
 
-Program('rdfcat')
+GeckoProgram('rdfcat', linkage='dependent')
 
 SOURCES += [
     'rdfcat.cpp',
 ]
 
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
-
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/rdf/tests/rdfpoll/moz.build
+++ b/rdf/tests/rdfpoll/moz.build
@@ -1,18 +1,11 @@
 # -*- 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/.
 
-Program('rdfpoll')
+GeckoProgram('rdfpoll', linkage='dependent')
 
 SOURCES += [
     'rdfpoll.cpp',
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/rdf/tests/triplescat/moz.build
+++ b/rdf/tests/triplescat/moz.build
@@ -1,20 +1,13 @@
 # -*- 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/.
 
-Program('triplescat')
+GeckoProgram('triplescat', linkage='dependent')
 
 SOURCES += [
     'triplescat.cpp',
 ]
 
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
-
 CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/security/manager/ssl/tests/compiled/moz.build
+++ b/security/manager/ssl/tests/compiled/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
   'TestCertDB',
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
+++ b/security/manager/ssl/tests/unit/tlsserver/cmd/moz.build
@@ -1,22 +1,22 @@
 # -*- 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/.
 
 FAIL_ON_WARNINGS = True
 
-SimplePrograms([
+GeckoSimplePrograms([
     'BadCertServer',
     'ClientAuthServer',
     'GenerateOCSPResponse',
     'OCSPStaplingServer',
-])
+], linkage=None)
 
 LOCAL_INCLUDES += [
     '../lib',
 ]
 
 USE_LIBS += [
     'mozalloc',
     'mozillapkix',
deleted file mode 100644
--- a/security/sandbox/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/.
-
-ifeq ($(OS_ARCH),WINNT)
-MOZ_GLUE_LDFLAGS =
-endif
-
-include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ /dev/null
@@ -1,5 +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/.
-#
-MOZ_GLUE_LDFLAGS =
--- a/startupcache/test/moz.build
+++ b/startupcache/test/moz.build
@@ -1,21 +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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestStartupCache',
 ])
 
 EXTRA_COMPONENTS += [
     'TestStartupCacheTelemetry.js',
     'TestStartupCacheTelemetry.manifest',
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/storage/test/moz.build
+++ b/storage/test/moz.build
@@ -1,17 +1,17 @@
 # -*- 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/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
-CppUnitTests([
+GeckoCppUnitTests([
     'test_AsXXX_helpers',
     'test_async_callbacks_with_spun_event_loops',
     'test_asyncStatementExecution_transaction',
     'test_binding_params',
     'test_file_perms',
     'test_mutex',
     'test_service_init_background_thread',
     'test_statement_scoper',
@@ -19,25 +19,21 @@ CppUnitTests([
     'test_transaction_helper',
     'test_true_async',
     'test_unlock_notify',
 ])
 
 if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT', 'Darwin'):
     # FIXME bug 523392: test_deadlock_detector doesn't like Windows
     # FIXME bug 523378: also fails on OS X
-    CppUnitTests([
+    GeckoCppUnitTests([
         'test_deadlock_detector',
     ])
 
 LOCAL_INCLUDES += [
     '../src',
 ]
 
 FAIL_ON_WARNINGS = True
 
 USE_LIBS += [
-    'mozalloc',
-    'nspr',
     'sqlite',
-    'xpcomglue_s',
-    'xul',
 ]
--- a/testing/mochitest/ssltunnel/moz.build
+++ b/testing/mochitest/ssltunnel/moz.build
@@ -1,15 +1,15 @@
 # -*- 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/.
 
-Program('ssltunnel')
+GeckoProgram('ssltunnel', linkage=None)
 
 SOURCES += [
     'ssltunnel.cpp',
 ]
 
 USE_LIBS += [
     'mozalloc',
     'nspr',
deleted file mode 100644
--- a/testing/tools/screenshot/Makefile.in
+++ /dev/null
@@ -1,5 +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/.
-
-MOZ_GLUE_PROGRAM_LDFLAGS =
--- a/toolkit/components/ctypes/tests/Makefile.in
+++ b/toolkit/components/ctypes/tests/Makefile.in
@@ -4,10 +4,8 @@
 
 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
-
-MOZ_GLUE_LDFLAGS =
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -1,19 +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/.
 
 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 =
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/toolkit/components/places/tests/cpp/moz.build
+++ b/toolkit/components/places/tests/cpp/moz.build
@@ -1,23 +1,16 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'test_IHistory',
 ])
 
 FAIL_ON_WARNINGS = True
 
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
-
 if CONFIG['JS_SHARED_LIBRARY']:
     USE_LIBS += [
         'js',
     ]
deleted file mode 100644
--- a/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
+++ /dev/null
@@ -1,5 +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/.
-
-MOZ_GLUE_LDFLAGS =
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -1,19 +1,15 @@
 # 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/.
 
 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)
 MOZ_WINCONSOLE = 0
 endif
 
 ifdef MOZ_WIDGET_GTK
 OS_CXXFLAGS += $(TK_CFLAGS) $(MOZ_GTHREAD_CFLAGS)
deleted file mode 100644
--- a/toolkit/crashreporter/injector/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/.
-
-MOZ_GLUE_LDFLAGS =
-
-include $(topsrcdir)/config/rules.mk
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -12,17 +12,17 @@ UNIFIED_SOURCES += [
     '../google-breakpad/src/common/logging.cc',
     '../google-breakpad/src/common/pathname_stripper.cc',
     '../google-breakpad/src/processor/basic_code_modules.cc',
     '../google-breakpad/src/processor/minidump.cc',
     'dumputils.cpp',
     'nsTestCrasher.cpp',
 ]
 
-SharedLibrary('testcrasher')
+GeckoSharedLibrary('testcrasher')
 
 EXTRA_JS_MODULES += [
     'CrashTestUtils.jsm',
 ]
 
 DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
     CONFIG['DLL_PREFIX'],
     LIBRARY_NAME,
@@ -31,15 +31,8 @@ DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
 
 DEFINES['NOMINMAX'] = True
 
 LOCAL_INCLUDES += [
     '../google-breakpad/src/',
 ]
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -6,20 +6,20 @@
 
 @template
 def Libxul(name):
     MSVC_ENABLE_PGO = True
 
     if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
         # This is going to be a framework named "XUL", not an ordinary library named
         # "libxul.dylib"
-        Framework(name)
+        GeckoFramework(name, linkage=None)
         SHARED_LIBRARY_NAME = 'XUL'
     else:
-        SharedLibrary(name)
+        GeckoSharedLibrary(name, linkage=None)
         SHARED_LIBRARY_NAME = 'xul'
 
     DELAYLOAD_DLLS += [
         'comdlg32.dll',
         'dbghelp.dll',
         'psapi.dll',
         'rasapi32.dll',
         'rasdlg.dll',
--- a/toolkit/mozapps/update/tests/Makefile.in
+++ b/toolkit/mozapps/update/tests/Makefile.in
@@ -55,18 +55,16 @@ chrome-data_DEST    := $(CHROMETESTROOT)
 chrome-data_FILES   := $(addprefix $(srcdir)/data/,$(_CHROME_DATA))
 
 INI_TEST_FILES = \
   TestAUSReadStrings1.ini \
   TestAUSReadStrings2.ini \
   TestAUSReadStrings3.ini \
   $(NULL)
 
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
 MOZ_WINCONSOLE = 1
 
 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/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -1,22 +1,13 @@
 # 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/.
 
-# Don't link the updater against libmozglue. See bug 687139
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) #{
-# clear out all the --wrap flags and remove dependency on mozglue for Gonk
-WRAP_LDFLAGS :=
-endif #}
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/toolkit/webapps/tests/Makefile.in
+++ b/toolkit/webapps/tests/Makefile.in
@@ -1,12 +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/.
 
 PROGRAMS_DEST = $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
-
-include $(topsrcdir)/config/rules.mk
-
-# 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 =
--- a/tools/trace-malloc/moz.build
+++ b/tools/trace-malloc/moz.build
@@ -19,23 +19,16 @@ SOURCES += [
     'tmreader.c',
 ]
 
 SimplePrograms([
     'leakstats',
     'tmstats',
 ], ext='.c')
 
-SimplePrograms([
+GeckoSimplePrograms([
     'bloatblame',
     'leaksoup',
 ])
 
 RESOURCE_FILES += [
     'spacetrace.css'
 ]
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/uriloader/exthandler/tests/moz.build
+++ b/uriloader/exthandler/tests/moz.build
@@ -11,15 +11,15 @@ XPCSHELL_TESTS_MANIFESTS += ['unit/xpcsh
 
 #FIXME/bug 575918: out-of-process xpcshell is broken on OS X
 if CONFIG['OS_ARCH'] != 'Darwin':
     # The encoding test is already implemented in the Downloads API by a set of
     # test cases with the string "content_encoding" in their names.
     if not CONFIG['MOZ_JSDOWNLOADS']:
         XPCSHELL_TESTS_MANIFESTS += ['unit_ipc/xpcshell.ini']
 
-SimplePrograms([
+GeckoSimplePrograms([
     'WriteArgument',
-])
+], linkage=None)
 
 USE_LIBS += [
     'nspr',
 ]
--- a/webapprt/gtk/moz.build
+++ b/webapprt/gtk/moz.build
@@ -1,32 +1,28 @@
 # -*- 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/.
 
-Program('webapprt-stub')
+# mozglue is statically linked into GeckoPrograms on gtk builds, so
+# we can use GeckoProgram, contrary to other platforms.
+GeckoProgram('webapprt-stub')
 
 SOURCES += [
     'webapprt.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
-DEFINES['XPCOM_GLUE'] = True
-
 GENERATED_INCLUDES += ['/build']
 LOCAL_INCLUDES += [
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
 ]
 
-USE_LIBS += [
-    'xpcomglue',
-]
-
 DISABLE_STL_WRAPPING = True
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
 
 OS_LIBS += CONFIG['TK_LIBS']
--- a/webapprt/mac/Makefile.in
+++ b/webapprt/mac/Makefile.in
@@ -1,21 +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/.
 
 # This switches $(INSTALL) to copy mode, like $(SYSINSTALL), so things that
 # 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 =
-
 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
@@ -1,14 +1,17 @@
 # -*- 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/.
 
+# Can't use GeckoProgram, because we don't want to create a dependency on
+# mozglue, which is impossible (difficult?) to dynamically link into our
+# executable, as we copy it to arbitrary locations.
 Program('webapprt-stub')
 
 SOURCES += [
     'webapprt.mm',
 ]
 
 DEFINES['XPCOM_GLUE'] = True
 
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/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/.
 
-# 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 =
-
 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
@@ -1,14 +1,17 @@
 # -*- 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/.
 
+# Can't use GeckoProgram, because we don't want to create a dependency on
+# mozglue, which is impossible (difficult?) to dynamically link into our
+# executable, as we copy it to arbitrary locations.
 Program('webapprt-stub')
 
 SOURCES += [
     'webapprt.cpp',
 ]
 
 DEFINES['XPCOM_GLUE'] = True
 if CONFIG['DEBUG']:
--- a/widget/tests/moz.build
+++ b/widget/tests/moz.build
@@ -3,30 +3,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/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestAppShellSteadyState',
 ])
 
 FAIL_ON_WARNINGS = True
 
 # if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
 #     if CONFIG['NS_ENABLE_TSF']:
 #         Test disabled because it uses the internal string APIs incorrectly
 #         (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']
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/xpcom/reflect/xptcall/tests/moz.build
+++ b/xpcom/reflect/xptcall/tests/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-SimplePrograms([
+GeckoSimplePrograms([
     'TestXPTCInvoke',
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/xpcom/reflect/xptinfo/tests/moz.build
+++ b/xpcom/reflect/xptinfo/tests/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-SimplePrograms([
+GeckoSimplePrograms([
     'TestInterfaceInfo'
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/xpcom/sample/program/moz.build
+++ b/xpcom/sample/program/moz.build
@@ -1,26 +1,15 @@
 # -*- 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/.
 
-# SIMPLE_PROGRAMS compiles a single .cpp file into an executable
-SimplePrograms([
+# GeckoSimplePrograms compiles a single .cpp file into an executable
+# depending on Gecko with standalone linkage.
+GeckoSimplePrograms([
     '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',
-]
+], linkage='standalone')
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/external/moz.build
+++ b/xpcom/tests/external/moz.build
@@ -1,16 +1,9 @@
 # -*- 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/.
 
-SimplePrograms([
+GeckoSimplePrograms([
     'TestMinStringAPI',
 ])
-
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
--- a/xpcom/tests/moz.build
+++ b/xpcom/tests/moz.build
@@ -34,28 +34,28 @@ SimplePrograms([
     'TestRacingServiceManager',
     'TestRegistrationOrder',
     'TestThreadPoolListener',
     'TestTimers',
     'TestUnicodeArguments',
 ])
 
 if CONFIG['OS_TARGET'] == 'WINNT':
-    SimplePrograms([
+    GeckoSimplePrograms([
         'TestBase64',
     ])
 
 if CONFIG['WRAP_STL_INCLUDES'] and not CONFIG['CLANG_CL']:
-    SimplePrograms([
+    GeckoSimplePrograms([
         'TestSTLWrappers',
     ])
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 
-CppUnitTests([
+GeckoCppUnitTests([
     'ShowAlignments',
     'TestAutoPtr',
     'TestAutoRef',
     'TestCOMArray',
     'TestCOMPtr',
     'TestCOMPtrEq',
     'TestDeque',
     'TestFile',
@@ -68,17 +68,17 @@ CppUnitTests([
     'TestPLDHash',
     'TestStringAPI',
     'TestTArray',
     'TestTextFormatter',
     'TestThreadUtils'
 ])
 
 if CONFIG['MOZ_MEMORY']:
-    CppUnitTests([
+    GeckoCppUnitTests([
         'TestJemalloc',
     ])
 
 # XXX Make these tests work in libxul builds.
 #CPP_UNIT_TESTS += [
 #    'TestArray',
 #    'TestCRT',
 #    'TestEncoding',
@@ -100,17 +100,17 @@ if CONFIG['MOZ_MEMORY']:
 # FIXME: bug 577500 TestStaticAtoms fails when run in dist/bin
 #CPP_UNIT_TESTS += [
 #    'TestStaticAtoms',
 #]
 
 if CONFIG['MOZ_DEBUG'] and CONFIG['OS_ARCH'] not in ('WINNT'):
     # FIXME bug 523392: TestDeadlockDetector doesn't like Windows
     # FIXME bug 523378: also fails on OS X
-    CppUnitTests([
+    GeckoCppUnitTests([
         'TestDeadlockDetector',
         'TestDeadlockDetectorScalability',
     ])
 
 XPIDL_MODULE = 'xpcomtest'
 XPIDL_SOURCES += [
     'NotXPCOMTest.idl',
 ]
@@ -118,19 +118,12 @@ XPIDL_SOURCES += [
 LOCAL_INCLUDES += [
     '../ds',
 ]
 
 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
@@ -1,23 +1,16 @@
 # -*- 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/.
 
-CppUnitTests([
+GeckoCppUnitTests([
     'TestCOM',
     'TestNtPathToDosPath',
 ])
 
-USE_LIBS += [
-    'mozalloc',
-    'nspr',
-    'xpcomglue_s',
-    'xul',
-]
-
 OS_LIBS += [
     'rpcrt4',
     'uuid',
     'mpr',
 ]
deleted file mode 100644
--- a/xpcom/typelib/xpt/tests/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/.
-
-MOZ_GLUE_LDFLAGS =
-MOZ_GLUE_PROGRAM_LDFLAGS =
--- a/xulrunner/app/moz.build
+++ b/xulrunner/app/moz.build
@@ -1,24 +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/.
 
 DIRS += ['profile']
 
-Program('xulrunner')
+GeckoProgram('xulrunner')
 
 SOURCES += [
     'nsXULRunnerApp.cpp',
 ]
 
 DEFINES['XULRUNNER_PROGNAME'] = '"xulrunner"'
-DEFINES['XPCOM_GLUE'] = True
 if CONFIG['DEBUG']:
     DEFINES['DEBUG'] = True
 
 LOCAL_INCLUDES += [
     '/toolkit/profile',
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
@@ -48,13 +47,9 @@ if CONFIG['OS_ARCH'] == 'WINNT':
         'uuid',
         'shell32',
         'ole32',
         'oleaut32',
         'version',
         'winspool',
     ]
 
-USE_LIBS += [
-    'xpcomglue',
-]
-
 DISABLE_STL_WRAPPING = True
--- a/xulrunner/stub/Makefile.in
+++ b/xulrunner/stub/Makefile.in
@@ -1,14 +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/.
 
-# Don't create a dependency on mozglue
-MOZ_GLUE_LDFLAGS =
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
--- a/xulrunner/stub/moz.build
+++ b/xulrunner/stub/moz.build
@@ -3,55 +3,47 @@
 # 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/.
 
 # The value of XULRUNNER_STUB_NAME is generated by configure to allow XULRunner
 # apps to override it using the --with-xulrunner-stub-name=<appname> argument.
 # If this configure argument is not present then the default name is
 # 'xulrunner-stub'.
-Program(CONFIG['XULRUNNER_STUB_NAME'])
+
+# We don't want to create a dependency on mozglue.
+# Statically link against the RTL on windows
+GeckoProgram(CONFIG['XULRUNNER_STUB_NAME'], mozglue=None, msvcrt='static')
 
 SOURCES += [
     'nsXULStub.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     FINAL_TARGET = 'dist/XUL.framework/Versions/%(MOZILLA_VERSION)s' % CONFIG
 
 DEFINES['XPCOM_GLUE'] = True
 
 LOCAL_INCLUDES += [
     '/xpcom/base',
     '/xpcom/build',
 ]
 
-
-# Statically link against the RTL on windows
-USE_STATIC_LIBS = True
-
 if CONFIG['OS_ARCH'] == 'WINNT':
     LOCAL_INCLUDES += ['/toolkit/xre']
 
 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',
-    ]
     OS_LIBS += [
         'shell32',
     ]
-else:
-    USE_LIBS += [
-        'xpcomglue',
-    ]
 
 DISABLE_STL_WRAPPING = True
 
 # Need to link with CoreFoundation on Mac
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     OS_LIBS += CONFIG['TK_LIBS']
--- a/xulrunner/tools/redit/moz.build
+++ b/xulrunner/tools/redit/moz.build
@@ -1,19 +1,15 @@
 # -*- 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['OS_ARCH'] == 'WINNT':
-    Program('redit')
+    GeckoProgram('redit')
     SOURCES += [
         'redit.cpp',
     ]
-    for var in ('WIN32_LEAN_AND_MEAN', 'UNICODE', '_UNICODE', 'XPCOM_GLUE'):
+    for var in ('WIN32_LEAN_AND_MEAN', 'UNICODE', '_UNICODE'):
         DEFINES[var] = True
     if CONFIG['GNU_CC']:
         WIN32_EXE_LDFLAGS += ['-municode']
-
-    USE_LIBS += [
-        'xpcomglue',
-    ]