]> git.sur5r.net Git - i3/i3/blob - common.mk
fix compilation with older xcb-util with -DXCB_COMPAT (Thanks okraits)
[i3/i3] / common.mk
1 UNAME=$(shell uname)
2 DEBUG=1
3 COVERAGE=0
4 INSTALL=install
5 FLEX=flex
6 BISON=bison
7 ifndef PREFIX
8   PREFIX=/usr
9 endif
10 ifndef SYSCONFDIR
11   ifeq ($(PREFIX),/usr)
12     SYSCONFDIR=/etc
13   else
14     SYSCONFDIR=$(PREFIX)/etc
15   endif
16 endif
17
18 # In dist tarballs, the version is stored in the I3_VERSION and VERSION files.
19 I3_VERSION := '$(shell [ -f $(TOPDIR)/I3_VERSION ] && cat $(TOPDIR)/I3_VERSION)'
20 VERSION := '$(shell [ -f $(TOPDIR)/VERSION ] && cat $(TOPDIR)/VERSION)'
21 ifeq ('',$(I3_VERSION))
22 VERSION := $(shell git describe --tags --abbrev=0)
23 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/::)\")'
24 endif
25
26 MAJOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 1)
27 MINOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 2)
28 PATCH_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 3)
29 ifeq (${PATCH_VERSION},)
30 PATCH_VERSION := 0
31 endif
32
33 ## Generic flags
34
35 # Default CFLAGS that users should be able to override
36 ifeq ($(DEBUG),1)
37 # Extended debugging flags, macros shall be available in gcc
38 CFLAGS ?= -pipe -gdwarf-2 -g3
39 else
40 CFLAGS ?= -pipe -O2 -freorder-blocks-and-partition
41 endif
42
43 # Default LDFLAGS that users should be able to override
44 LDFLAGS ?= $(as_needed_LDFLAG)
45
46 # Common CFLAGS for all i3 related binaries
47 I3_CFLAGS  = -std=c99
48 I3_CFLAGS += -Wall
49 # unused-function, unused-label, unused-variable are turned on by -Wall
50 # We don’t want unused-parameter because of the use of many callbacks
51 I3_CFLAGS += -Wunused-value
52 I3_CFLAGS += -Iinclude
53
54 I3_CPPFLAGS  = -DI3_VERSION=\"${I3_VERSION}\"
55 I3_CPPFLAGS += -DMAJOR_VERSION=${MAJOR_VERSION}
56 I3_CPPFLAGS += -DMINOR_VERSION=${MINOR_VERSION}
57 I3_CPPFLAGS += -DPATCH_VERSION=${PATCH_VERSION}
58 I3_CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
59 I3_CPPFLAGS += -DI3__FILE__=__FILE__
60
61
62 ## Libraries flags
63
64 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
65 $(error "pkg-config was not found")
66 endif
67
68 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
69 # no pkg-config support for certain libraries.
70 #
71 # NOTE that you must not use a blank after comma when calling this:
72 #     $(call ldflags_for_lib name, fallback) # bad
73 #     $(call ldflags_for_lib name,fallback) # good
74 # Otherwise, the compiler will get -l foo instead of -lfoo
75 #
76 # We redirect stderr to /dev/null because pkg-config prints an error if support
77 # for gnome-config was enabled but gnome-config is not actually installed.
78 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
79 ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
80
81 # XCB common stuff
82 XCB_CFLAGS  := $(call cflags_for_lib, xcb)
83 XCB_CFLAGS  += $(call cflags_for_lib, xcb-event)
84 XCB_LIBS    := $(call ldflags_for_lib, xcb,xcb)
85 XCB_LIBS    += $(call ldflags_for_lib, xcb-event,xcb-event)
86 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
87 XCB_CFLAGS  += $(call cflags_for_lib, xcb-atom)
88 XCB_CFLAGS  += $(call cflags_for_lib, xcb-aux)
89 XCB_LIBS    += $(call ldflags_for_lib, xcb-atom,xcb-atom)
90 XCB_LIBS    += $(call ldflags_for_lib, xcb-aux,xcb-aux)
91 XCB_CPPFLAGS+= -DXCB_COMPAT
92 else
93 XCB_CFLAGS  += $(call cflags_for_lib, xcb-util)
94 XCB_LIBS    += $(call ldflags_for_lib, xcb-util)
95 endif
96
97 # XCB keyboard stuff
98 XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
99 XCB_KBD_LIBS   := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
100
101 # XCB WM stuff
102 XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
103 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
104 XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
105 XCB_WM_LIBS   := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
106 XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
107 XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-randr,xcb-randr)
108
109 # Xlib
110 X11_CFLAGS := $(call cflags_for_lib, x11)
111 X11_LIBS   := $(call ldflags_for_lib, x11,X11)
112
113 # Xcursor
114 XCURSOR_CFLAGS := $(call cflags_for_lib, xcursor)
115 XCURSOR_LIBS   := $(call ldflags_for_lib, xcursor,Xcursor)
116
117 # yajl
118 YAJL_CFLAGS := $(call cflags_for_lib, yajl)
119 # Fallback for libyajl 1 which did not include yajl_version.h. We need
120 # YAJL_MAJOR from that file to decide which code path should be used.
121 YAJL_CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
122 YAJL_LIBS   := $(call ldflags_for_lib, yajl,yajl)
123
124 #libev
125 LIBEV_CFLAGS := $(call cflags_for_lib, libev)
126 LIBEV_LIBS   := $(call ldflags_for_lib, libev,ev)
127
128 # libpcre
129 PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
130 ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
131 I3_CPPFLAGS += -DPCRE_HAS_UCP=1
132 endif
133 PCRE_LIBS   := $(call ldflags_for_lib, libpcre,pcre)
134
135 # startup-notification
136 LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
137 LIBSN_LIBS   := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
138
139 # Pango
140 PANGO_CFLAGS := $(call cflags_for_lib, cairo)
141 PANGO_CFLAGS += $(call cflags_for_lib, pangocairo)
142 I3_CPPFLAGS  += -DPANGO_SUPPORT=1
143 PANGO_LIBS   := $(call ldflags_for_lib, cairo)
144 PANGO_LIBS   += $(call ldflags_for_lib, pangocairo)
145
146 # libi3
147 LIBS = -L$(TOPDIR) -li3
148
149 ## Platform-specific flags
150
151 # Please test if -Wl,--as-needed works on your platform and send me a patch.
152 # it is known not to work on Darwin (Mac OS X)
153 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
154 as_needed_LDFLAG = -Wl,--as-needed
155 endif
156
157 ifeq ($(UNAME),NetBSD)
158 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
159 I3_CFLAGS += -idirafter /usr/pkg/include
160 I3_LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
161 endif
162
163 ifeq ($(UNAME),OpenBSD)
164 I3_CFLAGS += -I${X11BASE}/include
165 LIBS += -liconv
166 I3_LDFLAGS += -L${X11BASE}/lib
167 endif
168
169 ifeq ($(UNAME),FreeBSD)
170 LIBS += -liconv
171 endif
172
173 ifeq ($(UNAME),Darwin)
174 LIBS += -liconv
175 else
176 # Darwin (Mac OS X) doesn’t have librt
177 LIBS += -lrt
178 endif
179
180 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
181 I3_CPPFLAGS += -D_GNU_SOURCE
182 endif
183
184
185 ifeq ($(COVERAGE),1)
186 I3_CFLAGS += -fprofile-arcs -ftest-coverage
187 LIBS += -lgcov
188 endif
189
190 V ?= 0
191 ifeq ($(V),0)
192 # Don’t print command lines which are run
193 .SILENT:
194
195 # echo-ing vars
196 V_ASCIIDOC = echo ASCIIDOC $@;
197 V_A2X = echo A2X $@;
198 endif
199
200 # Always remake the following targets
201 .PHONY: install clean dist distclean
202