Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 25 Feb 2015 15:20:21 +0200
changeset 1266 a1a6db7b859b
parent 1264 49032c3d9007
child 1267 5a6527540e19
permissions -rw-r--r--
Safely move data.

# Copyright (C) 2008-2010 by Oleksandr Gavenko <gavenkoa@gmail.com>
#
# You can do anything with this file without any warranty.


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

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:
# Delete target file if command fails.
.DELETE_ON_ERROR:
# Default target.
.DEFAULT_GOAL = all

################################################################
# Helper definition.

which = $(firstword $(foreach item,$(subst :, ,$(PATH)),$(wildcard $(item)/$1)))

################################################################
# Platform/environment definition.

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

host_os = unix
ifneq '' '$(COMSPEC)'
  ifneq '' '$(WINDIR)'
    # Probably under Windows.
    host_os = windows
  endif
endif

################################################################
# Installation directories.

emacsdir := $(HOME)/.emacs.d
mylispdir := $(emacsdir)/my

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

EMACS = emacs
# I prefer native Windows Emacs, so use it if available.
ifeq 'windows' '$(host_os)'
  ifneq '' '$(call which,runemacs.exe)'
    EMACS = runemacs
  endif
endif

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

################################################################
# Proj dirs/files.

EL_FILES := $(wildcard *.el)

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

################################################################
# Targets.

.PHONY: all
all: install

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

.PHONY: upgrade
upgrade:
	\
mkdir -p $(mylispdir); \
rm -f $(emacsdir)/autoload-my.el; \
[ -d $(emacsdir)/my-lisp ] && mv $(emacsdir)/my-lisp $(mylispdir); \
for f in .emacs-my .emacs-custom.el .emacs-pre .emacs-post .emacs-places .emacs.desktop .emacs.bmk .emacs-places .emacs-autogen .ido.last; do \
  if [ -f ~/$$f ]; then [ -f $(emacsdir)/$$f ] && mv ~/$$f $(emacsdir)/$$f.1 || mv ~/$$f $(emacsdir); fi; \
  if [ -f $(mylispdir)/$$f ]; then [ -f $(emacsdir)/$$f ] && mv $(mylispdir)/$$f $(emacsdir)/$$f.2 || mv $(mylispdir)/$$f $(emacsdir); fi; \
done; \
for f in `find $(mylispdir) -maxdepth 1 -type f -name '.emacs?*'`; do \
  fn=$${f##*/}; \
  [ -f $(emacsdir)/$$fn ] && mv $$f $(emacsdir)/$$fn.3 || mv $$f $(emacsdir); \
done;

.PHONY: install-all
install-all: install
	cp .emacs-pre $(emacsdir)/.emacs-pre
	cp .emacs-post $(emacsdir)/.emacs-post

.PHONY: install
install:
	mkdir -p $(mylispdir)
	find $(mylispdir) -type f -name '*.el' -delete
	for file in .emacs-pre .emacs-post; do \
		[ -f $(emacsdir)/$$file ] || cp $$file $(emacsdir)/$$file; \
	done
	cp .emacs $(emacsdir)/init.el
	cp .emacs-my $(emacsdir)/.emacs-my
	mkdir -p $(emacsdir)/server $(HOME)/.gnus/scores
	cp all.SCORE $(HOME)/.gnus/scores
	cp -f $(EL_FILES) $(mylispdir); \
	$(EMACS) -Q --batch --eval='(let ((generated-autoload-file "$(mylispdir)/loaddefs.el")) (update-directory-autoloads "$(mylispdir)"))'
	./.emacs-autogen.sh $(emacsdir)/.emacs-autogen
	cp -r srecode/ $(HOME)/.emacs.d/

.PHONY: uninstall
uninstall:
	rm -f $(HOME)/.emacs $(mylispdir)/.emacs-my $(mylispdir)/.emacs-autogen
	find $(mylispdir) -type f -name '*.el' -delete
	rm -f -r $(emacsdir)/srecode

.PHONY: tar
tar:
	tar cf dot-emacs.tar .emacs .emacs-my

################################################################
# Documentation targets.

.PHONY: html
html: $(HTML_FILES)

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

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

.PHONY: distclean
distclean: clean

.PHONY: clean
clean:
	rm -f dot-emacs.tar $(HTML_FILES)