Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 25 Feb 2015 01:13:28 +0200
changeset 1227 e2355b44d39d
parent 1226 febcf7755a3d
child 1236 f5be1005cdba
child 1262 daacd1a0408f
permissions -rw-r--r--
Enable wesnoth-mode if possible.

# 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; \
mv $(emacsdir)/my-lisp $(mylispdir); \
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; \
mv ~/.emacs.bmk $(mylispdir) || true; \
rm -f ~/.emacs-autogen; \
	\
rm -f ~/.emacs ~/.emacs-places; \
for f in $(mylispdir)/.emacs*; do \
  mv $$f $(emacsdir) || true; \
done; \
mv ~/.ido.last $(emacsdir) || true

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