]> git.sur5r.net Git - i3/i3/blob - common.mk
fed147b88614a6186ad030104fadf5e4bb08c454
[i3/i3] / common.mk
1 UNAME=$(shell uname)
2 DEBUG=1
3 COVERAGE=0
4 INSTALL=install
5 PREFIX=/usr
6 ifeq ($(PREFIX),/usr)
7 SYSCONFDIR=/etc
8 else
9 SYSCONFDIR=$(PREFIX)/etc
10 endif
11 # The escaping is absurd, but we need to escape for shell, sed, make, define
12 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'))"
13 VERSION:=$(shell git describe --tags --abbrev=0)
14
15 ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
16 $(error "pkg-config was not found")
17 endif
18
19 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
20 # no pkg-config support for certain libraries
21 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
22 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
23
24 CFLAGS += -std=c99
25 CFLAGS += -pipe
26 CFLAGS += -Wall
27 # unused-function, unused-label, unused-variable are turned on by -Wall
28 # We don’t want unused-parameter because of the use of many callbacks
29 CFLAGS += -Wunused-value
30 CFLAGS += -Iinclude
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-keysyms, xcb-keysyms)
53 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
54 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
55 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
56 else
57 LDFLAGS += $(call ldflags_for_lib, xcb-util)
58 endif
59 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
60 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
61 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
62 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
63 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
64 LDFLAGS += $(call ldflags_for_lib, x11, X11)
65 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
66 LDFLAGS += $(call ldflags_for_lib, libev, ev)
67
68 ifeq ($(UNAME),NetBSD)
69 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
70 CFLAGS += -idirafter /usr/pkg/include
71 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
72 endif
73
74 ifeq ($(UNAME),OpenBSD)
75 CFLAGS += -I${X11BASE}/include
76 LDFLAGS += -liconv
77 LDFLAGS += -L${X11BASE}/lib
78 endif
79
80 ifeq ($(UNAME),FreeBSD)
81 LDFLAGS += -liconv
82 endif
83
84 # Fallback for libyajl 1 which did not include yajl_version.h. We need
85 # YAJL_MAJOR from that file to decide which code path should be used.
86 CFLAGS += -idirafter yajl-fallback
87
88 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
89 CFLAGS += -D_GNU_SOURCE
90 endif
91
92 ifeq ($(DEBUG),1)
93 # Extended debugging flags, macros shall be available in gcc
94 CFLAGS += -gdwarf-2
95 CFLAGS += -g3
96 else
97 CFLAGS += -O2
98 CFLAGS += -freorder-blocks-and-partition
99 endif
100
101 ifeq ($(COVERAGE),1)
102 CFLAGS += -fprofile-arcs -ftest-coverage
103 LDFLAGS += -lgcov
104 endif
105
106 # Don’t print command lines which are run
107 .SILENT:
108
109 # Always remake the following targets
110 .PHONY: install clean dist distclean
111