Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 28 Jan 2017 01:45:34 +0200
changeset 821 7bfa94a26cde
parent 817 257a65e63780
child 886 74f10c613c59
permissions -rw-r--r--
Swap modifiers to previous assignment because I don't want to fix them in ~/.fvwm. Assign keycode to Caps_Lock before aliasing to LCtrl so ~/.xmodmaprc script can be re-evaluated without errors.


################################################################
# Standard GNU Makefile settings.

SHELL = /bin/sh -eu
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:
# Delete target file if command fails.
.DELETE_ON_ERROR:
# Default target.
.DEFAULT_GOAL = help

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

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

uname-s := $(shell uname -s)

host_os = linux
ifneq '' '$(filter CYGWIN%,$(uname-s))'
  host_os = cygwin
endif
ifeq 'SunOS' '$(uname-s)'
  host_os = solaris
endif

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

INSTALL_DATA := install -m 640
ifeq '$(host_os)' 'solaris'
  INSTALL_DATA := ginstall -m 640
endif

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

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

OVERRIDDEN_ITEMS := \
    .fvwm .xxkbrc .xmodmaprc .stalonetrayrc \
    .inputrc .minttyrc .Xdefaults .xinitrc .xserverrc .screenrc .dircolors \
    .env .bashrc .bash_completion .bash_completion.d .zshrc .vimrc .ssh \
    .pylintrc .pystartup .tclshrc .npmrc .guile \
    .gradle \
    .sqshrc \
    .signature .muttrc .tidy \
    .dictrc \
    .hgrc .hgignore .hgstyle .bazaar .gitconfig .gitignore .cvsrc .quiltrc .quiltrc-dpkg \
    .gnupg \
    .ackrc .grc \
    .mplayer \
    .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_DATA) $$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_DATA) $$file $(HOME)/$$file; \
			done; \
		fi; \
	done
	chmod 700 ~/.gnupg/
	chmod a+x ~/.fvwm/FvwmKbdd.pl ~/.fvwm/xinit
	command -v fvwm || exit 0; \
	for f in /etc/xdg/menus/*.menu; do \
		[ -f "$$f" ] || continue; \
		fname=$${f%.menu}; \
		fname=$${fname##*/}; \
		python .fvwm/xdg2fvwm.py Menu-$$fname $$f >~/.fvwm/$$fname.hook; \
		echo "Read $$[HOME]/.fvwm/$$fname.hook" >>~/.fvwm/config; \
		echo "AddToMenu MenuMyRoot $$fname Popup Menu-$$fname" >>~/.fvwm/config; \
	done
	mkdir -p ~/.screenshot
	for item in $(IFNONEXIST_ITEMS); do \
		if [ -f $$item -a ! -f $(HOME)/$$item ]; then \
			$(INSTALL_DATA) $$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_DATA) $$file $(HOME)/$$file; \
				fi; \
			done; \
		fi; \
	done
	chmod a+x ~/.xinitrc ~/.xserverrc
	rm -f ~/.xsession
	ln -s ~/.xinitrc ~/.xsession
	rm -f ~/.bash_profile
	ln -s ~/.bashrc ~/.bash_profile
	command -v /usr/bin/mc || exit 0; \
	v=`/usr/bin/mc --version | sed 's|.*\([0-9]\+\.[0-9]\+\.[0-9]\+\)$$|\1|;q'`; \
	vmajor=$${v%%.*}; \
	vminor=$${v#*.}; \
	vminor=$${vminor%.*}; \
	if [ $$vmajor -gt 4 -o '(' $$vmajor -eq 4 -a $$vminor -ge 8 ')' ]; then \
		mkdir -p $(HOME)/.config/mc $(HOME)/.local/share/mc/; \
		umask 0117; \
		$(INSTALL_DATA) .local/share/mc/bashrc $(HOME)/.local/share/mc/; \
		cat .config/mc/mc.ext /etc/mc/mc.ext > $(HOME)/.config/mc/mc.ext; \
		{ \
			echo 'default/*'; \
			echo '    Open=file %f'; \
			echo '    Edit=[ `du -m %f | { read size rest; echo $$size; }` -le 4 ] && e %f || echo Too large file for Emacs...'; \
		} >>$(HOME)/.config/mc/mc.ext; \
	else \
		mkdir -p $(HOME)/.mc; \
		$(INSTALL_DATA) .local/share/mc/bashrc $(HOME)/.mc; \
		$(INSTALL_DATA) .config/mc/mc.ext $(HOME)/.mc/bindings; \
	fi
ifneq '' '$(filter $(host_os),cygwin linux)'
	if command -v file 1>/dev/null; then \
		$(INSTALL_DATA) .magic $(HOME); \
		cd $(HOME); \
		file --compile -m .magic; \
	fi
endif
	mkdir -p $(HOME)/.local/share/applications/
	$(INSTALL_DATA) .local/share/applications/mimeapps.list $(HOME)/.local/share/applications/

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