btrfs-progs: build: add support for debugging builds
authorDavid Sterba <dsterba@suse.com>
Thu, 12 May 2016 12:13:30 +0000 (14:13 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 1 Jun 2016 12:56:56 +0000 (14:56 +0200)
Add an easy way to build a debugging version, without optimizations and
with debugging info by default. Any overrides can be done via
DEBUG_CFLAGS that are added on top of the defaults. Can be combined with
V, C or W options.

Usage:
  $ make D=1

Signed-off-by: David Sterba <dsterba@suse.com>
Makefile.in

index dadfd40..7e65efb 100644 (file)
@@ -10,7 +10,9 @@
 # Tuning by variables (environment or make arguments):
 #   V=1            verbose, print command lines (default: quiet)
 #   C=1            run checker before compilation (default checker: sparse)
+#   D=1            debugging build, turn off optimizations
 #   W=123          build with warnings (default: off)
+#   DEBUG_CFLAGS   additional compiler flags for debugging build
 #   EXTRA_CFLAGS   additional compiler flags
 #   EXTRA_LDFLAGS  additional linker flags
 #
@@ -36,13 +38,20 @@ DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
 EXTRA_CFLAGS :=
 EXTRA_LDFLAGS :=
 
+DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
+DEBUG_CFLAGS_INTERNAL =
+DEBUG_CFLAGS :=
+
 # Common build flags
 CFLAGS = @CFLAGS@ \
         -include config.h \
         -DBTRFS_FLAT_INCLUDES \
         -D_XOPEN_SOURCE=700  \
         -fno-strict-aliasing \
-        -fPIC $(EXTRAWARN_CFLAGS) $(EXTRA_CFLAGS)
+        -fPIC \
+        $(EXTRAWARN_CFLAGS) \
+        $(DEBUG_CFLAGS_INTERNAL) \
+        $(EXTRA_CFLAGS)
 
 LDFLAGS = @LDFLAGS@ \
          -rdynamic $(EXTRA_LDFLAGS)
@@ -107,6 +116,10 @@ else
   Q = @
 endif
 
+ifeq ("$(origin D)", "command line")
+  DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
+endif
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 # build all by default