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