14 SYSCONFDIR=$(PREFIX)/etc
17 # The escaping is absurd, but we need to escape for shell, sed, make, define
18 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'))"
19 VERSION:=$(shell git describe --tags --abbrev=0)
24 # Default CFLAGS that users should be able to override
26 # Extended debugging flags, macros shall be available in gcc
27 CFLAGS ?= -pipe -gdwarf-2 -g3
29 CFLAGS ?= -pipe -O2 -freorder-blocks-and-partition
32 # Default LDFLAGS that users should be able to override
33 LDFLAGS ?= $(as_needed_LDFLAG)
35 # Common CFLAGS for all i3 related binaries
38 # unused-function, unused-label, unused-variable are turned on by -Wall
39 # We don’t want unused-parameter because of the use of many callbacks
40 I3_CFLAGS += -Wunused-value
41 I3_CFLAGS += -Iinclude
43 I3_CPPFLAGS = -DI3_VERSION=\"${GIT_VERSION}\"
44 I3_CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
49 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
50 $(error "pkg-config was not found")
53 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
54 # no pkg-config support for certain libraries.
56 # NOTE that you must not use a blank after comma when calling this:
57 # $(call ldflags_for_lib name, fallback) # bad
58 # $(call ldflags_for_lib name,fallback) # good
59 # Otherwise, the compiler will get -l foo instead of -lfoo
61 # We redirect stderr to /dev/null because pkg-config prints an error if support
62 # for gnome-config was enabled but gnome-config is not actually installed.
63 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
64 ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
67 LIBS += -L $(TOPDIR) -li3
70 XCB_CFLAGS := $(call cflags_for_lib, xcb)
71 XCB_CFLAGS += $(call cflags_for_lib, xcb-event)
72 XCB_LIBS := $(call ldflags_for_lib, xcb,xcb)
73 XCB_LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
74 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
75 XCB_CFLAGS += $(call cflags_for_lib, xcb-atom)
76 XCB_CFLAGS += $(call cflags_for_lib, xcb-aux)
77 XCB_LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
78 XCB_LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
80 XCB_CFLAGS += $(call cflags_for_lib, xcb-util)
81 XCB_LIBS += $(call ldflags_for_lib, xcb-util)
85 XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
86 XCB_KBD_LIBS := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
89 XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
90 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
91 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
92 XCB_WM_LIBS := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
93 XCB_WM_LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
94 XCB_WM_LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
97 X11_CFLAGS := $(call cflags_for_lib, x11)
98 X11_LIBS := $(call ldflags_for_lib, x11,X11)
101 XCURSOR_CFLAGS := $(call cflags_for_lib, xcursor)
102 XCURSOR_LIBS := $(call ldflags_for_lib, xcursor,Xcursor)
105 YAJL_CFLAGS := $(call cflags_for_lib, yajl)
106 # Fallback for libyajl 1 which did not include yajl_version.h. We need
107 # YAJL_MAJOR from that file to decide which code path should be used.
108 YAJL_CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
109 YAJL_LIBS := $(call ldflags_for_lib, yajl,yajl)
112 LIBEV_CFLAGS := $(call cflags_for_lib, libev)
113 LIBEV_LIBS := $(call ldflags_for_lib, libev,ev)
116 PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
117 ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
118 I3_CPPFLAGS += -DPCRE_HAS_UCP=1
120 PCRE_LIBS := $(call ldflags_for_lib, libpcre,pcre)
122 # startup-notification
123 LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
124 LIBSN_LIBS := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
127 ## Platform-specific flags
129 # Please test if -Wl,--as-needed works on your platform and send me a patch.
130 # it is known not to work on Darwin (Mac OS X)
131 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
132 as_needed_LDFLAG = -Wl,--as-needed
135 ifeq ($(UNAME),NetBSD)
136 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
137 I3_CFLAGS += -idirafter /usr/pkg/include
138 I3_LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
141 ifeq ($(UNAME),OpenBSD)
142 I3_CFLAGS += -I${X11BASE}/include
144 I3_LDFLAGS += -L${X11BASE}/lib
147 ifeq ($(UNAME),FreeBSD)
151 ifeq ($(UNAME),Darwin)
154 # Darwin (Mac OS X) doesn’t have librt
158 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
159 I3_CPPFLAGS += -D_GNU_SOURCE
164 I3_CFLAGS += -fprofile-arcs -ftest-coverage
170 # Don’t print command lines which are run
174 V_ASCIIDOC = echo ASCIIDOC $@;
178 # Always remake the following targets
179 .PHONY: install clean dist distclean