9 SYSCONFDIR=$(PREFIX)/etc
11 # The escaping is absurd, but we need to escape for shell, sed, make, define
12 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'))"
13 VERSION:=$(shell git describe --tags --abbrev=0)
15 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
16 $(error "pkg-config was not found")
19 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
20 # no pkg-config support for certain libraries
21 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
22 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
27 # unused-function, unused-label, unused-variable are turned on by -Wall
28 # We don’t want unused-parameter because of the use of many callbacks
29 CFLAGS += -Wunused-value
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)
68 ifeq ($(UNAME),NetBSD)
69 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
70 CFLAGS += -idirafter /usr/pkg/include
71 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
74 ifeq ($(UNAME),OpenBSD)
75 CFLAGS += -I${X11BASE}/include
77 LDFLAGS += -L${X11BASE}/lib
80 ifeq ($(UNAME),FreeBSD)
84 # Fallback for libyajl 1 which did not include yajl_version.h. We need
85 # YAJL_MAJOR from that file to decide which code path should be used.
86 CFLAGS += -idirafter yajl-fallback
88 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
89 CFLAGS += -D_GNU_SOURCE
93 # Extended debugging flags, macros shall be available in gcc
98 CFLAGS += -freorder-blocks-and-partition
102 CFLAGS += -fprofile-arcs -ftest-coverage
106 # Don’t print command lines which are run
109 # Always remake the following targets
110 .PHONY: install clean dist distclean