Makefile
changeset 0 328995b5b8fd
child 1 d1f59db03d01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Wed Mar 09 21:23:23 2016 +0200
@@ -0,0 +1,150 @@
+
+################################################################
+# Standard GNU 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
+
+################################################################
+# Platform definition.
+
+host_os := linux
+ifneq '' '$(WINDIR)'
+  host_os := cygwin
+endif
+target_os := $(host_os)
+
+################################################################
+# Build tool definition/switches.
+
+RST2HTML := rst2html
+ifeq '$(host_os)' 'cygwin'
+  RST2HTML := rst2html.py
+endif
+
+RST_WARNING_FLAGS := --halt warning
+RST_RENDER_FLAGS := --strip-comments --embed-stylesheet --no-xml-declaration --math-output=HTML --initial-header-level=2
+RST_FLAGS := $(RST_WARNING_FLAGS) $(RST_RENDER_FLAGS)
+
+################################################################
+# Proj dirs/files.
+
+RST_FILES := $(wildcard *.rst)
+
+TMPL_DIR := tmpl
+
+HTML_DIR := dist/multi-html
+RST_HTML_FILES := $(patsubst %.rst,$(HTML_DIR)/%.html,$(RST_FILES))
+HTML_FILES := $(RST_HTML_FILES) $(HTML_DIR)/iframe.html
+
+################################################################
+# Deploy targets.
+
+WWW_SRV_NAME := defun.work
+WWW_SRV_USER := user
+HG_SRV_NAME := hg.defun.work
+HG_SRV_USER := user
+LOCAL_DIR := /srv/www/stat
+
+ifneq '' '$(filter deploy%,$(MAKECMDGOALS))'
+  $(shell rm -f $(HTML_DIR)/rst.tmpl)
+endif
+
+.PHONY: deploy
+deploy: deploy2defun-web deploy2defun-hg
+
+# Will be accessible via: http://stat.defun.work/
+.PHONY: deploy2defun-web
+deploy2defun-web: html
+	rsync --delete -avP -e ssh $(HTML_DIR)/ $(WWW_SRV_USER)@$(WWW_SRV_NAME):/srv/www/stat/
+
+.PHONY: deploy2defun-hg
+deploy2defun-hg:
+	hg push ssh://$(HG_SRV_USER)@$(HG_SRV_NAME)//srv/hg/tips || [ $$? = 1 ]
+
+.PHONY: deploy2local
+deploy2local: html
+	rsync --delete -avP $(HTML_DIR)/ $(LOCAL_DIR)
+
+################################################################
+# Build targets.
+
+.PHONY: all
+all:
+
+.PHONY: html
+html: $(HTML_FILES)
+
+$(HTML_DIR)/%.html: %.rst $(TMPL_DIR)/rst.css $(TMPL_DIR)/rst.tmpl $(MAKEFILE_LIST) | $(HTML_DIR)
+	$(RST2HTML) $(RST_FLAGS) --stylesheet=$(TMPL_DIR)/rst.css --template=$(TMPL_DIR)/rst.tmpl $*.rst $@
+
+$(HTML_DIR)/iframe.html: $(RST_FILES) $(MAKEFILE_LIST) | $(HTML_DIR)
+	{ \
+echo '<html><head>'; \
+echo '<meta charset="utf-8">'; \
+echo '<style>'; \
+echo 'a { text-decoration: none; color: hsl(240, 100%, 50%); }'; \
+echo 'a:hover { opacity: .5; }'; \
+echo '</style></head><body>'; \
+echo '<ul style="padding-left: 1em;">'; \
+for f in $(sort $(RST_FILES)); do \
+  n=$${f%.rst}; \
+  printf '<li><a target="_parent" href="%s.html">%s</a></li>\n' $$n $$n; \
+done; \
+echo '</ul>'; \
+echo '</body></html>'; \
+} >$@
+
+$(TMPL_DIR)/rst.tmpl: $(TMPL_DIR)/rst.tmpl.in $(MAKEFILE_LIST)
+	sed -e "s|{date}|$$(date +%F)|" -e "s|{rev}|$$(hg id -i)|"  <$< >$@
+
+################################################################
+# Init targets.
+
+$(HTML_DIR):
+	mkdir -p $@
+
+################################################################
+# Clean targets.
+
+.PHONY: distclean
+distclean: clean
+
+.PHONY: clean
+clean:
+	rm -r -f $(HTML_DIR)
+
+################################################################
+# Helper target.
+
+.PHONY: help
+help:
+	@echo Supported targets:
+	@sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(MAKEFILE_LIST)
+
+.PHONY: check-format-policy
+check-format-policy:
+	\
+for f in $(RST_FILES); do \
+  if grep '^.. -\*- coding: utf-8; -\*-' $$f >/dev/null; then :; else \
+    echo $$f:1:" Has no 'coding: utf-8' directive."; \
+  fi; \
+  if grep '^.. contents::' $$f >/dev/null; then :; else \
+    echo $$f:7:" Has no 'contents::' directive."; \
+  fi; \
+  if grep '^   :local:' $$f >/dev/null; then :; else \
+    echo $$f:7:" Has no ':local:' directive."; \
+  fi; \
+done
+