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