Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 25 Dec 2023 20:15:49 +0200
changeset 1772 d97be992a1f9
parent 1759 1bbd7898cc9b
permissions -rw-r--r--
Introduced Org state FAILED.


################################################################
# 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); \
cd $(mylispdir); \
$(EMACS) --batch -Q --eval='(progn (setq generated-autoload-file "./loaddefs.el") (update-directory-autoloads "."))'

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