commit c704742030d7ae8d797c9a7fc736c08fcab03bc3
parent d7aa1f45dfe457bbff93e08a02baa948f979ec17
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 3 Dec 2013 19:50:59 -0800
Add message printing mechanisms for debugging/errors
Diffstat:
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -35,6 +35,11 @@ FINAL_CFLAGS += -Werror=implicit-function-declaration -Werror=implicit-int \
-Werror=pointer-sign -Werror=pointer-arith \
-Wall -Wno-missing-braces
+ifeq ($(ENABLE_DEBUG),1)
+ FINAL_CPPFLAGS += -DENABLE_DEBUG=1
+ FINAL_CFLAGS += -g
+endif
+
compile = $(call quiet,CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -I . -c -o $@ $< \
-MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o -MT $(basename $@).lo
link = $(call quiet,CCLD,$(CC)) $(FINAL_CFLAGS) -o $@ $^
diff --git a/config.mk b/config.mk
@@ -8,10 +8,12 @@ PKGCONFIGDIR = $(LIBDIR)/pkgconfig
CC = gcc
CPPFLAGS = -D_GNU_SOURCE # Required for mkostemp
-CFLAGS = -pipe -g
+CFLAGS = -pipe
PKG_CONFIG ?= pkg-config
WAYLAND_SCANNER ?= wayland-scanner
+ENABLE_DEBUG = 1
+
ENABLE_STATIC = 1
ENABLE_SHARED = 1
ENABLE_XWAYLAND = 1
diff --git a/libswc/util.h b/libswc/util.h
@@ -2,6 +2,7 @@
#define SWC_UTIL_H
#include <stdlib.h>
+#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
@@ -11,6 +12,27 @@
#define EXPORT __attribute__((visibility("default")))
+#if ENABLE_DEBUG
+# define MESSAGE_SOURCE \
+ fprintf(stderr, "[swc:%s:%d] ", __FILE__, __LINE__);
+#else
+# define MESSAGE_SOURCE
+#endif
+
+#define MESSAGE(type, format, ...) \
+ do { MESSAGE_SOURCE \
+ fprintf(stderr, type ": " format, ## __VA_ARGS__); } \
+ while (false)
+
+#define WARNING(format, ...) MESSAGE("WARNING", format, ## __VA_ARGS__)
+#define ERROR(format, ...) MESSAGE("ERROR", format, ## __VA_ARGS__)
+
+#if ENABLE_DEBUG
+# define DEBUG(format, ...) MESSAGE("DEBUG", format, ## __VA_ARGS__)
+#else
+# define DEBUG(format, ...)
+#endif
+
#ifdef offsetof
# define OFFSET_OF offsetof
#else