From 8fd06cf41b2023665c3be15bb19a4abf5837cec6 Mon Sep 17 00:00:00 2001
From: Mike Hommey <mh+mozilla@glandium.org>
Date: Wed, 27 Nov 2013 22:55:07 +0900
Subject: [PATCH] Bug 874266 - Move all DEFINES that can be moved to moz.build.
 r=mshal

---
 accessible/public/ia2/Makefile.in             |  2 -
 accessible/public/ia2/moz.build               |  2 +
 accessible/public/msaa/Makefile.in            |  2 -
 accessible/public/msaa/moz.build              |  2 +
 b2g/app/Makefile.in                           | 11 ----
 b2g/app/moz.build                             |  8 +++
 b2g/chrome/Makefile.in                        |  8 ---
 b2g/chrome/moz.build                          |  3 +
 b2g/gaia/Makefile.in                          | 12 ----
 b2g/gaia/moz.build                            |  4 ++
 browser/app/Makefile.in                       | 11 ----
 browser/app/moz.build                         | 11 ++++
 browser/base/Makefile.in                      | 31 ----------
 browser/base/moz.build                        | 13 +++++
 browser/branding/aurora/locales/Makefile.in   |  2 +-
 browser/branding/aurora/locales/moz.build     |  1 +
 browser/branding/nightly/locales/Makefile.in  |  2 +-
 browser/branding/nightly/locales/moz.build    |  1 +
 .../branding/unofficial/locales/Makefile.in   |  2 +-
 browser/branding/unofficial/locales/moz.build |  1 +
 browser/components/feeds/src/Makefile.in      |  6 --
 browser/components/feeds/src/moz.build        |  3 +
 browser/components/migration/src/Makefile.in  | 12 ----
 browser/components/migration/src/moz.build    |  3 +
 browser/components/preferences/Makefile.in    | 15 -----
 .../preferences/in-content/Makefile.in        | 14 -----
 .../preferences/in-content/moz.build          |  5 ++
 browser/components/preferences/moz.build      |  6 ++
 browser/components/shell/src/Makefile.in      |  3 -
 browser/components/shell/src/moz.build        |  3 +
 browser/metro/Makefile.in                     |  6 +-
 browser/metro/base/Makefile.in                | 10 ----
 browser/metro/base/moz.build                  |  4 ++
 browser/metro/moz.build                       |  5 ++
 .../shell/commandexecutehandler/Makefile.in   |  2 -
 .../shell/commandexecutehandler/moz.build     |  3 +
 browser/metro/shell/linktool/Makefile.in      |  2 -
 browser/metro/shell/linktool/moz.build        |  3 +
 browser/metro/shell/testing/Makefile.in       |  2 -
 browser/metro/shell/testing/moz.build         |  3 +
 browser/modules/Makefile.in                   |  9 ---
 browser/modules/moz.build                     |  2 +
 build/Makefile.in                             | 33 +----------
 build/mobile/robocop/Makefile.in              |  4 --
 build/mobile/robocop/moz.build                |  2 +
 build/moz.build                               | 16 ++++++
 build/stlport/Makefile.in                     |  1 -
 build/stlport/moz.build                       |  2 +
 build/unix/elfhack/Makefile.in                |  2 -
 build/unix/elfhack/inject/Makefile.in         |  2 -
 build/unix/elfhack/inject/moz.build           |  2 +
 build/unix/elfhack/moz.build                  |  2 +
 db/sqlite3/src/Makefile.in                    | 57 -------------------
 db/sqlite3/src/moz.build                      | 43 ++++++++++++++
 dom/base/Makefile.in                          | 12 ----
 dom/base/moz.build                            |  3 +
 dom/bluetooth/Makefile.in                     |  8 ---
 dom/bluetooth/moz.build                       |  3 +
 dom/ipc/Makefile.in                           | 14 -----
 dom/ipc/moz.build                             |  8 +++
 dom/plugins/ipc/hangui/Makefile.in            |  4 --
 dom/plugins/ipc/hangui/moz.build              |  1 +
 embedding/tests/winEmbed/Makefile.in          |  1 -
 embedding/tests/winEmbed/moz.build            |  2 +
 .../spellcheck/hunspell/src/Makefile.in       |  6 --
 extensions/spellcheck/hunspell/src/moz.build  |  3 +
 gfx/2d/Makefile.in                            | 30 ----------
 gfx/2d/moz.build                              | 22 +++++++
 gfx/angle/Makefile.in                         |  5 --
 gfx/angle/moz.build                           |  4 ++
 gfx/angle/src/libEGL/Makefile.in              | 10 ----
 gfx/angle/src/libEGL/moz.build                |  9 +++
 gfx/angle/src/libGLESv2/Makefile.in           | 11 ----
 gfx/angle/src/libGLESv2/moz.build             | 10 ++++
 gfx/cairo/cairo/src/Makefile.in               | 32 -----------
 gfx/cairo/cairo/src/moz.build                 | 21 +++++++
 gfx/cairo/libpixman/src/Makefile.in           | 10 ----
 gfx/cairo/libpixman/src/moz.build             | 10 ++++
 gfx/gl/Makefile.in                            | 10 ----
 gfx/gl/moz.build                              |  6 ++
 gfx/graphite2/src/Makefile.in                 | 23 --------
 gfx/graphite2/src/moz.build                   | 16 ++++++
 gfx/harfbuzz/src/Makefile.in                  |  4 --
 gfx/harfbuzz/src/moz.build                    |  6 ++
 gfx/layers/Makefile.in                        |  8 ---
 gfx/layers/moz.build                          |  6 ++
 gfx/ots/src/Makefile.in                       | 40 -------------
 gfx/ots/src/moz.build                         |  9 +++
 gfx/skia/Makefile.in                          | 20 -------
 gfx/skia/moz.build                            | 15 +++++
 gfx/thebes/Makefile.in                        | 28 ---------
 gfx/thebes/moz.build                          | 19 +++++++
 intl/locale/src/unix/Makefile.in              |  9 ---
 intl/locale/src/unix/moz.build                |  8 +++
 intl/unicharutil/util/Makefile.in             |  1 -
 intl/unicharutil/util/moz.build               |  3 +
 ipc/chromium/Makefile.in                      | 10 ----
 ipc/chromium/moz.build                        |  5 ++
 ipc/glue/Makefile.in                          |  3 -
 ipc/glue/moz.build                            |  3 +
 js/ipc/Makefile.in                            |  2 -
 js/ipc/moz.build                              |  2 +
 js/src/Makefile.in                            | 23 --------
 js/src/config/Makefile.in                     |  5 --
 js/src/config/moz.build                       |  4 ++
 js/src/editline/Makefile.in                   |  8 ---
 js/src/editline/moz.build                     |  4 ++
 js/src/gdb/Makefile.in                        |  4 --
 js/src/gdb/moz.build                          |  5 ++
 js/src/jsapi-tests/Makefile.in                |  5 --
 js/src/jsapi-tests/moz.build                  |  5 ++
 js/src/moz.build                              | 17 ++++++
 js/src/shell/Makefile.in                      |  5 --
 js/src/shell/moz.build                        |  5 ++
 js/xpconnect/loader/Makefile.in               |  6 --
 js/xpconnect/loader/moz.build                 |  2 +
 js/xpconnect/src/Makefile.in                  | 24 --------
 js/xpconnect/src/moz.build                    | 17 ++++++
 .../tests/components/native/Makefile.in       |  2 -
 .../tests/components/native/moz.build         |  6 ++
 layout/style/test/Makefile.in                 |  2 -
 layout/style/test/moz.build                   |  1 +
 layout/tables/Makefile.in                     |  2 -
 layout/tables/moz.build                       |  2 +
 media/libcubeb/src/Makefile.in                | 30 ----------
 media/libcubeb/src/moz.build                  | 14 ++++-
 media/libopus/Makefile.in                     | 23 --------
 media/libopus/moz.build                       | 23 ++++++++
 media/libsoundtouch/src/Makefile.in           |  3 -
 media/libsoundtouch/src/moz.build             |  3 +
 media/libspeex_resampler/src/Makefile.in      | 15 -----
 media/libspeex_resampler/src/moz.build        | 18 ++++++
 media/libtheora/lib/Makefile.in               | 22 -------
 media/libtheora/lib/moz.build                 | 15 +++++
 media/libtremor/lib/Makefile.in               |  8 ---
 media/libtremor/lib/moz.build                 |  6 ++
 media/libvpx/Makefile.in                      |  9 ---
 media/libvpx/moz.build                        |  7 +++
 media/mtransport/build/Makefile.in            | 46 ---------------
 media/mtransport/build/moz.build              | 25 ++++++++
 media/mtransport/standalone/Makefile.in       | 48 ----------------
 media/mtransport/standalone/moz.build         | 25 ++++++++
 media/mtransport/test/Makefile.in             | 34 -----------
 media/mtransport/test/moz.build               | 15 +++++
 media/webrtc/signaling/test/Makefile.in       | 16 ------
 media/webrtc/signaling/test/moz.build         |  6 ++
 memory/build/Makefile.in                      |  4 --
 memory/build/moz.build                        |  4 ++
 memory/jemalloc/Makefile.in                   |  9 ---
 memory/jemalloc/moz.build                     |  9 +++
 memory/mozalloc/Makefile.in                   |  5 --
 memory/mozalloc/moz.build                     |  4 ++
 memory/mozjemalloc/Makefile.in                | 14 -----
 memory/mozjemalloc/moz.build                  | 12 ++++
 memory/replace/dmd/Makefile.in                |  2 -
 memory/replace/dmd/moz.build                  |  2 +
 memory/replace/jemalloc/Makefile.in           |  1 -
 memory/replace/jemalloc/moz.build             |  3 +
 mfbt/tests/Makefile.in                        |  3 -
 mfbt/tests/moz.build                          |  3 +
 mobile/android/app/Makefile.in                | 12 ----
 mobile/android/app/moz.build                  | 10 ++++
 mobile/android/base/Makefile.in               | 37 ------------
 mobile/android/base/moz.build                 | 25 ++++++++
 mobile/android/chrome/Makefile.in             |  9 ---
 mobile/android/chrome/moz.build               |  4 ++
 mobile/android/components/Makefile.in         |  7 ---
 mobile/android/components/moz.build           |  1 +
 mobile/android/geckoview_library/Makefile.in  |  2 -
 mobile/android/geckoview_library/moz.build    |  2 +
 modules/libbz2/src/Makefile.in                |  6 --
 modules/libbz2/src/moz.build                  |  6 ++
 modules/libmar/tests/Makefile.in              |  2 -
 modules/libmar/tests/moz.build                |  2 +
 modules/libmar/tool/Makefile.in               | 11 ----
 modules/libmar/tool/moz.build                 |  6 ++
 modules/libmar/verify/Makefile.in             |  1 -
 modules/libmar/verify/moz.build               |  3 +
 modules/libpref/src/Makefile.in               |  4 --
 modules/libpref/src/moz.build                 |  3 +
 mozglue/android/Makefile.in                   |  7 ---
 mozglue/android/moz.build                     |  5 ++
 mozglue/build/Makefile.in                     |  2 -
 mozglue/build/moz.build                       |  2 +
 mozglue/linker/Makefile.in                    |  2 -
 mozglue/linker/moz.build                      |  2 +
 netwerk/protocol/rtsp/Makefile.in             |  2 +-
 netwerk/protocol/rtsp/moz.build               |  3 +
 netwerk/sctp/datachannel/Makefile.in          | 18 ------
 netwerk/sctp/datachannel/moz.build            | 11 ++++
 netwerk/sctp/src/Makefile.in                  | 38 -------------
 netwerk/sctp/src/moz.build                    | 25 ++++++++
 netwerk/srtp/src/Makefile.in                  | 43 --------------
 netwerk/srtp/src/moz.build                    | 24 ++++++++
 netwerk/streamconv/test/Makefile.in           |  6 --
 netwerk/streamconv/test/moz.build             |  3 +
 other-licenses/skia-npapi/Makefile.in         |  4 --
 other-licenses/skia-npapi/moz.build           |  2 +
 parser/expat/lib/Makefile.in                  |  7 ---
 parser/expat/lib/moz.build                    |  2 +
 parser/html/Makefile.in                       |  2 -
 parser/html/moz.build                         |  2 +
 .../dirserviceprovider/standalone/Makefile.in |  1 -
 .../dirserviceprovider/standalone/moz.build   |  2 +
 security/manager/ssl/src/Makefile.in          | 11 ----
 security/manager/ssl/src/moz.build            |  4 ++
 security/sandbox/Makefile.in                  |  2 -
 security/sandbox/moz.build                    |  3 +
 .../sandbox/win/src/sandboxbroker/Makefile.in |  2 -
 .../sandbox/win/src/sandboxbroker/moz.build   |  4 ++
 storage/src/Makefile.in                       | 23 --------
 storage/src/moz.build                         | 19 +++++++
 testing/marionette/Makefile.in                |  7 ---
 testing/marionette/components/Makefile.in     |  7 ---
 testing/marionette/components/moz.build       |  3 +
 testing/marionette/moz.build                  |  3 +
 .../components/maintenanceservice/Makefile.in |  6 --
 .../components/maintenanceservice/moz.build   |  7 +++
 toolkit/components/search/Makefile.in         |  5 --
 toolkit/components/search/moz.build           |  2 +
 toolkit/components/telemetry/Makefile.in      |  4 --
 toolkit/components/telemetry/moz.build        |  3 +
 toolkit/content/Makefile.in                   | 15 -----
 toolkit/content/moz.build                     | 10 ++++
 toolkit/crashreporter/Makefile.in             | 15 -----
 .../breakpad-windows-libxul/Makefile.in       |  2 -
 .../breakpad-windows-libxul/moz.build         |  3 +
 .../breakpad-windows-standalone/Makefile.in   |  2 -
 .../breakpad-windows-standalone/moz.build     |  3 +
 toolkit/crashreporter/client/Makefile.in      |  1 -
 toolkit/crashreporter/client/moz.build        |  2 +
 .../src/client/linux/handler/Makefile.in      |  1 -
 .../src/client/linux/handler/moz.build        |  5 ++
 .../client/linux/minidump_writer/Makefile.in  |  4 --
 .../client/linux/minidump_writer/moz.build    |  3 +
 .../google-breakpad/src/common/Makefile.in    |  5 --
 .../src/common/linux/Makefile.in              |  6 --
 .../src/common/linux/moz.build                |  5 ++
 .../google-breakpad/src/common/moz.build      |  6 ++
 toolkit/crashreporter/moz.build               | 13 +++++
 toolkit/crashreporter/test/Makefile.in        |  2 -
 toolkit/crashreporter/test/moz.build          |  8 +++
 toolkit/modules/Makefile.in                   | 12 ----
 toolkit/modules/moz.build                     |  5 ++
 toolkit/mozapps/extensions/Makefile.in        | 14 +----
 toolkit/mozapps/extensions/moz.build          | 10 ++++
 toolkit/mozapps/update/tests/Makefile.in      | 13 -----
 toolkit/mozapps/update/tests/moz.build        | 15 +++++
 toolkit/mozapps/update/updater/Makefile.in    |  6 --
 toolkit/mozapps/update/updater/moz.build      |  6 ++
 toolkit/webapps/Makefile.in                   |  7 ---
 toolkit/webapps/moz.build                     |  2 +
 toolkit/xre/Makefile.in                       | 54 +-----------------
 toolkit/xre/moz.build                         | 37 ++++++++++++
 toolkit/xre/test/win/Makefile.in              |  2 -
 toolkit/xre/test/win/moz.build                |  2 +
 tools/jprof/stub/Makefile.in                  |  4 --
 tools/jprof/stub/moz.build                    |  2 +
 tools/trace-malloc/lib/Makefile.in            |  6 --
 tools/trace-malloc/lib/moz.build              |  5 ++
 webapprt/Makefile.in                          | 13 +----
 webapprt/gtk2/Makefile.in                     |  1 -
 webapprt/gtk2/moz.build                       |  1 +
 webapprt/mac/Makefile.in                      |  1 -
 webapprt/mac/moz.build                        |  1 +
 webapprt/moz.build                            |  9 +++
 webapprt/win/Makefile.in                      |  1 -
 webapprt/win/moz.build                        |  2 +
 widget/android/Makefile.in                    |  2 -
 widget/android/moz.build                      |  2 +
 widget/gonk/Makefile.in                       |  6 --
 widget/gonk/libdisplay/Makefile.in            |  2 -
 widget/gonk/libdisplay/moz.build              |  2 +
 widget/gonk/moz.build                         |  6 ++
 widget/gtk/Makefile.in                        |  2 -
 widget/gtk/moz.build                          |  4 ++
 widget/gtkxtbin/Makefile.in                   |  2 -
 widget/gtkxtbin/moz.build                     |  2 +
 widget/os2/Makefile.in                        |  4 --
 widget/os2/moz.build                          |  4 ++
 widget/qt/Makefile.in                         | 16 ------
 widget/qt/faststartupqt/Makefile.in           |  2 -
 widget/qt/faststartupqt/moz.build             |  9 +++
 widget/qt/moz.build                           | 13 +++++
 widget/windows/Makefile.in                    |  9 ---
 widget/windows/moz.build                      |  6 ++
 widget/windows/winrt/Makefile.in              | 10 ----
 widget/windows/winrt/moz.build                |  6 ++
 widget/xpwidgets/Makefile.in                  |  4 --
 widget/xpwidgets/moz.build                    |  3 +
 widget/xremoteclient/Makefile.in              |  2 -
 widget/xremoteclient/moz.build                |  2 +
 xpcom/build/Makefile.in                       |  9 ---
 xpcom/build/moz.build                         |  6 ++
 xpcom/glue/Makefile.in                        |  5 --
 xpcom/glue/moz.build                          |  6 ++
 xpcom/glue/nomozalloc/Makefile.in             |  7 ---
 xpcom/glue/nomozalloc/moz.build               |  8 +++
 xpcom/glue/standalone/Makefile.in             |  7 ---
 xpcom/glue/standalone/moz.build               |  8 +++
 .../glue/standalone/staticruntime/Makefile.in |  7 ---
 xpcom/glue/standalone/staticruntime/moz.build |  8 +++
 xpcom/glue/staticruntime/Makefile.in          |  5 --
 xpcom/glue/staticruntime/moz.build            |  6 ++
 xpcom/io/Makefile.in                          |  6 --
 xpcom/io/moz.build                            |  3 +
 xpcom/reflect/xptcall/src/md/os2/Makefile.in  |  2 -
 xpcom/reflect/xptcall/src/md/os2/moz.build    |  2 +
 xpcom/reflect/xptcall/src/md/unix/Makefile.in | 16 ------
 xpcom/reflect/xptcall/src/md/unix/moz.build   |  2 +
 xpcom/sample/program/Makefile.in              |  4 --
 xpcom/sample/program/moz.build                |  4 ++
 xpcom/tests/bug656331_component/Makefile.in   |  2 -
 xpcom/tests/bug656331_component/moz.build     |  6 ++
 xpcom/tests/component/Makefile.in             |  2 -
 xpcom/tests/component/moz.build               |  6 ++
 xpcom/tests/component_no_aslr/Makefile.in     |  2 -
 xpcom/tests/component_no_aslr/moz.build       |  6 ++
 xulrunner/app/Makefile.in                     |  7 ---
 xulrunner/app/moz.build                       |  6 ++
 xulrunner/setup/Makefile.in                   |  5 --
 xulrunner/setup/moz.build                     |  2 +
 xulrunner/stub/Makefile.in                    |  1 -
 xulrunner/stub/moz.build                      |  2 +
 xulrunner/tools/redit/Makefile.in             |  6 --
 xulrunner/tools/redit/moz.build               |  2 +
 326 files changed, 1106 insertions(+), 1566 deletions(-)
 delete mode 100644 b2g/chrome/Makefile.in
 delete mode 100644 browser/base/Makefile.in
 delete mode 100644 browser/components/migration/src/Makefile.in
 delete mode 100644 browser/components/preferences/Makefile.in
 delete mode 100644 browser/components/preferences/in-content/Makefile.in
 delete mode 100644 browser/metro/base/Makefile.in
 delete mode 100644 browser/modules/Makefile.in
 delete mode 100644 gfx/ots/src/Makefile.in
 delete mode 100644 js/src/editline/Makefile.in
 delete mode 100644 media/mtransport/build/Makefile.in
 delete mode 100644 media/mtransport/standalone/Makefile.in
 delete mode 100644 mobile/android/chrome/Makefile.in
 delete mode 100644 mobile/android/components/Makefile.in
 delete mode 100644 parser/expat/lib/Makefile.in
 delete mode 100644 security/manager/ssl/src/Makefile.in
 delete mode 100644 testing/marionette/Makefile.in
 delete mode 100644 testing/marionette/components/Makefile.in
 delete mode 100644 toolkit/components/search/Makefile.in
 delete mode 100644 toolkit/modules/Makefile.in
 delete mode 100644 toolkit/webapps/Makefile.in
 delete mode 100644 xulrunner/setup/Makefile.in

diff --git a/accessible/public/ia2/Makefile.in b/accessible/public/ia2/Makefile.in
index b00410aa64dcf..2aa0cc1d12d58 100644
--- a/accessible/public/ia2/Makefile.in
+++ b/accessible/public/ia2/Makefile.in
@@ -6,8 +6,6 @@ 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
diff --git a/accessible/public/ia2/moz.build b/accessible/public/ia2/moz.build
index be2265e8d1a21..d715a08b23e7d 100644
--- a/accessible/public/ia2/moz.build
+++ b/accessible/public/ia2/moz.build
@@ -7,3 +7,5 @@
 LIBRARY_NAME = 'IA2Marshal'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['REGISTER_PROXY_DLL'] = True
diff --git a/accessible/public/msaa/Makefile.in b/accessible/public/msaa/Makefile.in
index fed4aaf8c5225..b27fa0a385717 100644
--- a/accessible/public/msaa/Makefile.in
+++ b/accessible/public/msaa/Makefile.in
@@ -4,8 +4,6 @@
 
 DEFFILE = $(win_srcdir)/AccessibleMarshal.def
 
-DEFINES += -DREGISTER_PROXY_DLL
-
 GARBAGE += $(MIDL_GENERATED_FILES) done_gen dlldata.c
 
 MIDL_GENERATED_FILES = \
diff --git a/accessible/public/msaa/moz.build b/accessible/public/msaa/moz.build
index 6321c5d31d520..40c26ff79a603 100644
--- a/accessible/public/msaa/moz.build
+++ b/accessible/public/msaa/moz.build
@@ -17,3 +17,5 @@ GENERATED_SOURCES += [
 ]
 
 FORCE_SHARED_LIB = True
+
+DEFINES['REGISTER_PROXY_DLL'] = True
diff --git a/b2g/app/Makefile.in b/b2g/app/Makefile.in
index e67a17f30c98b..40fdebae4c96e 100644
--- a/b2g/app/Makefile.in
+++ b/b2g/app/Makefile.in
@@ -7,10 +7,6 @@ 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))
@@ -39,7 +35,6 @@ 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)
@@ -83,12 +78,6 @@ 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)"
diff --git a/b2g/app/moz.build b/b2g/app/moz.build
index f8966c2fdd2df..cd85ac98523ee 100644
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -12,3 +12,11 @@ if not CONFIG['LIBXUL_SDK']:
     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]
diff --git a/b2g/chrome/Makefile.in b/b2g/chrome/Makefile.in
deleted file mode 100644
index 382dc360ce945..0000000000000
--- 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)
diff --git a/b2g/chrome/moz.build b/b2g/chrome/moz.build
index 895d11993cfbb..27be5477130b4 100644
--- a/b2g/chrome/moz.build
+++ b/b2g/chrome/moz.build
@@ -4,3 +4,6 @@
 # License, v. 2.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']
diff --git a/b2g/gaia/Makefile.in b/b2g/gaia/Makefile.in
index 47e4713ad1b7d..368e83e66d71d 100644
--- a/b2g/gaia/Makefile.in
+++ b/b2g/gaia/Makefile.in
@@ -4,18 +4,6 @@
 
 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)
diff --git a/b2g/gaia/moz.build b/b2g/gaia/moz.build
index 6713659202d2e..282c716c25f22 100644
--- a/b2g/gaia/moz.build
+++ b/b2g/gaia/moz.build
@@ -10,7 +10,11 @@ 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"'
diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in
index bf74c1e9dc012..03086d51a023e 100644
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -4,10 +4,6 @@
 
 dist_dest   = $(DIST)/$(MOZ_MACBUNDLE_NAME)
 
-ifdef ENABLE_MARIONETTE
-DEFINES += -DENABLE_MARIONETTE=1
-endif
-
 PREF_JS_EXPORTS = $(srcdir)/profile/firefox.js \
 		  $(NULL)
 
@@ -17,7 +13,6 @@ 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\" \
@@ -25,13 +20,8 @@ DEFINES += \
   -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
@@ -43,7 +33,6 @@ LOCAL_INCLUDES += \
   -I$(DEPTH)/build \
   $(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += \
diff --git a/browser/app/moz.build b/browser/app/moz.build
index 45412588115bc..d76996f73d4f4 100644
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -11,3 +11,14 @@ 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
diff --git a/browser/base/Makefile.in b/browser/base/Makefile.in
deleted file mode 100644
index 160b1a60c4569..0000000000000
--- 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
diff --git a/browser/base/moz.build b/browser/base/moz.build
index b945757d4d37e..cb1a787f1996e 100644
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -21,3 +21,16 @@ BROWSER_CHROME_MANIFESTS += [
     '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
diff --git a/browser/branding/aurora/locales/Makefile.in b/browser/branding/aurora/locales/Makefile.in
index 778f74dd0f159..82f614ecea292 100644
--- a/browser/branding/aurora/locales/Makefile.in
+++ b/browser/branding/aurora/locales/Makefile.in
@@ -2,4 +2,4 @@
 # License, v. 2.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)
diff --git a/browser/branding/aurora/locales/moz.build b/browser/branding/aurora/locales/moz.build
index 895d11993cfbb..062fc309ba370 100644
--- a/browser/branding/aurora/locales/moz.build
+++ b/browser/branding/aurora/locales/moz.build
@@ -4,3 +4,4 @@
 # License, v. 2.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']
diff --git a/browser/branding/nightly/locales/Makefile.in b/browser/branding/nightly/locales/Makefile.in
index 778f74dd0f159..82f614ecea292 100644
--- a/browser/branding/nightly/locales/Makefile.in
+++ b/browser/branding/nightly/locales/Makefile.in
@@ -2,4 +2,4 @@
 # License, v. 2.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)
diff --git a/browser/branding/nightly/locales/moz.build b/browser/branding/nightly/locales/moz.build
index 895d11993cfbb..062fc309ba370 100644
--- a/browser/branding/nightly/locales/moz.build
+++ b/browser/branding/nightly/locales/moz.build
@@ -4,3 +4,4 @@
 # License, v. 2.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']
diff --git a/browser/branding/unofficial/locales/Makefile.in b/browser/branding/unofficial/locales/Makefile.in
index 778f74dd0f159..82f614ecea292 100644
--- a/browser/branding/unofficial/locales/Makefile.in
+++ b/browser/branding/unofficial/locales/Makefile.in
@@ -2,4 +2,4 @@
 # License, v. 2.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)
diff --git a/browser/branding/unofficial/locales/moz.build b/browser/branding/unofficial/locales/moz.build
index 895d11993cfbb..062fc309ba370 100644
--- a/browser/branding/unofficial/locales/moz.build
+++ b/browser/branding/unofficial/locales/moz.build
@@ -4,3 +4,4 @@
 # License, v. 2.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']
diff --git a/browser/components/feeds/src/Makefile.in b/browser/components/feeds/src/Makefile.in
index c92d8b0ec58da..c82bbbac0f03d 100644
--- a/browser/components/feeds/src/Makefile.in
+++ b/browser/components/feeds/src/Makefile.in
@@ -2,10 +2,4 @@
 # License, v. 2.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
diff --git a/browser/components/feeds/src/moz.build b/browser/components/feeds/src/moz.build
index 777f012ceea19..03cd8b9440782 100644
--- a/browser/components/feeds/src/moz.build
+++ b/browser/components/feeds/src/moz.build
@@ -19,3 +19,6 @@ EXTRA_PP_COMPONENTS += [
 ]
 
 FINAL_LIBRARY = 'browsercomps'
+
+for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'):
+    DEFINES[var] = CONFIG[var]
diff --git a/browser/components/migration/src/Makefile.in b/browser/components/migration/src/Makefile.in
deleted file mode 100644
index a15fafea2c947..0000000000000
--- 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
diff --git a/browser/components/migration/src/moz.build b/browser/components/migration/src/moz.build
index bf0a8cc53f63e..43d08fe9e2501 100644
--- a/browser/components/migration/src/moz.build
+++ b/browser/components/migration/src/moz.build
@@ -18,6 +18,7 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     EXTRA_COMPONENTS += [
         'IEProfileMigrator.js',
     ]
+    DEFINES['HAS_IE_MIGRATOR'] = True
 
 EXTRA_PP_COMPONENTS += [
     'BrowserProfileMigrators.manifest',
@@ -28,11 +29,13 @@ 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',
diff --git a/browser/components/preferences/Makefile.in b/browser/components/preferences/Makefile.in
deleted file mode 100644
index 8bc21d8d48631..0000000000000
--- 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
diff --git a/browser/components/preferences/in-content/Makefile.in b/browser/components/preferences/in-content/Makefile.in
deleted file mode 100644
index 9a8d9616efbf4..0000000000000
--- 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
diff --git a/browser/components/preferences/in-content/moz.build b/browser/components/preferences/in-content/moz.build
index 895d11993cfbb..e6bdbaf44a726 100644
--- a/browser/components/preferences/in-content/moz.build
+++ b/browser/components/preferences/in-content/moz.build
@@ -4,3 +4,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/.
 
+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
diff --git a/browser/components/preferences/moz.build b/browser/components/preferences/moz.build
index b11ffebf15f99..e35d8f9bb25f1 100644
--- a/browser/components/preferences/moz.build
+++ b/browser/components/preferences/moz.build
@@ -10,3 +10,9 @@ 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
diff --git a/browser/components/shell/src/Makefile.in b/browser/components/shell/src/Makefile.in
index 4425699c95ab6..df084b709de0a 100644
--- a/browser/components/shell/src/Makefile.in
+++ b/browser/components/shell/src/Makefile.in
@@ -5,9 +5,6 @@
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\" \
-  -DMOZ_APP_VERSION=\"$(MOZ_APP_VERSION)\"
-
 CXXFLAGS += $(TK_CFLAGS)
 
 clobber::
diff --git a/browser/components/shell/src/moz.build b/browser/components/shell/src/moz.build
index d426904cc24d8..61ed38f5e4410 100644
--- a/browser/components/shell/src/moz.build
+++ b/browser/components/shell/src/moz.build
@@ -24,3 +24,6 @@ EXTRA_COMPONENTS += [
     'nsSetDefaultBrowser.js',
     'nsSetDefaultBrowser.manifest',
 ]
+
+for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
diff --git a/browser/metro/Makefile.in b/browser/metro/Makefile.in
index 4aaeac6862d1d..3ce51911d3b57 100644
--- a/browser/metro/Makefile.in
+++ b/browser/metro/Makefile.in
@@ -7,12 +7,8 @@ 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
diff --git a/browser/metro/base/Makefile.in b/browser/metro/base/Makefile.in
deleted file mode 100644
index baebac1ccb8fa..0000000000000
--- 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)
diff --git a/browser/metro/base/moz.build b/browser/metro/base/moz.build
index cad3b48d9a9e4..1bba6b849a992 100644
--- a/browser/metro/base/moz.build
+++ b/browser/metro/base/moz.build
@@ -8,3 +8,7 @@ METRO_CHROME_MANIFESTS += ['tests/mochiperf/metro.ini', 'tests/mochitest/metro.i
 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']
diff --git a/browser/metro/moz.build b/browser/metro/moz.build
index a9000ff375aaa..d3eee1797cae3 100644
--- a/browser/metro/moz.build
+++ b/browser/metro/moz.build
@@ -17,3 +17,8 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     DIRS += ['shell']
 
 DIST_SUBDIR = 'metro'
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
+
+DEFINES['GRE_MILESTONE'] = CONFIG['GRE_MILESTONE']
diff --git a/browser/metro/shell/commandexecutehandler/Makefile.in b/browser/metro/shell/commandexecutehandler/Makefile.in
index 7a040be9c963c..2f8e55fbe4a2b 100644
--- a/browser/metro/shell/commandexecutehandler/Makefile.in
+++ b/browser/metro/shell/commandexecutehandler/Makefile.in
@@ -21,5 +21,3 @@ OS_LIBS = \
 	advapi32.lib \
 	wininet.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE -DNS_NO_XPCOM
diff --git a/browser/metro/shell/commandexecutehandler/moz.build b/browser/metro/shell/commandexecutehandler/moz.build
index 6af0a3fa0d3fe..89a07cf1bcba3 100644
--- a/browser/metro/shell/commandexecutehandler/moz.build
+++ b/browser/metro/shell/commandexecutehandler/moz.build
@@ -13,3 +13,6 @@ SOURCES += [
 
 # We want this exe in dist/bin
 DIST_SUBDIR = ''
+
+for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM'):
+    DEFINES[var] = True
diff --git a/browser/metro/shell/linktool/Makefile.in b/browser/metro/shell/linktool/Makefile.in
index 1160f3eff2140..786ce3c83c72a 100644
--- a/browser/metro/shell/linktool/Makefile.in
+++ b/browser/metro/shell/linktool/Makefile.in
@@ -14,5 +14,3 @@ OS_LIBS = \
 	shell32.lib \
 	propsys.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE
diff --git a/browser/metro/shell/linktool/moz.build b/browser/metro/shell/linktool/moz.build
index 596ac046a0cfa..7d93db9dc8568 100644
--- a/browser/metro/shell/linktool/moz.build
+++ b/browser/metro/shell/linktool/moz.build
@@ -11,3 +11,6 @@ SOURCES += [
 ]
 
 DIST_SUBDIR = 'metro/install'
+
+for var in ('UNICODE', '_UNICODE'):
+    DEFINES[var] = True
diff --git a/browser/metro/shell/testing/Makefile.in b/browser/metro/shell/testing/Makefile.in
index bfbb75abafc7f..230a7912fa813 100644
--- a/browser/metro/shell/testing/Makefile.in
+++ b/browser/metro/shell/testing/Makefile.in
@@ -21,5 +21,3 @@ OS_LIBS = \
 	propsys.lib \
 	advapi32.lib \
 	$(NULL)
-
-DEFINES += -DUNICODE -D_UNICODE
diff --git a/browser/metro/shell/testing/moz.build b/browser/metro/shell/testing/moz.build
index 53cf7fa15610b..fb7c08870f11f 100644
--- a/browser/metro/shell/testing/moz.build
+++ b/browser/metro/shell/testing/moz.build
@@ -12,3 +12,6 @@ SOURCES += [
 
 # We want this exe in dist/bin
 DIST_SUBDIR = ''
+
+for var in ('UNICODE', '_UNICODE'):
+    DEFINES[var] = True
diff --git a/browser/modules/Makefile.in b/browser/modules/Makefile.in
deleted file mode 100644
index 02871c0e72870..0000000000000
--- 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
diff --git a/browser/modules/moz.build b/browser/modules/moz.build
index 297fa9a082bed..0ee0c2191ee0b 100644
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -34,3 +34,5 @@ EXTRA_PP_JS_MODULES += [
     'RecentWindow.jsm',
 ]
 
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = 1
diff --git a/build/Makefile.in b/build/Makefile.in
index 348f1f67e07f2..15b9773b8dc82 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -24,9 +24,8 @@ 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))
@@ -39,34 +38,6 @@ 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
@@ -123,8 +94,6 @@ 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
diff --git a/build/mobile/robocop/Makefile.in b/build/mobile/robocop/Makefile.in
index 9637882795c6d..f405607ec66c2 100644
--- a/build/mobile/robocop/Makefile.in
+++ b/build/mobile/robocop/Makefile.in
@@ -75,10 +75,6 @@ JAVAFILES += \
   $(testconstants-dep) \
   $(NULL)
 
-DEFINES += \
-  -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
-  $(NULL)
-
 include $(topsrcdir)/config/rules.mk
 
 tools:: $(ANDROID_APK_NAME).apk
diff --git a/build/mobile/robocop/moz.build b/build/mobile/robocop/moz.build
index c9ab6ecd17d5a..df3ab1e557d2c 100644
--- a/build/mobile/robocop/moz.build
+++ b/build/mobile/robocop/moz.build
@@ -7,3 +7,5 @@
 ANDROID_RESFILES = [
     'res/values/strings.xml',
 ]
+
+DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
diff --git a/build/moz.build b/build/moz.build
index 6b9c35ad5ddfc..d76748b881d72 100644
--- a/build/moz.build
+++ b/build/moz.build
@@ -22,3 +22,19 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
         '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
+
diff --git a/build/stlport/Makefile.in b/build/stlport/Makefile.in
index cca81f61da3ce..e105f0af6835e 100644
--- a/build/stlport/Makefile.in
+++ b/build/stlport/Makefile.in
@@ -11,6 +11,5 @@ LIBRARY = $(LIB_PREFIX)$(LIBRARY_NAME).$(LIB_SUFFIX)
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -D_GNU_SOURCE
 CXXFLAGS += -fuse-cxa-atexit
 INCLUDES += -I$(srcdir)/stlport
diff --git a/build/stlport/moz.build b/build/stlport/moz.build
index 77277e67949aa..78c12f00bcbfc 100644
--- a/build/stlport/moz.build
+++ b/build/stlport/moz.build
@@ -45,3 +45,5 @@ SOURCES += [
     'src/c_locale.c',
     'src/cxa.c',
 ]
+
+DEFINES['_GNU_SOURCE'] = True
diff --git a/build/unix/elfhack/Makefile.in b/build/unix/elfhack/Makefile.in
index 1421c4e80047d..44bea9317f53b 100644
--- a/build/unix/elfhack/Makefile.in
+++ b/build/unix/elfhack/Makefile.in
@@ -15,8 +15,6 @@ 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 ===
diff --git a/build/unix/elfhack/inject/Makefile.in b/build/unix/elfhack/inject/Makefile.in
index ac0017104c9ad..79831fcc411bb 100644
--- a/build/unix/elfhack/inject/Makefile.in
+++ b/build/unix/elfhack/inject/Makefile.in
@@ -15,6 +15,4 @@ $(CSRCS): %.c: ../inject.c
 
 GARBAGE += $(CSRCS)
 
-DEFINES += -DELFHACK_BUILD
-
 CFLAGS := -O2 -fno-stack-protector $(filter -m% -I%,$(CFLAGS))
diff --git a/build/unix/elfhack/inject/moz.build b/build/unix/elfhack/inject/moz.build
index f7d0df5e8edf7..b560c8f69b9bc 100644
--- a/build/unix/elfhack/inject/moz.build
+++ b/build/unix/elfhack/inject/moz.build
@@ -16,3 +16,5 @@ else:
 GENERATED_SOURCES += [
     "%s.c" % cpu,
 ]
+
+DEFINES['ELFHACK_BUILD'] = True
diff --git a/build/unix/elfhack/moz.build b/build/unix/elfhack/moz.build
index ca759aa8a7a7a..4a96904f22876 100644
--- a/build/unix/elfhack/moz.build
+++ b/build/unix/elfhack/moz.build
@@ -23,3 +23,5 @@ HOST_SOURCES += [
 ]
 
 HOST_PROGRAM = 'elfhack'
+
+DEFINES['ELFHACK_BUILD'] = True
diff --git a/db/sqlite3/src/Makefile.in b/db/sqlite3/src/Makefile.in
index b7ee80f20808a..54b0ced3de671 100644
--- a/db/sqlite3/src/Makefile.in
+++ b/db/sqlite3/src/Makefile.in
@@ -46,68 +46,11 @@ 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
diff --git a/db/sqlite3/src/moz.build b/db/sqlite3/src/moz.build
index ca936206f56f7..962ce496be065 100644
--- a/db/sqlite3/src/moz.build
+++ b/db/sqlite3/src/moz.build
@@ -19,3 +19,46 @@ 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
diff --git a/dom/base/Makefile.in b/dom/base/Makefile.in
index 1aabfd5785bf4..7f0c43fe736ac 100644
--- a/dom/base/Makefile.in
+++ b/dom/base/Makefile.in
@@ -2,18 +2,6 @@
 # License, v. 2.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
diff --git a/dom/base/moz.build b/dom/base/moz.build
index 3796ceaecf1ca..6f5bdaef6e4d3 100644
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -164,3 +164,6 @@ LOCAL_INCLUDES += [
     '/xpcom/ds',
 ]
 
+for var in ('MOZ_JSDEBUGGER', 'MOZ_B2G_RIL', 'MOZ_B2G_FM'):
+    if CONFIG[var]:
+        DEFINES[var] = True
diff --git a/dom/bluetooth/Makefile.in b/dom/bluetooth/Makefile.in
index 1646ade62d72f..876ef12e0515a 100644
--- a/dom/bluetooth/Makefile.in
+++ b/dom/bluetooth/Makefile.in
@@ -19,18 +19,12 @@ 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
 
@@ -39,5 +33,3 @@ endif #MOZ_WIDGET_TOOLKIT
 LOCAL_INCLUDES += $(VPATH:%=-I%)
 
 endif #MOZ_B2G_BT
-
-include $(topsrcdir)/config/rules.mk
diff --git a/dom/bluetooth/moz.build b/dom/bluetooth/moz.build
index 4b4451ca93694..8a36a593d3532 100644
--- a/dom/bluetooth/moz.build
+++ b/dom/bluetooth/moz.build
@@ -45,6 +45,7 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluez/gonk',
                 'bluez/linux',
             ]
+            DEFINES['MOZ_B2G_BT_BLUEZ'] = True
         elif CONFIG['MOZ_B2G_BT_BLUEDROID']:
             SOURCES += [
                 'bluedroid/BluetoothA2dpManager.cpp',
@@ -55,6 +56,7 @@ if CONFIG['MOZ_B2G_BT']:
                 'bluedroid',
                 'bluedroid/gonk',
             ]
+            DEFINES['MOZ_B2G_BT_BLUEDROID'] = True
     elif CONFIG['MOZ_ENABLE_DBUS']:
         SOURCES += [
             'bluez/BluetoothHfpManager.cpp',
@@ -64,6 +66,7 @@ if CONFIG['MOZ_B2G_BT']:
             'bluez',
             'bluez/linux',
         ]
+        DEFINES['MOZ_BLUETOOTH_DBUS'] = True
 
     FINAL_LIBRARY = 'gklayout'
 
diff --git a/dom/ipc/Makefile.in b/dom/ipc/Makefile.in
index dfef49a48eb36..c97efbc03e9ec 100644
--- a/dom/ipc/Makefile.in
+++ b/dom/ipc/Makefile.in
@@ -4,18 +4,4 @@
 
 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)
diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build
index 9a1c353aeeb54..e1b4c5429d064 100644
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -108,3 +108,11 @@ LOCAL_INCLUDES += [
     '/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
diff --git a/dom/plugins/ipc/hangui/Makefile.in b/dom/plugins/ipc/hangui/Makefile.in
index d8abe21ad8e34..101c8a710db40 100644
--- a/dom/plugins/ipc/hangui/Makefile.in
+++ b/dom/plugins/ipc/hangui/Makefile.in
@@ -6,10 +6,6 @@ OS_LIBS = $(call EXPAND_LIBNAME,comctl32)
 
 RCINCLUDE = HangUIDlg.rc
 
-DEFINES += \
-  -DNS_NO_XPCOM \
-  $(NULL)
-
 STL_FLAGS = \
   -D_HAS_EXCEPTIONS=0 \
   $(NULL)
diff --git a/dom/plugins/ipc/hangui/moz.build b/dom/plugins/ipc/hangui/moz.build
index 1fb693c8cb8e6..8197adf59dfe5 100644
--- a/dom/plugins/ipc/hangui/moz.build
+++ b/dom/plugins/ipc/hangui/moz.build
@@ -14,3 +14,4 @@ UNIFIED_SOURCES += [
 ]
 include('/ipc/chromium/chromium-config.mozbuild')
 
+DEFINES['NS_NO_XPCOM'] = True
diff --git a/embedding/tests/winEmbed/Makefile.in b/embedding/tests/winEmbed/Makefile.in
index f1038d5c48111..65e17169c504f 100644
--- a/embedding/tests/winEmbed/Makefile.in
+++ b/embedding/tests/winEmbed/Makefile.in
@@ -34,7 +34,6 @@ LIBS = \
 	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
 	$(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 OS_LIBS		+= $(call EXPAND_LIBNAME,ole32 comdlg32 shell32 version)
diff --git a/embedding/tests/winEmbed/moz.build b/embedding/tests/winEmbed/moz.build
index 25cc4ba25a5a9..28d8d175996c5 100644
--- a/embedding/tests/winEmbed/moz.build
+++ b/embedding/tests/winEmbed/moz.build
@@ -13,3 +13,5 @@ SOURCES += [
 ]
 
 XPI_NAME = 'winembed'
+
+DEFINES['XPCOM_GLUE'] = True
diff --git a/extensions/spellcheck/hunspell/src/Makefile.in b/extensions/spellcheck/hunspell/src/Makefile.in
index 36003d8e03b40..dcdcc97adab83 100644
--- a/extensions/spellcheck/hunspell/src/Makefile.in
+++ b/extensions/spellcheck/hunspell/src/Makefile.in
@@ -2,12 +2,6 @@
 # License, v. 2.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
diff --git a/extensions/spellcheck/hunspell/src/moz.build b/extensions/spellcheck/hunspell/src/moz.build
index c052431203c66..b8be90549401b 100644
--- a/extensions/spellcheck/hunspell/src/moz.build
+++ b/extensions/spellcheck/hunspell/src/moz.build
@@ -23,5 +23,8 @@ if not CONFIG['MOZ_NATIVE_HUNSPELL']:
         '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'
diff --git a/gfx/2d/Makefile.in b/gfx/2d/Makefile.in
index b0741152c8b56..ef690caab4749 100644
--- a/gfx/2d/Makefile.in
+++ b/gfx/2d/Makefile.in
@@ -5,40 +5,10 @@
 
 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
diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build
index cc822dd193ebb..ecf71a92e18be 100644
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -51,6 +51,9 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
         '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',
@@ -58,10 +61,13 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
             '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 += [
@@ -83,6 +89,7 @@ if CONFIG['INTEL_ARCHITECTURE']:
             'FilterProcessingSSE2.cpp',
             'ImageScalingSSE2.cpp',
         ]
+        DEFINES['USE_SSE2'] = True
 
 UNIFIED_SOURCES += [
     'Blur.cpp',
@@ -122,3 +129,18 @@ 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
diff --git a/gfx/angle/Makefile.in b/gfx/angle/Makefile.in
index 76cfb92a09f67..220f27d7e7d91 100644
--- a/gfx/angle/Makefile.in
+++ b/gfx/angle/Makefile.in
@@ -3,9 +3,6 @@
 # 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
@@ -17,8 +14,6 @@ LOCAL_INCLUDES += \
   -I$(srcdir)/include/KHR \
   -I$(srcdir)/src
 
-DEFINES += -DCOMPILER_IMPLEMENTATION
-
 VPATH += $(srcdir)/src/compiler
 VPATH += $(srcdir)/src/compiler/depgraph
 VPATH += $(srcdir)/src/compiler/timing
diff --git a/gfx/angle/moz.build b/gfx/angle/moz.build
index 5f9419f0a50e0..d88b96a296d72 100644
--- a/gfx/angle/moz.build
+++ b/gfx/angle/moz.build
@@ -123,3 +123,7 @@ if CONFIG['OS_TARGET'] == 'WINNT':
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+DEFINES['ANGLE_DISABLE_TRACE'] = True
+DEFINES['ANGLE_COMPILE_OPTIMIZATION_LEVEL'] = 'D3DCOMPILE_OPTIMIZATION_LEVEL1'
+DEFINES['COMPILER_IMPLEMENTATION'] = True
diff --git a/gfx/angle/src/libEGL/Makefile.in b/gfx/angle/src/libEGL/Makefile.in
index d9967c25bd2d7..6890bca08c4b6 100644
--- a/gfx/angle/src/libEGL/Makefile.in
+++ b/gfx/angle/src/libEGL/Makefile.in
@@ -16,17 +16,7 @@ endif
 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 = \
diff --git a/gfx/angle/src/libEGL/moz.build b/gfx/angle/src/libEGL/moz.build
index b795ed41d937e..f5a380fd2f8bf 100644
--- a/gfx/angle/src/libEGL/moz.build
+++ b/gfx/angle/src/libEGL/moz.build
@@ -25,3 +25,12 @@ SOURCES += [
 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'
diff --git a/gfx/angle/src/libGLESv2/Makefile.in b/gfx/angle/src/libGLESv2/Makefile.in
index 1115d7296698f..fc0e98e5e3c33 100644
--- a/gfx/angle/src/libGLESv2/Makefile.in
+++ b/gfx/angle/src/libGLESv2/Makefile.in
@@ -16,17 +16,8 @@ endif
 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:
@@ -40,8 +31,6 @@ LOCAL_INCLUDES += \
   -I$(srcdir)/.. \
   -I"$(MOZ_DIRECTX_SDK_PATH)/include"
 
-DEFINES += -DCOMPILER_IMPLEMENTATION
-
 VPATH += $(srcdir)/renderer
 VPATH += $(srcdir)/..
 VPATH += $(srcdir)/../compiler
diff --git a/gfx/angle/src/libGLESv2/moz.build b/gfx/angle/src/libGLESv2/moz.build
index d9efc4b90dacc..9b5014958c005 100644
--- a/gfx/angle/src/libGLESv2/moz.build
+++ b/gfx/angle/src/libGLESv2/moz.build
@@ -179,3 +179,13 @@ SOURCES += ['renderer/' + src for src in [
 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'
diff --git a/gfx/cairo/cairo/src/Makefile.in b/gfx/cairo/cairo/src/Makefile.in
index d39295392424d..0e6f456e45a43 100644
--- a/gfx/cairo/cairo/src/Makefile.in
+++ b/gfx/cairo/cairo/src/Makefile.in
@@ -9,20 +9,6 @@ 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
@@ -52,25 +38,7 @@ CFLAGS += -Wno-missing-field-initializers
 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
diff --git a/gfx/cairo/cairo/src/moz.build b/gfx/cairo/cairo/src/moz.build
index 62ec1beb0e0b1..fb83858265a1d 100644
--- a/gfx/cairo/cairo/src/moz.build
+++ b/gfx/cairo/cairo/src/moz.build
@@ -48,10 +48,14 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
         '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',
@@ -60,6 +64,9 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'os2':
     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',
@@ -192,3 +199,17 @@ UNIFIED_SOURCES += [
 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
diff --git a/gfx/cairo/libpixman/src/Makefile.in b/gfx/cairo/libpixman/src/Makefile.in
index 59d6cb0b2fc52..9af8995da2882 100644
--- a/gfx/cairo/libpixman/src/Makefile.in
+++ b/gfx/cairo/libpixman/src/Makefile.in
@@ -6,14 +6,6 @@ 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)))
@@ -105,8 +97,6 @@ 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
diff --git a/gfx/cairo/libpixman/src/moz.build b/gfx/cairo/libpixman/src/moz.build
index bdcc8d8e2375c..6d54fc3053529 100644
--- a/gfx/cairo/libpixman/src/moz.build
+++ b/gfx/cairo/libpixman/src/moz.build
@@ -61,3 +61,13 @@ SOURCES += [
 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
diff --git a/gfx/gl/Makefile.in b/gfx/gl/Makefile.in
index 6a728dab11624..56409c55c0e14 100644
--- a/gfx/gl/Makefile.in
+++ b/gfx/gl/Makefile.in
@@ -2,21 +2,11 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-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))
diff --git a/gfx/gl/moz.build b/gfx/gl/moz.build
index df92abcc4ec95..e73d94c74ede9 100644
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -127,3 +127,9 @@ 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
diff --git a/gfx/graphite2/src/Makefile.in b/gfx/graphite2/src/Makefile.in
index a58563f6c5bb2..acdfc2c375a65 100644
--- a/gfx/graphite2/src/Makefile.in
+++ b/gfx/graphite2/src/Makefile.in
@@ -13,26 +13,3 @@ 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\""
diff --git a/gfx/graphite2/src/moz.build b/gfx/graphite2/src/moz.build
index f75fe45bc1b96..1c7f104b74c00 100644
--- a/gfx/graphite2/src/moz.build
+++ b/gfx/graphite2/src/moz.build
@@ -59,5 +59,21 @@ MSVC_ENABLE_PGO = True
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     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"'
diff --git a/gfx/harfbuzz/src/Makefile.in b/gfx/harfbuzz/src/Makefile.in
index 342774743a7af..8d483293a904f 100644
--- a/gfx/harfbuzz/src/Makefile.in
+++ b/gfx/harfbuzz/src/Makefile.in
@@ -29,10 +29,6 @@ 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
diff --git a/gfx/harfbuzz/src/moz.build b/gfx/harfbuzz/src/moz.build
index 132264e182f17..632545ce1c62b 100644
--- a/gfx/harfbuzz/src/moz.build
+++ b/gfx/harfbuzz/src/moz.build
@@ -56,3 +56,9 @@ UNIFIED_SOURCES += [
 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
diff --git a/gfx/layers/Makefile.in b/gfx/layers/Makefile.in
index febfc7cf8f53d..7064c57b262a5 100644
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -15,14 +15,6 @@ VPATH       = \
   $(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 += \
diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build
index 76b6251d5f337..527bbf0489cf3 100644
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -293,3 +293,9 @@ 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
diff --git a/gfx/ots/src/Makefile.in b/gfx/ots/src/Makefile.in
deleted file mode 100644
index 0435a64872c48..0000000000000
--- 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
diff --git a/gfx/ots/src/moz.build b/gfx/ots/src/moz.build
index ab39e428e64ed..ffe1b088b6f06 100644
--- a/gfx/ots/src/moz.build
+++ b/gfx/ots/src/moz.build
@@ -53,3 +53,12 @@ if CONFIG['OS_TARGET'] == 'WINNT':
     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
diff --git a/gfx/skia/Makefile.in b/gfx/skia/Makefile.in
index de867668a929f..ebd09eb0e4859 100644
--- a/gfx/skia/Makefile.in
+++ b/gfx/skia/Makefile.in
@@ -3,8 +3,6 @@
 # License, v. 2.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 \
@@ -50,7 +48,6 @@ VPATH += \
 
 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
@@ -59,23 +56,6 @@ 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
diff --git a/gfx/skia/moz.build b/gfx/skia/moz.build
index 1ca4e60992d8d..815473271f532 100644
--- a/gfx/skia/moz.build
+++ b/gfx/skia/moz.build
@@ -175,6 +175,8 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
         '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',
@@ -217,6 +219,7 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
             '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'):
@@ -240,6 +243,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):
         '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',
@@ -586,3 +590,14 @@ if not CONFIG['INTEL_ARCHITECTURE'] and CONFIG['CPU_ARCH'] == 'arm' and CONFIG['
 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
diff --git a/gfx/thebes/Makefile.in b/gfx/thebes/Makefile.in
index 666efb63cb9b9..85d20c24d942a 100644
--- a/gfx/thebes/Makefile.in
+++ b/gfx/thebes/Makefile.in
@@ -6,38 +6,10 @@ 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))
diff --git a/gfx/thebes/moz.build b/gfx/thebes/moz.build
index b3a993b34a92c..010d23640e788 100644
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -299,3 +299,22 @@ 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
diff --git a/intl/locale/src/unix/Makefile.in b/intl/locale/src/unix/Makefile.in
index aab47c262506d..f93f939d67601 100644
--- a/intl/locale/src/unix/Makefile.in
+++ b/intl/locale/src/unix/Makefile.in
@@ -7,14 +7,5 @@ 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) $^ $@
diff --git a/intl/locale/src/unix/moz.build b/intl/locale/src/unix/moz.build
index df6c6f3057410..8a9af0295ebf9 100644
--- a/intl/locale/src/unix/moz.build
+++ b/intl/locale/src/unix/moz.build
@@ -24,3 +24,11 @@ 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']
diff --git a/intl/unicharutil/util/Makefile.in b/intl/unicharutil/util/Makefile.in
index 88ac54b85f3e0..4ebb3f04e85bb 100644
--- a/intl/unicharutil/util/Makefile.in
+++ b/intl/unicharutil/util/Makefile.in
@@ -20,5 +20,4 @@ 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
diff --git a/intl/unicharutil/util/moz.build b/intl/unicharutil/util/moz.build
index 9824ea1f4c945..0275264e1b039 100644
--- a/intl/unicharutil/util/moz.build
+++ b/intl/unicharutil/util/moz.build
@@ -21,3 +21,6 @@ UNIFIED_SOURCES += intl_unicharutil_util_cppsrcs
 LIBRARY_NAME = 'unicharutil_external_s'
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['_MSC_VER']:
+    DEFINES['_USE_ANSI_CPP'] = True
diff --git a/ipc/chromium/Makefile.in b/ipc/chromium/Makefile.in
index 4ec2f6313b801..21dd07e5e0b56 100644
--- a/ipc/chromium/Makefile.in
+++ b/ipc/chromium/Makefile.in
@@ -26,12 +26,6 @@ vpath %.mm \
   $(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 # {
@@ -40,7 +34,6 @@ 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
@@ -56,9 +49,6 @@ 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 # }
diff --git a/ipc/chromium/moz.build b/ipc/chromium/moz.build
index c898fe2ca4315..ab21c075eee51 100644
--- a/ipc/chromium/moz.build
+++ b/ipc/chromium/moz.build
@@ -146,6 +146,7 @@ elif not CONFIG['MOZ_NATIVE_LIBEVENT']:
         'src/third_party/libevent/signal.c',
         'src/third_party/libevent/strlcpy.c',
     ]
+    DEFINES['HAVE_CONFIG_H'] = True
 
 if os_posix:
     SOURCES += [
@@ -177,6 +178,8 @@ if os_posix:
         SOURCES += [
             'src/base/message_pump_android.cc',
         ]
+        DEFINES['ANDROID'] = True
+        DEFINES['_POSIX_MONOTONIC_CLOCK'] = 0
 
 if os_macosx:
     UNIFIED_SOURCES += [
@@ -265,6 +268,8 @@ if os_bsd:
         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 += [
diff --git a/ipc/glue/Makefile.in b/ipc/glue/Makefile.in
index ca6b5ec229545..38bf1b4ba94ad 100644
--- a/ipc/glue/Makefile.in
+++ b/ipc/glue/Makefile.in
@@ -4,9 +4,6 @@
 
 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
diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build
index e35e9c5099682..6e6e2745bfade 100644
--- a/ipc/glue/moz.build
+++ b/ipc/glue/moz.build
@@ -106,3 +106,6 @@ IPDL_SOURCES = [
 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]
diff --git a/js/ipc/Makefile.in b/js/ipc/Makefile.in
index a4efa73794968..f4920440a76d0 100644
--- a/js/ipc/Makefile.in
+++ b/js/ipc/Makefile.in
@@ -10,5 +10,3 @@ LOCAL_INCLUDES += \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
-
-DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
diff --git a/js/ipc/moz.build b/js/ipc/moz.build
index 986797bc4002c..a453826476ecf 100644
--- a/js/ipc/moz.build
+++ b/js/ipc/moz.build
@@ -20,3 +20,5 @@ FAIL_ON_WARNINGS = True
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX']
diff --git a/js/src/Makefile.in b/js/src/Makefile.in
index ceb1be9aa5f40..84f591be6cd9b 100644
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -46,14 +46,6 @@ VPATH		+= \
 ###############################################
 # 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
@@ -367,19 +359,8 @@ DIST_GARBAGE = config.cache config.log config.status* \
 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
@@ -405,10 +386,6 @@ 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
diff --git a/js/src/config/Makefile.in b/js/src/config/Makefile.in
index 6195d37d8422a..3a0a7a528245b 100644
--- a/js/src/config/Makefile.in
+++ b/js/src/config/Makefile.in
@@ -15,11 +15,6 @@ 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)
diff --git a/js/src/config/moz.build b/js/src/config/moz.build
index d303d6c56595d..838c705d6524a 100644
--- a/js/src/config/moz.build
+++ b/js/src/config/moz.build
@@ -20,3 +20,7 @@ if CONFIG['HOST_OS_ARCH'] != 'WINNT':
         '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
diff --git a/js/src/editline/Makefile.in b/js/src/editline/Makefile.in
deleted file mode 100644
index 20928b8082992..0000000000000
--- 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
diff --git a/js/src/editline/moz.build b/js/src/editline/moz.build
index cf307701ea89c..63afd7f4042a3 100644
--- a/js/src/editline/moz.build
+++ b/js/src/editline/moz.build
@@ -12,3 +12,7 @@ UNIFIED_SOURCES += [
 ]
 
 FORCE_STATIC_LIB = True
+
+for var in ('ANSI_ARROWS', 'HAVE_TCGETATTR', 'HIDE', 'USE_DIRENT', 'SYS_UNIX',
+            'HAVE_STDLIB', 'UNIQUE_HISTORY'):
+    DEFINES[var] = True
diff --git a/js/src/gdb/Makefile.in b/js/src/gdb/Makefile.in
index 29b6823d954dc..d2eff85a956e8 100644
--- a/js/src/gdb/Makefile.in
+++ b/js/src/gdb/Makefile.in
@@ -6,10 +6,6 @@
 
 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..
diff --git a/js/src/gdb/moz.build b/js/src/gdb/moz.build
index 7fdf06e31b45a..4b8a796a8fecd 100644
--- a/js/src/gdb/moz.build
+++ b/js/src/gdb/moz.build
@@ -16,3 +16,8 @@ UNIFIED_SOURCES += [
     '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
diff --git a/js/src/jsapi-tests/Makefile.in b/js/src/jsapi-tests/Makefile.in
index e5d7c6eb935bf..ad73608b32c4b 100644
--- a/js/src/jsapi-tests/Makefile.in
+++ b/js/src/jsapi-tests/Makefile.in
@@ -4,11 +4,6 @@
 # License, v. 2.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..
diff --git a/js/src/jsapi-tests/moz.build b/js/src/jsapi-tests/moz.build
index 8aa75a044045a..29bb02f283321 100644
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -70,3 +70,8 @@ UNIFIED_SOURCES += [
     '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
diff --git a/js/src/moz.build b/js/src/moz.build
index ccf8839cf9b45..2f2d6b317f671 100644
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -402,3 +402,20 @@ 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
diff --git a/js/src/shell/Makefile.in b/js/src/shell/Makefile.in
index 260aa21bbd2c8..68f1db5f2e014 100644
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -11,11 +11,6 @@ ifdef _MSC_VER
 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)
diff --git a/js/src/shell/moz.build b/js/src/shell/moz.build
index 28528ff26a3a1..5ede1ed468a71 100644
--- a/js/src/shell/moz.build
+++ b/js/src/shell/moz.build
@@ -11,3 +11,8 @@ UNIFIED_SOURCES += [
     '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
diff --git a/js/xpconnect/loader/Makefile.in b/js/xpconnect/loader/Makefile.in
index 653fe904e22f2..cdcd75cc1b72e 100644
--- a/js/xpconnect/loader/Makefile.in
+++ b/js/xpconnect/loader/Makefile.in
@@ -7,9 +7,3 @@ LOCAL_INCLUDES += \
   -I$(srcdir)/../wrappers \
   -I$(topsrcdir)/content/base/src \
   $(NULL)
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += \
-  -DJS_THREADSAFE \
-  $(NULL)
diff --git a/js/xpconnect/loader/moz.build b/js/xpconnect/loader/moz.build
index 38fa13e1275d6..75dacdd34022c 100644
--- a/js/xpconnect/loader/moz.build
+++ b/js/xpconnect/loader/moz.build
@@ -22,3 +22,5 @@ FAIL_ON_WARNINGS = True
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'xpconnect_s'
+
+DEFINES['JS_THREADSAFE'] = True
diff --git a/js/xpconnect/src/Makefile.in b/js/xpconnect/src/Makefile.in
index dc3f3a3515f90..b45acbe3476f1 100644
--- a/js/xpconnect/src/Makefile.in
+++ b/js/xpconnect/src/Makefile.in
@@ -37,32 +37,8 @@ extra_export_files_FILES := \
 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 \
diff --git a/js/xpconnect/src/moz.build b/js/xpconnect/src/moz.build
index 7cf3c7416ac01..f1319cb59cd78 100644
--- a/js/xpconnect/src/moz.build
+++ b/js/xpconnect/src/moz.build
@@ -74,3 +74,20 @@ GENERATED_FILES = [
     '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
diff --git a/js/xpconnect/tests/components/native/Makefile.in b/js/xpconnect/tests/components/native/Makefile.in
index b1bd81e88b6b9..576df68547608 100644
--- a/js/xpconnect/tests/components/native/Makefile.in
+++ b/js/xpconnect/tests/components/native/Makefile.in
@@ -14,8 +14,6 @@ EXTRA_DSO_LDOPTS += \
   $(MOZ_COMPONENT_LIBS) \
   $(NULL)
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(componentdir)
 INSTALL_TARGETS += LIB
diff --git a/js/xpconnect/tests/components/native/moz.build b/js/xpconnect/tests/components/native/moz.build
index bb6c4e8040de5..504e63c33f878 100644
--- a/js/xpconnect/tests/components/native/moz.build
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -17,3 +17,9 @@ LIBRARY_NAME = 'xpctest'
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
diff --git a/layout/style/test/Makefile.in b/layout/style/test/Makefile.in
index 3549d34ddb4b6..4831fa8f37cbc 100644
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -222,8 +222,6 @@ VISITED_REFTEST_FILES = \
 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 \
diff --git a/layout/style/test/moz.build b/layout/style/test/moz.build
index ded35afe30cdd..7d1ab04c5c85a 100644
--- a/layout/style/test/moz.build
+++ b/layout/style/test/moz.build
@@ -16,3 +16,4 @@ HOST_SIMPLE_PROGRAMS += [
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
 
+DEFINES['MOZILLA_INTERNAL_API'] = True
diff --git a/layout/tables/Makefile.in b/layout/tables/Makefile.in
index 696156bfb5c28..632d13a530e34 100644
--- a/layout/tables/Makefile.in
+++ b/layout/tables/Makefile.in
@@ -5,8 +5,6 @@
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES         += -DDEBUG_TABLE_STRATEGY_off
-
 LOCAL_INCLUDES	= \
 		-I$(srcdir)/../base \
 		-I$(srcdir)/../generic \
diff --git a/layout/tables/moz.build b/layout/tables/moz.build
index 534b19fed00af..b75a389218704 100644
--- a/layout/tables/moz.build
+++ b/layout/tables/moz.build
@@ -30,3 +30,5 @@ FAIL_ON_WARNINGS = True
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gklayout'
+
+DEFINES['DEBUG_TABLE_STRATEGY_off'] = True
diff --git a/media/libcubeb/src/Makefile.in b/media/libcubeb/src/Makefile.in
index b4e378e0a4598..fd2b8db6097a3 100644
--- a/media/libcubeb/src/Makefile.in
+++ b/media/libcubeb/src/Makefile.in
@@ -3,36 +3,6 @@
 # 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 += \
diff --git a/media/libcubeb/src/moz.build b/media/libcubeb/src/moz.build
index 8f553c97a4d36..fad4b3c047f68 100644
--- a/media/libcubeb/src/moz.build
+++ b/media/libcubeb/src/moz.build
@@ -12,38 +12,46 @@ 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
 
diff --git a/media/libopus/Makefile.in b/media/libopus/Makefile.in
index bf8b0ff61e732..9fa04f2107d67 100644
--- a/media/libopus/Makefile.in
+++ b/media/libopus/Makefile.in
@@ -2,28 +2,6 @@
 # License, v. 2.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 \
@@ -52,7 +30,6 @@ ifndef MOZ_SAMPLE_TYPE_FLOAT32
 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))
diff --git a/media/libopus/moz.build b/media/libopus/moz.build
index 1f9fd64d6b3bb..0f21c2fc2c85f 100644
--- a/media/libopus/moz.build
+++ b/media/libopus/moz.build
@@ -14,3 +14,26 @@ EXPORTS.opus += [
 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
diff --git a/media/libsoundtouch/src/Makefile.in b/media/libsoundtouch/src/Makefile.in
index 889f169f3c1b3..e91148624f4ef 100644
--- a/media/libsoundtouch/src/Makefile.in
+++ b/media/libsoundtouch/src/Makefile.in
@@ -2,9 +2,6 @@
 # License, v. 2.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))
diff --git a/media/libsoundtouch/src/moz.build b/media/libsoundtouch/src/moz.build
index efbc89590907d..83c49bed97707 100644
--- a/media/libsoundtouch/src/moz.build
+++ b/media/libsoundtouch/src/moz.build
@@ -35,3 +35,6 @@ MSVC_ENABLE_PGO = True
 NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+# Use abort() instead of exception in SoundTouch.
+DEFINES['ST_NO_EXCEPTION_HANDLING'] = 1
diff --git a/media/libspeex_resampler/src/Makefile.in b/media/libspeex_resampler/src/Makefile.in
index 85398040bbe5e..f5e24435a878b 100644
--- a/media/libspeex_resampler/src/Makefile.in
+++ b/media/libspeex_resampler/src/Makefile.in
@@ -2,26 +2,11 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# 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
diff --git a/media/libspeex_resampler/src/moz.build b/media/libspeex_resampler/src/moz.build
index d4acfac1d8936..184065498143e 100644
--- a/media/libspeex_resampler/src/moz.build
+++ b/media/libspeex_resampler/src/moz.build
@@ -21,3 +21,21 @@ SOURCES += [
 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
diff --git a/media/libtheora/lib/Makefile.in b/media/libtheora/lib/Makefile.in
index fced5ac16fe8e..fdfbcdf00b615 100644
--- a/media/libtheora/lib/Makefile.in
+++ b/media/libtheora/lib/Makefile.in
@@ -3,31 +3,9 @@
 # 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
diff --git a/media/libtheora/lib/moz.build b/media/libtheora/lib/moz.build
index 98cf6b14a4a14..de7ccb0b54ced 100644
--- a/media/libtheora/lib/moz.build
+++ b/media/libtheora/lib/moz.build
@@ -29,6 +29,11 @@ if CONFIG['OS_TEST'] == 'arm' and CONFIG['GNU_AS']:
     ]]
 
 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 += [
@@ -54,6 +59,13 @@ if CONFIG['GNU_AS']:
             '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
 
@@ -61,3 +73,6 @@ if CONFIG['OS_TARGET'] == 'WINNT':
     NO_VISIBILITY_FLAGS = True
 
 FINAL_LIBRARY = 'gkmedias'
+
+# The encoder is currently not included.
+DEFINES['THEORA_DISABLE_ENCODE'] = True
diff --git a/media/libtremor/lib/Makefile.in b/media/libtremor/lib/Makefile.in
index 4ac11abbba38b..abe61c3118655 100644
--- a/media/libtremor/lib/Makefile.in
+++ b/media/libtremor/lib/Makefile.in
@@ -3,11 +3,3 @@
 # 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
diff --git a/media/libtremor/lib/moz.build b/media/libtremor/lib/moz.build
index 2e078a808c8a5..0f4aba1b43c47 100644
--- a/media/libtremor/lib/moz.build
+++ b/media/libtremor/lib/moz.build
@@ -20,3 +20,9 @@ SOURCES += [
 ]
 
 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
diff --git a/media/libvpx/Makefile.in b/media/libvpx/Makefile.in
index 73521f5977b05..447d14ff461e9 100644
--- a/media/libvpx/Makefile.in
+++ b/media/libvpx/Makefile.in
@@ -2,10 +2,6 @@
 # License, v. 2.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 \
@@ -186,11 +182,6 @@ ifdef VPX_ARM_ASM
 # 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
diff --git a/media/libvpx/moz.build b/media/libvpx/moz.build
index a55399d2f2efb..f4c09ca724888 100644
--- a/media/libvpx/moz.build
+++ b/media/libvpx/moz.build
@@ -94,3 +94,10 @@ if CONFIG['OS_TARGET'] == 'WINNT':
     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
diff --git a/media/mtransport/build/Makefile.in b/media/mtransport/build/Makefile.in
deleted file mode 100644
index d6d1f8f44efe0..0000000000000
--- 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
diff --git a/media/mtransport/build/moz.build b/media/mtransport/build/moz.build
index 0deb9c394af0c..58a7d0010ac2e 100644
--- a/media/mtransport/build/moz.build
+++ b/media/mtransport/build/moz.build
@@ -55,18 +55,30 @@ LOCAL_INCLUDES += [
 ]
 
 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',
     ]
@@ -75,3 +87,16 @@ if CONFIG['OS_TARGET'] == 'WINNT':
     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'
diff --git a/media/mtransport/standalone/Makefile.in b/media/mtransport/standalone/Makefile.in
deleted file mode 100644
index 651f9ca059b5e..0000000000000
--- 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
-
diff --git a/media/mtransport/standalone/moz.build b/media/mtransport/standalone/moz.build
index d287e07aba92d..9049dd8d99b9f 100644
--- a/media/mtransport/standalone/moz.build
+++ b/media/mtransport/standalone/moz.build
@@ -33,18 +33,30 @@ LOCAL_INCLUDES += [
 ]
 
 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',
     ]
@@ -53,3 +65,16 @@ FORCE_STATIC_LIB = True
 
 if CONFIG['OS_TARGET'] == 'WINNT':
     NO_VISIBILITY_FLAGS = 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'
diff --git a/media/mtransport/test/Makefile.in b/media/mtransport/test/Makefile.in
index 0322d419aa096..a04f8c8184b64 100644
--- a/media/mtransport/test/Makefile.in
+++ b/media/mtransport/test/Makefile.in
@@ -2,12 +2,6 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
-DEFINES += \
-  -DHAVE_STRDUP -DNR_SOCKET_IS_VOID_PTR -DSCTP_DEBUG -DINET
-
-ifneq ($(OS_TARGET),Android)
-DEFINES += -DINET6
-endif
 
 LIBS = \
   $(XPCOM_LIBS) \
@@ -48,36 +42,11 @@ LOCAL_INCLUDES += \
  -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)
@@ -94,7 +63,4 @@ LIBS += \
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-  $(NULL)
 endif
diff --git a/media/mtransport/test/moz.build b/media/mtransport/test/moz.build
index 43945999f9eba..576c80b14c15c 100644
--- a/media/mtransport/test/moz.build
+++ b/media/mtransport/test/moz.build
@@ -24,3 +24,18 @@ if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
 
 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
diff --git a/media/webrtc/signaling/test/Makefile.in b/media/webrtc/signaling/test/Makefile.in
index 29ac3014daaf2..f67c979dd360b 100644
--- a/media/webrtc/signaling/test/Makefile.in
+++ b/media/webrtc/signaling/test/Makefile.in
@@ -33,9 +33,6 @@ LIBS += \
 CPPFLAGS += \
   $(STLPORT_CPPFLAGS) \
   $(NULL)
-DEFINES += \
-  -DGTEST_USE_OWN_TR1_TUPLE=1 \
-   $(NULL)
 endif
 
 ifdef MOZ_NATIVE_JPEG
@@ -108,19 +105,6 @@ LIBS += \
   $(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 \
diff --git a/media/webrtc/signaling/test/moz.build b/media/webrtc/signaling/test/moz.build
index bba340f5b8144..1ff5bf1310439 100644
--- a/media/webrtc/signaling/test/moz.build
+++ b/media/webrtc/signaling/test/moz.build
@@ -13,3 +13,9 @@ if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
     ]
 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
diff --git a/memory/build/Makefile.in b/memory/build/Makefile.in
index 6e98f1b06d565..0b19766f6cda9 100644
--- a/memory/build/Makefile.in
+++ b/memory/build/Makefile.in
@@ -8,8 +8,6 @@ SDK_LIBRARY = $(REAL_LIBRARY)
 DIST_INSTALL = 1
 endif
 
-DEFINES += -DMOZ_MEMORY_IMPL
-
 ifdef MOZ_JEMALLOC3
 LOCAL_INCLUDES += -I../jemalloc/src/include
 ifdef _MSC_VER
@@ -24,8 +22,6 @@ SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/mozje
 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
diff --git a/memory/build/moz.build b/memory/build/moz.build
index f933a886a9c4d..52ef39a6b6470 100644
--- a/memory/build/moz.build
+++ b/memory/build/moz.build
@@ -9,11 +9,15 @@ EXPORTS += [
     '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',
diff --git a/memory/jemalloc/Makefile.in b/memory/jemalloc/Makefile.in
index 5b4aa176f39b2..8a7ae7c5cf131 100644
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -18,17 +18,8 @@ LOCAL_INCLUDES += \
 
 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
diff --git a/memory/jemalloc/moz.build b/memory/jemalloc/moz.build
index b40f981b4506e..4d16789b88bb1 100644
--- a/memory/jemalloc/moz.build
+++ b/memory/jemalloc/moz.build
@@ -39,3 +39,12 @@ if CONFIG['OS_TARGET'] == 'Darwin' and not CONFIG['MOZ_REPLACE_MALLOC']:
 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'
diff --git a/memory/mozalloc/Makefile.in b/memory/mozalloc/Makefile.in
index 8ccc8ee7e2e57..c330d97243edb 100644
--- a/memory/mozalloc/Makefile.in
+++ b/memory/mozalloc/Makefile.in
@@ -10,11 +10,6 @@ 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
diff --git a/memory/mozalloc/moz.build b/memory/mozalloc/moz.build
index 99cfff9630aa2..36f41fbd82eb4 100644
--- a/memory/mozalloc/moz.build
+++ b/memory/mozalloc/moz.build
@@ -44,3 +44,7 @@ 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
diff --git a/memory/mozjemalloc/Makefile.in b/memory/mozjemalloc/Makefile.in
index fb734c3ba542e..6b45d8eb9ff55 100644
--- a/memory/mozjemalloc/Makefile.in
+++ b/memory/mozjemalloc/Makefile.in
@@ -18,17 +18,3 @@ 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
diff --git a/memory/mozjemalloc/moz.build b/memory/mozjemalloc/moz.build
index 32293b9ec431e..d1d186ac7319c 100644
--- a/memory/mozjemalloc/moz.build
+++ b/memory/mozjemalloc/moz.build
@@ -14,3 +14,15 @@ if not CONFIG['MOZ_JEMALLOC3']:
     ]
     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
diff --git a/memory/replace/dmd/Makefile.in b/memory/replace/dmd/Makefile.in
index 409a5290a73ef..ea585d81c802c 100644
--- a/memory/replace/dmd/Makefile.in
+++ b/memory/replace/dmd/Makefile.in
@@ -3,8 +3,6 @@
 # License, v. 2.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=
diff --git a/memory/replace/dmd/moz.build b/memory/replace/dmd/moz.build
index a684f0e214017..26876696b7dfc 100644
--- a/memory/replace/dmd/moz.build
+++ b/memory/replace/dmd/moz.build
@@ -21,3 +21,5 @@ SOURCES += [
 LIBRARY_NAME = 'dmd'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
diff --git a/memory/replace/jemalloc/Makefile.in b/memory/replace/jemalloc/Makefile.in
index e15bb50111d08..58d7b57e63987 100644
--- a/memory/replace/jemalloc/Makefile.in
+++ b/memory/replace/jemalloc/Makefile.in
@@ -3,7 +3,6 @@
 # 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
diff --git a/memory/replace/jemalloc/moz.build b/memory/replace/jemalloc/moz.build
index 6a4da10d2fe04..f03a587b392ae 100644
--- a/memory/replace/jemalloc/moz.build
+++ b/memory/replace/jemalloc/moz.build
@@ -21,3 +21,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
 LIBRARY_NAME = 'replace_jemalloc'
 
 FORCE_SHARED_LIB = True
+
+DEFINES['MOZ_JEMALLOC3'] = True
+DEFINES['MOZ_REPLACE_JEMALLOC'] = True
diff --git a/mfbt/tests/Makefile.in b/mfbt/tests/Makefile.in
index e7a4567e7cfb4..77d167b19c0eb 100644
--- a/mfbt/tests/Makefile.in
+++ b/mfbt/tests/Makefile.in
@@ -13,9 +13,6 @@ 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)
diff --git a/mfbt/tests/moz.build b/mfbt/tests/moz.build
index cd3791ff23d60..3a701d985b706 100644
--- a/mfbt/tests/moz.build
+++ b/mfbt/tests/moz.build
@@ -26,3 +26,6 @@ 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
diff --git a/mobile/android/app/Makefile.in b/mobile/android/app/Makefile.in
index 92ea3350707f7..3d1399caa6334 100644
--- a/mobile/android/app/Makefile.in
+++ b/mobile/android/app/Makefile.in
@@ -15,7 +15,6 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += \
@@ -30,17 +29,6 @@ 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::
diff --git a/mobile/android/app/moz.build b/mobile/android/app/moz.build
index 63b9bbf004db1..0083dc859779b 100644
--- a/mobile/android/app/moz.build
+++ b/mobile/android/app/moz.build
@@ -7,3 +7,13 @@
 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']
diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in
index 6ed09e96bab48..4067cf6a10987 100644
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -4,10 +4,6 @@
 
 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
@@ -34,48 +30,15 @@ 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  \
diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build
index 944eda8e96393..a6d8a9387c83d 100644
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -984,3 +984,28 @@ if CONFIG['MOZ_CRASHREPORTER']:
         '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
diff --git a/mobile/android/chrome/Makefile.in b/mobile/android/chrome/Makefile.in
deleted file mode 100644
index 6bfb40097c75f..0000000000000
--- 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)
diff --git a/mobile/android/chrome/moz.build b/mobile/android/chrome/moz.build
index 895d11993cfbb..e7e76e41e6520 100644
--- a/mobile/android/chrome/moz.build
+++ b/mobile/android/chrome/moz.build
@@ -4,3 +4,7 @@
 # License, v. 2.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']
diff --git a/mobile/android/components/Makefile.in b/mobile/android/components/Makefile.in
deleted file mode 100644
index 5f4a13ec49c8a..0000000000000
--- 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)
diff --git a/mobile/android/components/moz.build b/mobile/android/components/moz.build
index c0804483491e4..bd8fbc327ce9d 100644
--- a/mobile/android/components/moz.build
+++ b/mobile/android/components/moz.build
@@ -36,3 +36,4 @@ EXTRA_PP_COMPONENTS += [
     'Sidebar.js',
 ]
 
+DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
diff --git a/mobile/android/geckoview_library/Makefile.in b/mobile/android/geckoview_library/Makefile.in
index ebc4521b6bd37..0b2785ba33e17 100644
--- a/mobile/android/geckoview_library/Makefile.in
+++ b/mobile/android/geckoview_library/Makefile.in
@@ -30,8 +30,6 @@ GARBAGE_DIRS = \
   res \
   $(NULL)
 
-DEFINES += -DANDROID_SDK=$(ANDROID_SDK)
-
 include $(topsrcdir)/config/rules.mk
 
 package: $(properties_deps)
diff --git a/mobile/android/geckoview_library/moz.build b/mobile/android/geckoview_library/moz.build
index c271ec3908ce6..b4a39509e51df 100644
--- a/mobile/android/geckoview_library/moz.build
+++ b/mobile/android/geckoview_library/moz.build
@@ -3,3 +3,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['ANDROID_SDK'] = CONFIG['ANDROID_SDK']
diff --git a/modules/libbz2/src/Makefile.in b/modules/libbz2/src/Makefile.in
index b656a822c8846..f6ec7452c78b8 100644
--- a/modules/libbz2/src/Makefile.in
+++ b/modules/libbz2/src/Makefile.in
@@ -8,12 +8,6 @@ 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...
diff --git a/modules/libbz2/src/moz.build b/modules/libbz2/src/moz.build
index 396f6aa16e87c..939ff7b7469e9 100644
--- a/modules/libbz2/src/moz.build
+++ b/modules/libbz2/src/moz.build
@@ -35,3 +35,9 @@ UNIFIED_SOURCES += [
 ]
 
 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
diff --git a/modules/libmar/tests/Makefile.in b/modules/libmar/tests/Makefile.in
index d3779410a559a..7d24d6cdb7fc3 100644
--- a/modules/libmar/tests/Makefile.in
+++ b/modules/libmar/tests/Makefile.in
@@ -4,8 +4,6 @@
 
 TESTROOT = $(abspath $(DEPTH))/_tests/xpcshell/$(relativesrcdir)
 
-DEFINES += -DBIN_SUFFIX=$(BIN_SUFFIX)
-
 include $(topsrcdir)/config/rules.mk
 
 libs:: unit/head_libmar.js.in
diff --git a/modules/libmar/tests/moz.build b/modules/libmar/tests/moz.build
index 191c90f0b92de..02cb19df69be4 100644
--- a/modules/libmar/tests/moz.build
+++ b/modules/libmar/tests/moz.build
@@ -5,3 +5,5 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
+
+DEFINES['BIN_SUFFIX'] = CONFIG['BIN_SUFFIX']
diff --git a/modules/libmar/tool/Makefile.in b/modules/libmar/tool/Makefile.in
index 2ba546f5af180..0eab1112396d7 100644
--- a/modules/libmar/tool/Makefile.in
+++ b/modules/libmar/tool/Makefile.in
@@ -16,17 +16,6 @@ endif
 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) \
diff --git a/modules/libmar/tool/moz.build b/modules/libmar/tool/moz.build
index af2ad4da634f1..dcdb2caa408d9 100644
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -13,3 +13,9 @@ SOURCES = [
 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
diff --git a/modules/libmar/verify/Makefile.in b/modules/libmar/verify/Makefile.in
index 8717e2896e5b3..5940a28bd80be 100644
--- a/modules/libmar/verify/Makefile.in
+++ b/modules/libmar/verify/Makefile.in
@@ -10,7 +10,6 @@ endif
 LOCAL_INCLUDES += -I$(srcdir)/../src
 
 ifneq ($(OS_ARCH),WINNT)
-DEFINES += -DMAR_NSS
 LOCAL_INCLUDES += -I$(srcdir)/../sign
 endif
 
diff --git a/modules/libmar/verify/moz.build b/modules/libmar/verify/moz.build
index 0739e57feda6b..346da9844105c 100644
--- a/modules/libmar/verify/moz.build
+++ b/modules/libmar/verify/moz.build
@@ -12,3 +12,6 @@ SOURCES += [
 ]
 
 FORCE_STATIC_LIB = True
+
+if CONFIG['OS_ARCH'] != 'WINNT':
+    DEFINES['MAR_NSS'] = True
diff --git a/modules/libpref/src/Makefile.in b/modules/libpref/src/Makefile.in
index 89969bbb070ab..45ca3fa21eb78 100644
--- a/modules/libpref/src/Makefile.in
+++ b/modules/libpref/src/Makefile.in
@@ -3,10 +3,6 @@
 # License, v. 2.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/, \
diff --git a/modules/libpref/src/moz.build b/modules/libpref/src/moz.build
index 8e8c9b8ca4ba1..ee85b27640d29 100644
--- a/modules/libpref/src/moz.build
+++ b/modules/libpref/src/moz.build
@@ -17,3 +17,6 @@ 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']
diff --git a/mozglue/android/Makefile.in b/mozglue/android/Makefile.in
index 60aa56ee7639a..9dfb5497523a5 100644
--- a/mozglue/android/Makefile.in
+++ b/mozglue/android/Makefile.in
@@ -3,13 +3,6 @@
 # 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
diff --git a/mozglue/android/moz.build b/mozglue/android/moz.build
index b4c46e2596fdc..0eef0b4366d05 100644
--- a/mozglue/android/moz.build
+++ b/mozglue/android/moz.build
@@ -18,3 +18,8 @@ SOURCES += [
 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
diff --git a/mozglue/build/Makefile.in b/mozglue/build/Makefile.in
index 916fe19f48005..2381fc57e3e28 100644
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -24,8 +24,6 @@ endif
  
 MOZ_GLUE_LDFLAGS = # Don't link against ourselves
 
-DEFINES += -DIMPL_MFBT
-
 ifeq (WINNT,$(OS_TARGET))
 DEFFILE = mozglue.def
 
diff --git a/mozglue/build/moz.build b/mozglue/build/moz.build
index 696d82dec1fa1..dc6d8abb10fdf 100644
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -68,3 +68,5 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     SOURCES += [
         'cpuacct.c',
     ]
+
+DEFINES['IMPL_MFBT'] = True
diff --git a/mozglue/linker/Makefile.in b/mozglue/linker/Makefile.in
index f44f1d3c65987..2e1e372d22326 100644
--- a/mozglue/linker/Makefile.in
+++ b/mozglue/linker/Makefile.in
@@ -6,8 +6,6 @@ STL_FLAGS =
 
 HOST_LIBS = -lz
 
-DEFINES += -DIMPL_MFBT
-
 include $(topsrcdir)/config/rules.mk
 
 ifeq (arm,$(TARGET_CPU))
diff --git a/mozglue/linker/moz.build b/mozglue/linker/moz.build
index ee9b40c76f17e..d953c9b400ae9 100644
--- a/mozglue/linker/moz.build
+++ b/mozglue/linker/moz.build
@@ -22,3 +22,5 @@ HOST_SOURCES += [
 HOST_PROGRAM = 'szip'
 
 FINAL_LIBRARY = 'mozglue'
+
+DEFINES['IMPL_MFBT'] = True
diff --git a/netwerk/protocol/rtsp/Makefile.in b/netwerk/protocol/rtsp/Makefile.in
index a5a297a724f00..c0ecb0c2b5bda 100644
--- a/netwerk/protocol/rtsp/Makefile.in
+++ b/netwerk/protocol/rtsp/Makefile.in
@@ -28,4 +28,4 @@ endif
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DIMPL_NS_NET -Wno-multichar -DFORCE_PR_LOG
+DEFINES += -Wno-multichar
diff --git a/netwerk/protocol/rtsp/moz.build b/netwerk/protocol/rtsp/moz.build
index fc61b2b90d64e..9aa0b863ad97f 100644
--- a/netwerk/protocol/rtsp/moz.build
+++ b/netwerk/protocol/rtsp/moz.build
@@ -50,3 +50,6 @@ 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
diff --git a/netwerk/sctp/datachannel/Makefile.in b/netwerk/sctp/datachannel/Makefile.in
index b3bed875c749f..ce4c7cc634956 100644
--- a/netwerk/sctp/datachannel/Makefile.in
+++ b/netwerk/sctp/datachannel/Makefile.in
@@ -11,21 +11,3 @@ LOCAL_INCLUDES = \
   -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
diff --git a/netwerk/sctp/datachannel/moz.build b/netwerk/sctp/datachannel/moz.build
index 37deadcddccd1..fdf48f468b502 100644
--- a/netwerk/sctp/datachannel/moz.build
+++ b/netwerk/sctp/datachannel/moz.build
@@ -21,3 +21,14 @@ 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
diff --git a/netwerk/sctp/src/Makefile.in b/netwerk/sctp/src/Makefile.in
index eff7c45ee4063..96724ed7c85f0 100644
--- a/netwerk/sctp/src/Makefile.in
+++ b/netwerk/sctp/src/Makefile.in
@@ -18,64 +18,28 @@ LOCAL_INCLUDES = \
   -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
@@ -85,8 +49,6 @@ endif
 endif
 endif
 endif
-endif
-endif
 
 include $(topsrcdir)/config/rules.mk
 
diff --git a/netwerk/sctp/src/moz.build b/netwerk/sctp/src/moz.build
index 54ed0fbc05865..f25b9a5bd6bc9 100644
--- a/netwerk/sctp/src/moz.build
+++ b/netwerk/sctp/src/moz.build
@@ -48,3 +48,28 @@ 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
diff --git a/netwerk/srtp/src/Makefile.in b/netwerk/srtp/src/Makefile.in
index fe27a1aad5c19..6aa35d9db5858 100644
--- a/netwerk/srtp/src/Makefile.in
+++ b/netwerk/srtp/src/Makefile.in
@@ -20,49 +20,6 @@ LOCAL_INCLUDES = \
   -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
diff --git a/netwerk/srtp/src/moz.build b/netwerk/srtp/src/moz.build
index 99e1adc0c3c4f..966bcbc38fe46 100644
--- a/netwerk/srtp/src/moz.build
+++ b/netwerk/srtp/src/moz.build
@@ -38,3 +38,27 @@ 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'
diff --git a/netwerk/streamconv/test/Makefile.in b/netwerk/streamconv/test/Makefile.in
index 8a395e5af006b..a9276fcdc2cef 100644
--- a/netwerk/streamconv/test/Makefile.in
+++ b/netwerk/streamconv/test/Makefile.in
@@ -17,10 +17,4 @@ 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
diff --git a/netwerk/streamconv/test/moz.build b/netwerk/streamconv/test/moz.build
index 988026eb8c3c6..2f65f1770eb62 100644
--- a/netwerk/streamconv/test/moz.build
+++ b/netwerk/streamconv/test/moz.build
@@ -13,3 +13,6 @@ UNIFIED_SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
+if CONFIG['OS_ARCH'] == 'WINNT':
+    for var in ('MOZ_NO_DEBUG_RTL', 'NGPREFS'):
+        DEFINES[var] = True
diff --git a/other-licenses/skia-npapi/Makefile.in b/other-licenses/skia-npapi/Makefile.in
index c03e9ca9bf29b..c0dbed78851f0 100644
--- a/other-licenses/skia-npapi/Makefile.in
+++ b/other-licenses/skia-npapi/Makefile.in
@@ -2,10 +2,6 @@
 # License, v. 2.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 \
diff --git a/other-licenses/skia-npapi/moz.build b/other-licenses/skia-npapi/moz.build
index ec2b780e6df12..be49c474f1003 100644
--- a/other-licenses/skia-npapi/moz.build
+++ b/other-licenses/skia-npapi/moz.build
@@ -17,3 +17,5 @@ SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['SK_BUILD_FOR_ANDROID_NDK'] = True
diff --git a/parser/expat/lib/Makefile.in b/parser/expat/lib/Makefile.in
deleted file mode 100644
index 84a0aadf0a8b2..0000000000000
--- 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
diff --git a/parser/expat/lib/moz.build b/parser/expat/lib/moz.build
index 326fdd892f7aa..b9cdebf09a162 100644
--- a/parser/expat/lib/moz.build
+++ b/parser/expat/lib/moz.build
@@ -22,3 +22,5 @@ FINAL_LIBRARY = 'gkmedias'
 GENERATED_FILES = [
     'moz_extensions.c',
 ]
+
+DEFINES['HAVE_EXPAT_CONFIG_H'] = True
diff --git a/parser/html/Makefile.in b/parser/html/Makefile.in
index 37e8b4518da06..2ed823acf9d68 100644
--- a/parser/html/Makefile.in
+++ b/parser/html/Makefile.in
@@ -7,5 +7,3 @@ include $(topsrcdir)/config/rules.mk
 INCLUDES	+= \
 		-I$(srcdir)/../../content/base/src \
 		$(NULL)
-
-#DEFINES		+= -DENABLE_VOID_MENUITEM
diff --git a/parser/html/moz.build b/parser/html/moz.build
index c69bc901d11f6..aee4666e22060 100644
--- a/parser/html/moz.build
+++ b/parser/html/moz.build
@@ -86,3 +86,5 @@ UNIFIED_SOURCES += [
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'gklayout'
+
+# DEFINES['ENABLE_VOID_MENUITEM'] = True
diff --git a/profile/dirserviceprovider/standalone/Makefile.in b/profile/dirserviceprovider/standalone/Makefile.in
index b0b6b08c3a49b..7af9f387cd0a8 100644
--- a/profile/dirserviceprovider/standalone/Makefile.in
+++ b/profile/dirserviceprovider/standalone/Makefile.in
@@ -6,5 +6,4 @@ include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = -I$(srcdir)/../src
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS =
diff --git a/profile/dirserviceprovider/standalone/moz.build b/profile/dirserviceprovider/standalone/moz.build
index 124e3b2b3ff9c..25a3ebd065783 100644
--- a/profile/dirserviceprovider/standalone/moz.build
+++ b/profile/dirserviceprovider/standalone/moz.build
@@ -11,3 +11,5 @@ UNIFIED_SOURCES += modules_profiledirservice_src_csrcs
 LIBRARY_NAME = 'profdirserviceprovidersa_s'
 
 FORCE_STATIC_LIB = True
+
+DEFINES['XPCOM_GLUE'] = 1
diff --git a/security/manager/ssl/src/Makefile.in b/security/manager/ssl/src/Makefile.in
deleted file mode 100644
index 86a8f19a008bb..0000000000000
--- 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)
diff --git a/security/manager/ssl/src/moz.build b/security/manager/ssl/src/moz.build
index f4414bd1ae109..7357000998f14 100644
--- a/security/manager/ssl/src/moz.build
+++ b/security/manager/ssl/src/moz.build
@@ -92,3 +92,7 @@ UNIFIED_SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['NSS_ENABLE_ECC'] = 'True'
+for var in ('DLL_PREFIX', 'DLL_SUFFIX'):
+    DEFINES[var] = '"%s"' % CONFIG[var]
diff --git a/security/sandbox/Makefile.in b/security/sandbox/Makefile.in
index ece8ec3c88dfd..7c93c4b4e5a88 100644
--- a/security/sandbox/Makefile.in
+++ b/security/sandbox/Makefile.in
@@ -9,8 +9,6 @@ LOCAL_INCLUDES += \
     -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
diff --git a/security/sandbox/moz.build b/security/sandbox/moz.build
index 291a368f8b2f2..4ce987bb125b4 100644
--- a/security/sandbox/moz.build
+++ b/security/sandbox/moz.build
@@ -117,3 +117,6 @@ elif CONFIG['OS_ARCH'] == 'WINNT':
         'win/src/Wow64.cc',
     ]
 
+    for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM', 'SANDBOX_EXPORTS',
+                'NOMINMAX', '_CRT_RAND_S'):
+        DEFINES[var] = True
diff --git a/security/sandbox/win/src/sandboxbroker/Makefile.in b/security/sandbox/win/src/sandboxbroker/Makefile.in
index 9fd3354023133..60374b59c457f 100644
--- a/security/sandbox/win/src/sandboxbroker/Makefile.in
+++ b/security/sandbox/win/src/sandboxbroker/Makefile.in
@@ -16,5 +16,3 @@ SHARED_LIBRARY_LIBS += \
 	$(NULL)
 
 OS_LIBS += $(call EXPAND_LIBNAME,dbghelp)
-
-DEFINES += -DUNICODE -D_UNICODE -DNS_NO_XPCOM -DNOMINMAX -DSANDBOX_EXPORTS
diff --git a/security/sandbox/win/src/sandboxbroker/moz.build b/security/sandbox/win/src/sandboxbroker/moz.build
index ced307e2ef795..0dfd8df3fce53 100644
--- a/security/sandbox/win/src/sandboxbroker/moz.build
+++ b/security/sandbox/win/src/sandboxbroker/moz.build
@@ -16,3 +16,7 @@ EXPORTS += [
 ]
 
 FORCE_SHARED_LIB = True
+
+for var in ('UNICODE', '_UNICODE', 'NS_NO_XPCOM', 'NOMINMAX',
+            'SANDBOX_EXPORTS'):
+    DEFINES[var] = True
diff --git a/storage/src/Makefile.in b/storage/src/Makefile.in
index c7391edbc3424..659b9c30c8a26 100644
--- a/storage/src/Makefile.in
+++ b/storage/src/Makefile.in
@@ -3,32 +3,9 @@
 # License, v. 2.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
diff --git a/storage/src/moz.build b/storage/src/moz.build
index 9f0c2aee53f80..73ab863a4af3c 100644
--- a/storage/src/moz.build
+++ b/storage/src/moz.build
@@ -40,3 +40,22 @@ SOURCES += [
 ]
 
 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
diff --git a/testing/marionette/Makefile.in b/testing/marionette/Makefile.in
deleted file mode 100644
index 0e1861faeed8b..0000000000000
--- 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
diff --git a/testing/marionette/components/Makefile.in b/testing/marionette/components/Makefile.in
deleted file mode 100644
index 542a6efb68f13..0000000000000
--- 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
diff --git a/testing/marionette/components/moz.build b/testing/marionette/components/moz.build
index ced6b577a3558..708e6dc81217b 100644
--- a/testing/marionette/components/moz.build
+++ b/testing/marionette/components/moz.build
@@ -11,3 +11,6 @@ EXTRA_COMPONENTS += [
 EXTRA_PP_COMPONENTS += [
     'marionettecomponent.js'
 ]
+
+if CONFIG['ENABLE_MARIONETTE']:
+    DEFINES['ENABLE_MARIONETTE'] = 1
diff --git a/testing/marionette/moz.build b/testing/marionette/moz.build
index cb2f4f9c5d671..7b4288f8a76c5 100644
--- a/testing/marionette/moz.build
+++ b/testing/marionette/moz.build
@@ -5,3 +5,6 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += ['components', 'atoms']
+
+if CONFIG['ENABLE_TESTS']:
+    DEFINES['ENABLE_TESTS'] = True
diff --git a/toolkit/components/maintenanceservice/Makefile.in b/toolkit/components/maintenanceservice/Makefile.in
index 1b58c8ddd4e03..86e384f4f1a1e 100644
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -2,9 +2,6 @@
 # License, v. 2.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
@@ -23,7 +20,6 @@ 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
@@ -40,8 +36,6 @@ endif
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DNS_NO_XPCOM
-
 ifdef _MSC_VER
 WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup
 endif
diff --git a/toolkit/components/maintenanceservice/moz.build b/toolkit/components/maintenanceservice/moz.build
index b2a303c51d2f5..06a3420e0b238 100644
--- a/toolkit/components/maintenanceservice/moz.build
+++ b/toolkit/components/maintenanceservice/moz.build
@@ -14,3 +14,10 @@ SOURCES += [
     '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
diff --git a/toolkit/components/search/Makefile.in b/toolkit/components/search/Makefile.in
deleted file mode 100644
index 7355d13216c2b..0000000000000
--- 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)
diff --git a/toolkit/components/search/moz.build b/toolkit/components/search/moz.build
index 79e3095a135aa..e1baea5d50b29 100644
--- a/toolkit/components/search/moz.build
+++ b/toolkit/components/search/moz.build
@@ -14,3 +14,5 @@ EXTRA_COMPONENTS += [
 EXTRA_PP_COMPONENTS += [
     'nsSearchService.js',
 ]
+
+DEFINES['MOZ_DISTRIBUTION_ID'] = CONFIG['MOZ_DISTRIBUTION_ID']
diff --git a/toolkit/components/telemetry/Makefile.in b/toolkit/components/telemetry/Makefile.in
index cb1f570dfbfd3..ed2322d95ff5d 100644
--- a/toolkit/components/telemetry/Makefile.in
+++ b/toolkit/components/telemetry/Makefile.in
@@ -9,10 +9,6 @@ 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)"
diff --git a/toolkit/components/telemetry/moz.build b/toolkit/components/telemetry/moz.build
index cfe134c55e6d5..dc082ee6f629b 100644
--- a/toolkit/components/telemetry/moz.build
+++ b/toolkit/components/telemetry/moz.build
@@ -49,3 +49,6 @@ FINAL_LIBRARY = 'xul'
 GENERATED_FILES = [
     'TelemetryHistogramData.inc',
 ]
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
diff --git a/toolkit/content/Makefile.in b/toolkit/content/Makefile.in
index cbd71daf33605..485b574eb6805 100644
--- a/toolkit/content/Makefile.in
+++ b/toolkit/content/Makefile.in
@@ -7,13 +7,6 @@ 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)
@@ -23,10 +16,6 @@ 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)"
@@ -34,9 +23,5 @@ 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)"
diff --git a/toolkit/content/moz.build b/toolkit/content/moz.build
index 0a6b67fd879f2..58bc41086cf99 100644
--- a/toolkit/content/moz.build
+++ b/toolkit/content/moz.build
@@ -5,3 +5,13 @@
 # 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
diff --git a/toolkit/crashreporter/Makefile.in b/toolkit/crashreporter/Makefile.in
index 211a46654069f..513422cba05ae 100644
--- a/toolkit/crashreporter/Makefile.in
+++ b/toolkit/crashreporter/Makefile.in
@@ -2,29 +2,14 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-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
 
diff --git a/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in b/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
index 37d8f126b0bbb..78ba9ac5c2897 100644
--- a/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
+++ b/toolkit/crashreporter/breakpad-windows-libxul/Makefile.in
@@ -18,8 +18,6 @@ VPATH += \
   $(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) \
diff --git a/toolkit/crashreporter/breakpad-windows-libxul/moz.build b/toolkit/crashreporter/breakpad-windows-libxul/moz.build
index 6d488d4291cc4..3df72f69d19e1 100644
--- a/toolkit/crashreporter/breakpad-windows-libxul/moz.build
+++ b/toolkit/crashreporter/breakpad-windows-libxul/moz.build
@@ -11,3 +11,6 @@ SOURCES += [
 LIBRARY_NAME = 'google_breakpad_libxul_s'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+for var in ('UNICODE', 'UNICODE_', 'BREAKPAD_NO_TERMINATE_THREAD', 'NOMINMAX'):
+    DEFINES[var] = True
diff --git a/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in b/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
index 9d905b46806c1..49532e4a5fdee 100644
--- a/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
+++ b/toolkit/crashreporter/breakpad-windows-standalone/Makefile.in
@@ -19,8 +19,6 @@ VPATH += \
   $(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) \
diff --git a/toolkit/crashreporter/breakpad-windows-standalone/moz.build b/toolkit/crashreporter/breakpad-windows-standalone/moz.build
index ea1ac59592455..579a0fa5c57e1 100644
--- a/toolkit/crashreporter/breakpad-windows-standalone/moz.build
+++ b/toolkit/crashreporter/breakpad-windows-standalone/moz.build
@@ -5,3 +5,6 @@
 # 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
diff --git a/toolkit/crashreporter/client/Makefile.in b/toolkit/crashreporter/client/Makefile.in
index 01e7388e919ff..40feebcff2542 100644
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -25,7 +25,6 @@ LIBS += \
   $(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
diff --git a/toolkit/crashreporter/client/moz.build b/toolkit/crashreporter/client/moz.build
index 4ce1793d3e2c7..bc2d59715c0b6 100644
--- a/toolkit/crashreporter/client/moz.build
+++ b/toolkit/crashreporter/client/moz.build
@@ -16,6 +16,8 @@ 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',
diff --git a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
index 69fa790b46ca7..aaa18c397bdbb 100644
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/Makefile.in
@@ -24,6 +24,5 @@ LOCAL_INCLUDES = \
 
 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
diff --git a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
index 24c5f78ea8edc..837b28422ac95 100644
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/moz.build
@@ -13,3 +13,8 @@ SOURCES += [
 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
diff --git a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
index 14c68f5e0d289..24c3576843423 100644
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/Makefile.in
@@ -9,7 +9,3 @@ LOCAL_INCLUDES = \
 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
diff --git a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
index 9396ba35b8c0d..13e04e1651d05 100644
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/minidump_writer/moz.build
@@ -13,3 +13,6 @@ SOURCES += [
 XPI_NAME = 'crashreporter'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['ELFSIZE'] = 32
diff --git a/toolkit/crashreporter/google-breakpad/src/common/Makefile.in b/toolkit/crashreporter/google-breakpad/src/common/Makefile.in
index 8c0137857afe0..9c463d44d21dd 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/common/Makefile.in
@@ -12,11 +12,6 @@ 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.
diff --git a/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in b/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
index 9b96e8ea8b22b..911261e51d5be 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/Makefile.in
@@ -11,12 +11,6 @@ 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
diff --git a/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build b/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
index bbe4ad0df5d2f..9af1365e8a56d 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/linux/moz.build
@@ -33,3 +33,8 @@ if CONFIG['MOZ_CRASHREPORTER']:
 LIBRARY_NAME = 'breakpad_linux_common_s'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+    DEFINES['ELFSIZE'] = 32
+
+DEFINES['NO_STABS_SUPPORT'] = True
diff --git a/toolkit/crashreporter/google-breakpad/src/common/moz.build b/toolkit/crashreporter/google-breakpad/src/common/moz.build
index 50c71e470f546..4b5f4d0b3dd3b 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/moz.build
@@ -83,3 +83,9 @@ 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
diff --git a/toolkit/crashreporter/moz.build b/toolkit/crashreporter/moz.build
index 7762bf6e592de..c09f9dcddf6eb 100644
--- a/toolkit/crashreporter/moz.build
+++ b/toolkit/crashreporter/moz.build
@@ -81,3 +81,16 @@ 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
diff --git a/toolkit/crashreporter/test/Makefile.in b/toolkit/crashreporter/test/Makefile.in
index 18dfc37871d6b..f1b394c304011 100644
--- a/toolkit/crashreporter/test/Makefile.in
+++ b/toolkit/crashreporter/test/Makefile.in
@@ -24,8 +24,6 @@ MOCHITEST_CRASHREPORTER_FILES = \
 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
diff --git a/toolkit/crashreporter/test/moz.build b/toolkit/crashreporter/test/moz.build
index 9a01724630b20..2fcb202f93459 100644
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -23,3 +23,11 @@ EXTRA_JS_MODULES += [
 ]
 
 FORCE_SHARED_LIB = True
+
+DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
+
+DEFINES['NOMINMAX'] = True
diff --git a/toolkit/modules/Makefile.in b/toolkit/modules/Makefile.in
deleted file mode 100644
index f9d643c8e1b48..0000000000000
--- 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)
diff --git a/toolkit/modules/moz.build b/toolkit/modules/moz.build
index 5b959c7f238f0..be34b31a36ac3 100644
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -59,3 +59,8 @@ if 'Android' != CONFIG['OS_TARGET']:
         '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
diff --git a/toolkit/mozapps/extensions/Makefile.in b/toolkit/mozapps/extensions/Makefile.in
index fd6e032cd083a..a3ef4233cc256 100644
--- a/toolkit/mozapps/extensions/Makefile.in
+++ b/toolkit/mozapps/extensions/Makefile.in
@@ -2,18 +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/.
 
-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
diff --git a/toolkit/mozapps/extensions/moz.build b/toolkit/mozapps/extensions/moz.build
index 0265ede7ce689..64c12d77dad00 100644
--- a/toolkit/mozapps/extensions/moz.build
+++ b/toolkit/mozapps/extensions/moz.build
@@ -45,3 +45,13 @@ EXTRA_PP_JS_MODULES += [
     '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
diff --git a/toolkit/mozapps/update/tests/Makefile.in b/toolkit/mozapps/update/tests/Makefile.in
index a193f5b2aea1d..1930b12be5a9d 100644
--- a/toolkit/mozapps/update/tests/Makefile.in
+++ b/toolkit/mozapps/update/tests/Makefile.in
@@ -7,20 +7,8 @@ CHROMETESTROOT = $(abspath $(DEPTH))/_tests/testing/mochitest/chrome/$(relatives
 
 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
@@ -91,7 +79,6 @@ endif
 
 ifeq ($(OS_ARCH),WINNT)
 USE_STATIC_LIBS = 1
-DEFINES += -DUNICODE -D_UNICODE
 endif # WINNT
 endif # Not Android
 
diff --git a/toolkit/mozapps/update/tests/moz.build b/toolkit/mozapps/update/tests/moz.build
index 8756238044a32..4a722e209c82b 100644
--- a/toolkit/mozapps/update/tests/moz.build
+++ b/toolkit/mozapps/update/tests/moz.build
@@ -21,3 +21,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     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
diff --git a/toolkit/mozapps/update/updater/Makefile.in b/toolkit/mozapps/update/updater/Makefile.in
index 2ef23d784aa11..05e0fe26fa2f8 100644
--- a/toolkit/mozapps/update/updater/Makefile.in
+++ b/toolkit/mozapps/update/updater/Makefile.in
@@ -28,7 +28,6 @@ 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
@@ -63,11 +62,6 @@ 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
diff --git a/toolkit/mozapps/update/updater/moz.build b/toolkit/mozapps/update/updater/moz.build
index d6a76fa5c4d77..ce934d82e48bb 100644
--- a/toolkit/mozapps/update/updater/moz.build
+++ b/toolkit/mozapps/update/updater/moz.build
@@ -20,6 +20,8 @@ if CONFIG['OS_ARCH'] == 'WINNT':
         'progressui_win.cpp',
         'win_dirent.cpp',
     ]
+    DEFINES['UNICODE'] = True
+    DEFINES['_UNICODE'] = True
 
 if CONFIG['MOZ_ENABLE_GTK']:
     have_progressui = 1
@@ -46,3 +48,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
         '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]
diff --git a/toolkit/webapps/Makefile.in b/toolkit/webapps/Makefile.in
deleted file mode 100644
index 3921d17964542..0000000000000
--- 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
diff --git a/toolkit/webapps/moz.build b/toolkit/webapps/moz.build
index 842552ee044fd..ab4a4ac4bf162 100644
--- a/toolkit/webapps/moz.build
+++ b/toolkit/webapps/moz.build
@@ -9,3 +9,5 @@ EXTRA_PP_JS_MODULES += [
     'WebappsInstaller.jsm',
 ]
 
+if CONFIG['MOZ_BUILD_APP'] == 'mobile/android':
+    DEFINES['MOZ_FENNEC'] = True
diff --git a/toolkit/xre/Makefile.in b/toolkit/xre/Makefile.in
index aaf486435942f..f31f016e87984 100644
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -10,29 +10,6 @@ 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
@@ -55,17 +32,6 @@ 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)
@@ -73,16 +39,6 @@ $(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
 
@@ -100,15 +56,7 @@ 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)
 
diff --git a/toolkit/xre/moz.build b/toolkit/xre/moz.build
index c5cd29281c0cb..9cf8991fb775f 100644
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -102,3 +102,40 @@ 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 ('APP_VERSION', 'APP_ID'):
+    DEFINES[var] = CONFIG['MOZ_%s' % var]
+
+if CONFIG['MOZILLA_OFFICIAL']:
+    DEFINES['MOZILLA_OFFICIAL'] = True
diff --git a/toolkit/xre/test/win/Makefile.in b/toolkit/xre/test/win/Makefile.in
index 22a409962cf50..565675c4a30eb 100644
--- a/toolkit/xre/test/win/Makefile.in
+++ b/toolkit/xre/test/win/Makefile.in
@@ -15,8 +15,6 @@ USE_STATIC_LIBS = 1
 
 include $(topsrcdir)/config/rules.mk
 
-DEFINES += -DNS_NO_XPCOM
-
 libs:: TestXREMakeCommandLineWin.ini
 	$(INSTALL) $^ $(FINAL_TARGET)/
 
diff --git a/toolkit/xre/test/win/moz.build b/toolkit/xre/test/win/moz.build
index cc3d2ee086132..d1b4808228aea 100644
--- a/toolkit/xre/test/win/moz.build
+++ b/toolkit/xre/test/win/moz.build
@@ -12,3 +12,5 @@ SIMPLE_PROGRAMS = [
 SOURCES += [
     '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]
+
+DEFINES['NS_NO_XPCOM'] = True
diff --git a/tools/jprof/stub/Makefile.in b/tools/jprof/stub/Makefile.in
index 1446533236286..8e6b6b8f8dcbf 100644
--- a/tools/jprof/stub/Makefile.in
+++ b/tools/jprof/stub/Makefile.in
@@ -6,7 +6,3 @@
 
 # override optimization
 MOZ_OPTIMIZE_FLAGS = -fno-omit-frame-pointer
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES		+= -D_IMPL_JPROF_API
diff --git a/tools/jprof/stub/moz.build b/tools/jprof/stub/moz.build
index 9ef5823e57f50..da55dc1aae332 100644
--- a/tools/jprof/stub/moz.build
+++ b/tools/jprof/stub/moz.build
@@ -17,3 +17,5 @@ LIBRARY_NAME = 'jprof'
 EXPORT_LIBRARY = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['_IMPL_JPROF_API'] = True
diff --git a/tools/trace-malloc/lib/Makefile.in b/tools/trace-malloc/lib/Makefile.in
index 82936bde34136..db9a3a20de6ae 100644
--- a/tools/trace-malloc/lib/Makefile.in
+++ b/tools/trace-malloc/lib/Makefile.in
@@ -6,9 +6,3 @@
 DEFFILE		= $(win_srcdir)/tm.def
 
 STL_FLAGS	=
-
-DEFINES		+= -DMOZ_NO_MOZALLOC
-
-ifdef WRAP_SYSTEM_INCLUDES
-DEFINES		+= -DWRAP_SYSTEM_INCLUDES
-endif
diff --git a/tools/trace-malloc/lib/moz.build b/tools/trace-malloc/lib/moz.build
index 3a0b2fc1dc9d7..81d3cf3ccdef7 100644
--- a/tools/trace-malloc/lib/moz.build
+++ b/tools/trace-malloc/lib/moz.build
@@ -23,3 +23,8 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     ]
 
 FINAL_LIBRARY = 'xpcom_core'
+
+if CONFIG['WRAP_SYSTEM_INCLUDES']:
+    DEFINES['WRAP_SYSTEM_INCLUDES'] = True
+
+DEFINES['MOZ_NO_MOZALLOC'] = True
diff --git a/webapprt/Makefile.in b/webapprt/Makefile.in
index 0f5710f92d0ed..64f53b1a41019 100644
--- a/webapprt/Makefile.in
+++ b/webapprt/Makefile.in
@@ -10,22 +10,11 @@ PREF_JS_EXPORTS = $(srcdir)/prefs.js \
 
 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 $@)
diff --git a/webapprt/gtk2/Makefile.in b/webapprt/gtk2/Makefile.in
index c684406a1ee42..bfc4fbc749983 100644
--- a/webapprt/gtk2/Makefile.in
+++ b/webapprt/gtk2/Makefile.in
@@ -9,7 +9,6 @@ LOCAL_INCLUDES += \
   -I$(DEPTH)/build \
   $(NULL)
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
diff --git a/webapprt/gtk2/moz.build b/webapprt/gtk2/moz.build
index e102213a60e6a..f4a499810b10c 100644
--- a/webapprt/gtk2/moz.build
+++ b/webapprt/gtk2/moz.build
@@ -12,3 +12,4 @@ SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
+DEFINES['XPCOM_GLUE'] = True
diff --git a/webapprt/mac/Makefile.in b/webapprt/mac/Makefile.in
index 74c42c6390e68..34f9e31144ef2 100644
--- a/webapprt/mac/Makefile.in
+++ b/webapprt/mac/Makefile.in
@@ -16,7 +16,6 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
diff --git a/webapprt/mac/moz.build b/webapprt/mac/moz.build
index 1ff1b3efef24e..d49a48d2b04bd 100644
--- a/webapprt/mac/moz.build
+++ b/webapprt/mac/moz.build
@@ -10,3 +10,4 @@ SOURCES += [
     'webapprt.mm',
 ]
 
+DEFINES['XPCOM_GLUE'] = True
diff --git a/webapprt/moz.build b/webapprt/moz.build
index 6ab093147fbc6..0f298755d10ab 100644
--- a/webapprt/moz.build
+++ b/webapprt/moz.build
@@ -35,3 +35,12 @@ 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']
diff --git a/webapprt/win/Makefile.in b/webapprt/win/Makefile.in
index 365ea0afd2477..beab17a5685ba 100644
--- a/webapprt/win/Makefile.in
+++ b/webapprt/win/Makefile.in
@@ -13,7 +13,6 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base
 LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
 LOCAL_INCLUDES += -I$(DEPTH)/build
 
-DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
diff --git a/webapprt/win/moz.build b/webapprt/win/moz.build
index 61042d25dfea8..f9e379e0d2d22 100644
--- a/webapprt/win/moz.build
+++ b/webapprt/win/moz.build
@@ -9,3 +9,5 @@ PROGRAM = 'webapprt-stub'
 SOURCES += [
     'webapprt.cpp',
 ]
+
+DEFINES['XPCOM_GLUE'] = True
diff --git a/widget/android/Makefile.in b/widget/android/Makefile.in
index 987f27e06e8ad..da6a6d8c20d49 100644
--- a/widget/android/Makefile.in
+++ b/widget/android/Makefile.in
@@ -4,8 +4,6 @@
 
 include $(topsrcdir)/config/rules.mk
 
-#DEFINES += -DDEBUG_WIDGETS
-
 LOCAL_INCLUDES += \
 	-I$(topsrcdir)/widget/xpwidgets \
 	-I$(topsrcdir)/widget/shared \
diff --git a/widget/android/moz.build b/widget/android/moz.build
index 4e54a5b2e9b53..80fdbf4cc7734 100644
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -46,3 +46,5 @@ LIBRARY_NAME = 'widget_android'
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+#DEFINES['DEBUG_WIDGETS'] = True
diff --git a/widget/gonk/Makefile.in b/widget/gonk/Makefile.in
index e2479ef0dc9b9..dfa45501b7f89 100644
--- a/widget/gonk/Makefile.in
+++ b/widget/gonk/Makefile.in
@@ -19,12 +19,6 @@ VPATH           = \
 
 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 \
diff --git a/widget/gonk/libdisplay/Makefile.in b/widget/gonk/libdisplay/Makefile.in
index f074a67e574c5..1b8d3a6b117f4 100644
--- a/widget/gonk/libdisplay/Makefile.in
+++ b/widget/gonk/libdisplay/Makefile.in
@@ -20,8 +20,6 @@ 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 \
diff --git a/widget/gonk/libdisplay/moz.build b/widget/gonk/libdisplay/moz.build
index f33aae067e7ca..60e095205f4ea 100644
--- a/widget/gonk/libdisplay/moz.build
+++ b/widget/gonk/libdisplay/moz.build
@@ -41,3 +41,5 @@ LIBRARY_NAME = 'display'
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FORCE_STATIC_LIB = True
+
+DEFINES['XPCOM_GLUE'] = True
diff --git a/widget/gonk/moz.build b/widget/gonk/moz.build
index 2ec804659dbaf..cb3f670404843 100644
--- a/widget/gonk/moz.build
+++ b/widget/gonk/moz.build
@@ -63,3 +63,9 @@ 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
diff --git a/widget/gtk/Makefile.in b/widget/gtk/Makefile.in
index bf88269a18528..089f475585a2c 100644
--- a/widget/gtk/Makefile.in
+++ b/widget/gtk/Makefile.in
@@ -12,8 +12,6 @@ CXXFLAGS        += $(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS) \
 CFLAGS          += $(TK_CFLAGS)
 CXXFLAGS        += $(TK_CFLAGS)
 
-DEFINES		+= -DCAIRO_GFX -DMOZ_APP_NAME='"$(MOZ_APP_NAME)"'
-
 INCLUDES	+= \
 		-I$(srcdir)/../xpwidgets \
 		-I$(srcdir)/../shared \
diff --git a/widget/gtk/moz.build b/widget/gtk/moz.build
index 5ea228a15b9d3..f5d4d777b6eef 100644
--- a/widget/gtk/moz.build
+++ b/widget/gtk/moz.build
@@ -80,3 +80,7 @@ else:
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['CAIRO_GFX'] = True
+
+DEFINES['MOZ_APP_NAME'] = '"%s"' % CONFIG['MOZ_APP_NAME']
diff --git a/widget/gtkxtbin/Makefile.in b/widget/gtkxtbin/Makefile.in
index 39a9541538e26..89188d36e8205 100644
--- a/widget/gtkxtbin/Makefile.in
+++ b/widget/gtkxtbin/Makefile.in
@@ -10,8 +10,6 @@ ifdef MOZ_ENABLE_GTK2
 CFLAGS		+= $(MOZ_GTK2_CFLAGS)
 endif
 
-DEFINES		+= -D_IMPL_GTKXTBIN_API
-
 INCLUDES	+= \
 		-I$(srcdir) \
 		$(NULL)
diff --git a/widget/gtkxtbin/moz.build b/widget/gtkxtbin/moz.build
index 9ca10b765cf9e..b8293e5049c16 100644
--- a/widget/gtkxtbin/moz.build
+++ b/widget/gtkxtbin/moz.build
@@ -14,3 +14,5 @@ if CONFIG['MOZ_ENABLE_GTK2']:
     ]
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['_IMPL_GTKXTBIN_API'] = True
diff --git a/widget/os2/Makefile.in b/widget/os2/Makefile.in
index 21e42a878e5cc..db811de8569b0 100644
--- a/widget/os2/Makefile.in
+++ b/widget/os2/Makefile.in
@@ -9,10 +9,6 @@ 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)
diff --git a/widget/os2/moz.build b/widget/os2/moz.build
index 93cc3621cbd66..14f7e330de7ca 100644
--- a/widget/os2/moz.build
+++ b/widget/os2/moz.build
@@ -28,3 +28,7 @@ SOURCES += [
 LIBRARY_NAME = 'wdgtos2'
 
 FINAL_LIBRARY = 'xul'
+
+DEFINES['USE_OS2_TOOLKIT_HEADERS'] = True
+
+DEFINES['MOZ_APP_DISPLAYNAME'] = '"%s"' % CONFIG['MOZ_APP_DISPLAYNAME']
diff --git a/widget/qt/Makefile.in b/widget/qt/Makefile.in
index ecb957c337e43..6f5c4a5fddde0 100644
--- a/widget/qt/Makefile.in
+++ b/widget/qt/Makefile.in
@@ -10,22 +10,6 @@ CXXFLAGS	+= $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_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 \
diff --git a/widget/qt/faststartupqt/Makefile.in b/widget/qt/faststartupqt/Makefile.in
index 4b4da16657d2a..989e7fe76db30 100644
--- a/widget/qt/faststartupqt/Makefile.in
+++ b/widget/qt/faststartupqt/Makefile.in
@@ -24,5 +24,3 @@ export:: $(EXPORT_SOURCES)
 LOCAL_INCLUDES += \
 	$(MOZ_QT_CFLAGS) \
 	$(NULL)
-
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)" -DMOZ_NO_MOZALLOC -DXPCOM_GLUE
diff --git a/widget/qt/faststartupqt/moz.build b/widget/qt/faststartupqt/moz.build
index aa14e14766045..177af102ccb0d 100644
--- a/widget/qt/faststartupqt/moz.build
+++ b/widget/qt/faststartupqt/moz.build
@@ -20,3 +20,12 @@ SOURCES += [
 ]
 
 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
diff --git a/widget/qt/moz.build b/widget/qt/moz.build
index 16a2dd26b9b20..d65045febc365 100644
--- a/widget/qt/moz.build
+++ b/widget/qt/moz.build
@@ -61,3 +61,16 @@ 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
diff --git a/widget/windows/Makefile.in b/widget/windows/Makefile.in
index 13c889b984f24..69ae8f627cbc3 100644
--- a/widget/windows/Makefile.in
+++ b/widget/windows/Makefile.in
@@ -4,15 +4,6 @@
 # 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. \
diff --git a/widget/windows/moz.build b/widget/windows/moz.build
index 16c00da872c22..1e31c64aa8595 100644
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -88,3 +88,9 @@ 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
diff --git a/widget/windows/winrt/Makefile.in b/widget/windows/winrt/Makefile.in
index 417cb7911b4fa..45ccc1aa127eb 100644
--- a/widget/windows/winrt/Makefile.in
+++ b/widget/windows/winrt/Makefile.in
@@ -2,16 +2,6 @@
 # License, v. 2.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 \
diff --git a/widget/windows/winrt/moz.build b/widget/windows/winrt/moz.build
index fe9e66d6c5729..586a505a1b230 100644
--- a/widget/windows/winrt/moz.build
+++ b/widget/windows/winrt/moz.build
@@ -28,3 +28,9 @@ EXTRA_COMPONENTS += [
 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
diff --git a/widget/xpwidgets/Makefile.in b/widget/xpwidgets/Makefile.in
index 1fc151267535f..031c55f9ee744 100644
--- a/widget/xpwidgets/Makefile.in
+++ b/widget/xpwidgets/Makefile.in
@@ -3,10 +3,6 @@
 # License, v. 2.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	+= \
diff --git a/widget/xpwidgets/moz.build b/widget/xpwidgets/moz.build
index 86a612230091a..616aec7848a56 100644
--- a/widget/xpwidgets/moz.build
+++ b/widget/xpwidgets/moz.build
@@ -75,3 +75,6 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gonk', 'android', 'qt', 'gtk2'
     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
diff --git a/widget/xremoteclient/Makefile.in b/widget/xremoteclient/Makefile.in
index c65c1a1e3d97b..1076b5c3b3835 100644
--- a/widget/xremoteclient/Makefile.in
+++ b/widget/xremoteclient/Makefile.in
@@ -7,8 +7,6 @@
 # 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))
diff --git a/widget/xremoteclient/moz.build b/widget/xremoteclient/moz.build
index 5b7217a9b0d67..4b12055dfe6a1 100644
--- a/widget/xremoteclient/moz.build
+++ b/widget/xremoteclient/moz.build
@@ -7,3 +7,5 @@
 PROGRAM = 'mozilla-xremote-client'
 
 FINAL_LIBRARY = 'xulapp_s'
+
+DEFINES['XPCOM_GLUE'] = True
diff --git a/xpcom/build/Makefile.in b/xpcom/build/Makefile.in
index c1ec63f65d73a..0f712e92af48f 100644
--- a/xpcom/build/Makefile.in
+++ b/xpcom/build/Makefile.in
@@ -23,15 +23,6 @@ LOCAL_INCLUDES	= \
 
 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
diff --git a/xpcom/build/moz.build b/xpcom/build/moz.build
index b4deb459277cb..c3885269a071c 100644
--- a/xpcom/build/moz.build
+++ b/xpcom/build/moz.build
@@ -69,3 +69,9 @@ 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']
diff --git a/xpcom/glue/Makefile.in b/xpcom/glue/Makefile.in
index d4c989b8ace6a..cf27052af67b9 100644
--- a/xpcom/glue/Makefile.in
+++ b/xpcom/glue/Makefile.in
@@ -16,9 +16,4 @@ 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
diff --git a/xpcom/glue/moz.build b/xpcom/glue/moz.build
index e5b47aed6baf9..97af35c55d47c 100644
--- a/xpcom/glue/moz.build
+++ b/xpcom/glue/moz.build
@@ -102,3 +102,9 @@ SDK_LIBRARY = [
 ]
 
 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']
diff --git a/xpcom/glue/nomozalloc/Makefile.in b/xpcom/glue/nomozalloc/Makefile.in
index 079592894998e..84043501d3782 100644
--- a/xpcom/glue/nomozalloc/Makefile.in
+++ b/xpcom/glue/nomozalloc/Makefile.in
@@ -24,11 +24,4 @@ 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
diff --git a/xpcom/glue/nomozalloc/moz.build b/xpcom/glue/nomozalloc/moz.build
index 0cc570a66232b..57d183664f914 100644
--- a/xpcom/glue/nomozalloc/moz.build
+++ b/xpcom/glue/nomozalloc/moz.build
@@ -22,3 +22,11 @@ SDK_LIBRARY = [
 
 # 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
diff --git a/xpcom/glue/standalone/Makefile.in b/xpcom/glue/standalone/Makefile.in
index 9221950a34fec..ae5265823e14b 100644
--- a/xpcom/glue/standalone/Makefile.in
+++ b/xpcom/glue/standalone/Makefile.in
@@ -19,11 +19,4 @@ 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
diff --git a/xpcom/glue/standalone/moz.build b/xpcom/glue/standalone/moz.build
index f336f6a2ff7ed..1abeca452e01f 100644
--- a/xpcom/glue/standalone/moz.build
+++ b/xpcom/glue/standalone/moz.build
@@ -29,3 +29,11 @@ SDK_LIBRARY = [
 ]
 
 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']
diff --git a/xpcom/glue/standalone/staticruntime/Makefile.in b/xpcom/glue/standalone/staticruntime/Makefile.in
index d854107d23098..89edca4a68d23 100644
--- a/xpcom/glue/standalone/staticruntime/Makefile.in
+++ b/xpcom/glue/standalone/staticruntime/Makefile.in
@@ -21,11 +21,4 @@ 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
diff --git a/xpcom/glue/standalone/staticruntime/moz.build b/xpcom/glue/standalone/staticruntime/moz.build
index d717d44e481cf..b38f972ecdda0 100644
--- a/xpcom/glue/standalone/staticruntime/moz.build
+++ b/xpcom/glue/standalone/staticruntime/moz.build
@@ -21,3 +21,11 @@ SDK_LIBRARY = [
 
 # 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']
diff --git a/xpcom/glue/staticruntime/Makefile.in b/xpcom/glue/staticruntime/Makefile.in
index a7a143d148130..d530e193b6fdd 100644
--- a/xpcom/glue/staticruntime/Makefile.in
+++ b/xpcom/glue/staticruntime/Makefile.in
@@ -22,9 +22,4 @@ 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
diff --git a/xpcom/glue/staticruntime/moz.build b/xpcom/glue/staticruntime/moz.build
index bf93358e19aa3..c016fc3d28191 100644
--- a/xpcom/glue/staticruntime/moz.build
+++ b/xpcom/glue/staticruntime/moz.build
@@ -21,3 +21,9 @@ SDK_LIBRARY = [
 ]
 
 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']
diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in
index 0f56e9976a37a..2969134195f0f 100644
--- a/xpcom/io/Makefile.in
+++ b/xpcom/io/Makefile.in
@@ -5,10 +5,4 @@
 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..
diff --git a/xpcom/io/moz.build b/xpcom/io/moz.build
index 0ae81eb532938..74d1e8e1a92ae 100644
--- a/xpcom/io/moz.build
+++ b/xpcom/io/moz.build
@@ -127,3 +127,6 @@ 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
diff --git a/xpcom/reflect/xptcall/src/md/os2/Makefile.in b/xpcom/reflect/xptcall/src/md/os2/Makefile.in
index 8d118f122b897..bfd197a92cfc2 100644
--- a/xpcom/reflect/xptcall/src/md/os2/Makefile.in
+++ b/xpcom/reflect/xptcall/src/md/os2/Makefile.in
@@ -9,8 +9,6 @@ LOCAL_INCLUDES = \
 		-I$(srcdir)/../unix \
 		-I$(srcdir)/../../../../xptinfo/src \
 		$(NULL)
-DEFINES		+= -DMOZ_NEED_LEADING_UNDERSCORE
-
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES	+= -I$(srcdir)/../..
diff --git a/xpcom/reflect/xptcall/src/md/os2/moz.build b/xpcom/reflect/xptcall/src/md/os2/moz.build
index 8943b15a42c91..3f4561636e683 100644
--- a/xpcom/reflect/xptcall/src/md/os2/moz.build
+++ b/xpcom/reflect/xptcall/src/md/os2/moz.build
@@ -10,3 +10,5 @@ SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xpcom_core'
+
+DEFINES['MOZ_NEED_LEADING_UNDERSCORE'] = True
diff --git a/xpcom/reflect/xptcall/src/md/unix/Makefile.in b/xpcom/reflect/xptcall/src/md/unix/Makefile.in
index 5ef8a45e304d7..07de632ab85c3 100644
--- a/xpcom/reflect/xptcall/src/md/unix/Makefile.in
+++ b/xpcom/reflect/xptcall/src/md/unix/Makefile.in
@@ -18,22 +18,6 @@ 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
 ######################################################################
diff --git a/xpcom/reflect/xptcall/src/md/unix/moz.build b/xpcom/reflect/xptcall/src/md/unix/moz.build
index 9a1a99243bf48..0e3b04131707e 100644
--- a/xpcom/reflect/xptcall/src/md/unix/moz.build
+++ b/xpcom/reflect/xptcall/src/md/unix/moz.build
@@ -16,6 +16,8 @@ if CONFIG['OS_ARCH'] == 'Darwin':
         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':
diff --git a/xpcom/sample/program/Makefile.in b/xpcom/sample/program/Makefile.in
index cf243e6f0d2ab..1b8e98f121e7f 100644
--- a/xpcom/sample/program/Makefile.in
+++ b/xpcom/sample/program/Makefile.in
@@ -17,7 +17,3 @@ 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
diff --git a/xpcom/sample/program/moz.build b/xpcom/sample/program/moz.build
index 05081e6626f65..8c32a9378320a 100644
--- a/xpcom/sample/program/moz.build
+++ b/xpcom/sample/program/moz.build
@@ -14,3 +14,7 @@ SOURCES += [
 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
diff --git a/xpcom/tests/bug656331_component/Makefile.in b/xpcom/tests/bug656331_component/Makefile.in
index 523a6c51d099f..fbd8c264150f3 100644
--- a/xpcom/tests/bug656331_component/Makefile.in
+++ b/xpcom/tests/bug656331_component/Makefile.in
@@ -24,8 +24,6 @@ EXTRA_DSO_LDOPTS += \
   $(NULL)
 endif
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
diff --git a/xpcom/tests/bug656331_component/moz.build b/xpcom/tests/bug656331_component/moz.build
index 68cfd97ac4947..eb92779936250 100644
--- a/xpcom/tests/bug656331_component/moz.build
+++ b/xpcom/tests/bug656331_component/moz.build
@@ -15,3 +15,9 @@ LIBRARY_NAME = 'test656331'
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
diff --git a/xpcom/tests/component/Makefile.in b/xpcom/tests/component/Makefile.in
index dbb8514fe655e..710b030ed58c7 100644
--- a/xpcom/tests/component/Makefile.in
+++ b/xpcom/tests/component/Makefile.in
@@ -22,8 +22,6 @@ EXTRA_DSO_LDOPTS += \
 		$(NULL)
 endif
 
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
-
 LIB_FILES = $(SHARED_LIBRARY)
 LIB_DEST = $(testxpcobjdir)/$(unittestlocation)
 INSTALL_TARGETS += LIB
diff --git a/xpcom/tests/component/moz.build b/xpcom/tests/component/moz.build
index 5d55dea24dd1a..82448ce4e0b79 100644
--- a/xpcom/tests/component/moz.build
+++ b/xpcom/tests/component/moz.build
@@ -15,3 +15,9 @@ LIBRARY_NAME = 'testcomponent'
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
diff --git a/xpcom/tests/component_no_aslr/Makefile.in b/xpcom/tests/component_no_aslr/Makefile.in
index f6d11543673d2..33c2c3eed285c 100644
--- a/xpcom/tests/component_no_aslr/Makefile.in
+++ b/xpcom/tests/component_no_aslr/Makefile.in
@@ -29,5 +29,3 @@ INSTALL_TARGETS += LIB
 include $(topsrcdir)/config/rules.mk
 
 LDFLAGS := $(filter-out -DYNAMICBASE,$(LDFLAGS)) -DYNAMICBASE:NO
-
-DEFINES += -DLIBRARY_FILENAME="$(SHARED_LIBRARY)"
diff --git a/xpcom/tests/component_no_aslr/moz.build b/xpcom/tests/component_no_aslr/moz.build
index 1e03dd7f1e6e4..0af8035fb631c 100644
--- a/xpcom/tests/component_no_aslr/moz.build
+++ b/xpcom/tests/component_no_aslr/moz.build
@@ -15,3 +15,9 @@ LIBRARY_NAME = 'testcompnoaslr'
 IS_COMPONENT = True
 
 FORCE_SHARED_LIB = True
+
+DEFINES['LIBRARY_FILENAME'] = '%s%s%s' % (
+    CONFIG['DLL_PREFIX'],
+    LIBRARY_NAME,
+    CONFIG['DLL_SUFFIX']
+)
diff --git a/xulrunner/app/Makefile.in b/xulrunner/app/Makefile.in
index 62dbe48d43726..f935caaee0ade 100644
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -8,13 +8,6 @@ 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 += \
diff --git a/xulrunner/app/moz.build b/xulrunner/app/moz.build
index e809fc88be459..dc549308f322e 100644
--- a/xulrunner/app/moz.build
+++ b/xulrunner/app/moz.build
@@ -11,3 +11,9 @@ 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']
diff --git a/xulrunner/setup/Makefile.in b/xulrunner/setup/Makefile.in
deleted file mode 100644
index e36fc237f8035..0000000000000
--- 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)
diff --git a/xulrunner/setup/moz.build b/xulrunner/setup/moz.build
index 6ff4682e8b04b..5f97e9dd33690 100644
--- a/xulrunner/setup/moz.build
+++ b/xulrunner/setup/moz.build
@@ -17,3 +17,5 @@ EXTRA_COMPONENTS += [
 EXTRA_PP_COMPONENTS += [
     'nsXULAppInstall.js',
 ]
+
+DEFINES['BIN_SUFFIX'] = CONFIG['BIN_SUFFIX']
diff --git a/xulrunner/stub/Makefile.in b/xulrunner/stub/Makefile.in
index bba6c240ba1a1..b7775887aaf29 100644
--- a/xulrunner/stub/Makefile.in
+++ b/xulrunner/stub/Makefile.in
@@ -12,7 +12,6 @@ LOCAL_INCLUDES = \
   -I$(topsrcdir)/xpcom/base \
   $(NULL)
 
-DEFINES  += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS = \
diff --git a/xulrunner/stub/moz.build b/xulrunner/stub/moz.build
index c1f98b8e04f07..dcce9657d0b65 100644
--- a/xulrunner/stub/moz.build
+++ b/xulrunner/stub/moz.build
@@ -16,3 +16,5 @@ SOURCES += [
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     FINAL_TARGET = 'dist/XUL.framework/Versions/%(MOZILLA_VERSION)s' % CONFIG
+
+DEFINES['XPCOM_GLUE'] = True
diff --git a/xulrunner/tools/redit/Makefile.in b/xulrunner/tools/redit/Makefile.in
index f831e13b38a09..54c99dcbb0843 100644
--- a/xulrunner/tools/redit/Makefile.in
+++ b/xulrunner/tools/redit/Makefile.in
@@ -8,12 +8,6 @@ SDK_BINARY =  \
 	$(PROGRAM) \
 	$(NULL)
 
-DEFINES += -DWIN32_LEAN_AND_MEAN \
-					 -DUNICODE \
-					 -D_UNICODE \
-					 -DXPCOM_GLUE \
-					 $(NULL)
-
 LIBS = \
   $(XPCOM_STANDALONE_GLUE_LDOPTS) \
   $(NULL)
diff --git a/xulrunner/tools/redit/moz.build b/xulrunner/tools/redit/moz.build
index 00d5f4a9dcbbf..0eb0c94a938f1 100644
--- a/xulrunner/tools/redit/moz.build
+++ b/xulrunner/tools/redit/moz.build
@@ -9,3 +9,5 @@ if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'redit.cpp',
     ]
+    for var in ('WIN32_LEAN_AND_MEAN', 'UNICODE', '_UNICODE', 'XPCOM_GLUE'):
+        DEFINES[var] = True
-- 
GitLab