Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 24 Apr 2012 13:30:21 +0300
changeset 432 dc9bb516bde7
parent 427 59627b533219
child 433 93d05f55825a
permissions -rw-r--r--
Add '.xxkbrc' to install target.

SHELL = /bin/sh
export PATH := /bin:/usr/bin:${PATH}

# Disable built in pattern rules.
MAKEFLAGS += -r
# Disable built in variables.
MAKEFLAGS += -R
# Disable built in suffix rules.
.SUFFIXES:
# Default target.
.DEFAULT_GOAL = help

################################################################
# Platform definition.

ifeq '' '$(HOME)'
  $(error HOME env var not set!)
endif

host_os = linux
ifneq '' '$(COMSPEC)'
  host_os = cygwin
endif

################################################################
# Build tool definition/switches.

RST2HTML = rst2html
ifeq '$(host_os)' 'cygwin'
  RST2HTML = rst2html.py
endif

################################################################
# Project dirs/files.

OVERRIDDEN_ITEMS := \
    .fvwm .xxkbrc \
    .inputrc .minttyrc .Xdefaults .xinitrc .xserverrc .screenrc .dircolors \
    .bashrc .bash_path .bash_completion .zshrc .vimrc .ssh .pystartup \
    .pylintrc \
    .signature .muttrc .tidy \
    .dictrc \
    .hgrc .hgignore .hgstyle .bazaar .gitconfig .gitignore .cvsrc \
    .gnupg \
    .glhackrc
MANUALINSTALL_ITEMS = .mc
IFNONEXIST_ITEMS = .wgetrc .subversion

RST_FILES = $(wildcard *.rst)
HTML_FILES = $(RST_FILES:.rst=.html)

################################################################
# Build targets.

.PHONY: all
all:

################################################################
# Install/uninstall targets.

.PHONY: install
install:
	for item in $(OVERRIDDEN_ITEMS); do \
		if [ -f $$item ]; then \
			install -m 640 $$item $(HOME)/$$item; \
		fi; \
		if [ -d $$item ]; then \
			for file in `find $$item`; do \
				if [ -d $$file ]; then \
					mkdir -p $(HOME)/$$file; \
					continue; \
				fi; \
				install -m 640 $$file $(HOME)/$$file; \
			done; \
		fi; \
	done
	for item in $(IFNONEXIST_ITEMS); do \
		if [ -f $$item -a ! -f $(HOME)/$$item ]; then \
			install -m 640 $$item $(HOME)/$$item; \
		fi; \
		if [ -d $$item ]; then \
			for file in `find $$item`; do \
				if [ -d $$file ]; then \
					mkdir -p $(HOME)/$$file; \
					continue; \
				fi; \
				if [ ! -f $(HOME)/$$file ]; then \
					install -m 640 $$file $(HOME)/$$file; \
				fi; \
			done; \
		fi; \
	done
	chmod a+x ~/.xinitrc ~/.xserverrc
	rm -f ~/.xsession
	ln -s ~/.xinitrc ~/.xsession
	v=`mc --version | sed 's|.*\([0-9]\+\.[0-9]\+\.[0-9]\+\)$$|\1|;q'`; \
	vmajor=$${v%%.*}; \
	vminor=$${v#*.}; \
	vminor=$${vminor%.*}; \
	umask 0117; \
	if [ $$vmajor -gt 4 -o '(' $$vmajor -eq 4 -a $$vminor -ge 8 ')' ]; then \
		mkdir -p $(HOME)/.config/mc $(HOME)/.local/share/mc/; \
		install -m 640 .local/share/mc/bashrc $(HOME)/.local/share/mc/; \
		cat .config/mc/mc.ext /etc/mc/mc.ext > $(HOME)/.local/share/mc/mc.ext; \
	else \
		mkdir -p $(HOME)/.mc; \
		install -m 640 .local/share/mc/bashrc $(HOME)/.mc; \
		install -m 640 .config/mc/mc.ext $(HOME)/.mc/bindings; \
	fi
	if command -v file 1>/dev/null; then \
		install -m 640 .magic $(HOME); \
		cd $(HOME); \
		file --compile -m .magic; \
	fi

.PHONY: uninstall
uninstall:
	for item in $(OVERRIDDEN_ITEMS); do \
		if [ -f $$item ]; then \
			[ -f $(HOME)/$$file ] && rm -f $(HOME)/$$item; \
		fi; \
		if [ -d $$item ]; then \
			for file in `find $$item -depth`; do \
				if [ -d $$file ]; then \
					rmdir $(HOME)/$$file || :; \
					continue; \
				fi; \
				[ -f $(HOME)/$$file ] && rm $(HOME)/$$file; \
			done; \
		fi; \
	done
	rm -f $(HOME)/.mc/bashrc $(HOME)/.mc/ini $(HOME)/.mc/bindings
	rmdir $(HOME)/.mc || :

################################################################
# Docs targets.

.PHONY: html
html: $(HTML_FILES)

# --stylesheet=rst.css
$(HTML_FILES): %.html: %.rst
	$(RST2HTML) $*.rst $@

################################################################
# Clean targets.

.PHONY: clean
clean:
	rm -f $(HTML_FILES)

.PHONY: distclean
distclean: clean

################################################################
# Helper target.

.PHONY: help
help:
	@echo
	@echo Supported targets:
	@sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(MAKEFILE_LIST)