3da218
UNAME=$(shell uname)
3da218
DEBUG=1
3da218
COVERAGE=0
3da218
INSTALL=install
3da218
FLEX=flex
3da218
BISON=bison
3da218
# Fedora changes begin
3da218
PREFIX=PUTINPREFIXHERE
3da218
SYSCONFDIR=PUTINSYSCONFDIRHERE
3da218
# Fedora changes end
3da218
3da218
# In dist tarballs, the version is stored in the I3_VERSION and VERSION files.
3da218
I3_VERSION := '$(shell [ -f $(TOPDIR)/I3_VERSION ] && cat $(TOPDIR)/I3_VERSION)'
3da218
VERSION := '$(shell [ -f $(TOPDIR)/VERSION ] && cat $(TOPDIR)/VERSION)'
3da218
ifeq ('',$(I3_VERSION))
3da218
VERSION := $(shell git describe --tags --abbrev=0)
3da218
I3_VERSION := '$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch \"$(shell git describe --tags --always --all | sed s:heads/::)\")'
3da218
endif
3da218
3da218
MAJOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 1)
3da218
MINOR_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 2)
3da218
PATCH_VERSION := $(shell echo ${VERSION} | cut -d '.' -f 3)
3da218
ifeq (${PATCH_VERSION},)
3da218
PATCH_VERSION := 0
3da218
endif
3da218
3da218
## Generic flags
3da218
3da218
# Default CFLAGS that users should be able to override
3da218
ifeq ($(DEBUG),1)
3da218
# Extended debugging flags, macros shall be available in gcc
3da218
CFLAGS ?= -pipe -gdwarf-2 -g3
3da218
else
3da218
CFLAGS ?= -pipe -O2 -freorder-blocks-and-partition
3da218
endif
3da218
3da218
# Default LDFLAGS that users should be able to override
3da218
LDFLAGS ?= $(as_needed_LDFLAG)
3da218
3da218
# Common CFLAGS for all i3 related binaries
Simon Wesp c110a5
# Fedora changes begin
Simon Wesp c110a5
I3_CFLAGS  = PUTINOPTFLAGSHERE -std=c99
Simon Wesp c110a5
# Fedora changes end
3da218
I3_CFLAGS += -Wall
3da218
# unused-function, unused-label, unused-variable are turned on by -Wall
3da218
# We don’t want unused-parameter because of the use of many callbacks
3da218
I3_CFLAGS += -Wunused-value
3da218
I3_CFLAGS += -Iinclude
3da218
3da218
I3_CPPFLAGS  = -DI3_VERSION=\"${I3_VERSION}\"
3da218
I3_CPPFLAGS += -DMAJOR_VERSION=${MAJOR_VERSION}
3da218
I3_CPPFLAGS += -DMINOR_VERSION=${MINOR_VERSION}
3da218
I3_CPPFLAGS += -DPATCH_VERSION=${PATCH_VERSION}
3da218
I3_CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
3da218
I3_CPPFLAGS += -DI3__FILE__=__FILE__
3da218
3da218
3da218
## Libraries flags
3da218
3da218
ifeq ($(shell which pkg-config 2>/dev/null 1>/dev/null || echo 1),1)
3da218
$(error "pkg-config was not found")
3da218
endif
3da218
3da218
# An easier way to get CFLAGS and LDFLAGS falling back in case there's
3da218
# no pkg-config support for certain libraries.
3da218
#
3da218
# NOTE that you must not use a blank after comma when calling this:
3da218
#     $(call ldflags_for_lib name, fallback) # bad
3da218
#     $(call ldflags_for_lib name,fallback) # good
3da218
# Otherwise, the compiler will get -l foo instead of -lfoo
3da218
#
3da218
# We redirect stderr to /dev/null because pkg-config prints an error if support
3da218
# for gnome-config was enabled but gnome-config is not actually installed.
3da218
cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
3da218
ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
3da218
3da218
# XCB common stuff
3da218
XCB_CFLAGS  := $(call cflags_for_lib, xcb)
3da218
XCB_CFLAGS  += $(call cflags_for_lib, xcb-event)
3da218
XCB_LIBS    := $(call ldflags_for_lib, xcb,xcb)
3da218
XCB_LIBS    += $(call ldflags_for_lib, xcb-event,xcb-event)
3da218
ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
3da218
XCB_CFLAGS  += $(call cflags_for_lib, xcb-atom)
3da218
XCB_CFLAGS  += $(call cflags_for_lib, xcb-aux)
3da218
XCB_LIBS    += $(call ldflags_for_lib, xcb-atom,xcb-atom)
3da218
XCB_LIBS    += $(call ldflags_for_lib, xcb-aux,xcb-aux)
3da218
XCB_CPPFLAGS+= -DXCB_COMPAT
3da218
else
3da218
XCB_CFLAGS  += $(call cflags_for_lib, xcb-util)
3da218
XCB_LIBS    += $(call ldflags_for_lib, xcb-util)
3da218
endif
3da218
3da218
# XCB keyboard stuff
3da218
XCB_KBD_CFLAGS := $(call cflags_for_lib, xcb-keysyms)
3da218
XCB_KBD_LIBS   := $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
3da218
3da218
# XCB WM stuff
3da218
XCB_WM_CFLAGS := $(call cflags_for_lib, xcb-icccm)
3da218
XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-xinerama)
3da218
XCB_WM_CFLAGS += $(call cflags_for_lib, xcb-randr)
3da218
XCB_WM_LIBS   := $(call ldflags_for_lib, xcb-icccm,xcb-icccm)
3da218
XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama)
3da218
XCB_WM_LIBS   += $(call ldflags_for_lib, xcb-randr,xcb-randr)
3da218
3da218
# Xlib
3da218
X11_CFLAGS := $(call cflags_for_lib, x11)
3da218
X11_LIBS   := $(call ldflags_for_lib, x11,X11)
3da218
3da218
# Xcursor
3da218
XCURSOR_CFLAGS := $(call cflags_for_lib, xcursor)
3da218
XCURSOR_LIBS   := $(call ldflags_for_lib, xcursor,Xcursor)
3da218
3da218
# yajl
3da218
YAJL_CFLAGS := $(call cflags_for_lib, yajl)
3da218
# Fallback for libyajl 1 which did not include yajl_version.h. We need
3da218
# YAJL_MAJOR from that file to decide which code path should be used.
3da218
YAJL_CFLAGS += -idirafter $(TOPDIR)/yajl-fallback
3da218
YAJL_LIBS   := $(call ldflags_for_lib, yajl,yajl)
3da218
3da218
#libev
3da218
LIBEV_CFLAGS := $(call cflags_for_lib, libev)
3da218
LIBEV_LIBS   := $(call ldflags_for_lib, libev,ev)
3da218
3da218
# libpcre
3da218
PCRE_CFLAGS := $(call cflags_for_lib, libpcre)
3da218
ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
3da218
I3_CPPFLAGS += -DPCRE_HAS_UCP=1
3da218
endif
3da218
PCRE_LIBS   := $(call ldflags_for_lib, libpcre,pcre)
3da218
3da218
# startup-notification
3da218
LIBSN_CFLAGS := $(call cflags_for_lib, libstartup-notification-1.0)
3da218
LIBSN_LIBS   := $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
3da218
3da218
# Pango
3da218
PANGO_CFLAGS := $(call cflags_for_lib, cairo)
3da218
PANGO_CFLAGS += $(call cflags_for_lib, pangocairo)
3da218
I3_CPPFLAGS  += -DPANGO_SUPPORT=1
3da218
PANGO_LIBS   := $(call ldflags_for_lib, cairo)
3da218
PANGO_LIBS   += $(call ldflags_for_lib, pangocairo)
3da218
3da218
# libi3
3da218
LIBS = -L$(TOPDIR) -li3
3da218
3da218
## Platform-specific flags
3da218
3da218
# Please test if -Wl,--as-needed works on your platform and send me a patch.
3da218
# it is known not to work on Darwin (Mac OS X)
3da218
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
3da218
as_needed_LDFLAG = -Wl,--as-needed
3da218
endif
3da218
3da218
ifeq ($(UNAME),NetBSD)
3da218
# We need -idirafter instead of -I to prefer the system’s iconv over GNU libiconv
3da218
I3_CFLAGS += -idirafter /usr/pkg/include
3da218
I3_LDFLAGS += -Wl,-rpath,/usr/local/lib -Wl,-rpath,/usr/pkg/lib
3da218
endif
3da218
3da218
ifeq ($(UNAME),OpenBSD)
3da218
I3_CFLAGS += -I${X11BASE}/include
3da218
LIBS += -liconv
3da218
I3_LDFLAGS += -L${X11BASE}/lib
3da218
endif
3da218
3da218
ifeq ($(UNAME),FreeBSD)
3da218
LIBS += -liconv
3da218
endif
3da218
3da218
ifeq ($(UNAME),Darwin)
3da218
LIBS += -liconv
3da218
else
3da218
# Darwin (Mac OS X) doesn’t have librt
3da218
LIBS += -lrt
3da218
endif
3da218
3da218
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
3da218
I3_CPPFLAGS += -D_GNU_SOURCE
3da218
endif
3da218
3da218
3da218
ifeq ($(COVERAGE),1)
3da218
I3_CFLAGS += -fprofile-arcs -ftest-coverage
3da218
LIBS += -lgcov
3da218
endif
3da218
3da218
V ?= 0
3da218
ifeq ($(V),0)
3da218
# Don’t print command lines which are run
3da218
.SILENT:
3da218
3da218
# echo-ing vars
3da218
V_ASCIIDOC = echo ASCIIDOC $@;
3da218
V_POD2HTML = echo POD2HTML $@;
3da218
V_POD2MAN = echo POD2MAN $@;
3da218
V_A2X = echo A2X $@;
3da218
endif
3da218
3da218
# Always remake the following targets
3da218
.PHONY: install clean dist distclean
3da218