# 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)))
curdir := $(realpath .)
################################################################
# 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 and files.
emacsdir := $(HOME)/.emacs.d
mylispdir := $(emacsdir)/my
# Compatibility version.
COMPAT_VER := 1
COMPAT_FILE := $(emacsdir)/.emacs-ver
################################################################
# 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: check-install-comapt
check-install-comapt:
[ -f $(COMPAT_FILE) ] || { echo $(COMPAT_FILE) missing, run '"make upgrade"' first; false; }
read ver <$(COMPAT_FILE); if [ "$$ver" -ne $(COMPAT_VER) ]; then echo "*** "Run '"make upgrade"' first" ***"; exit 1; fi
.PHONY: check-upgrade-comapt
check-upgrade-comapt:
\
if [ -f $(COMPAT_FILE) ]; then \
read ver <$(COMPAT_FILE); \
if [ "$$ver" -gt $(COMPAT_VER) ]; then \
echo "*** "Project is too old, downgrade is not possible..." ***"; \
exit 1; \
fi; \
fi
.PHONY: upgrade
upgrade: check-upgrade-comapt
\
mkdir -p $(mylispdir); \
rm -f $(emacsdir)/autoload-my.el; \
rm -f ~/.emacs; \
[ -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-places .emacs-autogen .ido.last .recentf; 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; \
if [ -f ~/.emacs.bmk ]; then [ -f $(emacsdir)/bookmarks ] && mv ~/.emacs.bmk $(emacsdir)/bookmarks.$$$$ || mv ~/.emacs.bmk $(emacsdir)/bookmarks; fi; \
if [ -f $(emacsdir)/.emacs.bmk ]; then [ -f $(emacsdir)/bookmarks ] && mv $(emacsdir)/.emacs.bmk $(emacsdir)/bookmarks.$$$$ || mv $(emacsdir)/.emacs.bmk $(emacsdir)/bookmarks; fi; \
echo $(COMPAT_VER) >$(COMPAT_FILE); \
make install
.PHONY: install-all
install-all: install
cp .emacs-pre $(emacsdir)/.emacs-pre
cp .emacs-post $(emacsdir)/.emacs-post
define cleanup_mylispdir
find $(mylispdir) -type f '(' -name '*.el' -o -name '*.elc' ')' -delete
endef
.PHONY: install
install: check-install-comapt
mkdir -p $(mylispdir)
$(cleanup_mylispdir)
for file in .emacs-pre .emacs-post; do \
[ -f $(emacsdir)/$$file ] || cp $$file $(emacsdir)/$$file; \
done
cp .emacs $(emacsdir)/init.el
cp .emacs-defs .emacs-my $(emacsdir)
mkdir -p $(emacsdir)/server $(HOME)/.gnus/scores
cp all.SCORE $(HOME)/.gnus/scores
cp -f $(EL_FILES) $(mylispdir); \
./.emacs-autogen.sh $(emacsdir)/.emacs-autogen; \
$(EMACS) -Q --batch --eval='(let ((generated-autoload-file "$(mylispdir)/loaddefs.el")) (update-directory-autoloads "$(mylispdir)"))'
\
$(EMACS) -Q --batch --eval='(load "$(curdir)/.emacs-defs")' --eval='(my-load.add-my-loadpaths)' --eval='(load "$(emacsdir)/.emacs-pre")' \
--eval='(byte-compile-file "$(emacsdir)/.emacs-my")' --eval='(byte-force-recompile "$(mylispdir)")'
cp -r srecode/ $(HOME)/.emacs.d/
.PHONY: uninstall
uninstall:
rm -f $(patsubst %,$(emacsdir)/%, init.el .emacs-defs .emacs-my .emacs-autogen)
$(cleanup_mylispdir)
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)