Bug 1045783 - Move most OS_LIBS to moz.build and do some related cleanup. r=mshal
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Aug 2014 07:25:33 +0900
changeset 219696 98614c9969ce8ba59350f978514f60706e18e03b
parent 219695 95cd38a0e6a54b3fc4e0a5969228e84300893fa9
child 219697 2aa5813d28081c066977f1e55b22f4c1104fb348
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs1045783
milestone34.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 1045783 - Move most OS_LIBS to moz.build and do some related cleanup. r=mshal
accessible/interfaces/ia2/Makefile.in
accessible/interfaces/ia2/moz.build
accessible/interfaces/msaa/Makefile.in
accessible/interfaces/msaa/moz.build
b2g/app/Makefile.in
b2g/app/moz.build
browser/app/Makefile.in
browser/app/moz.build
browser/components/build/Makefile.in
browser/components/build/moz.build
browser/metro/shell/commandexecutehandler/Makefile.in
browser/metro/shell/commandexecutehandler/moz.build
browser/metro/shell/linktool/Makefile.in
browser/metro/shell/linktool/moz.build
browser/metro/shell/testing/Makefile.in
browser/metro/shell/testing/moz.build
configure.in
content/media/apple/moz.build
content/media/fmp4/moz.build
dom/plugins/ipc/hangui/Makefile.in
dom/plugins/ipc/hangui/moz.build
dom/plugins/ipc/interpose/moz.build
dom/plugins/test/testplugin/testplugin.mk
dom/plugins/test/testplugin/testplugin.mozbuild
embedding/tests/winEmbed/Makefile.in
embedding/tests/winEmbed/moz.build
extensions/gnomevfs/Makefile.in
extensions/gnomevfs/moz.build
ipc/app/Makefile.in
ipc/app/moz.build
js/src/Makefile.in
js/src/gdb/Makefile.in
js/src/gdb/moz.build
js/src/jsapi-tests/Makefile.in
js/src/jsapi-tests/moz.build
js/src/moz.build
js/src/shell/Makefile.in
js/src/shell/moz.build
layout/media/Makefile.in
layout/media/moz.build
media/libcubeb/tests/Makefile.in
media/libcubeb/tests/moz.build
media/webrtc/signaling/test/Makefile.in
media/webrtc/signaling/test/moz.build
memory/replace/dmd/Makefile.in
memory/replace/dmd/moz.build
modules/libmar/tool/Makefile.in
modules/libmar/tool/moz.build
modules/libmar/verify/moz.build
mozglue/build/Makefile.in
mozglue/build/moz.build
mozglue/linker/tests/Makefile.in
mozglue/linker/tests/moz.build
security/build/Makefile.in
security/build/moz.build
security/sandbox/win/src/sandboxbroker/Makefile.in
security/sandbox/win/src/sandboxbroker/moz.build
storage/test/Makefile.in
storage/test/moz.build
testing/tools/screenshot/Makefile.in
testing/tools/screenshot/moz.build
toolkit/components/maintenanceservice/Makefile.in
toolkit/components/maintenanceservice/moz.build
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/client/moz.build
toolkit/library/libxul.mk
toolkit/library/libxul.mozbuild
toolkit/library/moz.build
toolkit/mozapps/update/tests/Makefile.in
toolkit/mozapps/update/tests/moz.build
toolkit/mozapps/update/updater/Makefile.in
toolkit/mozapps/update/updater/moz.build
toolkit/system/dbus/Makefile.in
toolkit/system/dbus/moz.build
toolkit/system/gnome/Makefile.in
toolkit/system/gnome/moz.build
toolkit/xre/test/win/Makefile.in
toolkit/xre/test/win/moz.build
tools/jprof/Makefile.in
tools/jprof/moz.build
webapprt/gtk/Makefile.in
webapprt/gtk/moz.build
webapprt/win/Makefile.in
webapprt/win/moz.build
widget/gtk/mozgtk/gtk2/Makefile.in
widget/gtk/mozgtk/gtk2/moz.build
widget/gtk/mozgtk/gtk3/Makefile.in
widget/gtk/mozgtk/gtk3/moz.build
widget/xremoteclient/Makefile.in
widget/xremoteclient/moz.build
xpcom/sample/Makefile.in
xpcom/sample/moz.build
xpcom/sample/program/Makefile.in
xpcom/sample/program/moz.build
xpcom/tests/bug656331_component/Makefile.in
xpcom/tests/bug656331_component/moz.build
xpcom/tests/component/Makefile.in
xpcom/tests/component/moz.build
xpcom/tests/component_no_aslr/Makefile.in
xpcom/tests/component_no_aslr/moz.build
xpcom/tests/windows/Makefile.in
xpcom/tests/windows/moz.build
xulrunner/app/Makefile.in
xulrunner/app/moz.build
xulrunner/stub/Makefile.in
xulrunner/stub/moz.build
--- a/accessible/interfaces/ia2/Makefile.in
+++ b/accessible/interfaces/ia2/Makefile.in
@@ -56,18 +56,16 @@ EMBED_MANIFEST_AT = 2
 
 INSTALL_TARGETS += midl
 midl_FILES := $(filter %.h %_i.c,$(MIDL_GENERATED_FILES))
 midl_DEST = $(DIST)/include
 midl_TARGET := export
 
 include $(topsrcdir)/config/rules.mk
 
-OS_LIBS += $(call EXPAND_LIBNAME,uuid kernel32 rpcns4 rpcrt4 ole32 oleaut32)
-
 # generate list of to-be-generated files that are missing
 # but ignore special file dlldata.c
 missing:=$(strip $(foreach onefile,$(strip $(subst dlldata.c,,$(MIDL_GENERATED_FILES))),$(if $(wildcard $(onefile)),,$(onefile))))
 
 missing_base:=$(sort $(basename $(subst _p.c,,$(subst _i.c,,$(missing)))))
 
 $(MIDL_GENERATED_FILES) : midl_done
 
--- a/accessible/interfaces/ia2/moz.build
+++ b/accessible/interfaces/ia2/moz.build
@@ -6,8 +6,17 @@
 
 LIBRARY_NAME = 'IA2Marshal'
 
 FORCE_SHARED_LIB = True
 
 DEFINES['REGISTER_PROXY_DLL'] = True
 
 DEFFILE = SRCDIR + '/IA2Marshal.def'
+
+OS_LIBS += [
+    'uuid',
+    'kernel32',
+    'rpcns4',
+    'rpcrt4',
+    'ole32',
+    'oleaut32',
+]
--- a/accessible/interfaces/msaa/Makefile.in
+++ b/accessible/interfaces/msaa/Makefile.in
@@ -11,18 +11,16 @@ MIDL_GENERATED_FILES = \
 	ISimpleDOMDocument.h \
 	ISimpleDOMDocument_p.c \
 	ISimpleDOMDocument_i.c \
 	ISimpleDOMText.h \
 	ISimpleDOMText_p.c \
 	ISimpleDOMText_i.c \
 	$(NULL)
 
-OS_LIBS += $(call EXPAND_LIBNAME,kernel32 rpcns4 rpcrt4 oleaut32)
-
 $(MIDL_GENERATED_FILES): done_gen
 
 done_gen: ISimpleDOMNode.idl \
           ISimpleDOMDocument.idl \
           ISimpleDOMText.idl
 
 	$(MIDL) $(MIDL_FLAGS) -I $(srcdir) -Oicf $(srcdir)/ISimpleDOMNode.idl
 	$(MIDL) $(MIDL_FLAGS) -Oicf $(srcdir)/ISimpleDOMDocument.idl
--- a/accessible/interfaces/msaa/moz.build
+++ b/accessible/interfaces/msaa/moz.build
@@ -16,8 +16,15 @@ GENERATED_SOURCES += [
     'ISimpleDOMText_p.c',
 ]
 
 FORCE_SHARED_LIB = True
 
 DEFINES['REGISTER_PROXY_DLL'] = True
 
 DEFFILE = SRCDIR + '/AccessibleMarshal.def'
+
+OS_LIBS += [
+    'kernel32',
+    'rpcns4',
+    'rpcrt4',
+    'oleaut32',
+]
--- a/b2g/app/Makefile.in
+++ b/b2g/app/Makefile.in
@@ -2,47 +2,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/.
 
 USE_RCS_MK := 1
 include $(topsrcdir)/config/makefiles/rcs.mk
 
 PREF_JS_EXPORTS = $(srcdir)/b2g.js
 
-ifndef LIBXUL_SDK
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  -lui \
-  -lEGL \
-  -lhardware_legacy \
-  -lhardware \
-  -lcutils \
-  $(MOZ_ZLIB_LIBS) \
-  $(NULL)
-ifeq ($(ANDROID_VERSION),$(findstring $(ANDROID_VERSION),17 18 19))
-OS_LIBS += \
-  -lgui \
-  -lsuspend \
-  $(NULL)
-endif
-endif
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  -lbinder \
-  -lutils \
-  $(NULL)
-endif
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,version)
-endif
-endif #LIBXUL_SDK
-
 UA_UPDATE_FILE = ua-update.json
 
 $(UA_UPDATE_FILE): % : %.in
 	# strip out comment lines, which are not valid in JSON
 	sed -e '/^ *\/\//d' -e '/^ *$$/d' $^ > $@
 
 UA_UPDATE_FILES = $(UA_UPDATE_FILE)
 UA_UPDATE_DEST  = $(FINAL_TARGET)
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -53,13 +53,36 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
         'display',
         'mozpng',
     ]
     if not CONFIG['MOZ_NATIVE_ZLIB']:
         USE_LIBS += [
             'mozz',
         ]
 
+    OS_LIBS += [
+        'ui',
+        'EGL',
+        'hardware_legacy',
+        'hardware',
+        'cutils',
+    ]
+    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+    if CONFIG['ANDROID_VERSION'] in ('17', '18', '19'):
+        OS_LIBS += [
+            'gui',
+            'suspend',
+        ]
+    OS_LIBS += [
+        'binder',
+        'utils',
+    ]
+
 USE_LIBS += [
     'xpcomglue',
 ]
 
 DISABLE_STL_WRAPPING = True
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    OS_LIBS += [
+        'version',
+    ]
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -20,24 +20,16 @@ DEFINES += \
   $(NULL)
 
 ifdef LIBXUL_SDK #{
 PREF_JS_EXPORTS += $(srcdir)/profile/channel-prefs.js
 endif #} LIBXUL_SDK
 
 # Build a binary bootstrapping with XRE_main
 
-ifdef MOZ_LINKER
-OS_LIBS += $(MOZ_ZLIB_LIBS)
-endif
-
-ifdef HAVE_CLOCK_MONOTONIC
-OS_LIBS += $(REALTIME_LIBS)
-endif
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -50,8 +50,14 @@ if CONFIG['OS_ARCH'] == 'WINNT':
 if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
     LDFLAGS += ['/HEAP:0x40000']
 
 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/components/build/Makefile.in
+++ b/browser/components/build/Makefile.in
@@ -1,28 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS	+= $(call EXPAND_LIBNAME,ole32 shell32 shlwapi)
-endif
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,version)
-endif
-
 EXTRA_LIBS += \
 	$(NSPR_LIBS) \
 	$(NULL)
 
-# Mac: Need to link with CoreFoundation for Mac Migrators (PList reading code)
-# GTK2: Need to link with glib for GNOME shell service
-ifneq (,$(filter cocoa gtk2 gtk3,$(MOZ_WIDGET_TOOLKIT)))
-OS_LIBS += \
-  $(TK_LIBS) \
-  $(NULL)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 # Ensure that we don't embed a manifest referencing the CRT.
 EMBED_MANIFEST_AT =
--- a/browser/components/build/moz.build
+++ b/browser/components/build/moz.build
@@ -24,8 +24,21 @@ LOCAL_INCLUDES += [
     '../shell',
 ]
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    OS_LIBS += [
+        'ole32',
+        'shell32',
+        'shlwapi',
+        'version',
+    ]
+
+# Mac: Need to link with CoreFoundation for Mac Migrators (PList reading code)
+# GTK2: Need to link with glib for GNOME shell service
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'gtk2', 'gtk3'):
+    OS_LIBS += CONFIG['TK_LIBS']
--- a/browser/metro/shell/commandexecutehandler/Makefile.in
+++ b/browser/metro/shell/commandexecutehandler/Makefile.in
@@ -4,18 +4,8 @@
 
 include $(topsrcdir)/config/config.mk
 
 DIST_PROGRAM = CommandExecuteHandler$(BIN_SUFFIX)
 
 # Don't link against mozglue.dll
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
-
-OS_LIBS += \
-	kernel32.lib \
-	user32.lib \
-	ole32.lib \
-	shlwapi.lib \
-	propsys.lib \
-	advapi32.lib \
-	wininet.lib \
-	$(NULL)
--- a/browser/metro/shell/commandexecutehandler/moz.build
+++ b/browser/metro/shell/commandexecutehandler/moz.build
@@ -15,8 +15,18 @@ SOURCES += [
 DIST_SUBDIR = ''
 
 for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM'):
     DEFINES[var] = True
 
 NO_PGO = True
 
 RCINCLUDE = 'CommandExecuteHandler.rc'
+
+OS_LIBS += [
+    'kernel32',
+    'user32',
+    'ole32',
+    'shlwapi',
+    'propsys',
+    'advapi32',
+    'wininet',
+]
deleted file mode 100644
--- a/browser/metro/shell/linktool/Makefile.in
+++ /dev/null
@@ -1,14 +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/.
-
-include $(topsrcdir)/config/config.mk
-
-OS_LIBS += \
-	kernel32.lib \
-	user32.lib \
-	ole32.lib \
-	shlwapi.lib \
-	shell32.lib \
-	propsys.lib \
-	$(NULL)
--- a/browser/metro/shell/linktool/moz.build
+++ b/browser/metro/shell/linktool/moz.build
@@ -11,8 +11,17 @@ SOURCES += [
 ]
 
 DIST_SUBDIR = 'metro/install'
 
 for var in ('UNICODE', '_UNICODE'):
     DEFINES[var] = True
 
 NO_PGO = True
+
+OS_LIBS += [
+    'kernel32',
+    'user32',
+    'ole32',
+    'shlwapi',
+    'shell32',
+    'propsys',
+]
--- a/browser/metro/shell/testing/Makefile.in
+++ b/browser/metro/shell/testing/Makefile.in
@@ -1,18 +1,7 @@
 # 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 =
-
-include $(topsrcdir)/config/config.mk
-
-OS_LIBS += \
-	kernel32.lib \
-	user32.lib \
-	ole32.lib \
-	shlwapi.lib \
-	propsys.lib \
-	advapi32.lib \
-	$(NULL)
--- a/browser/metro/shell/testing/moz.build
+++ b/browser/metro/shell/testing/moz.build
@@ -15,8 +15,17 @@ DIST_SUBDIR = ''
 
 for var in ('UNICODE', '_UNICODE'):
     DEFINES[var] = True
 
 NO_PGO = True
 
 # static win runtime linking
 USE_STATIC_LIBS = True
+
+OS_LIBS += [
+    'kernel32',
+    'user32',
+    'ole32',
+    'shlwapi',
+    'propsys',
+    'advapi32',
+]
--- a/configure.in
+++ b/configure.in
@@ -4203,32 +4203,34 @@ cairo-qt)
     MOZ_PDF_PRINTING=1
     AC_DEFINE(QT_NO_KEYWORDS)
     ;;
 
 cairo-cocoa)
     MOZ_WIDGET_TOOLKIT=cocoa
     AC_DEFINE(MOZ_WIDGET_COCOA)
     LDFLAGS="$LDFLAGS -framework Cocoa -lobjc"
-    TK_LIBS='-framework CoreLocation -framework QuartzCore -framework Carbon -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework AddressBook -framework OpenGL'
+    # Use -Wl as a trick to avoid -framework and framework names from
+    # being separated by AC_SUBST_LIST.
+    TK_LIBS='-Wl,-framework,CoreLocation -Wl,-framework,QuartzCore -Wl,-framework,Carbon -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,AddressBook -Wl,-framework,OpenGL'
     TK_CFLAGS="-DNO_X11"
     CFLAGS="$CFLAGS $TK_CFLAGS"
     CXXFLAGS="$CXXFLAGS $TK_CFLAGS"
     MOZ_USER_DIR="Mozilla"
     MOZ_FS_LAYOUT=bundle
     MOZ_WEBGL=1
     MOZ_INSTRUMENT_EVENT_LOOP=1
     ;;
 
 cairo-uikit)
     MOZ_WIDGET_TOOLKIT=uikit
     AC_DEFINE(MOZ_WIDGET_UIKIT)
     LDFLAGS="$LDFLAGS -framework UIKit -lobjc"
     TK_CFLAGS="-DNO_X11"
-    TK_LIBS='-framework Foundation -framework CoreFoundation -framework CoreGraphics -framework CoreText'
+    TK_LIBS='-Wl,-framework,Foundation -Wl,-framework,CoreFoundation -Wl,-framework,CoreGraphics -Wl,-framework,CoreText'
     CFLAGS="$CFLAGS $TK_CFLAGS"
     CXXFLAGS="$CXXFLAGS $TK_CFLAGS"
     MOZ_USER_DIR="Mozilla"
     MOZ_FS_LAYOUT=bundle
     ;;
 
 cairo-android)
     AC_DEFINE(MOZ_WIDGET_ANDROID)
--- a/content/media/apple/moz.build
+++ b/content/media/apple/moz.build
@@ -13,9 +13,9 @@ UNIFIED_SOURCES += [
     'AppleDecoder.cpp',
     'AppleMP3Reader.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'
 
-LDFLAGS += ['-framework AudioToolbox']
+OS_LIBS += ['-framework AudioToolbox']
--- a/content/media/fmp4/moz.build
+++ b/content/media/fmp4/moz.build
@@ -53,17 +53,17 @@ if CONFIG['MOZ_APPLEMEDIA']:
   UNIFIED_SOURCES += [
       'apple/AppleATDecoder.cpp',
       'apple/AppleCMLinker.cpp',
       'apple/AppleDecoderModule.cpp',
       'apple/AppleUtils.cpp',
       'apple/AppleVTDecoder.cpp',
       'apple/AppleVTLinker.cpp',
   ]
-  LDFLAGS += [
+  OS_LIBS += [
       '-framework AudioToolbox',
   ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '../base',
 ]
--- a/dom/plugins/ipc/hangui/Makefile.in
+++ b/dom/plugins/ipc/hangui/Makefile.in
@@ -1,9 +1,7 @@
 # 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/.
 
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32)
-
 MOZ_GLUE_LDFLAGS =
 
 include $(topsrcdir)/config/rules.mk
--- a/dom/plugins/ipc/hangui/moz.build
+++ b/dom/plugins/ipc/hangui/moz.build
@@ -18,8 +18,12 @@ DEFINES['NS_NO_XPCOM'] = True
 DEFINES['_HAS_EXCEPTIONS'] = 0
 
 DISABLE_STL_WRAPPING = True
 
 if CONFIG['GNU_CC']:
     WIN32_EXE_LDFLAGS += ['-municode']
 
 RCINCLUDE = 'HangUIDlg.rc'
+
+OS_LIBS += [
+    'comctl32',
+]
--- a/dom/plugins/ipc/interpose/moz.build
+++ b/dom/plugins/ipc/interpose/moz.build
@@ -9,9 +9,9 @@ LIBRARY_NAME = 'plugin_child_interpose'
 UNIFIED_SOURCES += [ "%s.mm" % (LIBRARY_NAME) ]
 
 UNIFIED_SOURCES += [
     'plugin_child_quirks.mm',
 ]
 
 FORCE_SHARED_LIB = True
 
-EXTRA_DSO_LDOPTS += ['-framework Carbon']
+OS_LIBS += ['-framework Carbon']
--- a/dom/plugins/test/testplugin/testplugin.mk
+++ b/dom/plugins/test/testplugin/testplugin.mk
@@ -1,24 +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/.
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
-include $(topsrcdir)/config/config.mk
-OS_LIBS += \
-                $(MOZ_QT_LIBS) \
-                $(XLDFLAGS) \
-                $(XLIBS)
-endif
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-OS_LIBS  += $(call EXPAND_LIBNAME,msimg32)
-
 # Windows opt builds without PGO break nptest.dll
 MOZ_OPTIMIZE=
 endif
 
 TEST_PLUGIN_FILES = $(SHARED_LIBRARY)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 MAC_PLIST_FILES += $(srcdir)/Info.plist
@@ -27,14 +17,8 @@ TEST_PLUGIN_DEST = $(DIST)/plugins/$(COC
 INSTALL_TARGETS += \
 	TEST_PLUGIN \
 	MAC_PLIST \
 	$(NULL)
 else
 TEST_PLUGIN_DEST = $(DIST)/plugins
 INSTALL_TARGETS += TEST_PLUGIN
 endif
-
-include $(topsrcdir)/config/rules.mk
-
-ifneq (,$(filter gtk2 gtk3,$(MOZ_WIDGET_TOOLKIT)))
-OS_LIBS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS)
-endif
--- a/dom/plugins/test/testplugin/testplugin.mozbuild
+++ b/dom/plugins/test/testplugin/testplugin.mozbuild
@@ -31,16 +31,19 @@ elif toolkit == 'android':
 elif toolkit == 'qt':
     UNIFIED_SOURCES += [
         relative_path + '/nptest_qt.cpp',
     ]
 elif toolkit == 'windows':
     UNIFIED_SOURCES += [
         relative_path + '/nptest_windows.cpp',
     ]
+    OS_LIBS += [
+        'msimg32',
+    ]
 
 FORCE_SHARED_LIB = True
 
 # must link statically with the CRT; nptest isn't Gecko code
 USE_STATIC_LIBS = True
 
 # Don't use STL wrappers; nptest isn't Gecko code
 DISABLE_STL_WRAPPING = True
@@ -51,12 +54,19 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
     DEFFILE = SRCDIR + '/nptest.def'
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa' and '64' in CONFIG['OS_TEST']:
     EXTRA_DSO_LDOPTS += ['-framework Carbon']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'):
     CXXFLAGS += CONFIG['MOZ_GTK2_CFLAGS']
     CFLAGS += CONFIG['MOZ_GTK2_CFLAGS']
+    OS_LIBS += CONFIG['MOZ_GTK2_LIBS']
+    OS_LIBS += CONFIG['XLDFLAGS']
+    OS_LIBS += CONFIG['XLIBS']
+    OS_LIBS += CONFIG['XEXT_LIBS']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
     CXXFLAGS += CONFIG['MOZ_QT_CFLAGS']
     CFLAGS += CONFIG['MOZ_QT_CFLAGS']
+    OS_LIBS += CONFIG['MOZ_QT_LIBS']
+    OS_LIBS += CONFIG['XLDFLAGS']
+    OS_LIBS += CONFIG['XLIBS']
deleted file mode 100644
--- a/embedding/tests/winEmbed/Makefile.in
+++ /dev/null
@@ -1,32 +0,0 @@
-# ***** BEGIN LICENSE BLOCK *****
-# Version: Mozilla-sample-code 1.0
-#
-# Copyright (c) 2002 Netscape Communications Corporation and
-# other contributors
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this Mozilla sample software and associated documentation files
-# (the "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to permit
-# persons to whom the Software is furnished to do so, subject to the
-# following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-# DEALINGS IN THE SOFTWARE.
-#
-# Contributor(s):
-#
-# ***** END LICENSE BLOCK *****
-
-OS_LIBS		+= $(call EXPAND_LIBNAME,ole32 comdlg32 shell32 version)
-
-include $(topsrcdir)/config/rules.mk
--- a/embedding/tests/winEmbed/moz.build
+++ b/embedding/tests/winEmbed/moz.build
@@ -33,8 +33,15 @@ else:
     LDFLAGS += ['/HEAP:0x40000']
 
 DISABLE_STL_WRAPPING = True
 
 USE_LIBS += [
     'profdirserviceprovidersa_s',
     'xpcomglue',
 ]
+
+OS_LIBS += [
+    'ole32',
+    'comdlg32',
+    'shell32',
+    'version',
+]
--- a/extensions/gnomevfs/Makefile.in
+++ b/extensions/gnomevfs/Makefile.in
@@ -1,9 +1,8 @@
 # vim:set ts=8 sw=8 sts=8 noet:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-OS_LIBS += \
+EXTRA_LIBS += \
 		   $(NSPR_LIBS) \
-		   $(MOZ_GNOMEVFS_LIBS) \
 		   $(NULL)
--- a/extensions/gnomevfs/moz.build
+++ b/extensions/gnomevfs/moz.build
@@ -18,8 +18,10 @@ IS_COMPONENT = True
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['MOZ_GNOMEVFS_CFLAGS']
+
+OS_LIBS += CONFIG['MOZ_GNOMEVFS_LIBS']
--- a/ipc/app/Makefile.in
+++ b/ipc/app/Makefile.in
@@ -9,23 +9,16 @@ endif
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 WRAP_LDFLAGS =
 else
 EXTRA_LIBS += \
   $(NSPR_LIBS) \
   $(NULL)
 endif
 
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  -lbinder \
-  -lutils \
-  $(NULL)
-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
@@ -52,8 +52,14 @@ 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']
 
 FAIL_ON_WARNINGS = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    OS_LIBS += [
+        'binder',
+        'utils',
+    ]
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -195,32 +195,20 @@ distclean::
 	$(RM) $(DIST_GARBAGE)
 
 ifneq ($(findstring -L,$(NSPR_LIBS)),)
 NSPR_STATIC_PATH = $(subst -L,,$(findstring -L,$(NSPR_LIBS)))
 else
 NSPR_STATIC_PATH = $(DIST)/lib
 endif
 
-# HP-UX does not require the extra linking of "-lm"
-ifeq (,$(filter HP-UX WINNT,$(OS_ARCH)))
-OS_LIBS	+= -lm
-endif
-
 CFLAGS += $(MOZ_ZLIB_CFLAGS)
-OS_LIBS += $(MOZ_ZLIB_LIBS)
 
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 
-ifeq ($(OS_ARCH),FreeBSD)
-OS_LIBS	+= -pthread
-endif
-ifeq ($(OS_ARCH),Linux)
-OS_LIBS	+= -ldl
-endif
 # Silence warnings on AIX/HP-UX from non-GNU compilers
 ifndef GNU_CC
 ifeq ($(OS_ARCH),AIX)
 # Suppress warnings from xlC
 # 1540-1281: offsetof() on null non-POD types
 # 1540-1608: anonymous unions using static data members
 CFLAGS		+= -qsuppress=1540-1281 -qsuppress=1540-1608
 CXXFLAGS	+= -qsuppress=1540-1281 -qsuppress=1540-1608
@@ -237,17 +225,16 @@ ifeq ($(OS_ARCH),SunOS)
 ifeq ($(TARGET_CPU),sparc)
 
 ifdef GNU_CC
 CFLAGS   += -mcpu=v9
 CXXFLAGS += -mcpu=v9
 endif # GNU_CC
 
 endif
-OS_LIBS	+= -lposix4 -ldl -lnsl -lsocket
 endif
 
 SCRIPTS = $(JS_CONFIG_NAME)
 SDK_BINARY = $(JS_CONFIG_NAME)
 
 $(LIBRARY_NAME).pc: js.pc
 	cp $^ $@
 
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -1,16 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS += $(NSPR_LIBS)
-OS_LIBS +=  $(MOZ_ZLIB_LIBS)
 
 ifdef MOZ_SHARED_ICU
 OS_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 OS_LIBS += $(MOZ_FFI_LIBS)
 
 # Place a GDB Python auto-load file next to the gdb-tests executable, both
--- a/js/src/gdb/moz.build
+++ b/js/src/gdb/moz.build
@@ -24,8 +24,10 @@ for var in ('EXPORT_JS_API', 'IMPL_MFBT'
     DEFINES[var] = True
 
 LOCAL_INCLUDES += ['..']
 GENERATED_INCLUDES += ['..']
 
 USE_LIBS += [
     'static:js',
 ]
+
+OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -1,16 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS      += $(NSPR_LIBS)
-OS_LIBS += $(MOZ_ZLIB_LIBS)
 
 ifdef MOZ_SHARED_ICU
 OS_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 OS_LIBS += $(MOZ_FFI_LIBS)
 
 ifdef QEMU_EXE
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -94,8 +94,10 @@ DEFINES['EXPORT_JS_API'] = True
 DEFINES['IMPL_MFBT'] = True
 
 LOCAL_INCLUDES += ['..']
 GENERATED_INCLUDES += ['..']
 
 USE_LIBS += [
     'static:js',
 ]
+
+OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -476,8 +476,33 @@ if CONFIG['_MSC_VER']:
     # XXX We should add this to CXXFLAGS, too?
     CFLAGS += ['-fp:precise']
 
 # Needed to "configure" it correctly.  Unfortunately these
 # flags wind up being applied to all code in js/src, not just
 # the code in js/src/assembler.
 DEFINES['USE_SYSTEM_MALLOC'] = 1
 DEFINES['ENABLE_ASSEMBLER'] = 1
+
+if CONFIG['OS_ARCH'] not in ('WINNT', 'HP-UX'):
+    OS_LIBS += [
+        'm',
+    ]
+
+OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+
+if CONFIG['OS_ARCH'] == 'FreeBSD':
+    OS_LIBS += [
+        '-pthread',
+    ]
+
+if CONFIG['OS_ARCH'] == 'Linux':
+    OS_LIBS += [
+        'dl',
+    ]
+
+if CONFIG['OS_ARCH'] == 'SunOS':
+    OS_LIBS += [
+        'posix4',
+        'dl',
+        'nsl',
+        'socket',
+    ]
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -1,16 +1,15 @@
 # -*- Mode: makefile -*-
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS      += $(NSPR_LIBS)
-OS_LIBS += $(EDITLINE_LIBS) $(MOZ_ZLIB_LIBS)
 ifdef MOZ_NATIVE_FFI
 OS_LIBS += $(MOZ_FFI_LIBS)
 endif
 ifdef MOZ_SHARED_ICU
 OS_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 ifeq ($(OS_ARCH),Darwin)
--- a/js/src/shell/moz.build
+++ b/js/src/shell/moz.build
@@ -24,8 +24,11 @@ for var in ('EXPORT_JS_API', 'IMPL_MFBT'
 if CONFIG['_MSC_VER']:
     # unnecessary PGO for js shell.  But gcc cannot turn off pgo because it is
     # necessary to link PGO lib on gcc when a object/static lib are compiled
     # for PGO.
     NO_PGO = True
 
 LOCAL_INCLUDES += ['..']
 GENERATED_INCLUDES += ['..']
+
+OS_LIBS += CONFIG['EDITLINE_LIBS']
+OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/layout/media/Makefile.in
+++ b/layout/media/Makefile.in
@@ -1,18 +1,15 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 ifeq (WINNT,$(OS_TARGET))
 EXTRA_LIBS += $(NSPR_LIBS)
-OS_LIBS += $(call EXPAND_LIBNAME,usp10 ole32)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq (WINNT,$(OS_TARGET))
 symbols.def: symbols.def.in $(GLOBAL_DEPS)
 	$(call py_action,preprocessor,$(ACDEFINES) $< -o $@)
-
-OS_LIBS += $(call EXPAND_LIBNAME, msimg32 winmm)
 endif
--- a/layout/media/moz.build
+++ b/layout/media/moz.build
@@ -12,8 +12,14 @@ if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
         'mozalloc',
     ]
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += ['webrtc']
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     DEFFILE = 'symbols.def'
+    OS_LIBS += [
+        'usp10',
+        'ole32',
+        'msimg32',
+        'winmm',
+    ]
deleted file mode 100644
--- a/media/libcubeb/tests/Makefile.in
+++ /dev/null
@@ -1,18 +0,0 @@
-# -*- Mode: makefile; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- #
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ifeq ($(OS_TARGET),Darwin)
-  OS_LDFLAGS += -framework AudioUnit -framework CoreAudio
-else
-  ifeq ($(OS_TARGET), OpenBSD)
-    OS_LIBS += -lsndio
-  else
-    ifeq ($(OS_TARGET),WINNT)
-      OS_LIBS += $(call EXPAND_LIBNAME,ole32)
-    endif
-    OS_LIBS += $(MOZ_ALSA_LIBS) \
-            $(MOZ_PULSEAUDIO_LIBS)
-  endif
-endif
--- a/media/libcubeb/tests/moz.build
+++ b/media/libcubeb/tests/moz.build
@@ -26,16 +26,19 @@ FAIL_ON_WARNINGS = True
 if CONFIG['OS_ARCH'] == 'WINNT':
     # On windows, the WASAPI backend needs the resampler we have in
     # /media/libspeex_resampler, so we can't get away with just linking cubeb's
     # .o
     USE_LIBS += [
         'cubeb',
         'speex',
     ]
+    OS_LIBS += [
+        'ole32'
+    ]
 else:
     # Otherwise, we can just grab all the compiled .o and compile against that,
     # linking the appriopriate libraries.
     USE_LIBS += [
         'cubeb',
     ]
     # Don't link gkmedias for it introduces dependencies on Android.
     if CONFIG['OS_TARGET'] == 'Android':
@@ -43,8 +46,21 @@ else:
             'speex',
         ]
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+if CONFIG['OS_TARGET'] == 'Darwin':
+    OS_LIBS += [
+        '-framework AudioUnit',
+        '-framework CoreAudio',
+    ]
+elif CONFIG['OS_TARGET'] == 'OpenBSD':
+    OS_LIBS += [
+        'sndio',
+    ]
+else:
+    OS_LIBS += CONFIG['MOZ_ALSA_LIBS']
+    OS_LIBS += CONFIG['MOZ_PULSEAUDIO_LIBS']
--- a/media/webrtc/signaling/test/Makefile.in
+++ b/media/webrtc/signaling/test/Makefile.in
@@ -2,88 +2,20 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 EXTRA_LIBS += \
   $(NSPR_LIBS) \
   $(NSS_LIBS) \
   $(NULL)
 
-OS_LIBS += \
-  $(MOZ_WEBRTC_X11_LIBS) \
-  $(REALTIME_LIBS) \
-  $(NULL)
-
-ifdef MOZ_ALSA
-OS_LIBS += \
-  $(MOZ_ALSA_LIBS) \
-  $(NULL)
-endif
-
 ifeq ($(OS_TARGET),Android)
 EXTRA_LIBS += \
   $(STLPORT_LDFLAGS) \
   $(STLPORT_LIBS) \
   $(NULL)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
 endif
 
-ifdef MOZ_NATIVE_JPEG
-OS_LIBS += \
-  $(MOZ_JPEG_LIBS) \
-  $(NULL)
-endif
-
-ifdef MOZ_NATIVE_LIBVPX
-OS_LIBS += \
-  $(MOZ_LIBVPX_LIBS) \
-  $(NULL)
-endif
-
-ifndef MOZ_TREE_PIXMAN
-OS_LIBS += \
-  $(MOZ_PIXMAN_LIBS) \
-  $(NULL)
-endif
-
-ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  $(XLIBS) \
-  $(MOZ_GTK2_LIBS) \
-  -lgmodule-2.0 -lgthread-2.0 \
-  $(NULL)
-endif
-
-ifeq (gtk3,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  $(MOZ_GTK3_LIBS) \
-  $(FT2_LIBS) \
-  $(NULL)
-endif
-
-ifeq (qt,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  $(XLIBS) \
-  $(TK_LIBS) \
-  $(MOZ_PANGO_LIBS) \
-  $(NULL)
-endif
-
-ifneq (,$(filter Linux DragonFly FreeBSD NetBSD OpenBSD,$(OS_TARGET)))
-OS_LIBS += \
-  $(MOZ_CAIRO_OSLIBS) \
-  $(NULL)
-endif
-
-ifeq ($(OS_TARGET),Darwin)
-OS_LIBS += \
-  $(TK_LIBS) \
-  $(NULL)
-endif
-
-ifdef MOZ_NATIVE_ZLIB
-OS_LIBS += $(MOZ_ZLIB_LIBS)
-endif
-
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/media/webrtc/webrtc-config.mk
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -67,17 +67,17 @@ if CONFIG['OS_TARGET'] == 'Linux':
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/linux/include',
     ]
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/darwin/include',
     ]
-    LDFLAGS += [
+    OS_LIBS += [
         '-framework AudioToolbox',
         '-framework AudioUnit',
         '-framework Carbon',
         '-framework CoreAudio',
         '-framework OpenGL',
         '-framework QTKit',
         '-framework QuartzCore',
         '-framework Security',
@@ -116,8 +116,50 @@ if not CONFIG['MOZ_NATIVE_ZLIB'] and not
     USE_LIBS += [
         'mozz',
     ]
 
 if CONFIG['JS_SHARED_LIBRARY']:
     USE_LIBS += [
         'js',
     ]
+
+OS_LIBS += CONFIG['MOZ_WEBRTC_X11_LIBS']
+OS_LIBS += CONFIG['REALTIME_LIBS']
+
+if CONFIG['MOZ_ALSA']:
+    OS_LIBS += CONFIG['MOZ_ALSA_LIBS']
+
+if CONFIG['MOZ_NATIVE_JPEG']:
+    OS_LIBS += CONFIG['MOZ_JPEG_LIBS']
+
+if CONFIG['MOZ_NATIVE_LIBVPX']:
+    OS_LIBS += CONFIG['MOZ_LIBVPX_LIBS']
+
+if not CONFIG['MOZ_TREE_PIXMAN']:
+    OS_LIBS += CONFIG['MOZ_PIXMAN_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2':
+    OS_LIBS += CONFIG['XLIBS']
+    OS_LIBS += CONFIG['MOZ_GTK2_LIBS']
+    OS_LIBS += [
+        'gmodule-2.0',
+        'gthread-2.0',
+    ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
+    OS_LIBS += CONFIG['MOZ_GTK3_LIBS']
+    OS_LIBS += CONFIG['FT2_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
+    OS_LIBS += CONFIG['XLIBS']
+    OS_LIBS += CONFIG['TK_LIBS']
+    OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
+
+if CONFIG['OS_TARGET'] in ('Linux', 'DragonFly', 'FreeBSD', 'NetBSD',
+        'OpenBSD'):
+    OS_LIBS += CONFIG['MOZ_CAIRO_OSLIBS']
+
+if CONFIG['OS_TARGET'] == 'Darwin':
+    OS_LIBS += CONFIG['TK_LIBS']
+
+if CONFIG['MOZ_NATIVE_ZLIB']:
+    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/memory/replace/dmd/Makefile.in
+++ b/memory/replace/dmd/Makefile.in
@@ -1,12 +1,8 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Disable mozglue.
 WRAP_LDFLAGS 	=
 MOZ_GLUE_LDFLAGS=
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS         += $(call EXPAND_LIBNAME,dbghelp)
-endif
--- a/memory/replace/dmd/moz.build
+++ b/memory/replace/dmd/moz.build
@@ -23,8 +23,13 @@ LIBRARY_NAME = 'dmd'
 FORCE_SHARED_LIB = True
 
 DEFINES['MOZ_NO_MOZALLOC'] = True
 
 if CONFIG['MOZ_OPTIMIZE']:
     DEFINES['MOZ_OPTIMIZE'] = True
 
 DISABLE_STL_WRAPPING = True
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    OS_LIBS += [
+        'dbghelp',
+    ]
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -25,21 +25,16 @@ EXTRA_LIBS += \
   $(DIST)/lib/$(LIB_PREFIX)nss3.$(LIB_SUFFIX) \
   $(DIST)/lib/$(LIB_PREFIX)nssutil3.$(LIB_SUFFIX) \
   $(NSPR_LIBS) \
   $(NULL)
 endif
 
 ifeq ($(HOST_OS_ARCH),WINNT)
 HOST_EXTRA_LIBS += $(call EXPAND_LIBNAME,ws2_32)
-OS_LIBS += $(call EXPAND_LIBNAME,ws2_32)
-ifdef MOZ_ENABLE_SIGNMAR
-OS_LIBS += $(call EXPAND_LIBNAME,crypt32)
-OS_LIBS += $(call EXPAND_LIBNAME,advapi32)
-endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef CROSS_COMPILE
 ifdef HOST_NSPR_MDCPUCFG
 HOST_CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
 CFLAGS += -DMDCPUCFG=$(HOST_NSPR_MDCPUCFG)
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -28,12 +28,21 @@ if CONFIG['MOZ_ENABLE_SIGNMAR']:
 for var in ('MAR_CHANNEL_ID', 'MOZ_APP_VERSION'):
     DEFINES[var] = '"%s"' % CONFIG[var]
 
 if not CONFIG['MOZ_ENABLE_SIGNMAR']:
     DEFINES['NO_SIGN_VERIFY'] = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_STATIC_LIBS = True
+
+    OS_LIBS += [
+        'ws2_32',
+    ]
+    if CONFIG['MOZ_ENABLE_SIGNMAR']:
+        OS_LIBS += [
+            'crypt32',
+            'advapi32',
+        ]
 elif CONFIG['OS_ARCH'] == 'Darwin':
-    LDFLAGS += [
+    OS_LIBS += [
       '-framework Security',
     ]
--- a/modules/libmar/verify/moz.build
+++ b/modules/libmar/verify/moz.build
@@ -14,17 +14,17 @@ UNIFIED_SOURCES += [
 FORCE_STATIC_LIB = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_STATIC_LIBS = True
 elif CONFIG['OS_ARCH'] == 'Darwin':
     UNIFIED_SOURCES += [
       'MacVerifyCrypto.cpp',
     ]
-    LDFLAGS += [
+    OS_LIBS += [
       '-framework Security',
     ]
 else:
     DEFINES['MAR_NSS'] = True
     LOCAL_INCLUDES += ['../sign']
 
 LOCAL_INCLUDES += [
     '../src',
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -22,21 +22,16 @@ mozglue.def: mozglue.def.in $(GLOBAL_DEP
 
 GARBAGE += mozglue.def
 
 ifneq (,$(filter -DEFAULTLIB:mozcrt,$(MOZ_GLUE_LDFLAGS)))
 # Don't install the import library if we use mozcrt
 NO_INSTALL_IMPORT_LIBRARY = 1
 endif
 
-
-OS_LIBS += \
-	$(call EXPAND_LIBNAME,version) \
-	$(NULL)
-
 endif
 
 ifeq (Darwin_1,$(OS_TARGET)_$(MOZ_REPLACE_MALLOC))
 OS_LDFLAGS += \
   -Wl,-U,_replace_init \
   -Wl,-U,_replace_malloc \
   -Wl,-U,_replace_posix_memalign \
   -Wl,-U,_replace_aligned_alloc \
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -30,16 +30,19 @@ if CONFIG['OS_TARGET'] == 'Android':
     ]
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     SOURCES += [
         'WindowsDllBlocklist.cpp',
     ]
     DEFFILE = 'mozglue.def'
     DISABLE_STL_WRAPPING = True
+    OS_LIBS += [
+        'version',
+    ]
 
 if CONFIG['MOZ_NUWA_PROCESS']:
     EXPORTS.ipc += [
         'Nuwa.h',
     ]
     SOURCES += [
         'Nuwa.cpp',
     ]
--- a/mozglue/linker/tests/Makefile.in
+++ b/mozglue/linker/tests/Makefile.in
@@ -1,17 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 ifdef MOZ_LINKER
 # Only link against the linker, not mozglue
 MOZ_GLUE_PROGRAM_LDFLAGS =
 MOZ_GLUE_LDFLAGS =
-OS_LIBS = $(MOZ_ZLIB_LIBS)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_LINKER
 check::
 	@$(EXIT_ON_ERROR) ./TestZip$(BIN_SUFFIX) $(srcdir)
 endif
--- a/mozglue/linker/tests/moz.build
+++ b/mozglue/linker/tests/moz.build
@@ -12,8 +12,11 @@ SOURCES += [
 SIMPLE_PROGRAMS += [
     'TestZip',
 ]
 LOCAL_INCLUDES += ['..']
 USE_LIBS += [
     'linker',
 ]
 DISABLE_STL_WRAPPING = True
+
+if CONFIG['MOZ_LINKER']:
+    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
--- a/security/build/Makefile.in
+++ b/security/build/Makefile.in
@@ -365,18 +365,16 @@ endif # MOZ_FOLD_LIBS
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_FOLD_LIBS
 # Force the linker to include everything from the static libraries.
 EXPAND_LIBS_EXEC += --extract
 
 $(SHARED_LIBRARY): $(addprefix ../,$(NSS_STATIC_LIBS))
 
-OS_LIBS += $(REALTIME_LIBS)
-
 ifdef IMPORT_LIB_SUFFIX
 IMPORT_PREFIX = $(LIB_PREFIX)
 IMPORT_SUFFIX = .$(IMPORT_LIB_SUFFIX)
 else
 IMPORT_PREFIX = $(DLL_PREFIX)
 IMPORT_SUFFIX = $(DLL_SUFFIX)
 endif
 
--- a/security/build/moz.build
+++ b/security/build/moz.build
@@ -10,15 +10,17 @@ if CONFIG['MOZ_FOLD_LIBS']:
 
     FORCE_SHARED_LIB = True
     SDK_LIBRARY = True
 
     USE_LIBS += [
         'mozsqlite3',
     ]
 
+    OS_LIBS += CONFIG['REALTIME_LIBS']
+
 if CONFIG['OS_TARGET'] == 'WINNT':
     DEFFILE = 'nss3.def'
 
 if CONFIG['OS_ARCH'] == 'Linux' and \
    CONFIG['MOZ_FOLD_LIBS'] and \
    CONFIG['GCC_USE_GNU_LD']:
     LD_VERSION_SCRIPT = 'nss3.def'
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ b/security/sandbox/win/src/sandboxbroker/Makefile.in
@@ -2,10 +2,8 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 MOZ_GLUE_LDFLAGS =
 
 EXTRA_LIBS += \
 	$(NSPR_LIBS) \
 	$(NULL)
-
-OS_LIBS += $(call EXPAND_LIBNAME,dbghelp)
--- a/security/sandbox/win/src/sandboxbroker/moz.build
+++ b/security/sandbox/win/src/sandboxbroker/moz.build
@@ -26,8 +26,12 @@ for var in ('UNICODE', '_UNICODE', 'NS_N
 
 LOCAL_INCLUDES += [
     '/security',
     '/security/sandbox',
     '/security/sandbox/chromium',
 ]
 
 DISABLE_STL_WRAPPING = True
+
+OS_LIBS += [
+    'dbghelp',
+]
--- a/storage/test/Makefile.in
+++ b/storage/test/Makefile.in
@@ -1,12 +1,8 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS += \
 	$(NSPR_LIBS) \
 	$(NULL)
-
-OS_LIBS += \
-	$(SQLITE_LIBS) \
-	$(NULL)
--- a/storage/test/moz.build
+++ b/storage/test/moz.build
@@ -41,8 +41,10 @@ USE_LIBS += [
     'xpcomglue_s',
     'xul',
 ]
 
 if not CONFIG['MOZ_NATIVE_SQLITE'] and not CONFIG['MOZ_FOLD_LIBS']:
     USE_LIBS += [
         'mozsqlite3',
     ]
+
+OS_LIBS += CONFIG['SQLITE_LIBS']
--- a/testing/tools/screenshot/Makefile.in
+++ b/testing/tools/screenshot/Makefile.in
@@ -1,18 +1,9 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-ifdef MOZ_WIDGET_GTK
-ifdef MOZ_X11
-
-OS_LIBS += $(TK_LIBS) $(XSS_LIBS)
-
-endif # X11
-endif # GTK
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 
-OS_LIBS += $(call EXPAND_LIBNAME,gdiplus)
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
 endif # windows
--- a/testing/tools/screenshot/moz.build
+++ b/testing/tools/screenshot/moz.build
@@ -5,16 +5,21 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['MOZ_WIDGET_GTK'] and CONFIG['MOZ_X11']:
     PROGRAM = 'screentopng'
     SOURCES += [
         'gdk-screenshot.cpp',
     ]
     CXXFLAGS += CONFIG['TK_CFLAGS']
+    OS_LIBS += CONFIG['TK_LIBS']
+    OS_LIBS += CONFIG['XSS_LIBS']
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     PROGRAM = 'screenshot'
     SOURCES += [
         'win32-screenshot.cpp',
     ]
     USE_STATIC_LIBS = True
     if CONFIG['GNU_CC']:
         WIN32_EXE_LDFLAGS += ['-municode']
+    OS_LIBS += [
+        'gdiplus',
+    ]
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -4,18 +4,16 @@
 
 DIST_PROGRAM = maintenanceservice$(BIN_SUFFIX)
 
 # Don't link the maintenanceservice against mozglue.dll. See bug 687139 and
 # bug 725876
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32)
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/toolkit/components/maintenanceservice/moz.build
+++ b/toolkit/components/maintenanceservice/moz.build
@@ -40,8 +40,14 @@ LOCAL_INCLUDES += [
 USE_STATIC_LIBS = True
 
 if CONFIG['_MSC_VER']:
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
 
 RCINCLUDE = 'maintenanceservice.rc'
 
 DISABLE_STL_WRAPPING = True
+
+OS_LIBS += [
+    'comctl32',
+    'ws2_32',
+    'shell32',
+]
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -7,28 +7,25 @@ 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)
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32 shell32 wininet shlwapi)
 MOZ_WINCONSOLE = 0
 endif
 
 ifdef MOZ_WIDGET_GTK
 OS_CXXFLAGS += $(TK_CFLAGS) $(MOZ_GTHREAD_CFLAGS)
-OS_LIBS += $(TK_LIBS) $(MOZ_GTHREAD_LIBS)
 endif
 
 ifeq ($(OS_ARCH),SunOS)
 OS_CXXFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_GTHREAD_CFLAGS)
-OS_LIBS += $(MOZ_GTK2_LIBS) $(MOZ_GTHREAD_LIBS)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(OS_ARCH),Darwin)
 libs::
 	$(NSINSTALL) -D $(DIST)/bin/crashreporter.app
 	rsync -a -C --exclude '*.in' $(srcdir)/macbuild/Contents $(DIST)/bin/crashreporter.app 
--- a/toolkit/crashreporter/client/moz.build
+++ b/toolkit/crashreporter/client/moz.build
@@ -19,25 +19,31 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     UNIFIED_SOURCES += [
         'crashreporter_win.cpp',
     ]
     DEFINES['UNICODE'] = True
     DEFINES['_UNICODE'] = True
     USE_LIBS += [
         'google_breakpad_libxul_s',
     ]
+    OS_LIBS += [
+        'comctl32',
+        'shell32',
+        'wininet',
+        'shlwapi',
+    ]
 elif CONFIG['OS_ARCH'] == 'Darwin':
     UNIFIED_SOURCES += [
         'crashreporter_osx.mm',
         'crashreporter_unix_common.cpp',
     ]
     LOCAL_INCLUDES += [
         '../google-breakpad/src/common/mac',
     ]
-    LDFLAGS += ['-framework Cocoa']
+    OS_LIBS += ['-framework Cocoa']
     USE_LIBS += [
         'breakpad_common_s',
         'breakpad_mac_common_s',
     ]
 elif CONFIG['OS_ARCH'] == 'SunOS':
     SOURCES += [
         'crashreporter_linux.cpp',
         'crashreporter_unix.cpp',
@@ -50,16 +56,18 @@ if CONFIG['MOZ_ENABLE_GTK']:
     UNIFIED_SOURCES += [
         'crashreporter_gtk_common.cpp',
         'crashreporter_linux.cpp',
         'crashreporter_unix_common.cpp'
     ]
     USE_LIBS += [
         'breakpad_linux_common_s',
     ]
+    OS_LIBS += CONFIG['TK_LIBS']
+    OS_LIBS += CONFIG['MOZ_GTHREAD_LIBS']
 
 RCINCLUDE = 'crashreporter.rc'
 
 # Don't use the STL wrappers in the crashreporter clients; they don't
 # link with -lmozalloc, and it really doesn't matter here anyway.
 DISABLE_STL_WRAPPING = True
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
--- a/toolkit/library/libxul.mk
+++ b/toolkit/library/libxul.mk
@@ -1,240 +1,67 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_DEPS += $(topsrcdir)/toolkit/library/libxul.mk
 
-# dependent libraries
-ifdef MOZ_B2G_BT_BLUEZ #{
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += -ldbus
-endif
-endif #}
-
-ifdef MOZ_B2G_CAMERA #{
-OS_LIBS += -lstagefright -lstagefright_omx
-endif #}
-
 ifeq (Linux,$(OS_ARCH))
 ifneq (Android,$(OS_TARGET))
-OS_LIBS += -lrt
 OS_LDFLAGS += -Wl,-version-script,symverscript
 
 symverscript: $(topsrcdir)/toolkit/library/symverscript.in
 	$(call py_action,preprocessor, \
 		-DVERSION='xul$(MOZILLA_SYMBOLVERSION)' $< -o $@)
 
 EXTRA_DEPS += symverscript
 endif
 endif
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-OS_LIBS += -lcups
-endif
-
 EXTRA_LIBS += \
   $(NSS_LIBS) \
   $(NULL)
 
-OS_LIBS += \
-  $(MOZ_CAIRO_OSLIBS) \
-  $(MOZ_WEBRTC_X11_LIBS) \
-  $(MOZ_APP_EXTRA_LIBS) \
-  $(SQLITE_LIBS) \
-  $(NULL)
-
 ifdef ENABLE_INTL_API
 ifneq (,$(JS_SHARED_LIBRARY)$(MOZ_NATIVE_ICU))
 OS_LIBS += $(MOZ_ICU_LIBS)
 endif
 endif
 
 ifdef MOZ_NATIVE_FFI
 OS_LIBS += $(MOZ_FFI_LIBS)
 endif
 
-ifdef MOZ_NATIVE_JPEG
-OS_LIBS += $(MOZ_JPEG_LIBS)
-endif
-
-ifdef MOZ_NATIVE_PNG
-OS_LIBS += $(MOZ_PNG_LIBS)
-endif
-
-ifdef MOZ_NATIVE_ZLIB
-OS_LIBS += $(MOZ_ZLIB_LIBS)
-endif
-
-ifdef MOZ_NATIVE_HUNSPELL
-OS_LIBS += $(MOZ_HUNSPELL_LIBS)
-endif
-
-ifdef MOZ_NATIVE_LIBEVENT
-OS_LIBS += $(MOZ_LIBEVENT_LIBS)
-endif
-
-ifdef MOZ_NATIVE_LIBVPX
-OS_LIBS += $(MOZ_LIBVPX_LIBS)
-endif
-
-ifndef MOZ_TREE_PIXMAN
-OS_LIBS += $(MOZ_PIXMAN_LIBS)
-endif
-
 ifdef MOZ_WEBRTC
 ifeq (WINNT,$(OS_TARGET))
 ifndef MOZ_HAS_WINSDK_WITH_D3D
 OS_LDFLAGS += \
   -LIBPATH:'$(MOZ_DIRECTX_SDK_PATH)/lib/$(MOZ_D3D_CPU_SUFFIX)' \
   $(NULL)
 endif
-OS_LIBS += $(call EXPAND_LIBNAME,secur32 crypt32 iphlpapi strmiids dmoguids wmcodecdspuuid amstrmid msdmo wininet)
 endif
 endif
 
-ifdef MOZ_ALSA
-OS_LIBS += $(MOZ_ALSA_LIBS)
-endif
-
-ifdef HAVE_CLOCK_MONOTONIC
-OS_LIBS += $(REALTIME_LIBS)
-endif
-
-ifeq (android,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += -lGLESv2
-endif
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  -lui \
-  -lmedia \
-  -lhardware_legacy \
-  -lhardware \
-  -lutils \
-  -lcutils \
-  -lsysutils \
-  -lcamera_client \
-  -lsensorservice \
-  -lstagefright \
-  -lstagefright_foundation \
-  -lstagefright_omx \
-  -lbinder \
-  -lgui \
-  -lmtp \
-  $(NULL)
-endif
-
-ifneq (,$(filter rtsp,$(NECKO_PROTOCOLS)))
-OS_LIBS += -lstagefright_foundation
-endif
-
-ifdef MOZ_WMF
-OS_LIBS += $(call EXPAND_LIBNAME,mfuuid wmcodecdspuuid strmiids)
-endif
-
-ifdef MOZ_DIRECTSHOW
-OS_LIBS += $(call EXPAND_LIBNAME,dmoguids wmcodecdspuuid strmiids msdmo)
-endif
-
-OS_LIBS += $(ICONV_LIBS)
-
 EXTRA_LIBS += $(NSPR_LIBS)
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-OS_LIBS += \
-  $(TK_LIBS) \
-  $(NULL)
-endif
-
-ifeq (OpenBSD,$(OS_ARCH))
-OS_LIBS += -lsndio
-endif
-
-ifdef MOZ_ENABLE_DBUS
-OS_LIBS += $(MOZ_DBUS_GLIB_LIBS)
-endif
-
-ifdef MOZ_WIDGET_GTK
-ifdef MOZ_ENABLE_GTK3
-OS_LIBS += $(filter-out -lgtk-3 -lgdk-3,$(TK_LIBS))
-else
-OS_LIBS += $(TK_LIBS)
-endif
-OS_LIBS += $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS) $(XCOMPOSITE_LIBS) $(MOZ_PANGO_LIBS) $(XT_LIBS) -lgthread-2.0
-OS_LIBS += $(FT2_LIBS)
-endif
-
-ifeq (qt,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += $(XLDFLAGS) $(XLIBS) $(XT_LIBS) $(MOZ_QT_LIBS)
-OS_LIBS += $(FT2_LIBS) $(MOZ_PANGO_LIBS)
-endif
-
 ifdef MOZ_TREE_FREETYPE
 OS_LIBS += $(FT2_LIBS)
 endif
 
-ifdef MOZ_ENABLE_STARTUP_NOTIFICATION
-OS_LIBS += $(MOZ_STARTUP_NOTIFICATION_LIBS)
-endif
-
-ifdef MOZ_ENABLE_LIBPROXY
-OS_LIBS += $(MOZ_LIBPROXY_LIBS)
-endif
-
-ifeq ($(OS_ARCH),SunOS)
-ifdef GNU_CC
-OS_LIBS += -lelf
-else
-OS_LIBS += -lelf -ldemangle
-endif
-endif
-
-ifeq ($(OS_ARCH),FreeBSD)
-OS_LIBS += $(call EXPAND_LIBNAME,util)
-endif
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi secur32 sensorsapi portabledeviceguids windowscodecs wininet wbemuuid wintrust wtsapi32)
-ifdef ACCESSIBILITY
-OS_LIBS += $(call EXPAND_LIBNAME,oleacc)
-endif
-ifdef MOZ_METRO
-OS_LIBS += $(call EXPAND_LIBNAME,uiautomationcore runtimeobject)
-endif
-endif # WINNT
-
-ifdef MOZ_ENABLE_QT
-OS_LIBS += $(MOZ_QT_LDFLAGS) $(XEXT_LIBS)
-endif
-
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-ifdef MOZ_GSTREAMER
-OS_LIBS += $(GSTREAMER_LIBS)
-endif
-endif
-
 # Generate GDB pretty printer-autoload files only on Linux. OSX's GDB is
 # too old to support Python pretty-printers; if this changes, we could make
 # this 'ifdef GNU_CC'.
 ifeq (Linux,$(OS_ARCH))
 # Create a GDB Python auto-load file alongside the libxul shared library in
 # the build directory.
 PP_TARGETS += LIBXUL_AUTOLOAD
 LIBXUL_AUTOLOAD = $(topsrcdir)/toolkit/library/libxul.so-gdb.py.in
 LIBXUL_AUTOLOAD_FLAGS := -Dtopsrcdir=$(abspath $(topsrcdir))
 endif
 
-OS_LIBS += $(LIBICONV)
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-OS_LIBS += $(call EXPAND_LIBNAME,usp10 oleaut32)
-endif
-
 # BFD ld doesn't create multiple PT_LOADs as usual when an unknown section
 # exists. Using an implicit linker script to make it fold that section in
 # .data.rel.ro makes it create multiple PT_LOADs. That implicit linker
 # script however makes gold misbehave, first because it doesn't like that
 # the linker script is given after crtbegin.o, and even past that, replaces
 # the default section rules with those from the script instead of
 # supplementing them. Which leads to a lib with a huge load of sections.
 ifdef LD_IS_BFD
--- a/toolkit/library/libxul.mozbuild
+++ b/toolkit/library/libxul.mozbuild
@@ -35,26 +35,16 @@ if CONFIG['MOZ_METRO']:
     ]
 
 if CONFIG['ACCESSIBILITY']:
     DELAYLOAD_DLLS += ['oleacc.dll']
 
 if CONFIG['MOZ_WEBRTC']:
     DELAYLOAD_DLLS += ['msdmo.dll']
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
-    LDFLAGS += [
-        '-framework OpenGL',
-        '-framework SystemConfiguration',
-        '-framework QTKit',
-        '-framework IOKit',
-        '-F%s' % CONFIG['MACOS_PRIVATE_FRAMEWORKS_DIR'],
-        '-framework CoreUI',
-    ]
-
 if CONFIG['OS_ARCH'] == 'WINNT' and not CONFIG['GNU_CC']:
     LOCAL_INCLUDES += [
         '/widget/windows',
         '/xpcom/base',
     ]
     # config/version.mk says $(srcdir)/$(RCINCLUDE), and this needs to
     # be valid in both toolkit/library and toolkit/library/gtest.
     # Eventually, the make backend would do its own path canonicalization
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -85,8 +85,244 @@ if CONFIG['MOZ_JPROF']:
         'jprof',
     ]
 
 # This needs to be last
 USE_LIBS += ['StaticXULComponentsEnd']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     CXXFLAGS += CONFIG['TK_CFLAGS']
+
+if CONFIG['MOZ_WEBRTC']:
+    if CONFIG['OS_TARGET'] == 'WINNT':
+        OS_LIBS += [
+            'secur32',
+            'crypt32',
+            'iphlpapi',
+            'strmiids',
+            'dmoguids',
+            'wmcodecdspuuid',
+            'amstrmid',
+            'msdmo',
+            'wininet',
+        ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += [
+        '-framework OpenGL',
+        '-framework SystemConfiguration',
+        '-framework QTKit',
+        '-framework IOKit',
+        '-F%s' % CONFIG['MACOS_PRIVATE_FRAMEWORKS_DIR'],
+        '-framework CoreUI',
+        'cups',
+    ]
+
+if CONFIG['MOZ_WMF']:
+    OS_LIBS += [
+        'mfuuid',
+        'wmcodecdspuuid',
+        'strmiids',
+    ]
+
+if CONFIG['MOZ_DIRECTSHOW']:
+    OS_LIBS += [
+        'dmoguids',
+        'wmcodecdspuuid',
+        'strmiids',
+        'msdmo',
+    ]
+
+if CONFIG['OS_ARCH'] == 'FreeBSD':
+    OS_LIBS += [
+        'util',
+    ]
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    OS_LIBS += [
+        'shell32',
+        'ole32',
+        'version',
+        'winspool',
+    ]
+
+if CONFIG['MOZ_B2G_BT_BLUEZ'] and CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    OS_LIBS += [
+        'dbus',
+    ]
+
+if CONFIG['MOZ_B2G_CAMERA']:
+    OS_LIBS += [
+        'stagefright',
+        'stagefright_omx',
+    ]
+
+if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['OS_TARGET'] != 'Android':
+    OS_LIBS += [
+        'rt',
+    ]
+
+OS_LIBS += CONFIG['MOZ_CAIRO_OSLIBS']
+OS_LIBS += CONFIG['MOZ_WEBRTC_X11_LIBS']
+OS_LIBS += CONFIG['MOZ_APP_EXTRA_LIBS']
+OS_LIBS += CONFIG['SQLITE_LIBS']
+
+if CONFIG['MOZ_NATIVE_JPEG']:
+    OS_LIBS += CONFIG['MOZ_JPEG_LIBS']
+
+if CONFIG['MOZ_NATIVE_PNG']:
+    OS_LIBS += CONFIG['MOZ_PNG_LIBS']
+
+if CONFIG['MOZ_NATIVE_ZLIB']:
+    OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+
+if CONFIG['MOZ_NATIVE_HUNSPELL']:
+    OS_LIBS += CONFIG['MOZ_HUNSPELL_LIBS']
+
+if CONFIG['MOZ_NATIVE_LIBEVENT']:
+    OS_LIBS += CONFIG['MOZ_LIBEVENT_LIBS']
+
+if CONFIG['MOZ_NATIVE_LIBVPX']:
+    OS_LIBS += CONFIG['MOZ_LIBVPX_LIBS']
+
+if not CONFIG['MOZ_TREE_PIXMAN']:
+    OS_LIBS += CONFIG['MOZ_PIXMAN_LIBS']
+
+if CONFIG['MOZ_ALSA']:
+    OS_LIBS += CONFIG['MOZ_ALSA_LIBS']
+
+if CONFIG['HAVE_CLOCK_MONOTONIC']:
+    OS_LIBS += CONFIG['REALTIME_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    OS_LIBS += [
+        'GLESv2',
+    ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    OS_LIBS += [
+        'ui',
+        'media',
+        'hardware_legacy',
+        'hardware',
+        'utils',
+        'cutils',
+        'sysutils',
+        'camera_client',
+        'sensorservice',
+        'stagefright',
+        'stagefright_foundation',
+        'stagefright_omx',
+        'binder',
+        'gui',
+        'mtp',
+    ]
+
+if 'rtsp' in CONFIG['NECKO_PROTOCOLS']:
+    OS_LIBS += [
+        'stagefright_foundation',
+    ]
+
+OS_LIBS += CONFIG['ICONV_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
+
+if CONFIG['OS_ARCH'] == 'OpenBSD':
+    OS_LIBS += [
+        'sndio',
+    ]
+
+if CONFIG['MOZ_ENABLE_DBUS']:
+    OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS']
+
+if CONFIG['MOZ_WIDGET_GTK']:
+    if CONFIG['MOZ_ENABLE_GTK3']:
+        OS_LIBS += [l for l in CONFIG['TK_LIBS']
+            if l not in ('-lgtk-3', '-lgdk-3')]
+    else:
+        OS_LIBS += CONFIG['TK_LIBS']
+    OS_LIBS += CONFIG['XLDFLAGS']
+    OS_LIBS += CONFIG['XLIBS']
+    OS_LIBS += CONFIG['XEXT_LIBS']
+    OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
+    OS_LIBS += CONFIG['XT_LIBS']
+    OS_LIBS += [
+        'gthread-2.0',
+    ]
+    OS_LIBS += CONFIG['FT2_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
+    OS_LIBS += CONFIG['XLDFLAGS']
+    OS_LIBS += CONFIG['XLIBS']
+    OS_LIBS += CONFIG['XT_LIBS']
+    OS_LIBS += CONFIG['MOZ_QT_LIBS']
+    OS_LIBS += CONFIG['FT2_LIBS']
+    OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
+
+if CONFIG['MOZ_ENABLE_STARTUP_NOTIFICATION']:
+    OS_LIBS += CONFIG['MOZ_STARTUP_NOTIFICATION_LIBS']
+
+if CONFIG['MOZ_ENABLE_LIBPROXY']:
+    OS_LIBS += CONFIG['MOZ_LIBPROXY_LIBS']
+
+if CONFIG['OS_ARCH'] == 'SunOS':
+    OS_LIBS += [
+        'elf',
+    ]
+    if CONFIG['GNU_CC']:
+        OS_LIBS += [
+            'demangle',
+        ]
+
+if CONFIG['OS_ARCH'] == 'FreeBSD':
+    OS_LIBS += [
+        'util',
+    ]
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    OS_LIBS += [
+        'shell32',
+        'ole32',
+        'version',
+        'winspool',
+        'comdlg32',
+        'imm32',
+        'msimg32',
+        'shlwapi',
+        'psapi',
+        'ws2_32',
+        'dbghelp',
+        'rasapi32',
+        'rasdlg',
+        'iphlpapi',
+        'uxtheme',
+        'setupapi',
+        'secur32',
+        'sensorsapi',
+        'portabledeviceguids',
+        'windowscodecs',
+        'wininet',
+        'wbemuuid',
+        'wintrust',
+        'wtsapi32',
+    ]
+    if CONFIG['ACCESSIBILITY']:
+        OS_LIBS += [
+            'oleacc',
+        ]
+    if CONFIG['MOZ_METRO']:
+        OS_LIBS += [
+            'uiautomationcore',
+            'runtimeobject',
+        ]
+
+if CONFIG['MOZ_ENABLE_QT']:
+    OS_LIBS += CONFIG['XEXT_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa' and CONFIG['MOZ_GSTREAMER']:
+    OS_LIBS += CONFIG['GSTREAMER_LIBS']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    OS_LIBS += [
+        'usp10',
+        'oleaut32',
+    ]
--- a/toolkit/mozapps/update/tests/Makefile.in
+++ b/toolkit/mozapps/update/tests/Makefile.in
@@ -64,20 +64,16 @@ INI_TEST_FILES = \
   TestAUSReadStrings1.ini \
   TestAUSReadStrings2.ini \
   TestAUSReadStrings3.ini \
   $(NULL)
 
 MOZ_GLUE_LDFLAGS =
 MOZ_WINCONSOLE = 1
 
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,wintrust shlwapi)
-endif
-
 endif # Not Android
 
 include $(topsrcdir)/config/rules.mk
 
 ifneq (android,$(MOZ_WIDGET_TOOLKIT))
 # TestAUSReadStrings runs during check in the following directory with a Unicode
 # char in order to test bug 473417 on Windows.
 ifeq ($(OS_ARCH),WINNT)
--- a/toolkit/mozapps/update/tests/moz.build
+++ b/toolkit/mozapps/update/tests/moz.build
@@ -31,16 +31,22 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'andr
         USE_LIBS += [
             'updatecommon-standalone',
         ]
     else:
         USE_LIBS += [
             'updatecommon',
         ]
 
+    if CONFIG['OS_ARCH'] == 'WINNT':
+        OS_LIBS += [
+            'wintrust',
+            'shlwapi',
+        ]
+
 for var in ('MOZ_APP_NAME', 'MOZ_APP_BASENAME', 'MOZ_APP_DISPLAYNAME',
             'MOZ_APP_VENDOR', 'BIN_SUFFIX', 'MOZ_DEBUG'):
     DEFINES[var] = CONFIG[var]
 
 DEFINES['NS_NO_XPCOM'] = True
 
 if CONFIG['MOZ_MAINTENANCE_SERVICE'] and not CONFIG['HAVE_64BIT_BUILD']:
     DEFINES['MOZ_MAINTENANCE_SERVICE'] = CONFIG['MOZ_MAINTENANCE_SERVICE']
--- a/toolkit/mozapps/update/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -2,32 +2,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Don't link the updater against libmozglue. See bug 687139
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
-ifdef MOZ_NATIVE_BZ2
-OS_LIBS += \
-  $(MOZ_BZ2_LIBS) \
-  $(NULL)
-endif
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32 shlwapi)
-endif
-
-ifdef MOZ_WIDGET_GTK
-OS_LIBS += $(TK_LIBS)
-endif
-
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) #{
-OS_LIBS += -lcutils -lsysutils
 # 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
@@ -49,14 +34,9 @@ libs::
 	rsync -a -C --exclude '*.in' $(srcdir)/macbuild/Contents $(DIST)/bin/updater.app 
 	sed -e 's/%APP_NAME%/$(MOZ_APP_DISPLAYNAME)/' $(srcdir)/macbuild/Contents/Resources/English.lproj/InfoPlist.strings.in | \
 	  iconv -f UTF-8 -t UTF-16 > $(DIST)/bin/updater.app/Contents/Resources/English.lproj/InfoPlist.strings
 	$(NSINSTALL) -D $(DIST)/bin/updater.app/Contents/MacOS
 	$(NSINSTALL) $(DIST)/bin/updater $(DIST)/bin/updater.app/Contents/MacOS
 	rm -f $(DIST)/bin/updater
 endif
 
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,crypt32)
-OS_LIBS += $(call EXPAND_LIBNAME,advapi32)
-endif
-
 CXXFLAGS += $(MOZ_BZ2_CFLAGS)
--- a/toolkit/mozapps/update/updater/moz.build
+++ b/toolkit/mozapps/update/updater/moz.build
@@ -29,50 +29,64 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     # Pick up nsWindowsRestart.cpp
     LOCAL_INCLUDES += [
         '/toolkit/xre',
     ]
     USE_LIBS += [
         'updatecommon-standalone',
         'verifymar',
     ]
+    OS_LIBS += [
+        'comctl32',
+        'ws2_32',
+        'shell32',
+        'shlwapi',
+        'crypt32',
+        'advapi32',
+    ]
 else:
     USE_LIBS += [
         'updatecommon',
     ]
 
 USE_LIBS += [
     'mar',
 ]
 
-if not CONFIG['MOZ_NATIVE_BZ2']:
+if CONFIG['MOZ_NATIVE_BZ2']:
+    OS_LIBS += CONFIG['MOZ_BZ2_LIBS']
+else:
     USE_LIBS += [
         'bz2',
     ]
 
 if CONFIG['MOZ_ENABLE_GTK']:
     have_progressui = 1
     SOURCES += [
         'progressui_gtk.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     have_progressui = 1
     SOURCES += [
         'launchchild_osx.mm',
         'progressui_osx.mm',
     ]
-    LDFLAGS += ['-framework Cocoa']
+    OS_LIBS += ['-framework Cocoa']
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     have_progressui = 1
     SOURCES += [
         'automounter_gonk.cpp',
         'progressui_gonk.cpp',
     ]
     DISABLE_STL_WRAPPING = True
+    OS_LIBS += [
+        'cutils',
+        'sysutils',
+    ]
 
 if have_progressui == 0:
     SOURCES += [
         'progressui_null.cpp',
     ]
 
 DEFINES['NS_NO_XPCOM'] = True
 DISABLE_STL_WRAPPING = True
@@ -97,8 +111,9 @@ elif CONFIG['OS_ARCH'] == 'WINNT':
 
 if CONFIG['MOZ_UPDATE_CHANNEL'] in ('beta', 'release', 'esr'):
     DEFINES['MAR_SIGNING_RELEASE_BETA'] = '1'
 elif CONFIG['MOZ_UPDATE_CHANNEL'] in ('nightly', 'aurora', 'nightly-elm', 'nightly-profiling', 'nightly-oak', 'nightly-ux'):
     DEFINES['MAR_SIGNING_AURORA_NIGHTLY'] = '1'
 
 if CONFIG['MOZ_WIDGET_GTK']:
     CXXFLAGS += CONFIG['TK_CFLAGS']
+    OS_LIBS += CONFIG['TK_LIBS']
--- a/toolkit/system/dbus/Makefile.in
+++ b/toolkit/system/dbus/Makefile.in
@@ -1,13 +1,7 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS += \
 	$(NSPR_LIBS) \
     $(NULL)
-
-OS_LIBS += \
-	$(MOZ_DBUS_GLIB_LIBS) \
-	$(NULL)
-                
-include $(topsrcdir)/config/rules.mk
--- a/toolkit/system/dbus/moz.build
+++ b/toolkit/system/dbus/moz.build
@@ -17,8 +17,10 @@ IS_COMPONENT = True
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
+
+OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS']
--- a/toolkit/system/gnome/Makefile.in
+++ b/toolkit/system/gnome/Makefile.in
@@ -1,15 +1,7 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS += \
 		$(NSPR_LIBS) \
         $(NULL)
-
-OS_LIBS += \
-		$(MOZ_GCONF_LIBS) \
-		$(MOZ_GNOMEVFS_LIBS) \
-		$(GLIB_LIBS) \
-		$(MOZ_GIO_LIBS) \
-		$(MOZ_DBUS_GLIB_LIBS) \
-		$(NULL)
--- a/toolkit/system/gnome/moz.build
+++ b/toolkit/system/gnome/moz.build
@@ -42,8 +42,14 @@ USE_LIBS += [
 CXXFLAGS += CONFIG['MOZ_GCONF_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_GNOMEVFS_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_GIO_CFLAGS']
 CXXFLAGS += CONFIG['GLIB_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
 
 if CONFIG['MOZ_ENABLE_GTK']:
     CXXFLAGS += CONFIG['TK_CFLAGS']
+
+OS_LIBS += CONFIG['MOZ_GCONF_LIBS']
+OS_LIBS += CONFIG['MOZ_GNOMEVFS_LIBS']
+OS_LIBS += CONFIG['GLIB_LIBS']
+OS_LIBS += CONFIG['MOZ_GIO_LIBS']
+OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS']
--- a/toolkit/xre/test/win/Makefile.in
+++ b/toolkit/xre/test/win/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/.
 
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32)
-
 MOZ_WINCONSOLE = 1
 
 include $(topsrcdir)/config/rules.mk
 
 libs:: TestXREMakeCommandLineWin.ini
 	$(INSTALL) $^ $(FINAL_TARGET)/
 
 check::
--- a/toolkit/xre/test/win/moz.build
+++ b/toolkit/xre/test/win/moz.build
@@ -17,8 +17,14 @@ DEFINES['NS_NO_XPCOM'] = True
 
 LOCAL_INCLUDES += [
     '/config',
     '/toolkit/xre',
 ]
 
 
 USE_STATIC_LIBS = True
+
+OS_LIBS += [
+    'comctl32',
+    'ws2_32',
+    'shell32',
+]
deleted file mode 100644
--- a/tools/jprof/Makefile.in
+++ /dev/null
@@ -1,12 +0,0 @@
-#! gmake
-#
-# 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/.
-
-OS_LIBS += \
-	-ldl \
-	-lbfd \
-	-liberty \
-	$(NULL)
-
--- a/tools/jprof/moz.build
+++ b/tools/jprof/moz.build
@@ -16,8 +16,13 @@ SOURCES += [
     'leaky.cpp',
     'strset.cpp',
 ]
 
 LOCAL_INCLUDES += [
     'stub',
 ]
 
+OS_LIBS += [
+    'dl',
+    'gfd',
+    'iberty',
+]
--- a/webapprt/gtk/Makefile.in
+++ b/webapprt/gtk/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/.
 
-OS_LIBS += \
-  $(TK_LIBS) \
-  $(NULL)
-
 NSDISTMODE = copy
 
 PROGRAMS_DEST = $(DIST)/bin
 
 include $(topsrcdir)/config/rules.mk
 
 GRE_BUILDID := $(shell cat $(DEPTH)/config/buildid)
 DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
--- a/webapprt/gtk/moz.build
+++ b/webapprt/gtk/moz.build
@@ -23,8 +23,10 @@ LOCAL_INCLUDES += [
 
 USE_LIBS += [
     'xpcomglue',
 ]
 
 DISABLE_STL_WRAPPING = True
 
 CXXFLAGS += CONFIG['TK_CFLAGS']
+
+OS_LIBS += CONFIG['TK_LIBS']
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/Makefile.in
@@ -17,18 +17,16 @@ endif
 # Installer stuff
 include $(topsrcdir)/toolkit/mozapps/installer/package-name.mk
 
 CONFIG_DIR = instgen
 SFX_MODULE = $(topsrcdir)/other-licenses/7zstub/firefox/7zSD.sfx
 APP_VERSION := $(shell cat $(topsrcdir)/browser/config/version.txt)
 DEFINES += -DAPP_VERSION=$(APP_VERSION)
 
-OS_LIBS += $(call EXPAND_LIBNAME,shell32)
-
 # Uninstaller
 ifdef LOCALE_MERGEDIR
 PPL_LOCALE_ARGS = \
   --l10n-dir=$(LOCALE_MERGEDIR)/webapprt/webapp-uninstaller \
   --l10n-dir=$(call EXPAND_LOCALE_SRCDIR,webapprt/locales)/webapp-uninstaller \
   --l10n-dir=$(topsrcdir)/webapprt/locales/en-US/webapp-uninstaller \
   $(NULL)
 else
--- a/webapprt/win/moz.build
+++ b/webapprt/win/moz.build
@@ -42,8 +42,12 @@ if not CONFIG['GNU_CC']:
 
 RCINCLUDE = 'webapprt.rc'
 
 USE_LIBS += [
     'xpcomglue_staticruntime',
 ]
 
 DISABLE_STL_WRAPPING = True
+
+OS_LIBS += [
+    'shell32',
+]
deleted file mode 100644
--- a/widget/gtk/mozgtk/gtk2/Makefile.in
+++ /dev/null
@@ -1,18 +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/.
-
-include $(topsrcdir)/config/rules.mk
-
-
-# If LDFLAGS contains -Wl,--as-needed, we need to add -Wl,--no-as-needed
-# before the gtk libraries, otherwise the linker will drop those dependencies
-# because no symbols are used from them. But those dependencies need to be
-# kept for things to work properly.
-ifeq (,$(filter -Wl,--as-needed),$(LDFLAGS))
-no_as_needed = $1
-else
-no_as_needed = -Wl,--no-as-needed $1 -Wl,--as-needed
-endif
-
-OS_LIBS += $(filter -L%,$(MOZ_GTK2_LIBS)) $(call no_as_needed,-lgtk-x11-2.0 -lgdk-x11-2.0)
--- a/widget/gtk/mozgtk/gtk2/moz.build
+++ b/widget/gtk/mozgtk/gtk2/moz.build
@@ -10,8 +10,27 @@ SOURCES += [
 
 DEFINES['GTK3_SYMBOLS'] = True
 
 LIBRARY_NAME = 'mozgtk2'
 
 SONAME = 'mozgtk'
 
 FORCE_SHARED_LIB = True
+
+# If LDFLAGS contains -Wl,--as-needed, we need to add -Wl,--no-as-needed
+# before the gtk libraries, otherwise the linker will drop those dependencies
+# because no symbols are used from them. But those dependencies need to be
+# kept for things to work properly.
+if '-Wl,--as-needed' in CONFIG['OS_LDFLAGS']:
+    no_as_needed = ['-Wl,--no-as-needed']
+    as_needed = ['-Wl,--as-needed']
+else:
+    no_as_needed = []
+    as_needed = []
+
+OS_LIBS += [f for f in CONFIG['MOZ_GTK2_LIBS'] if f.startswith('-L')]
+OS_LIBS += no_as_needed
+OS_LIBS += [
+    'gtk-x11-2.0',
+    'gdk-x11-2.0',
+]
+OS_LIBS += as_needed
deleted file mode 100644
--- a/widget/gtk/mozgtk/gtk3/Makefile.in
+++ /dev/null
@@ -1,17 +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/.
-
-include $(topsrcdir)/config/rules.mk
-
-# If LDFLAGS contains -Wl,--as-needed, we need to add -Wl,--no-as-needed
-# before the gtk libraries, otherwise the linker will drop those dependencies
-# because no symbols are used from them. But those dependencies need to be
-# kept for things to work properly.
-ifeq (,$(filter -Wl,--as-needed),$(LDFLAGS))
-no_as_needed = $1
-else
-no_as_needed = -Wl,--no-as-needed $1 -Wl,--as-needed
-endif
-
-OS_LIBS += $(filter -L%,$(MOZ_GTK3_LIBS)) $(call no_as_needed,-lgtk-3 -lgdk-3)
--- a/widget/gtk/mozgtk/gtk3/moz.build
+++ b/widget/gtk/mozgtk/gtk3/moz.build
@@ -10,8 +10,27 @@ SOURCES += [
 
 DEFINES['GTK2_SYMBOLS'] = True
 
 LIBRARY_NAME = 'mozgtk'
 
 SONAME = 'mozgtk'
 
 FORCE_SHARED_LIB = True
+
+# If LDFLAGS contains -Wl,--as-needed, we need to add -Wl,--no-as-needed
+# before the gtk libraries, otherwise the linker will drop those dependencies
+# because no symbols are used from them. But those dependencies need to be
+# kept for things to work properly.
+if '-Wl,--as-needed' in CONFIG['OS_LDFLAGS']:
+    no_as_needed = ['-Wl,--no-as-needed']
+    as_needed = ['-Wl,--as-needed']
+else:
+    no_as_needed = []
+    as_needed = []
+
+OS_LIBS += [f for f in CONFIG['MOZ_GTK3_LIBS'] if f.startswith('-L')]
+OS_LIBS += no_as_needed
+OS_LIBS += [
+    'gtk-3',
+    'gdk-3',
+]
+OS_LIBS += as_needed
--- a/widget/xremoteclient/Makefile.in
+++ b/widget/xremoteclient/Makefile.in
@@ -21,13 +21,8 @@ PROGOBJS = $(PROGCPPSRCS:.cpp=.$(OBJ_SUF
 CPPSRCS += \
   $(filter-out $(LIBCPPSRCS),$(PROGCPPSRCS)) \
   $(LIBCPPSRCS) \
   $(NULL)
 
 EXTRA_LIBS += \
 	$(NSPR_LIBS) \
 	$(NULL)
-
-OS_LIBS += \
-	$(XLDFLAGS) \
-	$(XLIBS) \
-	$(NULL)
--- a/widget/xremoteclient/moz.build
+++ b/widget/xremoteclient/moz.build
@@ -4,8 +4,11 @@
 # 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 = 'mozilla-xremote-client'
 
 FINAL_LIBRARY = 'xul'
 
 DEFINES['XPCOM_GLUE'] = True
+
+OS_LIBS += CONFIG['XLDFLAGS']
+OS_LIBS += CONFIG['XLIBS']
--- a/xpcom/sample/Makefile.in
+++ b/xpcom/sample/Makefile.in
@@ -1,15 +1,8 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_LIBS += \
 		$(NSPR_LIBS) \
 		$(NULL)
-
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-		$(TK_LIBS) \
-		$(NULL)
-endif
--- a/xpcom/sample/moz.build
+++ b/xpcom/sample/moz.build
@@ -40,8 +40,12 @@ RESOURCE_FILES.samples += [
     'xpconnect-sample.html',
 ]
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+# Need to link with CoreFoundation on Mac
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
deleted file mode 100644
--- a/xpcom/sample/program/Makefile.in
+++ /dev/null
@@ -1,11 +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/.
-
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS            += \
-		$(TK_LIBS) \
-		$(NULL)
-endif
--- a/xpcom/sample/program/moz.build
+++ b/xpcom/sample/program/moz.build
@@ -21,8 +21,12 @@ 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',
 ]
+
+# Need to link with CoreFoundation on Mac
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/bug656331_component/Makefile.in
+++ b/xpcom/tests/bug656331_component/Makefile.in
@@ -10,18 +10,11 @@ unittestlocation = xpcom/tests/unit
 MANIFEST = bug656331.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
 EXTRA_LIBS += \
   $(NSPR_LIBS) \
   $(NULL)
 
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-  $(TK_LIBS) \
-  $(NULL)
-endif
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
--- a/xpcom/tests/bug656331_component/moz.build
+++ b/xpcom/tests/bug656331_component/moz.build
@@ -20,8 +20,12 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' %
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+# Need to link with CoreFoundation on Mac
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/component/Makefile.in
+++ b/xpcom/tests/component/Makefile.in
@@ -8,18 +8,11 @@ unittestlocation = xpcom/tests/unit
 MANIFEST = testcomponent.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
 EXTRA_LIBS += \
 		$(NSPR_LIBS) \
 		$(NULL)
 
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-		$(TK_LIBS) \
-		$(NULL)
-endif
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
--- a/xpcom/tests/component/moz.build
+++ b/xpcom/tests/component/moz.build
@@ -20,8 +20,12 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' %
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+# Need to link with CoreFoundation on Mac
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
--- a/xpcom/tests/component_no_aslr/Makefile.in
+++ b/xpcom/tests/component_no_aslr/Makefile.in
@@ -8,22 +8,15 @@ unittestlocation = xpcom/tests/unit
 MANIFEST = testcompnoaslr.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(unittestlocation)
 PP_TARGETS += MANIFEST
 
 EXTRA_LIBS += \
 		$(NSPR_LIBS) \
 		$(NULL)
 
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS += \
-		$(TK_LIBS) \
-		$(NULL)
-endif
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
 
 include $(topsrcdir)/config/rules.mk
 
 LDFLAGS := $(filter-out -DYNAMICBASE,$(LDFLAGS)) -DYNAMICBASE:NO
--- a/xpcom/tests/component_no_aslr/moz.build
+++ b/xpcom/tests/component_no_aslr/moz.build
@@ -20,8 +20,12 @@ DEFINES['LIBRARY_FILENAME'] = '%s%s%s' %
     CONFIG['DLL_SUFFIX']
 )
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+# Need to link with CoreFoundation on Mac
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    OS_LIBS += CONFIG['TK_LIBS']
deleted file mode 100644
--- a/xpcom/tests/windows/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/.
-
-include $(topsrcdir)/config/rules.mk
-
-OS_LIBS	+= $(call EXPAND_LIBNAME,rpcrt4 uuid mpr)
--- a/xpcom/tests/windows/moz.build
+++ b/xpcom/tests/windows/moz.build
@@ -11,8 +11,14 @@ CPP_UNIT_TESTS += [
 
 SOURCES += sorted('%s.cpp' % t for t in CPP_UNIT_TESTS)
 
 USE_LIBS += [
     'mozalloc',
     'xpcomglue_s',
     'xul',
 ]
+
+OS_LIBS += [
+    'rpcrt4',
+    'uuid',
+    'mpr',
+]
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -21,20 +21,16 @@ endif
 endif
 
 # 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
 
 include $(topsrcdir)/config/config.mk
 
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 DEFINES += -DXULRUNNER_ICO='"$(DIST)/branding/xulrunner.ico"' -DDOCUMENT_ICO='"$(DIST)/branding/document.ico"'
 
 ifdef MOZ_WIDGET_GTK
 libs::
 	$(INSTALL) $(IFLAGS1) $(DIST)/branding/default16.png $(DIST)/bin/chrome/icons/default
 	$(INSTALL) $(IFLAGS1) $(DIST)/branding/default32.png $(DIST)/bin/chrome/icons/default
--- a/xulrunner/app/moz.build
+++ b/xulrunner/app/moz.build
@@ -37,14 +37,24 @@ if CONFIG['_MSC_VER']:
 # 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':
     RCINCLUDE = 'splash.rc'
+    OS_LIBS += [
+        'comctl32',
+        'comdlg32',
+        'uuid',
+        'shell32',
+        'ole32',
+        'oleaut32',
+        'version',
+        'winspool',
+    ]
 
 USE_LIBS += [
     'xpcomglue',
 ]
 
 DISABLE_STL_WRAPPING = True
--- a/xulrunner/stub/Makefile.in
+++ b/xulrunner/stub/Makefile.in
@@ -1,25 +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/.
 
 # Don't create a dependency on mozglue
 MOZ_GLUE_LDFLAGS =
 
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-OS_LIBS            += \
-		$(TK_LIBS) \
-		$(NULL)
-endif
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
-
-ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,shell32)
-endif
--- a/xulrunner/stub/moz.build
+++ b/xulrunner/stub/moz.build
@@ -37,14 +37,21 @@ if CONFIG['_MSC_VER']:
 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']