Add support for building with _GLIBCXX_DEBUG.  New configure option
--enable-expensive-checks allows the developer to enable runtime
checking that can greatly increase compile time.  Currently it only
turns on _GLIBCXX_DEBUG.  Other expensive debugging checks added later
should be controlled by this configure option.

This patch also updates llvm-config with a --cppflags option to inform
llvm-gcc how to build itself so that it is compatible with an llvm that
was built with _GLIBCXX_DEBUG.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37777 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Makefile.rules b/Makefile.rules
index d83f2fa..3da1135 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -260,6 +260,13 @@
   C.Flags   += -D_DEBUG
 endif
 
+# If DISABLE_EXPENSIVE_CHECKS=1 is specified (make command line or configured),
+# then disable expensive checks by defining the appropriate preprocessor symbols.
+ifdef ENABLE_EXPENSIVE_CHECKS
+  BuildMode := $(BuildMode)+Checks
+  CXX.Flags += -D_GLIBCXX_DEBUG
+endif
+
 ifeq ($(ENABLE_PIC),1)
   CXX.Flags += -fPIC
   C.Flags   += -fPIC
@@ -267,7 +274,8 @@
 
 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
 C.Flags       += $(CFLAGS)
-CPP.BaseFlags += $(CPPFLAGS)
+CPP.Defines   += $(CPPFLAGS)
+CPP.BaseFlags += $(CPP.Defines)
 LD.Flags      += $(LDFLAGS)
 AR.Flags      := cru
 LibTool.Flags := --tag=CXX