]> git.sur5r.net Git - i3/i3/blob - common.mk
Remove compatibility definitions for xcb-util < 0.3.8 (#2473)
[i3/i3] / common.mk
1 UNAME=$(shell uname)
2 DEBUG=1
3 ASAN=0
4 INSTALL=install
5 LN=ln
6 PKG_CONFIG=pkg-config
7 ifndef PREFIX
8   PREFIX=/usr
9 endif
10 ifndef EXEC_PREFIX
11   EXEC_PREFIX=$(PREFIX)
12 endif
13 ifndef SYSCONFDIR
14   ifeq ($(PREFIX),/usr)
15     SYSCONFDIR=/etc
16   else
17     SYSCONFDIR=$(PREFIX)/etc
18   endif
19 endif
20
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)/I3_VERSION ] && cat $(TOPDIR)/I3_VERSION | cut -d '-' -f 1)
25   I3_VERSION := '$(shell [ -f $(TOPDIR)/I3_VERSION ] && cat $(TOPDIR)/I3_VERSION)'
26 else
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/::)\")'
29 endif
30
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},)
35 PATCH_VERSION := 0
36 endif
37
38 ## Generic flags
39
40 # Default CFLAGS that users should be able to override
41 ifeq ($(DEBUG),1)
42 # Extended debugging flags, macros shall be available in gcc
43 CFLAGS ?= -pipe -gdwarf-2 -g3
44 else
45 CFLAGS ?= -pipe -O2 -freorder-blocks-and-partition
46 endif
47
48 ifeq ($(ASAN),1)
49 CFLAGS += -fsanitize=address -DI3_ASAN_ENABLED
50 LDFLAGS += -fsanitize=address
51 endif
52
53 # Default LDFLAGS that users should be able to override
54 LDFLAGS ?= $(as_needed_LDFLAG)
55
56 # Common CFLAGS for all i3 related binaries
57 I3_CFLAGS  = -std=c99
58 I3_CFLAGS += -Wall
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
63
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__
70
71
72 ## Libraries flags
73
74 ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null 1>/dev/null || echo 1),1)
75 $(error "pkg-config was not found")
76 endif
77
78 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
79 # no pkg-config support for certain libraries.
80 #
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
85 #
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))
90
91 # XCB common stuff
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 XCB_CFLAGS  += $(call cflags_for_lib, xcb-util)
97 XCB_LIBS    += $(call ldflags_for_lib, xcb-util)
98 ifneq ($(shell $(PKG_CONFIG) --atleast-version=0.3.8 xcb-util 2>/dev/null && echo 1),1)
99 $(error "xcb-util >= 0.3.8 not found")
100 endif
101 XCB_XKB_LIBS := $(call ldflags_for_lib, xcb-xkb,xcb-xkb)
102
103 # XCB keyboard stuff
104 XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
105 XCB_KBD_LIBS   := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
106
107 # XCB WM stuff
108 XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
109 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
110 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
111 XCB_WM_LIBS   := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
112 XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
113 XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-randr,xcb-randr)
114
115 # XCB cursor
116 XCB_CURSOR_CFLAGS := $(call cflags_for_lib, xcb-cursor)
117 XCB_CURSOR_LIBS   := $(call ldflags_for_lib, xcb-cursor,xcb-cursor)
118
119 XKB_COMMON_CFLAGS := $(call cflags_for_lib, xkbcommon,xkbcommon)
120 XKB_COMMON_LIBS := $(call ldflags_for_lib, xkbcommon,xkbcommon)
121 XKB_COMMON_X11_CFLAGS := $(call cflags_for_lib, xkbcommon-x11,xkbcommon-x11)
122 XKB_COMMON_X11_LIBS := $(call ldflags_for_lib, xkbcommon-x11,xkbcommon-x11)
123
124 # XCB xrm
125 XCB_XRM_CFLAGS := $(call cflags_for_lib, xcb-xrm)
126 XCB_XRM_LIBS   := $(call ldflags_for_lib, xcb-xrm,xcb-xrm)
127
128 # yajl
129 YAJL_CFLAGS := $(call cflags_for_lib, yajl)
130 YAJL_LIBS   := $(call ldflags_for_lib, yajl,yajl)
131
132 #libev
133 LIBEV_CFLAGS := $(call cflags_for_lib, libev)
134 LIBEV_LIBS   := $(call ldflags_for_lib, libev,ev)
135
136 # libpcre
137 PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
138 ifeq ($(shell $(PKG_CONFIG) --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
139 I3_CPPFLAGS += -DPCRE_HAS_UCP=1
140 endif
141 PCRE_LIBS   := $(call ldflags_for_lib, libpcre,pcre)
142
143 # startup-notification
144 LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
145 LIBSN_LIBS   := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
146
147 # Pango
148 PANGO_CFLAGS := $(call cflags_for_lib, cairo)
149 PANGO_CFLAGS += $(call cflags_for_lib, pangocairo)
150 I3_CPPFLAGS  += -DPANGO_SUPPORT=1
151 ifeq ($(shell $(PKG_CONFIG) --atleast-version=1.14.4 cairo 2>/dev/null && echo 1),1)
152 I3_CPPFLAGS  += -DCAIRO_SUPPORT=1
153 endif
154 PANGO_LIBS   := $(call ldflags_for_lib, cairo)
155 PANGO_LIBS   += $(call ldflags_for_lib, pangocairo)
156
157 # libi3
158 LIBS = -L$(TOPDIR) -li3 -lm
159
160 ## Platform-specific flags
161
162 # Please test if -Wl,--as-needed works on your platform and send me a patch.
163 # it is known not to work on Darwin (Mac OS X)
164 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
165 as_needed_LDFLAG = -Wl,--as-needed
166 endif
167
168 ifeq ($(UNAME),NetBSD)
169 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
170 I3_CFLAGS += -idirafter /usr/pkg/include
171 I3_LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
172 endif
173
174 ifeq ($(UNAME),OpenBSD)
175 I3_CFLAGS += -I${X11BASE}/include
176 LIBS += -liconv
177 I3_LDFLAGS += -L${X11BASE}/lib
178 endif
179
180 ifeq ($(UNAME),FreeBSD)
181 LIBS += -liconv
182 endif
183
184 ifeq ($(UNAME),Darwin)
185 LIBS += -liconv
186 else ifneq ($(UNAME),OpenBSD)
187 # Darwin (Mac OS X) and OpenBSD do not have librt
188 LIBS += -lrt
189 endif
190
191 ifeq ($(UNAME),SunOS)
192 LIBS += -lsocket -liconv -lgen
193 endif
194
195 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
196 I3_CPPFLAGS += -D_GNU_SOURCE
197 endif
198
199
200 ifeq ($(COVERAGE),1)
201 I3_CFLAGS += -fprofile-arcs -ftest-coverage
202 LIBS += -lgcov
203 endif
204
205 V ?= 0
206 ifeq ($(V),0)
207 # Don’t print command lines which are run
208 .SILENT:
209
210 # echo-ing vars
211 V_ASCIIDOC = echo ASCIIDOC $@;
212 V_POD2HTML = echo POD2HTML $@;
213 V_POD2MAN = echo POD2MAN $@;
214 V_A2X = echo A2X $@;
215 endif
216
217 # Always remake the following targets
218 .PHONY: install clean dist distclean
219