]> git.sur5r.net Git - i3/i3/blob - common.mk
Make i3 compatible with the very latest xcb
[i3/i3] / common.mk
1 UNAME=$(shell uname)
2 DEBUG=1
3 INSTALL=install
4 PREFIX=/usr
5 ifeq ($(PREFIX),/usr)
6 SYSCONFDIR=/etc
7 else
8 SYSCONFDIR=$(PREFIX)/etc
9 endif
10 # The escaping is absurd, but we need to escape for shell, sed, make, define
11 GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f .git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' .git/HEAD || echo 'unknown'))"
12 VERSION:=$(shell git describe --tags --abbrev=0)
13
14 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
15 $(error "pkg-config was not found")
16 endif
17
18 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
19 # no pkg-config support for certain libraries
20 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
21 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
22
23 CFLAGS += -std=c99
24 CFLAGS += -pipe
25 CFLAGS += -Wall
26 # unused-function, unused-label, unused-variable are turned on by -Wall
27 # We don’t want unused-parameter because of the use of many callbacks
28 CFLAGS += -Wunused-value
29 CFLAGS += -Iinclude
30 CFLAGS += -I/usr/local/include
31 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
32 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
33 CFLAGS += -DXCB_COMPAT
34 CFLAGS += $(call cflags_for_lib, xcb-atom)
35 CFLAGS += $(call cflags_for_lib, xcb-aux)
36 else
37 CFLAGS += $(call cflags_for_lib, xcb-util)
38 endif
39 CFLAGS += $(call cflags_for_lib, xcb-icccm)
40 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
41 CFLAGS += $(call cflags_for_lib, xcb-randr)
42 CFLAGS += $(call cflags_for_lib, xcb)
43 CFLAGS += $(call cflags_for_lib, xcursor)
44 CFLAGS += $(call cflags_for_lib, x11)
45 CFLAGS += $(call cflags_for_lib, yajl)
46 CFLAGS += $(call cflags_for_lib, libev)
47 CFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
48 CFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
49
50 LDFLAGS += -lm
51 LDFLAGS += $(call ldflags_for_lib, xcb-event, xcb-event)
52 LDFLAGS += $(call ldflags_for_lib, xcb-property, xcb-property)
53 LDFLAGS += $(call ldflags_for_lib, xcb-keysyms, xcb-keysyms)
54 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
55 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
56 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
57 else
58 LDFLAGS += $(call ldflags_for_lib, xcb-util)
59 endif
60 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
61 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
62 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
63 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
64 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
65 LDFLAGS += $(call ldflags_for_lib, x11, X11)
66 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
67 LDFLAGS += $(call ldflags_for_lib, libev, ev)
68 LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
69
70 ifeq ($(UNAME),NetBSD)
71 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
72 CFLAGS += -idirafter /usr/pkg/include
73 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
74 endif
75
76 ifeq ($(UNAME),OpenBSD)
77 CFLAGS += -I${X11BASE}/include
78 LDFLAGS += -liconv
79 LDFLAGS += -L${X11BASE}/lib
80 endif
81
82 ifeq ($(UNAME),FreeBSD)
83 LDFLAGS += -liconv
84 endif
85
86 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
87 CFLAGS += -D_GNU_SOURCE
88 endif
89
90 ifeq ($(DEBUG),1)
91 # Extended debugging flags, macros shall be available in gcc
92 CFLAGS += -gdwarf-2
93 CFLAGS += -g3
94 else
95 CFLAGS += -O2
96 CFLAGS += -freorder-blocks-and-partition
97 endif
98
99 # Don’t print command lines which are run
100 .SILENT:
101
102 # Always remake the following targets
103 .PHONY: install clean dist distclean
104