]> git.sur5r.net Git - i3/i3/blob - common.mk
i3bar: Bugfix: Add tray icon padding when calculating text position (Thanks Bacardi55)
[i3/i3] / common.mk
1 UNAME=$(shell uname)
2 DEBUG=1
3 COVERAGE=0
4 INSTALL=install
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 # The escaping is absurd, but we need to escape for shell, sed, make, define
16 GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f $(TOPDIR)/.git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' $(TOPDIR)/.git/HEAD || echo 'unknown'))"
17 VERSION:=$(shell git describe --tags --abbrev=0)
18
19 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
20 $(error "pkg-config was not found")
21 endif
22
23 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
24 # no pkg-config support for certain libraries.
25 #
26 # NOTE that you must not use a blank after comma when calling this:
27 #     $(call ldflags_for_lib name, fallback) # bad
28 #     $(call ldflags_for_lib name,fallback) # good
29 # Otherwise, the compiler will get -l foo instead of -lfoo
30 #
31 # We redirect stderr to /dev/null because pkg-config prints an error if support
32 # for gnome-config was enabled but gnome-config is not actually installed.
33 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
34 ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
35
36 CFLAGS += -std=c99
37 CFLAGS += -pipe
38 CFLAGS += -Wall
39 # unused-function, unused-label, unused-variable are turned on by -Wall
40 # We don’t want unused-parameter because of the use of many callbacks
41 CFLAGS += -Wunused-value
42 CFLAGS += -Iinclude
43 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
44 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
45 CPPFLAGS += -DXCB_COMPAT
46 CFLAGS += $(call cflags_for_lib, xcb-atom)
47 CFLAGS += $(call cflags_for_lib, xcb-aux)
48 else
49 CFLAGS += $(call cflags_for_lib, xcb-util)
50 endif
51 CFLAGS += $(call cflags_for_lib, xcb-icccm)
52 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
53 CFLAGS += $(call cflags_for_lib, xcb-randr)
54 CFLAGS += $(call cflags_for_lib, xcb)
55 CFLAGS += $(call cflags_for_lib, xcursor)
56 CFLAGS += $(call cflags_for_lib, x11)
57 CFLAGS += $(call cflags_for_lib, yajl)
58 CFLAGS += $(call cflags_for_lib, libev)
59 CFLAGS += $(call cflags_for_lib, libpcre)
60 CPPFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
61 CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
62 CPPFLAGS += -DTERM_EMU=\"$(TERM_EMU)\"
63
64 ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
65 CPPFLAGS += -DPCRE_HAS_UCP=1
66 endif
67
68 LIBS += -lm
69 LIBS += -L $(TOPDIR)/libi3 -li3
70 LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
71 LIBS += $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
72 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
73 LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
74 LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
75 else
76 LIBS += $(call ldflags_for_lib, xcb-util)
77 endif
78 LIBS += $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
79 LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
80 LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
81 LIBS += $(call ldflags_for_lib, xcb,xcb)
82 LIBS += $(call ldflags_for_lib, xcursor,Xcursor)
83 LIBS += $(call ldflags_for_lib, x11,X11)
84 LIBS += $(call ldflags_for_lib, yajl,yajl)
85 LIBS += $(call ldflags_for_lib, libev,ev)
86 LIBS += $(call ldflags_for_lib, libpcre,pcre)
87
88 # Please test if -Wl,--as-needed works on your platform and send me a patch.
89 # it is known not to work on Darwin (Mac OS X)
90 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
91 LDFLAGS += -Wl,--as-needed
92 endif
93
94 ifeq ($(UNAME),NetBSD)
95 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
96 CFLAGS += -idirafter /usr/pkg/include
97 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
98 endif
99
100 ifeq ($(UNAME),OpenBSD)
101 CFLAGS += -I${X11BASE}/include
102 LIBS += -liconv
103 LDFLAGS += -L${X11BASE}/lib
104 endif
105
106 ifeq ($(UNAME),FreeBSD)
107 LIBS += -liconv
108 endif
109
110 ifeq ($(UNAME),Darwin)
111 LIBS += -liconv
112 endif
113
114 # Fallback for libyajl 1 which did not include yajl_version.h. We need
115 # YAJL_MAJOR from that file to decide which code path should be used.
116 CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
117
118 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
119 CPPFLAGS += -D_GNU_SOURCE
120 endif
121
122 ifeq ($(DEBUG),1)
123 # Extended debugging flags, macros shall be available in gcc
124 CFLAGS += -gdwarf-2
125 CFLAGS += -g3
126 else
127 CFLAGS += -O2
128 CFLAGS += -freorder-blocks-and-partition
129 endif
130
131 ifeq ($(COVERAGE),1)
132 CFLAGS += -fprofile-arcs -ftest-coverage
133 LIBS += -lgcov
134 endif
135
136 # Don’t print command lines which are run
137 .SILENT:
138
139 # Always remake the following targets
140 .PHONY: install clean dist distclean
141