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