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