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