Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 28 Sep 2011 15:33:51 +0300
changeset 218 92582492ecde
parent 217 fdcf941346bb
child 226 97139da73273
permissions -rw-r--r--
Add heading.

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

.PHONY: all
all:

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

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

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

OVERRIDDEN_ITEMS = \
    .inputrc .minttyrc .Xdefaults .xinitrc .xserverrc .screenrc .dircolors \
    .bashrc .bash_completion .zshrc .vimrc .ssh \
    .mailsign .muttrc .tidy \
    .dictrc \
    .hgrc .hgignore .bazaar .gitconfig .gitignore .cvs \
    .gnupg
MANUALINSTALL_ITEMS = .mc
IFNONEXIST_ITEMS = .wgetrc .subversion

################################################################
# 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
	mkdir -p $(HOME)/.mc
	install -m 640 .mc/bashrc $(HOME)/.mc
ifeq '$(host_os)' 'windows'
	install -m 640 .mc/bindings.cygwin $(HOME)/.mc/bindings
else
	install -m 640 .mc/bindings $(HOME)/.mc/bindings
endif

.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 || :

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

.PHONY: clean
clean:

.PHONY: distclean
distclean: clean

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

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