12 SYSCONFDIR=$(PREFIX)/etc
15 # The escaping is absurd, but we need to escape for shell, sed, make, define
16 GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f $(TOPDIR)/.git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' $(TOPDIR)/.git/HEAD || echo 'unknown'))"
17 VERSION:=$(shell git describe --tags --abbrev=0)
19 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
20 $(error "pkg-config was not found")
23 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
24 # no pkg-config support for certain libraries.
26 # NOTE that you must not use a blank after comma when calling this:
27 # $(call ldflags_for_lib name, fallback) # bad
28 # $(call ldflags_for_lib name,fallback) # good
29 # Otherwise, the compiler will get -l foo instead of -lfoo
31 # We redirect stderr to /dev/null because pkg-config prints an error if support
32 # for gnome-config was enabled but gnome-config is not actually installed.
33 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
34 ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
39 # unused-function, unused-label, unused-variable are turned on by -Wall
40 # We don’t want unused-parameter because of the use of many callbacks
41 CFLAGS += -Wunused-value
43 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
44 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
45 CPPFLAGS += -DXCB_COMPAT
46 CFLAGS += $(call cflags_for_lib, xcb-atom)
47 CFLAGS += $(call cflags_for_lib, xcb-aux)
49 CFLAGS += $(call cflags_for_lib, xcb-util)
51 CFLAGS += $(call cflags_for_lib, xcb-icccm)
52 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
53 CFLAGS += $(call cflags_for_lib, xcb-randr)
54 CFLAGS += $(call cflags_for_lib, xcb)
55 CFLAGS += $(call cflags_for_lib, xcursor)
56 CFLAGS += $(call cflags_for_lib, x11)
57 CFLAGS += $(call cflags_for_lib, yajl)
58 CFLAGS += $(call cflags_for_lib, libev)
59 CFLAGS += $(call cflags_for_lib, libpcre)
60 CFLAGS += $(call cflags_for_lib, libstartup-notification-1.0)
61 CPPFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
62 CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
64 ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
65 CPPFLAGS += -DPCRE_HAS_UCP=1
69 LIBS += -L $(TOPDIR)/libi3 -li3
70 LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
71 LIBS += $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
72 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
73 LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
74 LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
76 LIBS += $(call ldflags_for_lib, xcb-util)
78 LIBS += $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
79 LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
80 LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
81 LIBS += $(call ldflags_for_lib, xcb,xcb)
82 LIBS += $(call ldflags_for_lib, xcursor,Xcursor)
83 LIBS += $(call ldflags_for_lib, x11,X11)
84 LIBS += $(call ldflags_for_lib, yajl,yajl)
85 LIBS += $(call ldflags_for_lib, libev,ev)
86 LIBS += $(call ldflags_for_lib, libpcre,pcre)
87 LIBS += $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
89 # Please test if -Wl,--as-needed works on your platform and send me a patch.
90 # it is known not to work on Darwin (Mac OS X)
91 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
92 LDFLAGS += -Wl,--as-needed
95 ifeq ($(UNAME),NetBSD)
96 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
97 CFLAGS += -idirafter /usr/pkg/include
98 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
101 ifeq ($(UNAME),OpenBSD)
102 CFLAGS += -I${X11BASE}/include
104 LDFLAGS += -L${X11BASE}/lib
107 ifeq ($(UNAME),FreeBSD)
111 ifeq ($(UNAME),Darwin)
115 # Fallback for libyajl 1 which did not include yajl_version.h. We need
116 # YAJL_MAJOR from that file to decide which code path should be used.
117 CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
119 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
120 CPPFLAGS += -D_GNU_SOURCE
124 # Extended debugging flags, macros shall be available in gcc
129 CFLAGS += -freorder-blocks-and-partition
133 CFLAGS += -fprofile-arcs -ftest-coverage
137 # Don’t print command lines which are run
140 # Always remake the following targets
141 .PHONY: install clean dist distclean