]> git.sur5r.net Git - i3/i3/blob - common.mk
a9bab084c7bb0e4b34369072b827de0e9dd09993
[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 # An easier way to get CFLAGS and LDFLAGS falling back in case there's
15 # no pkg-config support for certain libraries
16 cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
17 ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
18
19 CFLAGS += -std=c99
20 CFLAGS += -pipe
21 CFLAGS += -Wall
22 # unused-function, unused-label, unused-variable are turned on by -Wall
23 # We don’t want unused-parameter because of the use of many callbacks
24 CFLAGS += -Wunused-value
25 CFLAGS += -Iinclude
26 CFLAGS += -I/usr/local/include
27 CFLAGS += $(call cflags_for_lib, xcb-event)
28 CFLAGS += $(call cflags_for_lib, xcb-property)
29 CFLAGS += $(call cflags_for_lib, xcb-keysyms)
30 CFLAGS += $(call cflags_for_lib, xcb-atom)
31 CFLAGS += $(call cflags_for_lib, xcb-aux)
32 CFLAGS += $(call cflags_for_lib, xcb-icccm)
33 CFLAGS += $(call cflags_for_lib, xcb-xinerama)
34 CFLAGS += $(call cflags_for_lib, xcb-randr)
35 CFLAGS += $(call cflags_for_lib, xcb)
36 CFLAGS += $(call cflags_for_lib, xcursor)
37 CFLAGS += $(call cflags_for_lib, x11)
38 CFLAGS += $(call cflags_for_lib, yajl)
39 CFLAGS += $(call cflags_for_lib, libev)
40 CFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
41 CFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
42
43 LDFLAGS += -lm
44 LDFLAGS += $(call ldflags_for_lib, xcb-event, xcb-event)
45 LDFLAGS += $(call ldflags_for_lib, xcb-property, xcb-property)
46 LDFLAGS += $(call ldflags_for_lib, xcb-keysyms, xcb-keysyms)
47 LDFLAGS += $(call ldflags_for_lib, xcb-atom, xcb-atom)
48 LDFLAGS += $(call ldflags_for_lib, xcb-aux, xcb-aux)
49 LDFLAGS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm)
50 LDFLAGS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama)
51 LDFLAGS += $(call ldflags_for_lib, xcb-randr, xcb-randr)
52 LDFLAGS += $(call ldflags_for_lib, xcb, xcb)
53 LDFLAGS += $(call ldflags_for_lib, xcursor, Xcursor)
54 LDFLAGS += $(call ldflags_for_lib, x11, X11)
55 LDFLAGS += $(call ldflags_for_lib, yajl, yajl)
56 LDFLAGS += $(call ldflags_for_lib, libev, ev)
57 LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
58
59 ifeq ($(UNAME),NetBSD)
60 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
61 CFLAGS += -idirafter /usr/pkg/include
62 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
63 endif
64
65 ifeq ($(UNAME),OpenBSD)
66 CFLAGS += -I${X11BASE}/include
67 LDFLAGS += -liconv
68 LDFLAGS += -L${X11BASE}/lib
69 endif
70
71 ifeq ($(UNAME),FreeBSD)
72 LDFLAGS += -liconv
73 endif
74
75 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
76 CFLAGS += -D_GNU_SOURCE
77 endif
78
79 ifeq ($(DEBUG),1)
80 # Extended debugging flags, macros shall be available in gcc
81 CFLAGS += -gdwarf-2
82 CFLAGS += -g3
83 else
84 CFLAGS += -O2
85 CFLAGS += -freorder-blocks-and-partition
86 endif
87
88 # Don’t print command lines which are run
89 .SILENT:
90
91 # Always remake the following targets
92 .PHONY: install clean dist distclean
93