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