-LIBS += $(call ldflags_for_lib, xcb-util)
-endif
-LIBS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
-LIBS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
-LIBS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
-LIBS += $(call ldflags_for_lib, xcb, xcb)
-LIBS += $(call ldflags_for_lib, xcursor, Xcursor)
-LIBS += $(call ldflags_for_lib, x11, X11)
-LIBS += $(call ldflags_for_lib, yajl, yajl)
-LIBS += $(call ldflags_for_lib, libev, ev)
-LIBS += $(call ldflags_for_lib, libpcre, pcre)
+XCB_CFLAGS += $(call cflags_for_lib, xcb-util)
+XCB_LIBS += $(call ldflags_for_lib, xcb-util)
+endif
+
+# XCB keyboard stuff
+XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
+XCB_KBD_LIBS := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
+
+# XCB WM stuff
+XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
+XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
+XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
+XCB_WM_LIBS := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
+XCB_WM_LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
+XCB_WM_LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
+
+# Xlib
+X11_CFLAGS := $(call cflags_for_lib, x11)
+X11_LIBS := $(call ldflags_for_lib, x11,X11)
+
+# Xcursor
+XCURSOR_CFLAGS := $(call cflags_for_lib, xcursor)
+XCURSOR_LIBS := $(call ldflags_for_lib, xcursor,Xcursor)
+
+# yajl
+YAJL_CFLAGS := $(call cflags_for_lib, yajl)
+# Fallback for libyajl 1 which did not include yajl_version.h. We need
+# YAJL_MAJOR from that file to decide which code path should be used.
+YAJL_CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
+YAJL_LIBS := $(call ldflags_for_lib, yajl,yajl)
+
+#libev
+LIBEV_CFLAGS := $(call cflags_for_lib, libev)
+LIBEV_LIBS := $(call ldflags_for_lib, libev,ev)
+
+# libpcre
+PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
+ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
+I3_CPPFLAGS += -DPCRE_HAS_UCP=1
+endif
+PCRE_LIBS := $(call ldflags_for_lib, libpcre,pcre)
+
+# startup-notification
+LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
+LIBSN_LIBS := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
+
+# Pango
+PANGO_CFLAGS := $(call cflags_for_lib, cairo)
+PANGO_CFLAGS += $(call cflags_for_lib, pangocairo)
+I3_CPPFLAGS += -DPANGO_SUPPORT=1
+PANGO_LIBS := $(call ldflags_for_lib, cairo)
+PANGO_LIBS += $(call ldflags_for_lib, pangocairo)
+
+# libi3
+LIBS = -L$(TOPDIR) -li3
+
+## Platform-specific flags