17 SYSCONFDIR=$(PREFIX)/etc
21 # In dist and snapshot tarballs, use the I3_VERSION and VERSION files. Otherwise use git information.
22 ifeq ($(wildcard .git),)
23 # not in git repository
24 VERSION := '$(shell [ -f $(TOPDIR)/VERSION ] && cat $(TOPDIR)/VERSION)'
25 I3_VERSION := '$(shell [ -f $(TOPDIR)/I3_VERSION ] && cat $(TOPDIR)/I3_VERSION)'
27 VERSION := $(shell git describe --tags --abbrev=0)
28 I3_VERSION := '$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch \"$(shell git describe --tags --always --all | sed s:heads/::)\")'
31 MAJOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 1)
32 MINOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 2)
33 PATCH_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 3)
34 ifeq (${PATCH_VERSION},)
40 # Default CFLAGS that users should be able to override
42 # Extended debugging flags, macros shall be available in gcc
43 CFLAGS ?= -pipe -gdwarf-2 -g3
45 CFLAGS ?= -pipe -O2 -freorder-blocks-and-partition
49 CFLAGS += -fsanitize=address -DI3_ASAN_ENABLED
50 LDFLAGS += -fsanitize=address
53 # Default LDFLAGS that users should be able to override
54 LDFLAGS ?= $(as_needed_LDFLAG)
56 # Common CFLAGS for all i3 related binaries
59 # unused-function, unused-label, unused-variable are turned on by -Wall
60 # We don’t want unused-parameter because of the use of many callbacks
61 I3_CFLAGS += -Wunused-value
62 I3_CFLAGS += -Iinclude
64 I3_CPPFLAGS = -DI3_VERSION=\"${I3_VERSION}\"
65 I3_CPPFLAGS += -DMAJOR_VERSION=${MAJOR_VERSION}
66 I3_CPPFLAGS += -DMINOR_VERSION=${MINOR_VERSION}
67 I3_CPPFLAGS += -DPATCH_VERSION=${PATCH_VERSION}
68 I3_CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
69 I3_CPPFLAGS += -DI3__FILE__=__FILE__
74 ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null 1>/dev/null || echo 1),1)
75 $(error "pkg-config was not found")
78 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
79 # no pkg-config support for certain libraries.
81 # NOTE that you must not use a blank after comma when calling this:
82 # $(call ldflags_for_lib name, fallback) # bad
83 # $(call ldflags_for_lib name,fallback) # good
84 # Otherwise, the compiler will get -l foo instead of -lfoo
86 # We redirect stderr to /dev/null because pkg-config prints an error if support
87 # for gnome-config was enabled but gnome-config is not actually installed.
88 cflags_for_lib = $(shell $(PKG_CONFIG) --silence-errors --cflags $(1) 2>/dev/null)
89 ldflags_for_lib = $(shell $(PKG_CONFIG) --exists 2>/dev/null $(1) && $(PKG_CONFIG) --libs $(1) 2>/dev/null || echo -l$(2))
92 XCB_CFLAGS := $(call cflags_for_lib, xcb)
93 XCB_CFLAGS += $(call cflags_for_lib, xcb-event)
94 XCB_LIBS := $(call ldflags_for_lib, xcb,xcb)
95 XCB_LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
96 ifeq ($(shell $(PKG_CONFIG) --exists xcb-util 2>/dev/null || echo 1),1)
97 XCB_CFLAGS += $(call cflags_for_lib, xcb-atom)
98 XCB_CFLAGS += $(call cflags_for_lib, xcb-aux)
99 XCB_LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
100 XCB_LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
101 XCB_CPPFLAGS+= -DXCB_COMPAT
103 XCB_CFLAGS += $(call cflags_for_lib, xcb-util)
104 XCB_LIBS += $(call ldflags_for_lib, xcb-util)
106 XCB_XKB_LIBS := $(call ldflags_for_lib, xcb-xkb,xcb-xkb)
109 XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
110 XCB_KBD_LIBS := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
113 XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
114 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
115 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
116 XCB_WM_LIBS := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
117 XCB_WM_LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
118 XCB_WM_LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
121 XCB_CURSOR_CFLAGS := $(call cflags_for_lib, xcb-cursor)
122 XCB_CURSOR_LIBS := $(call ldflags_for_lib, xcb-cursor,xcb-cursor)
124 XKB_COMMON_CFLAGS := $(call cflags_for_lib, xkbcommon,xkbcommon)
125 XKB_COMMON_LIBS := $(call ldflags_for_lib, xkbcommon,xkbcommon)
126 XKB_COMMON_X11_CFLAGS := $(call cflags_for_lib, xkbcommon-x11,xkbcommon-x11)
127 XKB_COMMON_X11_LIBS := $(call ldflags_for_lib, xkbcommon-x11,xkbcommon-x11)
130 XCB_XRM_CFLAGS := $(call cflags_for_lib, xcb-xrm)
131 XCB_XRM_LIBS := $(call ldflags_for_lib, xcb-xrm,xcb-xrm)
134 YAJL_CFLAGS := $(call cflags_for_lib, yajl)
135 YAJL_LIBS := $(call ldflags_for_lib, yajl,yajl)
138 LIBEV_CFLAGS := $(call cflags_for_lib, libev)
139 LIBEV_LIBS := $(call ldflags_for_lib, libev,ev)
142 PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
143 ifeq ($(shell $(PKG_CONFIG) --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
144 I3_CPPFLAGS += -DPCRE_HAS_UCP=1
146 PCRE_LIBS := $(call ldflags_for_lib, libpcre,pcre)
148 # startup-notification
149 LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
150 LIBSN_LIBS := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
153 PANGO_CFLAGS := $(call cflags_for_lib, cairo)
154 PANGO_CFLAGS += $(call cflags_for_lib, pangocairo)
155 I3_CPPFLAGS += -DPANGO_SUPPORT=1
156 ifeq ($(shell $(PKG_CONFIG) --atleast-version=1.14.4 cairo 2>/dev/null && echo 1),1)
157 I3_CPPFLAGS += -DCAIRO_SUPPORT=1
159 PANGO_LIBS := $(call ldflags_for_lib, cairo)
160 PANGO_LIBS += $(call ldflags_for_lib, pangocairo)
163 LIBS = -L$(TOPDIR) -li3 -lm
165 ## Platform-specific flags
167 # Please test if -Wl,--as-needed works on your platform and send me a patch.
168 # it is known not to work on Darwin (Mac OS X)
169 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
170 as_needed_LDFLAG = -Wl,--as-needed
173 ifeq ($(UNAME),NetBSD)
174 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
175 I3_CFLAGS += -idirafter /usr/pkg/include
176 I3_LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
179 ifeq ($(UNAME),OpenBSD)
180 I3_CFLAGS += -I${X11BASE}/include
182 I3_LDFLAGS += -L${X11BASE}/lib
185 ifeq ($(UNAME),FreeBSD)
189 ifeq ($(UNAME),Darwin)
191 else ifneq ($(UNAME),OpenBSD)
192 # Darwin (Mac OS X) and OpenBSD do not have librt
196 ifeq ($(UNAME),SunOS)
197 LIBS += -lsocket -liconv -lgen
200 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
201 I3_CPPFLAGS += -D_GNU_SOURCE
206 I3_CFLAGS += -fprofile-arcs -ftest-coverage
212 # Don’t print command lines which are run
216 V_ASCIIDOC = echo ASCIIDOC $@;
217 V_POD2HTML = echo POD2HTML $@;
218 V_POD2MAN = echo POD2MAN $@;
222 # Always remake the following targets
223 .PHONY: install clean dist distclean