Makefile
changeset 77 c2bad6178c65
parent 57 94e1b2d0bd31
child 80 1ed275e69293
--- a/Makefile	Thu Sep 18 01:24:29 2014 +0300
+++ b/Makefile	Thu Sep 18 01:51:07 2014 +0300
@@ -80,6 +80,19 @@
 endif
 
 ################################################################
+# Build tools definition/switches.
+
+RST_WARNING_FLAGS := --halt warning
+RST_FLAGS := --strip-comments
+RST_FLAGS += $(RST_WARNING_FLAGS)
+
+RST2HTML := rst2html
+ifeq '$(host_os)' 'cygwin'
+  RST2HTML := rst2html.py
+endif
+RST2HTML_FLAGS := $(RST_FLAGS)
+
+################################################################
 # Project dirs/files.
 
 pkgname = 2048-js-ai
@@ -88,9 +101,14 @@
 
 DIST_DIR = $(fullpkgname)
 
+RST_GEN_FILES := VERSION.rst
+RST_COMMON_FILES := VERSION.rst header.rst
+RST_FILES := $(filter-out $(RST_COMMON_FILES),$(sort $(wildcard *.rst) $(RST_GEN_FILES)))
+RST_HTML_FILES := $(RST_FILES:.rst=.html)
+
 JS_FILES := $(wildcard *.js)
-HTML_FILES := $(wildcard *.html)
-WWW_FILES := $(JS_FILES) $(HTML_FILES)
+HTML_FILES := 2048.html
+WWW_FILES := $(JS_FILES) $(RST_HTML_FILES)
 
 DIST_FILES = $(WWW_FILES) README.rst VERSION
 
@@ -182,6 +200,37 @@
 	cp $(DIST_FILES) $@
 
 ################################################################
+# Documentation targets.
+
+.PHONY: docs
+docs: rst2html
+
+.PHONY: rst2html
+rst2html: $(RST_HTML_FILES)
+
+$(RST_HTML_FILES): $(RST_COMMON_FILES)
+
+$(RST_HTML_FILES): %.html: %.rst rst.css header.rst VERSION.rst $(BUILD_SCRIPTS)
+	$(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=rst.css $*.rst $@
+
+VERSION.rst: VERSION $(BUILD_SCRIPTS)
+	{ \
+	echo 'For ``$(pkgname)`` version: ``$(vmajor).$(vminor)``.'; \
+	echo; \
+	case ${visclean} in \
+		yes) echo 'Source files are at revision: ``$(vrev)``.';; \
+		no) echo 'Some source files was modified from revision: ``$(vrev)``.';; \
+	esac; \
+	echo; \
+	case ${vatrelease} in \
+		yes) echo 'Package is at release state.';; \
+		no) echo 'Package is far from release state by $(vtagdist) changes.';; \
+	esac; \
+	echo; \
+	echo 'Build date: ``'$$(date +%F)'``.'; \
+	} >$@
+
+################################################################
 # Helpers targets.
 
 .PHONY: help
@@ -216,5 +265,5 @@
 
 .PHONY: clean
 clean:
-	rm -rf $(JSDOC_DIR) $(DIST_DIR) $(DIST_TARBALLS)
+	rm -rf $(JSDOC_DIR) $(RST_GEN_FILES) $(RST_HTML_FILES) $(DIST_DIR) $(DIST_TARBALLS)