Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 16 Jun 2021 12:50:08 +0300
changeset 1734 ae2c6a001464
parent 1718 9d72f4424570
child 1759 1bbd7898cc9b
permissions -rw-r--r--
Add some standard places to PATH if they are not set by login script. Rearrange the order of paths so system's are first, user's are last. For Cygwin this helps with Cygwin's paths to be situated before "C:/Windows" (Emacs is not started from a login shell on Windows!).


################################################################
# 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
	install -m 0644 -t $(emacsdir) .emacs-pre .emacs-post

.PHONY: install-packages
install-packages:
	$(EMACS) --batch -l "$(curdir)/.emacs-defs" -f my-lisp--install-external-packages

.PHONY: install
install: upgrade
	rm -rf $(mylispdir)
	mkdir -p $(mylispdir)
	echo $(COMPAT_VER) >$(COMPAT_FILE)
	for f in .emacs-pre .emacs-post; do \
		[[ -f $(emacsdir)/$$f ]] || install -m 0644 $$f $(emacsdir)/$$f; \
	done
	install -m 0644 -t $(emacsdir) .emacs-defs init.el .emacs-my
	mkdir -p $(emacsdir)/server
	$(SHELL) .emacs-autogen.sh $(emacsdir)/.emacs-autogen
	cp -r srecode/ $(HOME)/.emacs.d/
	\
install -m 0644 -t $(mylispdir) $(EL_FILES); \
$(EMACS) --batch -Q --eval='(progn (setq generated-autoload-file "$(mylispdir)/loaddefs.el") (update-directory-autoloads "$(mylispdir)"))'

.PHONY: uninstall
uninstall:
	rm -f $(patsubst %,$(emacsdir)/%, init.el .emacs-defs .emacs-my .emacs-autogen)
	rm -rf $(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-modes check-byte-compile-dot-emacs

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

.PHONY: check-byte-compile-dot-emacs
check-byte-compile-dot-emacs:
	$(EMACS) --batch --load "$(curdir)/.emacs-defs" -f 'my-lisp--load-all' --eval='(byte-compile-file ".emacs-my")'
	rm -f .emacs-my.elc

################################################################
# 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)