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