8 SYSCONFDIR=$(PREFIX)/etc
10 # The escaping is absurd, but we need to escape for shell, sed, make, define
11 GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f .git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' .git/HEAD || echo 'unknown'))"
12 VERSION:=$(shell git describe --tags --abbrev=0)
14 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
15 $(error "pkg-config was not found")
18 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
19 # no pkg-config support for certain libraries
20 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
21 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
26 # unused-function, unused-label, unused-variable are turned on by -Wall
27 # We don’t want unused-parameter because of the use of many callbacks
28 CFLAGS += -Wunused-value
30 CFLAGS += -I/usr/local/include
31 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
32 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
33 CFLAGS += -DXCB_COMPAT
34 CFLAGS += $(call cflags_for_lib, xcb-atom)
35 CFLAGS += $(call cflags_for_lib, xcb-aux)
37 CFLAGS += $(call cflags_for_lib, xcb-util)
39 CFLAGS += $(call cflags_for_lib, xcb-icccm)
40 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
41 CFLAGS += $(call cflags_for_lib, xcb-randr)
42 CFLAGS += $(call cflags_for_lib, xcb)
43 CFLAGS += $(call cflags_for_lib, xcursor)
44 CFLAGS += $(call cflags_for_lib, x11)
45 CFLAGS += $(call cflags_for_lib, yajl)
46 CFLAGS += $(call cflags_for_lib, libev)
47 CFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
48 CFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
51 LDFLAGS += $(call ldflags_for_lib, xcb-event, xcb-event)
52 LDFLAGS += $(call ldflags_for_lib, xcb-keysyms, xcb-keysyms)
53 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
54 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
55 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
57 LDFLAGS += $(call ldflags_for_lib, xcb-util)
59 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
60 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
61 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
62 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
63 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
64 LDFLAGS += $(call ldflags_for_lib, x11, X11)
65 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
66 LDFLAGS += $(call ldflags_for_lib, libev, ev)
67 LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
69 ifeq ($(UNAME),NetBSD)
70 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
71 CFLAGS += -idirafter /usr/pkg/include
72 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
75 ifeq ($(UNAME),OpenBSD)
76 CFLAGS += -I${X11BASE}/include
78 LDFLAGS += -L${X11BASE}/lib
81 ifeq ($(UNAME),FreeBSD)
85 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
86 CFLAGS += -D_GNU_SOURCE
90 # Extended debugging flags, macros shall be available in gcc
95 CFLAGS += -freorder-blocks-and-partition
98 # Don’t print command lines which are run
101 # Always remake the following targets
102 .PHONY: install clean dist distclean