commit c704742
Michael Forney
·
2013-12-04 03:50:59 +0000 UTC
parent d7aa1f4
Add message printing mechanisms for debugging/errors
3 files changed,
+30,
-1
M
Makefile
+5,
-0
1@@ -35,6 +35,11 @@ FINAL_CFLAGS += -Werror=implicit-function-declaration -Werror=implicit-int \
2 -Werror=pointer-sign -Werror=pointer-arith \
3 -Wall -Wno-missing-braces
4
5+ifeq ($(ENABLE_DEBUG),1)
6+ FINAL_CPPFLAGS += -DENABLE_DEBUG=1
7+ FINAL_CFLAGS += -g
8+endif
9+
10 compile = $(call quiet,CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -I . -c -o $@ $< \
11 -MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o -MT $(basename $@).lo
12 link = $(call quiet,CCLD,$(CC)) $(FINAL_CFLAGS) -o $@ $^
+3,
-1
1@@ -8,10 +8,12 @@ PKGCONFIGDIR = $(LIBDIR)/pkgconfig
2
3 CC = gcc
4 CPPFLAGS = -D_GNU_SOURCE # Required for mkostemp
5-CFLAGS = -pipe -g
6+CFLAGS = -pipe
7 PKG_CONFIG ?= pkg-config
8 WAYLAND_SCANNER ?= wayland-scanner
9
10+ENABLE_DEBUG = 1
11+
12 ENABLE_STATIC = 1
13 ENABLE_SHARED = 1
14 ENABLE_XWAYLAND = 1
+22,
-0
1@@ -2,6 +2,7 @@
2 #define SWC_UTIL_H
3
4 #include <stdlib.h>
5+#include <stdio.h>
6 #include <stdbool.h>
7 #include <string.h>
8 #include <sys/time.h>
9@@ -11,6 +12,27 @@
10
11 #define EXPORT __attribute__((visibility("default")))
12
13+#if ENABLE_DEBUG
14+# define MESSAGE_SOURCE \
15+ fprintf(stderr, "[swc:%s:%d] ", __FILE__, __LINE__);
16+#else
17+# define MESSAGE_SOURCE
18+#endif
19+
20+#define MESSAGE(type, format, ...) \
21+ do { MESSAGE_SOURCE \
22+ fprintf(stderr, type ": " format, ## __VA_ARGS__); } \
23+ while (false)
24+
25+#define WARNING(format, ...) MESSAGE("WARNING", format, ## __VA_ARGS__)
26+#define ERROR(format, ...) MESSAGE("ERROR", format, ## __VA_ARGS__)
27+
28+#if ENABLE_DEBUG
29+# define DEBUG(format, ...) MESSAGE("DEBUG", format, ## __VA_ARGS__)
30+#else
31+# define DEBUG(format, ...)
32+#endif
33+
34 #ifdef offsetof
35 # define OFFSET_OF offsetof
36 #else