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