9 SYSCONFDIR=$(PREFIX)/etc
12 # The escaping is absurd, but we need to escape for shell, sed, make, define
13 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'))"
14 VERSION:=$(shell git describe --tags --abbrev=0)
16 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
17 $(error "pkg-config was not found")
20 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
21 # no pkg-config support for certain libraries
22 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
23 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
28 # unused-function, unused-label, unused-variable are turned on by -Wall
29 # We don’t want unused-parameter because of the use of many callbacks
30 CFLAGS += -Wunused-value
32 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
33 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
34 CFLAGS += -DXCB_COMPAT
35 CFLAGS += $(call cflags_for_lib, xcb-atom)
36 CFLAGS += $(call cflags_for_lib, xcb-aux)
38 CFLAGS += $(call cflags_for_lib, xcb-util)
40 CFLAGS += $(call cflags_for_lib, xcb-icccm)
41 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
42 CFLAGS += $(call cflags_for_lib, xcb-randr)
43 CFLAGS += $(call cflags_for_lib, xcb)
44 CFLAGS += $(call cflags_for_lib, xcursor)
45 CFLAGS += $(call cflags_for_lib, x11)
46 CFLAGS += $(call cflags_for_lib, yajl)
47 CFLAGS += $(call cflags_for_lib, libev)
48 CFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
49 CFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
50 CFLAGS += -DTERM_EMU=\"$(TERM_EMU)\"
53 LDFLAGS += $(call ldflags_for_lib, xcb-event, xcb-event)
54 LDFLAGS += $(call ldflags_for_lib, xcb-keysyms, xcb-keysyms)
55 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
56 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
57 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
59 LDFLAGS += $(call ldflags_for_lib, xcb-util)
61 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
62 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
63 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
64 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
65 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
66 LDFLAGS += $(call ldflags_for_lib, x11, X11)
67 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
68 LDFLAGS += $(call ldflags_for_lib, libev, ev)
70 ifeq ($(UNAME),NetBSD)
71 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
72 CFLAGS += -idirafter /usr/pkg/include
73 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
76 ifeq ($(UNAME),OpenBSD)
77 CFLAGS += -I${X11BASE}/include
79 LDFLAGS += -L${X11BASE}/lib
82 ifeq ($(UNAME),FreeBSD)
86 # Fallback for libyajl 1 which did not include yajl_version.h. We need
87 # YAJL_MAJOR from that file to decide which code path should be used.
88 CFLAGS += -idirafter yajl-fallback
90 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
91 CFLAGS += -D_GNU_SOURCE
95 # Extended debugging flags, macros shall be available in gcc
100 CFLAGS += -freorder-blocks-and-partition
104 CFLAGS += -fprofile-arcs -ftest-coverage
108 # Don’t print command lines which are run
111 # Always remake the following targets
112 .PHONY: install clean dist distclean