Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 02 Jan 2021 00:33:04 +0200
changeset 1666 06937ff1ec5f
parent 1665 3685e2321a9b
child 1667 7f70095fbf32
permissions -rw-r--r--
Moved my elisp modes to dedicated directory to not mixt with init.el.

# 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/bash
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.

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)/mylisp

# Compatibility version.
COMPAT_VER := 2
COMPAT_FILE := $(emacsdir)/.emacs-ver

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

# To byte-compile under Windows register Cygwin Emacs to be first in PATH!
EMACS = emacs

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

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

EL_FILES := $(wildcard mylisp/*.el)
ELC_FILES := $(EL_FILES:.el=.elc)

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

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

.PHONY: all
all: install

################################################################
# Deploy targets.

.PHONY: deploy
deploy: deploy2defun deploy2sf


DEFUN_USER ?= user
DEFUN_HG_SRV ?= hg.defun.work
DEFUN_HG_DIR ?= /srv/hg/dot-emacs

.PHONY: deploy2defun
deploy2defun: deploy2defun-src

.PHONY: deploy2defun-src
deploy2defun-src:
	hg push ssh://$(DEFUN_USER)@$(DEFUN_HG_SRV)/$(DEFUN_HG_DIR) || [ $$? = 1 ]


SF_USER ?= gavenkoa

.PHONY: deploy2sf
deploy2sf: deploy2sf-src

.PHONY: deploy2sf-src
deploy2sf-src:
	hg push ssh://$(SF_USER)@hg.code.sf.net/u/$(SF_USER)/dot-emacs || [ $$? = 1 ]

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

ifneq '' '$(filter upgrade,$(MAKECMDGOALS))'
  ifeq '' '$(filter install%,$(MAKECMDGOALS))'
    $(error "upgrade" should be invoked from "install")
  endif
endif

.PHONY: upgrade
upgrade:
	\
if [[ -f ~/.emacs ]]; then \
  echo An old style install detected, delete ~/.emacs first.; \
  false; \
fi
	\
[[ -f $(COMPAT_FILE) ]] || exit 0; \
read ver <$(COMPAT_FILE); \
if [[ "$$ver" -gt $(COMPAT_VER) ]]; then \
  echo "*** "Project is too old, downgrade is not possible..." ***"; \
  exit 1; \
fi; \
for ((i=ver+1; i <= $(COMPAT_VER); i++)); do \
  $(SHELL) upgrade/$$i.bash; \
done

.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' -o -name '*~' ')' -exec rm {} ';'
endef

.PHONY: install
install: upgrade
	mkdir -p $(mylispdir)
	echo $(COMPAT_VER) >$(COMPAT_FILE)
	$(cleanup_mylispdir)
	for file in .emacs-pre .emacs-post; do \
		[ -f $(emacsdir)/$$file ] || cp $$file $(emacsdir)/$$file; \
	done
	\
cp .emacs-defs init.el .emacs-my $(emacsdir)
	\
mkdir -p $(emacsdir)/server $(HOME)/.gnus/scores; \
cp all.SCORE $(HOME)/.gnus/scores
	$(SHELL) .emacs-autogen.sh $(emacsdir)/.emacs-autogen
	\
cp -f $(EL_FILES) $(mylispdir); \
$(EMACS) --batch -Q --eval='(progn (setq generated-autoload-file "$(mylispdir)/loaddefs.el") (update-directory-autoloads "$(mylispdir)"))'
	\
$(EMACS) --batch --load "$(curdir)/.emacs-defs" -f 'my-load.add-my-loadpaths' --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

################################################################
# Check targets.

.PHONY: check
check: check-byte-compile

.PHONY: check-byte-compile
check-byte-compile:
	\
$(EMACS) -f package-initialize --eval '(push "mylisp" load-path)'  --batch -f batch-byte-compile $(EL_FILES) || :
	rm -f $(ELC_FILES)

################################################################
# 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) $(ELC_FILES)