Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 04 Feb 2015 23:43:38 +0200
changeset 1202 17ed3f571ca4
parent 1199 dff272add01e
child 1209 aa1de5eb3665
permissions -rw-r--r--
Add shortcut for recentf.

# 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 *-mode.el) debian-doc.el maven-central.el

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

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

.PHONY: all
all: install

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

.PHONY: upgrade
upgrade:
	\
if [ ! -d $(mylispdir) ]; then \
  if [ -d $(emacsdir)/my-lisp ]; then \
    rm -f $(emacsdir)/autoload-my.el; \
    mv $(emacsdir)/my-lisp $(mylispdir); \
  else \
    mkdir -p $(mylispdir); \
  fi; \
  mv ~/.emacs-my $(mylispdir)/.emacs || true; \
  mv ~/.emacs-custom.el $(mylispdir)/.emacs-custom || true; \
  mv ~/.emacs-pre $(mylispdir) || true; \
  mv ~/.emacs-post $(mylispdir) || true; \
  mv ~/.emacs-places $(mylispdir) || true; \
  mv ~/.emacs.desktop $(mylispdir) || true; \
  rm -f ~/.emacs-autogen; \
fi

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

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