[Mesa-dev] [PATCH] Rename the DEBUG macro to MESA_DEBUG

Vedran Miletić vedran at miletic.net
Thu Jul 21 17:48:46 UTC 2016


LLVM and Mesa both define the DEBUG macro in incompatible ways. As a
general practice, we should avoid using such generic names when it is
possible to do so.

This patch renames all occurrences of the DEBUG macro to MESA_DEBUG,
and removes workarounds previously used to enable building Mesa with
LLVM (pop_macro() and push_macro() function calls).

Please let me know if I missed any.

Signed-off-by: Vedran Miletić <vedran at miletic.net>
---
 configure.ac                                       |  2 +-
 src/compiler/glsl/ir_validate.cpp                  |  4 +-
 src/compiler/nir/nir.h                             |  6 +-
 src/compiler/nir/nir_metadata.c                    |  4 +-
 src/compiler/nir/nir_validate.c                    |  5 +-
 src/egl/drivers/haiku/egl_haiku.cpp                |  6 +-
 src/egl/main/eglconfig.c                           |  6 +-
 src/gallium/auxiliary/draw/draw_cliptest_tmp.h     |  4 +-
 src/gallium/auxiliary/gallivm/lp_bld_debug.h       | 12 ++--
 src/gallium/auxiliary/gallivm/lp_bld_init.c        | 16 +++---
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp      | 23 ++------
 src/gallium/auxiliary/gallivm/lp_bld_struct.c      | 16 +++---
 src/gallium/auxiliary/os/os_memory.h               |  6 +-
 src/gallium/auxiliary/os/os_misc.c                 |  4 +-
 src/gallium/auxiliary/os/os_misc.h                 |  6 +-
 .../auxiliary/pipebuffer/pb_buffer_fenced.c        | 10 ++--
 src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c |  6 +-
 src/gallium/auxiliary/tgsi/tgsi_exec.c             | 16 +++---
 src/gallium/auxiliary/tgsi/tgsi_ureg.c             |  8 +--
 src/gallium/auxiliary/util/u_cache.c               | 16 +++---
 src/gallium/auxiliary/util/u_cpu_detect.c          |  8 +--
 src/gallium/auxiliary/util/u_debug.c               | 18 +++---
 src/gallium/auxiliary/util/u_debug.h               | 66 +++++++++++-----------
 src/gallium/auxiliary/util/u_debug_flush.c         |  4 +-
 src/gallium/auxiliary/util/u_debug_flush.h         |  6 +-
 src/gallium/auxiliary/util/u_debug_image.c         |  4 +-
 src/gallium/auxiliary/util/u_debug_image.h         |  8 +--
 src/gallium/drivers/freedreno/ir3/ir3.c            | 16 +++---
 src/gallium/drivers/freedreno/ir3/ir3.h            | 18 +++---
 src/gallium/drivers/freedreno/ir3/ir3_print.c      |  4 +-
 src/gallium/drivers/freedreno/ir3/ir3_ra.c         |  4 +-
 src/gallium/drivers/i915/i915_debug.c              |  6 +-
 src/gallium/drivers/i915/i915_debug.h              |  6 +-
 src/gallium/drivers/ilo/core/ilo_debug.h           | 17 +++---
 src/gallium/drivers/llvmpipe/lp_debug.h            |  6 +-
 src/gallium/drivers/llvmpipe/lp_perf.h             |  6 +-
 src/gallium/drivers/llvmpipe/lp_rast.c             |  4 +-
 src/gallium/drivers/llvmpipe/lp_rast.h             |  4 +-
 src/gallium/drivers/llvmpipe/lp_rast_priv.h        |  6 +-
 src/gallium/drivers/llvmpipe/lp_scene.c            |  4 +-
 src/gallium/drivers/llvmpipe/lp_screen.c           |  8 +--
 src/gallium/drivers/llvmpipe/lp_setup_line.c       |  4 +-
 src/gallium/drivers/llvmpipe/lp_setup_point.c      |  4 +-
 src/gallium/drivers/llvmpipe/lp_state_sampler.c    |  4 +-
 src/gallium/drivers/llvmpipe/lp_test_main.c        |  4 +-
 src/gallium/drivers/llvmpipe/lp_texture.c          | 24 ++++----
 src/gallium/drivers/llvmpipe/lp_texture.h          |  4 +-
 .../drivers/nouveau/codegen/nv50_ir_driver.h       |  6 +-
 .../drivers/nouveau/codegen/nv50_ir_inlines.h      |  4 +-
 src/gallium/drivers/nouveau/nouveau_screen.h       |  4 +-
 src/gallium/drivers/nouveau/nouveau_statebuf.h     | 10 ++--
 src/gallium/drivers/nouveau/nv50/nv50_program.c    |  6 +-
 src/gallium/drivers/nouveau/nvc0/nvc0_program.c    | 14 ++---
 src/gallium/drivers/nouveau/nvc0/nve4_compute.c    | 12 ++--
 src/gallium/drivers/r300/r300_cb.h                 |  6 +-
 src/gallium/drivers/r300/r300_context.c            |  6 +-
 src/gallium/drivers/r300/r300_cs.h                 |  6 +-
 src/gallium/drivers/softpipe/sp_tex_sample.c       |  4 +-
 src/gallium/drivers/svga/svga_debug.h              |  8 +--
 src/gallium/drivers/svga/svga_draw.c               |  6 +-
 src/gallium/drivers/svga/svga_format.c             |  6 +-
 src/gallium/drivers/svga/svga_pipe_draw.c          |  4 +-
 .../drivers/svga/svga_resource_buffer_upload.c     |  4 +-
 src/gallium/drivers/svga/svga_screen.c             | 18 +++---
 src/gallium/drivers/svga/svga_screen.h             |  6 +-
 src/gallium/drivers/svga/svga_state.c              |  6 +-
 src/gallium/drivers/svga/svga_state_constants.c    |  4 +-
 src/gallium/drivers/svga/svga_state_fs.c           | 10 ++--
 .../drivers/swr/rasterizer/jitter/JitManager.cpp   |  5 --
 .../drivers/swr/rasterizer/jitter/JitManager.h     |  6 --
 src/gallium/drivers/swr/swr_shader.cpp             |  4 --
 src/gallium/drivers/swr/swr_state.cpp              |  4 --
 src/gallium/drivers/trace/tr_context.h             |  4 +-
 src/gallium/drivers/vc4/vc4_cl.h                   | 20 +++----
 src/gallium/drivers/vc4/vc4_qir_validate.c         |  4 +-
 src/gallium/drivers/vc4/vc4_qpu_validate.c         |  4 +-
 src/gallium/state_trackers/glx/xlib/glx_usefont.c  | 16 +++---
 src/gallium/state_trackers/hgl/hgl.c               |  6 +-
 src/gallium/state_trackers/nine/basetexture9.c     |  8 +--
 src/gallium/state_trackers/nine/basetexture9.h     |  6 +-
 src/gallium/state_trackers/nine/nine_debug.h       | 30 +++++-----
 src/gallium/state_trackers/nine/nine_dump.c        |  4 +-
 src/gallium/state_trackers/nine/nine_dump.h        |  4 +-
 src/gallium/state_trackers/nine/nine_ff.c          |  4 +-
 src/gallium/state_trackers/nine/surface9.c         |  4 +-
 src/gallium/state_trackers/nine/surface9.h         |  4 +-
 src/gallium/state_trackers/nine/volume9.c          |  4 +-
 src/gallium/state_trackers/wgl/stw_device.c        |  8 +--
 src/gallium/state_trackers/wgl/stw_device.h        |  4 +-
 src/gallium/state_trackers/wgl/stw_ext_pbuffer.c   |  4 +-
 .../targets/haiku-softpipe/GalliumContext.cpp      |  6 +-
 .../targets/haiku-softpipe/SoftwareRenderer.cpp    |  6 +-
 src/gallium/winsys/i915/drm/i915_drm_buffer.c      |  4 +-
 .../winsys/svga/drm/pb_buffer_simple_fenced.c      | 10 ++--
 src/gallium/winsys/svga/drm/vmw_buffer.c           | 16 +++---
 src/gallium/winsys/svga/drm/vmw_buffer.h           |  6 +-
 src/gallium/winsys/svga/drm/vmw_context.c          | 32 +++++------
 src/gallium/winsys/svga/drm/vmw_screen_ioctl.c     |  4 +-
 src/gallium/winsys/svga/drm/vmw_screen_pools.c     |  4 +-
 src/gallium/winsys/svga/drm/vmw_shader.c           |  4 +-
 src/gallium/winsys/svga/drm/vmw_surface.c          |  4 +-
 src/gallium/winsys/sw/hgl/hgl_sw_winsys.c          |  6 +-
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c  |  6 +-
 src/glx/glxext.c                                   |  8 +--
 src/glx/xfont.c                                    | 18 +++---
 src/intel/vulkan/anv_entrypoints_gen.py            |  6 +-
 src/intel/vulkan/anv_private.h                     | 18 +++---
 src/mapi/mapi_abi.py                               |  6 +-
 src/mesa/drivers/dri/i915/intel_batchbuffer.h      | 18 +++---
 src/mesa/drivers/dri/i965/brw_context.h            |  4 +-
 src/mesa/drivers/dri/i965/brw_disasm.c             |  4 +-
 .../drivers/dri/i965/brw_performance_monitor.c     |  8 +--
 src/mesa/drivers/dri/i965/intel_batchbuffer.c      |  4 +-
 src/mesa/drivers/dri/i965/intel_batchbuffer.h      | 14 ++---
 src/mesa/drivers/dri/radeon/radeon_debug.h         |  6 +-
 src/mesa/drivers/x11/xfonts.c                      | 16 +++---
 src/mesa/drivers/x11/xm_tri.c                      | 10 ++--
 src/mesa/main/context.c                            | 12 ++--
 src/mesa/main/debug.c                              |  8 +--
 src/mesa/main/errors.c                             | 22 ++++----
 src/mesa/main/feedback.c                           |  4 +-
 src/mesa/main/formats.c                            |  4 +-
 src/mesa/main/imports.c                            |  8 +--
 src/mesa/main/macros.h                             |  6 +-
 src/mesa/main/mtypes.h                             |  6 +-
 src/mesa/main/shaderapi.c                          |  8 +--
 src/mesa/main/teximage.c                           |  4 +-
 src/mesa/program/prog_optimize.c                   |  8 +--
 src/mesa/sparc/sparc.c                             |  4 +-
 src/mesa/state_tracker/st_atom.c                   | 12 +---
 src/mesa/state_tracker/st_atom_framebuffer.c       |  4 +-
 src/mesa/state_tracker/st_debug.c                  |  8 +--
 src/mesa/state_tracker/st_debug.h                  |  6 +-
 src/mesa/state_tracker/st_format.c                 |  6 +-
 src/mesa/swrast/s_lines.c                          |  6 +-
 src/mesa/swrast/s_span.c                           |  4 +-
 src/mesa/swrast/s_texfetch.c                       |  4 +-
 src/mesa/swrast/s_triangle.c                       |  6 +-
 src/mesa/vbo/vbo_exec.h                            |  4 +-
 src/mesa/vbo/vbo_exec_api.c                        | 12 ++--
 src/mesa/x86-64/x86-64.c                           |  4 +-
 src/util/ralloc.c                                  | 12 ++--
 142 files changed, 569 insertions(+), 611 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3799d8d..1774345 100644
--- a/configure.ac
+++ b/configure.ac
@@ -495,7 +495,7 @@ if test "x$enable_profile" = xyes; then
 fi
 
 if test "x$enable_debug" = xyes; then
-    DEFINES="$DEFINES -DDEBUG"
+    DEFINES="$DEFINES -DMESA_DEBUG"
     if test "x$enable_profile" = xyes; then
         AC_MSG_WARN([Debug and Profile are enabled at the same time])
     fi
diff --git a/src/compiler/glsl/ir_validate.cpp b/src/compiler/glsl/ir_validate.cpp
index 126f9bf..3e1d98a 100644
--- a/src/compiler/glsl/ir_validate.cpp
+++ b/src/compiler/glsl/ir_validate.cpp
@@ -915,7 +915,7 @@ validate_ir_tree(exec_list *instructions)
     * and it's half composed of assert()s anyway which wouldn't do
     * anything.
     */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    ir_validate v;
 
    v.run(instructions);
@@ -923,5 +923,5 @@ validate_ir_tree(exec_list *instructions)
    foreach_in_list(ir_instruction, ir, instructions) {
       visit_tree(ir, check_node_type, NULL);
    }
-#endif
+#endif /* MESA_DEBUG */
 }
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index a80f9c9..32abb32 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2246,7 +2246,7 @@ nir_function_impl *nir_function_impl_clone(const nir_function_impl *fi);
 nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);
 nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void nir_validate_shader(nir_shader *shader);
 void nir_metadata_set_validation_flag(nir_shader *shader);
 void nir_metadata_check_validation_flag(nir_shader *shader);
@@ -2261,12 +2261,12 @@ should_clone_nir(void)
 
    return should_clone;
 }
-#else
+#else /* MESA_DEBUG */
 static inline void nir_validate_shader(nir_shader *shader) { (void) shader; }
 static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
 static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
 static inline bool should_clone_nir(void) { return false; }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 #define _PASS(nir, do_pass) do {                                     \
    do_pass                                                           \
diff --git a/src/compiler/nir/nir_metadata.c b/src/compiler/nir/nir_metadata.c
index 9e1cff5..ab97280 100644
--- a/src/compiler/nir/nir_metadata.c
+++ b/src/compiler/nir/nir_metadata.c
@@ -53,7 +53,7 @@ nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved)
    impl->valid_metadata &= preserved;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 /**
  * Make sure passes properly invalidate metadata (part 1).
  *
@@ -87,4 +87,4 @@ nir_metadata_check_validation_flag(nir_shader *shader)
       }
    }
 }
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 63e85cf..0e3332d 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -35,7 +35,7 @@
 /* Since this file is just a pile of asserts, don't bother compiling it if
  * we're not building a debug build.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 /*
  * Per-register validation state.
@@ -1189,5 +1189,4 @@ nir_validate_shader(nir_shader *shader)
 
    destroy_validate_state(&state);
 }
-
-#endif /* NDEBUG */
+#endif /* MESA_DEBUG */
diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp
index ef74f65..6fedcac 100644
--- a/src/egl/drivers/haiku/egl_haiku.cpp
+++ b/src/egl/drivers/haiku/egl_haiku.cpp
@@ -41,13 +41,13 @@
 #include <OpenGLKit.h>
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #	define TRACE(x...) printf("egl_haiku: " x)
 #	define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #	define TRACE(x...)
 #	define CALLED()
-#endif
+#endif /* MESA_DEBUG */
 #define ERROR(x...) printf("egl_haiku: " x)
 
 
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index 435d924..92de1c8 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -470,11 +470,11 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
       }
 
       if (!matched) {
-#ifndef DEBUG
-         /* only print the common errors when DEBUG is not defined */
+#ifndef MESA_DEBUG
+         /* only print the common errors when MESA_DEBUG is not defined */
          if (attr != EGL_RENDERABLE_TYPE)
             break;
-#endif
+#endif /* MESA_DEBUG */
          _eglLog(_EGL_DEBUG,
                "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)",
                val, attr, cmp);
diff --git a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
index 6fbefa5..a83a104 100644
--- a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
+++ b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
@@ -170,7 +170,7 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
 	 position[2] = position[2] * w * scale[2] + trans[2];
 	 position[3] = w;
       }
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* For debug builds, set the clipped vertex's window coordinate
        * to NaN to help catch potential errors later.
        */
@@ -181,7 +181,7 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
          position[2] =
          position[3] = zero / zero; /* MSVC doesn't accept 0.0 / 0.0 */
       }
-#endif
+#endif /* MESA_DEBUG */
 
       if ((flags & DO_EDGEFLAG) && ef) {
          const float *edgeflag = out->data[ef];
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
index f96a1af..d88e13b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
@@ -53,27 +53,27 @@ extern "C" {
 #endif
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 extern unsigned gallivm_debug;
-#else
+#else /* MESA_DEBUG */
 #define gallivm_debug 0
-#endif
+#endif /* MESA_DEBUG */
 
 
 static inline void
 lp_build_name(LLVMValueRef val, const char *format, ...)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    char name[32];
    va_list ap;
    va_start(ap, format);
    util_vsnprintf(name, sizeof name, format, ap);
    va_end(ap);
    LLVMSetValueName(val, name);
-#else
+#else /* MESA_DEBUG */
    (void)val;
    (void)format;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 22340c0..99c08db 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -53,7 +53,7 @@ static bool USE_MCJIT = 0;
 #endif
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 unsigned gallivm_debug = 0;
 
 static const struct debug_named_value lp_bld_debug_flags[] = {
@@ -71,7 +71,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
 };
 
 DEBUG_GET_ONCE_FLAGS_OPTION(gallivm_debug, "GALLIVM_DEBUG", lp_bld_debug_flags, 0)
-#endif
+#endif /* MESA_DEBUG */
 
 
 static boolean gallivm_initialized = FALSE;
@@ -401,16 +401,16 @@ lp_build_init(void)
    LLVMLinkInJIT();
 #endif
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    gallivm_debug = debug_get_option_gallivm_debug();
-#endif
+#endif /* MESA_DEBUG */
 
    lp_set_target_options();
 
    util_cpu_detect();
 
    /* For simulating less capable machines */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_get_bool_option("LP_FORCE_SSE2", FALSE)) {
       assert(util_cpu_caps.has_sse2);
       util_cpu_caps.has_sse3 = 0;
@@ -422,7 +422,7 @@ lp_build_init(void)
       util_cpu_caps.has_f16c = 0;
       util_cpu_caps.has_fma = 0;
    }
-#endif
+#endif /* MESA_DEBUG */
 
    /* AMD Bulldozer AVX's throughput is the same as SSE2; and because using
     * 8-wide vector needs more floating ops than 4-wide (due to padding), it is
@@ -528,13 +528,13 @@ gallivm_verify_function(struct gallivm_state *gallivm,
                         LLVMValueRef func)
 {
    /* Verify the LLVM IR.  If invalid, dump and abort */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (LLVMVerifyFunction(func, LLVMPrintMessageAction)) {
       lp_debug_dump_value(func);
       assert(0);
       return;
    }
-#endif
+#endif /* MESA_DEBUG */
 
    if (gallivm_debug & GALLIVM_DEBUG_IR) {
       /* Print the LLVM IR to stderr */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 791a470..60f1fda 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -50,12 +50,6 @@
 
 #include <stddef.h>
 
-// Workaround http://llvm.org/PR23628
-#if HAVE_LLVM >= 0x0307
-#  pragma push_macro("DEBUG")
-#  undef DEBUG
-#endif
-
 #include <llvm-c/Core.h>
 #include <llvm-c/ExecutionEngine.h>
 #include <llvm/Target/TargetOptions.h>
@@ -86,11 +80,6 @@
 #include <llvm/ExecutionEngine/JITEventListener.h>
 #endif
 
-// Workaround http://llvm.org/PR23628
-#if HAVE_LLVM >= 0x0307
-#  pragma pop_macro("DEBUG")
-#endif
-
 #include "c11/threads.h"
 #include "os/os_thread.h"
 #include "pipe/p_config.h"
@@ -496,20 +485,20 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
 #endif
 #endif
 
-#if defined(DEBUG) && HAVE_LLVM < 0x0307
+#if defined(MESA_DEBUG) && HAVE_LLVM < 0x0307
    options.JITEmitDebugInfo = true;
-#endif
+#endif /* MESA_DEBUG, HAVE_LLVM */
 
    /* XXX: Workaround http://llvm.org/PR21435 */
-#if defined(DEBUG) || defined(PROFILE) || \
+#if defined(MESA_DEBUG) || defined(PROFILE) || \
     (HAVE_LLVM >= 0x0303 && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)))
 #if HAVE_LLVM < 0x0304
    options.NoFramePointerElimNonLeaf = true;
-#endif
+#endif /* HAVE_LLVM */
 #if HAVE_LLVM < 0x0307
    options.NoFramePointerElim = true;
-#endif
-#endif
+#endif /* HAVE_LLVM */
+#endif /* MESA_DEBUG, PROFILE, HAVE_LLVM, PIPE_ARCH_X86, PIPE_ARCH_X86_64 */
 
    builder.setEngineKind(EngineKind::JIT)
           .setErrorStr(&Error)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index 067740b..29037f7 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -89,10 +89,10 @@ lp_build_array_get_ptr(struct gallivm_state *gallivm,
    indices[0] = lp_build_const_int32(gallivm, 0);
    indices[1] = index;
    element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, ARRAY_SIZE(indices), "");
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    lp_build_name(element_ptr, "&%s[%s]",
                  LLVMGetValueName(ptr), LLVMGetValueName(index));
-#endif
+#endif /* MESA_DEBUG */
    return element_ptr;
 }
 
@@ -108,9 +108,9 @@ lp_build_array_get(struct gallivm_state *gallivm,
    assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
    element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
    res = LLVMBuildLoad(gallivm->builder, element_ptr, "");
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
-#endif
+#endif /* MESA_DEBUG */
    return res;
 }
 
@@ -139,9 +139,9 @@ lp_build_pointer_get(LLVMBuilderRef builder,
    assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
    element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
    res = LLVMBuildLoad(builder, element_ptr, "");
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
-#endif
+#endif /* MESA_DEBUG */
    return res;
 }
 
@@ -158,9 +158,9 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder,
    element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
    res = LLVMBuildLoad(builder, element_ptr, "");
    LLVMSetAlignment(res, alignment);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
-#endif
+#endif /* MESA_DEBUG */
    return res;
 }
 
diff --git a/src/gallium/auxiliary/os/os_memory.h b/src/gallium/auxiliary/os/os_memory.h
index 46a6b6e..e3e5f17 100644
--- a/src/gallium/auxiliary/os/os_memory.h
+++ b/src/gallium/auxiliary/os/os_memory.h
@@ -67,14 +67,14 @@ os_free_aligned(void *ptr);
 }
 #endif
 
-#elif defined(PIPE_OS_WINDOWS) && defined(DEBUG) && !defined(DEBUG_MEMORY_IMPLEMENTATION)
+#elif defined(PIPE_OS_WINDOWS) && defined(MESA_DEBUG) && !defined(DEBUG_MEMORY_IMPLEMENTATION)
 
 #  include "os_memory_debug.h"
 
-#else
+#else /* PIPE_OS_WINDOWS, MESA_DEBUG, DEBUG_MEMORY_IMPLEMENTATION */
 
 #  include "os_memory_stdc.h"
 
-#endif
+#endif /* PIPE_OS_WINDOWS, MESA_DEBUG, DEBUG_MEMORY_IMPLEMENTATION */
 
 #endif /* _OS_MEMORY_H_ */
diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
index 82e4957..1f7545c 100644
--- a/src/gallium/auxiliary/os/os_misc.c
+++ b/src/gallium/auxiliary/os/os_misc.c
@@ -69,7 +69,7 @@ os_log_message(const char *message)
    static FILE *fout = NULL;
 
    if (!fout) {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* one-time init */
       const char *filename = os_get_option("GALLIUM_LOG_FILE");
       if (filename) {
@@ -83,7 +83,7 @@ os_log_message(const char *message)
          }
          fout = fopen(filename, mode);
       }
-#endif
+#endif /* MESA_DEBUG */
       if (!fout)
          fout = stderr;
    }
diff --git a/src/gallium/auxiliary/os/os_misc.h b/src/gallium/auxiliary/os/os_misc.h
index 403c8ee..9885f9c 100644
--- a/src/gallium/auxiliary/os/os_misc.h
+++ b/src/gallium/auxiliary/os/os_misc.h
@@ -66,11 +66,11 @@ extern "C" {
 /*
  * Abort the program.
  */
-#if defined(DEBUG)
+#if defined(MESA_DEBUG)
 #  define os_abort() do { os_break(); abort(); } while(0)
-#else
+#else /* MESA_DEBUG */
 #  define os_abort() abort()
-#endif
+#endif /* MESA_DEBUG */
 
 
 /*
diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
index 7717d78..71a33ba 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
@@ -196,7 +196,7 @@ fenced_buffer_copy_storage_to_cpu_locked(struct fenced_buffer *fenced_buf);
 static void
 fenced_manager_dump_locked(struct fenced_manager *fenced_mgr)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct pb_fence_ops *ops = fenced_mgr->ops;
    struct list_head *curr, *next;
    struct fenced_buffer *fenced_buf;
@@ -235,9 +235,9 @@ fenced_manager_dump_locked(struct fenced_manager *fenced_mgr)
       curr = next;
       next = curr->next;
    }
-#else
+#else /* MESA_DEBUG */
    (void)fenced_mgr;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
@@ -987,9 +987,9 @@ fenced_bufmgr_destroy(struct pb_manager *mgr)
          ;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* assert(!fenced_mgr->num_unfenced); */
-#endif
+#endif /* MESA_DEBUG */
 
    pipe_mutex_unlock(fenced_mgr->mutex);
    pipe_mutex_destroy(fenced_mgr->mutex);
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
index 4e36866..22697c7 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
@@ -47,7 +47,7 @@
 #include "pb_bufmgr.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 
 #define PB_DEBUG_CREATE_BACKTRACE 8
@@ -482,7 +482,7 @@ pb_debug_manager_create(struct pb_manager *provider,
 }
 
 
-#else /* !DEBUG */
+#else /* MESA_DEBUG */
 
 
 struct pb_manager *
@@ -493,4 +493,4 @@ pb_debug_manager_create(struct pb_manager *provider,
 }
 
 
-#endif /* !DEBUG */
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 1457c06..23b4ded 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -389,7 +389,7 @@ micro_exp2(union tgsi_exec_channel *dst,
    dst->f[2] = util_fast_exp2(src->f[2]);
    dst->f[3] = util_fast_exp2(src->f[3]);
 #else
-#if DEBUG
+#ifdef MESA_DEBUG
    /* Inf is okay for this instruction, so clamp it to silence assertions. */
    uint i;
    union tgsi_exec_channel clamped;
@@ -404,7 +404,7 @@ micro_exp2(union tgsi_exec_channel *dst,
       }
    }
    src = &clamped;
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
    dst->f[0] = powf(2.0f, src->f[0]);
    dst->f[1] = powf(2.0f, src->f[1]);
@@ -747,17 +747,17 @@ check_inf_or_nan(const union tgsi_exec_channel *chan)
 }
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static void
 print_chan(const char *msg, const union tgsi_exec_channel *chan)
 {
    debug_printf("%s = {%f, %f, %f, %f}\n",
                 msg, chan->f[0], chan->f[1], chan->f[2], chan->f[3]);
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static void
 print_temp(const struct tgsi_exec_machine *mach, uint index)
 {
@@ -773,7 +773,7 @@ print_temp(const struct tgsi_exec_machine *mach, uint index)
                    tmp->xyzw[i].f[3]);
    }
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
 void
@@ -1074,11 +1074,11 @@ tgsi_exec_machine_create(enum pipe_shader_type shader_type)
       mach->Temps[TGSI_EXEC_TEMP_HALF_I].xyzw[TGSI_EXEC_TEMP_HALF_C].f[i] = 0.5f;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* silence warnings */
    (void) print_chan;
    (void) print_temp;
-#endif
+#endif /* MESA_DEBUG */
 
    return mach;
 
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index b67c383..854d105 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -1108,14 +1108,14 @@ static void validate( unsigned opcode,
                       unsigned nr_dst,
                       unsigned nr_src )
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    const struct tgsi_opcode_info *info = tgsi_get_opcode_info( opcode );
    assert(info);
    if (info) {
       assert(nr_dst == info->num_dst);
       assert(nr_src == info->num_src);
    }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 struct ureg_emit_insn_result
@@ -2000,13 +2000,13 @@ const struct tgsi_token *ureg_finalize( struct ureg_program *ureg )
       tgsi_dump( tokens, 0 );
    }
 
-#if DEBUG
+#if MESA_DEBUG
    if (tokens && !tgsi_sanity_check(tokens)) {
       debug_printf("tgsi_ureg.c, sanity check failed on generated tokens:\n");
       tgsi_dump(tokens, 0);
       assert(0);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    
    return tokens;
diff --git a/src/gallium/auxiliary/util/u_cache.c b/src/gallium/auxiliary/util/u_cache.c
index c748cb9..5ae0802 100644
--- a/src/gallium/auxiliary/util/u_cache.c
+++ b/src/gallium/auxiliary/util/u_cache.c
@@ -56,9 +56,9 @@ struct util_cache_entry
    void *key;
    void *value;
    
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    unsigned count;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 
@@ -214,9 +214,9 @@ util_cache_set(struct util_cache *cache,
 
    util_cache_entry_destroy(cache, entry);
    
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    ++entry->count;
-#endif
+#endif /* MESA_DEBUG */
    
    entry->key = key;
    entry->hash = hash;
@@ -289,7 +289,7 @@ util_cache_destroy(struct util_cache *cache)
    if (!cache)
       return;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (cache->count >= 20*cache->size) {
       /* Normal approximation of the Poisson distribution */
       double mean = (double)cache->count/(double)cache->size;
@@ -302,7 +302,7 @@ util_cache_destroy(struct util_cache *cache)
          assert(z <= 6.0);
       }
    }
-#endif
+#endif /* MESA_DEBUG */
       
    util_cache_clear(cache);
    
@@ -341,7 +341,7 @@ util_cache_remove(struct util_cache *cache,
 static void
 ensure_sanity(const struct util_cache *cache)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    unsigned i, cnt = 0;
 
    assert(cache);
@@ -375,7 +375,7 @@ ensure_sanity(const struct util_cache *cache)
 
       assert(header == &cache->lru);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    (void)cache;
 }
diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c
index 3a51ab9..19fddcb 100644
--- a/src/gallium/auxiliary/util/u_cpu_detect.c
+++ b/src/gallium/auxiliary/util/u_cpu_detect.c
@@ -73,9 +73,9 @@
 #endif
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", FALSE)
-#endif
+#endif /* MESA_DEBUG */
 
 
 struct util_cpu_caps util_cpu_caps;
@@ -430,7 +430,7 @@ util_cpu_detect(void)
    check_os_altivec_support();
 #endif /* PIPE_ARCH_PPC */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_get_option_dump_cpu()) {
       debug_printf("util_cpu_caps.nr_cpus = %u\n", util_cpu_caps.nr_cpus);
 
@@ -456,7 +456,7 @@ util_cpu_detect(void)
       debug_printf("util_cpu_caps.has_altivec = %u\n", util_cpu_caps.has_altivec);
       debug_printf("util_cpu_caps.has_daz = %u\n", util_cpu_caps.has_daz);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    util_cpu_detect_initialized = TRUE;
 }
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 3a94b75..2bf10a9 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -110,7 +110,7 @@ debug_disable_error_message_boxes(void)
 }
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 debug_print_blob(const char *name, const void *blob, unsigned size)
 {
@@ -124,7 +124,7 @@ debug_print_blob(const char *name, const void *blob, unsigned size)
       debug_printf("%d:\t%08x\n", i, ublob[i]);
    }
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
 static boolean
@@ -412,13 +412,13 @@ debug_dump_flags(const struct debug_named_value *names, unsigned long value)
 }
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 debug_print_format(const char *msg, unsigned fmt )
 {
    debug_printf("%s: %s\n", msg, util_format_name(fmt));
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
 /** Return string name of given primitive type */
@@ -447,7 +447,7 @@ u_prim_name(enum pipe_prim_type prim)
 
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int fl_indent = 0;
 const char* fl_function[1024];
 
@@ -482,11 +482,11 @@ debug_funclog_enter_exit(const char* f, const int line, const char* file)
       debug_printf("  ");
    debug_printf("%s\n", f);
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 /**
  * Print PIPE_TRANSFER_x flags with a message.
  */
@@ -563,6 +563,4 @@ debug_print_usage_enum(const char *msg, enum pipe_resource_usage usage)
 
    debug_printf("%s: %s\n", msg, debug_dump_enum(names, usage));
 }
-
-
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index 7da7f53..ae6785b 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -90,14 +90,14 @@ debug_printf(const char *format, ...) _util_printf_format(1,2);
 static inline void
 debug_printf(const char *format, ...)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    va_list ap;
    va_start(ap, format);
    _debug_vprintf(format, ap);
    va_end(ap);
-#else
+#else /* MESA_DEBUG */
    (void) format; /* silence warning */
-#endif
+#endif /* MESA_DEBUG */
 }
 #endif
 
@@ -118,14 +118,14 @@ debug_printf(const char *format, ...)
    } while (0)
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
-#else
+#else /* MESA_DEBUG */
 #define debug_vprintf(_format, _ap) ((void)0)
-#endif
+#endif /* MESA_DEBUG */
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 /**
  * Dump a blob in hex to the same place that debug_printf sends its
  * messages.
@@ -135,10 +135,10 @@ void debug_print_blob( const char *name, const void *blob, unsigned size );
 /* Print a message along with a prettified format string
  */
 void debug_print_format(const char *msg, unsigned fmt );
-#else
+#else /* MESA_DEBUG */
 #define debug_print_blob(_name, _blob, _size) ((void)0)
 #define debug_print_format(_msg, _fmt) ((void)0)
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
@@ -153,11 +153,11 @@ debug_disable_error_message_boxes(void);
 /**
  * Hard-coded breakpoint.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_break() os_break()
-#else /* !DEBUG */
+#else /* MESA_DEBUG */
 #define debug_break() ((void)0)
-#endif /* !DEBUG */
+#endif /* MESA_DEBUG */
 
 
 long
@@ -185,11 +185,11 @@ void _debug_assert_fail(const char *expr,
  * For non debug builds the assert macro will expand to a no-op, so do not
  * call functions with side effects in the assert expression.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
-#else
+#else /* MESA_DEBUG */
 #define debug_assert(expr) (void)(0 && (expr))
-#endif
+#endif /* MESA_DEBUG */
 
 
 /** Override standard assert macro */
@@ -202,43 +202,43 @@ void _debug_assert_fail(const char *expr,
 /**
  * Output the current function name.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_checkpoint() \
    _debug_printf("%s\n", __FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #define debug_checkpoint() \
    ((void)0) 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
  * Output the full source code position.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_checkpoint_full() \
    _debug_printf("%s:%u:%s\n", __FILE__, __LINE__, __FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #define debug_checkpoint_full() \
    ((void)0) 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
  * Output a warning message. Muted on release version.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_warning(__msg) \
    _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
-#else
+#else /* MESA_DEBUG */
 #define debug_warning(__msg) \
    ((void)0) 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
  * Emit a warning message, but only once.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_warn_once(__msg) \
    do { \
       static bool warned = FALSE; \
@@ -248,22 +248,22 @@ void _debug_assert_fail(const char *expr,
          warned = TRUE; \
       } \
    } while (0)
-#else
+#else /* MESA_DEBUG */
 #define debug_warn_once(__msg) \
    ((void)0) 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
  * Output an error message. Not muted on release version.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define debug_error(__msg) \
    _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) 
-#else
+#else /* MESA_DEBUG */
 #define debug_error(__msg) \
    _debug_printf("error: %s\n", __msg)
-#endif
+#endif /* MESA_DEBUG */
 
 /**
  * Output a debug log message to the debug info callback.
@@ -346,7 +346,7 @@ debug_dump_flags(const struct debug_named_value *names,
 /**
  * Function enter exit loggers
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int debug_funclog_enter(const char* f, const int line, const char* file);
 void debug_funclog_exit(const char* f, const int line, const char* file);
 void debug_funclog_enter_exit(const char* f, const int line, const char* file);
@@ -369,7 +369,7 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file);
 #define DEBUG_FUNCLOG_ENTER_EXIT() \
    debug_funclog_enter_exit(__FUNCTION__, __LINE__, __FILE__)
 
-#else
+#else /* MESA_DEBUG */
 #define DEBUG_FUNCLOG_ENTER() \
    int __debug_decleration_work_around
 #define DEBUG_FUNCLOG_EXIT() \
@@ -377,7 +377,7 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file);
 #define DEBUG_FUNCLOG_EXIT_RET(ret) \
    do { (void)__debug_decleration_work_around; return ret; } while(0)
 #define DEBUG_FUNCLOG_ENTER_EXIT()
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
diff --git a/src/gallium/auxiliary/util/u_debug_flush.c b/src/gallium/auxiliary/util/u_debug_flush.c
index 52e72cd..176e38f 100644
--- a/src/gallium/auxiliary/util/u_debug_flush.c
+++ b/src/gallium/auxiliary/util/u_debug_flush.c
@@ -37,7 +37,7 @@
  * @author Thomas Hellstrom <thellstrom at vmware.com>
  */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include "pipe/p_compiler.h"
 #include "util/u_debug_stack.h"
 #include "util/u_debug.h"
@@ -385,4 +385,4 @@ debug_flush_ctx_destroy(struct debug_flush_ctx *fctx)
    util_hash_table_destroy(fctx->ref_hash);
    FREE(fctx);
 }
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/auxiliary/util/u_debug_flush.h b/src/gallium/auxiliary/util/u_debug_flush.h
index a604167..46ef1ae 100644
--- a/src/gallium/auxiliary/util/u_debug_flush.h
+++ b/src/gallium/auxiliary/util/u_debug_flush.h
@@ -36,7 +36,7 @@
  *
  * @author Thomas Hellstrom <thellstrom at vmware.com>
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 #ifndef U_DEBUG_FLUSH_H_
 #define U_DEBUG_FLUSH_H_
@@ -134,5 +134,5 @@ void debug_flush_flush(struct debug_flush_ctx *fctx);
 void debug_flush_cb_reference(struct debug_flush_ctx *fctx,
                               struct debug_flush_buf *fbuf);
 
-#endif
-#endif
+#endif /* U_DEBUG_FLUSH_H_*/
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/auxiliary/util/u_debug_image.c b/src/gallium/auxiliary/util/u_debug_image.c
index 98d73a6..db1b6d1 100644
--- a/src/gallium/auxiliary/util/u_debug_image.c
+++ b/src/gallium/auxiliary/util/u_debug_image.c
@@ -35,7 +35,7 @@
 #include <stdio.h>
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 /**
  * Dump an image to .ppm file.
@@ -345,4 +345,4 @@ error1:
    ;
 }
 
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/auxiliary/util/u_debug_image.h b/src/gallium/auxiliary/util/u_debug_image.h
index f190eec..bf2d713 100644
--- a/src/gallium/auxiliary/util/u_debug_image.h
+++ b/src/gallium/auxiliary/util/u_debug_image.h
@@ -32,7 +32,7 @@
 #include "pipe/p_format.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 struct pipe_context;
 struct pipe_surface;
 struct pipe_transfer;
@@ -61,14 +61,14 @@ void debug_dump_float_rgba_bmp(const char *filename,
 void debug_dump_ubyte_rgba_bmp(const char *filename,
                                unsigned width, unsigned height,
                                const ubyte *rgba, unsigned stride);
-#else
+#else /* MESA_DEBUG */
 #define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
 #define debug_dump_surface(pipe, prefix, surface) ((void)0)
 #define debug_dump_surface_bmp(pipe, filename, surface) ((void)0)
 #define debug_dump_transfer_bmp(filename, transfer, ptr) ((void)0)
 #define debug_dump_float_rgba_bmp(filename, width, height, rgba, stride) ((void)0)
 #define debug_dump_ubyte_rgba_bmp(filename, width, height, rgba, stride) ((void)0)
-#endif
+#endif /* MESA_DEBUG */
 
 
-#endif
+#endif /* U_DEBUG_IMAGE_H */
diff --git a/src/gallium/drivers/freedreno/ir3/ir3.c b/src/gallium/drivers/freedreno/ir3/ir3.c
index 78ec1cc..f5bbeb2 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3.c
@@ -617,10 +617,10 @@ static void insert_instr(struct ir3_block *block,
 		struct ir3_instruction *instr)
 {
 	struct ir3 *shader = block->shader;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	static uint32_t serialno = 0;
 	instr->serialno = ++serialno;
-#endif
+#endif /* MESA_DEBUG */
 	list_addtail(&instr->node, &block->instr_list);
 
 	if (is_input(instr))
@@ -630,10 +630,10 @@ static void insert_instr(struct ir3_block *block,
 struct ir3_block * ir3_block_create(struct ir3 *shader)
 {
 	struct ir3_block *block = ir3_alloc(shader, sizeof(*block));
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	static uint32_t serialno = 0;
 	block->serialno = ++serialno;
-#endif
+#endif /* MESA_DEBUG */
 	block->shader = shader;
 	list_inithead(&block->node);
 	list_inithead(&block->instr_list);
@@ -650,9 +650,9 @@ static struct ir3_instruction *instr_create(struct ir3_block *block, int nreg)
 	ptr  += sizeof(*instr);
 	instr->regs = (struct ir3_register **)ptr;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	instr->regs_max = nreg;
-#endif
+#endif /* MESA_DEBUG */
 
 	return instr;
 }
@@ -705,9 +705,9 @@ struct ir3_register * ir3_reg_create(struct ir3_instruction *instr,
 {
 	struct ir3 *shader = instr->block->shader;
 	struct ir3_register *reg = reg_create(shader, num, flags);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	debug_assert(instr->regs_count < instr->regs_max);
-#endif
+#endif /* MESA_DEBUG */
 	instr->regs[instr->regs_count++] = reg;
 	return reg;
 }
diff --git a/src/gallium/drivers/freedreno/ir3/ir3.h b/src/gallium/drivers/freedreno/ir3/ir3.h
index e0d0eee..fac59ec 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3.h
+++ b/src/gallium/drivers/freedreno/ir3/ir3.h
@@ -187,9 +187,9 @@ struct ir3_instruction {
 		IR3_INSTR_UNUSED= 0x2000,
 	} flags;
 	int repeat;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	unsigned regs_max;
-#endif
+#endif /* MESA_DEBUG */
 	unsigned regs_count;
 	struct ir3_register **regs;
 	union {
@@ -300,9 +300,9 @@ struct ir3_instruction {
 	/* Entry in ir3_block's instruction list: */
 	struct list_head node;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	uint32_t serialno;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 static inline struct ir3_instruction *
@@ -440,19 +440,19 @@ struct ir3_block {
 	 */
 	void *data;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	uint32_t serialno;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 static inline uint32_t
 block_id(struct ir3_block *block)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	return block->serialno;
-#else
+#else /* MESA_DEBUG */
 	return (uint32_t)(unsigned long)block;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 struct ir3 * ir3_create(struct ir3_compiler *compiler,
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_print.c b/src/gallium/drivers/freedreno/ir3/ir3_print.c
index 8aebf21..02ba06b 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_print.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_print.c
@@ -37,9 +37,9 @@ static void print_instr_name(struct ir3_instruction *instr)
 {
 	if (!instr)
 		return;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	printf("%04u:", instr->serialno);
-#endif
+#endif /* MESA_DEBUG */
 	printf("%04u:", instr->name);
 	printf("%03u: ", instr->depth);
 
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_ra.c b/src/gallium/drivers/freedreno/ir3/ir3_ra.c
index f70c779..337822a 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_ra.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_ra.c
@@ -511,9 +511,9 @@ ra_block_name_instructions(struct ir3_ra_ctx *ctx, struct ir3_block *block)
 	list_for_each_entry (struct ir3_instruction, instr, &block->instr_list, node) {
 		struct ir3_ra_instr_data *id = &ctx->instrd[instr->ip];
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 		instr->name = ~0;
-#endif
+#endif /* MESA_DEBUG */
 
 		ctx->instr_cnt++;
 
diff --git a/src/gallium/drivers/i915/i915_debug.c b/src/gallium/drivers/i915/i915_debug.c
index 19f887b..99fd00d 100644
--- a/src/gallium/drivers/i915/i915_debug.c
+++ b/src/gallium/drivers/i915/i915_debug.c
@@ -243,7 +243,7 @@ BITS(
    PRINTF(stream, ": 0x%x\n", ((dw) & himask) >> (lo));
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define MBZ( dw, hi, lo) do {							\
    unsigned x = (dw) >> (lo);				\
    unsigned lomask = (1 << (lo)) - 1;			\
@@ -251,10 +251,10 @@ BITS(
    himask = (1UL << (hi)) - 1;				\
    assert ((x & himask & ~lomask) == 0);	\
 } while (0)
-#else
+#else /* MESA_DEBUG */
 #define MBZ( dw, hi, lo) do {							\
 } while (0)
-#endif
+#endif /* MESA_DEBUG */
 
 static void
 FLAG(
diff --git a/src/gallium/drivers/i915/i915_debug.h b/src/gallium/drivers/i915/i915_debug.h
index 0f12a59..e46fee1 100644
--- a/src/gallium/drivers/i915/i915_debug.h
+++ b/src/gallium/drivers/i915/i915_debug.h
@@ -47,7 +47,7 @@ struct i915_winsys_batchbuffer;
 
 extern unsigned i915_debug;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static inline boolean
 I915_DBG_ON(unsigned flags)
 {
@@ -65,10 +65,10 @@ I915_DBG(unsigned flags, const char *fmt, ...)
       va_end(args);
    }
 }
-#else
+#else /* MESA_DEBUG */
 #define I915_DBG_ON(flags) (0)
 static inline void I915_DBG(unsigned flags, const char *fmt, ...) {}
-#endif
+#endif /* MESA_DEBUG */
 
 void i915_debug_init(struct i915_screen *i915);
 
diff --git a/src/gallium/drivers/ilo/core/ilo_debug.h b/src/gallium/drivers/ilo/core/ilo_debug.h
index 532a2aa..30e88ff 100644
--- a/src/gallium/drivers/ilo/core/ilo_debug.h
+++ b/src/gallium/drivers/ilo/core/ilo_debug.h
@@ -33,11 +33,11 @@
 #include "ilo_core.h"
 
 /* enable debug flags affecting hot pathes only with debug builds */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define ILO_DEBUG_HOT 1
-#else
+#else /* MESA_DEBUG */
 #define ILO_DEBUG_HOT 0
-#endif
+#endif /* MESA_DEBUG */
 
 enum ilo_debug {
    ILO_DEBUG_BATCH     = 1 << 0,
@@ -92,31 +92,28 @@ ilo_err(const char *format, ...)
 static inline void _util_printf_format(1, 2)
 ilo_warn(const char *format, ...)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    va_list ap;
 
    va_start(ap, format);
    _debug_vprintf(format, ap);
    va_end(ap);
-#else
-#endif
+#endif /* MESA_DEBUG */
 }
 
 static inline bool
 ilo_is_zeroed(const void *ptr, size_t size)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    size_t i;
 
    for (i = 0; i < size; i++) {
       if (*((const char *) ptr) != 0)
          return false;
    }
+#endif /* MESA_DEBUG */
 
    return true;
-#else
-   return true;
-#endif
 }
 
 #endif /* ILO_DEBUG_H */
diff --git a/src/gallium/drivers/llvmpipe/lp_debug.h b/src/gallium/drivers/llvmpipe/lp_debug.h
index 1038c5f..85efa6a 100644
--- a/src/gallium/drivers/llvmpipe/lp_debug.h
+++ b/src/gallium/drivers/llvmpipe/lp_debug.h
@@ -63,11 +63,11 @@ st_print_current(void);
 
 extern int LP_PERF;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 extern int LP_DEBUG;
-#else
+#else /* MESA_DEBUG */
 #define LP_DEBUG 0
-#endif
+#endif /* MESA_DEBUG */
 
 void st_debug_init( void );
 
diff --git a/src/gallium/drivers/llvmpipe/lp_perf.h b/src/gallium/drivers/llvmpipe/lp_perf.h
index 455adf7..ec300c9 100644
--- a/src/gallium/drivers/llvmpipe/lp_perf.h
+++ b/src/gallium/drivers/llvmpipe/lp_perf.h
@@ -69,15 +69,15 @@ extern struct lp_counters lp_count;
 
 
 /** Increment the named counter (only for debug builds) */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define LP_COUNT(counter) lp_count.counter++
 #define LP_COUNT_ADD(counter, incr)  lp_count.counter += (incr)
 #define LP_COUNT_GET(counter) (lp_count.counter)
-#else
+#else /* MESA_DEBUG */
 #define LP_COUNT(counter)
 #define LP_COUNT_ADD(counter, incr) (void)(incr)
 #define LP_COUNT_GET(counter) 0
-#endif
+#endif /* MESA_DEBUG */
 
 
 extern void
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 9e56c96..07ecbe0 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -49,11 +49,11 @@
 #include "lp_tex_sample.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int jit_line = 0;
 const struct lp_rast_state *jit_state = NULL;
 const struct lp_rasterizer_task *jit_task = NULL;
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.h b/src/gallium/drivers/llvmpipe/lp_rast.h
index d9be7f3..1743577 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast.h
@@ -131,11 +131,11 @@ struct lp_rast_plane {
  * Objects of this type are put into the lp_setup_context::data buffer.
  */
 struct lp_rast_triangle {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    float v[3][2];
    float pad0;
    float pad1;
-#endif
+#endif /* MESA_DEBUG */
 
    /* inputs for the shader */
    struct lp_rast_shader_inputs inputs;
diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
index 9aa7e87..4c8ef1e 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
@@ -45,7 +45,7 @@
 /* If we crash in a jitted function, we can examine jit_line and jit_state
  * to get some info.  This is not thread-safe, however.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 struct lp_rasterizer_task;
 extern int jit_line;
@@ -65,12 +65,12 @@ extern const struct lp_rasterizer_task *jit_task;
       jit_state = NULL; \
    } while (0)
 
-#else
+#else /* MESA_DEBUG */
 
 #define BEGIN_JIT_CALL(X, Y)
 #define END_JIT_CALL()
 
-#endif
+#endif /* MESA_DEBUG */
 
 
 struct lp_rasterizer;
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c
index 223be93..355666b 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.c
+++ b/src/gallium/drivers/llvmpipe/lp_scene.c
@@ -64,7 +64,7 @@ lp_scene_create( struct pipe_context *pipe )
 
    pipe_mutex_init(scene->mutex);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* Do some scene limit sanity checks here */
    {
       size_t maxBins = TILES_X * TILES_Y;
@@ -77,7 +77,7 @@ lp_scene_create( struct pipe_context *pipe )
       /* We'll also need space for at least one other data block */
       assert(maxCommandPlusData <= LP_SCENE_MAX_SIZE);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    return scene;
 }
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
index 61c3fb7..274abd1 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -51,7 +51,7 @@
 
 #include "state_tracker/sw_winsys.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int LP_DEBUG = 0;
 
 static const struct debug_named_value lp_debug_flags[] = {
@@ -69,7 +69,7 @@ static const struct debug_named_value lp_debug_flags[] = {
    { "fs", DEBUG_FS, NULL },
    DEBUG_NAMED_VALUE_END
 };
-#endif
+#endif /* MESA_DEBUG */
 
 int LP_PERF = 0;
 static const struct debug_named_value lp_perf_flags[] = {
@@ -601,9 +601,9 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
 
    util_cpu_detect();
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 );
-#endif
+#endif /* MESA_DEBUG */
 
    LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 );
 
diff --git a/src/gallium/drivers/llvmpipe/lp_setup_line.c b/src/gallium/drivers/llvmpipe/lp_setup_line.c
index 018130c..f3dff11 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_line.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_line.c
@@ -603,12 +603,12 @@ try_setup_line( struct lp_setup_context *setup,
    if (!line)
       return FALSE;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    line->v[0][0] = v1[0][0];
    line->v[1][0] = v2[0][0];   
    line->v[0][1] = v1[0][1];
    line->v[1][1] = v2[0][1];
-#endif
+#endif /* MESA_DEBUG */
 
    LP_COUNT(nr_tris);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c
index ddb6f0e..8936af0 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_point.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c
@@ -451,10 +451,10 @@ try_setup_point( struct lp_setup_context *setup,
    if (!point)
       return FALSE;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    point->v[0][0] = v0[0][0];
    point->v[0][1] = v0[0][1];
-#endif
+#endif /* MESA_DEBUG */
 
    LP_COUNT(nr_tris);
 
diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
index 4441f2a..9d1c596 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c
@@ -184,7 +184,7 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe,
       pipe_resource_reference(&view->texture, texture);
       view->context = pipe;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
      /*
       * This is possibly too lenient, but the primary reason is just
       * to catch state trackers which forget to initialize this, so
@@ -212,7 +212,7 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe,
          else
             assert(0);
       }
-#endif
+#endif /* MESA_DEBUG */
    }
 
    return view;
diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c
index 518ca27..1381508 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_main.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_main.c
@@ -390,12 +390,12 @@ int main(int argc, char **argv)
          n = atoi(argv[i]);
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (verbose >= 2) {
       gallivm_debug |= GALLIVM_DEBUG_IR;
       gallivm_debug |= GALLIVM_DEBUG_ASM;
    }
-#endif
+#endif /* MESA_DEBUG */
 
    if (fp) {
       /* Warm up the caches */
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index 36f1c6b..a4b52f0 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -54,9 +54,9 @@
 #include "state_tracker/sw_winsys.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static struct llvmpipe_resource resource_list;
-#endif
+#endif /* MESA_DEBUG */
 static unsigned id_counter = 0;
 
 
@@ -293,9 +293,9 @@ llvmpipe_resource_create_front(struct pipe_screen *_screen,
 
    lpr->id = id_counter++;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    insert_at_tail(&resource_list, lpr);
-#endif
+#endif /* MESA_DEBUG */
 
    return &lpr->base;
 
@@ -334,10 +334,10 @@ llvmpipe_resource_destroy(struct pipe_screen *pscreen,
       align_free(lpr->data);
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (lpr->next)
       remove_from_list(lpr);
-#endif
+#endif /* MESA_DEBUG */
 
    FREE(lpr);
 }
@@ -470,9 +470,9 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen,
 
    lpr->id = id_counter++;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    insert_at_tail(&resource_list, lpr);
-#endif
+#endif /* MESA_DEBUG */
 
    return &lpr->base;
 
@@ -763,7 +763,7 @@ llvmpipe_resource_size(const struct pipe_resource *resource)
 }
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 llvmpipe_print_resources(void)
 {
@@ -782,13 +782,13 @@ llvmpipe_print_resources(void)
    }
    debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total);
 }
-#endif
+#endif /* MESA_DEBUG */
 
 
 void
 llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* init linked list for tracking resources */
    {
       static boolean first_call = TRUE;
@@ -798,7 +798,7 @@ llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
          first_call = FALSE;
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 
    screen->resource_create = llvmpipe_resource_create;
 /*   screen->resource_create_front = llvmpipe_resource_create_front; */
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h
index 3d315bb..52a2c7c 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.h
+++ b/src/gallium/drivers/llvmpipe/lp_texture.h
@@ -90,10 +90,10 @@ struct llvmpipe_resource
 
    unsigned id;  /**< temporary, for debugging */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /** for linked list */
    struct llvmpipe_resource *prev, *next;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h b/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
index 58a5d38..eb29f89 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.h
@@ -59,15 +59,15 @@ struct nv50_ir_varying
 #define NV50_PROGRAM_IR_GLSL 2
 #define NV50_PROGRAM_IR_LLVM 3
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 # define NV50_IR_DEBUG_BASIC     (1 << 0)
 # define NV50_IR_DEBUG_VERBOSE   (2 << 0)
 # define NV50_IR_DEBUG_REG_ALLOC (1 << 2)
-#else
+#else /* MESA_DEBUG */
 # define NV50_IR_DEBUG_BASIC     0
 # define NV50_IR_DEBUG_VERBOSE   0
 # define NV50_IR_DEBUG_REG_ALLOC 0
-#endif
+#endif /* MESA_DEBUG *
 
 struct nv50_ir_prog_symbol
 {
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_inlines.h b/src/gallium/drivers/nouveau/codegen/nv50_ir_inlines.h
index 4cb53ab..7ee2764 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_inlines.h
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_inlines.h
@@ -222,7 +222,7 @@ Instruction *Value::getUniqueInsn() const
             return (*it)->getInsn();
       // should be unreachable and trigger assertion at the end
    }
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (reg.data.id < 0) {
       int n = 0;
       for (DefCIterator it = defs.begin(); n < 2 && it != defs.end(); ++it)
@@ -231,7 +231,7 @@ Instruction *Value::getUniqueInsn() const
       if (n > 1)
          WARN("value %%%i not uniquely defined\n", id); // return NULL ?
    }
-#endif
+#endif /* MESA_DEBUG */
    assert(defs.front()->get() == this);
    return defs.front()->getInsn();
 }
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h
index 28c4760..e08d511 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.h
+++ b/src/gallium/drivers/nouveau/nouveau_screen.h
@@ -4,9 +4,9 @@
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 # define NOUVEAU_ENABLE_DRIVER_STATISTICS
-#endif
+#endif /* MESA_DEBUG */
 
 typedef uint32_t u32;
 typedef uint16_t u16;
diff --git a/src/gallium/drivers/nouveau/nouveau_statebuf.h b/src/gallium/drivers/nouveau/nouveau_statebuf.h
index da5d797..e867b65 100644
--- a/src/gallium/drivers/nouveau/nouveau_statebuf.h
+++ b/src/gallium/drivers/nouveau/nouveau_statebuf.h
@@ -7,18 +7,18 @@
 struct nouveau_statebuf_builder
 {
    uint32_t* p;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    uint32_t* pend;
-#endif
+#endif /* MESA_DEBUG */
 };
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define sb_init(var) {var, var + sizeof(var) / sizeof((var)[0])}
 #define sb_data(sb, v) do {assert((sb).p != (sb).pend);  *(sb).p++ = (v);} while(0)
-#else
+#else /* MESA_DEBUG */
 #define sb_init(var) {var}
 #define sb_data(sb, v) *(sb).p++ = (v)
-#endif
+#endif /* MESA_DEBUG */
 
 static inline uint32_t sb_header(unsigned subc, unsigned mthd, unsigned size)
 {
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_program.c b/src/gallium/drivers/nouveau/nv50/nv50_program.c
index 2b66877..48bd858 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_program.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_program.c
@@ -358,12 +358,12 @@ nv50_program_translate(struct nv50_program *prog, uint16_t chipset,
 
    info->driverPriv = prog;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    info->optLevel = debug_get_num_option("NV50_PROG_OPTIMIZE", 3);
    info->dbgFlags = debug_get_num_option("NV50_PROG_DEBUG", 0);
-#else
+#else /* MESA_DEBUG */
    info->optLevel = 3;
-#endif
+#endif /* MESA_DEBUG */
 
    ret = nv50_ir_generate_code(info);
    if (ret) {
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
index 5fc2753..ee873e6 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
@@ -516,7 +516,7 @@ nvc0_program_create_tfb_state(const struct nv50_ir_prog_info *info,
    return tfb;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static void
 nvc0_program_dump(struct nvc0_program *prog)
 {
@@ -535,7 +535,7 @@ nvc0_program_dump(struct nvc0_program *prog)
    }
    debug_printf("\n");
 }
-#endif
+#endif /* MESA_DEBUG */
 
 bool
 nvc0_program_translate(struct nvc0_program *prog, uint16_t chipset,
@@ -578,12 +578,12 @@ nvc0_program_translate(struct nvc0_program *prog, uint16_t chipset,
 
    info->assignSlots = nvc0_program_assign_varying_slots;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    info->optLevel = debug_get_num_option("NV50_PROG_OPTIMIZE", 3);
    info->dbgFlags = debug_get_num_option("NV50_PROG_DEBUG", 0);
-#else
+#else /* MESA_DEBUG */
    info->optLevel = 3;
-#endif
+#endif /* MESA_DEBUG */
 
    ret = nv50_ir_generate_code(info);
    if (ret) {
@@ -764,10 +764,10 @@ nvc0_program_upload_code(struct nvc0_context *nvc0, struct nvc0_program *prog)
       }
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_get_bool_option("NV50_PROG_DEBUG", false))
       nvc0_program_dump(prog);
-#endif
+#endif /* MESA_DEBUG */
 
    if (!is_cp)
       nvc0->base.push_data(&nvc0->base, screen->text, prog->code_base,
diff --git a/src/gallium/drivers/nouveau/nvc0/nve4_compute.c b/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
index f1ea4d9..7c03277 100644
--- a/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
+++ b/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
@@ -27,9 +27,9 @@
 
 #include "codegen/nv50_ir_driver.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static void nve4_compute_dump_launch_desc(const struct nve4_cp_launch_desc *);
-#endif
+#endif /* MESA_DEBUG */
 
 
 int
@@ -619,10 +619,10 @@ nve4_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info)
 
    nve4_compute_upload_input(nvc0, info);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_get_num_option("NV50_PROG_DEBUG", 0))
       nve4_compute_dump_launch_desc(desc);
-#endif
+#endif /* MESA_DEBUG */
 
    if (unlikely(info->indirect)) {
       struct nv04_resource *res = nv04_resource(info->indirect);
@@ -757,7 +757,7 @@ nve4_compute_validate_textures(struct nvc0_context *nvc0)
 }
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static const char *nve4_cache_split_name(unsigned value)
 {
    switch (value) {
@@ -815,7 +815,7 @@ nve4_compute_dump_launch_desc(const struct nve4_cp_launch_desc *desc)
                    i, address, size, valid ? "" : "  (invalid)");
    }
 }
-#endif
+#endif /* MESA_DEBUG */
 
 #ifdef NOUVEAU_NVE4_MP_TRAP_HANDLER
 static void
diff --git a/src/gallium/drivers/r300/r300_cb.h b/src/gallium/drivers/r300/r300_cb.h
index e031e99..917626b 100644
--- a/src/gallium/drivers/r300/r300_cb.h
+++ b/src/gallium/drivers/r300/r300_cb.h
@@ -65,7 +65,7 @@
  * Command buffer setup.
  */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 #define CB_LOCALS \
     int cs_count = 0; \
@@ -93,7 +93,7 @@
 
 #define CB_USED_DW(x) cs_count -= x
 
-#else
+#else /* MESA_DEBUG */
 
 #define CB_LOCALS \
     uint32_t *cs_ptr = NULL; (void) cs_ptr
@@ -105,7 +105,7 @@
 #define END_CB
 #define CB_USED_DW(x)
 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index d100a9d..ddb6fee 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -480,11 +480,11 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     rc_init_regalloc_state(&r300->fs_regalloc_state);
 
     /* Print driver info. */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
     {
-#else
+#else /* MESA_DEBUG */
     if (DBG_ON(r300, DBG_INFO)) {
-#endif
+#endif /* MESA_DEBUG */
         fprintf(stderr,
                 "r300: DRM version: %d.%d.%d, Name: %s, ID: 0x%04x, GB: %d, Z: %d\n"
                 "r300: GART size: %"PRIu64" MB, VRAM size: %"PRIu64" MB\n"
diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h
index 727b9e2..7b97423 100644
--- a/src/gallium/drivers/r300/r300_cs.h
+++ b/src/gallium/drivers/r300/r300_cs.h
@@ -43,7 +43,7 @@
     struct radeon_winsys *cs_winsys = (context)->rws; \
     int cs_count = 0; (void) cs_count; (void) cs_winsys;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 #define BEGIN_CS(size) do { \
     assert(size <= (cs_copy->current.max_dw - cs_copy->current.cdw)); \
@@ -59,13 +59,13 @@
 
 #define CS_USED_DW(x) cs_count -= (x)
 
-#else
+#else /* MESA_DEBUG */
 
 #define BEGIN_CS(size)
 #define END_CS
 #define CS_USED_DW(x)
 
-#endif
+#endif /* MESA_DEBUG */
 
 /**
  * Writing pure DWORDs.
diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c
index 5998681..01c374c 100644
--- a/src/gallium/drivers/softpipe/sp_tex_sample.c
+++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
@@ -3479,7 +3479,7 @@ softpipe_create_sampler_view(struct pipe_context *pipe,
       pipe_resource_reference(&view->texture, resource);
       view->context = pipe;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
      /*
       * This is possibly too lenient, but the primary reason is just
       * to catch state trackers which forget to initialize this, so
@@ -3507,7 +3507,7 @@ softpipe_create_sampler_view(struct pipe_context *pipe,
          else
             assert(0);
       }
-#endif
+#endif /* MESA_DEBUG */
 
       if (any_swizzle(view)) {
          sview->need_swizzle = TRUE;
diff --git a/src/gallium/drivers/svga/svga_debug.h b/src/gallium/drivers/svga/svga_debug.h
index 039f79d..8791a94 100644
--- a/src/gallium/drivers/svga/svga_debug.h
+++ b/src/gallium/drivers/svga/svga_debug.h
@@ -46,18 +46,18 @@
 #define DEBUG_CACHE        0x8000
 #define DEBUG_STREAMOUT    0x10000
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 extern int SVGA_DEBUG;
 #define DBSTR(x) x
-#else
+#else /* MESA_DEBUG */
 #define SVGA_DEBUG 0
 #define DBSTR(x) ""
-#endif
+#endif /* MESA_DEBUG */
 
 static inline void
 SVGA_DBG( unsigned flag, const char *fmt, ... )
 {
-#ifdef DEBUG 
+#ifdef MESA_DEBUG
     if (SVGA_DEBUG & flag)
     {
         va_list args;
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index 600df89..080b7e1 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -892,13 +892,13 @@ svga_hwtnl_prim(struct svga_hwtnl *hwtnl,
    }
    else {
       /* batch up drawing commands */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       check_draw_params(hwtnl, range, min_index, max_index, ib);
       assert(start_instance == 0);
       assert(instance_count <= 1);
-#else
+#else /* MESA_DEBUG */
       (void) check_draw_params;
-#endif
+#endif /* MESA_DEBUG */
 
       if (hwtnl->cmd.prim_count + 1 >= QSZ) {
          ret = svga_hwtnl_flush(hwtnl);
diff --git a/src/gallium/drivers/svga/svga_format.c b/src/gallium/drivers/svga/svga_format.c
index 1b3cebe..c7ee005 100644
--- a/src/gallium/drivers/svga/svga_format.c
+++ b/src/gallium/drivers/svga/svga_format.c
@@ -1867,11 +1867,11 @@ svga_get_format_cap(struct svga_screen *ss,
    SVGA3dDevCapResult result;
    const struct format_cap *entry;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    check_format_tables();
-#else
+#else /* MESA_DEBUG */
    (void) check_format_tables;
-#endif
+#endif /* MESA_DEBUG */
 
    assert(format < ARRAY_SIZE(format_cap_table));
    entry = &format_cap_table[format];
diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c
index c9bcf3a..989aec9 100644
--- a/src/gallium/drivers/svga/svga_pipe_draw.c
+++ b/src/gallium/drivers/svga/svga_pipe_draw.c
@@ -212,11 +212,11 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
 
    svga_update_state_retry( svga, SVGA_STATE_NEED_SWTNL );
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (svga->curr.vs->base.id == svga->debug.disable_shader ||
        svga->curr.fs->base.id == svga->debug.disable_shader)
       return;
-#endif
+#endif /* MESA_DEBUG */
 
    if (svga->state.sw.need_swtnl) {
       svga->hud.num_fallbacks++;  /* for SVGA_QUERY_NUM_FALLBACKS */
diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c
index be4c694..f0a5797 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer_upload.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c
@@ -491,9 +491,9 @@ svga_buffer_upload_flush(struct svga_context *svga,
 
    assert(sbuf->head.prev && sbuf->head.next);
    LIST_DEL(&sbuf->head);  /* remove from svga->dirty_buffers list */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    sbuf->head.next = sbuf->head.prev = NULL;
-#endif
+#endif /* MESA_DEBUG */
    sbuf->dma.pending = FALSE;
    sbuf->dma.flags.discard = FALSE;
    sbuf->dma.flags.unsynchronized = FALSE;
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 13253ac..d7956dd 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -45,7 +45,7 @@
 /* NOTE: this constant may get moved into a svga3d*.h header file */
 #define SVGA3D_DX_MAX_RESOURCE_SIZE (128 * 1024 * 1024)
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int SVGA_DEBUG = 0;
 
 static const struct debug_named_value svga_debug_flags[] = {
@@ -67,7 +67,7 @@ static const struct debug_named_value svga_debug_flags[] = {
    { "query",       DEBUG_QUERY, NULL },
    DEBUG_NAMED_VALUE_END
 };
-#endif
+#endif /* MESA_DEBUG */
 
 static const char *
 svga_get_vendor( struct pipe_screen *pscreen )
@@ -81,14 +81,14 @@ svga_get_name( struct pipe_screen *pscreen )
 {
    const char *build = "", *llvm = "", *mutex = "";
    static char name[100];
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* Only return internal details in the DEBUG version:
     */
    build = "build: DEBUG;";
    mutex = "mutex: " PIPE_ATOMIC ";";
-#else
+#else /* MESA_DEBUG */
    build = "build: RELEASE;";
-#endif
+#endif /* MESA_DEBUG */
 #ifdef HAVE_LLVM
    llvm = "LLVM;";
 #endif
@@ -912,9 +912,9 @@ svga_screen_create(struct svga_winsys_screen *sws)
    struct svga_screen *svgascreen;
    struct pipe_screen *screen;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    SVGA_DEBUG = debug_get_flags_option("SVGA_DEBUG", svga_debug_flags, 0 );
-#endif
+#endif /* MESA_DEBUG */
 
    svgascreen = CALLOC_STRUCT(svga_screen);
    if (!svgascreen)
@@ -1095,7 +1095,7 @@ svga_winsys_screen(struct pipe_screen *screen)
    return svga_screen(screen)->sws;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 struct svga_screen *
 svga_screen(struct pipe_screen *screen)
 {
@@ -1103,4 +1103,4 @@ svga_screen(struct pipe_screen *screen)
    assert(screen->destroy == svga_destroy_screen);
    return (struct svga_screen *)screen;
 }
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h
index 98b56b2..09bf3bc 100644
--- a/src/gallium/drivers/svga/svga_screen.h
+++ b/src/gallium/drivers/svga/svga_screen.h
@@ -88,16 +88,16 @@ struct svga_screen
    } hud;
 };
 
-#ifndef DEBUG
+#ifndef MESA_DEBUG
 /** cast wrapper */
 static inline struct svga_screen *
 svga_screen(struct pipe_screen *pscreen)
 {
    return (struct svga_screen *) pscreen;
 }
-#else
+#else /* MESA_DEBUG */
 struct svga_screen *
 svga_screen(struct pipe_screen *screen);
-#endif
+#endif /* MESA_DEBUG */
 
 #endif /* SVGA_SCREEN_H */
diff --git a/src/gallium/drivers/svga/svga_state.c b/src/gallium/drivers/svga/svga_state.c
index 4479a27..5924e1a 100644
--- a/src/gallium/drivers/svga/svga_state.c
+++ b/src/gallium/drivers/svga/svga_state.c
@@ -129,11 +129,11 @@ update_state(struct svga_context *svga,
              const struct svga_tracked_state *atoms[],
              unsigned *state)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    boolean debug = TRUE;
-#else
+#else /* MESA_DEBUG */
    boolean debug = FALSE;
-#endif
+#endif /* MESA_DEBUG */
    enum pipe_error ret = PIPE_OK;
    unsigned i;
 
diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c
index 8784f47..307bbeb 100644
--- a/src/gallium/drivers/svga/svga_state_constants.c
+++ b/src/gallium/drivers/svga/svga_state_constants.c
@@ -328,12 +328,12 @@ emit_const_range(struct svga_context *svga,
           shader == PIPE_SHADER_FRAGMENT);
    assert(!svga_have_vgpu10(svga));
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (offset + count > SVGA3D_CONSTREG_MAX) {
       debug_printf("svga: too many constants (offset %u + count %u = %u (max = %u))\n",
                    offset, count, offset + count, SVGA3D_CONSTREG_MAX);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    if (offset > SVGA3D_CONSTREG_MAX) {
       /* This isn't OK, but if we propagate an error all the way up we'll
diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c
index 72d591b..f3effc8 100644
--- a/src/gallium/drivers/svga/svga_state_fs.c
+++ b/src/gallium/drivers/svga/svga_state_fs.c
@@ -52,11 +52,11 @@
 static const struct tgsi_token *
 get_dummy_fragment_shader(void)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    static const float color[4] = { 1.0, 0.0, 0.0, 0.0 }; /* red */
-#else
+#else /* MESA_DEBUG */
    static const float color[4] = { 0.0, 0.0, 0.0, 0.0 }; /* black */
-#endif
+#endif /* MESA_DEBUG */
    struct ureg_program *ureg;
    const struct tgsi_token *tokens;
    struct ureg_src src;
@@ -237,7 +237,7 @@ make_fs_key(const struct svga_context *svga,
       key->fs.white_fragments = 1;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /*
     * We expect a consistent set of samplers and sampler views.
     * Do some debug checks/warnings here.
@@ -265,7 +265,7 @@ make_fs_key(const struct svga_context *svga,
          warned = TRUE;
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 
    /* XXX: want to limit this to the textures that the shader actually
     * refers to.
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index c6cbccf..04d83b4 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
@@ -35,9 +35,6 @@
 #include "JitManager.h"
 #include "fetch_jit.h"
 
-#pragma push_macro("DEBUG")
-#undef DEBUG
-
 #if defined(_WIN32)
 #include "llvm/ADT/Triple.h"
 #endif
@@ -55,8 +52,6 @@
 #include "llvm/ExecutionEngine/JITEventListener.h"
 #endif
 
-#pragma pop_macro("DEBUG")
-
 #include "core/state.h"
 
 #include "state_llvm.h"
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
index 354bfe8..2cdb38f 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
@@ -36,10 +36,6 @@
 #pragma warning(disable : 4146 4244 4267 4800 4996)
 #endif
 
-// llvm 3.7+ reuses "DEBUG" as an enum value
-#pragma push_macro("DEBUG")
-#undef DEBUG
-
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
@@ -84,8 +80,6 @@ using PassManager = llvm::legacy::PassManager;
 #include "llvm/Support/DynamicLibrary.h"
 
 
-#pragma pop_macro("DEBUG")
-
 using namespace llvm;
 //////////////////////////////////////////////////////////////////////////
 /// JitInstructionSet
diff --git a/src/gallium/drivers/swr/swr_shader.cpp b/src/gallium/drivers/swr/swr_shader.cpp
index ecb4545..cbb63de 100644
--- a/src/gallium/drivers/swr/swr_shader.cpp
+++ b/src/gallium/drivers/swr/swr_shader.cpp
@@ -21,13 +21,9 @@
  * IN THE SOFTWARE.
  ***************************************************************************/
 
-// llvm redefines DEBUG
-#pragma push_macro("DEBUG")
-#undef DEBUG
 #include "JitManager.h"
 #include "llvm-c/Core.h"
 #include "llvm/Support/CBindingWrapping.h"
-#pragma pop_macro("DEBUG")
 
 #include "state.h"
 #include "state_llvm.h"
diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp
index dac95ce..1a41b4a 100644
--- a/src/gallium/drivers/swr/swr_state.cpp
+++ b/src/gallium/drivers/swr/swr_state.cpp
@@ -21,11 +21,7 @@
  * IN THE SOFTWARE.
  ***************************************************************************/
 
-// llvm redefines DEBUG
-#pragma push_macro("DEBUG")
-#undef DEBUG
 #include "JitManager.h"
-#pragma pop_macro("DEBUG")
 
 #include "common/os.h"
 #include "jit_api.h"
diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h
index ad57d9d..33cf7cf 100644
--- a/src/gallium/drivers/trace/tr_context.h
+++ b/src/gallium/drivers/trace/tr_context.h
@@ -58,9 +58,9 @@ static inline struct trace_context *
 trace_context(struct pipe_context *pipe)
 {
    assert(pipe);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    trace_context_check(pipe);
-#endif
+#endif /* MESA_DEBUG */
    return (struct trace_context *)pipe;
 }
 
diff --git a/src/gallium/drivers/vc4/vc4_cl.h b/src/gallium/drivers/vc4/vc4_cl.h
index bf4be0e..50eeb7a 100644
--- a/src/gallium/drivers/vc4/vc4_cl.h
+++ b/src/gallium/drivers/vc4/vc4_cl.h
@@ -44,9 +44,9 @@ struct vc4_cl {
         struct vc4_cl_out *next;
         struct vc4_cl_out *reloc_next;
         uint32_t size;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
         uint32_t reloc_count;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 void vc4_init_cl(struct vc4_context *vc4, struct vc4_cl *cl);
@@ -147,10 +147,10 @@ static inline void
 cl_start_reloc(struct vc4_cl *cl, struct vc4_cl_out **out, uint32_t n)
 {
         assert(n == 1 || n == 2);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
         assert(cl->reloc_count == 0);
         cl->reloc_count = n;
-#endif
+#endif /* MESA_DEBUG */
 
         cl_u8(out, VC4_PACKET_GEM_HANDLES);
         cl->reloc_next = *out;
@@ -161,10 +161,10 @@ cl_start_reloc(struct vc4_cl *cl, struct vc4_cl_out **out, uint32_t n)
 static inline struct vc4_cl_out *
 cl_start_shader_reloc(struct vc4_cl *cl, uint32_t n)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
         assert(cl->reloc_count == 0);
         cl->reloc_count = n;
-#endif
+#endif /* MESA_DEBUG */
         cl->reloc_next = cl->next;
 
         /* Reserve the space where hindex will be written. */
@@ -180,9 +180,9 @@ cl_reloc(struct vc4_context *vc4, struct vc4_cl *cl, struct vc4_cl_out **cl_out,
         *(uint32_t *)cl->reloc_next = vc4_gem_hindex(vc4, bo);
         cl_advance(&cl->reloc_next, 4);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
         cl->reloc_count--;
-#endif
+#endif /* MESA_DEBUG */
 
         cl_u32(cl_out, offset);
 }
@@ -195,9 +195,9 @@ cl_aligned_reloc(struct vc4_context *vc4, struct vc4_cl *cl,
         *(uint32_t *)cl->reloc_next = vc4_gem_hindex(vc4, bo);
         cl_advance(&cl->reloc_next, 4);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
         cl->reloc_count--;
-#endif
+#endif /* MESA_DEBUG */
 
         cl_aligned_u32(cl_out, offset);
 }
diff --git a/src/gallium/drivers/vc4/vc4_qir_validate.c b/src/gallium/drivers/vc4/vc4_qir_validate.c
index e8d4372..1891031 100644
--- a/src/gallium/drivers/vc4/vc4_qir_validate.c
+++ b/src/gallium/drivers/vc4/vc4_qir_validate.c
@@ -42,9 +42,9 @@ void qir_validate(struct vc4_compile *c)
          * keep compiling the validation code to make sure it doesn't get
          * broken.
          */
-#ifndef DEBUG
+#ifndef MESA_DEBUG
         return;
-#endif
+#endif /* MESA_DEBUG */
 
         for (int i = 0; i < c->num_temps; i++) {
                 struct qinst *def = c->defs[i];
diff --git a/src/gallium/drivers/vc4/vc4_qpu_validate.c b/src/gallium/drivers/vc4/vc4_qpu_validate.c
index 10bb84d..190041e 100644
--- a/src/gallium/drivers/vc4/vc4_qpu_validate.c
+++ b/src/gallium/drivers/vc4/vc4_qpu_validate.c
@@ -114,9 +114,9 @@ vc4_qpu_validate(uint64_t *insts, uint32_t num_inst)
          * keep compiling the validation code to make sure it doesn't get
          * broken.
          */
-#ifndef DEBUG
+#ifndef MESA_DEBUG
         return;
-#endif
+#endif /* MESA_DEBUG */
 
         for (int i = 0; i < num_inst; i++) {
                 uint64_t inst = insts[i];
diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
index b3e9c79..e2edf58 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_usefont.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
@@ -37,7 +37,7 @@
 
 /* Some debugging info.  */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include <ctype.h>
 
 int debug_xfonts = 0;
@@ -94,7 +94,7 @@ dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap)
       putchar('\n');
    }
 }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 
 /* Implementation.  */
@@ -285,10 +285,10 @@ glXUseXFont(Font font, int first, int count, int listbase)
    gc = XCreateGC(dpy, pixmap, valuemask, &values);
    XFreePixmap(dpy, pixmap);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_xfonts)
       dump_font_struct(fs);
-#endif
+#endif /* MESA_DEBUG */
 
    for (i = 0; i < count; i++) {
       unsigned int width, height, bm_width, bm_height;
@@ -309,13 +309,13 @@ glXUseXFont(Font font, int first, int count, int listbase)
 	 valid = 1;
       }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       if (debug_xfonts) {
 	 char s[7];
 	 sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
 	 dump_char_struct(ch, s);
       }
-#endif
+#endif /* MESA_DEBUG */
 
       /* glBitmap()' parameters:
          straight from the glXUseXFont(3) manpage.  */
@@ -344,13 +344,13 @@ glXUseXFont(Font font, int first, int count, int listbase)
 	 fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
 
 	 glBitmap(width, height, x0, y0, dx, dy, bm);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	 if (debug_xfonts) {
 	    printf("width/height = %u/%u\n", width, height);
 	    printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
 	    dump_bitmap(bm_width, bm_height, bm);
 	 }
-#endif
+#endif /* MESA_DEBUG */
       }
       else {
 	 glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
diff --git a/src/gallium/state_trackers/hgl/hgl.c b/src/gallium/state_trackers/hgl/hgl.c
index 0e122fe..f0ed3ab 100644
--- a/src/gallium/state_trackers/hgl/hgl.c
+++ b/src/gallium/state_trackers/hgl/hgl.c
@@ -21,13 +21,13 @@
 #include "GLView.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #   define TRACE(x...) printf("hgl:state_tracker: " x)
 #   define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #   define TRACE(x...)
 #   define CALLED()
-#endif
+#endif /* MESA_DEBUG */
 #define ERROR(x...) printf("hgl:state_tracker: " x)
 
 
diff --git a/src/gallium/state_trackers/nine/basetexture9.c b/src/gallium/state_trackers/nine/basetexture9.c
index 829a7c6..ee6d76a 100644
--- a/src/gallium/state_trackers/nine/basetexture9.c
+++ b/src/gallium/state_trackers/nine/basetexture9.c
@@ -28,10 +28,10 @@
 #include "cubetexture9.h"
 #include "volumetexture9.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include "nine_pipe.h"
 #include "nine_dump.h"
-#endif
+#endif /* MESA_DEBUG */
 
 #include "util/u_format.h"
 #include "util/u_gen_mipmap.h"
@@ -604,7 +604,7 @@ NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This )
     BASETEX_REGISTER_UPDATE(This);
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
 {
@@ -619,4 +619,4 @@ NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
         This->base.info.array_size, This->base.info.last_level,
         This->managed.lod, This->managed.lod_resident);
 }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/state_trackers/nine/basetexture9.h b/src/gallium/state_trackers/nine/basetexture9.h
index 980c4a5..2ddf854 100644
--- a/src/gallium/state_trackers/nine/basetexture9.h
+++ b/src/gallium/state_trackers/nine/basetexture9.h
@@ -131,13 +131,13 @@ NineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB )
     return This->view[sRGB];
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 NineBaseTexture9_Dump( struct NineBaseTexture9 *This );
-#else
+#else /* MESA_DEBUG */
 static inline void
 NineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }
-#endif
+#endif /* MESA_DEBUG */
 
 #define BASETEX_REGISTER_UPDATE(t) do { \
     if (((t)->managed.dirty | ((t)->dirty_mip)) && (t)->base.base.bind) \
diff --git a/src/gallium/state_trackers/nine/nine_debug.h b/src/gallium/state_trackers/nine/nine_debug.h
index 4c017ea..ffcd626 100644
--- a/src/gallium/state_trackers/nine/nine_debug.h
+++ b/src/gallium/state_trackers/nine/nine_debug.h
@@ -33,7 +33,7 @@ _nine_debug_printf( unsigned long flag,
 
 #define ERR(fmt, ...) _nine_debug_printf(DBG_ERROR, __FUNCTION__, fmt, ## __VA_ARGS__)
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define WARN(fmt, ...) _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__)
 #define WARN_ONCE(fmt, ...) \
     do { \
@@ -43,17 +43,17 @@ _nine_debug_printf( unsigned long flag,
             _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__); \
         } \
     } while(0)
-#else
+#else /* MESA_DEBUG */
 #define WARN(fmt, ...)
 #define WARN_ONCE(fmt, ...)
-#endif
+#endif /* MESA_DEBUG */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define DBG_FLAG(flag, fmt, ...) \
     _nine_debug_printf(flag, __FUNCTION__, fmt, ## __VA_ARGS__)
-#else
+#else /* MESA_DEBUG */
 #define DBG_FLAG(flag, fmt, ...)
-#endif
+#endif /* MESA_DEBUG */
 #define DBG(fmt, ...) DBG_FLAG(DBG_CHANNEL, fmt, ## __VA_ARGS__)
 
 #define DBG_UNKNOWN              (1<< 0)
@@ -89,34 +89,34 @@ _nine_stub( const char *file,
             const char *func,
             unsigned line );
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define STUB(ret) \
     do { \
         _nine_stub(__FILE__, __FUNCTION__, __LINE__); \
         return ret; \
     } while (0)
-#else
+#else /* MESA_DEBUG */
 #define STUB(ret) do { return ret; } while (0)
-#endif
+#endif /* MESA_DEBUG */
 
 /* the expression for this macro is equivalent of that to assert, however this
  * macro is designed to be used in conditionals ala
  * if (user_error(required condition)) { assertion failed }
  * It also prints debug message if the assertion fails. */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define user_error(x) \
     (!(x) ? (DBG_FLAG(DBG_USER, "User assertion failed: `%s'\n", #x), TRUE) \
           : FALSE)
-#else
+#else /* MESA_DEBUG */
 #define user_error(x) (!(x) ? TRUE : FALSE)
-#endif
+#endif /* MESA_DEBUG */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define user_warn(x) \
     if ((x)) { DBG_FLAG(DBG_USER, "User warning: `%s'\n", #x); }
-#else
+#else /* MESA_DEBUG */
 #define user_warn(x)
-#endif
+#endif /* MESA_DEBUG */
 
 /* nonfatal assert */
 #define user_assert(x, r) \
diff --git a/src/gallium/state_trackers/nine/nine_dump.c b/src/gallium/state_trackers/nine/nine_dump.c
index 1ca5505..f45c3fd 100644
--- a/src/gallium/state_trackers/nine/nine_dump.c
+++ b/src/gallium/state_trackers/nine/nine_dump.c
@@ -8,7 +8,7 @@
 
 #include "nine_dump.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 static char __thread tls[128];
 
@@ -810,4 +810,4 @@ nine_dump_D3DCAPS9(unsigned ch, const D3DCAPS9 *caps)
     FREE(s);
 }
 
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
diff --git a/src/gallium/state_trackers/nine/nine_dump.h b/src/gallium/state_trackers/nine/nine_dump.h
index a0ffe7b..4e5dc36 100644
--- a/src/gallium/state_trackers/nine/nine_dump.h
+++ b/src/gallium/state_trackers/nine/nine_dump.h
@@ -16,7 +16,7 @@ const char *nine_D3DPRESENTFLAG_to_str(DWORD);
 const char *nine_D3DLOCK_to_str(DWORD);
 const char *nine_D3DSAMP_to_str(DWORD);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 void
 nine_dump_D3DADAPTER_IDENTIFIER9(unsigned, const D3DADAPTER_IDENTIFIER9 *);
@@ -47,6 +47,6 @@ static inline void
 nine_dump_D3DTSS_value(unsigned ch, D3DTEXTURESTAGESTATETYPE tss, DWORD value)
 { }
 
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 #endif /* _NINE_DUMP_H_H_ */
diff --git a/src/gallium/state_trackers/nine/nine_ff.c b/src/gallium/state_trackers/nine/nine_ff.c
index 899e54e..3fb4adf 100644
--- a/src/gallium/state_trackers/nine/nine_ff.c
+++ b/src/gallium/state_trackers/nine/nine_ff.c
@@ -2350,7 +2350,7 @@ nine_d3d_matrix_inverse(D3DMATRIX *D, const D3DMATRIX *M)
     for (k = 0; k < 4; k++)
         D->m[i][k] *= det;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
     {
         D3DMATRIX I;
 
@@ -2361,7 +2361,7 @@ nine_d3d_matrix_inverse(D3DMATRIX *D, const D3DMATRIX *M)
             if (fabsf(I.m[i][k] - (float)(i == k)) > 1e-3)
                 DBG("Matrix inversion check FAILED !\n");
     }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 /* TODO: don't use 4x4 inverse, unless this gets all nicely inlined ? */
diff --git a/src/gallium/state_trackers/nine/surface9.c b/src/gallium/state_trackers/nine/surface9.c
index 2606dbf..1e3df62 100644
--- a/src/gallium/state_trackers/nine/surface9.c
+++ b/src/gallium/state_trackers/nine/surface9.c
@@ -219,7 +219,7 @@ NineSurface9_CreatePipeSurface( struct NineSurface9 *This, const int sRGB )
     return This->surface[sRGB];
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 NineSurface9_Dump( struct NineSurface9 *This )
 {
@@ -247,7 +247,7 @@ NineSurface9_Dump( struct NineSurface9 *This )
         NineUnknown_Release(NineUnknown(tex));
     }
 }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 HRESULT NINE_WINAPI
 NineSurface9_GetContainer( struct NineSurface9 *This,
diff --git a/src/gallium/state_trackers/nine/surface9.h b/src/gallium/state_trackers/nine/surface9.h
index a83e8dd..9d79b36 100644
--- a/src/gallium/state_trackers/nine/surface9.h
+++ b/src/gallium/state_trackers/nine/surface9.h
@@ -144,13 +144,13 @@ NineSurface9_IsOffscreenPlain (struct NineSurface9 *This )
     return This->base.usage == 0 && !This->texture;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void
 NineSurface9_Dump( struct NineSurface9 *This );
 #else
 static inline void
 NineSurface9_Dump( struct NineSurface9 *This ) { }
-#endif
+#endif /* MESA_DEBUG */
 
 /*** Direct3D public ***/
 
diff --git a/src/gallium/state_trackers/nine/volume9.c b/src/gallium/state_trackers/nine/volume9.c
index 1fdc638..a5114c5 100644
--- a/src/gallium/state_trackers/nine/volume9.c
+++ b/src/gallium/state_trackers/nine/volume9.c
@@ -176,14 +176,14 @@ static inline void
 NineVolume9_MarkContainerDirty( struct NineVolume9 *This )
 {
     struct NineBaseTexture9 *tex;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
     /* This is always contained by a NineVolumeTexture9. */
     GUID id = IID_IDirect3DVolumeTexture9;
     REFIID ref = &id;
     assert(NineUnknown_QueryInterface(This->base.container, ref, (void **)&tex)
            == S_OK);
     assert(NineUnknown_Release(NineUnknown(tex)) != 0);
-#endif
+#endif /* MESA_DEBUG */
 
     tex = NineBaseTexture9(This->base.container);
     assert(tex);
diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c
index b57f96f..68411de 100644
--- a/src/gallium/state_trackers/wgl/stw_device.c
+++ b/src/gallium/state_trackers/wgl/stw_device.c
@@ -80,9 +80,9 @@ stw_init(const struct stw_winsys *stw_winsys)
    stw_dev = &stw_dev_storage;
    memset(stw_dev, 0, sizeof(*stw_dev));
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    stw_dev->memdbg_no = debug_memory_begin();
-#endif
+#endif /* MESA_DEBUG */
    
    stw_dev->stw_winsys = stw_winsys;
 
@@ -184,9 +184,9 @@ stw_cleanup(void)
    _glapi_destroy_multithread();
 #endif
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    debug_memory_end(stw_dev->memdbg_no);
-#endif
+#endif /* MESA_DEBUG */
 
    stw_tls_cleanup();
 
diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h
index ecf212d..83f9a78 100644
--- a/src/gallium/state_trackers/wgl/stw_device.h
+++ b/src/gallium/state_trackers/wgl/stw_device.h
@@ -74,9 +74,9 @@ struct stw_device
    CRITICAL_SECTION fb_mutex;
    struct stw_framebuffer *fb_head;
    
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    unsigned long memdbg_no;
-#endif
+#endif /* MESA_DEBUG */
 
    bool initialized;
 };
diff --git a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
index d709faa..8fe371e 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c
@@ -225,7 +225,7 @@ wglCreatePbufferARB(HDC hCurrentDC,
       return 0;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /*
     * Verify the client area size matches the specified size.
     */
@@ -235,7 +235,7 @@ wglCreatePbufferARB(HDC hCurrentDC,
    assert(rect.top == 0);
    assert(rect.right - rect.left == iWidth);
    assert(rect.bottom - rect.top == iHeight);
-#endif
+#endif /* MESA_DEBUG */
 
    hDC = GetDC(hWnd);
    if (!hDC) {
diff --git a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
index 1e3874b..e83810a 100644
--- a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
+++ b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
@@ -31,13 +31,13 @@
 #include "target-helpers/inline_debug_helper.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #	define TRACE(x...) printf("GalliumContext: " x)
 #	define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #	define TRACE(x...)
 #	define CALLED()
-#endif
+#endif /* MESA_DEBUG */
 #define ERROR(x...) printf("GalliumContext: " x)
 
 
diff --git a/src/gallium/targets/haiku-softpipe/SoftwareRenderer.cpp b/src/gallium/targets/haiku-softpipe/SoftwareRenderer.cpp
index 18cb1ac..b4df5d9 100644
--- a/src/gallium/targets/haiku-softpipe/SoftwareRenderer.cpp
+++ b/src/gallium/targets/haiku-softpipe/SoftwareRenderer.cpp
@@ -21,13 +21,13 @@
 #include <new>
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #	define TRACE(x...) printf("SoftwareRenderer: " x)
 #	define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #	define TRACE(x...)
 #	define CALLED()
-#endif
+#endif /* MESA_DEBUG */
 #define ERROR(x...)	printf("SoftwareRenderer: " x)
 
 
diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
index ba454ec..c746dba 100644
--- a/src/gallium/winsys/i915/drm/i915_drm_buffer.c
+++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
@@ -219,10 +219,10 @@ i915_drm_buffer_destroy(struct i915_winsys *iws,
 {
    drm_intel_bo_unreference(intel_bo(buffer));
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    i915_drm_buffer(buffer)->magic = 0;
    i915_drm_buffer(buffer)->bo = NULL;
-#endif
+#endif /* MESA_DEBUG */
 
    FREE(buffer);
 }
diff --git a/src/gallium/winsys/svga/drm/pb_buffer_simple_fenced.c b/src/gallium/winsys/svga/drm/pb_buffer_simple_fenced.c
index d049d1d..33f99f6 100644
--- a/src/gallium/winsys/svga/drm/pb_buffer_simple_fenced.c
+++ b/src/gallium/winsys/svga/drm/pb_buffer_simple_fenced.c
@@ -160,7 +160,7 @@ fenced_buffer_create_gpu_storage_locked(struct fenced_manager *fenced_mgr,
 static void
 fenced_manager_dump_locked(struct fenced_manager *fenced_mgr)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct pb_fence_ops *ops = fenced_mgr->ops;
    struct list_head *curr, *next;
    struct fenced_buffer *fenced_buf;
@@ -199,9 +199,9 @@ fenced_manager_dump_locked(struct fenced_manager *fenced_mgr)
       curr = next;
       next = curr->next;
    }
-#else
+#else /* MESA_DEBUG */
    (void)fenced_mgr;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
@@ -804,9 +804,9 @@ fenced_bufmgr_destroy(struct pb_manager *mgr)
          ;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /*assert(!fenced_mgr->num_unfenced);*/
-#endif
+#endif /* MESA_DEBUG */
 
    pipe_mutex_unlock(fenced_mgr->mutex);
    pipe_mutex_destroy(fenced_mgr->mutex);
diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.c b/src/gallium/winsys/svga/drm/vmw_buffer.c
index 3ac80c7..6cdef20 100644
--- a/src/gallium/winsys/svga/drm/vmw_buffer.c
+++ b/src/gallium/winsys/svga/drm/vmw_buffer.c
@@ -282,7 +282,7 @@ vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf,
    return TRUE;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 struct svga_winsys_buffer {
    struct pb_buffer *pb_buf;
    struct debug_flush_buf *fbuf;
@@ -320,7 +320,7 @@ vmw_debug_flush_buf(struct svga_winsys_buffer *buffer)
    return buffer->fbuf;
 }
 
-#endif
+#endif /* MESA_DEBUG */
 
 void
 vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws,
@@ -329,10 +329,10 @@ vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws,
    struct pb_buffer *pbuf = vmw_pb_buffer(buf);
    (void)sws;
    pb_reference(&pbuf, NULL);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    debug_flush_buf_reference(&buf->fbuf, NULL);
    FREE(buf);
-#endif
+#endif /* MESA_DEBUG */
 }
 
 void *
@@ -348,10 +348,10 @@ vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws,
 
    map = pb_map(vmw_pb_buffer(buf), flags, NULL);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (map != NULL)
       debug_flush_map(buf->fbuf, flags);
-#endif
+#endif /* MESA_DEBUG */
 
    return map;
 }
@@ -363,9 +363,9 @@ vmw_svga_winsys_buffer_unmap(struct svga_winsys_screen *sws,
 {
    (void)sws;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    debug_flush_unmap(buf->fbuf);
-#endif
+#endif /* MESA_DEBUG */
 
    pb_unmap(vmw_pb_buffer(buf));
 }
diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.h b/src/gallium/winsys/svga/drm/vmw_buffer.h
index 6e1151e..5e3f45b 100644
--- a/src/gallium/winsys/svga/drm/vmw_buffer.h
+++ b/src/gallium/winsys/svga/drm/vmw_buffer.h
@@ -49,7 +49,7 @@ struct vmw_buffer_desc {
 };
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 struct pb_buffer *
 vmw_pb_buffer(struct svga_winsys_buffer *buffer);
@@ -58,7 +58,7 @@ vmw_svga_winsys_buffer_wrap(struct pb_buffer *buffer);
 struct debug_flush_buf *
 vmw_debug_flush_buf(struct svga_winsys_buffer *buffer);
 
-#else
+#else /* MESA_DEBUG */
 static inline struct pb_buffer *
 vmw_pb_buffer(struct svga_winsys_buffer *buffer)
 {
@@ -72,7 +72,7 @@ vmw_svga_winsys_buffer_wrap(struct pb_buffer *buffer)
 {
    return (struct svga_winsys_buffer *)buffer;
 }
-#endif
+#endif /* MESA_DEBUG */
 
 void
 vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws,
diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c
index 8d23bff..fe74557 100644
--- a/src/gallium/winsys/svga/drm/vmw_context.c
+++ b/src/gallium/winsys/svga/drm/vmw_context.c
@@ -97,11 +97,11 @@ struct vmw_svga_winsys_context
    struct vmw_winsys_screen *vws;
    struct util_hash_table *hash;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    boolean must_flush;
    struct debug_stack_frame must_flush_stack[VMW_MUST_FLUSH_STACK];
    struct debug_flush_ctx *fctx;
-#endif
+#endif /* MESA_DEBUG */
 
    struct {
       uint8_t buffer[VMW_COMMAND_SIZE];
@@ -247,10 +247,10 @@ vmw_swc_flush(struct svga_winsys_context *swc,
    vswc->region.used = 0;
    vswc->region.reserved = 0;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    vswc->must_flush = FALSE;
    debug_flush_flush(vswc->fctx);
-#endif
+#endif /* MESA_DEBUG */
    swc->hints &= ~SVGA_HINT_FLAG_CAN_PRE_FLUSH;
    vswc->preemptive_flush = FALSE;
    vswc->seen_surfaces = 0;
@@ -272,7 +272,7 @@ vmw_swc_reserve(struct svga_winsys_context *swc,
 {
    struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* Check if somebody forgot to check the previous failure */
    if(vswc->must_flush) {
       debug_printf("Forgot to flush:\n");
@@ -280,7 +280,7 @@ vmw_swc_reserve(struct svga_winsys_context *swc,
       assert(!vswc->must_flush);
    }
    debug_flush_might_flush(vswc->fctx);
-#endif
+#endif /* MESA_DEBUG */
 
    assert(nr_bytes <= vswc->command.size);
    if(nr_bytes > vswc->command.size)
@@ -291,11 +291,11 @@ vmw_swc_reserve(struct svga_winsys_context *swc,
       vswc->surface.used + nr_relocs > vswc->surface.size ||
       vswc->shader.used + nr_relocs > vswc->shader.size ||
       vswc->region.used + nr_relocs > vswc->region.size) {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       vswc->must_flush = TRUE;
       debug_backtrace_capture(vswc->must_flush_stack, 1,
                               VMW_MUST_FLUSH_STACK);
-#endif
+#endif /* MESA_DEBUG */
       return NULL;
    }
 
@@ -385,10 +385,10 @@ vmw_swc_region_relocation(struct svga_winsys_context *swc,
          vswc->preemptive_flush = TRUE;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (!(flags & SVGA_RELOC_INTERNAL))
       debug_flush_cb_reference(vswc->fctx, vmw_debug_flush_buf(buffer));
-#endif
+#endif /* MESA_DEBUG */
 }
 
 static void
@@ -429,10 +429,10 @@ vmw_swc_mob_relocation(struct svga_winsys_context *swc,
          vswc->preemptive_flush = TRUE;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (!(flags & SVGA_RELOC_INTERNAL))
       debug_flush_cb_reference(vswc->fctx, vmw_debug_flush_buf(buffer));
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
@@ -650,9 +650,9 @@ vmw_swc_destroy(struct svga_winsys_context *swc)
    util_hash_table_destroy(vswc->hash);
    pb_validate_destroy(vswc->validate);
    vmw_ioctl_context_destroy(vswc->vws, swc->cid);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    debug_flush_ctx_destroy(vswc->fctx);
-#endif
+#endif /* MESA_DEBUG */
    FREE(vswc);
 }
 
@@ -811,9 +811,9 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    if (!vswc->hash)
       goto out_no_hash;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    vswc->fctx = debug_flush_ctx_create(TRUE, VMW_DEBUG_FLUSH_STACK);
-#endif
+#endif /* MESA_DEBUG */
 
    return &vswc->base;
 
diff --git a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c
index 1740d1a..dbddae7 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c
@@ -416,7 +416,7 @@ vmw_ioctl_command(struct vmw_winsys_screen *vws, int32_t cid,
    int ret;
    int argsize;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    {
       static boolean firsttime = TRUE;
       static boolean debug = FALSE;
@@ -434,7 +434,7 @@ vmw_ioctl_command(struct vmw_winsys_screen *vws, int32_t cid,
          size = 0;
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 
    memset(&arg, 0, sizeof(arg));
    memset(&rep, 0, sizeof(rep));
diff --git a/src/gallium/winsys/svga/drm/vmw_screen_pools.c b/src/gallium/winsys/svga/drm/vmw_screen_pools.c
index 48c95e5..b383940 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen_pools.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen_pools.c
@@ -192,11 +192,11 @@ vmw_pools_init(struct vmw_winsys_screen *vws)
       vws->pools.gmr_fenced = simple_fenced_bufmgr_create
          (vws->pools.gmr_mm, vws->fence_ops);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced,
                                                       4096,
                                                       4096);
-#endif
+#endif /* MESA_DEBUG */
       if(!vws->pools.gmr_fenced)
          goto error;
 
diff --git a/src/gallium/winsys/svga/drm/vmw_shader.c b/src/gallium/winsys/svga/drm/vmw_shader.c
index 56ffdd1..77ba562 100644
--- a/src/gallium/winsys/svga/drm/vmw_shader.c
+++ b/src/gallium/winsys/svga/drm/vmw_shader.c
@@ -52,11 +52,11 @@ vmw_svga_winsys_shader_reference(struct vmw_svga_winsys_shader **pdst,
 
       if (!sws->have_vgpu10)
          vmw_ioctl_shader_destroy(dst->screen, dst->shid);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* to detect dangling pointers */
       assert(p_atomic_read(&dst->validated) == 0);
       dst->shid = SVGA3D_INVALID_ID;
-#endif
+#endif /* MESA_DEBUG */
       sws->buffer_destroy(sws, dst->buf);
       FREE(dst);
    }
diff --git a/src/gallium/winsys/svga/drm/vmw_surface.c b/src/gallium/winsys/svga/drm/vmw_surface.c
index a438b1a..942ae27 100644
--- a/src/gallium/winsys/svga/drm/vmw_surface.c
+++ b/src/gallium/winsys/svga/drm/vmw_surface.c
@@ -196,11 +196,11 @@ vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst,
       if (dst->buf)
          vmw_svga_winsys_buffer_destroy(&dst->screen->base, dst->buf);
       vmw_ioctl_surface_destroy(dst->screen, dst->sid);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* to detect dangling pointers */
       assert(p_atomic_read(&dst->validated) == 0);
       dst->sid = SVGA3D_INVALID_ID;
-#endif
+#endif /* MESA_DEBUG */
       pipe_mutex_destroy(dst->mutex);
       FREE(dst);
    }
diff --git a/src/gallium/winsys/sw/hgl/hgl_sw_winsys.c b/src/gallium/winsys/sw/hgl/hgl_sw_winsys.c
index 89dd547..b0ed770 100644
--- a/src/gallium/winsys/sw/hgl/hgl_sw_winsys.c
+++ b/src/gallium/winsys/sw/hgl/hgl_sw_winsys.c
@@ -41,13 +41,13 @@
 #include "hgl_sw_winsys.h"
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #   define TRACE(x...) printf("hgl:winsys: " x)
 #   define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
-#else
+#else /* MESA_DEBUG */
 #   define TRACE(x...)
 #   define CALLED()
-#endif
+#endif /* MESA_DEBUG */
 #define ERROR(x...) printf("hgl:winsys: " x)
 
 
diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
index 21ac0d7..85f2679 100644
--- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
+++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
@@ -53,11 +53,11 @@
 #include "state_tracker/drm_driver.h"
 #include "kms_dri_sw_winsys.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define DEBUG_PRINT(msg, ...) fprintf(stderr, msg, __VA_ARGS__)
-#else
+#else /* MESA_DEBUG */
 #define DEBUG_PRINT(msg, ...)
-#endif
+#endif /* MESA_DEBUG */
 
 
 struct kms_sw_displaytarget
diff --git a/src/glx/glxext.c b/src/glx/glxext.c
index dc87fb9..7014bb4 100644
--- a/src/glx/glxext.c
+++ b/src/glx/glxext.c
@@ -52,9 +52,9 @@
 #include <xcb/glx.h>
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 void __glXDumpDrawBuffer(struct glx_context * ctx);
-#endif
+#endif /* MESA_DEBUG */
 
 /*
 ** You can set this cell to 1 to force the gl drawing stuff to be
@@ -1081,7 +1081,7 @@ __glXSendLargeCommand(struct glx_context * ctx,
 
 /************************************************************************/
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 _X_HIDDEN void
 __glXDumpDrawBuffer(struct glx_context * ctx)
 {
@@ -1104,4 +1104,4 @@ __glXDumpDrawBuffer(struct glx_context * ctx)
       printf("\n");
    }
 }
-#endif
+#endif /* MESA_DEBUG */
diff --git a/src/glx/xfont.c b/src/glx/xfont.c
index 00498bc..c389ab6 100644
--- a/src/glx/xfont.c
+++ b/src/glx/xfont.c
@@ -39,7 +39,7 @@
 
 /* Some debugging info.  */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #undef _R
 #undef _G
 #undef _B
@@ -99,7 +99,7 @@ dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap)
       putchar('\n');
    }
 }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 
 /* Implementation.  */
@@ -297,10 +297,10 @@ DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int lis
    gc = XCreateGC(dpy, pixmap, valuemask, &values);
    XFreePixmap(dpy, pixmap);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_xfonts)
       dump_font_struct(fs);
-#endif
+#endif /* MESA_DEBUG */
 
    for (i = 0; i < count; i++) {
       unsigned int width, height, bm_width, bm_height;
@@ -321,13 +321,13 @@ DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int lis
          valid = 1;
       }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       if (debug_xfonts) {
          char s[7];
          sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
          dump_char_struct(ch, s);
       }
-#endif
+#endif /* MESA_DEBUG */
 
       /* glBitmap()' parameters:
          straight from the glXUseXFont(3) manpage.  */
@@ -355,13 +355,13 @@ DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int lis
          fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
 
          glBitmap(width, height, x0, y0, dx, dy, bm);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
          if (debug_xfonts) {
             printf("width/height = %u/%u\n", width, height);
             printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
             dump_bitmap(bm_width, bm_height, bm);
          }
-#endif
+#endif /* MESA_DEBUG */
       }
       else {
          glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
@@ -382,4 +382,4 @@ DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int lis
    glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
 }
 
-#endif
+#endif /* GLX_DIRECT_RENDERING */
diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 2896174..6fe63f6 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -214,11 +214,11 @@ for layer in [ "anv", "validate", "gen7", "gen75", "gen8", "gen9" ]:
     print "};\n"
 
 print """
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static bool enable_validate = true;
-#else
+#else /* MESA_DEBUG */
 static bool enable_validate = false;
-#endif
+#endif /* MESA_DEBUG */
 
 /* We can't use symbols that need resolving (like, oh, getenv) in the resolve
  * function. This means that we have to determine whether or not to use the
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index d8a9d87..cbde11a 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -177,13 +177,13 @@ struct anv_common {
 
 VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
-#else
+#else /* MESA_DEBUG */
 #define vk_error(error) error
 #define vk_errorf(error, format, ...) error
-#endif
+#endif /* MESA_DEBUG */
 
 void __anv_finishme(const char *file, int line, const char *format, ...)
    anv_printflike(3, 4);
@@ -197,24 +197,24 @@ void anv_loge_v(const char *format, va_list va);
    __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
 
 /* A non-fatal assert.  Useful for debugging. */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define anv_assert(x) ({ \
    if (unlikely(!(x))) \
       fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
 })
-#else
+#else /* MESA_DEBUG */
 #define anv_assert(x)
-#endif
+#endif /* MESA_DEBUG */
 
 /**
  * If a block of code is annotated with anv_validate, then the block runs only
  * in debug builds.
  */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #define anv_validate if (1)
-#else
+#else /* MESA_DEBUG */
 #define anv_validate if (0)
-#endif
+#endif /* MESA_DEBUG */
 
 void anv_abortf(const char *format, ...) anv_noreturn anv_printflike(1, 2);
 void anv_abortfv(const char *format, va_list va) anv_noreturn;
diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py
index 012a5c3..24704ad 100644
--- a/src/mapi/mapi_abi.py
+++ b/src/mapi/mapi_abi.py
@@ -595,7 +595,7 @@ class ABIPrinter(object):
         if self.lib_need_noop_array:
             print
             print '#ifdef MAPI_TMP_NOOP_ARRAY'
-            print '#ifdef DEBUG'
+            print '#ifdef MESA_DEBUG'
             print
             print self.c_noop_functions(self.prefix_noop, self.prefix_warn)
             print
@@ -603,13 +603,13 @@ class ABIPrinter(object):
             print self.c_noop_initializer(self.prefix_noop, False)
             print '};'
             print
-            print '#else /* DEBUG */'
+            print '#else /* MESA_DEBUG */'
             print
             print 'const mapi_func table_%s_array[] = {' % (self.prefix_noop)
             print self.c_noop_initializer(self.prefix_noop, True)
             print '};'
             print
-            print '#endif /* DEBUG */'
+            print '#endif /* MESA_DEBUG */'
             print '#undef MAPI_TMP_NOOP_ARRAY'
             print '#endif /* MAPI_TMP_NOOP_ARRAY */'
 
diff --git a/src/mesa/drivers/dri/i915/intel_batchbuffer.h b/src/mesa/drivers/dri/i915/intel_batchbuffer.h
index c4efa76..0aee6dfb 100644
--- a/src/mesa/drivers/dri/i915/intel_batchbuffer.h
+++ b/src/mesa/drivers/dri/i915/intel_batchbuffer.h
@@ -81,9 +81,9 @@ intel_batchbuffer_space(struct intel_context *intel)
 static inline void
 intel_batchbuffer_emit_dword(struct intel_context *intel, GLuint dword)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    assert(intel_batchbuffer_space(intel) >= 4);
-#endif
+#endif /* MESA_DEBUG */
    intel->batch.map[intel->batch.used++] = dword;
 }
 
@@ -97,9 +97,9 @@ static inline void
 intel_batchbuffer_require_space(struct intel_context *intel,
                                 GLuint sz)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    assert(sz < intel->maxBatchSize - BATCH_RESERVED);
-#endif
+#endif /* MESA_DEBUG */
    if (intel_batchbuffer_space(intel) < sz)
       intel_batchbuffer_flush(intel);
 }
@@ -110,15 +110,15 @@ intel_batchbuffer_begin(struct intel_context *intel, int n)
    intel_batchbuffer_require_space(intel, n * 4);
 
    intel->batch.emit = intel->batch.used;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    intel->batch.total = n;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 static inline void
 intel_batchbuffer_advance(struct intel_context *intel)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct intel_batchbuffer *batch = &intel->batch;
    unsigned int _n = batch->used - batch->emit;
    assert(batch->total != 0);
@@ -128,9 +128,9 @@ intel_batchbuffer_advance(struct intel_context *intel)
       abort();
    }
    batch->total = 0;
-#else
+#else /* MESA_DEBUG */
    (void) intel;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 /* Here are the crusty old macros, to be removed:
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index bfad868..5d66aed 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -610,9 +610,9 @@ struct intel_batchbuffer {
    /** Last BO submitted to the hardware.  Used for glFinish(). */
    drm_intel_bo *last_bo;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    uint16_t emit, total;
-#endif
+#endif /* MESA_DEBUG */
    uint16_t reserved_space;
    uint32_t *map_next;
    uint32_t *map;
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index d74d5d5..fab18ed 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -1190,7 +1190,7 @@ qtr_ctrl(FILE *file, const struct brw_device_info *devinfo, brw_inst *inst)
    return 0;
 }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 static __attribute__((__unused__)) int
 brw_disassemble_imm(const struct brw_device_info *devinfo,
                     uint32_t dw3, uint32_t dw2, uint32_t dw1, uint32_t dw0)
@@ -1200,7 +1200,7 @@ brw_disassemble_imm(const struct brw_device_info *devinfo,
    inst.data[1] = (((uint64_t) dw3) << 32) | ((uint64_t) dw2);
    return brw_disassemble_inst(stderr, devinfo, &inst, false);
 }
-#endif
+#endif /* MESA_DEBUG */
 
 int
 brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
diff --git a/src/mesa/drivers/dri/i965/brw_performance_monitor.c b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
index f8e50e1..275fc17 100644
--- a/src/mesa/drivers/dri/i965/brw_performance_monitor.c
+++ b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
@@ -844,7 +844,7 @@ add_deltas(struct brw_context *brw,
        * value (or remain unchanged).  This happens periodically due to
        * wraparound, but can also indicate serious problems.
        */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       if (end[i] < start[i]) {
          int counter = brw->perfmon.oa_snapshot_layout[i];
          if (counter >= 0) {
@@ -854,7 +854,7 @@ add_deltas(struct brw_context *brw,
                 end[i], start[i], end[i] - start[i]);
          }
       }
-#endif
+#endif /* MESA_DEBUG */
       monitor->oa_results[i] += end[i] - start[i];
    }
 }
@@ -1111,12 +1111,12 @@ brw_begin_perf_monitor(struct gl_context *ctx,
 
       monitor->oa_bo =
          drm_intel_bo_alloc(brw->bufmgr, "perf. monitor OA bo", 4096, 64);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* Pre-filling the BO helps debug whether writes landed. */
       drm_intel_bo_map(monitor->oa_bo, true);
       memset((char *) monitor->oa_bo->virtual, 0xff, 4096);
       drm_intel_bo_unmap(monitor->oa_bo);
-#endif
+#endif /* MESA_DEBUG */
 
       /* Allocate storage for accumulated OA counter values. */
       monitor->oa_results =
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 5a0db9f..ff55a68 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -117,9 +117,9 @@ intel_batchbuffer_require_space(struct brw_context *brw, GLuint sz,
       intel_batchbuffer_flush(brw);
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    assert(sz < BATCH_SZ - BATCH_RESERVED);
-#endif
+#endif /* MESA_DEBUG */
    if (intel_batchbuffer_space(brw) < sz)
       intel_batchbuffer_flush(brw);
 
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.h b/src/mesa/drivers/dri/i965/intel_batchbuffer.h
index 67e8e8f..ff54e60 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.h
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.h
@@ -105,9 +105,9 @@ intel_batchbuffer_space(struct brw_context *brw)
 static inline void
 intel_batchbuffer_emit_dword(struct brw_context *brw, GLuint dword)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    assert(intel_batchbuffer_space(brw) >= 4);
-#endif
+#endif /* MESA_DEBUG */
    *brw->batch.map_next++ = dword;
    assert(brw->batch.ring != UNKNOWN_RING);
 }
@@ -123,16 +123,16 @@ intel_batchbuffer_begin(struct brw_context *brw, int n, enum brw_gpu_ring ring)
 {
    intel_batchbuffer_require_space(brw, n * 4, ring);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    brw->batch.emit = USED_BATCH(brw->batch);
    brw->batch.total = n;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 static inline void
 intel_batchbuffer_advance(struct brw_context *brw)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct intel_batchbuffer *batch = &brw->batch;
    unsigned int _n = USED_BATCH(*batch) - batch->emit;
    assert(batch->total != 0);
@@ -142,9 +142,9 @@ intel_batchbuffer_advance(struct brw_context *brw)
       abort();
    }
    batch->total = 0;
-#else
+#else /* MESA_DEBUG */
    (void) brw;
-#endif
+#endif /* MESA_DEBUG */
 }
 
 #define BEGIN_BATCH(n) do {                            \
diff --git a/src/mesa/drivers/dri/radeon/radeon_debug.h b/src/mesa/drivers/dri/radeon/radeon_debug.h
index df2f1ab..403fd00 100644
--- a/src/mesa/drivers/dri/radeon/radeon_debug.h
+++ b/src/mesa/drivers/dri/radeon/radeon_debug.h
@@ -47,11 +47,11 @@ typedef enum radeon_debug_levels {
  * errors.
  */
 #ifndef RADEON_DEBUG_LEVEL
-# ifdef DEBUG
+# ifdef MESA_DEBUG
 #  define RADEON_DEBUG_LEVEL RADEON_TRACE
-# else
+# else /* MESA_DEBUG */
 #  define RADEON_DEBUG_LEVEL RADEON_VERBOSE
-# endif
+# endif /* MESA_DEBUG */
 #endif
 
 typedef enum radeon_debug_types {
diff --git a/src/mesa/drivers/x11/xfonts.c b/src/mesa/drivers/x11/xfonts.c
index 8405013..d3bb084 100644
--- a/src/mesa/drivers/x11/xfonts.c
+++ b/src/mesa/drivers/x11/xfonts.c
@@ -37,7 +37,7 @@
 
 /* Some debugging info.  */
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include <ctype.h>
 
 int debug_xfonts = 0;
@@ -94,7 +94,7 @@ dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap)
       putchar('\n');
    }
 }
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
 
 
 /* Implementation.  */
@@ -284,10 +284,10 @@ Fake_glXUseXFont(Font font, int first, int count, int listbase)
    gc = XCreateGC(dpy, pixmap, valuemask, &values);
    XFreePixmap(dpy, pixmap);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (debug_xfonts)
       dump_font_struct(fs);
-#endif
+#endif /* MESA_DEBUG */
 
    for (i = 0; i < count; i++) {
       unsigned int width, height, bm_width, bm_height;
@@ -308,13 +308,13 @@ Fake_glXUseXFont(Font font, int first, int count, int listbase)
 	 valid = 1;
       }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       if (debug_xfonts) {
 	 char s[7];
 	 sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
 	 dump_char_struct(ch, s);
       }
-#endif
+#endif /* MESA_DEBUG */
 
       /* glBitmap()' parameters:
          straight from the glXUseXFont(3) manpage.  */
@@ -343,13 +343,13 @@ Fake_glXUseXFont(Font font, int first, int count, int listbase)
 	 fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
 
 	 glBitmap(width, height, x0, y0, dx, dy, bm);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 	 if (debug_xfonts) {
 	    printf("width/height = %u/%u\n", width, height);
 	    printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
 	    dump_bitmap(bm_width, bm_height, bm);
 	 }
-#endif
+#endif /* MESA_DEBUG */
       }
       else {
 	 glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c
index da26235..446528f 100644
--- a/src/mesa/drivers/x11/xm_tri.c
+++ b/src/mesa/drivers/x11/xm_tri.c
@@ -975,7 +975,7 @@ void _xmesa_print_triangle_func( swrast_tri_func triFunc )
 #endif
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 /* record the current triangle function name */
 static const char *triFuncName = NULL;
@@ -986,11 +986,11 @@ do {                                   \
     return triFunc;                    \
 } while (0)
 
-#else
+#else /* MESA_DEBUG */
 
 #define USE(triFunc)  return triFunc
 
-#endif
+#endif /* MESA_DEBUG */
 
 
 /**
@@ -1005,9 +1005,9 @@ get_triangle_func(struct gl_context *ctx)
    XMesaContext xmesa = XMESA_CONTEXT(ctx);
    const struct xmesa_renderbuffer *xrb;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    triFuncName = NULL;
-#endif
+#endif /* MESA_DEBUG */
 
    /* trivial fallback tests */
    if ((ctx->DrawBuffer->_ColorDrawBufferIndexes[0] != BUFFER_BIT_FRONT_LEFT) &&
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 574c0fb..92bc68c 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -396,12 +396,12 @@ one_time_init( struct gl_context *ctx )
 
       atexit(one_time_fini);
 
-#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
+#if defined(MESA_DEBUG) && defined(__DATE__) && defined(__TIME__)
       if (MESA_VERBOSE != 0) {
 	 _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
 		     PACKAGE_VERSION, __DATE__, __TIME__);
       }
-#endif
+#endif /* MESA_DEBUG, __DATE__, __TIME__ */
    }
 
    /* per-API one-time init */
@@ -634,11 +634,11 @@ _mesa_init_constants(struct gl_constants *consts, gl_api api)
    consts->GLSLVersion = 120;
    _mesa_override_glsl_version(consts);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    consts->GenerateTemporaryNames = true;
-#else
+#else /* MESA_DEBUG */
    consts->GenerateTemporaryNames = false;
-#endif
+#endif /* MESA_DEBUG */
 
    /* GL_ARB_framebuffer_object */
    consts->MaxSamples = 0;
@@ -1955,7 +1955,7 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
       return GL_FALSE;
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    if (ctx->_Shader->Flags & GLSL_LOG) {
       struct gl_shader_program **shProg = ctx->_Shader->CurrentProgram;
       gl_shader_stage i;
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 5ca7d5c..52f4a1e 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -139,7 +139,7 @@ void _mesa_print_info( struct gl_context *ctx )
 static void
 set_verbose_flags(const char *str)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct option {
       const char *name;
       GLbitfield flag;
@@ -168,7 +168,7 @@ set_verbose_flags(const char *str)
       if (strstr(str, opts[i].name) || strcmp(str, "all") == 0)
          MESA_VERBOSE |= opts[i].flag;
    }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
@@ -180,7 +180,7 @@ set_verbose_flags(const char *str)
 static void
 set_debug_flags(const char *str)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    struct option {
       const char *name;
       GLbitfield flag;
@@ -201,7 +201,7 @@ set_debug_flags(const char *str)
       if (strstr(str, opts[i].name))
          MESA_DEBUG_FLAGS |= opts[i].flag;
    }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 9932b4a..e817187 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -65,16 +65,16 @@ output_if_debug(const char *prefixString, const char *outputString,
          LogFile = fopen(logFile, "w");
       if (!LogFile)
          LogFile = stderr;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       /* in debug builds, print messages unless MESA_DEBUG="silent" */
       if (MESA_DEBUG_FLAGS & DEBUG_SILENT)
          debug = 0;
       else
          debug = 1;
-#else
+#else /* MESA_DEBUG */
       /* in release builds, be silent unless MESA_DEBUG is set */
       debug = getenv("MESA_DEBUG") != NULL;
-#endif
+#endif /* MESA_DEBUG */
    }
 
    /* Now only print the string if we're required to do so. */
@@ -135,7 +135,7 @@ flush_delayed_errors( struct gl_context *ctx )
 
 /**
  * Report a warning (a recoverable error condition) to stderr if
- * either DEBUG is defined or the MESA_DEBUG env var is set.
+ * either MESA_DEBUG macro is defined or the MESA_DEBUG env var is set.
  *
  * \param ctx GL context.
  * \param fmtString printf()-like format string.
@@ -195,17 +195,17 @@ should_output(struct gl_context *ctx, GLenum error, const char *fmtString)
    if (debug == -1) {
       const char *debugEnv = getenv("MESA_DEBUG");
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       if (debugEnv && strstr(debugEnv, "silent"))
          debug = GL_FALSE;
       else
          debug = GL_TRUE;
-#else
+#else /* MESA_DEBUG */
       if (debugEnv)
          debug = GL_TRUE;
       else
          debug = GL_FALSE;
-#endif
+#endif /* MESA_DEBUG */
    }
 
    if (debug) {
@@ -261,7 +261,7 @@ _mesa_gl_debug(struct gl_context *ctx,
  * Record an OpenGL state error.  These usually occur when the user
  * passes invalid parameters to a GL function.
  *
- * If debugging is enabled (either at compile-time via the DEBUG macro, or
+ * If debugging is enabled (either at compile-time via the MESA_DEBUG macro, or
  * run-time via the MESA_DEBUG environment variable), report the error with
  * _mesa_debug().
  * 
@@ -345,7 +345,7 @@ _mesa_error_no_memory(const char *caller)
 
 /**
  * Report debug information.  Print error message to stderr via fprintf().
- * No-op if DEBUG mode not enabled.
+ * No-op if MESA_DEBUG mode not enabled.
  * 
  * \param ctx GL context.
  * \param fmtString printf()-style format string, followed by optional args.
@@ -353,14 +353,14 @@ _mesa_error_no_memory(const char *caller)
 void
 _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    char s[MAX_DEBUG_MESSAGE_LENGTH];
    va_list args;
    va_start(args, fmtString);
    _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
    va_end(args);
    output_if_debug("Mesa", s, GL_FALSE);
-#endif /* DEBUG */
+#endif /* MESA_DEBUG */
    (void) ctx;
    (void) fmtString;
 }
diff --git a/src/mesa/main/feedback.c b/src/mesa/main/feedback.c
index 699e2a8..185b027 100644
--- a/src/mesa/main/feedback.c
+++ b/src/mesa/main/feedback.c
@@ -429,9 +429,9 @@ _mesa_RenderMode( GLenum mode )
 	 }
 	 if (ctx->Select.BufferCount > ctx->Select.BufferSize) {
 	    /* overflow */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
             _mesa_warning(ctx, "Feedback buffer overflow");
-#endif
+#endif /* MESA_DEBUG */
 	    result = -1;
 	 }
 	 else {
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 9d9830f..e5f0ad2 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -800,9 +800,9 @@ _mesa_get_uncompressed_format(mesa_format format)
    case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
       return MESA_FORMAT_RGB_FLOAT32;
    default:
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       assert(!_mesa_is_format_compressed(format));
-#endif
+#endif /* MESA_DEBUG */
       return format;
    }
 }
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 808b8f6..df5dff6 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -103,13 +103,13 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
    buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
    *(uintptr_t *)(buf - sizeof(void *)) = ptr;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* mark the non-aligned area */
    while ( ptr < buf - sizeof(void *) ) {
       *(unsigned long *)ptr = 0xcdcdcdcd;
       ptr += sizeof(unsigned long);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    return (void *) buf;
 #endif /* defined(HAVE_POSIX_MEMALIGN) */
@@ -152,13 +152,13 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
    buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
    *(uintptr_t *)(buf - sizeof(void *)) = ptr;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* mark the non-aligned area */
    while ( ptr < buf - sizeof(void *) ) {
       *(unsigned long *)ptr = 0xcdcdcdcd;
       ptr += sizeof(unsigned long);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    return (void *)buf;
 #endif /* defined(HAVE_POSIX_MEMALIGN) */
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index ed207d4..72bedbd 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -143,7 +143,7 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
  *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
  *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
  ***/
-#ifndef DEBUG
+#ifndef MESA_DEBUG
 /* This function/macro is sensitive to precision.  Test very carefully
  * if you change it!
  */
@@ -166,12 +166,12 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
            __tmp.f = (FLT) * (255.0F/256.0F) + 32768.0F;		\
            UB = (GLubyte) __tmp.i;					\
         } while (0)
-#else
+#else /* MESA_DEBUG */
 #define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
 	ub = ((GLubyte) _mesa_lroundevenf(CLAMP((f), 0.0F, 1.0F) * 255.0F))
 #define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
 	ub = ((GLubyte) _mesa_lroundevenf((f) * 255.0F))
-#endif
+#endif /* MESA_DEBUG */
 
 static fi_type UINT_AS_UNION(GLuint u)
 {
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index ad046e2..9276c4f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4655,15 +4655,15 @@ struct gl_memory_info
    unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
 };
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 extern int MESA_VERBOSE;
 extern int MESA_DEBUG_FLAGS;
 # define MESA_FUNCTION __func__
-#else
+#else /* MESA_DEBUG */
 # define MESA_VERBOSE 0
 # define MESA_DEBUG_FLAGS 0
 # define MESA_FUNCTION "a function"
-#endif
+#endif /* MESA_DEBUG */
 
 
 /** The MESA_VERBOSE var is a bitmask of these flags */
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index c5c5024..7929ec2 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -454,7 +454,7 @@ detach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
          shProg->Shaders = newList;
          shProg->NumShaders = n - 1;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
          /* sanity check - make sure the new list's entries are sensible */
          for (j = 0; j < shProg->NumShaders; j++) {
             assert(shProg->Shaders[j]->Stage == MESA_SHADER_VERTEX ||
@@ -464,7 +464,7 @@ detach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
                    shProg->Shaders[j]->Stage == MESA_SHADER_FRAGMENT);
             assert(shProg->Shaders[j]->RefCount > 0);
          }
-#endif
+#endif /* MESA_DEBUG */
 
          return;
       }
@@ -1001,9 +1001,9 @@ shader_source(struct gl_shader *sh, const GLchar *source)
    /* free old shader source string and install new one */
    free((void *)sh->Source);
    sh->Source = source;
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    sh->SourceChecksum = _mesa_str_checksum(sh->Source);
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 8869b3d..a70e3ea 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -720,7 +720,7 @@ make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
    const GLint numPixels = width * height * depth;
    GLubyte *data = (GLubyte *) malloc(numPixels * components * sizeof(GLubyte));
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /*
     * Let's see if anyone finds this.  If glTexImage2D() is called with
     * a NULL image pointer then load the texture image with something
@@ -753,7 +753,7 @@ make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
          }
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 
    return data;
 }
diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c
index 321cffa..fc2d059 100644
--- a/src/mesa/program/prog_optimize.c
+++ b/src/mesa/program/prog_optimize.c
@@ -839,14 +839,14 @@ insert_interval_by_end(struct interval_list *list, const struct interval *inv)
    list->Intervals[i + 1] = *inv;
    list->Num++;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    {
       GLuint i;
       for (i = 0; i + 1 < list->Num; i++) {
          assert(list->Intervals[i].End <= list->Intervals[i + 1].End);
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
@@ -892,14 +892,14 @@ static void
 sort_interval_list_by_start(struct interval_list *list)
 {
    qsort(list->Intervals, list->Num, sizeof(struct interval), compare_start);
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    {
       GLuint i;
       for (i = 0; i + 1 < list->Num; i++) {
          assert(list->Intervals[i].Start <= list->Intervals[i + 1].Start);
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 }
 
 struct loop_info
diff --git a/src/mesa/sparc/sparc.c b/src/mesa/sparc/sparc.c
index 8d0509c..5f77676 100644
--- a/src/mesa/sparc/sparc.c
+++ b/src/mesa/sparc/sparc.c
@@ -35,9 +35,9 @@
 #include "math/m_xform.h"
 #include "tnl/t_context.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include "math/m_debug.h"
-#endif
+#endif /* MESA_DEBUG */
 
 #define XFORM_ARGS 	GLvector4f *to_vec, 		\
 			const GLfloat m[16], 		\
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index b9d3191..10f9a2f 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -241,11 +241,7 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
 
    /*printf("%s %x/%x\n", __func__, state->mesa, state->st);*/
 
-#ifdef DEBUG
-   if (1) {
-#else
-   if (0) {
-#endif
+#ifdef MESA_DEBUG
       /* Debug version which enforces various sanity checks on the
        * state flags which are generated and checked to help ensure
        * state atoms are ordered correctly in the list.
@@ -282,14 +278,12 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
 	 prev = *state;
       }
       /*printf("\n");*/
-
-   }
-   else {
+#else /* MESA_DEBUG */
       for (i = 0; i < num_atoms; i++) {
 	 if (check_state(state, &atoms[i]->dirty))
 	    atoms[i]->update( st );
       }
-   }
+#endif /* MESA_DEBUG */
 
    memset(state, 0, sizeof(*state));
 }
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index 7d769f2..ccb3fb7 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -194,7 +194,7 @@ update_framebuffer_state( struct st_context *st )
          pipe_surface_reference(&framebuffer->zsbuf, NULL);
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* Make sure the resource binding flags were set properly */
    for (i = 0; i < framebuffer->nr_cbufs; i++) {
       assert(!framebuffer->cbufs[i] ||
@@ -203,7 +203,7 @@ update_framebuffer_state( struct st_context *st )
    if (framebuffer->zsbuf) {
       assert(framebuffer->zsbuf->texture->bind & PIPE_BIND_DEPTH_STENCIL);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    if (framebuffer->width == UINT_MAX)
       framebuffer->width = 0;
diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c
index b51f350..1704c5c 100644
--- a/src/mesa/state_tracker/st_debug.c
+++ b/src/mesa/state_tracker/st_debug.c
@@ -42,7 +42,7 @@
 
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 int ST_DEBUG = 0;
 
 static const struct debug_named_value st_debug_flags[] = {
@@ -64,15 +64,15 @@ static const struct debug_named_value st_debug_flags[] = {
 };
 
 DEBUG_GET_ONCE_FLAGS_OPTION(st_debug, "ST_DEBUG", st_debug_flags, 0)
-#endif
+#endif /* MESA_DEBUG */
 
 
 void
 st_debug_init(void)
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    ST_DEBUG = debug_get_option_st_debug();
-#endif
+#endif /* MESA_DEBUG */
 }
 
 
diff --git a/src/mesa/state_tracker/st_debug.h b/src/mesa/state_tracker/st_debug.h
index 6c1e915..b3c42db 100644
--- a/src/mesa/state_tracker/st_debug.h
+++ b/src/mesa/state_tracker/st_debug.h
@@ -53,13 +53,13 @@ st_print_current(void);
 #define DEBUG_GREMEDY   0x1000
 #define DEBUG_NOREADPIXCACHE 0x2000
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 extern int ST_DEBUG;
 #define DBSTR(x) x
-#else
+#else /* MESA_DEBUG */
 #define ST_DEBUG 0
 #define DBSTR(x) ""
-#endif
+#endif /* MESA_DEBUG */
 
 void st_debug_init( void );
 
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 99527b7..ea3c0ca 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -2087,7 +2087,7 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
    int j;
    enum pipe_format pf;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    {
       static boolean firstCall = TRUE;
       if (firstCall) {
@@ -2095,9 +2095,9 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
          firstCall = FALSE;
       }
    }
-#else
+#else /* MESA_DEBUG */
    (void) test_format_conversion;
-#endif
+#endif /* MESA_DEBUG */
 
    /* can't render to compressed formats at this time */
    if (_mesa_is_compressed_format(st->ctx, internalFormat)
diff --git a/src/mesa/swrast/s_lines.c b/src/mesa/swrast/s_lines.c
index ab8da7d..2bc2d6f 100644
--- a/src/mesa/swrast/s_lines.c
+++ b/src/mesa/swrast/s_lines.c
@@ -193,7 +193,7 @@ _swrast_add_spec_terms_line(struct gl_context *ctx,
 
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 /* record the current line function name */
 static const char *lineFuncName = NULL;
@@ -205,11 +205,11 @@ do {                                    \
     swrast->Line = lineFunc;            \
 } while (0)
 
-#else
+#else /* MESA_DEBUG */
 
 #define USE(lineFunc)  swrast->Line = lineFunc
 
-#endif
+#endif /* MESA_DEBUG */
 
 
 
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index cd939ba..5905ec7 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1176,7 +1176,7 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
       }
    }
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* Make sure all fragments are within window bounds */
    if (span->arrayMask & SPAN_XY) {
       /* array of pixel locations */
@@ -1190,7 +1190,7 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
          }
       }
    }
-#endif
+#endif /* MESA_DEBUG */
 
    /* Polygon Stippling */
    if (ctx->Polygon.StippleFlag && span->primitive == GL_POLYGON) {
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index 721d088..76dfc7e 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -474,13 +474,13 @@ set_fetch_functions(const struct gl_sampler_object *samp,
 {
    mesa_format format = texImage->Base.TexFormat;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* check that the table entries are sorted by format name */
    mesa_format fmt;
    for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
       assert(texfetch_funcs[fmt].Name == fmt);
    }
-#endif
+#endif /* MESA_DEBUG */
 
    STATIC_ASSERT(ARRAY_SIZE(texfetch_funcs) == MESA_FORMAT_COUNT);
 
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 876a74b..6aba786 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -969,7 +969,7 @@ _swrast_add_spec_terms_triangle(struct gl_context *ctx, const SWvertex *v0,
 
 
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 
 /* record the current triangle function name */
 const char *_mesa_triFuncName = NULL;
@@ -981,11 +981,11 @@ do {						\
     swrast->Triangle = triFunc;			\
 } while (0)
 
-#else
+#else /* MESA_DEBUG */
 
 #define USE(triFunc)  swrast->Triangle = triFunc;
 
-#endif
+#endif /* MESA_DEBUG */
 
 
 
diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h
index 4f11f17..16cf439 100644
--- a/src/mesa/vbo/vbo_exec.h
+++ b/src/mesa/vbo/vbo_exec.h
@@ -136,9 +136,9 @@ struct vbo_exec_context
    /* Which flags to set in vbo_exec_begin_vertices() */
    GLbitfield begin_vertices_flags;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    GLint flush_call_depth;
-#endif
+#endif /* MESA_DEBUG */
 };
 
 
diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
index 32f15db..9d79ed3 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -1247,18 +1247,18 @@ void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags )
 {
    struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* debug check: make sure we don't get called recursively */
    exec->flush_call_depth++;
    assert(exec->flush_call_depth == 1);
-#endif
+#endif /* MESA_DEBUG */
 
    if (_mesa_inside_begin_end(ctx)) {
       /* We've had glBegin but not glEnd! */
-#ifdef DEBUG
+#ifdef MESA_DEBUG
       exec->flush_call_depth--;
       assert(exec->flush_call_depth == 0);
-#endif
+#endif /* MESA_DEBUG */
       return;
    }
 
@@ -1269,10 +1269,10 @@ void vbo_exec_FlushVertices( struct gl_context *ctx, GLuint flags )
     */
    ctx->Driver.NeedFlush &= ~(FLUSH_UPDATE_CURRENT | flags);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    exec->flush_call_depth--;
    assert(exec->flush_call_depth == 0);
-#endif
+#endif /* MESA_DEBUG */
 }
 
 void vbo_reset_attr(struct vbo_exec_context *exec, GLuint attr)
diff --git a/src/mesa/x86-64/x86-64.c b/src/mesa/x86-64/x86-64.c
index d484038..4270fe1 100644
--- a/src/mesa/x86-64/x86-64.c
+++ b/src/mesa/x86-64/x86-64.c
@@ -37,9 +37,9 @@
 #include "x86-64.h"
 #include "../x86/x86_xform.h"
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
 #include "math/m_debug.h"
-#endif
+#endif /* MESA_DEBUG */
 
 extern void _mesa_x86_64_cpuid(unsigned int *regs);
 
diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 9526011..51356ef 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -53,10 +53,10 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr);
 
 struct ralloc_header
 {
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    /* A canary value used to determine whether a pointer is ralloc'd. */
    unsigned canary;
-#endif
+#endif /* MESA_DEBUG */
 
    struct ralloc_header *parent;
 
@@ -80,9 +80,9 @@ get_header(const void *ptr)
 {
    ralloc_header *info = (ralloc_header *) (((char *) ptr) -
 					    sizeof(ralloc_header));
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    assert(info->canary == CANARY);
-#endif
+#endif /* MESA_DEBUG */
    return info;
 }
 
@@ -133,9 +133,9 @@ rzalloc_size(const void *ctx, size_t size)
 
    add_child(parent, info);
 
-#ifdef DEBUG
+#ifdef MESA_DEBUG
    info->canary = CANARY;
-#endif
+#endif /* MESA_DEBUG */
 
    return PTR_FROM_HEADER(info);
 }
-- 
2.7.4



More information about the mesa-dev mailing list