]> git.sur5r.net Git - i3/i3/blob - common.mk
remove hard-coded paths since we now use pkg-config for all the dependencies
[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 += $(call cflags_for_lib, xcb-keysyms)
31 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
32 CFLAGS += -DXCB_COMPAT
33 CFLAGS += $(call cflags_for_lib, xcb-atom)
34 CFLAGS += $(call cflags_for_lib, xcb-aux)
35 else
36 CFLAGS += $(call cflags_for_lib, xcb-util)
37 endif
38 CFLAGS += $(call cflags_for_lib, xcb-icccm)
39 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
40 CFLAGS += $(call cflags_for_lib, xcb-randr)
41 CFLAGS += $(call cflags_for_lib, xcb)
42 CFLAGS += $(call cflags_for_lib, xcursor)
43 CFLAGS += $(call cflags_for_lib, x11)
44 CFLAGS += $(call cflags_for_lib, yajl)
45 CFLAGS += $(call cflags_for_lib, libev)
46 CFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
47 CFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
48
49 LDFLAGS += -lm
50 LDFLAGS += $(call ldflags_for_lib, xcb-event, xcb-event)
51 LDFLAGS += $(call ldflags_for_lib, xcb-keysyms, xcb-keysyms)
52 ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
53 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
54 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
55 else
56 LDFLAGS += $(call ldflags_for_lib, xcb-util)
57 endif
58 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
59 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
60 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
61 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
62 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
63 LDFLAGS += $(call ldflags_for_lib, x11, X11)
64 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
65 LDFLAGS += $(call ldflags_for_lib, libev, ev)
66
67 ifeq ($(UNAME),NetBSD)
68 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
69 CFLAGS += -idirafter /usr/pkg/include
70 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
71 endif
72
73 ifeq ($(UNAME),OpenBSD)
74 CFLAGS += -I${X11BASE}/include
75 LDFLAGS += -liconv
76 LDFLAGS += -L${X11BASE}/lib
77 endif
78
79 ifeq ($(UNAME),FreeBSD)
80 LDFLAGS += -liconv
81 endif
82
83 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
84 CFLAGS += -D_GNU_SOURCE
85 endif
86
87 ifeq ($(DEBUG),1)
88 # Extended debugging flags, macros shall be available in gcc
89 CFLAGS += -gdwarf-2
90 CFLAGS += -g3
91 else
92 CFLAGS += -O2
93 CFLAGS += -freorder-blocks-and-partition
94 endif
95
96 # Don’t print command lines which are run
97 .SILENT:
98
99 # Always remake the following targets
100 .PHONY: install clean dist distclean
101