2014-01-20 03:40:50 -05:00
|
|
|
QUIET?=@
|
2014-01-17 03:50:51 -05:00
|
|
|
CFLAGS?=-Wall -Wextra -O3
|
2014-01-20 03:40:50 -05:00
|
|
|
VERSION?=0.14.1
|
2014-01-19 08:18:42 -05:00
|
|
|
|
|
|
|
PROGRAM=simpleswitcher
|
|
|
|
|
|
|
|
|
2012-08-27 06:24:30 -04:00
|
|
|
PREFIX?=$(DESTDIR)/usr
|
2014-01-20 03:40:50 -05:00
|
|
|
BIN_DIR?=$(PREFIX)/bin
|
|
|
|
MAN_DIR?=$(PREFIX)/share/man/man1
|
|
|
|
|
|
|
|
MAN_PAGE=$(PROGRAM).1
|
2012-06-29 13:10:13 -04:00
|
|
|
|
2014-01-19 08:18:42 -05:00
|
|
|
BUILD_DIR=build
|
|
|
|
SOURCE_DIR=source
|
|
|
|
DOC_DIR=doc
|
|
|
|
|
|
|
|
SOURCES=$(wildcard $(SOURCE_DIR)/*.c)
|
|
|
|
OBJECTS=$(SOURCES:$(SOURCE_DIR)/%.c=$(BUILD_DIR)/%.o)
|
|
|
|
HEADERS=$(wildcard include/*.h)
|
2014-01-20 03:40:50 -05:00
|
|
|
OTHERS=Makefile LICENSE README.md
|
|
|
|
|
|
|
|
|
|
|
|
INSTALL_MANPAGE_PATH=$(MAN_DIR)/$(MAN_PAGE).gz
|
|
|
|
INSTALL_PROGRAM=$(BIN_DIR)/$(PROGRAM)
|
|
|
|
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2014-01-20 03:40:50 -05:00
|
|
|
DIST_TARGET=$(BUILD_DIR)/$(PROGRAM)-$(VERSION).tar.xz
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2014-01-20 03:40:50 -05:00
|
|
|
|
|
|
|
CFLAGS+=-DMANPAGE_PATH="\"$(INSTALL_MANPAGE_PATH)\""
|
2014-01-19 07:57:54 -05:00
|
|
|
CFLAGS+=-std=c99
|
2014-01-19 08:18:42 -05:00
|
|
|
CFLAGS+=-Iinclude/
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2013-01-20 07:01:13 -05:00
|
|
|
# Check deps.
|
2014-01-14 02:36:07 -05:00
|
|
|
ifeq (${DEBUG},1)
|
2014-01-19 07:57:54 -05:00
|
|
|
CFLAGS+=-DTIMING=1 -g3
|
2014-01-14 02:36:07 -05:00
|
|
|
LDADD+=-lrt
|
|
|
|
endif
|
2013-01-20 07:01:13 -05:00
|
|
|
|
2014-01-19 07:57:54 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Check dependencies
|
|
|
|
##
|
2013-01-20 07:01:13 -05:00
|
|
|
PKG_CONFIG?=$(shell which pkg-config)
|
|
|
|
ifeq (${PKG_CONFIG},${EMPTY})
|
|
|
|
$(error Failed to find pkg-config. Please install pkg-config)
|
|
|
|
endif
|
|
|
|
|
2014-01-25 17:37:37 -05:00
|
|
|
CFLAGS+=$(shell ${PKG_CONFIG} --cflags x11 xinerama xft libxdg-basedir)
|
|
|
|
LDADD+=$(shell ${PKG_CONFIG} --libs x11 xinerama xft libxdg-basedir)
|
2013-01-20 07:01:13 -05:00
|
|
|
|
|
|
|
ifeq (${LDADD},${EMPTY})
|
|
|
|
$(error Failed to find the required dependencies: x11, xinerama, xft)
|
|
|
|
endif
|
|
|
|
|
2014-01-19 07:57:54 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Check for i3.
|
|
|
|
##
|
2014-01-10 07:38:38 -05:00
|
|
|
I3?=$(shell which i3)
|
|
|
|
ifneq (${I3},${EMPTY})
|
|
|
|
$(info I3 mode is enabled)
|
2014-01-11 04:34:43 -05:00
|
|
|
CFLAGS+=-DI3 -I${PREFIX}/include/
|
2014-01-10 07:38:38 -05:00
|
|
|
endif
|
|
|
|
|
2014-01-19 08:18:42 -05:00
|
|
|
all: $(BUILD_DIR)/$(PROGRAM)
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
2014-01-20 03:40:50 -05:00
|
|
|
$(info Creating build dir)
|
|
|
|
$(QUIET)mkdir -p $@
|
2012-06-29 13:10:13 -04:00
|
|
|
|
2014-01-20 03:40:50 -05:00
|
|
|
# Objects depend on header files and makefile too.
|
2014-01-19 08:18:42 -05:00
|
|
|
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | Makefile $(HEADERS) $(BUILD_DIR)
|
2014-01-20 03:40:50 -05:00
|
|
|
$(info Compiling $^ -> $@)
|
|
|
|
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $^
|
2012-06-29 13:10:13 -04:00
|
|
|
|
2014-01-19 08:18:42 -05:00
|
|
|
$(BUILD_DIR)/$(PROGRAM): $(OBJECTS)
|
2014-01-20 03:40:50 -05:00
|
|
|
$(info Linking $@)
|
|
|
|
$(QUIET)$(CC) -o $@ $^ $(LDADD) $(LDFLAGS)
|
2012-06-29 13:10:13 -04:00
|
|
|
|
2014-01-20 03:40:50 -05:00
|
|
|
install: $(INSTALL_PROGRAM) $(INSTALL_MANPAGE_PATH)
|
2012-08-27 06:24:30 -04:00
|
|
|
|
2014-01-20 03:40:50 -05:00
|
|
|
$(INSTALL_PROGRAM): $(BUILD_DIR)/$(PROGRAM)
|
|
|
|
$(info Install $^ -> $@ )
|
|
|
|
$(QUIET)install -Dm 755 $^ $@
|
|
|
|
|
|
|
|
|
|
|
|
$(BUILD_DIR)/$(MAN_PAGE).gz: $(DOC_DIR)/$(MAN_PAGE)
|
|
|
|
$(info Creating man page)
|
|
|
|
$(QUIET) gzip -c $^ > $@
|
|
|
|
|
|
|
|
$(INSTALL_MANPAGE_PATH): $(BUILD_DIR)/$(MAN_PAGE).gz
|
|
|
|
$(info Install $^ -> $@)
|
|
|
|
$(QUIET) install -Dm 644 $^ $(INSTALL_MANPAGE_PATH)
|
2013-05-19 08:16:34 -04:00
|
|
|
|
2012-06-29 13:10:13 -04:00
|
|
|
clean:
|
2014-01-20 03:40:50 -05:00
|
|
|
$(info Clean build dir)
|
|
|
|
$(QUIET)rm -rf $(BUILD_DIR)
|
2014-01-10 04:35:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
indent:
|
2014-01-19 08:18:42 -05:00
|
|
|
@astyle --style=linux -S -C -D -N -H -L -W3 -f $(SOURCES) $(HEADERS)
|
2014-01-20 03:40:50 -05:00
|
|
|
|
|
|
|
dist: $(DIST_TARGET)
|
|
|
|
|
|
|
|
$(BUILD_DIR)/$(PROGRAM)-$(VERSION): $(SOURCES) $(HEADERS) $(DOC_DIR)/$(MAN_PAGE) $(OTHERS) | $(BUILD_DIR)
|
|
|
|
$(info Create release directory)
|
|
|
|
$(QUIET)mkdir -p $@
|
|
|
|
$(QUIET)cp -a --parents $^ $@
|
|
|
|
|
|
|
|
|
|
|
|
$(DIST_TARGET): $(BUILD_DIR)/$(PROGRAM)-$(VERSION)
|
|
|
|
$(info Creating release tarball: $@)
|
|
|
|
$(QUIET) tar -C $(BUILD_DIR) -cavvJf $@ $(PROGRAM)-$(VERSION)
|