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