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