-cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
-ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
-
-ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
-I3_CPPFLAGS += -DXCB_COMPAT
-CFLAGS += $(call cflags_for_lib, xcb-atom)
-CFLAGS += $(call cflags_for_lib, xcb-aux)
-else
-CFLAGS += $(call cflags_for_lib, xcb-util)
+cflags_for_lib = $(shell $(PKG_CONFIG) --silence-errors --cflags $(1) 2>/dev/null)
+ldflags_for_lib = $(shell $(PKG_CONFIG) --exists 2>/dev/null $(1) && $(PKG_CONFIG) --libs $(1) 2>/dev/null || echo -l$(2))
+
+# XCB common stuff
+XCB_CFLAGS := $(call cflags_for_lib, xcb)
+XCB_CFLAGS += $(call cflags_for_lib, xcb-event)
+XCB_LIBS := $(call ldflags_for_lib, xcb,xcb)
+XCB_LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
+XCB_CFLAGS += $(call cflags_for_lib, xcb-util)
+XCB_LIBS += $(call ldflags_for_lib, xcb-util)
+ifneq ($(shell $(PKG_CONFIG) --atleast-version=0.3.8 xcb-util 2>/dev/null && echo 1),1)
+$(error "xcb-util >= 0.3.8 not found")