--- a/Makefile Sun Mar 13 16:46:19 2016 +0200
+++ b/Makefile Sun Mar 13 18:20:35 2016 +0200
@@ -44,17 +44,19 @@
################################################################
# Version extracting/generation.
+VER_FILE := dist/misc/VERSION
+
# Prevent making distribution with wrong version.
ifneq '' '$(filter deploy% dist%,$(MAKECMDGOALS))'
ifeq '' '$(MAKE_RESTARTS)'
- $(info $(shell rm -f VERSION))
+ $(shell rm -f $(VER_FILE))
endif
endif
# Here are vmajor and vminor. Look README section "Versioning rules."
--include VERSION
+-include $(VER_FILE)
-VERSION:
+$(VER_FILE): | $(dir $(VER_FILE))
\
vtagdist=$$(hg log -r . --template '{latesttagdistance}'); \
vatrelease=$$([ $$vtagdist -le 1 ] && echo yes || echo no); \
@@ -73,7 +75,7 @@
echo "vatrelease=$$vatrelease"; \
echo "vmajor=$$vmajor"; \
echo "vminor=$$vminor"; \
-} >VERSION
+} >$@
################################################################
# Determine platform/environment.
@@ -105,7 +107,8 @@
ifeq '$(host_os)' 'cygwin'
RST2HTML := rst2html.py
endif
-RST2HTML_FLAGS := $(RST_FLAGS)
+RST2HTML_RENDER_FLAGS := --strip-comments --embed-stylesheet --no-xml-declaration --math-output=HTML --initial-header-level=2
+RST2HTML_FLAGS := $(RST_FLAGS) $(RST2HTML_RENDER_FLAGS)
LATEX2PDF := pdflatex
@@ -128,15 +131,27 @@
pkgname = gadict
fullpkgname = $(pkgname)-$(vmajor).$(vminor)
+GADICT_FILES := $(wildcard *.gadict)
+
C5_FILES := $(wildcard *.dict-c5)
DICT_FILES := $(C5_FILES:.dict-c5=.dict)
DICTDZ_FILES := $(C5_FILES:.dict-c5=.dict.dz)
INDEX_FILES := $(C5_FILES:.dict-c5=.index)
-RST_GEN_FILES := VERSION.rst STAT.rst index.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)
+RST_TMPL_FILE = dist/misc/rst.tmpl
+RST_CSS_FILE = www/tmpl/rst.css
+
+RST_GEN_FILES := STAT.rst
+RST_COMMON_FILES := header.rst
+RST_FILES := $(wildcard www/*.rst)
+RST_HTML_FILES := $(patsubst www/%.rst,dist/www/%.html,$(RST_FILES))
+
+INDEX_HTML_FILE := dist/www/index.html
+
+STAT_RST_FILE := dist/misc/STAT.rst
+STAT_HTML_FILE := dist/www/STAT.html
+
+HTML_FILES := $(RST_HTML_FILES) $(INDEX_HTML_FILE) $(STAT_HTML_FILE)
LOGO_NAME := logo
LOGO_SVG := $(LOGO_NAME).svg
@@ -146,20 +161,29 @@
DIST_DIR = $(fullpkgname)
DISTSRC_DIR = $(fullpkgname)_src
-DIST_FILES = $(DICTDZ_FILES) $(INDEX_FILES) $(RST_HTML_FILES) $(RST_FILES) VERSION
+DIST_FILES = $(DICTDZ_FILES) $(INDEX_FILES) $(RST_HTML_FILES) $(RST_FILES)
-DISTSRC_HELPER_FILES = VERSION Makefile rst.css .dir-locals.el
+DISTSRC_HELPER_FILES = Makefile rst.css .dir-locals.el
DISTSRC_FILES = $(C5_FILES) $(RST_FILES) $(DISTSRC_HELPER_FILES)
DIST_TARBALLS = $(DIST_DIR).tar.gz $(DIST_DIR).tar.bz2
DISTSRC_TARBALLS = $(DISTSRC_DIR).tar.gz $(DISTSRC_DIR).tar.bz2
################################################################
-# Deploy targets.
+# Deploy/release targets.
.PHONY: deploy
deploy: deploy2defun deploy2sf
+.PHONY: release
+release: release2defun release2sf
+
+.PHONY: release2defun
+release2defun: validate-release deploy2defun
+
+.PHONY: release2sf
+release2defun: validate-release deploy2sf
+
DEFUN_USER ?= user
DEFUN_HG_SRV ?= hg.defun.work
@@ -175,12 +199,13 @@
hg push ssh://$(DEFUN_USER)@$(DEFUN_HG_SRV)/$(DEFUN_HG_DIR) || [ $$? = 1 ]
.PHONY: deploy2defun-www
-deploy2defun-www: $(RST_HTML_FILES)
+deploy2defun-www: $(HTML_FILES)
( \
echo 'cd $(DEFUN_WWW_DIR)'; \
-for f in $(RST_HTML_FILES); do \
- echo "put $$f"; \
- echo "chmod 644 $$f"; \
+for f in $(HTML_FILES); do \
+ n=$${f##*/}; \
+ echo "put $$f $$n"; \
+ echo "chmod 644 $$n"; \
done; \
echo 'quit'; \
) | sftp -b - $(DEFUN_USER)@$(DEFUN_WWW_SRV)
@@ -194,7 +219,7 @@
# Next time any action fully automated.
.PHONY: deploy2sf
-deploy2sf: deploy2sf-src deploy2sf-www deploy2sf-voa deploy2sf-release
+deploy2sf: deploy2sf-src deploy2sf-www deploy2sf-voa
.PHONY: deploy2sf-src
deploy2sf-src:
@@ -202,11 +227,12 @@
# Will be accessed via http://$(pkgname).sourceforge.net
.PHONY: deploy2sf-www
-deploy2sf-www: deploy-check $(RST_HTML_FILES)
+deploy2sf-www: $(HTML_FILES)
( echo 'cd htdocs'; \
-for f in $(RST_HTML_FILES); do \
- echo "put $$f"; \
- echo "chmod 644 $$f"; \
+for f in $(HTML_FILES); do \
+ n=$${f##*/}; \
+ echo "put $$f $$n"; \
+ echo "chmod 644 $$n"; \
done; \
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@web.sourceforge.net
@@ -219,8 +245,10 @@
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@web.sourceforge.net
-.PHONY: deploy2sf-release
-deploy2sf-release: deploy-check $(DIST_TARBALLS) $(DISTSRC_TARBALLS)
+.PHONY: release2sf
+deploy2sf-release: validate-release $(DIST_TARBALLS) $(DISTSRC_TARBALLS)
+ exit 1
+ : TODO broken due to new project hierarchy
( echo 'cd /home/frs/project/$(shell v=$(pkgname); echo $${v:0:1}/$${v:0:2})/$(pkgname)'; \
echo "put README.rst"; \
echo "chmod 644 README.rst"; \
@@ -233,8 +261,8 @@
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@frs.sourceforge.net
-.PHONY: deploy-check
-deploy-check:
+.PHONY: validate-release
+validate-release:
\
case ${visclean} in \
no) echo "Local changes found. Build stop."; \
@@ -320,26 +348,50 @@
.PHONY: html
html: $(RST_HTML_FILES)
-$(RST_HTML_FILES): %.html: %.rst $(RST_COMMON_FILES) rst.css $(BUILD_SCRIPTS)
- $(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=rst.css $*.rst $@
+$(INDEX_HTML_FILE): dist/www/README.html
+ cp $< $@
+
+$(RST_HTML_FILES): dist/www/%.html: www/%.rst $(RST_CSS_FILE) $(RST_TMPL_FILE) $(BUILD_SCRIPTS) | dist/www
+ $(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=$(RST_CSS_FILE) --template=$(RST_TMPL_FILE) www/$*.rst $@
+
+dist/www:
+ mkdir -p $@
-VERSION.rst: VERSION $(BUILD_SCRIPTS)
+$(RST_TMPL_FILE): www/tmpl/rst.tmpl.in $(BUILD_SCRIPTS) | $(dir $(RST_TMPL_FILE))
+ \
+[[ ${visclean} = no ]] && warn1='<b>Warning</b>: Build done with local changes!' || :; \
+[[ ${vatrelease} = no ]] && warn2='<b>Warning</b>: Build is far from latest <tt>$(vtag)</tt> release state by $(vtagdist) changes.' || :; \
+sed -e "s|{date}|$$(date +%F)|" -e "s|{rev}|$$(hg id -i)|" -e "s|{warn1}|$$warn1|" -e "s|{warn2}|$$warn2|" <$< >$@
+
+################################################################
+# Article statistics.
+
+.PHONY: stat
+stat: $(STAT_HTML_FILE)
+
+$(STAT_HTML_FILE): $(STAT_RST_FILE) $(RST_CSS_FILE) $(RST_TMPL_FILE) | dist/www
+ $(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=$(RST_CSS_FILE) --template=$(RST_TMPL_FILE) $< $@
+
+$(STAT_RST_FILE): $(GADICT_FILES) $(BUILD_SCRIPTS)
{ \
- echo '``$(pkgname)`` ``v$(vmajor).$(vminor)`` built on ``'$$(date +%F)'`` from revision ``$(vrev)``.'; \
- echo; \
- case ${visclean} in \
- yes) : ;; \
- no) echo 'WARNING!! Source tree has local changes!';; \
- esac; \
- echo; \
- case ${vatrelease} in \
- yes) : ;; \
- no) echo 'Package is far from release state by $(vtagdist) changes.';; \
- esac; \
- } >$@
-
-index.rst: README.rst
- cp $< $@
+echo '==========================='; \
+echo ' gadict project statistics'; \
+echo '==========================='; \
+echo '.. contents::'; \
+echo ' :local:'; \
+echo; \
+echo '======================================== ====='; \
+echo ' Dictionary Count'; \
+echo '======================================== ====='; \
+total=0; \
+for dic in $(GADICT_FILES); do \
+ cnt=`grep '^__' $$dic | wc -l`; \
+ printf '%40s %5s\n' $${dic%.dict-c5} $$cnt; \
+ total=$$(($$total + $$cnt)); \
+done; \
+printf '%40s %5s\n' '**Total**' $$total; \
+echo '======================================== ====='; \
+} >$@
################################################################
# Misc targets.
@@ -387,42 +439,6 @@
todo:
grep -nH 'TODO\|XXX' $(RST_FILES) $(C5_FILES)
-.PHONY: stat
-stat: STAT.rst
-
-STAT.rst: $(C5_FILES) header.rst VERSION.rst $(BUILD_SCRIPTS)
- { \
-echo '.. include:: header.rst'; \
-echo; \
-echo '============================'; \
-echo ' gadict project statistics.'; \
-echo '============================'; \
-echo '.. contents::'; \
-echo; \
-echo 'Document version.'; \
-echo '================='; \
-echo; \
-echo '.. include:: VERSION.rst'; \
-echo; \
-echo 'Statistics on count of articles in gadict dictionaries.'; \
-echo '======================================================='; \
-echo; \
-echo 'You must know that some words have articles (usually but not always same) in'; \
-echo 'several dictionaries. So real count of words is less then total count.'; \
-echo; \
-echo '======================================== ====='; \
-echo ' Dictionary Count'; \
-echo '======================================== ====='; \
-total=0; \
-for dic in $(C5_FILES); do \
- cnt=`grep '^_____' $$dic | wc -l`; \
- printf '%40s %5s\n' $${dic%.dict-c5} $$cnt; \
- total=$$(($$total + $$cnt)); \
-done; \
-printf '%40s %5s\n' '**Total**' $$total; \
-echo '======================================== ====='; \
-} >$@
-
.PHONY: logo-png
logo-png: logo-64x64.png
@@ -436,12 +452,8 @@
.PHONY: distclean
distclean: clean
- rm -f VERSION
.PHONY: clean
clean:
- rm -f $(DICTDZ_FILES) $(INDEX_FILES) $(RST_GEN_FILES) $(RST_HTML_FILES) $(LOGO_PNG_FILES)
- rm -rf $(DIST_DIR) $(DIST_TARBALLS)
- rm -rf $(DISTSRC_DIR) $(DISTSRC_TARBALLS)
- rm -f $(patsubst %, voa-special%, .pdf .log .out .aux)
+ rm -rf dist/