Bug 874266 - Move all DEFINES that can be moved to moz.build. r=mshal
☠☠ backed out by e668d88804d1 ☠ ☠
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 28 Nov 2013 13:08:16 +0900
changeset 157925 3fd4b546eed453156a7d87548c9d30f938f46053
parent 157924 a35d2e3a872f6f2962c86420568b1b2dbbdce599
child 157926 2e43ded4b791dfac2ffb415798812cf5e616a195
push id3719
push usercbook@mozilla.com
push dateThu, 28 Nov 2013 13:35:33 +0000
treeherderfx-team@9edf20552d79 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs874266
milestone28.0a1
Bug 874266 - Move all DEFINES that can be moved to moz.build. r=mshal
accessible/public/ia2/Makefile.in
accessible/public/ia2/moz.build
accessible/public/msaa/Makefile.in
accessible/public/msaa/moz.build
b2g/app/Makefile.in
b2g/app/moz.build
b2g/chrome/Makefile.in
b2g/chrome/moz.build
b2g/gaia/Makefile.in
b2g/gaia/moz.build
browser/app/Makefile.in
browser/app/moz.build
browser/base/Makefile.in
browser/base/moz.build
browser/branding/aurora/locales/Makefile.in
browser/branding/aurora/locales/moz.build
browser/branding/nightly/locales/Makefile.in
browser/branding/nightly/locales/moz.build
browser/branding/unofficial/locales/Makefile.in
browser/branding/unofficial/locales/moz.build
browser/components/feeds/src/Makefile.in
browser/components/feeds/src/moz.build
browser/components/migration/src/Makefile.in
browser/components/migration/src/moz.build
browser/components/preferences/Makefile.in
browser/components/preferences/in-content/Makefile.in
browser/components/preferences/in-content/moz.build
browser/components/preferences/moz.build
browser/components/shell/src/Makefile.in
browser/components/shell/src/moz.build
browser/metro/Makefile.in
browser/metro/base/Makefile.in
browser/metro/base/moz.build
browser/metro/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
browser/modules/Makefile.in
browser/modules/moz.build
build/Makefile.in
build/mobile/robocop/Makefile.in
build/mobile/robocop/moz.build
build/moz.build
build/stlport/Makefile.in
build/stlport/moz.build
build/unix/elfhack/Makefile.in
build/unix/elfhack/inject/Makefile.in
build/unix/elfhack/inject/moz.build
build/unix/elfhack/moz.build
db/sqlite3/src/Makefile.in
db/sqlite3/src/moz.build
dom/base/Makefile.in
dom/base/moz.build
dom/bluetooth/Makefile.in
dom/bluetooth/moz.build
dom/ipc/Makefile.in
dom/ipc/moz.build
dom/plugins/ipc/hangui/Makefile.in
dom/plugins/ipc/hangui/moz.build
embedding/tests/winEmbed/Makefile.in
embedding/tests/winEmbed/moz.build
extensions/spellcheck/hunspell/src/Makefile.in
extensions/spellcheck/hunspell/src/moz.build
gfx/2d/Makefile.in
gfx/2d/moz.build
gfx/angle/Makefile.in
gfx/angle/moz.build
gfx/angle/src/libEGL/Makefile.in
gfx/angle/src/libEGL/moz.build
gfx/angle/src/libGLESv2/Makefile.in
gfx/angle/src/libGLESv2/moz.build
gfx/cairo/cairo/src/Makefile.in
gfx/cairo/cairo/src/moz.build
gfx/cairo/libpixman/src/Makefile.in
gfx/cairo/libpixman/src/moz.build
gfx/gl/Makefile.in
gfx/gl/moz.build
gfx/graphite2/src/Makefile.in
gfx/graphite2/src/moz.build
gfx/harfbuzz/src/Makefile.in
gfx/harfbuzz/src/moz.build
gfx/layers/Makefile.in
gfx/layers/moz.build
gfx/ots/src/Makefile.in
gfx/ots/src/moz.build
gfx/skia/Makefile.in
gfx/skia/moz.build
gfx/thebes/Makefile.in
gfx/thebes/moz.build
intl/locale/src/unix/Makefile.in
intl/locale/src/unix/moz.build
intl/unicharutil/util/Makefile.in
intl/unicharutil/util/moz.build
ipc/chromium/Makefile.in
ipc/chromium/moz.build
ipc/glue/Makefile.in
ipc/glue/moz.build
js/ipc/Makefile.in
js/ipc/moz.build
js/src/Makefile.in
js/src/config/Makefile.in
js/src/config/moz.build
js/src/editline/Makefile.in
js/src/editline/moz.build
js/src/gdb/Makefile.in
js/src/gdb/moz.build
js/src/jsapi-tests/Makefile.in
js/src/jsapi-tests/moz.build
js/src/moz.build
js/src/shell/Makefile.in
js/src/shell/moz.build
js/xpconnect/loader/Makefile.in
js/xpconnect/loader/moz.build
js/xpconnect/src/Makefile.in
js/xpconnect/src/moz.build
js/xpconnect/tests/components/native/Makefile.in
js/xpconnect/tests/components/native/moz.build
layout/style/test/Makefile.in
layout/style/test/moz.build
layout/tables/Makefile.in
layout/tables/moz.build
media/libcubeb/src/Makefile.in
media/libcubeb/src/moz.build
media/libopus/Makefile.in
media/libopus/moz.build
media/libsoundtouch/src/Makefile.in
media/libsoundtouch/src/moz.build
media/libspeex_resampler/src/Makefile.in
media/libspeex_resampler/src/moz.build
media/libtheora/lib/Makefile.in
media/libtheora/lib/moz.build
media/libtremor/lib/Makefile.in
media/libtremor/lib/moz.build
media/libvpx/Makefile.in
media/libvpx/moz.build
media/mtransport/build/Makefile.in
media/mtransport/build/moz.build
media/mtransport/standalone/Makefile.in
media/mtransport/standalone/moz.build
media/mtransport/test/Makefile.in
media/mtransport/test/moz.build
media/webrtc/signaling/test/Makefile.in
media/webrtc/signaling/test/moz.build
memory/build/Makefile.in
memory/build/moz.build
memory/jemalloc/Makefile.in
memory/jemalloc/moz.build
memory/mozalloc/Makefile.in
memory/mozalloc/moz.build
memory/mozjemalloc/Makefile.in
memory/mozjemalloc/moz.build
memory/replace/dmd/Makefile.in
memory/replace/dmd/moz.build
memory/replace/jemalloc/Makefile.in
memory/replace/jemalloc/moz.build
mfbt/tests/Makefile.in
mfbt/tests/moz.build
mobile/android/app/Makefile.in
mobile/android/app/moz.build
mobile/android/base/Makefile.in
mobile/android/base/moz.build
mobile/android/chrome/Makefile.in
mobile/android/chrome/moz.build
mobile/android/components/Makefile.in
mobile/android/components/moz.build
mobile/android/geckoview_library/Makefile.in
mobile/android/geckoview_library/moz.build
modules/libbz2/src/Makefile.in
modules/libbz2/src/moz.build
modules/libmar/tests/Makefile.in
modules/libmar/tests/moz.build
modules/libmar/tool/Makefile.in
modules/libmar/tool/moz.build
modules/libmar/verify/Makefile.in
modules/libmar/verify/moz.build
modules/libpref/src/Makefile.in
modules/libpref/src/moz.build
mozglue/android/Makefile.in
mozglue/android/moz.build
mozglue/build/Makefile.in
mozglue/build/moz.build
mozglue/linker/Makefile.in
mozglue/linker/moz.build
netwerk/protocol/rtsp/Makefile.in
netwerk/protocol/rtsp/moz.build
netwerk/sctp/datachannel/Makefile.in
netwerk/sctp/datachannel/moz.build
netwerk/sctp/src/Makefile.in
netwerk/sctp/src/moz.build
netwerk/srtp/src/Makefile.in
netwerk/srtp/src/moz.build
netwerk/streamconv/test/Makefile.in
netwerk/streamconv/test/moz.build
other-licenses/skia-npapi/Makefile.in
other-licenses/skia-npapi/moz.build
parser/expat/lib/Makefile.in
parser/expat/lib/moz.build
parser/html/Makefile.in
parser/html/moz.build
profile/dirserviceprovider/standalone/Makefile.in
profile/dirserviceprovider/standalone/moz.build
security/manager/ssl/src/Makefile.in
security/manager/ssl/src/moz.build
security/sandbox/Makefile.in
security/sandbox/moz.build
security/sandbox/win/src/sandboxbroker/Makefile.in
security/sandbox/win/src/sandboxbroker/moz.build
storage/src/Makefile.in
storage/src/moz.build
testing/marionette/Makefile.in
testing/marionette/components/Makefile.in
testing/marionette/components/moz.build
testing/marionette/moz.build
toolkit/components/maintenanceservice/Makefile.in
toolkit/components/maintenanceservice/moz.build
toolkit/components/search/Makefile.in
toolkit/components/search/moz.build
toolkit/components/telemetry/Makefile.in
toolkit/components/telemetry/moz.build
toolkit/content/Makefile.in
toolkit/content/moz.build
toolkit/crashreporter/Makefile.in
toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
toolkit/crashreporter/breakpad-windows-libxul/moz.build
toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
toolkit/crashreporter/breakpad-windows-standalone/moz.build
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/client/moz.build
toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
toolkit/crashreporter/google-breakpad/src/common/Makefile.in
toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
toolkit/crashreporter/google-breakpad/src/common/moz.build
toolkit/crashreporter/moz.build
toolkit/crashreporter/test/Makefile.in
toolkit/crashreporter/test/moz.build
toolkit/modules/Makefile.in
toolkit/modules/moz.build
toolkit/mozapps/extensions/Makefile.in
toolkit/mozapps/extensions/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/webapps/Makefile.in
toolkit/webapps/moz.build
toolkit/xre/Makefile.in
toolkit/xre/moz.build
toolkit/xre/test/win/Makefile.in
toolkit/xre/test/win/moz.build
tools/jprof/stub/Makefile.in
tools/jprof/stub/moz.build
tools/trace-malloc/lib/Makefile.in
tools/trace-malloc/lib/moz.build
webapprt/Makefile.in
webapprt/gtk2/Makefile.in
webapprt/gtk2/moz.build
webapprt/mac/Makefile.in
webapprt/mac/moz.build
webapprt/moz.build
webapprt/win/Makefile.in
webapprt/win/moz.build
widget/android/Makefile.in
widget/android/moz.build
widget/gonk/Makefile.in
widget/gonk/libdisplay/Makefile.in
widget/gonk/libdisplay/moz.build
widget/gonk/moz.build
widget/gtk/Makefile.in
widget/gtk/moz.build
widget/gtkxtbin/Makefile.in
widget/gtkxtbin/moz.build
widget/os2/Makefile.in
widget/os2/moz.build
widget/qt/Makefile.in
widget/qt/faststartupqt/Makefile.in
widget/qt/faststartupqt/moz.build
widget/qt/moz.build
widget/windows/Makefile.in
widget/windows/moz.build
widget/windows/winrt/Makefile.in
widget/windows/winrt/moz.build
widget/xpwidgets/Makefile.in
widget/xpwidgets/moz.build
widget/xremoteclient/Makefile.in
widget/xremoteclient/moz.build
xpcom/build/Makefile.in
xpcom/build/moz.build
xpcom/glue/Makefile.in
xpcom/glue/moz.build
xpcom/glue/nomozalloc/Makefile.in
xpcom/glue/nomozalloc/moz.build
xpcom/glue/standalone/Makefile.in
xpcom/glue/standalone/moz.build
xpcom/glue/standalone/staticruntime/Makefile.in
xpcom/glue/standalone/staticruntime/moz.build
xpcom/glue/staticruntime/Makefile.in
xpcom/glue/staticruntime/moz.build
xpcom/io/Makefile.in
xpcom/io/moz.build
xpcom/reflect/xptcall/src/md/os2/Makefile.in
xpcom/reflect/xptcall/src/md/os2/moz.build
xpcom/reflect/xptcall/src/md/unix/Makefile.in
xpcom/reflect/xptcall/src/md/unix/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
xulrunner/app/Makefile.in
xulrunner/app/moz.build
xulrunner/setup/Makefile.in
xulrunner/setup/moz.build
xulrunner/stub/Makefile.in
xulrunner/stub/moz.build
xulrunner/tools/redit/Makefile.in
xulrunner/tools/redit/moz.build
--- a/accessible/public/ia2/Makefile.in
+++ b/accessible/public/ia2/Makefile.in
@@ -1,18 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DEFFILE       = $(win_srcdir)/IA2Marshal.def
 
 IA2DIR        = $(topsrcdir)/other-licenses/ia2
 
-DEFINES       += -DREGISTER_PROXY_DLL
-
 GARBAGE       += $(MIDL_GENERATED_FILES)
 
 # Please keep this list in sync with the moz.build file until the rest of this
 # Makefile is ported over.
 MIDL_INTERFACES = \
   Accessible2.idl \
   Accessible2_2.idl \
   AccessibleAction.idl \
--- a/accessible/public/ia2/moz.build
+++ b/accessible/public/ia2/moz.build
@@ -2,8 +2,10 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LIBRARY_NAME = 'IA2Marshal'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['REGISTER_PROXY_DLL'] = True
--- a/accessible/public/msaa/Makefile.in
+++ b/accessible/public/msaa/Makefile.in
@@ -1,16 +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/.
 
 DEFFILE = $(win_srcdir)/AccessibleMarshal.def
 
-DEFINES += -DREGISTER_PROXY_DLL
-
 GARBAGE += $(MIDL_GENERATED_FILES) done_gen dlldata.c
 
 MIDL_GENERATED_FILES = \
 	ISimpleDOMNode.h \
 	ISimpleDOMNode_p.c \
 	ISimpleDOMNode_i.c \
 	ISimpleDOMDocument.h \
 	ISimpleDOMDocument_p.c \
--- a/accessible/public/msaa/moz.build
+++ b/accessible/public/msaa/moz.build
@@ -12,8 +12,10 @@ GENERATED_SOURCES += [
     'ISimpleDOMDocument_p.c',
     'ISimpleDOMNode_i.c',
     'ISimpleDOMNode_p.c',
     'ISimpleDOMText_i.c',
     'ISimpleDOMText_p.c',
 ]
 
 FORCE_SHARED_LIB = True
+
+DEFINES['REGISTER_PROXY_DLL'] = True
--- a/b2g/app/Makefile.in
+++ b/b2g/app/Makefile.in
@@ -2,20 +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
 
-ifdef ENABLE_MARIONETTE
-DEFINES += -DENABLE_MARIONETTE=1
-endif
-
 ifndef LIBXUL_SDK
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 LIBS += \
   -lui \
   -lEGL \
   -lhardware_legacy \
   -lhardware \
@@ -34,17 +30,16 @@ OS_LDFLAGS += -Wl,--export-dynamic
 LOCAL_INCLUDES += -I$(topsrcdir)/widget/gonk/libdisplay
 endif
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += $(JEMALLOC_LIBS)
 
 LIBS += \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(NULL)
 
@@ -78,22 +73,16 @@ INSTALL_TARGETS += UA_UPDATE
 
 # Make sure the standalone glue doesn't try to get libxpcom.so from b2g/app.
 NSDISTMODE = copy
 
 include $(topsrcdir)/config/rules.mk
 
 APP_ICON = b2g
 
-DEFINES += \
-  -DAPP_NAME=$(MOZ_APP_NAME) \
-  -DAPP_VERSION=$(MOZ_APP_VERSION) \
-  -DMOZ_UPDATER=$(MOZ_UPDATER) \
-  $(NULL)
-
 source_repo ?= $(call getSourceRepo,$(srcdir)/..)
 ifneq (,$(filter http%,$(source_repo)))
   DEFINES += -DMOZ_SOURCE_REPO="$(source_repo)"
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 REDIT_PATH = $(LIBXUL_DIST)/bin
 endif
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -7,8 +7,16 @@
 if not CONFIG['LIBXUL_SDK']:
     if CONFIG['GAIADIR']:
         PROGRAM = CONFIG['MOZ_APP_NAME'] + "-bin"
     else:
         PROGRAM = CONFIG['MOZ_APP_NAME']
     SOURCES += [
         'nsBrowserApp.cpp',
     ]
+
+if CONFIG['ENABLE_MARIONETTE']:
+    DEFINES['ENABLE_MARIONETTE'] = 1
+
+DEFINES['XPCOM_GLUE'] = True
+
+for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION', 'MOZ_UPDATER'):
+    DEFINES[var] = CONFIG[var]
deleted file mode 100644
--- a/b2g/chrome/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/.
-
-DEFINES += -DAB_CD=$(MOZ_UI_LOCALE) \
-           -DPACKAGE=browser \
-           -DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
-           $(NULL)
--- a/b2g/chrome/moz.build
+++ b/b2g/chrome/moz.build
@@ -1,6 +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/.
 
+DEFINES['AB_CD'] = CONFIG['MOZ_UI_LOCALE']
+DEFINES['PACKAGE'] = 'browser'
+DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
--- a/b2g/gaia/Makefile.in
+++ b/b2g/gaia/Makefile.in
@@ -1,26 +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
 
-ifeq ($(OS_ARCH),WINNT)
-DEFINES += \
-  -DB2G_NAME=L\"$(MOZ_APP_NAME)-bin$(BIN_SUFFIX)\" \
-  -DGAIA_PATH=L\"$(subst /,\\\\,$(GAIA_PATH))\" \
-  $(NULL)
-else # Non-windows machines use the same wrapper program
-DEFINES += \
-  -DB2G_NAME=\"$(MOZ_APP_NAME)-bin$(BIN_SUFFIX)\" \
-  -DGAIA_PATH=\"$(GAIA_PATH)\" \
-  $(NULL)
-endif
-
 ifdef .PYMAKE
 # For use of GNU make in pymake builds.
 GAIA_MAKE=$(GMAKE)
 else
 GAIA_MAKE=$(MAKE)
 endif
 
 # This is needed to avoid making run-b2g depend on mozglue
--- a/b2g/gaia/moz.build
+++ b/b2g/gaia/moz.build
@@ -5,12 +5,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 PROGRAM = CONFIG['MOZ_APP_NAME']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'run-b2g.cpp',
     ]
+    DEFINES['B2G_NAME'] = 'L"%s-bin%s"' % (PROGRAM, CONFIG['BIN_SUFFIX'])
+    DEFINES['GAIA_PATH'] = 'L"gaia\\\\profile"'
 else:
     SOURCES += [
         'run-b2g.c',
     ]
+    DEFINES['B2G_NAME'] = '"%s-bin%s"' % (PROGRAM, CONFIG['BIN_SUFFIX'])
+    DEFINES['GAIA_PATH'] = '"gaia/profile"'
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -1,54 +1,43 @@
 # 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_dest   = $(DIST)/$(MOZ_MACBUNDLE_NAME)
 
-ifdef ENABLE_MARIONETTE
-DEFINES += -DENABLE_MARIONETTE=1
-endif
-
 PREF_JS_EXPORTS = $(srcdir)/profile/firefox.js \
 		  $(NULL)
 
 
 # hardcode en-US for the moment
 AB_CD = en-US
 
 DEFINES += \
   -DAB_CD=$(AB_CD) \
-  -DAPP_VERSION="$(MOZ_APP_VERSION)" \
   -DFIREFOX_ICO=\"$(DIST)/branding/firefox.ico\" \
   -DDOCUMENT_ICO=\"$(DIST)/branding/document.ico\" \
   -DNEWWINDOW_ICO=\"$(DIST)/branding/newwindow.ico\" \
   -DNEWTAB_ICO=\"$(DIST)/branding/newtab.ico\" \
   -DPBMODE_ICO=\"$(DIST)/branding/pbmode.ico\" \
   $(NULL)
 
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL
-endif
-
 ifdef LIBXUL_SDK #{
 PREF_JS_EXPORTS += $(srcdir)/profile/channel-prefs.js
-DEFINES += -DLIBXUL_SDK
 endif #} LIBXUL_SDK
 
 # Build a binary bootstrapping with XRE_main
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/toolkit/xre \
   -I$(topsrcdir)/xpcom/base \
   -I$(topsrcdir)/xpcom/build \
   -I$(DEPTH)/build \
   $(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += \
 	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
 	$(NULL)
 
 ifdef MOZ_LINKER
 LIBS += $(MOZ_ZLIB_LIBS)
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -6,8 +6,19 @@
 
 DIRS += ['profile/extensions']
 
 PROGRAM = CONFIG['MOZ_APP_NAME']
 
 SOURCES += [
     'nsBrowserApp.cpp',
 ]
+
+if CONFIG['ENABLE_MARIONETTE']:
+    DEFINES['ENABLE_MARIONETTE'] = 1
+
+DEFINES['APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
+
+for var in ('MOZILLA_OFFICIAL', 'LIBXUL_SDK'):
+    if CONFIG[var]:
+        DEFINES[var] = True
+
+DEFINES['XPCOM_GLUE'] = True
deleted file mode 100644
--- a/browser/base/Makefile.in
+++ /dev/null
@@ -1,31 +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
-
-abs_srcdir = $(abspath $(srcdir))
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += \
-	-DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
-	-DAPP_LICENSE_BLOCK=$(abs_srcdir)/content/overrides/app-license.html \
-	$(NULL)
-
-ifneq (,$(filter windows gtk2 gtk3 cocoa, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DHAVE_SHELL_SERVICE=1
-endif
-
-ifneq (,$(filter windows cocoa gtk2 gtk3, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DCONTEXT_COPY_IMAGE_CONTENTS=1
-endif
-
-ifneq (,$(filter windows cocoa, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DCAN_DRAW_IN_TITLEBAR=1
-endif
-
-ifneq (,$(filter windows gtk2 gtk3, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DMENUBAR_CAN_AUTOHIDE=1
-endif
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -16,8 +16,21 @@ MOCHITEST_CHROME_MANIFESTS += [
     'content/test/chrome/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += [
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/social/browser.ini',
 ]
+
+DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
+DEFINES['APP_LICENSE_BLOCK'] = '%s/content/overrides/app-license.html' % SRCDIR
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3', 'cocoa'):
+    DEFINES['HAVE_SHELL_SERVICE'] = 1
+    DEFINES['CONTEXT_COPY_IMAGE_CONTENTS'] = 1
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'cocoa'):
+    DEFINES['CAN_DRAW_IN_TITLEBAR'] = 1
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3'):
+    DEFINES['MENUBAR_CAN_AUTOHIDE'] = 1
--- a/browser/branding/aurora/locales/Makefile.in
+++ b/browser/branding/aurora/locales/Makefile.in
@@ -1,5 +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/.
 
-DEFINES += -DAB_CD=$(AB_CD) -DMOZ_DISTRIBUTION_ID_UNQUOTED=$(MOZ_DISTRIBUTION_ID)
+DEFINES += -DAB_CD=$(AB_CD)
--- a/browser/branding/aurora/locales/moz.build
+++ b/browser/branding/aurora/locales/moz.build
@@ -1,6 +1,7 @@
 # -*- 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/.
 
+DEFINES['MOZ_DISTRIBUTION_ID_UNQUOTED'] = CONFIG['MOZ_DISTRIBUTION_ID']
--- a/browser/branding/nightly/locales/Makefile.in
+++ b/browser/branding/nightly/locales/Makefile.in
@@ -1,5 +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/.
 
-DEFINES += -DAB_CD=$(AB_CD) -DMOZ_DISTRIBUTION_ID_UNQUOTED=$(MOZ_DISTRIBUTION_ID)
+DEFINES += -DAB_CD=$(AB_CD)
--- a/browser/branding/nightly/locales/moz.build
+++ b/browser/branding/nightly/locales/moz.build
@@ -1,6 +1,7 @@
 # -*- 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/.
 
+DEFINES['MOZ_DISTRIBUTION_ID_UNQUOTED'] = CONFIG['MOZ_DISTRIBUTION_ID']
--- a/browser/branding/unofficial/locales/Makefile.in
+++ b/browser/branding/unofficial/locales/Makefile.in
@@ -1,5 +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/.
 
-DEFINES += -DAB_CD=$(AB_CD) -DMOZ_DISTRIBUTION_ID_UNQUOTED=$(MOZ_DISTRIBUTION_ID)
+DEFINES += -DAB_CD=$(AB_CD)
--- a/browser/branding/unofficial/locales/moz.build
+++ b/browser/branding/unofficial/locales/moz.build
@@ -1,6 +1,7 @@
 # -*- 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/.
 
+DEFINES['MOZ_DISTRIBUTION_ID_UNQUOTED'] = CONFIG['MOZ_DISTRIBUTION_ID']
--- a/browser/components/feeds/src/Makefile.in
+++ b/browser/components/feeds/src/Makefile.in
@@ -1,11 +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/.
 
-DEFINES += \
-	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-	-DMOZ_MACBUNDLE_NAME=$(MOZ_MACBUNDLE_NAME) \
-	$(NULL)
-
-
 LOCAL_INCLUDES = -I$(srcdir)/../../build
--- a/browser/components/feeds/src/moz.build
+++ b/browser/components/feeds/src/moz.build
@@ -14,8 +14,11 @@ EXTRA_COMPONENTS += [
     'WebContentConverter.js',
 ]
 
 EXTRA_PP_COMPONENTS += [
     'FeedWriter.js',
 ]
 
 FINAL_LIBRARY = 'browsercomps'
+
+for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'):
+    DEFINES[var] = CONFIG[var]
deleted file mode 100644
--- a/browser/components/migration/src/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/.
-
-ifeq ($(OS_ARCH),WINNT)
-
-DEFINES += -DHAS_IE_MIGRATOR -DHAS_SAFARI_MIGRATOR
-endif
-
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DHAS_SAFARI_MIGRATOR
-endif
--- a/browser/components/migration/src/moz.build
+++ b/browser/components/migration/src/moz.build
@@ -13,29 +13,32 @@ EXTRA_COMPONENTS += [
     'FirefoxProfileMigrator.js',
     'ProfileMigrator.js',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     EXTRA_COMPONENTS += [
         'IEProfileMigrator.js',
     ]
+    DEFINES['HAS_IE_MIGRATOR'] = True
 
 EXTRA_PP_COMPONENTS += [
     'BrowserProfileMigrators.manifest',
     'ChromeProfileMigrator.js',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     EXTRA_PP_COMPONENTS += [
         'SafariProfileMigrator.js',
     ]
+    DEFINES['HAS_SAFARI_MIGRATOR'] = True
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXTRA_PP_COMPONENTS += [
         'SafariProfileMigrator.js',
     ]
+    DEFINES['HAS_SAFARI_MIGRATOR'] = True
 
 EXTRA_PP_JS_MODULES += [
     'MigrationUtils.jsm',
 ]
 
 FINAL_LIBRARY = 'browsercomps'
deleted file mode 100644
--- a/browser/components/preferences/Makefile.in
+++ /dev/null
@@ -1,15 +0,0 @@
-# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
-# 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
-
-DEFINES += \
-	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-	-DMOZ_MACBUNDLE_NAME=$(MOZ_MACBUNDLE_NAME) \
-	$(NULL)
-
-ifneq (,$(filter windows gtk2 gtk3 cocoa, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DHAVE_SHELL_SERVICE=1
-endif
deleted file mode 100644
--- a/browser/components/preferences/in-content/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/rules.mk
-
-DEFINES += \
-	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-	-DMOZ_MACBUNDLE_NAME=$(MOZ_MACBUNDLE_NAME) \
-	$(NULL)
-
-ifneq (,$(filter windows gtk2 cocoa, $(MOZ_WIDGET_TOOLKIT)))
-DEFINES += -DHAVE_SHELL_SERVICE=1
-endif
--- a/browser/components/preferences/in-content/moz.build
+++ b/browser/components/preferences/in-content/moz.build
@@ -1,6 +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/.
 
+for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'):
+    DEFINES[var] = CONFIG[var]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'cocoa'):
+    DEFINES['HAVE_SHELL_SERVICE'] = 1
--- a/browser/components/preferences/moz.build
+++ b/browser/components/preferences/moz.build
@@ -5,8 +5,14 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 PARALLEL_DIRS += ['in-content']
 
 BROWSER_CHROME_MANIFESTS += [
     'in-content/tests/browser.ini',
     'tests/browser.ini',
 ]
+
+for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'):
+    DEFINES[var] = CONFIG[var]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3', 'cocoa'):
+    DEFINES['HAVE_SHELL_SERVICE'] = 1
--- a/browser/components/shell/src/Makefile.in
+++ b/browser/components/shell/src/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/.
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\" \
-  -DMOZ_APP_VERSION=\"$(MOZ_APP_VERSION)\"
-
 CXXFLAGS += $(TK_CFLAGS)
 
 clobber::
 	rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
--- a/browser/components/shell/src/moz.build
+++ b/browser/components/shell/src/moz.build
@@ -19,8 +19,11 @@ elif CONFIG['MOZ_WIDGET_GTK']:
 
 if SOURCES:
     FINAL_LIBRARY = 'browsercomps'
 
 EXTRA_COMPONENTS += [
     'nsSetDefaultBrowser.js',
     'nsSetDefaultBrowser.manifest',
 ]
+
+for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
--- a/browser/metro/Makefile.in
+++ b/browser/metro/Makefile.in
@@ -2,22 +2,18 @@
 # 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
 
 #########################################
 # application.ini
 
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL
-endif
-
 GRE_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DGRE_BUILDID=$(GRE_BUILDID)
+DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 # 'application.ini' breaks firefox build config. So we use something different.
 metroapp.ini: metroapp.ini.in $(DEPTH)/config/buildid $(topsrcdir)/config/milestone.txt
 	$(RM) "metroapp.ini"
 	$(call py_action,preprocessor,$(DEFINES) $< -o $@)
 
 libs:: metroapp.ini
 	$(INSTALL) metroapp.ini $(FINAL_TARGET)
deleted file mode 100644
--- a/browser/metro/base/Makefile.in
+++ /dev/null
@@ -1,10 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-include $(topsrcdir)/config/config.mk
-
-DEFINES += -DAB_CD=$(MOZ_UI_LOCALE) \
-           -DPACKAGE=browser \
-           -DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
-           $(NULL)
--- a/browser/metro/base/moz.build
+++ b/browser/metro/base/moz.build
@@ -3,8 +3,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/.
 
 METRO_CHROME_MANIFESTS += ['tests/mochiperf/metro.ini', 'tests/mochitest/metro.ini']
 XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
 
 DIST_SUBDIR = 'metro'
+
+DEFINES['AB_CD'] = CONFIG['MOZ_UI_LOCALE']
+DEFINES['PACKAGE'] = 'browser'
+DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
--- a/browser/metro/moz.build
+++ b/browser/metro/moz.build
@@ -12,8 +12,13 @@ DIRS += [
     'profile',
     'locales',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DIRS += ['shell']
 
 DIST_SUBDIR = 'metro'
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
+
+DEFINES['GRE_MILESTONE'] = CONFIG['GRE_MILESTONE']
--- a/browser/metro/shell/commandexecutehandler/Makefile.in
+++ b/browser/metro/shell/commandexecutehandler/Makefile.in
@@ -16,10 +16,8 @@ OS_LIBS = \
 	kernel32.lib \
 	user32.lib \
 	ole32.lib \
 	shlwapi.lib \
 	propsys.lib \
 	advapi32.lib \
 	wininet.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE -DNS_NO_XPCOM
--- a/browser/metro/shell/commandexecutehandler/moz.build
+++ b/browser/metro/shell/commandexecutehandler/moz.build
@@ -8,8 +8,11 @@ PROGRAM = 'CommandExecuteHandler'
 
 SOURCES += [
     'CEHHelper.cpp',
     'CommandExecuteHandler.cpp',
 ]
 
 # We want this exe in dist/bin
 DIST_SUBDIR = ''
+
+for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM'):
+    DEFINES[var] = True
--- a/browser/metro/shell/linktool/Makefile.in
+++ b/browser/metro/shell/linktool/Makefile.in
@@ -9,10 +9,8 @@ include $(topsrcdir)/config/config.mk
 OS_LIBS = \
 	kernel32.lib \
 	user32.lib \
 	ole32.lib \
 	shlwapi.lib \
 	shell32.lib \
 	propsys.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE
--- a/browser/metro/shell/linktool/moz.build
+++ b/browser/metro/shell/linktool/moz.build
@@ -6,8 +6,11 @@
 
 PROGRAM = 'linktool'
 
 SOURCES += [
     'linktool.cpp',
 ]
 
 DIST_SUBDIR = 'metro/install'
+
+for var in ('UNICODE', '_UNICODE'):
+    DEFINES[var] = True
--- a/browser/metro/shell/testing/Makefile.in
+++ b/browser/metro/shell/testing/Makefile.in
@@ -16,10 +16,8 @@ include $(topsrcdir)/config/config.mk
 OS_LIBS = \
 	kernel32.lib \
 	user32.lib \
 	ole32.lib \
 	shlwapi.lib \
 	propsys.lib \
 	advapi32.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE
--- a/browser/metro/shell/testing/moz.build
+++ b/browser/metro/shell/testing/moz.build
@@ -7,8 +7,11 @@
 PROGRAM = 'metrotestharness'
 
 SOURCES += [
     'metrotestharness.cpp',
 ]
 
 # We want this exe in dist/bin
 DIST_SUBDIR = ''
+
+for var in ('UNICODE', '_UNICODE'):
+    DEFINES[var] = True
deleted file mode 100644
--- a/browser/modules/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/.
-
-include $(topsrcdir)/config/config.mk
-
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL=1
-endif
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -29,8 +29,10 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
         'WindowsPreviewPerTab.jsm',
     ]
 
 EXTRA_PP_JS_MODULES += [
     'AboutHome.jsm',
     'RecentWindow.jsm',
 ]
 
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = 1
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -19,59 +19,30 @@ ifdef LIBXUL_SDK
 APP_INI_DEPS = $(LIBXUL_DIST)/bin/platform.ini
 else
 APP_INI_DEPS = $(topsrcdir)/config/milestone.txt
 endif
 
 APP_BUILDID := $(shell cat $(DEPTH)/config/buildid)
 APP_INI_DEPS += $(DEPTH)/config/buildid
 
-DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DAPP_BUILDID=$(APP_BUILDID)
+DEFINES += -DAPP_BUILDID=$(APP_BUILDID)
 
-DEFINES += -DMOZ_APP_VERSION="$(MOZ_APP_VERSION)"
 APP_INI_DEPS += $(DEPTH)/config/autoconf.mk
 
 MOZ_SOURCE_STAMP := $(firstword $(shell cd $(topsrcdir)/$(MOZ_BUILD_APP)/.. && hg parent --template="{node|short}\n" 2>/dev/null))
 ifdef MOZ_SOURCE_STAMP
 DEFINES += -DMOZ_SOURCE_STAMP="$(MOZ_SOURCE_STAMP)"
 endif
 
 source_repo ?= $(call getSourceRepo,$(topsrcdir)/$(MOZ_BUILD_APP)/..)
 ifneq (,$(source_repo))
   DEFINES += -DMOZ_SOURCE_REPO="$(source_repo)"
 endif
 
-DEFINES += \
-  -DMOZ_APP_BASENAME="$(MOZ_APP_BASENAME)" \
-  -DMOZ_APP_VENDOR="$(MOZ_APP_VENDOR)" \
-  -DMOZ_APP_ID="$(MOZ_APP_ID)" \
-  -DMAR_CHANNEL_ID="$(MAR_CHANNEL_ID)" \
-  -DACCEPTED_MAR_CHANNEL_IDS="$(ACCEPTED_MAR_CHANNEL_IDS)" \
-  $(NULL)
-
-ifeq ($(MOZ_BUILD_APP),browser)
-DEFINES += -DMOZ_BUILD_APP_IS_BROWSER
-endif
-
-ifdef MOZ_APP_PROFILE
-DEFINES += -DMOZ_APP_PROFILE="$(MOZ_APP_PROFILE)"
-endif
-
-ifdef MOZ_CRASHREPORTER
-DEFINES += -DMOZ_CRASHREPORTER
-endif
-
-ifdef MOZ_PROFILE_MIGRATOR
-DEFINES += -DMOZ_PROFILE_MIGRATOR
-endif
-
-ifdef MOZ_EXTENSION_MANAGER
-DEFINES += -DMOZ_EXTENSION_MANAGER
-endif
-
 endif
 
 # Put a useful .gdbinit in the bin directory, to be picked up automatically
 # by GDB when we debug executables there.
 # NOTE: Keep .gdbinit in the topsrcdir for people who run gdb from the topsrcdir.
 GDBINIT_FILES := $(topsrcdir)/.gdbinit
 GDBINIT_DEST = $(FINAL_TARGET)
 INSTALL_TARGETS += GDBINIT
@@ -118,18 +89,16 @@ leaktest.py: leaktest.py.in
 	$(call py_action,preprocessor,$^ -o $@)
 	chmod +x $@
 GARBAGE += leaktest.py
 
 ifdef MOZ_APP_BASENAME
 $(FINAL_TARGET)/application.ini: $(APP_INI_DEPS)
 
 ifdef MOZ_APP_STATIC_INI
-DEFINES += -DMOZ_APP_STATIC_INI
-
 application.ini.h: appini_header.py $(FINAL_TARGET)/application.ini
 	$(PYTHON) $^ > $@
 export:: application.ini.h
 GARBAGE += application.ini.h
 endif
 endif
 
 libs:: $(_LEAKTEST_FILES)
--- a/build/mobile/robocop/Makefile.in
+++ b/build/mobile/robocop/Makefile.in
@@ -70,20 +70,16 @@ GARBAGE += \
 
 JAVAFILES += \
   $(java-harness) \
   $(java-tests) \
   $(robocop-deps) \
   $(testconstants-dep) \
   $(NULL)
 
-DEFINES += \
-  -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
-  $(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 tools:: $(ANDROID_APK_NAME).apk
 
 GENERATED_DIRS += $(dir-tests)
 
 # The test APK needs to know the contents of the target APK while not
 # being linked against them.  This is a best effort to avoid getting
--- a/build/mobile/robocop/moz.build
+++ b/build/mobile/robocop/moz.build
@@ -2,8 +2,10 @@
 # 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/.
 
 ANDROID_RESFILES = [
     'res/values/strings.xml',
 ]
+
+DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
--- a/build/moz.build
+++ b/build/moz.build
@@ -17,8 +17,24 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
     TEST_DIRS += [
         'mobile/sutagent/android',
         'mobile/sutagent/android/watcher',
         'mobile/sutagent/android/ffxcp',
         'mobile/sutagent/android/fencp',
         'mobile/robocop',
     ]
 
+for var in ('GRE_MILESTONE', 'MOZ_APP_VERSION', 'MOZ_APP_BASENAME',
+            'MOZ_APP_VENDOR', 'MOZ_APP_ID', 'MAR_CHANNEL_ID',
+            'ACCEPTED_MAR_CHANNEL_IDS'):
+    DEFINES[var] = CONFIG[var]
+
+if CONFIG['MOZ_BUILD_APP'] == 'browser':
+    DEFINES['MOZ_BUILD_APP_IS_BROWSER'] = True
+
+if CONFIG['MOZ_APP_PROFILE']:
+    DEFINES['MOZ_APP_PROFILE'] = CONFIG['MOZ_APP_PROFILE']
+
+for var in ('MOZ_CRASHREPORTER', 'MOZ_PROFILE_MIGRATOR',
+            'MOZ_EXTENSION_MANAGER', 'MOZ_APP_STATIC_INI'):
+    if CONFIG[var]:
+        DEFINES[var] = True
+
--- a/build/stlport/Makefile.in
+++ b/build/stlport/Makefile.in
@@ -6,11 +6,10 @@ MODULES = stlport
 STL_FLAGS =
 
 # Force to build a static library, instead of a fake library, without
 # installing it in dist/lib.
 LIBRARY = $(LIB_PREFIX)$(LIBRARY_NAME).$(LIB_SUFFIX)
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -D_GNU_SOURCE
 CXXFLAGS += -fuse-cxa-atexit
 INCLUDES += -I$(srcdir)/stlport
--- a/build/stlport/moz.build
+++ b/build/stlport/moz.build
@@ -40,8 +40,10 @@ SOURCES += [
     'src/strstream.cpp',
     'src/time_facets.cpp',
 ]
 
 SOURCES += [
     'src/c_locale.c',
     'src/cxa.c',
 ]
+
+DEFINES['_GNU_SOURCE'] = True
--- a/build/unix/elfhack/Makefile.in
+++ b/build/unix/elfhack/Makefile.in
@@ -10,18 +10,16 @@ NO_PROFILE_GUIDED_OPTIMIZE = 1
 VPATH += $(topsrcdir)/build
 
 OS_CXXFLAGS := $(filter-out -fno-exceptions,$(OS_CXXFLAGS)) -fexceptions
 
 WRAP_LDFLAGS=
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DELFHACK_BUILD
-
 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.
 	@echo ===
 	# Fail if the library doesn't have $(DT_TYPE) .dynamic info
--- a/build/unix/elfhack/inject/Makefile.in
+++ b/build/unix/elfhack/inject/Makefile.in
@@ -10,11 +10,9 @@ include $(topsrcdir)/config/rules.mk
 
 export:: $(CSRCS:.c=.$(OBJ_SUFFIX))
 
 $(CSRCS): %.c: ../inject.c
 	cp $< $@
 
 GARBAGE += $(CSRCS)
 
-DEFINES += -DELFHACK_BUILD
-
 CFLAGS := -O2 -fno-stack-protector $(filter -m% -I%,$(CFLAGS))
--- a/build/unix/elfhack/inject/moz.build
+++ b/build/unix/elfhack/inject/moz.build
@@ -11,8 +11,10 @@ if CONFIG['TARGET_CPU'].endswith('86'):
 elif CONFIG['TARGET_CPU'].startswith('arm'):
     cpu = 'arm'
 else:
     cpu = CONFIG['TARGET_CPU']
 
 GENERATED_SOURCES += [
     "%s.c" % cpu,
 ]
+
+DEFINES['ELFHACK_BUILD'] = True
--- a/build/unix/elfhack/moz.build
+++ b/build/unix/elfhack/moz.build
@@ -18,8 +18,10 @@ if not CONFIG['CROSS_COMPILE']:
     ]
 
 HOST_SOURCES += [
     'elf.cpp',
     'elfhack.cpp',
 ]
 
 HOST_PROGRAM = 'elfhack'
+
+DEFINES['ELFHACK_BUILD'] = True
--- a/db/sqlite3/src/Makefile.in
+++ b/db/sqlite3/src/Makefile.in
@@ -41,78 +41,21 @@ MODULE_OPTIMIZE_FLAGS = -O2
 endif
 
 # Force /O2 optimisation on Windows because using the default /O1 causes
 # crashes with MSVC2005 and PGO. See bug 719584.
 ifeq ($(OS_ARCH),WINNT)
 MODULE_OPTIMIZE_FLAGS = -O2
 endif
 
-# -DSQLITE_SECURE_DELETE=1 will cause SQLITE to 0-fill delete data so we
-# don't have to vacuum to make sure the data is not visible in the file.
-# -DSQLITE_ENABLE_FTS3=1 enables the full-text index module.
-# -DSQLITE_CORE=1 statically links that module into the SQLite library.
-# -DSQLITE_DEFAULT_PAGE_SIZE=32768 and SQLITE_MAX_DEFAULT_PAGE_SIZE=32768
-# increases the page size from 1k, see bug 416330.  It must be kept in sync with
-# the value of PREF_TS_PAGESIZE_DEFAULT in mozStorageService.cpp.  The value can
-# be overridden on a per-platform basis through the use of the PREF_TS_PAGESIZE
-# hidden preference.  If that preference is missing or invalid then this value
-# will be used.
-# -DSQLITE_MAX_SCHEMA_RETRY increases the times SQLite may try to reparse
-# statements when the schema changes. This is important when supporting lots of
-# concurrent connections, especially when they use shared cache.
-# Note: Be sure to update the configure.in checks when these change!
-DEFINES = \
-  -DSQLITE_SECURE_DELETE=1 \
-  -DSQLITE_THREADSAFE=1 \
-  -DSQLITE_CORE=1 \
-  -DSQLITE_ENABLE_FTS3=1 \
-  -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 \
-  -DSQLITE_DEFAULT_PAGE_SIZE=32768 \
-  -DSQLITE_MAX_DEFAULT_PAGE_SIZE=32768 \
-  -DSQLITE_MAX_SCHEMA_RETRY=25 \
-  $(NULL)
-
-# -DSQLITE_ENABLE_LOCKING_STYLE=1 to help with AFP folders
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-DEFINES += -DSQLITE_ENABLE_LOCKING_STYLE=1
-endif
-
-# Turn on SQLite's assertions in debug builds.
-ifdef MOZ_DEBUG
-DEFINES += -DSQLITE_DEBUG=1
-endif
-
 # disable PGO for Sun Studio
 ifdef SOLARIS_SUNPRO_CC
 NO_PROFILE_GUIDED_OPTIMIZE = 1
 endif
 
-ifeq ($(OS_ARCH),OS2)
-ifdef MOZ_OS2_HIGH_MEMORY
-DEFINES += -DOS2_HIGH_MEMORY
-endif
-endif
-
-ifeq ($(OS_TARGET),Android)
-# default to user readable only to fit Android security model
-DEFINES += -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600
-endif
-
-# Force using malloc_usable_size when building with jemalloc because _msize
-# causes assertions on Win64. See bug 719579.
-ifeq ($(OS_ARCH),WINNT)
-ifdef MOZ_MEMORY
-DEFINES += \
-  -DHAVE_MALLOC_USABLE_SIZE \
-  -DSQLITE_WITHOUT_MSIZE \
-  $(NULL)
-endif
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 # next line allows use of MOZ_OBJDIR in .mozconfig with older gcc on BeOS, maybe others
 LOCAL_INCLUDES += -I$(srcdir)
 
 ifeq ($(OS_ARCH),OS2)
 ADD_TO_DEF_FILE = $(PYTHON) -m mozbuild.action.preprocessor $(DEFINES) \
        $(srcdir)/sqlite.def | sed -e '1,/^EXPORTS$$/ d' -e 's,sqlite3,_\0,' \
--- a/db/sqlite3/src/moz.build
+++ b/db/sqlite3/src/moz.build
@@ -14,8 +14,51 @@ LIBRARY_NAME = 'mozsqlite3'
 SOURCES += [
     'sqlite3.c',
 ]
 
 if CONFIG['MOZ_FOLD_LIBS']:
     FORCE_STATIC_LIB = True
 else:
     FORCE_SHARED_LIB = True
+
+# -DSQLITE_SECURE_DELETE=1 will cause SQLITE to 0-fill delete data so we
+# don't have to vacuum to make sure the data is not visible in the file.
+# -DSQLITE_ENABLE_FTS3=1 enables the full-text index module.
+# -DSQLITE_CORE=1 statically links that module into the SQLite library.
+# -DSQLITE_DEFAULT_PAGE_SIZE=32768 and SQLITE_MAX_DEFAULT_PAGE_SIZE=32768
+# increases the page size from 1k, see bug 416330.  It must be kept in sync with
+# the value of PREF_TS_PAGESIZE_DEFAULT in mozStorageService.cpp.  The value can
+# be overridden on a per-platform basis through the use of the PREF_TS_PAGESIZE
+# hidden preference.  If that preference is missing or invalid then this value
+# will be used.
+# -DSQLITE_MAX_SCHEMA_RETRY increases the times SQLite may try to reparse
+# statements when the schema changes. This is important when supporting lots of
+# concurrent connections, especially when they use shared cache.
+# Note: Be sure to update the configure.in checks when these change!
+for var in ('SQLITE_SECURE_DELETE', 'SQLITE_THREADSAFE', 'SQLITE_CORE',
+            'SQLITE_ENABLE_FTS3', 'SQLITE_ENABLE_UNLOCK_NOTIFY'):
+    DEFINES[var] = 1
+
+DEFINES['SQLITE_DEFAULT_PAGE_SIZE'] = 32768
+DEFINES['SQLITE_MAX_DEFAULT_PAGE_SIZE'] = 32768
+DEFINES['SQLITE_MAX_SCHEMA_RETRY'] = 25
+
+# -DSQLITE_ENABLE_LOCKING_STYLE=1 to help with AFP folders
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    DEFINES['SQLITE_ENABLE_LOCKING_STYLE'] = 1
+
+# Turn on SQLite's assertions in debug builds.
+if CONFIG['MOZ_DEBUG']:
+    DEFINES['SQLITE_DEBUG'] = 1
+
+if CONFIG['OS_ARCH'] == 'OS2' and CONFIG['MOZ_OS2_HIGH_MEMORY']:
+    DEFINES['OS2_HIGH_MEMORY'] = True
+
+if CONFIG['OS_TARGET'] == 'Android':
+    # default to user readable only to fit Android security model
+    DEFINES['SQLITE_DEFAULT_FILE_PERMISSIONS'] = '0600'
+
+# Force using malloc_usable_size when building with jemalloc because _msize
+# causes assertions on Win64. See bug 719579.
+if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_MEMORY']:
+    DEFINES['HAVE_MALLOC_USABLE_SIZE'] = True
+    DEFINES['SQLITE_WITHOUT_MSIZE'] = True
--- a/dom/base/Makefile.in
+++ b/dom/base/Makefile.in
@@ -1,22 +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_JSDEBUGGER
-DEFINES += -DMOZ_JSDEBUGGER
-endif
-
-ifdef MOZ_B2G_RIL
-DEFINES += -DMOZ_B2G_RIL
-endif
-
-ifdef MOZ_B2G_FM
-DEFINES += -DMOZ_B2G_FM
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_X11
 CXXFLAGS += $(TK_CFLAGS)
 LDFLAGS += $(TK_LIBS)
 endif
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -159,8 +159,11 @@ include('/ipc/chromium/chromium-config.m
 FINAL_LIBRARY = 'gklayout'
 
 LOCAL_INCLUDES += [
     '/js/xpconnect/src',
     '/js/xpconnect/wrappers',
     '/xpcom/ds',
 ]
 
+for var in ('MOZ_JSDEBUGGER', 'MOZ_B2G_RIL', 'MOZ_B2G_FM'):
+    if CONFIG[var]:
+        DEFINES[var] = True
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -14,30 +14,22 @@
 
 VPATH += $(srcdir)/ipc
 
 ifneq (,$(MOZ_B2G_BT))
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 ifdef MOZ_B2G_BT_BLUEZ
 LOCAL_INCLUDES += $(MOZ_DBUS_CFLAGS)
-DEFINES += -DMOZ_B2G_BT_BLUEZ
-else
-ifdef MOZ_B2G_BT_BLUEDROID
-DEFINES += -DMOZ_B2G_BT_BLUEDROID
-endif #MOZ_B2G_BT_BLUEDROID
 endif #MOZ_B2G_BT_BLUEZ
 else
 ifdef MOZ_ENABLE_DBUS
 LOCAL_INCLUDES += $(MOZ_DBUS_CFLAGS)
 CFLAGS += $(MOZ_DBUS_GLIB_CFLAGS)
 CXXFLAGS += $(MOZ_DBUS_GLIB_CFLAGS) -DHAVE_PTHREADS
-DEFINES += -DMOZ_BLUETOOTH_DBUS
 endif #MOZ_ENABLE_DBUS
 endif #MOZ_WIDGET_TOOLKIT
 
 # Add VPATH to LOCAL_INCLUDES so we are going to include the correct backend
 # subdirectory.
 LOCAL_INCLUDES += $(VPATH:%=-I%)
 
 endif #MOZ_B2G_BT
-
-include $(topsrcdir)/config/rules.mk
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -40,35 +40,38 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluez/gonk/BluetoothGonkService.cpp',
                 'bluez/linux/BluetoothDBusService.cpp',
             ]
             LOCAL_INCLUDES += [
                 'bluez',
                 'bluez/gonk',
                 'bluez/linux',
             ]
+            DEFINES['MOZ_B2G_BT_BLUEZ'] = True
         elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
             SOURCES += [
                 'bluedroid/BluetoothA2dpManager.cpp',
                 'bluedroid/BluetoothHfpManager.cpp',
                 'bluedroid/gonk/BluetoothServiceBluedroid.cpp',
             ]
             LOCAL_INCLUDES += [
                 'bluedroid',
                 'bluedroid/gonk',
             ]
+            DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
     elif CONFIG['MOZ_ENABLE_DBUS']:
         SOURCES += [
             'bluez/BluetoothHfpManager.cpp',
             'bluez/linux/BluetoothDBusService.cpp',
         ]
         LOCAL_INCLUDES += [
             'bluez',
             'bluez/linux',
         ]
+        DEFINES['MOZ_BLUETOOTH_DBUS'] = True
 
     FINAL_LIBRARY = 'gklayout'
 
 EXPORTS.mozilla.dom.bluetooth.ipc += [
     'ipc/BluetoothMessageUtils.h',
 ]
 
 EXPORTS.mozilla.dom.bluetooth += [
--- a/dom/ipc/Makefile.in
+++ b/dom/ipc/Makefile.in
@@ -1,21 +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/.
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gonk qt))
-DEFINES += -DMOZ_ENABLE_FREETYPE
-endif
-
-ifdef MOZ_PERMISSIONS
-DEFINES += -DMOZ_PERMISSIONS
-endif
-
-ifdef MOZ_CHILD_PERMISSIONS
-DEFINES += -DMOZ_CHILD_PERMISSIONS
-endif
-
 CXXFLAGS += $(TK_CFLAGS)
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -103,8 +103,16 @@ LOCAL_INCLUDES += [
     '/layout/base',
     '/netwerk/base/src',
     '/toolkit/xre',
     '/uriloader/exthandler',
     '/widget/xpwidgets',
     '/xpcom/base',
 ]
 
+DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX']
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gonk', 'qt'):
+    DEFINES['MOZ_ENABLE_FREETYPE'] = True
+
+for var in ('MOZ_PERMISSIONS', 'MOZ_CHILD_PERMISSIONS'):
+    if CONFIG[var]:
+        DEFINES[var] = True
--- a/dom/plugins/ipc/hangui/Makefile.in
+++ b/dom/plugins/ipc/hangui/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/.
 
 OS_LIBS = $(call EXPAND_LIBNAME,comctl32)
 
 RCINCLUDE = HangUIDlg.rc
 
-DEFINES += \
-  -DNS_NO_XPCOM \
-  $(NULL)
-
 STL_FLAGS = \
   -D_HAS_EXCEPTIONS=0 \
   $(NULL)
 
 MOZ_GLUE_LDFLAGS =
 
 include $(topsrcdir)/config/rules.mk
 
--- a/dom/plugins/ipc/hangui/moz.build
+++ b/dom/plugins/ipc/hangui/moz.build
@@ -9,8 +9,9 @@ FAIL_ON_WARNINGS = True
 PROGRAM = 'plugin-hang-ui'
 
 UNIFIED_SOURCES += [
     'MiniShmChild.cpp',
     'PluginHangUIChild.cpp',
 ]
 include('/ipc/chromium/chromium-config.mozbuild')
 
+DEFINES['NS_NO_XPCOM'] = True
--- a/embedding/tests/winEmbed/Makefile.in
+++ b/embedding/tests/winEmbed/Makefile.in
@@ -29,17 +29,16 @@
 
 RESFILE		= winEmbed.res
 
 LIBS = \
 	$(DEPTH)/profile/dirserviceprovider/standalone/$(LIB_PREFIX)profdirserviceprovidersa_s.$(LIB_SUFFIX) \
 	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
 	$(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 OS_LIBS		+= $(call EXPAND_LIBNAME,ole32 comdlg32 shell32 version)
 
 include $(topsrcdir)/config/rules.mk
 
 #
 # Control the default heap size.
--- a/embedding/tests/winEmbed/moz.build
+++ b/embedding/tests/winEmbed/moz.build
@@ -8,8 +8,10 @@ PROGRAM = 'winEmbed'
 
 SOURCES += [
     'WebBrowserChrome.cpp',
     'WindowCreator.cpp',
     'winEmbed.cpp',
 ]
 
 XPI_NAME = 'winembed'
+
+DEFINES['XPCOM_GLUE'] = True
--- a/extensions/spellcheck/hunspell/src/Makefile.in
+++ b/extensions/spellcheck/hunspell/src/Makefile.in
@@ -1,18 +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/.
 
-ifndef MOZ_NATIVE_HUNSPELL
-# This variable is referenced in configure.in.  Make sure to change that file
-# too if you need to change this variable.
-DEFINES = -DHUNSPELL_STATIC
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES        += -I$(topsrcdir)/extensions/spellcheck/src
 
 ifdef MOZ_NATIVE_HUNSPELL
 # MOZ_HUNSPELL_CFLAGS is extracted through pkgconfig during configure,
 # even though the variable doesn't show up in configure.in.
 CXXFLAGS += $(MOZ_HUNSPELL_CFLAGS)
--- a/extensions/spellcheck/hunspell/src/moz.build
+++ b/extensions/spellcheck/hunspell/src/moz.build
@@ -18,10 +18,13 @@ if not CONFIG['MOZ_NATIVE_HUNSPELL']:
         'filemgr.cpp',
         'hashmgr.cpp',
         'hunspell.cpp',
         'hunzip.cpp',
         'phonet.cpp',
         'replist.cpp',
         'suggestmgr.cpp',
     ]
+    # This variable is referenced in configure.in.  Make sure to change that file
+    # too if you need to change this variable.
+    DEFINES['HUNSPELL_STATIC'] = True
 
 FINAL_LIBRARY = 'spellchecker'
--- a/gfx/2d/Makefile.in
+++ b/gfx/2d/Makefile.in
@@ -1,49 +1,19 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 VPATH		=  $(srcdir) $(srcdir)/unittest
 
-DEFINES += -DMOZ_GFX -DUSE_CAIRO -DGFX2D_INTERNAL -DMOZ2D_HAS_MOZ_CAIRO
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gtk3 gonk qt))
-DEFINES += -DMOZ_ENABLE_FREETYPE
 OS_CXXFLAGS += $(CAIRO_FT_CFLAGS)
 endif
 
-DEFINES += -DSK_A32_SHIFT=24 -DSK_R32_SHIFT=16 -DSK_G32_SHIFT=8 -DSK_B32_SHIFT=0
-
-ifdef MOZ_DEBUG
-DEFINES += -DGFX_LOG_DEBUG -DGFX_LOG_WARNING
-endif
-
-# Are we targeting x86 or x64?  If so, build SSE2 files.
-ifneq (,$(INTEL_ARCHITECTURE))
-# VC2005 doesn't support _mm_castsi128_ps, so SSE2 is turned off
-ifneq (1400,$(_MSC_VER))
-DEFINES += -DUSE_SSE2
-endif
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-DEFINES += -DWIN32 -DINITGUID
-
-ifdef MOZ_ENABLE_SKIA
-DEFINES += -DSKIA_IMPLEMENTATION=1 -DGR_IMPLEMENTATION=1
-endif
-
-# For Direct2D 1.1 we require WINSDK_MAXVER 0x06020000 or higher.
-ifdef MOZ_ENABLE_DIRECT2D1_1
-DEFINES += -DUSE_D2D1_1
-endif
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 # Due to bug 796023, we can't have -DUNICODE and -D_UNICODE; defining those
 # macros changes the type of LOGFONT to LOGFONTW instead of LOGFONTA. This
 # changes the symbol names of exported C++ functions that use LOGFONT.
 DEFINES := $(filter-out -DUNICODE -D_UNICODE,$(DEFINES))
 
 # The file uses SSE2 intrinsics, so it needs special compile flags on some
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -46,27 +46,33 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     SOURCES += [
         'DrawTargetD2D.cpp',
         'PathD2D.cpp',
         'ScaledFontDWrite.cpp',
         'SourceSurfaceD2D.cpp',
         'SourceSurfaceD2DTarget.cpp',
     ]
+    DEFINES['WIN32'] = True
+    DEFINES['INITGUID'] = True
+    # For Direct2D 1.1 we require WINSDK_MAXVER 0x06020000 or higher.
     if CONFIG['MOZ_ENABLE_DIRECT2D1_1']:
         SOURCES += [
             'DrawTargetD2D1.cpp',
             'FilterNodeD2D1.cpp',
             'RadialGradientEffectD2D1.cpp',
             'SourceSurfaceD2D1.cpp'
         ]
+        DEFINES['USE_D2D1_1'] = True
     if CONFIG['MOZ_ENABLE_SKIA']:
         SOURCES += [
             'ScaledFontWin.cpp',
         ]
+        DEFINES['SKIA_IMPLEMENTATION'] = 1
+        DEFINES['GR_IMPLEMENTATION'] = 1
 
 if CONFIG['MOZ_ENABLE_SKIA']:
     UNIFIED_SOURCES += [
         'convolver.cpp',
         'DrawTargetSkia.cpp',
         'PathSkia.cpp',
         'SourceSurfaceSkia.cpp',
     ]
@@ -78,16 +84,17 @@ if CONFIG['MOZ_ENABLE_SKIA']:
 if CONFIG['INTEL_ARCHITECTURE']:
     # VC2005 doesn't support _mm_castsi128_ps, so SSE2 is turned off
     if CONFIG['_MSC_VER'] != '1400':
         SOURCES += [
             'BlurSSE2.cpp',
             'FilterProcessingSSE2.cpp',
             'ImageScalingSSE2.cpp',
         ]
+        DEFINES['USE_SSE2'] = True
 
 UNIFIED_SOURCES += [
     'Blur.cpp',
     'DataSourceSurface.cpp',
     'DrawEventRecorder.cpp',
     'DrawTargetCairo.cpp',
     'DrawTargetDual.cpp',
     'DrawTargetRecording.cpp',
@@ -117,8 +124,23 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'gkmedias'
+
+for var in ('MOZ_GFX', 'USE_CAIRO', 'GFX2D_INTERNAL', 'MOZ2D_HAS_MOZ_CAIRO'):
+    DEFINES[var] = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk', 'qt'):
+    DEFINES['MOZ_ENABLE_FREETYPE'] = True
+
+DEFINES['SK_A32_SHIFT'] = 24
+DEFINES['SK_R32_SHIFT'] = 16
+DEFINES['SK_G32_SHIFT'] = 8
+DEFINES['SK_B32_SHIFT'] = 0
+
+if CONFIG['MOZ_DEBUG']:
+    DEFINES['GFX_LOG_DEBUG'] = True
+    DEFINES['GFX_LOG_WARNING'] = True
--- a/gfx/angle/Makefile.in
+++ b/gfx/angle/Makefile.in
@@ -1,29 +1,24 @@
 # 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 below is a rough translation of build_angle.gypi:
-DEFINES += -DANGLE_DISABLE_TRACE
-DEFINES += -DANGLE_COMPILE_OPTIMIZATION_LEVEL=D3DCOMPILE_OPTIMIZATION_LEVEL1
-
 # Target: 'preprocessor'
 # src/compiler/preprocessor:
 VPATH += $(srcdir)/src/compiler/preprocessor
 
 # Target: 'translator_common'
 #   Requires: 'preprocessor'
 LOCAL_INCLUDES += \
   -I$(srcdir)/include \
   -I$(srcdir)/include/KHR \
   -I$(srcdir)/src
 
-DEFINES += -DCOMPILER_IMPLEMENTATION
-
 VPATH += $(srcdir)/src/compiler
 VPATH += $(srcdir)/src/compiler/depgraph
 VPATH += $(srcdir)/src/compiler/timing
 VPATH += $(srcdir)/src/third_party/compiler
 VPATH += $(srcdir)/src/third_party/murmurhash
 
 # Target: 'translator_glsl'
 #   Requires: 'translator_common'
--- a/gfx/angle/moz.build
+++ b/gfx/angle/moz.build
@@ -118,8 +118,12 @@ UNIFIED_SOURCES += ['src/compiler/' + sr
     'VersionGLSL.cpp',
 ]]
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['ANGLE_DISABLE_TRACE'] = True
+DEFINES['ANGLE_COMPILE_OPTIMIZATION_LEVEL'] = 'D3DCOMPILE_OPTIMIZATION_LEVEL1'
+DEFINES['COMPILER_IMPLEMENTATION'] = True
--- a/gfx/angle/src/libEGL/Makefile.in
+++ b/gfx/angle/src/libEGL/Makefile.in
@@ -11,27 +11,17 @@ OS_CPPFLAGS += -EHsc
 endif
 
 # Since we're building off in our own world, we don't want to have
 # mozilla-config.h and -DMOZILLA_CLIENT automatically included and defined, so
 # we just overwrite OS_COMPILE_C(XX)FLAGS.
 OS_COMPILE_CFLAGS   = $(OS_CPPFLAGS)
 OS_COMPILE_CXXFLAGS = $(OS_CPPFLAGS)
 
-DEFINES += -DLIBEGL_EXPORTS
-DEFINES += -DANGLE_BUILD -DNOMINMAX -D_CRT_SECURE_NO_DEPRECATE
-
-ifndef MOZ_DEBUG
-DEFINES += -D_SECURE_SCL=0
-endif
-
 # Below is a transcription of the EGL target from build_angle.gypi.
-DEFINES += -DANGLE_DISABLE_TRACE
-DEFINES += -DANGLE_COMPILE_OPTIMIZATION_LEVEL=D3DCOMPILE_OPTIMIZATION_LEVEL1
-
 # Target: 'libEGL'
 #   Links with: 'libGLESv2'
 LOCAL_INCLUDES = \
   -I$(srcdir)/../../include \
   -I$(srcdir)/../../include/KHR \
   -I$(srcdir)/.. \
   -I$(srcdir)/../libGLESv2 \
   -I"$(MOZ_DIRECTX_SDK_PATH)/include"
--- a/gfx/angle/src/libEGL/moz.build
+++ b/gfx/angle/src/libEGL/moz.build
@@ -20,8 +20,17 @@ SOURCES += [
     'main.cpp',
     'Surface.cpp',
 ]
 
 # On Windows, we don't automatically get "lib" prepended, but we need it.
 LIBRARY_NAME = 'libEGL'
 
 FORCE_SHARED_LIB = True
+
+for var in ('LIBEGL_EXPORTS', 'ANGLE_BUILD', 'NOMINMAX',
+            '_CRT_SECURE_NO_DEPRECATE', 'ANGLE_DISABLE_TRACE'):
+    DEFINES[var] = True
+
+if not CONFIG['MOZ_DEBUG']:
+    DEFINES['_SECURE_SCL'] = 0
+
+DEFINES['ANGLE_COMPILE_OPTIMIZATION_LEVEL'] = 'D3DCOMPILE_OPTIMIZATION_LEVEL1'
--- a/gfx/angle/src/libGLESv2/Makefile.in
+++ b/gfx/angle/src/libGLESv2/Makefile.in
@@ -11,42 +11,31 @@ OS_CPPFLAGS += -EHsc
 endif
 
 # Since we're building off in our own world, we don't want to have
 #
 # we just overwrite OS_COMPILE_C(XX)FLAGS.
 OS_COMPILE_CFLAGS   = $(OS_CPPFLAGS)
 OS_COMPILE_CXXFLAGS = $(OS_CPPFLAGS)
 
-DEFINES += -DLIBGLESV2_EXPORTS
-DEFINES += -DANGLE_BUILD -DNOMINMAX -D_CRT_SECURE_NO_DEPRECATE
-
-ifndef MOZ_DEBUG
-DEFINES += -D_SECURE_SCL=0
-endif
-
 # The below is a rough translation of build_angle.gypi,
 # copied from src/Makefile.in.
-DEFINES += -DANGLE_DISABLE_TRACE
-DEFINES += -DANGLE_COMPILE_OPTIMIZATION_LEVEL=D3DCOMPILE_OPTIMIZATION_LEVEL1
 
 # Target: 'preprocessor'
 # src/compiler/preprocessor:
 VPATH += $(srcdir)/../compiler/preprocessor
 
 # Target: 'translator_common'
 #   Requires: 'preprocessor'
 LOCAL_INCLUDES += \
   -I$(srcdir)/../../include \
   -I$(srcdir)/../../include/KHR \
   -I$(srcdir)/.. \
   -I"$(MOZ_DIRECTX_SDK_PATH)/include"
 
-DEFINES += -DCOMPILER_IMPLEMENTATION
-
 VPATH += $(srcdir)/renderer
 VPATH += $(srcdir)/..
 VPATH += $(srcdir)/../compiler
 VPATH += $(srcdir)/../compiler/depgraph
 VPATH += $(srcdir)/../compiler/timing
 VPATH += $(srcdir)/../third_party/compiler
 VPATH += $(srcdir)/../third_party/murmurhash
 
--- a/gfx/angle/src/libGLESv2/moz.build
+++ b/gfx/angle/src/libGLESv2/moz.build
@@ -174,8 +174,18 @@ SOURCES += ['renderer/' + src for src in
     'VertexDataManager.cpp',
     'VertexDeclarationCache.cpp',
 ]]
 
 # On Windows, we don't automatically get "lib" prepended, but we need it.
 LIBRARY_NAME = 'libGLESv2'
 
 FORCE_SHARED_LIB = True
+
+for var in ('LIBGLESV2_EXPORTS', 'ANGLE_BUILD', 'NOMINMAX',
+            '_CRT_SECURE_NO_DEPRECATE', 'ANGLE_DISABLE_TRACE',
+            'COMPILER_IMPLEMENTATION'):
+    DEFINES[var] = True
+
+if not CONFIG['MOZ_DEBUG']:
+    DEFINES['_SECURE_SCL'] = 0
+
+DEFINES['ANGLE_COMPILE_OPTIMIZATION_LEVEL'] = 'D3DCOMPILE_OPTIMIZATION_LEVEL1'
--- a/gfx/cairo/cairo/src/Makefile.in
+++ b/gfx/cairo/cairo/src/Makefile.in
@@ -4,30 +4,16 @@
 
 ifdef GNU_CC
 ifeq ($(OS_TARGET),Android)
 MODULE_OPTIMIZE_FLAGS = -O2
 endif
 endif
 
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-DEFINES += -DDISABLE_SOME_FLOATING_POINT
-ifndef NS_PRINTING
-DEFINES += -DCAIRO_OMIT_WIN32_PRINTING
-endif
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
-DEFINES += -DOS2_USE_PLATFORM_ALLOC
-ifdef MOZ_OS2_HIGH_MEMORY
-DEFINES += -DOS2_HIGH_MEMORY
-endif
-endif
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
 OS_INCLUDES += $(MOZ_QT_CFLAGS)
 endif
 
 ifdef MOZ_X11
 OS_INCLUDES += $(XCFLAGS)
 endif
 
@@ -47,30 +33,12 @@ include $(topsrcdir)/config/rules.mk
 ifdef GNU_CC
 # Disable spammy "missing initializer" GCC warning
 CFLAGS += -Wno-missing-field-initializers
 
 # Disable spammy "implicit conversion from enumeration type 'cairo_" warnings.
 CFLAGS += -Wno-conversion
 endif # GNU_CC
 
-DEFINES += -DPACKAGE_VERSION="\"moz\"" -DPACKAGE_BUGREPORT="\"http://bugzilla.mozilla.org/\""
-
-DEFINES += -DCAIRO_HAS_PTHREAD -D_GNU_SOURCE
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-DEFINES += -DCAIRO_WIN32_STATIC_BUILD
-endif
-
-ifdef MOZ_TREE_CAIRO
-DEFINES += -DMOZ_TREE_CAIRO
-endif
-
 ifndef MOZ_TREE_PIXMAN
 CFLAGS += $(MOZ_PIXMAN_CFLAGS)
 CXXFLAGS += $(MOZ_PIXMAN_CFLAGS)
-else
-DEFINES += -DMOZ_TREE_PIXMAN
 endif
-
-ifdef MOZ_TREE_FREETYPE
-DEFINES += -DHAVE_FT_LIBRARY_SETLCDFILTER -DFT_LCD_FILTER_H="$(topsrcdir)/modules/freetype2/include/freetype/ftlcdfil.h"
-endif
--- a/gfx/cairo/cairo/src/moz.build
+++ b/gfx/cairo/cairo/src/moz.build
@@ -43,28 +43,35 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
     if CONFIG['MOZ_ENABLE_D2D_SURFACE']:
         SOURCES += [
             'cairo-d2d-surface.cpp',
         ]
     SOURCES += [
         'cairo-win32-font.c',
         'cairo-win32-surface.c',
     ]
+    DEFINES['DISABLE_SOME_FLOATING_POINT'] = True
+    DEFINES['CAIRO_WIN32_STATIC_BUILD'] = True
     if CONFIG['NS_PRINTING']:
         SOURCES += [
             'cairo-win32-printing-surface.c',
         ]
+    else:
+        DEFINES['CAIRO_OMIT_WIN32_PRINTING'] = True
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'os2':
     EXPORTS.cairo += [
         'cairo-os2-private.h',
         'cairo-os2.h',
     ]
     SOURCES += [
         'cairo-os2-surface.c',
     ]
+    DEFINES['OS2_USE_PLATFORM_ALLOC'] = True
+    if CONFIG['MOZ_OS2_HIGH_MEMORY']:
+        DEFINES['OS2_HIGH_MEMORY'] = True
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXPORTS.cairo += [
         'cairo-quartz-image.h',
         'cairo-quartz.h',
     ]
     SOURCES += [
         'cairo-quartz-font.c',
         'cairo-quartz-image-surface.c',
@@ -187,8 +194,22 @@ UNIFIED_SOURCES += [
     'cairo-version.c',
     'cairo-wideint.c',
     'cairo.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['PACKAGE_VERSION'] = '"moz"'
+DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'
+
+for var in ('CAIRO_HAS_PTHREAD', '_GNU_SOURCE'):
+    DEFINES[var] = True
+
+for var in ('MOZ_TREE_CAIRO', 'MOZ_TREE_PIXMAN'):
+    if CONFIG[var]:
+        DEFINES[var] = True
+
+if CONFIG['MOZ_TREE_FREETYPE']:
+    DEFINES['HAVE_FT_LIBRARY_SETLCDFILTER'] = True
+    DEFINES['FT_LCD_FILTER_H'] = '%s/modules/freetype2/include/freetype/ftlcdfil.h' % TOPSRCDIR
--- a/gfx/cairo/libpixman/src/Makefile.in
+++ b/gfx/cairo/libpixman/src/Makefile.in
@@ -1,24 +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/.
 
 ifeq ($(OS_TARGET),Android)
 MODULE_OPTIMIZE_FLAGS = -O2
 endif
 
-ifdef MOZ_USE_PTHREADS
-DEFINES += -DHAVE_PTHREAD_SETSPECIFIC
-endif
-
-ifdef _MSC_VER
-DEFINES += -DPIXMAN_USE_XP_DLL_TLS_WORKAROUND
-endif
-
 # Build MMX code either with VC or with gcc-on-x86
 ifdef _MSC_VER
 ifeq (86,$(findstring 86,$(OS_TEST)))
 ifneq (64,$(findstring 64,$(OS_TEST)))
 USE_MMX=1
 endif
 USE_SSE2=1
 MMX_CFLAGS=
@@ -100,18 +92,16 @@ CSRCS += pixman-arm-neon.c
 DEFINES += -DUSE_ARM_NEON
 ARM_NEON_CFLAGS = -mfpu=neon
 endif
 
 LOCAL_INCLUDES	+= -I$(srcdir) -I$(srcdir)/../../cairo/src
 
 include $(topsrcdir)/config/rules.mk
 
-CFLAGS += -DPACKAGE="mozpixman" -D_USE_MATH_DEFINES
-
 # Disable spammy "missing initializer" GCC warning
 ifdef GNU_CC
 CFLAGS += -Wno-missing-field-initializers
 endif # GNU_CC
 
 # special rule for pixman-mmx to get the right cflags
 pixman-mmx.$(OBJ_SUFFIX): COMPILE_CFLAGS += $(MMX_CFLAGS)
 
--- a/gfx/cairo/libpixman/src/moz.build
+++ b/gfx/cairo/libpixman/src/moz.build
@@ -56,8 +56,18 @@ SOURCES += [
     'pixman-utils.c',
     'pixman-x86.c',
     'pixman.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+if CONFIG['MOZ_USE_PTHREADS']:
+    DEFINES['HAVE_PTHREAD_SETSPECIFIC'] = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['PIXMAN_USE_XP_DLL_TLS_WORKAROUND'] = True
+
+DEFINES['PACKAGE'] = 'mozpixman'
+
+DEFINES['_USE_MATH_DEFINES'] = True
--- a/gfx/gl/Makefile.in
+++ b/gfx/gl/Makefile.in
@@ -1,25 +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 ($(MOZ_WIDGET_TOOLKIT),windows)
-ifdef MOZ_WEBGL
-DEFINES += -DMOZ_D3DCOMPILER_DLL=$(MOZ_D3DCOMPILER_DLL)
-endif
-endif
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
 LOCAL_INCLUDES = -I$(topsrcdir)/widget/gonk
 LOCAL_INCLUDES += -I$(ANDROID_SOURCE)/hardware/libhardware/include
 endif
 
-ifdef MOZ_ANDROID_OMTC
-DEFINES += -DMOZ_ANDROID_OMTC
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 DEFINES := $(filter-out -DUNICODE,$(DEFINES))
 
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
 CFLAGS   += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -122,8 +122,14 @@ UNIFIED_SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows' and CONFIG['MOZ_WEBGL']:
+    DEFINES['MOZ_D3DCOMPILER_DLL'] = CONFIG['MOZ_D3DCOMPILER_DLL']
+
+if CONFIG['MOZ_ANDROID_OMTC']:
+    DEFINES['MOZ_ANDROID_OMTC'] = True
--- a/gfx/graphite2/src/Makefile.in
+++ b/gfx/graphite2/src/Makefile.in
@@ -8,31 +8,8 @@
 ifdef GNU_CC
 _MACHINE = direct
 else
 _MACHINE = call
 endif
 
 # get the lists of source files and exported headers
 include $(srcdir)/files.mk
-
-# on Windows, we're going to link graphite with gkmedias instead of libxul
-ifeq (WINNT,$(OS_TARGET))
-endif
-
-ifeq (WINNT,$(OS_TARGET))
-DEFINES += -DGRAPHITE2_EXPORTING
-else
-# tell graphite2 not to export symbols, we'll be linking it directly with thebes
-DEFINES += -DGRAPHITE2_STATIC
-endif
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -DPACKAGE_VERSION="\"moz\""
-DEFINES += -DPACKAGE_BUGREPORT="\"http://bugzilla.mozilla.org/\""
-
-# disable features we don't need in the graphite2 code, to reduce code size
-DEFINES += -DGRAPHITE2_NFILEFACE -DGRAPHITE2_NTRACING -DGRAPHITE2_NSEGCACHE
-
-# provide a custom header that overrides malloc() and friends,
-# to ensure safe OOM handling
-DEFINES += -DGRAPHITE2_CUSTOM_HEADER="\"MozGrMalloc.h\""
--- a/gfx/graphite2/src/moz.build
+++ b/gfx/graphite2/src/moz.build
@@ -54,10 +54,26 @@ UNIFIED_SOURCES += [
     'TtfUtil.cpp',
     'UtfCodec.cpp',
 ]
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
+    DEFINES['GRAPHITE2_EXPORTING'] = True
+else:
+    # tell graphite2 not to export symbols, we'll be linking it directly with
+    # thebes
+    DEFINES['GRAPHITE2_STATIC'] = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['PACKAGE_VERSION'] = '"moz"'
+DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'
+
+# disable features we don't need in the graphite2 code, to reduce code size
+for var in ('GRAPHITE2_NFILEFACE', 'GRAPHITE2_NTRACING', 'GRAPHITE2_NSEGCACHE'):
+    DEFINES[var] = True
+
+# provide a custom header that overrides malloc() and friends,
+# to ensure safe OOM handling
+DEFINES['GRAPHITE2_CUSTOM_HEADER'] = '"MozGrMalloc.h"'
--- a/gfx/harfbuzz/src/Makefile.in
+++ b/gfx/harfbuzz/src/Makefile.in
@@ -24,15 +24,11 @@
 # Mozilla author(s): Jonathan Kew
 #
 
 LOCAL_INCLUDES  += -I$(srcdir) 
 
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DPACKAGE_VERSION="\"moz\""
-DEFINES += -DPACKAGE_BUGREPORT="\"http://bugzilla.mozilla.org/\""
-DEFINES += -DHAVE_OT=1 -DHB_NO_MT -DHB_NO_UNICODE_FUNCS
-
 # Cancel the effect of the -DDEBUG macro if present,
 # because harfbuzz uses that name for its own purposes
 COMPILE_CXXFLAGS += -UDEBUG
--- a/gfx/harfbuzz/src/moz.build
+++ b/gfx/harfbuzz/src/moz.build
@@ -51,8 +51,14 @@ UNIFIED_SOURCES += [
     'hb-shaper.cc',
     'hb-unicode.cc',
     'hb-warning.cc',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['PACKAGE_VERSION'] = '"moz"'
+DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'
+DEFINES['HAVE_OT'] = 1
+DEFINES['HB_NO_MT'] = True
+DEFINES['HB_NO_UNICODE_FUNCS'] = True
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -10,24 +10,16 @@ VPATH       = \
   $(srcdir)/composite \
   $(srcdir)/opengl \
   $(srcdir)/d3d9 \
   $(srcdir)/d3d10 \
   $(srcdir)/d3d11 \
   $(srcdir)/ipc \
   $(NULL)
 
-ifdef MOZ_DEBUG
-DEFINES += -DD3D_DEBUG_INFO
-endif
-
-ifdef MOZ_ENABLE_D3D10_LAYER
-DEFINES	+= -DMOZ_ENABLE_D3D10_LAYER
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES += \
         -I$(topsrcdir)/content/events/src \
         -I$(ANDROID_SOURCE)/frameworks/base/include/media/stagefright \
         -I$(ANDROID_SOURCE)/frameworks/base/include/media/stagefright/openmax \
         -I$(ANDROID_SOURCE)/frameworks/av/include/media/stagefright \
         -I$(ANDROID_SOURCE)/frameworks/native/include/media/openmax \
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -288,8 +288,14 @@ IPDL_SOURCES = [
     'ipc/PLayerTransaction.ipdl',
 ]
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'thebes'
+
+if CONFIG['MOZ_DEBUG']:
+    DEFINES['D3D_DEBUG_INFO'] = True
+
+if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
+    DEFINES['MOZ_ENABLE_D3D10_LAYER'] = True
deleted file mode 100644
--- a/gfx/ots/src/Makefile.in
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# Copyright (C) 2010  Mozilla Foundation
-#
-#  This is used to integrate the OTS library with the Mozilla build.
-#
-# Permission is hereby granted, without written agreement and without
-# license or royalty fees, to use, copy, modify, and distribute this
-# software and its documentation for any purpose, provided that the
-# above copyright notice and the following two paragraphs appear in
-# all copies of this software.
-#
-# IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
-# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
-# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
-# IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-# DAMAGE.
-#
-# THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-# FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
-# ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
-# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-#
-# Mozilla author(s): Jonathan Kew
-#
-
-
-ifeq (WINNT,$(OS_TARGET))
-endif
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -DPACKAGE_VERSION="\"moz\""
-DEFINES += -DPACKAGE_BUGREPORT="\"http://bugzilla.mozilla.org/\""
-DEFINES += -DNOMINMAX
-DEFINES += -DMOZ_OTS_REPORT_ERRORS
-
-ifeq (WINNT,$(OS_TARGET))
-DEFINES += -DOTS_DLL -DOTS_DLL_EXPORTS
-endif
--- a/gfx/ots/src/moz.build
+++ b/gfx/ots/src/moz.build
@@ -48,8 +48,17 @@ UNIFIED_SOURCES += [
 ]
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['PACKAGE_VERSION'] = '"moz"'
+DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'
+DEFINES['NOMINMAX'] = True
+DEFINES['MOZ_OTS_REPORT_ERRORS'] = True
+
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['OTS_DLL'] = True
+    DEFINES['OTS_DLL_EXPORTS'] = True
--- a/gfx/skia/Makefile.in
+++ b/gfx/skia/Makefile.in
@@ -1,15 +1,13 @@
 # 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEFINES += -DSK_A32_SHIFT=24 -DSK_R32_SHIFT=16 -DSK_G32_SHIFT=8 -DSK_B32_SHIFT=0
-
 LOCAL_INCLUDES += \
 	-I$(srcdir)/include/core \
 	-I$(srcdir)/include/config \
 	-I$(srcdir)/include/gpu \
 	-I$(srcdir)/include/pipe \
 	-I$(srcdir)/include/ports \
 	-I$(srcdir)/include/images \
 	-I$(srcdir)/include/lazy \
@@ -45,42 +43,24 @@ VPATH += \
 	$(srcdir)/src/utils \
 	$(srcdir)/src/utils/android \
 	$(srcdir)/src/utils/mac \
 	$(srcdir)/src/sfnt \
 	$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gonk))
 OS_CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(CAIRO_FT_CFLAGS)
-DEFINES += -DSK_FONTHOST_CAIRO_STANDALONE=0
 endif
 
 ifdef MOZ_WIDGET_GTK
 OS_CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PANGO_CFLAGS) $(CAIRO_FT_CFLAGS)
 endif
 
 ifeq (qt,$(MOZ_WIDGET_TOOLKIT))
 OS_CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PANGO_CFLAGS) $(CAIRO_FT_CFLAGS)
-ifeq (Linux,$(OS_TARGET))
-DEFINES += -DSK_USE_POSIX_THREADS=1
-endif
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gtk3 gonk cocoa))
-DEFINES += -DSK_USE_POSIX_THREADS=1
-endif
-
-ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DSKIA_IMPLEMENTATION=1 -DGR_IMPLEMENTATION=1
-endif
-
-ifneq (,$(INTEL_ARCHITECTURE))
-ifdef HAVE_TOOLCHAIN_SUPPORT_MSSSE3
-DEFINES += -DSK_BUILD_SSSE3
-endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifneq (,$(INTEL_ARCHITECTURE))
 ifdef GNU_CC
 SkBitmapProcState_opts_SSE2.$(OBJ_SUFFIX): CXXFLAGS+=-msse2
 SkBitmapProcState_opts_SSSE3.$(OBJ_SUFFIX): CXXFLAGS+=-mssse3
--- a/gfx/skia/moz.build
+++ b/gfx/skia/moz.build
@@ -170,16 +170,18 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wi
         'src/ports/SkTime_win.cpp',
         'src/utils/SkThreadUtils_win.cpp',
     ]
     # left out of UNIFIED_SOURCES for now to avoid having to patch skia. Should revisit eventually.
     SOURCES += [
         'src/ports/SkFontHost_sandbox_none.cpp',
         'src/ports/SkFontHost_win.cpp',
     ]
+    DEFINES['SKIA_IMPLEMENTATION'] = 1
+    DEFINES['GR_IMPLEMENTATION'] = 1
 elif CONFIG['MOZ_WIDGET_GTK']:
     EXPORTS.skia += [
         'include/ports/SkTypeface_cairo.h',
     ]
     UNIFIED_SOURCES += [
         'src/ports/SkThread_pthread.cpp',
         'src/ports/SkTime_Unix.cpp',
         'src/utils/SkOSFile.cpp',
@@ -212,16 +214,17 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt
             'include/ports/SkTypeface_cairo.h',
         ]
         UNIFIED_SOURCES += [
             'src/ports/SkThread_pthread.cpp',
             'src/ports/SkTime_Unix.cpp',
             'src/utils/SkThreadUtils_pthread.cpp',
             'src/utils/SkThreadUtils_pthread_linux.cpp',
         ]
+        DEFINES['SK_USE_POSIX_THREADS'] = 1
 # Separate 'if' from above, since the else below applies to all != 'android'
 # toolkits.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
     EXPORTS.skia += [
         'include/ports/SkTypeface_cairo.h',
     ]
     UNIFIED_SOURCES += [
         'src/images/SkImageRef_ashmem.cpp',
@@ -235,16 +238,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('and
     ]
     # left out of UNIFIED_SOURCES for now to avoid having to patch skia. Should revisit eventually.
     SOURCES += [
         'src/ports/SkFontHost_cairo.cpp',
         'src/ports/SkFontHost_FreeType.cpp',
         'src/ports/SkFontHost_FreeType_common.cpp',
         'src/ports/SkFontHost_linux.cpp',
     ]
+    DEFINES['SK_FONTHOST_CAIRO_STANDALONE'] = 0
 else:
     UNIFIED_SOURCES += [
         'src/ports/SkDebug_stdio.cpp',
     ]
 
 if CONFIG['INTEL_ARCHITECTURE']:
     # We need to build SSE2-enabled files separately so that we're able
     # to pass -msse2 for them. We won't be able to unify them with the rest,
@@ -581,8 +585,19 @@ else:
 if not CONFIG['INTEL_ARCHITECTURE'] and CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC']:
     SOURCES += [
         'src/opts/memset.arm.S',
     ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['SK_A32_SHIFT'] = 24
+DEFINES['SK_R32_SHIFT'] = 16
+DEFINES['SK_G32_SHIFT'] = 8
+DEFINES['SK_B32_SHIFT'] = 0
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk', 'cocoa'):
+    DEFINES['SK_USE_POSIX_THREADS'] = 1
+
+if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['HAVE_TOOLCHAIN_SUPPORT_MSSSE3']:
+    DEFINES['SK_BUILD_SSSE3'] = 1
--- a/gfx/thebes/Makefile.in
+++ b/gfx/thebes/Makefile.in
@@ -1,48 +1,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LOCAL_INCLUDES += \
 	-I$(topsrcdir)/content/xml/document/src \
 	$(NULL)
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),$(findstring $(MOZ_WIDGET_TOOLKIT),android gtk2 gtk3 gonk qt))
-DEFINES += -DMOZ_ENABLE_FREETYPE
-endif
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-
-ifdef MOZ_ENABLE_D3D9_LAYER
-DEFINES +=	-DMOZ_ENABLE_D3D9_LAYER
-endif
-
-ifdef MOZ_ENABLE_D3D10_LAYER
-DEFINES +=	-DMOZ_ENABLE_D3D10_LAYER
-endif
-
 ACDEFINES +=	-UWIN32_LEAN_AND_MEAN
 endif
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),android)
-# This is set for "normal Android", that is, when Gecko is running on
-# top of the android java runtime.
-DEFINES +=	-DMOZ_USING_ANDROID_JAVA_WIDGETS
-endif
-
-DEFINES += \
-	-DMOZ_OTS_REPORT_ERRORS \
-	-DGRAPHITE2_STATIC \
-	$(NULL)
-
-ifeq (WINNT,$(OS_TARGET))
-DEFINES += -DOTS_DLL
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 DEFINES := $(filter-out -DUNICODE,$(DEFINES))
 
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
 CFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) $(TK_CFLAGS)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),android)
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -294,8 +294,27 @@ LIBRARY_NAME = 'thebes'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 GENERATED_FILES = [
     'PremultiplyTables.h',
 ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'gonk', 'qt'):
+    DEFINES['MOZ_ENABLE_FREETYPE'] = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    for var in ('MOZ_ENABLE_D3D9_LAYER', 'MOZ_ENABLE_D3D10_LAYER'):
+        if CONFIG[var]:
+            DEFINES[var] = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    # This is set for "normal Android", that is, when Gecko is running on
+    # top of the android java runtime.
+    DEFINES['MOZ_USING_ANDROID_JAVA_WIDGETS'] = True
+
+DEFINES['MOZ_OTS_REPORT_ERRORS'] = True
+DEFINES['GRAPHITE2_STATIC'] = True
+
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['OTS_DLL'] = True
--- a/intl/locale/src/unix/Makefile.in
+++ b/intl/locale/src/unix/Makefile.in
@@ -2,19 +2,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/.
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= -I$(srcdir)/..
 
-# CODESET is not automatically defined on some older versions of Redhat.
-# Define _XOPEN_SOURCE so CODESET will get defined and thus allow
-# nl_langinfo(CODESET) to compile on these systems.
-ifeq ($(OS_ARCH), Linux)
-DEFINES		+= -D_XOPEN_SOURCE=500
-endif
-
-DEFINES += -DOSTYPE=\"$(OS_CONFIG)\"
-
 unixcharset.properties.h: $(srcdir)/../props2arrays.py unixcharset.properties
 	$(PYTHON) $^ $@
--- a/intl/locale/src/unix/moz.build
+++ b/intl/locale/src/unix/moz.build
@@ -19,8 +19,16 @@ else:
         'nsUNIXCharset.cpp',
     ]
 
 FINAL_LIBRARY = 'i18n'
 
 GENERATED_FILES = [
     'unixcharset.properties.h',
 ]
+
+# CODESET is not automatically defined on some older versions of Redhat.
+# Define _XOPEN_SOURCE so CODESET will get defined and thus allow
+# nl_langinfo(CODESET) to compile on these systems.
+if CONFIG['OS_ARCH'] == 'Linux':
+    DEFINES['_XOPEN_SOURCE'] = 500
+
+DEFINES['OSTYPE'] = '"%s"' % CONFIG['OS_CONFIG']
--- a/intl/unicharutil/util/Makefile.in
+++ b/intl/unicharutil/util/Makefile.in
@@ -15,10 +15,9 @@ USE_STATIC_LIBS = 1
 LOCAL_INCLUDES += -I$(srcdir)/../src
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
--- a/intl/unicharutil/util/moz.build
+++ b/intl/unicharutil/util/moz.build
@@ -16,8 +16,11 @@ EXPORTS += [
 
 include('objs.mozbuild')
 
 UNIFIED_SOURCES += intl_unicharutil_util_cppsrcs
 
 LIBRARY_NAME = 'unicharutil_external_s'
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
--- a/ipc/chromium/Makefile.in
+++ b/ipc/chromium/Makefile.in
@@ -21,49 +21,39 @@ vpath %.cc \
   $(srcdir)/src/chrome/common \
   $(NULL)
 
 vpath %.mm \
   $(srcdir)/src/base \
   $(srcdir)/src/chrome/common \
   $(NULL)
 
-ifneq ($(OS_ARCH),WINNT) # (if OS_POSIX) {
-ifeq ($(OS_TARGET),Android)
-DEFINES += -DANDROID -D_POSIX_MONOTONIC_CLOCK=0
-endif # Android
-endif # } Not WINNT (OS_POSIX)
-
 # libevent
 
 ifndef MOZ_NATIVE_LIBEVENT # {
 
 ifneq ($(OS_ARCH),WINNT) # (if OS_POSIX) {
 
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/include
-DEFINES += -DHAVE_CONFIG_H
 
 ifeq ($(OS_ARCH),Darwin) # (OS_MACOSX) {
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/mac
 
 else # } else {
 
 ifneq (,$(filter-out DragonFly FreeBSD NetBSD OpenBSD,$(OS_ARCH))) # (OS_LINUX) {
 ifeq ($(OS_TARGET),Android) # {
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/android
 else # } else {
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/linux
 endif # }
 
 else # } else (OS_BSD)  {
 
-ifneq (,$(filter DragonFly FreeBSD,$(OS_ARCH))) # (not OS_DRAGONFLY and not OS_FREEBSD) {
-DEFINES += -D_EVENT_HAVE_SENDFILE
-endif # }
 LOCAL_INCLUDES += -I$(srcdir)/src/third_party/libevent/bsd
 
 endif # }
 
 endif # }
 
 endif # }
 
--- a/ipc/chromium/moz.build
+++ b/ipc/chromium/moz.build
@@ -141,16 +141,17 @@ elif not CONFIG['MOZ_NATIVE_LIBEVENT']:
         'src/third_party/libevent/http.c',
         'src/third_party/libevent/listener.c',
         'src/third_party/libevent/log.c',
         'src/third_party/libevent/poll.c',
         'src/third_party/libevent/select.c',
         'src/third_party/libevent/signal.c',
         'src/third_party/libevent/strlcpy.c',
     ]
+    DEFINES['HAVE_CONFIG_H'] = True
 
 if os_posix:
     SOURCES += [
         'src/base/condition_variable_posix.cc',
         'src/base/debug_util_posix.cc',
         'src/base/event_recorder_stubs.cc',
         'src/base/file_descriptor_shuffle.cc',
         'src/base/file_util_posix.cc',
@@ -172,16 +173,18 @@ if os_posix:
         'src/chrome/common/file_descriptor_set_posix.cc',
         'src/chrome/common/ipc_channel_posix.cc',
         'src/chrome/common/process_watcher_posix_sigchld.cc',
     ]
     if CONFIG['OS_TARGET'] == 'Android':
         SOURCES += [
             'src/base/message_pump_android.cc',
         ]
+        DEFINES['ANDROID'] = True
+        DEFINES['_POSIX_MONOTONIC_CLOCK'] = 0
 
 if os_macosx:
     UNIFIED_SOURCES += [
         'src/base/debug_util_mac.cc',
         'src/base/hmac_mac.cc',
         'src/base/idle_timer.cc',
         'src/base/sys_info_mac.cc',
         'src/base/time_mac.cc',
@@ -260,16 +263,18 @@ if os_bsd:
         ]
         GENERATED_SOURCES += [
             'src/base/moc_message_pump_qt.cc',
         ]
     if not CONFIG['MOZ_NATIVE_LIBEVENT']:
         SOURCES += [
             'src/third_party/libevent/kqueue.c',
         ]
+        if not os_freebsd and not os_dragonfly:
+            DEFINES['_EVENT_HAVE_SENDFILE'] = True
 
 if CONFIG['_MSC_VER']:
     SOURCES += [
         'src/base/debug_on_start.cc',
     ]
 
 ost = CONFIG['OS_TEST']
 if ost.find('86') == -1 and ost.find('arm') == -1 and ost.find('mips') == -1:
--- a/ipc/glue/Makefile.in
+++ b/ipc/glue/Makefile.in
@@ -1,16 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter
 
-DEFINES += -DMOZ_CHILD_PROCESS_NAME=\"$(MOZ_CHILD_PROCESS_NAME)\"
-DEFINES += -DMOZ_CHILD_PROCESS_BUNDLE=\"$(MOZ_CHILD_PROCESS_BUNDLE)\"
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_CONTENT_SANDBOX
 ifeq ($(OS_ARCH),WINNT)
 LOCAL_INCLUDES += -I$(topsrcdir)/security/sandbox/win/src/sandboxbroker
 endif
 endif
--- a/ipc/glue/moz.build
+++ b/ipc/glue/moz.build
@@ -101,8 +101,11 @@ IPDL_SOURCES = [
     'InputStreamParams.ipdlh',
     'ProtocolTypes.ipdlh',
     'URIParams.ipdlh',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+for var in ('MOZ_CHILD_PROCESS_NAME', 'MOZ_CHILD_PROCESS_BUNDLE'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
--- a/js/ipc/Makefile.in
+++ b/js/ipc/Makefile.in
@@ -5,10 +5,8 @@
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/dom/base \
   -I$(topsrcdir)/js/ipc \
   -I$(topsrcdir)/js/public \
   -I$(topsrcdir)/js/xpconnect/src \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
-
-DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
--- a/js/ipc/moz.build
+++ b/js/ipc/moz.build
@@ -15,8 +15,10 @@ IPDL_SOURCES += [
     'PJavaScript.ipdl',
 ]
 
 FAIL_ON_WARNINGS = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX']
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -41,24 +41,16 @@ VPATH		+= \
 #
 VPATH		+= \
 		$(srcdir)/../public \
 		$(NULL)
 
 ###############################################
 # BEGIN enable non-releasable features
 #
-ifdef NIGHTLY_BUILD
-DEFINES += -DENABLE_PARALLEL_JS
-endif
-
-ifdef NIGHTLY_BUILD
-DEFINES += -DENABLE_BINARYDATA
-endif
-
 # Ion
 ifdef ENABLE_ION
 VPATH +=	$(srcdir)/jit
 VPATH +=	$(srcdir)/jit/shared
 
 ifeq (86, $(findstring 86,$(TARGET_CPU)))
 ifeq (x86_64, $(TARGET_CPU))
 VPATH +=	$(srcdir)/jit/x64
@@ -356,29 +348,18 @@ DIST_GARBAGE = config.cache config.log c
    backend.mk config/backend.mk devtools/backend.mk editline/backend.mk \
    gdb/backend.mk jsapi-tests/backend.mk shell/backend.mk tests/backend.mk \
    backend.RecursiveMakeBackend backend.RecursiveMakeBackend.pp \
    devtools/rootAnalysis/Makefile
 
 distclean::
 	$(RM) $(DIST_GARBAGE)
 
-DEFINES		+= -DEXPORT_JS_API
-
 INCLUDES	+= -I$(srcdir)
 
-ifdef JS_THREADSAFE
-DEFINES		+= -DJS_THREADSAFE
-endif
-
-ifdef JS_HAS_CTYPES
-DEFINES		+= -DJS_HAS_CTYPES
-DEFINES         += -DDLL_PREFIX=\"$(DLL_PREFIX)\" -DDLL_SUFFIX=\"$(DLL_SUFFIX)\"
-endif
-
 ifneq ($(findstring -L,$(NSPR_LIBS)),)
 NSPR_STATIC_PATH = $(subst -L,,$(findstring -L,$(NSPR_LIBS)))
 else
 NSPR_STATIC_PATH = $(DIST)/lib
 endif
 
 ifdef MOZ_ETW
 # This will get the ETW provider resources into the library mozjs.dll
@@ -394,20 +375,16 @@ CFLAGS += $(MOZ_ZLIB_CFLAGS)
 EXTRA_LIBS += $(MOZ_ZLIB_LIBS)
 # Enable zlib usage if zlib has been located. When building the browser on
 # Windows, MOZ_ZLIB_LIBS is empty because zlib is part of libmozglue. We thus
 # also enable zlib if mozglue is present.
 ifneq (,$(MOZ_ZLIB_LIBS)$(MOZ_GLUE_LDFLAGS))
 DEFINES += -DUSE_ZLIB
 endif
 
-ifdef MOZ_LINKER
-DEFINES += -DMOZ_LINKER
-endif
-
 ifdef MOZ_NATIVE_ICU
 EXTRA_DSO_LDOPTS += $(MOZ_ICU_LIBS)
 else
 SHARED_LIBRARY_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 # Prevent floating point errors caused by VC++ optimizations
 ifdef _MSC_VER
--- a/js/src/config/Makefile.in
+++ b/js/src/config/Makefile.in
@@ -10,21 +10,16 @@ override NSBUILDROOT :=
 endif
 
 ifdef GNU_CC
 MODULE_OPTIMIZE_FLAGS = -O3
 endif
 
 include $(topsrcdir)/config/config.mk
 
-# Force wrap zlib system header if building js as a shared library.
-ifneq (,$(JS_SHARED_LIBRARY)$(MOZ_NATIVE_ZLIB))
-DEFINES += -DMOZ_NATIVE_ZLIB=1
-endif
-
 ifneq (WINNT,$(HOST_OS_ARCH))
 # Ensure nsinstall is atomically created
 nsinstall$(HOST_BIN_SUFFIX): $(HOST_PROGRAM)
 	cp $^ $@.tmp
 	mv $@.tmp $@
 
 NSINSTALL_FILES := nsinstall$(HOST_BIN_SUFFIX)
 NSINSTALL_DEST := $(DIST)/bin
--- a/js/src/config/moz.build
+++ b/js/src/config/moz.build
@@ -15,8 +15,12 @@ NO_DIST_INSTALL = True
 NO_VISIBILITY_FLAGS = True
 
 if CONFIG['HOST_OS_ARCH'] != 'WINNT':
     HOST_SOURCES += [
         'nsinstall.c',
         'pathsub.c',
     ]
     HOST_PROGRAM = 'nsinstall_real'
+
+# Force wrap zlib system header if building js as a shared library.
+if CONFIG['JS_SHARED_LIBRARY'] or CONFIG['MOZ_NATIVE_ZLIB']:
+    DEFINES['MOZ_NATIVE_ZLIB'] = 1
deleted file mode 100644
--- a/js/src/editline/Makefile.in
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- 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/.
-
-DEFINES += -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX \
-	-DHAVE_STDLIB -DUNIQUE_HISTORY
--- a/js/src/editline/moz.build
+++ b/js/src/editline/moz.build
@@ -7,8 +7,12 @@
 LIBRARY_NAME = 'editline'
 
 UNIFIED_SOURCES += [
     'editline.c',
     'sysunix.c',
 ]
 
 FORCE_STATIC_LIB = True
+
+for var in ('ANSI_ARROWS', 'HAVE_TCGETATTR', 'HIDE', 'USE_DIRENT', 'SYS_UNIX',
+            'HAVE_STDLIB', 'UNIQUE_HISTORY'):
+    DEFINES[var] = True
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -1,20 +1,16 @@
 # -*- 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/.
 
 VPATH		= @srcdir@ @srcdir@/tests
 
-# Building against js_static requires that we declare mfbt sybols "exported"
-# on its behalf.
-DEFINES += -DEXPORT_JS_API -DIMPL_MFBT
-
 LIBS = $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
 ifdef MOZ_NATIVE_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
--- a/js/src/gdb/moz.build
+++ b/js/src/gdb/moz.build
@@ -11,8 +11,13 @@ UNIFIED_SOURCES += [
     'tests/test-jsid.cpp',
     'tests/test-JSObject.cpp',
     'tests/test-JSString.cpp',
     'tests/test-jsval.cpp',
     'tests/test-prettyprinters.cpp',
     'tests/test-Root.cpp',
     'tests/typedef-printers.cpp',
 ]
+
+# Building against js_static requires that we declare mfbt sybols "exported"
+# on its behalf.
+for var in ('EXPORT_JS_API', 'IMPL_MFBT'):
+    DEFINES[var] = True
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -1,19 +1,14 @@
 # -*- Mode: makefile -*-
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEFINES         += -DEXPORT_JS_API
-# Building against js_static requires that we declare mfbt sybols "exported"
-# on its behalf.
-DEFINES         += -DIMPL_MFBT
-
 LIBS      = $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(NSPR_LIBS) $(MOZ_ZLIB_LIBS)
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
 ifdef MOZ_NATIVE_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -65,8 +65,13 @@ UNIFIED_SOURCES += [
     'testStringBuffer.cpp',
     'testStructuredClone.cpp',
     'testToIntWidth.cpp',
     'testTrap.cpp',
     'testTypedArrays.cpp',
     'testUTF8.cpp',
     'testXDR.cpp',
 ]
+
+DEFINES['EXPORT_JS_API'] = True
+# Building against js_static requires that we declare mfbt sybols "exported"
+# on its behalf.
+DEFINES['IMPL_MFBT'] = True
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -397,8 +397,25 @@ if CONFIG['JS_SHARED_LIBRARY']:
     FORCE_SHARED_LIB = True
 
 FORCE_STATIC_LIB = True
 
 if CONFIG['MOZ_ETW']:
     GENERATED_FILES = [
         'ETWProvider.h',
     ]
+
+if CONFIG['NIGHTLY_BUILD']:
+    DEFINES['ENABLE_PARALLEL_JS'] = True
+    DEFINES['ENABLE_BINARYDATA'] = True
+
+DEFINES['EXPORT_JS_API'] = True
+
+if CONFIG['JS_THREADSAFE']:
+    DEFINES['JS_THREADSAFE'] = True
+
+if CONFIG['JS_HAS_CTYPES']:
+    DEFINES['JS_HAS_CTYPES'] = True
+    for var in ('DLL_PREFIX', 'DLL_SUFFIX'):
+        DEFINES[var] = '"%s"' % CONFIG[var]
+
+if CONFIG['MOZ_LINKER']:
+    DEFINES['MOZ_LINKER'] = True
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -6,21 +6,16 @@
 
 ifdef _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_PROFILE_GUIDED_OPTIMIZE := 1
 endif
 
-DEFINES         += -DEXPORT_JS_API
-# Building against js_static requires that we declare mfbt sybols "exported"
-# on its behalf.
-DEFINES         += -DIMPL_MFBT
-
 LIBS      = $(NSPR_LIBS) $(EDITLINE_LIBS) $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX) $(MOZ_ZLIB_LIBS)
 ifdef MOZ_NATIVE_FFI
 EXTRA_LIBS += $(MOZ_FFI_LIBS)
 endif
 ifdef MOZ_NATIVE_ICU
 EXTRA_LIBS += $(MOZ_ICU_LIBS)
 endif
 
--- a/js/src/shell/moz.build
+++ b/js/src/shell/moz.build
@@ -6,8 +6,13 @@
 
 PROGRAM = CONFIG['JS_SHELL_NAME']
 
 UNIFIED_SOURCES += [
     'js.cpp',
     'jsheaptools.cpp',
     'jsoptparse.cpp',
 ]
+
+# Building against js_static requires that we declare mfbt sybols "exported"
+# on its behalf.
+for var in ('EXPORT_JS_API', 'IMPL_MFBT'):
+    DEFINES[var] = True
--- a/js/xpconnect/loader/Makefile.in
+++ b/js/xpconnect/loader/Makefile.in
@@ -2,14 +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/.
 
 LOCAL_INCLUDES += \
   -I$(srcdir)/../src \
   -I$(srcdir)/../wrappers \
   -I$(topsrcdir)/content/base/src \
   $(NULL)
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += \
-  -DJS_THREADSAFE \
-  $(NULL)
--- a/js/xpconnect/loader/moz.build
+++ b/js/xpconnect/loader/moz.build
@@ -17,8 +17,10 @@ EXTRA_JS_MODULES += [
     'XPCOMUtils.jsm',
 ]
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'xpconnect_s'
+
+DEFINES['JS_THREADSAFE'] = True
--- a/js/xpconnect/src/Makefile.in
+++ b/js/xpconnect/src/Makefile.in
@@ -32,42 +32,18 @@ INSTALL_TARGETS += extra_export_files
 extra_export_files_FILES := \
   DictionaryHelpers.h \
   GeneratedEventClasses.h \
   GeneratedEvents.h \
   $(NULL)
 extra_export_files_DEST = $(DIST)/include
 extra_export_files_TARGET := export
 
-# XPCShellImpl.cpp requires hardcoded vendor/profile/appname stuff on Windows
-# This sucks, bug 921148 tracks this.
-ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
-  ifdef MOZ_APP_PROFILE
-    DEFINES += -DMOZ_APP_PROFILE='"$(MOZ_APP_PROFILE)"'
-  else
-    ifdef MOZ_APP_VENDOR
-      DEFINES += -DMOZ_APP_VENDOR='"$(MOZ_APP_VENDOR)"'
-    endif
-    ifdef MOZ_APP_BASENAME
-      DEFINES += -DMOZ_APP_BASENAME='"$(MOZ_APP_BASENAME)"'
-    endif
-    DEFINES += -DMOZ_APP_NAME='"$(MOZ_APP_NAME)"'
-  endif
-endif
-
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += \
-  -DJS_THREADSAFE \
-  $(NULL)
-
-ifdef MOZ_JSDEBUGGER
-DEFINES += -DMOZ_JSDEBUGGER
-endif
-
 dom_quickstubs.h: dom_quickstubs.cpp
 
 dom_quickstubs.cpp: $(srcdir)/dom_quickstubs.qsconf \
                     $(srcdir)/qsgen.py \
                     $(LIBXUL_DIST)/sdk/bin/header.py \
                     $(LIBXUL_DIST)/sdk/bin/xpidl.py
 	$(PYTHON) $(topsrcdir)/config/pythonpath.py \
 	  $(PLY_INCLUDE) \
--- a/js/xpconnect/src/moz.build
+++ b/js/xpconnect/src/moz.build
@@ -69,8 +69,25 @@ include('/ipc/chromium/chromium-config.m
 FINAL_LIBRARY = 'gklayout'
 
 GENERATED_FILES = [
     'DictionaryHelpers.h',
     'dom_quickstubs.h',
     'GeneratedEventClasses.h',
     'GeneratedEvents.h',
 ]
+
+# XPCShellImpl.cpp requires hardcoded vendor/profile/appname stuff on Windows
+# This sucks, bug 921148 tracks this.
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    if CONFIG['MOZ_APP_PROFILE']:
+        DEFINES['MOZ_APP_PROFILE'] = '"%s"' % CONFIG['MOZ_APP_PROFILE']
+    else:
+        if CONFIG['MOZ_APP_VENDOR']:
+            DEFINES['MOZ_APP_VENDOR'] = '"%s"' % CONFIG['MOZ_APP_VENDOR']
+        if CONFIG['MOZ_APP_BASENAME']:
+            DEFINES['MOZ_APP_BASENAME'] = '"%s"' % CONFIG['MOZ_APP_BASENAME']
+        DEFINES['MOZ_APP_NAME'] = '"%s"' % CONFIG['MOZ_APP_NAME']
+
+DEFINES['JS_THREADSAFE'] = True
+
+if CONFIG['MOZ_JSDEBUGGER']:
+    DEFINES['MOZ_JSDEBUGGER'] = True
--- a/js/xpconnect/tests/components/native/Makefile.in
+++ b/js/xpconnect/tests/components/native/Makefile.in
@@ -9,13 +9,11 @@ MANIFEST = xpctest.manifest
 MANIFEST_PATH = $(testxpcobjdir)/$(componentdir)
 PP_TARGETS += MANIFEST
 
 EXTRA_DSO_LDOPTS += \
   $(XPCOM_GLUE_LDOPTS) \
   $(MOZ_COMPONENT_LIBS) \
   $(NULL)
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(componentdir)
 INSTALL_TARGETS += LIB
--- a/js/xpconnect/tests/components/native/moz.build
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -12,8 +12,14 @@ UNIFIED_SOURCES += [
     'xpctest_params.cpp',
 ]
 
 LIBRARY_NAME = 'xpctest'
 
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -215,18 +215,16 @@ VISITED_REFTEST_FILES = \
 		$(topsrcdir)/layout/reftests/svg/pseudo-classes-02-ref.svg \
 		$(topsrcdir)/layout/reftests/svg/as-image/lime100x100.svg \
 		$(topsrcdir)/layout/reftests/svg/as-image/svg-image-visited-1-helper.svg \
 		$(topsrcdir)/layout/reftests/svg/as-image/svg-image-visited-2-helper.svg \
 		$(NULL)
 VISITED_REFTEST_DEST = $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)/css-visited/
 INSTALL_TARGETS += VISITED_REFTEST
 
-DEFINES += -DMOZILLA_INTERNAL_API
-
 ifdef COMPILE_ENVIRONMENT
 MOCHITEST_FILES += \
 		test_property_database.html \
 		css_properties.js \
 		$(NULL)
 
 css_properties.js: host_ListCSSProperties$(HOST_BIN_SUFFIX) css_properties_like_longhand.js Makefile
 	$(RM) $@
--- a/layout/style/test/moz.build
+++ b/layout/style/test/moz.build
@@ -11,8 +11,9 @@ HOST_SOURCES += [
 ]
 
 HOST_SIMPLE_PROGRAMS += [
     'host_%s' % f.replace('.cpp', '') for f in HOST_SOURCES
 ]
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
 
+DEFINES['MOZILLA_INTERNAL_API'] = True
--- a/layout/tables/Makefile.in
+++ b/layout/tables/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/.
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES         += -DDEBUG_TABLE_STRATEGY_off
-
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../base \
 		-I$(srcdir)/../generic \
 		-I$(srcdir)/../style \
 		-I$(srcdir)/../xul/base/src \
 		-I$(srcdir)/../../content/html/content/src \
 		-I$(srcdir)/../../content/base/src \
 		-I$(srcdir)/../../intl/unicharutil/util \
--- a/layout/tables/moz.build
+++ b/layout/tables/moz.build
@@ -25,8 +25,10 @@ UNIFIED_SOURCES += [
     'SpanningCellSorter.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gklayout'
+
+DEFINES['DEBUG_TABLE_STRATEGY_off'] = True
--- a/media/libcubeb/src/Makefile.in
+++ b/media/libcubeb/src/Makefile.in
@@ -1,43 +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/.
 
 
-ifeq ($(OS_TARGET),WINNT)
-DEFINES         += -DUSE_WINMM -DUSE_WASAPI
-endif
-
-ifeq ($(OS_TARGET),Android)
-ifneq ($(MOZ_WIDGET_TOOLKIT),gonk)
-DEFINES         += -DUSE_AUDIOTRACK
-endif
-DEFINES         += -DUSE_OPENSL
-endif
-
-ifeq ($(OS_TARGET),Darwin)
-DEFINES         += -DUSE_AUDIOUNIT
-endif
-
-ifeq ($(OS_ARCH),OpenBSD)
-DEFINES         += -DUSE_SNDIO
-endif
-
-ifdef MOZ_ALSA
-DEFINES         += -DUSE_ALSA
-endif
-
-ifdef MOZ_PULSEAUDIO
-DEFINES         += -DUSE_PULSE
-ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
-DEFINES         += -DDISABLE_LIBPULSE_DLOPEN
-endif
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 CFLAGS += \
         $(MOZ_ALSA_CFLAGS) \
         $(MOZ_PULSEAUDIO_CFLAGS) \
         $(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
--- a/media/libcubeb/src/moz.build
+++ b/media/libcubeb/src/moz.build
@@ -7,47 +7,55 @@
 SOURCES += [
     'cubeb.c',
 ]
 
 if CONFIG['MOZ_ALSA']:
     SOURCES += [
         'cubeb_alsa.c',
     ]
+    DEFINES['USE_ALSA'] = True
 
 if CONFIG['MOZ_PULSEAUDIO']:
     SOURCES += [
         'cubeb_pulse.c',
     ]
+    DEFINES['USE_PULSE'] = True
+    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+        DEFINES['DISABLE_LIBPULSE_DLOPEN'] = True
 
 if CONFIG['OS_ARCH'] == 'OpenBSD':
     SOURCES += [
         'cubeb_sndio.c',
     ]
+    DEFINES['USE_SNDIO'] = True
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     SOURCES += [
         'cubeb_audiounit.c',
     ]
+    DEFINES['USE_AUDIOUNIT'] = True
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     SOURCES += [
+        'cubeb_wasapi.cpp',
         'cubeb_winmm.c',
     ]
-    SOURCES += [
-        'cubeb_wasapi.cpp'
-    ]
+    DEFINES['USE_WINMM'] = True
+    DEFINES['USE_WASAPI'] = True
 
 if CONFIG['OS_TARGET'] == 'Android':
     SOURCES += [
         'cubeb_opensl.c',
     ]
+    DEFINES['USE_OPENSL'] = True
     if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
         SOURCES += [
             'cubeb_audiotrack.c',
         ]
+        DEFINES['USE_AUDIOTRACK'] = True
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
--- a/media/libopus/Makefile.in
+++ b/media/libopus/Makefile.in
@@ -1,34 +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/.
 
-DEFINES += \
-  -DOPUS_BUILD \
-  -DOPUS_VERSION='"v1.1-beta-23-gf2446c2-mozilla"' \
-  -DUSE_ALLOCA \
-  $(NULL)
-
-ifneq ($(filter $(OS_ARCH),Linux Darwin DragonFly FreeBSD NetBSD OpenBSD),)
-  DEFINES += -DHAVE_LRINTF
-endif
-ifeq ($(OS_ARCH), WINNT)
-  DEFINES += -Dinline=__inline
-ifdef GNU_CC
-  DEFINES += -DHAVE_LRINTF
-endif
-endif
-ifeq ($(OS_ARCH),AIX)
-DEFINES += -Dalloca=__alloca
-endif
-ifeq ($(OS_ARCH),SunOS)
-DEFINES += -DHAVE_ALLOCA_H
-endif
-
 LOCAL_INCLUDES += \
   -I$(srcdir)/include \
   -I$(srcdir)/celt \
   -I$(srcdir)/silk \
   -I$(srcdir)/src \
   $(NULL)
 
 VPATH += \
@@ -47,17 +25,16 @@ CSRCS = \
   $(notdir $(OPUS_SOURCES)) \
   $(NULL)
 
 ifndef MOZ_SAMPLE_TYPE_FLOAT32
   MOZ_OPUS_FIXED = 1
 endif
 
 ifdef MOZ_OPUS_FIXED
-DEFINES += -DFIXED_POINT=1 -DDISABLE_FLOAT_API
 LOCAL_INCLUDES += -I$(srcdir)/silk/fixed
 VPATH += $(srcdir)/silk/fixed
 CSRCS += $(notdir $(SILK_SOURCES_FIXED))
 else
 LOCAL_INCLUDES += -I$(srcdir)/silk/float
 VPATH += $(srcdir)/silk/float
 CSRCS += $(notdir $(SILK_SOURCES_FLOAT)) \
          $(notdir $(OPUS_SOURCES_FLOAT))
--- a/media/libopus/moz.build
+++ b/media/libopus/moz.build
@@ -9,8 +9,31 @@ EXPORTS.opus += [
     'include/opus_defines.h',
     'include/opus_multistream.h',
     'include/opus_types.h',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['OPUS_BUILD'] = True
+DEFINES['OPUS_VERSION'] = '"v1.1-beta-23-gf2446c2-mozilla"'
+DEFINES['USE_ALLOCA'] = True
+
+if CONFIG['OS_ARCH'] in ('Linux', 'Darwin', 'DragonFly', 'FreeBSD',
+                         'NetBSD', 'OpenBSD'):
+    DEFINES['HAVE_LRINTF'] = True
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    DEFINES['inline'] = '__inline'
+    if CONFIG['GNU_CC']:
+        DEFINES['HAVE_LRINTF'] = True
+
+if CONFIG['OS_ARCH'] == 'AIX':
+    DEFINES['alloca'] = '__alloca'
+
+if CONFIG['OS_ARCH'] == 'SunOS':
+    DEFINES['HAVE_ALLOCA_H'] = True
+
+if not CONFIG['MOZ_SAMPLE_TYPE_FLOAT32']:
+    DEFINES['FIXED_POINT'] = 1
+    DEFINES['DISABLE_FLOAT_API'] = True
--- a/media/libsoundtouch/src/Makefile.in
+++ b/media/libsoundtouch/src/Makefile.in
@@ -1,15 +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/.
 
-# Use abort() instead of exception in SoundTouch.
-DEFINES += -DST_NO_EXCEPTION_HANDLING=1
-
 include $(topsrcdir)/config/rules.mk
 
 ifneq (,$(INTEL_ARCHITECTURE))
 ifdef GNU_CC
 mmx_optimized.$(OBJ_SUFFIX): CXXFLAGS+=-msse2
 sse_optimized.$(OBJ_SUFFIX): CXXFLAGS+=-msse2
 endif
 ifdef SOLARIS_SUNPRO_CXX
--- a/media/libsoundtouch/src/moz.build
+++ b/media/libsoundtouch/src/moz.build
@@ -31,8 +31,11 @@ if CONFIG['INTEL_ARCHITECTURE']:
             'mmx_optimized.cpp',
         ]
 
 MSVC_ENABLE_PGO = True
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+# Use abort() instead of exception in SoundTouch.
+DEFINES['ST_NO_EXCEPTION_HANDLING'] = 1
--- a/media/libspeex_resampler/src/Makefile.in
+++ b/media/libspeex_resampler/src/Makefile.in
@@ -1,29 +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/.
 
-# We don't compile the full speex codec, only the resampler.
-DEFINES += -DOUTSIDE_SPEEX
-# Speex wants a random prefix when building in another program, to avoid name
-# clashes
-DEFINES += -DRANDOM_PREFIX=speex
-# We don't use -fvisibility=hidden
-DEFINES += -DSPX_RESAMPLE_EXPORT=
-
-ifeq ($(OS_TARGET),Android)
-DEFINES += -DFIXED_POINT
-else
-DEFINES += -DFLOATING_POINT
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 # Only use SSE code when using floating point samples, and on x86
 ifneq (,$(INTEL_ARCHITECTURE))
 ifneq ($(OS_TARGET),Android)
-DEFINES += -D_USE_SSE -D_USE_SSE2
 ifdef GNU_CC
 resample.$(OBJ_SUFFIX): CFLAGS+=-msse2
 endif
 endif
 endif
--- a/media/libspeex_resampler/src/moz.build
+++ b/media/libspeex_resampler/src/moz.build
@@ -16,8 +16,26 @@ SOURCES += [
 
 SOURCES += [
     'resample.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+# We don't compile the full speex codec, only the resampler.
+DEFINES['OUTSIDE_SPEEX'] = True
+# Speex wants a random prefix when building in another program, to avoid name
+# clashes
+DEFINES['RANDOM_PREFIX'] = 'speex'
+# We don't use -fvisibility=hidden
+DEFINES['SPX_RESAMPLE_EXPORT'] = ''
+
+if CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['FIXED_POINT'] = True
+else:
+    DEFINES['FLOATING_POINT'] = True
+
+# Only use SSE code when using floating point samples, and on x86
+if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['OS_TARGET'] != 'Android':
+    DEFINES['_USE_SSE'] = True
+    DEFINES['_USE_SSE2'] = True
--- a/media/libtheora/lib/Makefile.in
+++ b/media/libtheora/lib/Makefile.in
@@ -1,38 +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/.
 
 
-# The encoder is currently not included.
-DEFINES += -DTHEORA_DISABLE_ENCODE
-
-ifeq ($(findstring 86,$(OS_TEST)), 86)
-ifneq ($(OS_ARCH),SunOS)
-ifneq ($(OS_ARCH)$(OS_TEST),WINNTx86_64)
-DEFINES += -DOC_X86_ASM
-ifeq (64,$(findstring 64,$(OS_TEST)))
-DEFINES += -DOC_X86_64_ASM
-endif
-endif
-endif
-endif
-
 ifdef GNU_AS
 ifeq ($(findstring arm,$(OS_TEST)), arm)
 
-DEFINES += -DOC_ARM_ASM -DOC_ARM_ASM_EDSP -DOC_ARM_ASM_MEDIA -DOC_ARM_ASM_NEON
-
-# The Android NDK doesn't pre-define anything to indicate the OS it's on, so
-# do it for them.
-ifeq ($(OS_TARGET),Android)
-DEFINES += -D__linux__
-endif
-
 # These flags are a lie; they're just used to enable the requisite
 # opcodes; actual arch detection is done at runtime.
 ASFLAGS = -march=armv7-a -mfpu=neon
 
 armfrag-gnu.$(ASM_SUFFIX): armopts-gnu.S
 armidct-gnu.$(ASM_SUFFIX): armopts-gnu.S
 armloop-gnu.$(ASM_SUFFIX): armopts-gnu.S
 
--- a/media/libtheora/lib/moz.build
+++ b/media/libtheora/lib/moz.build
@@ -24,16 +24,21 @@ if CONFIG['OS_TEST'] == 'arm' and CONFIG
     GENERATED_SOURCES += [ '%s.%s' % (f, CONFIG['ASM_SUFFIX']) for f in [
         'armbits-gnu',
         'armfrag-gnu',
         'armidct-gnu',
         'armloop-gnu',
     ]]
 
 if '86' in CONFIG['OS_TEST']:
+    if CONFIG['OS_ARCH'] != 'SunOS':
+        if CONFIG['OS_ARCH'] != 'WINNT' or CONFIG['OS_TEST'] != 'x86_64':
+            DEFINES['OC_X86_ASM'] = True
+            if '64' in CONFIG['OS_TEST']:
+                DEFINES['OC_X86_64_ASM'] = True
     if CONFIG['_MSC_VER']:
         if '64' not in CONFIG['OS_TEST']:
             SOURCES += [
                 'x86_vc/mmxfrag.c',
                 'x86_vc/mmxidct.c',
                 'x86_vc/mmxstate.c',
                 'x86_vc/x86cpu.c',
                 'x86_vc/x86state.c',
@@ -49,15 +54,25 @@ if '86' in CONFIG['OS_TEST']:
         ]
 
 if CONFIG['GNU_AS']:
     if 'arm' in CONFIG['OS_TEST']:
         SOURCES += [
             'arm/armcpu.c',
             'arm/armstate.c',
         ]
+        for var in ('OC_ARM_ASM', 'OC_ARM_ASM_EDSP', 'OC_ARM_ASM_MEDIA',
+                    'OC_ARM_ASM_NEON'):
+            DEFINES[var] = True
+        # The Android NDK doesn't pre-define anything to indicate the OS it's
+        # on, so do it for them.
+        if CONFIG['OS_TARGET'] == 'Android':
+            DEFINES['__linux__'] = True
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+# The encoder is currently not included.
+DEFINES['THEORA_DISABLE_ENCODE'] = True
--- a/media/libtremor/lib/Makefile.in
+++ b/media/libtremor/lib/Makefile.in
@@ -1,13 +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/.
 
 LOCAL_INCLUDES += -I$(topsrcdir)/media/libtremor/include/tremor
-
-ifeq ($(OS_ARCH),AIX)
-DEFINES += -Dalloca=__alloca
-endif
-
-ifeq (arm_1_, $(TARGET_CPU)_$(GNU_CC)_$(MOZ_THUMB2))
-DEFINES += -D_ARM_ASSEM_
-endif
--- a/media/libtremor/lib/moz.build
+++ b/media/libtremor/lib/moz.build
@@ -15,8 +15,14 @@ SOURCES += [
     'tremor_registry.c',
     'tremor_res012.c',
     'tremor_sharedbook.c',
     'tremor_synthesis.c',
     'tremor_window.c',
 ]
 
 FINAL_LIBRARY = 'gkmedias'
+
+if CONFIG['OS_ARCH'] == 'AIX':
+    DEFINES['alloca'] = '__alloca'
+
+if CONFIG['TARGET_CPU'] == 'arm' and CONFIG['GNU_CC'] and not CONFIG['MOZ_THUMB2']:
+    DEFINES['_ARM_ASSEM_'] = True
--- a/media/libvpx/Makefile.in
+++ b/media/libvpx/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/.
 
-
-DEFINES += -DHAVE_CONFIG_H=vpx_config.h
-
-
 LOCAL_INCLUDES += \
   -I. \
   -I$(topsrcdir)/media/libvpx \
   -I$(topsrcdir)/media/libvpx/vp8/ \
   -I$(topsrcdir)/media/libvpx/vp8/common/ \
   -I$(topsrcdir)/media/libvpx/vp8/common/arm \
   -I$(topsrcdir)/media/libvpx/vp8/common/x86 \
   -I$(topsrcdir)/media/libvpx/vp8/decoder \
@@ -181,21 +177,16 @@ endif
 
 endif
 
 ifdef VPX_ARM_ASM
 # Building on an ARM platform with a supported assembler, include
 # the optimized assembly in the build.
 
 ifeq ($(OS_TARGET),Android)
-
-# Older versions of the Android NDK don't pre-define anything to indicate the
-# OS they're on, so do it for them.
-DEFINES += -D__linux__
-
 # For cpu-features.h
 LOCAL_INCLUDES += -I$(ANDROID_NDK)/sources/android/cpufeatures
 ifndef MOZ_WEBRTC
 # For cpu-features.c
 VPATH += $(ANDROID_NDK)/sources/android/cpufeatures
 CSRCS += cpu-features.c
 endif
 endif
--- a/media/libvpx/moz.build
+++ b/media/libvpx/moz.build
@@ -89,8 +89,15 @@ SOURCES += [
 ]
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['HAVE_CONFIG_H'] = 'vpx_config.h'
+
+if CONFIG['OS_TARGET'] == 'Android':
+    # Older versions of the Android NDK don't pre-define anything to indicate
+    # the OS they're on, so do it for them.
+    DEFINES['__linux__'] = True
deleted file mode 100644
--- a/media/mtransport/build/Makefile.in
+++ /dev/null
@@ -1,46 +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/.
-
-DEFINES += -DHAVE_STRDUP -DNR_SOCKET_IS_VOID_PTR
-
-ifneq (,$(filter Darwin DragonFly FreeBSD NetBSD OpenBSD,$(OS_TARGET)))
-ifeq ($(OS_TARGET), Darwin)
-DEFINES += -DDARWIN
-else
-DEFINES += -DBSD
-endif
-endif
-
-ifeq ($(OS_TARGET), Linux)
-DEFINES += -DLINUX -DUSE_INTERFACE_PRIORITIZER
-endif
-
-ifeq ($(OS_TARGET), Android)
-DEFINES += -DLINUX -DANDROID
-endif
-
-ifeq ($(OS_TARGET), WINNT)
-DEFINES += -DWIN
-endif
-
-DEFINES += \
-   -DR_DEFINED_INT2=int16_t -DR_DEFINED_UINT2=uint16_t \
-   -DR_DEFINED_INT4=int32_t -DR_DEFINED_UINT4=uint32_t \
-   -DR_DEFINED_INT8=int64_t -DR_DEFINED_UINT8=uint64_t \
-   $(NULL)
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DUSE_INTERFACE_PRIORITIZER
-endif
-
-# for stun.h
-ifeq (WINNT,$(OS_TARGET))
-DEFINES += \
-  -DWIN32 \
-  -DNOMINMAX \
-  $(NULL)
-else ifeq (Linux,$(OS_TARGET))
-DEFINES += -DLINUX
-endif
--- a/media/mtransport/build/moz.build
+++ b/media/mtransport/build/moz.build
@@ -50,28 +50,53 @@ LOCAL_INCLUDES += [
     '/media/mtransport/third_party/nrappkit/src/port/generic/include',
     '/media/mtransport/third_party/nrappkit/src/registry',
     '/media/mtransport/third_party/nrappkit/src/share',
     '/media/mtransport/third_party/nrappkit/src/stats',
     '/media/mtransport/third_party/nrappkit/src/util/libekr',
 ]
 
 if CONFIG['OS_TARGET'] in ['Darwin', 'DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD']:
+    if CONFIG['OS_TARGET'] == 'Darwin':
+        DEFINES['DARWIN'] = True
+    else:
+        DEFINES['BSD'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/darwin/include',
     ]
 elif CONFIG['OS_TARGET'] == 'Linux':
+    DEFINES['LINUX'] = True
+    DEFINES['USE_INTERFACE_PRIORITIZER'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/linux/include',
     ]
 elif CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['LINUX'] = True
+    DEFINES['ANDROID'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/android/include',
     ]
 elif CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['WIN'] = True
+    # for stun.h
+    DEFINES['WIN32'] = True
+    DEFINES['NOMINMAX'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/win32/include',
     ]
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'xul'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['USE_INTERFACE_PRIORITIZER'] = True
+
+for var in ('HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR'):
+    DEFINES[var] = True
+
+DEFINES['R_DEFINED_INT2'] = 'int16_t'
+DEFINES['R_DEFINED_UINT2'] = 'uint16_t'
+DEFINES['R_DEFINED_INT4'] = 'int32_t'
+DEFINES['R_DEFINED_UINT4'] = 'uint32_t'
+DEFINES['R_DEFINED_INT8'] = 'int64_t'
+DEFINES['R_DEFINED_UINT8'] = 'uint64_t'
deleted file mode 100644
--- a/media/mtransport/standalone/Makefile.in
+++ /dev/null
@@ -1,48 +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/.
-
-
-DEFINES += -DHAVE_STRDUP -DNR_SOCKET_IS_VOID_PTR
-
-ifneq (,$(filter Darwin DragonFly FreeBSD NetBSD OpenBSD,$(OS_TARGET)))
-ifeq ($(OS_TARGET), Darwin)
-DEFINES += -DDARWIN
-else
-DEFINES += -DBSD
-endif
-endif
-
-ifeq ($(OS_TARGET), Linux)
-DEFINES += -DLINUX -DUSE_INTERFACE_PRIORITIZER
-endif
-
-ifeq ($(OS_TARGET), Android)
-DEFINES += -DLINUX -DANDROID
-endif
-
-ifeq ($(OS_TARGET), WINNT)
-DEFINES += -DWIN
-endif
-
-DEFINES += \
-   -DR_DEFINED_INT2=int16_t -DR_DEFINED_UINT2=uint16_t \
-   -DR_DEFINED_INT4=int32_t -DR_DEFINED_UINT4=uint32_t \
-   -DR_DEFINED_INT8=int64_t -DR_DEFINED_UINT8=uint64_t \
-   $(NULL)
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DUSE_INTERFACE_PRIORITIZER
-endif
-
-# for stun.h
-ifeq (WINNT,$(OS_TARGET))
-DEFINES += \
-  -DWIN32 \
-  -DNOMINMAX \
-  $(NULL)
-else ifeq (Linux,$(OS_TARGET))
-DEFINES += -DLINUX
-endif
-
--- a/media/mtransport/standalone/moz.build
+++ b/media/mtransport/standalone/moz.build
@@ -28,25 +28,50 @@ LOCAL_INCLUDES += [
     '/media/mtransport/third_party/nrappkit/src/port/generic/include',
     '/media/mtransport/third_party/nrappkit/src/registry',
     '/media/mtransport/third_party/nrappkit/src/share',
     '/media/mtransport/third_party/nrappkit/src/stats',
     '/media/mtransport/third_party/nrappkit/src/util/libekr',
 ]
 
 if CONFIG['OS_TARGET'] in ['Darwin', 'DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD']:
+    if CONFIG['OS_TARGET'] == 'Darwin':
+        DEFINES['DARWIN'] = True
+    else:
+        DEFINES['BSD'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/darwin/include',
     ]
 elif CONFIG['OS_TARGET'] == 'Linux':
+    DEFINES['LINUX'] = True
+    DEFINES['USE_INTERFACE_PRIORITIZER'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/linux/include',
     ]
 elif CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['LINUX'] = True
+    DEFINES['ANDROID'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/android/include',
     ]
 elif CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['WIN'] = True
+    # for stun.h
+    DEFINES['WIN32'] = True
+    DEFINES['NOMINMAX'] = True
     LOCAL_INCLUDES += [
         '/media/mtransport/third_party/nrappkit/src/port/win32/include',
     ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['USE_INTERFACE_PRIORITIZER'] = True
+
+for var in ('HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR'):
+    DEFINES[var] = True
+
+DEFINES['R_DEFINED_INT2'] = 'int16_t'
+DEFINES['R_DEFINED_UINT2'] = 'uint16_t'
+DEFINES['R_DEFINED_INT4'] = 'int32_t'
+DEFINES['R_DEFINED_UINT4'] = 'uint32_t'
+DEFINES['R_DEFINED_INT8'] = 'int64_t'
+DEFINES['R_DEFINED_UINT8'] = 'uint64_t'
--- a/media/mtransport/test/Makefile.in
+++ b/media/mtransport/test/Makefile.in
@@ -1,18 +1,12 @@
 # -*- 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/.
-DEFINES += \
-  -DHAVE_STRDUP -DNR_SOCKET_IS_VOID_PTR -DSCTP_DEBUG -DINET
-
-ifneq ($(OS_TARGET),Android)
-DEFINES += -DINET6
-endif
 
 LIBS = \
   $(XPCOM_LIBS) \
   $(NSPR_LIBS) \
   $(NSS_LIBS) \
   $(DEPTH)/media/mtransport/standalone/$(LIB_PREFIX)mtransport_s.$(LIB_SUFFIX) \
   $(DEPTH)/media/mtransport/third_party/nICEr/nicer_nicer/$(LIB_PREFIX)nicer.$(LIB_SUFFIX) \
   $(DEPTH)/media/mtransport/third_party/nrappkit/nrappkit_nrappkit/$(LIB_PREFIX)nrappkit.$(LIB_SUFFIX) \
@@ -43,58 +37,30 @@ LOCAL_INCLUDES += \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/util/libekr \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/log \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/registry \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/stats \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/plugin \
  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/event \
  $(NULL)
 
-# SCTP DEFINES
-ifeq ($(OS_TARGET),WINNT)
-DEFINES += -D__Userspace_os_Windows=1
-else
-ifeq ($(OS_TARGET),Darwin)
-DEFINES += -D__Userspace_os_Darwin=1
-else
-ifeq ($(OS_TARGET),Linux)
-DEFINES += -D__Userspace_os_Linux=1
-else
-ifeq ($(OS_TARGET),FreeBSD)
-DEFINES += -D__Userspace_os_FreeBSD=1
-else
-#default_fallback; probably doesn't work
-DEFINES += -D__Userspace_os_$(OS_TARGET)=1
-endif
-endif
-endif
-endif
-
 ifneq (,$(filter Darwin DragonFly FreeBSD NetBSD OpenBSD,$(OS_TARGET)))
 LOCAL_INCLUDES +=  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/port/darwin/include
 ifneq (,$(filter DragonFly FreeBSD NetBSD OpenBSD,$(OS_TARGET)))
 LOCAL_INCLUDES +=  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/port/generic/include
 endif
-ifeq ($(OS_TARGET), Darwin)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-  $(NULL)
-endif
 endif
 
 ifeq ($(OS_TARGET), Linux)
 LOCAL_INCLUDES +=  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/port/linux/include
 endif
 
 ifeq ($(OS_TARGET), Android)
 LOCAL_INCLUDES +=  -I$(topsrcdir)/media/mtransport/third_party/nrappkit/src/port/android/include
 
 LIBS += \
   $(STLPORT_LDFLAGS) \
   $(STLPORT_LIBS) \
   $(NULL)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-  $(NULL)
 endif
--- a/media/mtransport/test/moz.build
+++ b/media/mtransport/test/moz.build
@@ -19,8 +19,23 @@ if CONFIG['OS_TARGET'] != 'WINNT' and CO
 
     if CONFIG['MOZ_SCTP']:
         CPP_UNIT_TESTS += [
             'sctp_unittest.cpp',
         ]
 
 FAIL_ON_WARNINGS = True
 
+for var in ('HAVE_STRDUP', 'NR_SOCKET_IS_VOID_PTR', 'SCTP_DEBUG', 'INET'):
+    DEFINES[var] = True
+
+if CONFIG['OS_TARGET'] != 'Android':
+    DEFINES['INET6'] = True
+
+# SCTP DEFINES
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['__Userspace_os_Windows'] = 1
+else:
+    # Works for Darwin, Linux, Android. Probably doesn't work for others.
+    DEFINES['__Userspace_os_%s' % CONFIG['OS_TARGET']] = 1
+
+if CONFIG['OS_TARGET'] in ('Darwin', 'Android'):
+    DEFINES['GTEST_USE_OWN_TR1_TUPLE'] = 1
--- a/media/webrtc/signaling/test/Makefile.in
+++ b/media/webrtc/signaling/test/Makefile.in
@@ -28,19 +28,16 @@ endif
 ifeq ($(OS_TARGET),Android)
 LIBS += \
   $(STLPORT_LDFLAGS) \
   $(STLPORT_LIBS) \
   $(NULL)
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-   $(NULL)
 endif
 
 ifdef MOZ_NATIVE_JPEG
 LIBS += \
   $(MOZ_JPEG_LIBS) \
   $(NULL)
 endif
 
@@ -103,29 +100,16 @@ LIBS += \
 endif
 
 ifeq ($(OS_TARGET),WINNT)
 LIBS += \
   $(DEPTH)/staticlib/components/$(LIB_PREFIX)windowsproxy.$(LIB_SUFFIX) \
   $(NULL)
 endif
 
-DEFINES += \
-  -DUSE_FAKE_MEDIA_STREAMS \
-  -DUSE_FAKE_PCOBSERVER \
-  -DNR_SOCKET_IS_VOID_PTR \
-  -DHAVE_STRDUP \
-  $(NULL)
-
-ifeq ($(OS_TARGET),Darwin)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-  $(NULL)
-endif
-
 LOCAL_INCLUDES += \
  -I. \
  -I$(topsrcdir)/media/webrtc/trunk/testing/gtest/include \
  -I$(topsrcdir)/ipc/chromium/src \
  -I$(topsrcdir)/media/mtransport \
  -I$(topsrcdir)/media/mtransport/test \
  -I$(topsrcdir)/media/webrtc/signaling/include \
  -I$(topsrcdir)/media/webrtc/signaling/src/sipcc/core/sdp \
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -8,8 +8,14 @@ if CONFIG['OS_TARGET'] != 'WINNT' and CO
     CPP_UNIT_TESTS += [
         'mediaconduit_unittests.cpp',
         'mediapipeline_unittest.cpp',
         'sdp_unittests.cpp',
         'signaling_unittests.cpp',
     ]
 include('/ipc/chromium/chromium-config.mozbuild')
 
+if CONFIG['OS_TARGET'] in ('Darwin', 'Android'):
+    DEFINES['GTEST_USE_OWN_TR1_TUPLE'] = 1
+
+for var in ('USE_FAKE_MEDIA_STREAMS', 'USE_FAKE_PCOBSERVER',
+            'NR_SOCKET_IS_VOID_PTR', 'HAVE_STRDUP'):
+    DEFINES[var] = True
--- a/memory/build/Makefile.in
+++ b/memory/build/Makefile.in
@@ -3,31 +3,27 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 STLFLAGS =
 ifdef MOZ_GLUE_PROGRAM_LDFLAGS
 SDK_LIBRARY = $(REAL_LIBRARY)
 DIST_INSTALL = 1
 endif
 
-DEFINES += -DMOZ_MEMORY_IMPL
-
 ifdef MOZ_JEMALLOC3
 LOCAL_INCLUDES += -I../jemalloc/src/include
 ifdef _MSC_VER
 LOCAL_INCLUDES += -I$(topsrcdir)/memory/jemalloc/src/include/msvc_compat
 endif
 
 ifndef MOZ_NATIVE_JEMALLOC
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
 endif
 else
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/mozjemalloc)
 endif
 
 ifdef MOZ_REPLACE_MALLOC
-DEFINES += -DMOZ_REPLACE_MALLOC
-
 # The zone allocator for OSX needs some jemalloc internal functions
 ifeq (Darwin,$(OS_TARGET))
 LOCAL_INCLUDES += -I$(topsrcdir)/memory/jemalloc/src/include
 endif
 endif
--- a/memory/build/moz.build
+++ b/memory/build/moz.build
@@ -4,21 +4,25 @@
 # 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/.
 
 EXPORTS += [
     'mozmemory.h',
     'mozmemory_wrap.h',
 ]
 
+DEFINES['MOZ_MEMORY_IMPL'] = True
+
 if CONFIG['MOZ_REPLACE_MALLOC']:
     EXPORTS += [
         'malloc_decls.h',
         'replace_malloc.h',
     ]
+    DEFINES['MOZ_REPLACE_MALLOC'] = True
+
 SOURCES += [
     'jemalloc_config.c',
     'mozmemory_wrap.c',
 ]
 
 if CONFIG['MOZ_JEMALLOC3']:
     SOURCES += [
         'mozjemalloc_compat.c',
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -13,22 +13,13 @@ include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES += \
   -I$(srcdir)/src/include \
   -Isrc/include \
   $(NULL)
 
 ifdef _MSC_VER
 LOCAL_INCLUDES += -I$(srcdir)/src/include/msvc_compat
-
-DEFINES += -DDLLEXPORT
-endif
-
-ifeq ($(OS_TARGET),Linux)
-# For mremap
-DEFINES += -D_GNU_SOURCE
 endif
 
 ifdef GNU_CC
 CFLAGS += -std=gnu99
 endif
-
-DEFINES += -Dabort=moz_abort
--- a/memory/jemalloc/moz.build
+++ b/memory/jemalloc/moz.build
@@ -34,8 +34,17 @@ SOURCES += [
 if CONFIG['OS_TARGET'] == 'Darwin' and not CONFIG['MOZ_REPLACE_MALLOC']:
     SOURCES += [
         'src/src/zone.c',
     ]
 
 LIBRARY_NAME = 'jemalloc'
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['DLLEXPORT'] = True
+
+if CONFIG['OS_TARGET'] == 'Linux':
+    # For mremap
+    DEFINES['_GNU_SOURCE'] = True
+
+DEFINES['abort'] = 'moz_abort'
--- a/memory/mozalloc/Makefile.in
+++ b/memory/mozalloc/Makefile.in
@@ -5,20 +5,15 @@
 
 STL_FLAGS	=
 ifdef _MSC_VER
 STL_FLAGS	= -D_HAS_EXCEPTIONS=0
 endif
 
 DIST_INSTALL 	= 1
 
-ifeq (,$(filter-out OS2,$(OS_ARCH)))
-# The strndup declaration in string.h is in an ifdef __USE_GNU section
-DEFINES		+= -D_GNU_SOURCE
-endif
-
 ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
 SDK_LIBRARY = $(IMPORT_LIBRARY)
 else
 SDK_LIBRARY = $(SHARED_LIBRARY)
 endif
 
 LOCAL_INCLUDES += -I$(DEPTH)/xpcom
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -39,8 +39,12 @@ UNIFIED_SOURCES += [
 ]
 
 LIBRARY_NAME = 'mozalloc'
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     FORCE_STATIC_LIB = True
 else:
     FORCE_SHARED_LIB = True
+
+if CONFIG['OS_ARCH'] != 'OS2':
+    # The strndup declaration in string.h is in an ifdef __USE_GNU section
+    DEFINES['_GNU_SOURCE'] = True
--- a/memory/mozjemalloc/Makefile.in
+++ b/memory/mozjemalloc/Makefile.in
@@ -13,22 +13,8 @@ endif
 ifeq (Linux,$(OS_TARGET))
 #XXX: PGO on Linux causes problems here
 # See bug 419470
 NO_PROFILE_GUIDED_OPTIMIZE = 1
 endif
 endif
 
 LOCAL_INCLUDES += -I$(topsrcdir)/memory/build
-
-# For non release/esr builds, enable (some) fatal jemalloc assertions.  This
-# helps us catch memory errors.
-ifeq (,$(filter release esr,$(MOZ_UPDATE_CHANNEL)))
-DEFINES	+= -DMOZ_JEMALLOC_HARD_ASSERTS
-endif
-
-DEFINES += -Dabort=moz_abort
-
-ifdef MOZ_REPLACE_MALLOC
-DEFINES += -DMOZ_REPLACE_MALLOC
-endif
-
-DEFINES += -DMOZ_JEMALLOC_IMPL
--- a/memory/mozjemalloc/moz.build
+++ b/memory/mozjemalloc/moz.build
@@ -9,8 +9,20 @@ EXPORTS += [
 ]
 
 if not CONFIG['MOZ_JEMALLOC3']:
     SOURCES += [
         'jemalloc.c',
     ]
     LIBRARY_NAME = 'jemalloc'
     FORCE_STATIC_LIB = True
+
+# For non release/esr builds, enable (some) fatal jemalloc assertions.  This
+# helps us catch memory errors.
+if CONFIG['MOZ_UPDATE_CHANNEL'] not in ('release', 'esr'):
+    DEFINES['MOZ_JEMALLOC_HARD_ASSERTS'] = True
+
+DEFINES['abort'] = 'moz_abort'
+
+if CONFIG['MOZ_REPLACE_MALLOC']:
+    DEFINES['MOZ_REPLACE_MALLOC'] = True
+
+DEFINES['MOZ_JEMALLOC_IMPL'] = True
--- a/memory/replace/dmd/Makefile.in
+++ b/memory/replace/dmd/Makefile.in
@@ -1,15 +1,13 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEFINES 	+= -DMOZ_NO_MOZALLOC
-
 # Disable mozglue.
 WRAP_LDFLAGS 	=
 MOZ_GLUE_LDFLAGS=
 
 STL_FLAGS 	=
 
 ifeq ($(OS_ARCH),WINNT)
 OS_LIBS         += $(call EXPAND_LIBNAME,dbghelp)
--- a/memory/replace/dmd/moz.build
+++ b/memory/replace/dmd/moz.build
@@ -16,8 +16,10 @@ SOURCES += [
 
 SOURCES += [
     '../../../nsprpub/lib/libc/src/strcpy.c',
 ]
 
 LIBRARY_NAME = 'dmd'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
--- a/memory/replace/jemalloc/Makefile.in
+++ b/memory/replace/jemalloc/Makefile.in
@@ -1,14 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
-DEFINES += -DMOZ_JEMALLOC3 -DMOZ_REPLACE_JEMALLOC
 LOCAL_INCLUDES += -I../../jemalloc/src/include
 ifdef _MSC_VER
 LOCAL_INCLUDES += -I$(topsrcdir)/memory/jemalloc/src/include/msvc_compat
 endif
 
 VPATH += $(topsrcdir)/memory/build
 
 MOZ_GLUE_LDFLAGS = # Don't link against mozglue
--- a/memory/replace/jemalloc/moz.build
+++ b/memory/replace/jemalloc/moz.build
@@ -16,8 +16,11 @@ SOURCES += [
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     SOURCES += [
         'pthread_atfork.c',
     ]
 
 LIBRARY_NAME = 'replace_jemalloc'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['MOZ_JEMALLOC3'] = True
+DEFINES['MOZ_REPLACE_JEMALLOC'] = True
--- a/mfbt/tests/Makefile.in
+++ b/mfbt/tests/Makefile.in
@@ -8,14 +8,11 @@ STL_FLAGS =
 # 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=
 
-# Since we link directly with MFBT object files, define IMPL_MFBT
-DEFINES += -DIMPL_MFBT
-
 include $(topsrcdir)/config/rules.mk
 
 LIBS= $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
--- a/mfbt/tests/moz.build
+++ b/mfbt/tests/moz.build
@@ -21,8 +21,11 @@ CPP_UNIT_TESTS += [
     'TestTypeTraits.cpp',
     'TestWeakPtr.cpp',
 ]
 
 if not CONFIG['MOZ_ASAN']:
     CPP_UNIT_TESTS += [
         'TestPoisonArea.cpp',
     ]
+
+# Since we link directly with MFBT object files, define IMPL_MFBT
+DEFINES['IMPL_MFBT'] = True
--- a/mobile/android/app/Makefile.in
+++ b/mobile/android/app/Makefile.in
@@ -10,42 +10,30 @@ DIST_FILES = recommended-addons.json
 ifndef LIBXUL_SDK
 ifneq (Android,$(OS_TARGET))
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(NULL)
 
 endif
 endif #LIBXUL_SDK
 
 # Make sure the standalone glue doesn't try to get libxpcom.so from mobile/app.
 NSDISTMODE = copy
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += \
-  -DAPP_NAME=$(MOZ_APP_NAME) \
-  -DAPP_VERSION=$(MOZ_APP_VERSION) \
-  -DMOZ_UPDATER=$(MOZ_UPDATER) \
-  -DMOZ_APP_UA_NAME=$(MOZ_APP_UA_NAME) \
-  $(NULL)
-
-ifdef MOZ_PKG_SPECIAL
-DEFINES += -DMOZ_PKG_SPECIAL=$(MOZ_PKG_SPECIAL)
-endif
-
 APP_BINARY = $(MOZ_APP_NAME)$(BIN_SUFFIX)
 
 libs::
 ifdef LIBXUL_SDK
 	cp $(LIBXUL_DIST)/bin/xulrunner-stub$(BIN_SUFFIX) $(DIST)/bin/$(APP_BINARY)
 endif
 ifndef SKIP_COPY_XULRUNNER #{
 ifdef LIBXUL_SDK
--- a/mobile/android/app/moz.build
+++ b/mobile/android/app/moz.build
@@ -2,8 +2,18 @@
 # 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['OS_TARGET'] != 'Android':
         PROGRAM = CONFIG['MOZ_APP_NAME']
+        DEFINES['XPCOM_GLUE'] = True
+
+for var in ('APP_NAME', 'APP_VERSION'):
+    DEFINES[var] = CONFIG['MOZ_%s' % var]
+
+for var in ('MOZ_UPDATER', 'MOZ_APP_UA_NAME'):
+    DEFINES[var] = CONFIG[var]
+
+if CONFIG['MOZ_PKG_SPECIAL']:
+    DEFINES['MOZ_PKG_SPECIAL'] = CONFIG['MOZ_PKG_SPECIAL']
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -1,18 +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_FILES := package-name.txt.in
 
-ifdef MOZ_ANDROID_ANR_REPORTER
-DEFINES += -DMOZ_ANDROID_ANR_REPORTER=1
-endif
-
 ifneq (,$(findstring -march=armv7,$(OS_CFLAGS)))
 MIN_CPU_VERSION=7
 else
 MIN_CPU_VERSION=5
 endif
 
 MOZ_APP_BUILDID=$(shell cat $(DEPTH)/config/buildid)
 
@@ -29,58 +25,25 @@ else #not arm, so x86
 ANDROID_VERSION_CODE=$(shell echo $$((`cat $(DEPTH)/config/buildid | cut -c1-10` + 1)))
 endif
 endif
 
 UA_BUILDID=$(shell echo $(ANDROID_VERSION_CODE) | cut -c1-8)
 
 MOZ_BUILD_TIMESTAMP=$(shell echo `$(PYTHON) $(topsrcdir)/toolkit/xre/make-platformini.py --print-timestamp`)
 
-ifdef MOZ_UPDATER
-DEFINES +=  -DMOZ_UPDATER=$(MOZ_UPDATER)
-endif
-
-# Mangle our package name to avoid Bug 750548.
 DEFINES += \
-  -DMANGLED_ANDROID_PACKAGE_NAME=$(subst fennec,f3nn3c,$(ANDROID_PACKAGE_NAME)) \
-  -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
-  -DANDROID_CPU_ARCH=$(ANDROID_CPU_ARCH) \
   -DANDROID_VERSION_CODE=$(ANDROID_VERSION_CODE) \
-  -DCPU_ARCH=$(CPU_ARCH) \
-  -DGRE_MILESTONE=$(GRE_MILESTONE) \
-  -DMOZILLA_OFFICIAL=$(MOZILLA_OFFICIAL) \
   -DMOZ_ANDROID_SHARED_ID="$(MOZ_ANDROID_SHARED_ID)" \
   -DMOZ_ANDROID_SHARED_ACCOUNT_TYPE="$(MOZ_ANDROID_SHARED_ACCOUNT_TYPE)" \
-  -DMOZ_APP_ABI=$(TARGET_XPCOM_ABI) \
-  -DMOZ_APP_BASENAME=$(MOZ_APP_BASENAME) \
   -DMOZ_APP_BUILDID=$(MOZ_APP_BUILDID) \
-  -DMOZ_APP_DISPLAYNAME="$(MOZ_APP_DISPLAYNAME)" \
-  -DMOZ_APP_ID=$(MOZ_APP_ID) \
-  -DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-  -DMOZ_APP_VENDOR=$(MOZ_APP_VENDOR) \
-  -DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
   -DMOZ_BUILD_TIMESTAMP=$(MOZ_BUILD_TIMESTAMP) \
-  -DMOZ_CHILD_PROCESS_NAME=$(MOZ_CHILD_PROCESS_NAME) \
-  -DMOZ_CRASHREPORTER=$(MOZ_CRASHREPORTER) \
-  -DMOZ_MIN_CPU_VERSION=$(MIN_CPU_VERSION) \
-  -DMOZ_UPDATE_CHANNEL=$(MOZ_UPDATE_CHANNEL) \
-  -DOMNIJAR_NAME=$(OMNIJAR_NAME) \
-  -DOS_TARGET=$(OS_TARGET) \
-  -DTARGET_XPCOM_ABI=$(TARGET_XPCOM_ABI) \
   -DUA_BUILDID=$(UA_BUILDID) \
   $(NULL)
 
-ifdef MOZ_PKG_SPECIAL
-DEFINES += -DMOZ_PKG_SPECIAL=$(MOZ_PKG_SPECIAL)
-endif
-
-ifdef MOZ_LINKER_EXTRACT
-DEFINES += -DMOZ_LINKER_EXTRACT=1
-endif
-
 GARBAGE += \
   AndroidManifest.xml  \
   classes.dex  \
   gecko.ap_  \
   res/values/strings.xml \
   .aapt.deps \
   fennec_ids.txt \
   javah.out \
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -979,8 +979,33 @@ ANDROID_RESFILES += [
     'resources/xml/searchable.xml',
 ]
 
 if CONFIG['MOZ_CRASHREPORTER']:
     ANDROID_RESFILES += [
         'resources/drawable-mdpi/crash_reporter.png',
         'resources/layout/crash_reporter.xml',
     ]
+
+for var in ('MOZ_ANDROID_ANR_REPORTER', 'MOZ_LINKER_EXTRACT'):
+    if CONFIG[var]:
+        DEFINES[var] = 1
+
+for var in ('MOZ_UPDATER', 'MOZ_PKG_SPECIAL'):
+    if CONFIG[var]:
+        DEFINES[var] = CONFIG[var]
+
+for var in ('ANDROID_PACKAGE_NAME', 'ANDROID_CPU_ARCH', 'CPU_ARCH',
+            'GRE_MILESTONE', 'MOZILLA_OFFICIAL', 'MOZ_APP_BASENAME',
+            'MOZ_APP_DISPLAYNAME', 'MOZ_APP_ID', 'MOZ_APP_NAME',
+            'MOZ_APP_VENDOR', 'MOZ_APP_VERSION', 'MOZ_CHILD_PROCESS_NAME',
+            'MOZ_CRASHREPORTER', 'MOZ_UPDATE_CHANNEL', 'OMNIJAR_NAME',
+            'OS_TARGET', 'TARGET_XPCOM_ABI'):
+    DEFINES[var] = CONFIG[var]
+
+# Mangle our package name to avoid Bug 750548.
+DEFINES['MANGLED_ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME'].replace('fennec', 'f3nn3c')
+DEFINES['MOZ_APP_ABI'] = CONFIG['TARGET_XPCOM_ABI']
+
+if '-march=armv7' in CONFIG['OS_CFLAGS']:
+    DEFINES['MOZ_MIN_CPU_VERSION'] = 7
+else:
+    DEFINES['MOZ_MIN_CPU_VERSION'] = 5
deleted file mode 100644
--- a/mobile/android/chrome/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/.
-
-DEFINES += -DAB_CD=$(MOZ_UI_LOCALE) \
-           -DPACKAGE=browser \
-           -DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
-           -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
-           $(NULL)
--- a/mobile/android/chrome/moz.build
+++ b/mobile/android/chrome/moz.build
@@ -1,6 +1,10 @@
 # -*- 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/.
 
+DEFINES['AB_CD'] = CONFIG['MOZ_UI_LOCALE']
+DEFINES['PACKAGE'] = 'browser'
+DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
+DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
deleted file mode 100644
--- a/mobile/android/components/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/.
-
-DEFINES += \
-  -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
-  $(NULL)
--- a/mobile/android/components/moz.build
+++ b/mobile/android/components/moz.build
@@ -31,8 +31,9 @@ EXTRA_PP_COMPONENTS += [
     'BrowserCLH.js',
     'DirectoryProvider.js',
     'HelperAppDialog.js',
     'MobileComponents.manifest',
     'SessionStore.js',
     'Sidebar.js',
 ]
 
+DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
--- a/mobile/android/geckoview_library/Makefile.in
+++ b/mobile/android/geckoview_library/Makefile.in
@@ -25,18 +25,16 @@ GARBAGE_DIRS = \
   bin \
   libs \
   src \
   .deps \
   gen  \
   res \
   $(NULL)
 
-DEFINES += -DANDROID_SDK=$(ANDROID_SDK)
-
 include $(topsrcdir)/config/rules.mk
 
 package: $(properties_deps)
 	# Make directory for the zips
 	$(MKDIR) -p $(DIST)/geckoview_library
 
 	# Zip the assets
 	cd $(DIST)/fennec; \
--- a/mobile/android/geckoview_library/moz.build
+++ b/mobile/android/geckoview_library/moz.build
@@ -1,5 +1,7 @@
 # -*- 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/.
+
+DEFINES['ANDROID_SDK'] = CONFIG['ANDROID_SDK']
--- a/modules/libbz2/src/Makefile.in
+++ b/modules/libbz2/src/Makefile.in
@@ -3,19 +3,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/.
 
 ifeq ($(OS_ARCH),WINNT)
 USE_STATIC_LIBS = 1
 endif
 
-# This is defined by the bzip2-1.0.3 Makefile.  It appears to be used to
-# configure GLIBC to support large files.  This isn't something we care about
-# at this stage, since we're only interested in the streaming API, but we
-# define it here anyways for consistency.
-DEFINES	+= -D_FILE_OFFSET_BITS=64
-
 include $(topsrcdir)/config/rules.mk
 
 # The intermediate (.ii/.s) files for host and target can have the same name...
 # disable parallel builds
 .NOTPARALLEL:
--- a/modules/libbz2/src/moz.build
+++ b/modules/libbz2/src/moz.build
@@ -30,8 +30,14 @@ UNIFIED_SOURCES += [
     'compress.c',
     'crctable.c',
     'decompress.c',
     'huffman.c',
     'randtable.c',
 ]
 
 FORCE_STATIC_LIB = True
+
+# This is defined by the bzip2-1.0.3 Makefile.  It appears to be used to
+# configure GLIBC to support large files.  This isn't something we care about
+# at this stage, since we're only interested in the streaming API, but we
+# define it here anyways for consistency.
+DEFINES['_FILE_OFFSET_BITS'] = 64
--- a/modules/libmar/tests/Makefile.in
+++ b/modules/libmar/tests/Makefile.in
@@ -1,16 +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/.
 
 TESTROOT = $(abspath $(DEPTH))/_tests/xpcshell/$(relativesrcdir)
 
-DEFINES += -DBIN_SUFFIX=$(BIN_SUFFIX)
-
 include $(topsrcdir)/config/rules.mk
 
 libs:: unit/head_libmar.js.in
 	$(call py_action,preprocessor,-Fsubstitution $(DEFINES) $(ACDEFINES) $^ -o $(TESTROOT)/unit/head_libmar.js)
 
 ifneq ($(OS_TARGET),Android)
 ifndef MOZ_PROFILE_GENERATE
 libs::
--- a/modules/libmar/tests/moz.build
+++ b/modules/libmar/tests/moz.build
@@ -1,7 +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/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
+
+DEFINES['BIN_SUFFIX'] = CONFIG['BIN_SUFFIX']
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -11,27 +11,16 @@ endif
 # 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 =
 
-DEFINES += \
-  -DMAR_CHANNEL_ID='"$(MAR_CHANNEL_ID)"' \
-  -DMOZ_APP_VERSION='"$(MOZ_APP_VERSION)"' \
-  $(NULL)
-
-ifndef MOZ_ENABLE_SIGNMAR
-DEFINES += \
-  -DNO_SIGN_VERIFY \
-  $(NULL)
-endif
-
 HOST_CFLAGS += \
   -DNO_SIGN_VERIFY \
   $(DEFINES) \
   $(NULL)
 
 HOST_LIBS = $(DIST)/host/lib/$(LIB_PREFIX)hostmar.$(LIB_SUFFIX)
 LIBS = $(DEPTH)/modules/libmar/src/$(LIB_PREFIX)mar.$(LIB_SUFFIX)
 
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -8,8 +8,14 @@ if CONFIG['MOZ_ENABLE_SIGNMAR']:
     PROGRAM = 'signmar'
 
 SOURCES = [
     'mar.c',
 ]
 HOST_SOURCES += SOURCES
 
 HOST_PROGRAM = 'mar'
+
+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
--- a/modules/libmar/verify/Makefile.in
+++ b/modules/libmar/verify/Makefile.in
@@ -5,17 +5,16 @@
 ifeq ($(OS_ARCH),WINNT)
 USE_STATIC_LIBS = 1
 endif
 
 # This makefile just builds support for reading archives.
 LOCAL_INCLUDES += -I$(srcdir)/../src
 
 ifneq ($(OS_ARCH),WINNT)
-DEFINES += -DMAR_NSS
 LOCAL_INCLUDES += -I$(srcdir)/../sign
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 # The intermediate (.ii/.s) files for host and target can have the same name...
 # disable parallel builds
 .NOTPARALLEL:
--- a/modules/libmar/verify/moz.build
+++ b/modules/libmar/verify/moz.build
@@ -7,8 +7,11 @@
 LIBRARY_NAME = 'verifymar'
 
 SOURCES += [
     'cryptox.c',
     'mar_verify.c',
 ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['OS_ARCH'] != 'WINNT':
+    DEFINES['MAR_NSS'] = True
--- a/modules/libpref/src/Makefile.in
+++ b/modules/libpref/src/Makefile.in
@@ -1,17 +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/.
 
-DEFINES += -DOS_ARCH=$(OS_ARCH) \
-           -DMOZ_WIDGET_TOOLKIT=$(MOZ_WIDGET_TOOLKIT) \
-           $(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 GARBAGE		+= $(addprefix $(DIST)/bin/defaults/pref/, \
 			mailnews.js editor.js \
 			aix.js unix.js winpref.js os2prefs.js)
 
 GARBAGE		+= greprefs.js
 
--- a/modules/libpref/src/moz.build
+++ b/modules/libpref/src/moz.build
@@ -12,8 +12,11 @@ SOURCES += [
     'prefread.cpp',
 ]
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['OS_ARCH'] = CONFIG['OS_ARCH']
+DEFINES['MOZ_WIDGET_TOOLKIT'] = CONFIG['MOZ_WIDGET_TOOLKIT']
--- a/mozglue/android/Makefile.in
+++ b/mozglue/android/Makefile.in
@@ -1,20 +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/.
 
 STL_FLAGS=
-DEFINES += \
-  -DANDROID_PACKAGE_NAME='"$(ANDROID_PACKAGE_NAME)"' \
-  $(NULL)
-
-ifdef MOZ_FOLD_LIBS
-DEFINES += -DMOZ_FOLD_LIBS
-endif
 
 LOCAL_INCLUDES += -I$(DEPTH)/build
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 
 LOCAL_INCLUDES += -I$(srcdir)/../linker
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/components/startup
 LOCAL_INCLUDES += -I$(topsrcdir)/db/sqlite3/src
 LOCAL_INCLUDES += -I$(topsrcdir)/base/src
--- a/mozglue/android/moz.build
+++ b/mozglue/android/moz.build
@@ -13,8 +13,13 @@ SOURCES += [
     'nsGeckoUtils.cpp',
     'NSSBridge.cpp',
     'SQLiteBridge.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'mozglue'
+
+DEFINES['ANDROID_PACKAGE_NAME'] = '"%s"' % CONFIG['ANDROID_PACKAGE_NAME']
+
+if CONFIG['MOZ_FOLD_LIBS']:
+    DEFINES['MOZ_FOLD_LIBS'] = True
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -19,18 +19,16 @@ else
 SDK_LIBRARY = $(REAL_LIBRARY)
 endif
 endif
 
 endif
  
 MOZ_GLUE_LDFLAGS = # Don't link against ourselves
 
-DEFINES += -DIMPL_MFBT
-
 ifneq (,$(ZLIB_IN_MOZGLUE)$(MOZ_LINKER))
 ifdef MOZ_NATIVE_ZLIB
 EXTRA_DSO_LDOPTS += $(MOZ_ZLIB_LIBS)
 else
 SHARED_LIBRARY_LIBS += $(MOZ_ZLIB_LIBS)
 endif
 endif
 
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -63,8 +63,10 @@ if CONFIG['MOZ_ASAN']:
 
 
 LIBRARY_NAME = 'mozglue'
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     SOURCES += [
         'cpuacct.c',
     ]
+
+DEFINES['IMPL_MFBT'] = True
--- a/mozglue/linker/Makefile.in
+++ b/mozglue/linker/Makefile.in
@@ -1,18 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 STL_FLAGS =
 
 HOST_LIBS = -lz
 
-DEFINES += -DIMPL_MFBT
-
 include $(topsrcdir)/config/rules.mk
 
 ifeq (arm,$(TARGET_CPU))
 ifdef MOZ_THUMB2
 HOST_CXXFLAGS += -DTARGET_THUMB
 else
 HOST_CXXFLAGS += -DTARGET_ARM
 endif
--- a/mozglue/linker/moz.build
+++ b/mozglue/linker/moz.build
@@ -17,8 +17,10 @@ LIBRARY_NAME = 'linker'
 HOST_SOURCES += [
     'SeekableZStream.cpp',
     'szip.cpp',
 ]
 
 HOST_PROGRAM = 'szip'
 
 FINAL_LIBRARY = 'mozglue'
+
+DEFINES['IMPL_MFBT'] = True
--- a/netwerk/protocol/rtsp/Makefile.in
+++ b/netwerk/protocol/rtsp/Makefile.in
@@ -23,9 +23,9 @@ LOCAL_INCLUDES += -I$(ANDROID_SOURCE)/fr
                   $(NULL)
 else
 LOCAL_INCLUDES += -I$(ANDROID_SOURCE)/frameworks/av/media/libstagefright/mpeg2ts \
                   $(NULL)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DIMPL_NS_NET -Wno-multichar -DFORCE_PR_LOG
+DEFINES += -Wno-multichar
--- a/netwerk/protocol/rtsp/moz.build
+++ b/netwerk/protocol/rtsp/moz.build
@@ -45,8 +45,11 @@ SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'necko'
+
+for var in ('IMPL_NS_NET', 'FORCE_PR_LOG'):
+    DEFINES[var] = True
--- a/netwerk/sctp/datachannel/Makefile.in
+++ b/netwerk/sctp/datachannel/Makefile.in
@@ -6,26 +6,8 @@
 NO_PROFILE_GUIDED_OPTIMIZE = 1 # Don't PGO
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/xpcom/ds \
   -I$(srcdir)/../src \
   -I$(DEPTH)/dist/include/mozilla/net \
   -I$(topsrcdir)/media/webrtc/trunk/third_party/libjingle/source \
   -I$(topsrcdir)/media/mtransport \
   $(NULL)
-
-DEFINES = \
-  -DINET=1 \
-  -DSCTP_DEBUG=1 \
-  $(NULL)
-
-ifneq ($(OS_TARGET),Android)
-DEFINES += -DINET6=1
-endif
-
-ifeq ($(OS_TARGET),WINNT)
-DEFINES += -D__Userspace_os_Windows=1
-else
-DEFINES += -D__Userspace_os_$(OS_TARGET)=1
-endif
-
-
-include $(topsrcdir)/config/rules.mk
--- a/netwerk/sctp/datachannel/moz.build
+++ b/netwerk/sctp/datachannel/moz.build
@@ -16,8 +16,19 @@ SOURCES += [
     'DataChannel.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'necko'
+
+DEFINES['INET'] = 1
+DEFINES['SCTP_DEBUG'] = 1
+
+if CONFIG['OS_TARGET'] != 'Android':
+    DEFINES['INET6'] = 1
+
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['__Userspace_os_Windows'] = 1
+else:
+    DEFINES['__Userspace_os_%s' % CONFIG['OS_TARGET']] = 1
--- a/netwerk/sctp/src/Makefile.in
+++ b/netwerk/sctp/src/Makefile.in
@@ -13,83 +13,45 @@ NO_PROFILE_GUIDED_OPTIMIZE = 1 # Don't P
 
 LOCAL_INCLUDES = \
   -I$(srcdir)/../../base/src \
   -I$(topsrcdir)/content/base/src \
   -I$(topsrcdir)/content/events/src \
   -I$(topsrcdir)/xpcom/ds \
   $(NULL)
 
-# Android NDK r5c, used on the builders at the time of this writing, doesn't
-# have the headers we need for IPv6
-ifeq ($(OS_TARGET),Android)
-  IPV6_DEFINE=
-else
-  IPV6_DEFINE=-DINET6=1
-endif
-
-DEFINES = \
-  -DSCTP_SIMPLE_ALLOCATOR=1 \
-  -DUSE_SCTP_SHA1=1 \
-  -DSCTP_PROCESS_LEVEL_LOCKS=1 \
-  -D__Userspace__=1 \
-  -DINET=1 \
-  $(IPV6_DEFINE) \
-  -DCALLBACK_API=1 \
-  -DSCTP_DEBUG=1 \
-  $(NULL)
-
-ifeq ($(OS_TARGET),WINNT)
-DEFINES += \
-  -D__Userspace_os_Windows=1 \
-  -D_LIB=1 \
-  $(NULL)
-else
 ifeq ($(OS_TARGET),Darwin)
 DEFINES += \
-  -D__Userspace_os_Darwin=1 \
-  -D__APPLE_USE_RFC_2292=1 \
   -U__APPLE__ \
   $(NULL)
 else
-ifeq (,$(filter-out Linux Android,$(OS_TARGET)))
-DEFINES += -D__Userspace_os_Linux=1
-# to make sure that in6_pktinfo gets defined on all distros
-DEFINES += -D_GNU_SOURCE
-else
 ifeq ($(OS_TARGET),FreeBSD)
 DEFINES += \
-  -D__Userspace_os_FreeBSD=1 \
   -U__FreeBSD__ \
   $(NULL)
 else
 ifeq ($(OS_TARGET),NetBSD)
 DEFINES += \
-  -D__Userspace_os_NetBSD=1 \
   -U__NetBSD__ \
   $(NULL)
 else
 ifeq ($(OS_TARGET),OpenBSD)
 DEFINES += \
-  -D__Userspace_os_OpenBSD=1 \
   -U__OpenBSD__ \
   $(NULL)
 else
 ifeq ($(OS_TARGET),DragonFly)
 DEFINES += \
-  -D__Userspace_os_DragonFly=1 \
   -U__DragonFly__ \
   $(NULL)
 else
 #error Unsupported platform!
 endif
 endif
 endif
 endif
 endif
-endif
-endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef GNU_CC
 CFLAGS += -std=gnu99
 endif
--- a/netwerk/sctp/src/moz.build
+++ b/netwerk/sctp/src/moz.build
@@ -43,8 +43,33 @@ if CONFIG['OS_TARGET'] == 'Android':
         'ifaddrs_android.cpp',
     ]
 
 LIBRARY_NAME = 'nksctp_s'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'necko'
+
+for var in ('SCTP_SIMPLE_ALLOCATOR', 'USE_SCTP_SHA1',
+            'SCTP_PROCESS_LEVEL_LOCKS', '__Userspace__', 'INET',
+            'CALLBACK_API', 'SCTP_DEBUG'):
+    DEFINES[var] = 1
+
+# Android NDK r5c, used on the builders at the time of this writing, doesn't
+# have the headers we need for IPv6
+if CONFIG['OS_TARGET'] != 'Android':
+    DEFINES['INET6'] = 1
+
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['__Userspace_os_Windows'] = 1
+    DEFINES['_LIB'] = 1
+elif CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['__Userspace_os_Linux'] = 1
+else:
+    DEFINES['__Userspace_os_%s' % CONFIG['OS_TARGET']] = 1
+
+if CONFIG['OS_TARGET'] == 'Darwin':
+    DEFINES['__APPLE_USE_RFC_2292'] = 1
+
+if CONFIG['OS_TARGET'] in ('Linux', 'Android'):
+    # to make sure that in6_pktinfo gets defined on all distros
+    DEFINES['_GNU_SOURCE'] = True
--- a/netwerk/srtp/src/Makefile.in
+++ b/netwerk/srtp/src/Makefile.in
@@ -15,56 +15,13 @@ VPATH = \
   @srcdir@/crypto/rng \
   $(NULL)
 
 LOCAL_INCLUDES = \
   -I$(srcdir)/include \
   -I$(srcdir)/crypto/include \
   $(NULL)
 
-DEFINES += \
-  -DHAVE_STDLIB_H=1 \
-  -DHAVE_UINT8_T=1 \
-  -DHAVE_UINT16_T=1 \
-  -DHAVE_UINT32_T=1 \
-  -DHAVE_UINT64_T=1 \
-  $(NULL)
-
-# We know stdint.h will define uint8/16/32/64_t, so we don't need
-# to define SIZEOF_UNSIGNED_LONG/SIZEOF_UNSIGNED_LONG_LONG
-
-ifeq ($(CPU_ARCH),arm)
-
-# XXX while arm is not a CISC architecture, the code guarded by CPU_RISC makes
-# (at least) the AES ciphers fail their self-tests on ARM, so for now we're
-# falling back to the (presumably) slower-on-this-architecture but working
-# code path.  https://bugzilla.mozilla.org/show_bug.cgi?id=822380 has been filed
-# to make the right and more performant fix and push it back upstream.
-
-DEFINES += -DCPU_CISC=1
-
-else ifeq ($(CPU_ARCH),x86)
-DEFINES += \
-  -DCPU_CISC=1 \
-  -DHAVE_X86 \
-  $(NULL)
-else ifeq ($(CPU_ARCH),x86_64)
-DEFINES += \
-  -DCPU_CISC=1 \
-  -DHAVE_X86 \
-  $(NULL)
-else
-# best guess
-DEFINES += -DCPU_RISC=1
-endif
-
-ifeq ($(OS_TARGET),WINNT)
-DEFINES += \
-  -DHAVE_WINSOCK2_H=1 \
-  -Dinline=__inline \
-  $(NULL)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 ifdef GNU_CC
 CFLAGS += -std=gnu99
 endif
--- a/netwerk/srtp/src/moz.build
+++ b/netwerk/srtp/src/moz.build
@@ -33,8 +33,32 @@ UNIFIED_SOURCES += [
     'srtp/srtp.c',
 ]
 
 LIBRARY_NAME = 'nksrtp_s'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'necko'
+
+# We know stdint.h will define uint8/16/32/64_t, so we don't need
+# to define SIZEOF_UNSIGNED_LONG/SIZEOF_UNSIGNED_LONG_LONG
+for var in ('HAVE_STDLIB_H', 'HAVE_UINT8_T', 'HAVE_UINT16_T',
+            'HAVE_UINT32_T', 'HAVE_UINT64_T'):
+    DEFINES[var] = 1
+
+# XXX while arm is not a CISC architecture, the code guarded by CPU_RISC makes
+# (at least) the AES ciphers fail their self-tests on ARM, so for now we're
+# falling back to the (presumably) slower-on-this-architecture but working
+# code path.  https://bugzilla.mozilla.org/show_bug.cgi?id=822380 has been filed
+# to make the right and more performant fix and push it back upstream.
+if CONFIG['CPU_ARCH'] in ('arm', 'x86', 'x86_64'):
+    DEFINES['CPU_CISC'] = 1
+else:
+    # best guess
+    DEFINES['CPU_RISC'] = 1
+
+if  CONFIG['CPU_ARCH'] in ('x86', 'x86_64'):
+    DEFINES['HAVE_X86'] = True
+
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFINES['HAVE_WINSOCK2_H'] = True
+    DEFINES['inline'] = '__inline'
--- a/netwerk/streamconv/test/Makefile.in
+++ b/netwerk/streamconv/test/Makefile.in
@@ -12,15 +12,9 @@ LIBS		= \
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(OS_ARCH),WINNT)
 ifdef GNU_CXX
 LDFLAGS		+= -mconsole
 else
 LDFLAGS		+= -SUBSYSTEM:CONSOLE
 endif
-ifdef MOZ_NO_DEBUG_RTL
-DEFINES		+= -MOZ_NO_DEBUG_RTL
-endif
-ifdef NGPREFS
-DEFINES		+= -DNGPREFS
-endif
 endif # WINNT
--- a/netwerk/streamconv/test/moz.build
+++ b/netwerk/streamconv/test/moz.build
@@ -8,8 +8,11 @@ PROGRAM = 'TestStreamConv'
 
 UNIFIED_SOURCES += [
     'Converters.cpp',
     'TestStreamConv.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    for var in ('MOZ_NO_DEBUG_RTL', 'NGPREFS'):
+        DEFINES[var] = True
--- a/other-licenses/skia-npapi/Makefile.in
+++ b/other-licenses/skia-npapi/Makefile.in
@@ -1,15 +1,11 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEFINES += \
-  -DSK_BUILD_FOR_ANDROID_NDK \
-  $(NULL)
-
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/dom/plugins/base \
   -I$(topsrcdir)/dom/plugins/base/android \
   -I$(topsrcdir)/gfx/skia/include/core \
   -I$(topsrcdir)/gfx/skia/include/config \
   -I$(topsrcdir)/gfx/gl \
   $(NULL)
--- a/other-licenses/skia-npapi/moz.build
+++ b/other-licenses/skia-npapi/moz.build
@@ -12,8 +12,10 @@ SOURCES += [
     'ANPCanvas.cpp',
     'ANPPaint.cpp',
     'ANPPath.cpp',
     'ANPTypeface.cpp',
     'SkANP.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['SK_BUILD_FOR_ANDROID_NDK'] = True
deleted file mode 100644
--- a/parser/expat/lib/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/.
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -DHAVE_EXPAT_CONFIG_H
--- a/parser/expat/lib/moz.build
+++ b/parser/expat/lib/moz.build
@@ -17,8 +17,10 @@ SOURCES += [
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gkmedias'
 
 GENERATED_FILES = [
     'moz_extensions.c',
 ]
+
+DEFINES['HAVE_EXPAT_CONFIG_H'] = True
--- a/parser/html/Makefile.in
+++ b/parser/html/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/.
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= \
 		-I$(srcdir)/../../content/base/src \
 		$(NULL)
-
-#DEFINES		+= -DENABLE_VOID_MENUITEM
--- a/parser/html/moz.build
+++ b/parser/html/moz.build
@@ -81,8 +81,10 @@ UNIFIED_SOURCES += [
     'nsHtml5UTF16Buffer.cpp',
     'nsHtml5ViewSourceUtils.cpp',
     'nsParserUtils.cpp',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gklayout'
+
+# DEFINES['ENABLE_VOID_MENUITEM'] = True
--- a/profile/dirserviceprovider/standalone/Makefile.in
+++ b/profile/dirserviceprovider/standalone/Makefile.in
@@ -1,10 +1,9 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = -I$(srcdir)/../src
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS =
--- a/profile/dirserviceprovider/standalone/moz.build
+++ b/profile/dirserviceprovider/standalone/moz.build
@@ -6,8 +6,10 @@
 
 include('../src/objs.mozbuild')
 
 UNIFIED_SOURCES += modules_profiledirservice_src_csrcs
 
 LIBRARY_NAME = 'profdirserviceprovidersa_s'
 
 FORCE_STATIC_LIB = True
+
+DEFINES['XPCOM_GLUE'] = 1
deleted file mode 100644
--- a/security/manager/ssl/src/Makefile.in
+++ /dev/null
@@ -1,11 +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/.
-
-DEFINES += \
-  -DNSS_ENABLE_ECC \
-  -DDLL_PREFIX=\"$(DLL_PREFIX)\" \
-  -DDLL_SUFFIX=\"$(DLL_SUFFIX)\" \
-  $(NULL)
--- a/security/manager/ssl/src/moz.build
+++ b/security/manager/ssl/src/moz.build
@@ -87,8 +87,12 @@ if CONFIG['MOZ_XUL']:
         'nsCertTree.cpp',
     ]
 
 UNIFIED_SOURCES += [
     'md4.c',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['NSS_ENABLE_ECC'] = 'True'
+for var in ('DLL_PREFIX', 'DLL_SUFFIX'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
--- a/security/sandbox/Makefile.in
+++ b/security/sandbox/Makefile.in
@@ -4,18 +4,16 @@
 
 ifeq ($(OS_ARCH),WINNT)
 LOCAL_INCLUDES += \
     -I$(topsrcdir)/security/sandbox/base/shim \
     -I$(topsrcdir)/security \
     -I$(topsrcdir)/nsprpub \
     $(NULL)
 
-DEFINES += -DUNICODE -D_UNICODE -DNS_NO_XPCOM -DSANDBOX_EXPORTS -DNOMINMAX -D_CRT_RAND_S
-
 EXTRA_SDK_DECLS = $(topsrcdir)/security/sandbox/base/shim/sdkdecls.h
 
 ifdef _MSC_VER
 OS_CXXFLAGS += -FI $(EXTRA_SDK_DECLS)
 else
 OS_CXXFLAGS += -include $(EXTRA_SDK_DECLS)
 endif
 
--- a/security/sandbox/moz.build
+++ b/security/sandbox/moz.build
@@ -112,8 +112,11 @@ elif CONFIG['OS_ARCH'] == 'WINNT':
         'win/src/target_process.cc',
         'win/src/target_services.cc',
         'win/src/win2k_threadpool.cc',
         'win/src/win_utils.cc',
         'win/src/window.cc',
         'win/src/Wow64.cc',
     ]
 
+    for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM', 'SANDBOX_EXPORTS',
+                'NOMINMAX', '_CRT_RAND_S'):
+        DEFINES[var] = True
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ b/security/sandbox/win/src/sandboxbroker/Makefile.in
@@ -11,10 +11,8 @@ LOCAL_INCLUDES += \
     $(NULL)
 
 SHARED_LIBRARY_LIBS += \
 	../../../$(LIB_PREFIX)sandbox_s.$(LIB_SUFFIX) \
 	$(NSPR_LIBS) \
 	$(NULL)
 
 OS_LIBS += $(call EXPAND_LIBNAME,dbghelp)
-
-DEFINES += -DUNICODE -D_UNICODE -DNS_NO_XPCOM -DNOMINMAX -DSANDBOX_EXPORTS
--- a/security/sandbox/win/src/sandboxbroker/moz.build
+++ b/security/sandbox/win/src/sandboxbroker/moz.build
@@ -11,8 +11,12 @@ SOURCES += [
     'sandboxBroker.cpp',
 ]
 
 EXPORTS += [
     'sandboxBroker.h',
 ]
 
 FORCE_SHARED_LIB = True
+
+for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM', 'NOMINMAX',
+            'SANDBOX_EXPORTS'):
+    DEFINES[var] = True
--- a/storage/src/Makefile.in
+++ b/storage/src/Makefile.in
@@ -1,34 +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 use the jemalloc allocator on Android, because we can't guarantee
-# that Gecko will configure sqlite before it is first used (bug 730495).
-#
-# Don't use the jemalloc allocator when using system sqlite. Linked in libraries
-# (such as NSS) might trigger an initialization of sqlite and allocation
-# of memory using the default allocator, prior to the storage service
-# registering its allocator, causing memory management failures (bug 938730).
-#
-# Note: On Windows our sqlite build assumes we use jemalloc.  If you disable
-# MOZ_STORAGE_MEMORY on Windows, you will also need to change the "ifdef
-# MOZ_MEMORY" options in db/sqlite3/src/Makefile.in.
-ifdef MOZ_MEMORY
-ifndef MOZ_NATIVE_SQLITE
-ifneq ($(OS_TARGET), Android)
-DEFINES += -DMOZ_STORAGE_MEMORY
-endif
-endif
-endif
-
 # For nsDependentJSString
 LOCAL_INCLUDES = \
   $(SQLITE_CFLAGS) \
   -I$(topsrcdir)/db/sqlite3/src \
   -I$(topsrcdir)/dom/base \
   $(NULL)
-
-# This is the default value.  If we ever change it when compiling sqlite, we
-# will need to change it here as well.
-DEFINES += -DSQLITE_MAX_LIKE_PATTERN_LENGTH=50000
--- a/storage/src/moz.build
+++ b/storage/src/moz.build
@@ -35,8 +35,27 @@ UNIFIED_SOURCES += [
 
 # These files need to be built separately because they #include variantToSQLiteT_impl.h.
 SOURCES += [
     'mozStorageBindingParams.cpp',
     'mozStorageConnection.cpp',
 ]
 
 FINAL_LIBRARY = 'storagecomps'
+
+# Don't use the jemalloc allocator on Android, because we can't guarantee
+# that Gecko will configure sqlite before it is first used (bug 730495).
+#
+# Don't use the jemalloc allocator when using system sqlite. Linked in libraries
+# (such as NSS) might trigger an initialization of sqlite and allocation
+# of memory using the default allocator, prior to the storage service
+# registering its allocator, causing memory management failures (bug 938730).
+#
+# Note: On Windows our sqlite build assumes we use jemalloc.  If you disable
+# MOZ_STORAGE_MEMORY on Windows, you will also need to change the "ifdef
+# MOZ_MEMORY" options in db/sqlite3/src/Makefile.in.
+if CONFIG['MOZ_MEMORY'] and not CONFIG['MOZ_NATIVE_SQLITE']:
+    if CONFIG['OS_TARGET'] != 'Android':
+        DEFINES['MOZ_STORAGE_MEMORY'] = True
+
+# This is the default value.  If we ever change it when compiling sqlite, we
+# will need to change it here as well.
+DEFINES['SQLITE_MAX_LIKE_PATTERN_LENGTH'] = 50000
deleted file mode 100644
--- a/testing/marionette/Makefile.in
+++ /dev/null
@@ -1,7 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ifdef ENABLE_TESTS
-    DEFINES += -DENABLE_TESTS
-endif
deleted file mode 100644
--- a/testing/marionette/components/Makefile.in
+++ /dev/null
@@ -1,7 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ifdef ENABLE_MARIONETTE
-DEFINES += -DENABLE_MARIONETTE=1
-endif
--- a/testing/marionette/components/moz.build
+++ b/testing/marionette/components/moz.build
@@ -6,8 +6,11 @@
 
 EXTRA_COMPONENTS += [
     'MarionetteComponents.manifest'
 ]
 
 EXTRA_PP_COMPONENTS += [
     'marionettecomponent.js'
 ]
+
+if CONFIG['ENABLE_MARIONETTE']:
+    DEFINES['ENABLE_MARIONETTE'] = 1
--- a/testing/marionette/moz.build
+++ b/testing/marionette/moz.build
@@ -1,7 +1,10 @@
 # -*- 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 += ['components', 'atoms']
+
+if CONFIG['ENABLE_TESTS']:
+    DEFINES['ENABLE_TESTS'] = True
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -1,15 +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/.
 
-# For debugging purposes only
-#DEFINES += -DDISABLE_UPDATER_AUTHENTICODE_CHECK
-
 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 =
 STL_FLAGS=
 
@@ -18,35 +15,32 @@ LIBS += $(call EXPAND_LIBNAME_PATH,updat
 else
 LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon,../../mozapps/update/common)
 endif
 
 USE_STATIC_LIBS = 1
 RCINCLUDE = maintenanceservice.rc
 
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32)
-DEFINES += -DUNICODE -D_UNICODE
 ifndef GNU_CC
 RCFLAGS += -I$(srcdir)
 else
 RCFLAGS += --include-dir $(srcdir)
 endif
 
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DNS_NO_XPCOM
-
 ifdef _MSC_VER
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 endif
 
 # Pick up nsWindowsRestart.cpp
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre \
   -I$(topsrcdir)/toolkit/mozapps/update/common \
   $(NULL)
--- a/toolkit/components/maintenanceservice/moz.build
+++ b/toolkit/components/maintenanceservice/moz.build
@@ -9,8 +9,15 @@ PROGRAM = 'maintenanceservice'
 SOURCES += [
     'certificatecheck.cpp',
     'maintenanceservice.cpp',
     'registrycertificates.cpp',
     'servicebase.cpp',
     'serviceinstall.cpp',
     'workmonitor.cpp',
 ]
+
+# For debugging purposes only
+#DEFINES['DISABLE_UPDATER_AUTHENTICODE_CHECK'] = True
+
+DEFINES['UNICODE'] = True
+DEFINES['_UNICODE'] = True
+DEFINES['NS_NO_XPCOM'] = True
deleted file mode 100644
--- a/toolkit/components/search/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/.
-
-DEFINES += -DMOZ_DISTRIBUTION_ID=$(MOZ_DISTRIBUTION_ID)
--- a/toolkit/components/search/moz.build
+++ b/toolkit/components/search/moz.build
@@ -9,8 +9,10 @@ TEST_DIRS += ['tests']
 EXTRA_COMPONENTS += [
     'nsSearchSuggestions.js',
     'toolkitsearch.manifest',
 ]
 
 EXTRA_PP_COMPONENTS += [
     'nsSearchService.js',
 ]
+
+DEFINES['MOZ_DISTRIBUTION_ID'] = CONFIG['MOZ_DISTRIBUTION_ID']
--- a/toolkit/components/telemetry/Makefile.in
+++ b/toolkit/components/telemetry/Makefile.in
@@ -4,20 +4,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 USE_RCS_MK := 1
 include $(topsrcdir)/config/makefiles/rcs.mk
 
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/threads
 
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL
-endif
-
 MOZ_HISTOGRAMS_VERSION ?= $(call getSourceRepo)/rev/$(firstword $(shell hg -R $(topsrcdir) parent --template="{node|short}\n" 2>/dev/null))
 ifdef MOZ_HISTOGRAMS_VERSION
 DEFINES += -DHISTOGRAMS_FILE_VERSION="$(MOZ_HISTOGRAMS_VERSION)"
 endif
 
 INSTALL_TARGETS += histoenums
 histoenums_FILES := TelemetryHistogramEnums.h
 histoenums_DEST = $(DIST)/include/mozilla
--- a/toolkit/components/telemetry/moz.build
+++ b/toolkit/components/telemetry/moz.build
@@ -44,8 +44,11 @@ MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 GENERATED_FILES = [
     'TelemetryHistogramData.inc',
 ]
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
--- a/toolkit/content/Makefile.in
+++ b/toolkit/content/Makefile.in
@@ -2,41 +2,26 @@
 # 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/.
 
 USE_RCS_MK := 1
 include $(topsrcdir)/config/makefiles/makeutils.mk
 
 DEFINES += \
-  -Dtarget="$(target)" \
-  -Dac_configure_args="$(ac_configure_args)" \
-  -DCC="$(CC)" \
-  -DCC_VERSION="$(CC_VERSION)" \
-  -DCFLAGS="$(CFLAGS)" \
-  -DCXX="$(CXX)" \
-  -DCXX_VERSION="$(CXX_VERSION)" \
   -DCXXFLAGS="$(CXXFLAGS)" \
   -DCPPFLAGS="$(CPPFLAGS)" \
   $(NULL)
 
 MOZ_SOURCE_STAMP ?= $(shell hg -R $(topsrcdir) parent --template="{node|short}\n" 2>/dev/null)
 ifdef MOZ_SOURCE_STAMP
 DEFINES += -DSOURCE_CHANGESET="$(MOZ_SOURCE_STAMP)"
 endif
 
-ifeq (Android,$(OS_TARGET))
-DEFINES += -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME)
-endif
-
 source_repo ?= $(call getSourceRepo)
 ifneq (,$(filter http%,$(source_repo)))
   DEFINES += -DSOURCE_REPO="$(source_repo)"
 else ifneq (,$(strip $(source_repo)))
   DEFINES += -DSOURCE_GIT_COMMIT="$(source_repo)"
 endif
 
-ifneq (,$(findstring stlport,$(STLPORT_LIBS)))
-DEFINES += -DUSE_STLPORT
-endif
-
 BUILD_HOSTNAME = $(shell hostname -s || hostname)
 DEFINES += -DBUILD_HOSTNAME="$(BUILD_HOSTNAME)"
--- a/toolkit/content/moz.build
+++ b/toolkit/content/moz.build
@@ -1,7 +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/.
 
 TEST_DIRS += ['tests']
+
+for var in ('target', 'ac_configure_args', 'CC', 'CC_VERSION', 'CFLAGS',
+            'CXX', 'CXX_VERSION'):
+    DEFINES[var] = CONFIG[var]
+
+if CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
+
+if 'stlport' in CONFIG['STLPORT_LIBS']:
+    DEFINES['USE_STLPORT'] = True
--- a/toolkit/crashreporter/Makefile.in
+++ b/toolkit/crashreporter/Makefile.in
@@ -1,32 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-ifeq ($(OS_ARCH),Linux)
-# MOZ_APP_NAME is needed on Android, where we
-# need to launch by package name.
-DEFINES += \
-  -DANDROID_PACKAGE_NAME=\"$(ANDROID_PACKAGE_NAME)\"
-  $(NULL)
-endif
-
-ifeq ($(OS_ARCH),SunOS)
-# there's no define for this normally
-DEFINES += -DXP_SOLARIS
-endif
-
 ifeq ($(OS_TARGET),Android)
 # NDK5 workarounds
-DEFINES += -D_STLP_CONST_CONSTRUCTOR_BUG -D_STLP_NO_MEMBER_TEMPLATES
 TARGET_LOCAL_INCLUDES = \
   -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/android/include/ \
   $(NULL)
 endif
 
 LOCAL_INCLUDES += -I$(srcdir)/google-breakpad/src
-DEFINES += -DUNICODE -D_UNICODE
 
 include $(topsrcdir)/config/rules.mk
 
 check::
 	$(PYTHON) $(srcdir)/tools/unit-symbolstore.py
--- a/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
+++ b/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
@@ -13,16 +13,14 @@ include $(topsrcdir)/toolkit/crashreport
 
 VPATH += \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/windows \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/handler \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/sender \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/crash_generation \
   $(NULL)
 
-DEFINES += -DUNICODE -DUNICODE_ -DBREAKPAD_NO_TERMINATE_THREAD -DNOMINMAX
-
 CPPSRCS += \
   $(objs_common) \
   $(objs_crash_generation) \
   $(objs_handler) \
   $(objs_sender) \
   $(NULL)
--- a/toolkit/crashreporter/breakpad-windows-libxul/moz.build
+++ b/toolkit/crashreporter/breakpad-windows-libxul/moz.build
@@ -6,8 +6,11 @@
 
 SOURCES += [
     '../google-breakpad/src/common/windows/http_upload.cc',
 ]
 
 LIBRARY_NAME = 'google_breakpad_libxul_s'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+for var in ('UNICODE', 'UNICODE_', 'BREAKPAD_NO_TERMINATE_THREAD', 'NOMINMAX'):
+    DEFINES[var] = True
--- a/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
+++ b/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
@@ -14,15 +14,13 @@ include $(topsrcdir)/toolkit/crashreport
 include $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/crash_generation/objs.mk
 
 VPATH += \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/windows \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/handler \
   $(topsrcdir)/toolkit/crashreporter/google-breakpad/src/client/windows/crash_generation \
   $(NULL)
 
-DEFINES += -DUNICODE -DUNICODE_ -DBREAKPAD_NO_TERMINATE_THREAD -DNOMINMAX
-
 CPPSRCS += \
   $(objs_common) \
   $(objs_crash_generation) \
   $(objs_handler) \
   $(NULL)
--- a/toolkit/crashreporter/breakpad-windows-standalone/moz.build
+++ b/toolkit/crashreporter/breakpad-windows-standalone/moz.build
@@ -1,7 +1,10 @@
 # -*- 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/.
 
 FINAL_LIBRARY = 'breakpadinjector'
+
+for var in ('UNICODE', 'UNICODE_', 'BREAKPAD_NO_TERMINATE_THREAD', 'NOMINMAX'):
+    DEFINES[var] = True
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -20,17 +20,16 @@ LOCAL_INCLUDES = -I$(srcdir)/../google-b
 VPATH += $(topsrcdir)/build/
 
 ifeq ($(OS_ARCH),WINNT)
 LIBS += \
   $(DEPTH)/toolkit/crashreporter/breakpad-windows-libxul/$(LIB_PREFIX)google_breakpad_libxul_s.$(LIB_SUFFIX)
   $(NULL)
 LOCAL_INCLUDES += -I$(srcdir)
 RCINCLUDE = crashreporter.rc
-DEFINES += -DUNICODE -D_UNICODE
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 shell32 wininet shlwapi)
 MOZ_WINCONSOLE = 0
 endif
 
 ifeq ($(OS_ARCH),Darwin)
 OS_LIBS += -framework Cocoa
 LIBS += \
   $(DEPTH)/toolkit/crashreporter/google-breakpad/src/common/$(LIB_PREFIX)breakpad_common_s.$(LIB_SUFFIX) \
--- a/toolkit/crashreporter/client/moz.build
+++ b/toolkit/crashreporter/client/moz.build
@@ -11,16 +11,18 @@ if CONFIG['OS_TARGET'] != 'Android':
 SOURCES += [
     'crashreporter.cpp',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'crashreporter_win.cpp',
     ]
+    DEFINES['UNICODE'] = True
+    DEFINES['_UNICODE'] = True
 elif CONFIG['OS_ARCH'] == 'Darwin':
     SOURCES += [
         'crashreporter_unix_common.cpp',
     ]
 elif CONFIG['OS_ARCH'] == 'SunOS':
     SOURCES += [
         'crashreporter_linux.cpp',
         'crashreporter_unix.cpp',
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
@@ -19,11 +19,10 @@ endif #}
 VPATH += $(srcdir)/../log
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src \
   $(NULL)
 
 ifeq ($(OS_TARGET),Android)
 # NDK5 workarounds
-DEFINES += -D_STLP_CONST_CONSTRUCTOR_BUG -D_STLP_NO_MEMBER_TEMPLATES
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/android/include/
 endif
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
@@ -8,8 +8,13 @@ SOURCES += [
     '../log/log.cc',
     'exception_handler.cc',
     'minidump_descriptor.cc',
 ]
 
 XPI_NAME = 'crashreporter'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['OS_TARGET'] == 'Android':
+    # NDK5 workarounds
+    DEFINES['_STLP_CONST_CONSTRUCTOR_BUG'] = True
+    DEFINES['_STLP_NO_MEMBER_TEMPLATES'] = True
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
@@ -4,12 +4,8 @@
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src \
   $(NULL)
 
 ifeq ($(OS_TARGET),Android)
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/android/include/
 endif
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DELFSIZE=32
-endif
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
@@ -8,8 +8,11 @@ SOURCES += [
     'linux_dumper.cc',
     'linux_ptrace_dumper.cc',
     'minidump_writer.cc',
 ]
 
 XPI_NAME = 'crashreporter'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['ELFSIZE'] = 32
--- a/toolkit/crashreporter/google-breakpad/src/common/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/common/Makefile.in
@@ -7,21 +7,16 @@ ifdef MOZ_CRASHREPORTER
 endif
 endif
 
 LOCAL_INCLUDES 	= -I$(srcdir)/..
 
 ifeq ($(OS_TARGET),Android)
 VPATH += $(srcdir)/android
 TARGET_LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/android/include/
-DEFINES += -DNO_STABS_SUPPORT
-endif
-
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DELFSIZE=32
 endif
 
 # This kind of sucks.
 ifeq (Linux,$(OS_ARCH))
 HOST_CXXFLAGS += -DHAVE_A_OUT_H
 OS_CXXFLAGS += -DHAVE_A_OUT_H
 endif
 ifeq (Darwin,$(OS_ARCH))
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
@@ -6,18 +6,12 @@ LOCAL_INCLUDES = \
   -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src \
   $(NULL)
 
 ifneq (Android,$(OS_TARGET))
 else
 TARGET_LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src/common/android/include/
 endif
 
-ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DELFSIZE=32
-endif
-
-DEFINES += -DNO_STABS_SUPPORT
-
 include $(topsrcdir)/config/rules.mk
 
 # See https://bugzilla.mozilla.org/show_bug.cgi?id=741348#c11
 file_id.$(OBJ_SUFFIX): STL_FLAGS=
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
@@ -28,8 +28,13 @@ if CONFIG['MOZ_CRASHREPORTER']:
         'guid_creator.cc',
         'linux_libc_support.cc',
         'memory_mapped_file.cc',
     ]
 
 LIBRARY_NAME = 'breakpad_linux_common_s'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['ELFSIZE'] = 32
+
+DEFINES['NO_STABS_SUPPORT'] = True
--- a/toolkit/crashreporter/google-breakpad/src/common/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/moz.build
@@ -78,8 +78,14 @@ if CONFIG['OS_TARGET'] == 'Android':
         'android/breakpad_getcontext.S',
     ]
 
 LIBRARY_NAME = 'breakpad_common_s'
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['ELFSIZE'] = 32
+
+if CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['NO_STABS_SUPPORT'] = True
--- a/toolkit/crashreporter/moz.build
+++ b/toolkit/crashreporter/moz.build
@@ -76,8 +76,21 @@ EXTRA_JS_MODULES += [
     'KeyValueParser.jsm',
 ]
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['OS_TARGET'] == 'Android':
+    DEFINES['ANDROID_PACKAGE_NAME'] = '"%s"' % CONFIG['ANDROID_PACKAGE_NAME']
+    # NDK5 workarounds
+    DEFINES['_STLP_CONST_CONSTRUCTOR_BUG'] = True
+    DEFINES['_STLP_NO_MEMBER_TEMPLATES'] = True
+
+if CONFIG['OS_ARCH'] == 'SunOS':
+    # there's no define for this normally
+    DEFINES['XP_SOLARIS'] = True
+
+DEFINES['UNICODE'] = True
+DEFINES['_UNICODE'] = True
--- a/toolkit/crashreporter/test/Makefile.in
+++ b/toolkit/crashreporter/test/Makefile.in
@@ -19,17 +19,15 @@ MOCHITEST_CRASHREPORTER_FILES = \
   browser/crashreport.sjs \
   browser/browser_aboutCrashes.js \
   browser/browser_bug471404.js \
   browser/browser_aboutCrashesResubmit.js \
   $(NULL)
 MOCHITEST_CRASHREPORTER_DEST = $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)/browser
 INSTALL_TARGETS += MOCHITEST_CRASHREPORTER
 
-DEFINES += -DSHARED_LIBRARY=$(SHARED_LIBRARY) -DNOMINMAX
-
 UNIT_FILES = $(SHARED_LIBRARY) $(EXTRA_JS_MODULES)
 UNIT_DEST = $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/
 INSTALL_TARGETS += UNIT
 
 UNIT_IPC_FILES = $(UNIT_FILES)
 UNIT_IPC_DEST = $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit_ipc/
 INSTALL_TARGETS += UNIT_IPC
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -18,8 +18,16 @@ SOURCES += [
 
 LIBRARY_NAME = 'testcrasher'
 
 EXTRA_JS_MODULES += [
     'CrashTestUtils.jsm',
 ]
 
 FORCE_SHARED_LIB = True
+
+DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
+
+DEFINES['NOMINMAX'] = True
deleted file mode 100644
--- a/toolkit/modules/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/.
-
-ifdef MOZ_TOOLKIT_SEARCH
-DEFINES += -DMOZ_TOOLKIT_SEARCH
-endif
-
-DEFINES += \
-  -DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-  -DMOZ_BUILD_APP=$(MOZ_BUILD_APP) \
-  $(NULL)
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -54,8 +54,13 @@ EXTRA_PP_JS_MODULES += [
     'WindowDraggingUtils.jsm',
 ]
 
 if 'Android' != CONFIG['OS_TARGET']:
     EXTRA_PP_JS_MODULES += [
         'LightweightThemeConsumer.jsm',
     ]
 
+DEFINES['MOZ_APP_NAME'] = CONFIG['MOZ_APP_NAME']
+DEFINES['MOZ_BUILD_APP'] = CONFIG['MOZ_BUILD_APP']
+
+if CONFIG['MOZ_TOOLKIT_SEARCH']:
+    DEFINES['MOZ_TOOLKIT_SEARCH'] = True
--- a/toolkit/mozapps/extensions/Makefile.in
+++ b/toolkit/mozapps/extensions/Makefile.in
@@ -1,19 +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/.
 
-ifeq (,$(filter aurora beta release esr,$(MOZ_UPDATE_CHANNEL)))
-DEFINES += -DMOZ_COMPATIBILITY_NIGHTLY=1
-endif
-
-# This is used in multiple places, so is defined here to avoid it getting
-# out of sync.
-DEFINES += -DMOZ_EXTENSIONS_DB_SCHEMA=15
-
-# Additional debugging info is exposed in debug builds, or by setting the
-# MOZ_EM_DEBUG environment variable when building.
+# Additional debugging info is exposed by setting the MOZ_EM_DEBUG
+# environment variable when building.
 ifneq (,$(MOZ_EM_DEBUG))
 DEFINES += -DMOZ_EM_DEBUG=1
-else ifdef MOZ_DEBUG
-DEFINES += -DMOZ_EM_DEBUG=1
 endif
--- a/toolkit/mozapps/extensions/moz.build
+++ b/toolkit/mozapps/extensions/moz.build
@@ -40,8 +40,18 @@ EXTRA_JS_MODULES += [
 ]
 
 EXTRA_PP_JS_MODULES += [
     'AddonManager.jsm',
     'XPIProvider.jsm',
     'XPIProviderUtils.js',
 ]
 
+if CONFIG['MOZ_UPDATE_CHANNEL'] not in ('aurora', 'beta', 'release', 'esr'):
+    DEFINES['MOZ_COMPATIBILITY_NIGHTLY'] = 1
+
+# This is used in multiple places, so is defined here to avoid it getting
+# out of sync.
+DEFINES['MOZ_EXTENSIONS_DB_SCHEMA'] = 15
+
+# Additional debugging info is exposed in debug builds
+if CONFIG['MOZ_DEBUG']:
+    DEFINES['MOZ_EM_DEBUG'] = 1
--- a/toolkit/mozapps/update/tests/Makefile.in
+++ b/toolkit/mozapps/update/tests/Makefile.in
@@ -2,30 +2,18 @@
 # 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/.
 
 XPCSHELLTESTROOT = $(abspath $(DEPTH))/_tests/xpcshell/$(relativesrcdir)
 CHROMETESTROOT = $(abspath $(DEPTH))/_tests/testing/mochitest/chrome/$(relativesrcdir)
 
 DEFINES += \
   -DAB_CD=$(AB_CD) \
-  -DMOZ_APP_NAME=$(MOZ_APP_NAME) \
-  -DMOZ_APP_DISPLAYNAME="$(MOZ_APP_DISPLAYNAME)" \
-  -DBIN_SUFFIX=$(BIN_SUFFIX) \
-  -DNS_NO_XPCOM \
-  -DMOZ_DEBUG=$(MOZ_DEBUG) \
   $(NULL)
 
-ifdef MOZ_MAINTENANCE_SERVICE
-DEFINES += -DMOZ_MAINTENANCE_SERVICE=$(MOZ_MAINTENANCE_SERVICE)
-endif
-
-# For debugging purposes only
-#DEFINES += -DDISABLE_UPDATER_AUTHENTICODE_CHECK
-
 PP_TARGETS            += aus-update-head
 aus-update-head_FLAGS := -Fsubstitution $(DEFINES) $(ACDEFINES)
 aus-update-head       := $(srcdir)/unit_aus_update/head_update.js
 aus-update-head_PATH  := $(XPCSHELLTESTROOT)/unit_aus_update
 
 INSTALL_TARGETS       += xpcshell-data
 xpcshell-data_TARGET  := libs
 xpcshell-data_DEST    := $(XPCSHELLTESTROOT)/data
@@ -86,17 +74,16 @@ MOZ_WINCONSOLE = 1
 ifeq ($(OS_ARCH),WINNT)
 LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon-standalone,../common-standalone)
 else
 LIBS += $(call EXPAND_LIBNAME_PATH,updatecommon,../common)
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 USE_STATIC_LIBS = 1
-DEFINES += -DUNICODE -D_UNICODE
 endif # WINNT
 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.
--- a/toolkit/mozapps/update/tests/moz.build
+++ b/toolkit/mozapps/update/tests/moz.build
@@ -16,8 +16,23 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'andr
     SIMPLE_PROGRAMS = [
         'TestAUSHelper',
         'TestAUSReadStrings',
     ]
 
     SOURCES += [
         '%s.cpp' % s for s in SIMPLE_PROGRAMS
     ]
+
+for var in ('MOZ_APP_NAME', 'MOZ_APP_DISPLAYNAME', 'BIN_SUFFIX', 'MOZ_DEBUG'):
+    DEFINES[var] = CONFIG[var]
+
+DEFINES['NS_NO_XPCOM'] = True
+
+if CONFIG['MOZ_MAINTENANCE_SERVICE']:
+    DEFINES['MOZ_MAINTENANCE_SERVICE'] = CONFIG['MOZ_MAINTENANCE_SERVICE']
+
+# For debugging purposes only
+#DEFINES['DISABLE_UPDATER_AUTHENTICODE_CHECK'] = True
+
+if CONFIG['OS_ARCH'] == 'WINNT':
+    DEFINES['UNICODE'] = True
+    DEFINES['_UNICODE'] = True
--- a/toolkit/mozapps/update/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -23,17 +23,16 @@ LIBS += \
   $(MOZ_BZ2_LIBS) \
   $(NULL)
 
 ifeq ($(OS_ARCH),WINNT)
 LIBS += $(call EXPAND_LIBNAME_PATH,verifymar,$(DEPTH)/modules/libmar/verify)
 USE_STATIC_LIBS = 1
 RCINCLUDE = updater.rc
 OS_LIBS += $(call EXPAND_LIBNAME,delayimp comctl32 ws2_32 shell32 shlwapi)
-DEFINES += -DUNICODE -D_UNICODE
 ifndef GNU_CC
 RCFLAGS += -I$(srcdir)
 else
 RCFLAGS += --include-dir $(srcdir)
 endif
 
 endif
 
@@ -58,21 +57,16 @@ ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DNS_NO_XPCOM \
-  -DMAR_CHANNEL_ID='"$(MAR_CHANNEL_ID)"' \
-  -DMOZ_APP_VERSION='"$(MOZ_APP_VERSION)"' \
-  $(NULL)
-
 ifdef _MSC_VER
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 WIN32_EXE_LDFLAGS += -DELAYLOAD:wsock32.dll -DELAYLOAD:crypt32.dll -DELAYLOAD:userenv.dll
 endif
 
 ifdef MOZ_WIDGET_GTK
 libs:: updater.png
 	$(NSINSTALL) -D $(DIST)/bin/icons
--- a/toolkit/mozapps/update/updater/moz.build
+++ b/toolkit/mozapps/update/updater/moz.build
@@ -15,16 +15,18 @@ SOURCES += [
 have_progressui = 0
 if CONFIG['OS_ARCH'] == 'WINNT':
     have_progressui = 1
     SOURCES += [
         'loaddlls.cpp',
         'progressui_win.cpp',
         'win_dirent.cpp',
     ]
+    DEFINES['UNICODE'] = True
+    DEFINES['_UNICODE'] = True
 
 if CONFIG['MOZ_ENABLE_GTK']:
     have_progressui = 1
     SOURCES += [
         'progressui_gtk.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
@@ -41,8 +43,12 @@ if have_progressui == 0:
         'progressui_null.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     SOURCES += [
         'launchchild_osx.mm',
         'progressui_osx.mm',
     ]
+
+DEFINES['NS_NO_XPCOM'] = True
+for var in ('MAR_CHANNEL_ID', 'MOZ_APP_VERSION'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
deleted file mode 100644
--- a/toolkit/webapps/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/.
-
-ifeq ($(MOZ_BUILD_APP),mobile/android)
-DEFINES += -DMOZ_FENNEC=1
-endif
--- a/toolkit/webapps/moz.build
+++ b/toolkit/webapps/moz.build
@@ -4,8 +4,10 @@
 # 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_PP_JS_MODULES += [
     'WebappOSUtils.jsm',
     'WebappsInstaller.jsm',
 ]
 
+if CONFIG['MOZ_BUILD_APP'] == 'mobile/android':
+    DEFINES['MOZ_FENNEC'] = True
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -5,39 +5,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/makeutils.mk
 
 milestone_txt = $(topsrcdir)/config/milestone.txt
 
-ifeq ($(MOZ_GL_DEFAULT_PROVIDER),GLX)
-DEFINES += -DUSE_GLX_TEST
-endif
-
-DEFINES += \
-  -DMOZ_APP_NAME='"$(MOZ_APP_NAME)"' \
-  -DMOZ_APP_VERSION='"$(MOZ_APP_VERSION)"' \
-  $(NULL)
-
-ifdef MOZ_UPDATER
-ifneq (android,$(MOZ_WIDGET_TOOLKIT))
-DEFINES += -DMOZ_UPDATER
-endif
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
-DEFINES += -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE
-endif
-
-ifeq ($(MOZ_WIDGET_TOOLKIT),android)
-DEFINES += -DANDROID_PACKAGE_NAME='"$(ANDROID_PACKAGE_NAME)"'
-endif
-
 ifdef MOZ_ENABLE_XREMOTE
 LOCAL_INCLUDES += -I$(topsrcdir)/widget/xremoteclient
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/testing/gtest/mozilla \
@@ -50,44 +27,23 @@ LOCAL_INCLUDES += \
   $(NULL)
 
 CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS)
 
 ifdef MOZ_WIDGET_GTK
 CXXFLAGS += $(MOZ_PANGO_CFLAGS)
 endif
 
-DEFINES += \
-  -DOS_TARGET=\"$(OS_TARGET)\" \
-  -DMOZ_WIDGET_TOOLKIT=\"$(MOZ_WIDGET_TOOLKIT)\"
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += \
-  -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\" \
-  -DTARGET_OS_ABI=\"$(OS_TARGET)_$(TARGET_XPCOM_ABI)\" \
-  $(NULL)
-endif
-
 # Should version be optional or required ?
 TOOLKIT_EM_VERSION=$(shell $(PERL) $(topsrcdir)/config/milestone.pl --topsrcdir=$(topsrcdir))
 $(call warnIfEmpty,TOOLKIT_EM_VERSION)
 
 # Valid if null: {warn,error}IfEmpty
 DEFINES += -DTOOLKIT_EM_VERSION=\"$(TOOLKIT_EM_VERSION)\"
 
-ifdef WRAP_SYSTEM_INCLUDES
-DEFINES += -DWRAP_SYSTEM_INCLUDES
-endif
-
-ifeq ($(OS_ARCH),Linux)
-ifneq (,$(findstring lib64,$(libdir)))
-DEFINES += -DHAVE_USR_LIB64_DIR
-endif
-endif
-
 MOZ_SOURCE_STAMP ?= $(firstword $(shell hg -R $(topsrcdir) parent --template="{node|short}\n" 2>/dev/null))
 ifdef MOZ_SOURCE_STAMP
 
   INIARGS = --sourcestamp=$(MOZ_SOURCE_STAMP)
 
   source_repo := $(call getSourceRepo)
 
   # extra sanity check for old versions of hg, no showconfig support
@@ -95,25 +51,17 @@ ifdef MOZ_SOURCE_STAMP
     INIARGS += --sourcerepo=$(source_repo)
   endif
 
 endif # MOZ_SOURCE_STAMP
 
 GRE_BUILDID   := $(strip $(firstword $(shell cat $(DEPTH)/config/buildid 2>/dev/null)))
 $(call errorIfEmpty,GRE_MILESTONE GRE_BUILDID)
 
-DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DGRE_BUILDID=$(GRE_BUILDID)
-
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL
-endif
-
-DEFINES += -DAPP_VERSION=$(MOZ_APP_VERSION)
-
-DEFINES += -DAPP_ID="$(MOZ_APP_ID)"
+DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 $(srcdir)/nsAppRunner.cpp: $(DEPTH)/config/buildid $(milestone_txt)
 
 platform.ini: FORCE
 	$(PYTHON) $(srcdir)/make-platformini.py --buildid=$(GRE_BUILDID) $(INIARGS) $(milestone_txt) > $@
 
 GARBAGE += platform.ini
 
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -97,8 +97,47 @@ if CONFIG['MOZ_UPDATER']:
 
 MSVC_ENABLE_PGO = True
 
 LIBRARY_NAME = 'xulapp_s'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+if CONFIG['MOZ_GL_DEFAULT_PROVIDER'] == 'GLX':
+    DEFINES['USE_GLX_TEST'] = True
+
+for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION', 'OS_TARGET',
+            'MOZ_WIDGET_TOOLKIT'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
+
+if CONFIG['MOZ_UPDATER'] and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
+    DEFINES['MOZ_UPDATER'] = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    DEFINES['WIN32_LEAN_AND_MEAN'] = True
+    DEFINES['UNICODE'] = True
+    DEFINES['_UNICODE'] = True
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+    DEFINES['ANDROID_PACKAGE_NAME'] = '"%s"' % CONFIG['ANDROID_PACKAGE_NAME']
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
+    DEFINES['TARGET_OS_ABI'] = '"%s_%s"' % (CONFIG['OS_TARGET'],
+                                            CONFIG['TARGET_XPCOM_ABI'])
+
+if CONFIG['WRAP_SYSTEM_INCLUDES']:
+    DEFINES['WRAP_SYSTEM_INCLUDES'] = True
+
+if CONFIG['OS_ARCH'] == 'Linux' and 'lib64' in CONFIG['libdir']:
+    DEFINES['HAVE_USR_LIB64_DIR'] = True
+
+DEFINES['GRE_MILESTONE'] = CONFIG['GRE_MILESTONE']
+for var in ('GRE_MILESTONE', 'MOZ_APP_ID'):
+    DEFINES[var] = CONFIG[var]
+
+for var in ('APP_VERSION', 'APP_ID'):
+    DEFINES[var] = CONFIG['MOZ_%s' % var]
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
--- a/toolkit/xre/test/win/Makefile.in
+++ b/toolkit/xre/test/win/Makefile.in
@@ -10,18 +10,16 @@ LOCAL_INCLUDES += \
   -I$(topsrcdir)/config \
   $(NULL)
 
 MOZ_WINCONSOLE = 1
 USE_STATIC_LIBS = 1
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DNS_NO_XPCOM
-
 libs:: TestXREMakeCommandLineWin.ini
 	$(INSTALL) $^ $(FINAL_TARGET)/
 
 check::
 	@echo "Running TestXREMakeCommandLineWin tests"
 	@$(RUN_TEST_PROGRAM) $(FINAL_TARGET)/TestXREMakeCommandLineWin.exe
 	@echo "Running TestDllInterceptor tests"
 	@$(RUN_TEST_PROGRAM) $(FINAL_TARGET)/TestDllInterceptor.exe
--- a/toolkit/xre/test/win/moz.build
+++ b/toolkit/xre/test/win/moz.build
@@ -7,8 +7,10 @@
 SIMPLE_PROGRAMS = [
     'TestDllInterceptor',
     'TestXREMakeCommandLineWin',
 ]
 
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
+
+DEFINES['NS_NO_XPCOM'] = True
--- a/tools/jprof/stub/Makefile.in
+++ b/tools/jprof/stub/Makefile.in
@@ -1,12 +1,8 @@
 #! 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/.
 
 # override optimization
 MOZ_OPTIMIZE_FLAGS = -fno-omit-frame-pointer
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES		+= -D_IMPL_JPROF_API
--- a/tools/jprof/stub/moz.build
+++ b/tools/jprof/stub/moz.build
@@ -12,8 +12,10 @@ SOURCES += [
     'libmalloc.cpp',
 ]
 
 LIBRARY_NAME = 'jprof'
 
 EXPORT_LIBRARY = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['_IMPL_JPROF_API'] = True
--- a/tools/trace-malloc/lib/Makefile.in
+++ b/tools/trace-malloc/lib/Makefile.in
@@ -1,14 +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/.
 
 DEFFILE		= $(win_srcdir)/tm.def
 
 STL_FLAGS	=
-
-DEFINES		+= -DMOZ_NO_MOZALLOC
-
-ifdef WRAP_SYSTEM_INCLUDES
-DEFINES		+= -DWRAP_SYSTEM_INCLUDES
-endif
--- a/tools/trace-malloc/lib/moz.build
+++ b/tools/trace-malloc/lib/moz.build
@@ -18,8 +18,13 @@ SOURCES += [
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'nsDebugHelpWin32.cpp',
         'nsWinTraceMalloc.cpp',
     ]
 
 FINAL_LIBRARY = 'xpcom_core'
+
+if CONFIG['WRAP_SYSTEM_INCLUDES']:
+    DEFINES['WRAP_SYSTEM_INCLUDES'] = True
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
--- a/webapprt/Makefile.in
+++ b/webapprt/Makefile.in
@@ -5,32 +5,21 @@
 # Include config.mk explicitly so we can override FINAL_TARGET.
 include $(topsrcdir)/config/config.mk
 
 PREF_JS_EXPORTS = $(srcdir)/prefs.js \
                   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
-ifdef MOZ_DEBUG
-DEFINES += -DMOZ_DEBUG=1
-endif
-
-ifdef MOZILLA_OFFICIAL
-DEFINES += -DMOZILLA_OFFICIAL
-endif
-
 libs:: $(call mkdir_deps,$(FINAL_TARGET))
 	$(call py_action,buildlist,$(FINAL_TARGET)/chrome.manifest "resource webapprt ./")
 
 GRE_BUILDID := $(shell cat $(DEPTH)/config/buildid)
-DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) \
-           -DGRE_BUILDID=$(GRE_BUILDID) \
-           -DMOZ_APP_BASENAME=$(MOZ_APP_BASENAME) \
-           $(NULL)
+DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 webapprt.ini: application.ini.in $(DEPTH)/config/buildid $(topsrcdir)/config/milestone.txt
 	$(call py_action,preprocessor,$(DEFINES) $< -o $@)
 
 libs:: webapprt.ini
 	$(INSTALL) webapprt.ini $(FINAL_TARGET)
 
 GARBAGE += webapprt.ini
--- a/webapprt/gtk2/Makefile.in
+++ b/webapprt/gtk2/Makefile.in
@@ -4,17 +4,16 @@
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/toolkit/xre \
   -I$(topsrcdir)/xpcom/base \
   -I$(topsrcdir)/xpcom/build \
   -I$(DEPTH)/build \
   $(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(MOZ_GTK2_LIBS) \
   $(NULL)
 
 NSDISTMODE = copy
--- a/webapprt/gtk2/moz.build
+++ b/webapprt/gtk2/moz.build
@@ -7,8 +7,9 @@
 PROGRAM = 'webapprt-stub'
 
 SOURCES += [
     'webapprt.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
+DEFINES['XPCOM_GLUE'] = True
--- a/webapprt/mac/Makefile.in
+++ b/webapprt/mac/Makefile.in
@@ -11,17 +11,16 @@ NSDISTMODE = copy
 MOZ_GLUE_LDFLAGS =
 MOZ_GLUE_PROGRAM_LDFLAGS =
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(NULL)
 
 PROGRAMS_DEST = $(DIST)/bin
 
--- a/webapprt/mac/moz.build
+++ b/webapprt/mac/moz.build
@@ -5,8 +5,9 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 PROGRAM = 'webapprt-stub'
 
 SOURCES += [
     'webapprt.mm',
 ]
 
+DEFINES['XPCOM_GLUE'] = True
--- a/webapprt/moz.build
+++ b/webapprt/moz.build
@@ -30,8 +30,17 @@ EXTRA_JS_MODULES += [
 ]
 
 MOCHITEST_WEBAPPRT_CHROME_MANIFESTS += ['test/chrome/webapprt.ini']
 MOCHITEST_MANIFESTS += ['test/content/mochitest.ini']
 
 # Place webapprt resources in a separate app dir
 DIST_SUBDIR = 'webapprt'
 export('DIST_SUBDIR')
+
+if CONFIG['MOZ_DEBUG']:
+    DEFINES['MOZ_DEBUG'] = 1
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
+
+DEFINES['GRE_MILESTONE'] = CONFIG['GRE_MILESTONE']
+DEFINES['MOZ_APP_BASENAME'] = CONFIG['MOZ_APP_BASENAME']
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/Makefile.in
@@ -8,17 +8,16 @@ USE_STATIC_LIBS = 1
 # to dynamically link into our executable, as we copy it to arbitrary locations.
 MOZ_GLUE_LDFLAGS =
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
   $(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS) \
   $(NULL)
 
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
--- a/webapprt/win/moz.build
+++ b/webapprt/win/moz.build
@@ -4,8 +4,10 @@
 # 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'
 
 SOURCES += [
     'webapprt.cpp',
 ]
+
+DEFINES['XPCOM_GLUE'] = True
--- a/widget/android/Makefile.in
+++ b/widget/android/Makefile.in
@@ -1,16 +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/.
 
 include $(topsrcdir)/config/rules.mk
 
-#DEFINES += -DDEBUG_WIDGETS
-
 LOCAL_INCLUDES += \
 	-I$(topsrcdir)/widget/xpwidgets \
 	-I$(topsrcdir)/widget/shared \
 	-I$(topsrcdir)/dom/system/android \
 	-I$(topsrcdir)/docshell/base \
 	-I$(topsrcdir)/content/events/src \
 	-I$(topsrcdir)/netwerk/cache \
 	-I$(topsrcdir)/widget/android/android \
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -41,8 +41,10 @@ SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
 LIBRARY_NAME = 'widget_android'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+#DEFINES['DEBUG_WIDGETS'] = True
--- a/widget/gonk/Makefile.in
+++ b/widget/gonk/Makefile.in
@@ -14,22 +14,16 @@
 
 VPATH           = \
   $(srcdir) \
   $(srcdir)/libui \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DHAVE_OFF64_T -DSK_BUILD_FOR_ANDROID_NDK
-
-ifdef MOZ_OMX_DECODER
-DEFINES += -DMOZ_OMX_DECODER
-endif
-
 LOCAL_INCLUDES += \
 	-I$(ANDROID_SOURCE)/hardware/libhardware/include \
 	-I$(ANDROID_SOURCE)/hardware/libhardware_legacy/include \
 	-I$(ANDROID_SOURCE)/frameworks/native/opengl/include \
 	-I$(topsrcdir)/widget/xpwidgets \
 	-I$(topsrcdir)/widget/shared \
 	-I$(topsrcdir)/dom/system/android \
 	-I$(topsrcdir)/content/events/src \
--- a/widget/gonk/libdisplay/Makefile.in
+++ b/widget/gonk/libdisplay/Makefile.in
@@ -15,18 +15,16 @@
 VPATH           = \
   $(srcdir) \
   $(NULL)
 
 STL_FLAGS=
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DXPCOM_GLUE
-
 LOCAL_INCLUDES += \
 	-I$(ANDROID_SOURCE)/hardware/libhardware/include \
 	-I$(ANDROID_SOURCE)/hardware/libhardware_legacy/include \
 	-I$(ANDROID_SOURCE)/frameworks/native/include/gui \
 	-I$(ANDROID_SOURCE)/frameworks/native/opengl/include \
 	-I$(ANDROID_SOURCE)/system/core/libsuspend/include \
 	-I$(srcdir) \
 	$(NULL)
--- a/widget/gonk/libdisplay/moz.build
+++ b/widget/gonk/libdisplay/moz.build
@@ -36,8 +36,10 @@ elif CONFIG['ANDROID_VERSION'] == '15':
 elif CONFIG['COMPILE_ENVIRONMENT']:
     error('Unsupported platform version: %s' % (CONFIG['ANDROID_VERSION']))
 
 LIBRARY_NAME = 'display'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FORCE_STATIC_LIB = True
+
+DEFINES['XPCOM_GLUE'] = True
--- a/widget/gonk/moz.build
+++ b/widget/gonk/moz.build
@@ -58,8 +58,14 @@ SOURCES += [
     'ProcessOrientation.cpp'
 ]
 
 LIBRARY_NAME = 'widget_gonk'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['HAVE_OFF64_T'] = True
+DEFINES['SK_BUILD_FOR_ANDROID_NDK'] = True
+
+if CONFIG['MOZ_OMX_DECODER']:
+    DEFINES['MOZ_OMX_DECODER'] = True
--- a/widget/gtk/Makefile.in
+++ b/widget/gtk/Makefile.in
@@ -7,18 +7,16 @@ include $(topsrcdir)/config/rules.mk
 
 CFLAGS          += $(MOZ_STARTUP_NOTIFICATION_CFLAGS)
 CXXFLAGS        += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) \
 		               $(MOZ_STARTUP_NOTIFICATION_CFLAGS)
 
 CFLAGS          += $(TK_CFLAGS)
 CXXFLAGS        += $(TK_CFLAGS)
 
-DEFINES		+= -DCAIRO_GFX -DMOZ_APP_NAME='"$(MOZ_APP_NAME)"'
-
 INCLUDES	+= \
 		-I$(srcdir)/../xpwidgets \
 		-I$(srcdir)/../shared \
 		-I$(topsrcdir)/layout/generic \
 		-I$(topsrcdir)/layout/xul/base/src \
 		-I$(topsrcdir)/other-licenses/atk-1.0 \
 		$(NULL)
 ifdef MOZ_X11
--- a/widget/gtk/moz.build
+++ b/widget/gtk/moz.build
@@ -75,8 +75,12 @@ if CONFIG['MOZ_ENABLE_GTK2']:
 else:
     SOURCES += [
         'gtk3drawing.c',
     ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['CAIRO_GFX'] = True
+
+DEFINES['MOZ_APP_NAME'] = '"%s"' % CONFIG['MOZ_APP_NAME']
--- a/widget/gtkxtbin/Makefile.in
+++ b/widget/gtkxtbin/Makefile.in
@@ -5,13 +5,11 @@
 
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_ENABLE_GTK2
 CFLAGS		+= $(MOZ_GTK2_CFLAGS)
 endif
 
-DEFINES		+= -D_IMPL_GTKXTBIN_API
-
 INCLUDES	+= \
 		-I$(srcdir) \
 		$(NULL)
--- a/widget/gtkxtbin/moz.build
+++ b/widget/gtkxtbin/moz.build
@@ -9,8 +9,10 @@ EXPORTS += [
 ]
 
 if CONFIG['MOZ_ENABLE_GTK2']:
     SOURCES += [
         'gtk2xtbin.c',
     ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['_IMPL_GTKXTBIN_API'] = True
--- a/widget/os2/Makefile.in
+++ b/widget/os2/Makefile.in
@@ -4,20 +4,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 RESFILE		= widget.res
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS)
 
-DEFINES += -DUSE_OS2_TOOLKIT_HEADERS
-
-DEFINES += -DMOZ_APP_DISPLAYNAME=\"$(MOZ_APP_DISPLAYNAME)\"
-
 LOCAL_INCLUDES	= -I. -I$(srcdir)/../xpwidgets -I$(srcdir)
 
 install-readme:	README.$(MOZ_APP_NAME)
 ifneq (,$(filter-out xulrunner sunbird,$(MOZ_APP_NAME)))
 	cp -f $^ $(DIST)/bin/README.txt
 endif
 
 libs::	install-readme
--- a/widget/os2/moz.build
+++ b/widget/os2/moz.build
@@ -23,8 +23,12 @@ SOURCES += [
     'nsWidgetFactory.cpp',
     'nsWindow.cpp',
     'os2FrameWindow.cpp',
 ]
 
 LIBRARY_NAME = 'wdgtos2'
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['USE_OS2_TOOLKIT_HEADERS'] = True
+
+DEFINES['MOZ_APP_DISPLAYNAME'] = '"%s"' % CONFIG['MOZ_APP_DISPLAYNAME']
--- a/widget/qt/Makefile.in
+++ b/widget/qt/Makefile.in
@@ -5,32 +5,16 @@
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS	+= $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS) \
 		$(MOZ_PIXMAN_CFLAGS)
 CFLAGS		+= $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS) \
 		$(MOZ_PIXMAN_CFLAGS)
 
-#DEFINES		+= -DDEBUG_WIDGETS
-
-ifeq ($(OS_ARCH), Linux)
-DEFINES         += -D_BSD_SOURCE
-endif
-ifeq ($(OS_ARCH), SunOS) 
-ifndef GNU_CC
-# When using Sun's WorkShop compiler, including
-# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
-# causes most of these compiles to fail with:
-# line 29: Error: Multiple declaration for std::tm.
-# So, this gets around the problem.
-DEFINES         += -D_TIME_H=1
-endif
-endif
-
 LOCAL_INCLUDES	+= \
 		   -I$(topsrcdir)/widget/shared \
 		   -I$(topsrcdir)/widget/xpwidgets \
 		   -I$(topsrcdir)/widget/qt/faststartupqt \
 		   -I$(srcdir) \
 		   $(NULL)
 ifdef MOZ_X11
 INCLUDES   	+= -I$(srcdir)/../shared/x11
--- a/widget/qt/faststartupqt/Makefile.in
+++ b/widget/qt/faststartupqt/Makefile.in
@@ -19,10 +19,8 @@ EXPORT_SOURCES = \
 
 GARBAGE += $(EXPORT_SOURCES)
 export:: $(EXPORT_SOURCES)
 	$(INSTALL) $^ .
 
 LOCAL_INCLUDES += \
 	$(MOZ_QT_CFLAGS) \
 	$(NULL)
-
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)" -DMOZ_NO_MOZALLOC -DXPCOM_GLUE
--- a/widget/qt/faststartupqt/moz.build
+++ b/widget/qt/faststartupqt/moz.build
@@ -15,8 +15,17 @@ SOURCES += [
     TOPSRCDIR + '/widget/qt/mozqglwidgetwrapper.cpp',
 ]
 
 SOURCES += [
     'nsFastStartupQt.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
+DEFINES['XPCOM_GLUE'] = True
--- a/widget/qt/moz.build
+++ b/widget/qt/moz.build
@@ -56,8 +56,21 @@ if CONFIG[' MOZ_ENABLE_QTMOBILITY']:
         'moc_mozqorientationsensorfilter.cpp',
     ]
 
 LIBRARY_NAME = 'widget_qt'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+#DEFINES['DEBUG_WIDGETS'] = True
+
+if CONFIG['OS_ARCH'] == 'Linux':
+    DEFINES['_BSD_SOURCE'] = True
+
+if CONFIG['OS_ARCH'] == 'SunOS' and not CONFIG['GNU_CC']:
+    # When using Sun's WorkShop compiler, including
+    # /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
+    # causes most of these compiles to fail with:
+    # line 29: Error: Multiple declaration for std::tm.
+    # So, this gets around the problem.
+    DEFINES['_TIME_H'] = 1
--- a/widget/windows/Makefile.in
+++ b/widget/windows/Makefile.in
@@ -1,23 +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/.
 
 RESFILE		= widget.res
-DEFINES		+= -DMOZ_UNICODE 
-
-ifdef MOZ_ENABLE_D3D9_LAYER
-DEFINES		+= -DMOZ_ENABLE_D3D9_LAYER
-endif
-
-ifdef MOZ_ENABLE_D3D10_LAYER
-DEFINES		+= -DMOZ_ENABLE_D3D10_LAYER
-endif
 
 LOCAL_INCLUDES	= \
 		-I. \
 		-I$(srcdir)/../xpwidgets \
 		-I$(srcdir)/../shared \
 		-I$(srcdir) \
 		-I$(topsrcdir)/layout/generic \
 		-I$(topsrcdir)/layout/xul/base/src \
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -83,8 +83,14 @@ if CONFIG['NS_ENABLE_TSF']:
 
 MSVC_ENABLE_PGO = True
 
 LIBRARY_NAME = 'widget_windows'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['MOZ_UNICODE'] = True
+
+for var in ('MOZ_ENABLE_D3D9_LAYER', 'MOZ_ENABLE_D3D10_LAYER'):
+    if CONFIG[var]:
+        DEFINES[var] = True
--- a/widget/windows/winrt/Makefile.in
+++ b/widget/windows/winrt/Makefile.in
@@ -1,22 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEFINES		+= -DMOZ_UNICODE
-
-ifdef MOZ_ENABLE_D3D9_LAYER
-DEFINES		+= -DMOZ_ENABLE_D3D9_LAYER
-endif
-
-ifdef MOZ_ENABLE_D3D10_LAYER
-DEFINES		+= -DMOZ_ENABLE_D3D10_LAYER
-endif
-
 LOCAL_INCLUDES	= \
 		-I. \
 		-I$(srcdir)/../../shared \
 		-I$(srcdir)/../../xpwidgets \
 		-I$(srcdir) \
 		-I$(srcdir)/../ \
 		-I$(topsrcdir)/layout/generic \
 		-I$(topsrcdir)/layout/xul/base/src \
--- a/widget/windows/winrt/moz.build
+++ b/widget/windows/winrt/moz.build
@@ -23,8 +23,14 @@ SOURCES += [
 EXTRA_COMPONENTS += [
     'MetroUIUtils.js',
     'MetroUIUtils.manifest',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['MOZ_UNICODE'] = True
+
+for var in ('MOZ_ENABLE_D3D9_LAYER', 'MOZ_ENABLE_D3D10_LAYER'):
+    if CONFIG[var]:
+        DEFINES[var] = True
--- a/widget/xpwidgets/Makefile.in
+++ b/widget/xpwidgets/Makefile.in
@@ -1,17 +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_ENABLE_D3D10_LAYER
-DEFINES		+= -DMOZ_ENABLE_D3D10_LAYER
-endif
-
 ifneq (,$(filter gtk3 gtk2,$(MOZ_WIDGET_TOOLKIT)))
 # gtk3 shares includes with gtk2
 LOCAL_INCLUDES	+= \
 		-I$(srcdir)/../gtk \
 		$(NULL)
 else
 LOCAL_INCLUDES	+= \
  		-I$(srcdir)/../$(MOZ_WIDGET_TOOLKIT) \
--- a/widget/xpwidgets/moz.build
+++ b/widget/xpwidgets/moz.build
@@ -70,8 +70,11 @@ LIBRARY_NAME = 'xpwidgets_s'
 include('/ipc/chromium/chromium-config.mozbuild')
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     FINAL_LIBRARY = 'widget_mac'
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gonk', 'android', 'qt', 'gtk2', 'gtk3'):
     FINAL_LIBRARY = 'widget_%s' % CONFIG['MOZ_WIDGET_TOOLKIT']
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'os2':
     FINAL_LIBRARY = 'wdgtos2'
+
+if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
+    DEFINES['MOZ_ENABLE_D3D10_LAYER'] = True
--- a/widget/xremoteclient/Makefile.in
+++ b/widget/xremoteclient/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/.
 
 # NOTE: This directory is part of tier 50, and is linked directly into
 # the application binaries. The fact that it's under mozilla/widget is a fluke
 # of tree history.
 
-DEFINES += -DXPCOM_GLUE
-
 LIBCPPSRCS = XRemoteClient.cpp
 
 OBJS = $(LIBCPPSRCS:.cpp=.$(OBJ_SUFFIX))
 
 EXTRA_DSO_LDOPTS = \
 		$(XLIBS) $(XLDFLAGS)  \
 		$(MOZ_COMPONENT_LIBS) \
 		$(NULL)
--- a/widget/xremoteclient/moz.build
+++ b/widget/xremoteclient/moz.build
@@ -2,8 +2,10 @@
 # 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 = 'mozilla-xremote-client'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+DEFINES['XPCOM_GLUE'] = True
--- a/xpcom/build/Makefile.in
+++ b/xpcom/build/Makefile.in
@@ -18,20 +18,11 @@ LOCAL_INCLUDES	= \
 		-I$(srcdir)/../threads \
 		-I$(srcdir)/../reflect/xptinfo/src \
 		-I$(topsrcdir)/chrome/src \
 		-I$(srcdir)/../../docshell/base \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES		+= \
-		-D_IMPL_NS_STRINGAPI \
-		-DOMNIJAR_NAME="$(OMNIJAR_NAME)" \
-		$(NULL)
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
-
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 CXXFLAGS	+= $(TK_CFLAGS)
 endif
--- a/xpcom/build/moz.build
+++ b/xpcom/build/moz.build
@@ -64,8 +64,14 @@ SOURCES += [
 
 MSVC_ENABLE_PGO = True
 
 LIBRARY_NAME = 'xpcom_core'
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['_IMPL_NS_STRINGAPI'] = True
+DEFINES['OMNIJAR_NAME'] = CONFIG['OMNIJAR_NAME']
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
--- a/xpcom/glue/Makefile.in
+++ b/xpcom/glue/Makefile.in
@@ -11,14 +11,9 @@ LOCAL_INCLUDES	= \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
--- a/xpcom/glue/moz.build
+++ b/xpcom/glue/moz.build
@@ -97,8 +97,14 @@ UNIFIED_SOURCES += [
 
 LIBRARY_NAME = 'xpcomglue_s'
 
 SDK_LIBRARY = [
     "%s%s.%s" % (CONFIG['LIB_PREFIX'], 'xpcomglue_s', CONFIG['LIB_SUFFIX']),
 ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
--- a/xpcom/glue/nomozalloc/Makefile.in
+++ b/xpcom/glue/nomozalloc/Makefile.in
@@ -19,16 +19,9 @@ USE_STATIC_LIBS = 1
 STL_FLAGS       =
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
-
-DEFINES += -DMOZ_NO_MOZALLOC
--- a/xpcom/glue/nomozalloc/moz.build
+++ b/xpcom/glue/nomozalloc/moz.build
@@ -17,8 +17,16 @@ SOURCES += [
 LIBRARY_NAME = 'xpcomglue_s_nomozalloc'
 
 SDK_LIBRARY = [
     "%s%s.%s" % (CONFIG['LIB_PREFIX'], 'xpcomglue_s_nomozalloc', CONFIG['LIB_SUFFIX']),
 ]
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
--- a/xpcom/glue/standalone/Makefile.in
+++ b/xpcom/glue/standalone/Makefile.in
@@ -14,16 +14,9 @@ LOCAL_INCLUDES	= \
 STL_FLAGS	=
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives in obj files about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
-
-DEFINES		+= -DXPCOM_GLUE
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
--- a/xpcom/glue/standalone/moz.build
+++ b/xpcom/glue/standalone/moz.build
@@ -24,8 +24,16 @@ EXPORTS += [
     'nsXPCOMGlue.h',
 ]
 
 SDK_LIBRARY = [
     "%s%s.%s" % (CONFIG['LIB_PREFIX'], 'xpcomglue', CONFIG['LIB_SUFFIX']),
 ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
+
+DEFINES['XPCOM_GLUE'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
--- a/xpcom/glue/standalone/staticruntime/Makefile.in
+++ b/xpcom/glue/standalone/staticruntime/Makefile.in
@@ -16,16 +16,9 @@ USE_STATIC_LIBS = 1
 STL_FLAGS	=
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives in obj files about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
-
-DEFINES		+= -DXPCOM_GLUE
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
--- a/xpcom/glue/standalone/staticruntime/moz.build
+++ b/xpcom/glue/standalone/staticruntime/moz.build
@@ -16,8 +16,16 @@ SOURCES += [
 LIBRARY_NAME = 'xpcomglue_staticruntime'
 
 SDK_LIBRARY = [
     "%s%s.%s" % (CONFIG['LIB_PREFIX'], 'xpcomglue_staticruntime', CONFIG['LIB_SUFFIX']),
 ]
 
 # create a static lib
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
+
+DEFINES['XPCOM_GLUE'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
--- a/xpcom/glue/staticruntime/Makefile.in
+++ b/xpcom/glue/staticruntime/Makefile.in
@@ -17,14 +17,9 @@ USE_STATIC_LIBS = 1
 STL_FLAGS	=
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef _MSC_VER
 # Don't include directives about which CRT to use
 OS_COMPILE_CXXFLAGS += -Zl
 OS_COMPILE_CFLAGS += -Zl
-DEFINES += -D_USE_ANSI_CPP
 endif
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
--- a/xpcom/glue/staticruntime/moz.build
+++ b/xpcom/glue/staticruntime/moz.build
@@ -16,8 +16,14 @@ SOURCES += [
 
 LIBRARY_NAME = 'xpcomglue_staticruntime_s'
 
 SDK_LIBRARY = [
     "%s%s.%s" % (CONFIG['LIB_PREFIX'], 'xpcomglue_staticruntime_s', CONFIG['LIB_SUFFIX']),
 ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
--- a/xpcom/io/Makefile.in
+++ b/xpcom/io/Makefile.in
@@ -1,14 +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/.
 
 MOZILLA_INTERNAL_API = 1
 include $(topsrcdir)/config/rules.mk
 
-ifeq ($(OS_ARCH),Linux)
-ifneq (,$(findstring lib64,$(libdir)))
-DEFINES     += -DHAVE_USR_LIB64_DIR
-endif
-endif
-
 LOCAL_INCLUDES	+= -I..
--- a/xpcom/io/moz.build
+++ b/xpcom/io/moz.build
@@ -122,8 +122,11 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xpcom_core'
+
+if CONFIG['OS_ARCH'] == 'Linux' and 'lib64' in CONFIG['libdir']:
+    DEFINES['HAVE_USR_LIB64_DIR'] = True
--- a/xpcom/reflect/xptcall/src/md/os2/Makefile.in
+++ b/xpcom/reflect/xptcall/src/md/os2/Makefile.in
@@ -4,13 +4,11 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MOZILLA_INTERNAL_API = 1
 
 LOCAL_INCLUDES = \
 		-I$(srcdir)/../unix \
 		-I$(srcdir)/../../../../xptinfo/src \
 		$(NULL)
-DEFINES		+= -DMOZ_NEED_LEADING_UNDERSCORE
-
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES	+= -I$(srcdir)/../..
--- a/xpcom/reflect/xptcall/src/md/os2/moz.build
+++ b/xpcom/reflect/xptcall/src/md/os2/moz.build
@@ -5,8 +5,10 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     '../unix/xptcinvoke_gcc_x86_unix.cpp',
     'xptcstubs_gcc_x86_os2.cpp',
 ]
 
 FINAL_LIBRARY = 'xpcom_core'
+
+DEFINES['MOZ_NEED_LEADING_UNDERSCORE'] = True
--- a/xpcom/reflect/xptcall/src/md/unix/Makefile.in
+++ b/xpcom/reflect/xptcall/src/md/unix/Makefile.in
@@ -14,32 +14,16 @@ ifeq ($(OS_ARCH),SunOS)
 ifneq (86,$(findstring 86,$(OS_TEST)))
 # disable PGO for this directory with Sun Studio on SPARC because
 # compiling with xprofile=collect will insert code into nsXPTCStubBase::Stub##n
 NO_PROFILE_GUIDED_OPTIMIZE = 1
 endif
 endif
 
 ######################################################################
-# i386 and beyond
-######################################################################
-#
-# Lots of Unixish x86 flavors
-#
-
-ifeq (Darwin,$(OS_ARCH))
-ifeq (86,$(findstring 86,$(OS_TEST)))
-ifeq (x86_64,$(OS_TEST))
-else
-DEFINES		+= -DMOZ_NEED_LEADING_UNDERSCORE
-endif
-endif
-endif
-
-######################################################################
 # ARM
 ######################################################################
 #
 # Linux/ARM
 #
 ifeq ($(OS_ARCH),Linux)
 ifneq (,$(filter arm% sa110,$(OS_TEST)))
 CXXFLAGS += -O2
--- a/xpcom/reflect/xptcall/src/md/unix/moz.build
+++ b/xpcom/reflect/xptcall/src/md/unix/moz.build
@@ -11,16 +11,18 @@ if CONFIG['OS_ARCH'] == 'Darwin':
     ]
     if CONFIG['OS_TEST'] == 'powerpc':
         SOURCES += [
             'xptcinvoke_asm_ppc_rhapsody.s',
         ]
         GENERATED_SOURCES += [
             'xptcstubs_asm_ppc_darwin.s',
         ]
+    if '86' in CONFIG['OS_TEST'] and CONFIG['OS_TEST'] != 'x86_64':
+        DEFINES['MOZ_NEED_LEADING_UNDERSCORE'] = True
 
 if CONFIG['OS_ARCH'] in ('NetBSD', 'OpenBSD', 'GNU'):
     if CONFIG['CPU_ARCH'] == 'x86':
         SOURCES += [
             'xptcinvoke_gcc_x86_unix.cpp',
             'xptcstubs_gcc_x86_unix.cpp'
         ]
 
--- a/xpcom/sample/program/Makefile.in
+++ b/xpcom/sample/program/Makefile.in
@@ -12,12 +12,8 @@ LIBS            = \
 		$(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 LIBS            += \
 		$(TK_LIBS) \
 		$(NULL)
 endif
-
-# Whatever code is going to be linked with the *standalone* glue must be
-# built with the XPCOM_GLUE define set.
-DEFINES += -DXPCOM_GLUE
--- a/xpcom/sample/program/moz.build
+++ b/xpcom/sample/program/moz.build
@@ -9,8 +9,12 @@
 SOURCES += [
     'nsTestSample.cpp',
 ]
 
 # SIMPLE_PROGRAMS compiles a single .cpp file into an executable
 SIMPLE_PROGRAMS += [
     'nsTestSample'
 ]
+
+# Whatever code is going to be linked with the *standalone* glue must be
+# built with the XPCOM_GLUE define set.
+DEFINES['XPCOM_GLUE'] = True
--- a/xpcom/tests/bug656331_component/Makefile.in
+++ b/xpcom/tests/bug656331_component/Makefile.in
@@ -19,13 +19,11 @@ EXTRA_DSO_LDOPTS = \
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
   $(TK_LIBS) \
   $(NULL)
 endif
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 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
@@ -10,8 +10,14 @@ SOURCES += [
     'TestComponent.cpp',
 ]
 
 LIBRARY_NAME = 'test656331'
 
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
--- a/xpcom/tests/component/Makefile.in
+++ b/xpcom/tests/component/Makefile.in
@@ -17,13 +17,11 @@ EXTRA_DSO_LDOPTS = \
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 EXTRA_DSO_LDOPTS += \
 		$(TK_LIBS) \
 		$(NULL)
 endif
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
--- a/xpcom/tests/component/moz.build
+++ b/xpcom/tests/component/moz.build
@@ -10,8 +10,14 @@ SOURCES += [
     'TestComponent.cpp',
 ]
 
 LIBRARY_NAME = 'testcomponent'
 
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
--- a/xpcom/tests/component_no_aslr/Makefile.in
+++ b/xpcom/tests/component_no_aslr/Makefile.in
@@ -24,10 +24,8 @@ endif
 
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
 
 include $(topsrcdir)/config/rules.mk
 
 LDFLAGS := $(filter-out -DYNAMICBASE,$(LDFLAGS)) -DYNAMICBASE:NO
-
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
--- a/xpcom/tests/component_no_aslr/moz.build
+++ b/xpcom/tests/component_no_aslr/moz.build
@@ -10,8 +10,14 @@ SOURCES += [
     'TestComponent.cpp',
 ]
 
 LIBRARY_NAME = 'testcompnoaslr'
 
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -3,23 +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/.
 
 PREF_JS_EXPORTS = $(srcdir)/xulrunner.js
 GARBAGE += $(addprefix $(DIST)/bin/defaults/pref/,xulrunner.js)
 
 DEFINES += -DAB_CD=$(AB_CD)
 
-DEFINES += -DXULRUNNER_PROGNAME=\"xulrunner\"
-
-ifdef TARGET_XPCOM_ABI
-DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
-endif
-
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/toolkit/xre \
   -I$(topsrcdir)/toolkit/profile \
   -I$(topsrcdir)/xpcom/base \
   -I$(topsrcdir)/xpcom/build \
   $(NULL)
--- a/xulrunner/app/moz.build
+++ b/xulrunner/app/moz.build
@@ -6,8 +6,14 @@
 
 DIRS += ['profile']
 
 PROGRAM = 'xulrunner'
 
 SOURCES += [
     'nsXULRunnerApp.cpp',
 ]
+
+DEFINES['XULRUNNER_PROGNAME'] = '"xulrunner"'
+DEFINES['XPCOM_GLUE'] = True
+
+if CONFIG['TARGET_XPCOM_ABI']:
+    DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
deleted file mode 100644
--- a/xulrunner/setup/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/.
-
-DEFINES = -DBIN_SUFFIX=$(BIN_SUFFIX)
--- a/xulrunner/setup/moz.build
+++ b/xulrunner/setup/moz.build
@@ -12,8 +12,10 @@ XPIDL_MODULE = 'xulapp_setup'
 
 EXTRA_COMPONENTS += [
     'nsXULAppInstall.manifest',
 ]
 
 EXTRA_PP_COMPONENTS += [
     'nsXULAppInstall.js',
 ]
+
+DEFINES['BIN_SUFFIX'] = CONFIG['BIN_SUFFIX']
--- a/xulrunner/stub/Makefile.in
+++ b/xulrunner/stub/Makefile.in
@@ -7,17 +7,16 @@ USE_STATIC_LIBS = 1
 # Don't create a dependency on mozglue
 MOZ_GLUE_LDFLAGS =
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/xpcom/build \
   -I$(topsrcdir)/xpcom/base \
   $(NULL)
 
-DEFINES  += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
   $(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS) \
   $(NULL)
 
 # Need to link with CoreFoundation on Mac
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
--- a/xulrunner/stub/moz.build
+++ b/xulrunner/stub/moz.build
@@ -11,8 +11,10 @@
 PROGRAM = CONFIG['XULRUNNER_STUB_NAME']
 
 SOURCES += [
     'nsXULStub.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     FINAL_TARGET = 'dist/XUL.framework/Versions/%(MOZILLA_VERSION)s' % CONFIG
+
+DEFINES['XPCOM_GLUE'] = True
--- a/xulrunner/tools/redit/Makefile.in
+++ b/xulrunner/tools/redit/Makefile.in
@@ -3,22 +3,16 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ifeq ($(OS_ARCH),WINNT)
 
 SDK_BINARY =  \
 	$(PROGRAM) \
 	$(NULL)
 
-DEFINES += -DWIN32_LEAN_AND_MEAN \
-					 -DUNICODE \
-					 -D_UNICODE \
-					 -DXPCOM_GLUE \
-					 $(NULL)
-
 LIBS = \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(NULL)
 
 ifdef GNU_CC
 WIN32_EXE_LDFLAGS = -municode
 endif
 
--- a/xulrunner/tools/redit/moz.build
+++ b/xulrunner/tools/redit/moz.build
@@ -4,8 +4,10 @@
 # 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'
     SOURCES += [
         'redit.cpp',
     ]
+    for var in ('WIN32_LEAN_AND_MEAN', 'UNICODE', '_UNICODE', 'XPCOM_GLUE'):
+        DEFINES[var] = True