]> git.sur5r.net Git - i3/i3/blob - common.mk
Merge branch 'startup-notification' into next
[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 CPPFLAGS += -DTERM_EMU=\"$(TERM_EMU)\"
64
65 ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
66 CPPFLAGS += -DPCRE_HAS_UCP=1
67 endif
68
69 LIBS += -lm
70 LIBS += -L $(TOPDIR)/libi3 -li3
71 LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
72 LIBS += $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
73 ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
74 LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
75 LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
76 else
77 LIBS += $(call ldflags_for_lib, xcb-util)
78 endif
79 LIBS += $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
80 LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
81 LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr)
82 LIBS += $(call ldflags_for_lib, xcb,xcb)
83 LIBS += $(call ldflags_for_lib, xcursor,Xcursor)
84 LIBS += $(call ldflags_for_lib, x11,X11)
85 LIBS += $(call ldflags_for_lib, yajl,yajl)
86 LIBS += $(call ldflags_for_lib, libev,ev)
87 LIBS += $(call ldflags_for_lib, libpcre,pcre)
88 LIBS += $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
89
90 # Please test if -Wl,--as-needed works on your platform and send me a patch.
91 # it is known not to work on Darwin (Mac OS X)
92 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
93 LDFLAGS += -Wl,--as-needed
94 endif
95
96 ifeq ($(UNAME),NetBSD)
97 # We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
98 CFLAGS += -idirafter /usr/pkg/include
99 LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
100 endif
101
102 ifeq ($(UNAME),OpenBSD)
103 CFLAGS += -I${X11BASE}/include
104 LIBS += -liconv
105 LDFLAGS += -L${X11BASE}/lib
106 endif
107
108 ifeq ($(UNAME),FreeBSD)
109 LIBS += -liconv
110 endif
111
112 ifeq ($(UNAME),Darwin)
113 LIBS += -liconv
114 endif
115
116 # Fallback for libyajl 1 which did not include yajl_version.h. We need
117 # YAJL_MAJOR from that file to decide which code path should be used.
118 CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
119
120 ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
121 CPPFLAGS += -D_GNU_SOURCE
122 endif
123
124 ifeq ($(DEBUG),1)
125 # Extended debugging flags, macros shall be available in gcc
126 CFLAGS += -gdwarf-2
127 CFLAGS += -g3
128 else
129 CFLAGS += -O2
130 CFLAGS += -freorder-blocks-and-partition
131 endif
132
133 ifeq ($(COVERAGE),1)
134 CFLAGS += -fprofile-arcs -ftest-coverage
135 LIBS += -lgcov
136 endif
137
138 # Don’t print command lines which are run
139 .SILENT:
140
141 # Always remake the following targets
142 .PHONY: install clean dist distclean
143