Fix formatting and typos for automated translation to different
dictionary format.
# To build dictionary you need to install:
#
# $ sudo apt-get install dictfmt
#
# Available target:
#
# all build dictionaries
# install install dictionaries, so they been available in stardict, may require root permission
# uninstall remove dictionaries, they been unavailable in stardict, may require root permission
#
# You can override such variables in Makefile.config:
#
# SF_USER SourceForge user name.
# prefix Prefix to install path.
# DESTDIR Prefix to 'prefix' variable value.
################################################################
# Standard GNU 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 = help
################################################################
# Build script definitions.
BUILD_SCRIPTS := $(firstword $(MAKEFILE_LIST))
ifneq '' '$(wildcard Makefile.config)'
include Makefile.config
BUILD_SCRIPTS += Makefile.config
endif
################################################################
# Version extracting/generation.
# Prevent making distribution with wrong version.
ifneq '' '$(filter deploy% dist%,$(MAKECMDGOALS))'
ifeq '' '$(MAKE_RESTARTS)'
$(info $(shell rm -f VERSION))
endif
endif
# Here are vmajor and vminor. Look README section "Versioning rules."
-include VERSION
VERSION:
\
vtagdist=$$(hg log -r . --template '{latesttagdistance}'); \
vatrelease=$$([ $$vtagdist -le 1 ] && echo yes || echo no); \
vtag=$$(hg log -r . --template '{latesttag}'); \
vmajor=$${vtag#v}; \
vmajor=$${vmajor%%.*}; \
vminor=$${vtag#*.}; \
vrev=$$(hg id -i); \
visclean=$$(case $$vrev in *+) echo no;; *) echo yes;; esac); \
vrev=$${vrev%+}; \
{ \
echo "vrev=$$vrev"; \
echo "vtag=$$vtag"; \
echo "vtagdist=$$vtagdist"; \
echo "visclean=$$visclean"; \
echo "vatrelease=$$vatrelease"; \
echo "vmajor=$$vmajor"; \
echo "vminor=$$vminor"; \
} >VERSION
################################################################
# Determine platform/environment.
host_os = unix
ifneq '' '$(COMSPEC)'
ifneq '' '$(WINDIR)'
# Probably under Windows.
host_os = windows
ifneq '' '$(wildcard /etc/setup/*cygwin*)'
# Probably under Cygwin.
host_os = cygwin
endif
endif
endif
################################################################
# Build tools definition/switches.
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644
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)
LATEX2PDF := pdflatex
################################################################
# Install paths.
ifeq '$(origin prefix)' 'undefined'
ifeq '$(shell id -u)' '0'
prefix = /usr/local
else
prefix = $(HOME)/usr
endif
endif
datarootdir := $(DESTDIR)$(prefix)/share
datadir = $(datarootdir)/dictd
################################################################
# Project dirs/files.
pkgname = gadict
fullpkgname = $(pkgname)-$(vmajor).$(vminor)
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)
LOGO_NAME := logo
LOGO_SVG := $(LOGO_NAME).svg
LOGO_DIM := 32x32 48x48 64x64
LOGO_PNG_FILES := $(patsubst %,$(LOGO_NAME)-%.png,$(LOGO_DIM))
DIST_DIR = $(fullpkgname)
DISTSRC_DIR = $(fullpkgname)_src
DIST_FILES = $(DICTDZ_FILES) $(INDEX_FILES) $(RST_HTML_FILES) $(RST_FILES) VERSION
DISTSRC_HELPER_FILES = VERSION 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.
ifeq '' '$(SF_USER)'
SF_USER := gavenkoa
endif
.PHONY: deploy
deploy: deploy2sf
# First time you deploy to SourceForge (sf) you need manually login to:
# $ sftp $(SF_USER),$(pkgname)@web.sourceforge.net
# as it may require interactive input for accepting server public key.
# Next time any action fully automated.
.PHONY: deploy2sf
deploy2sf: deploy2sf-src deploy2sf-doc deploy2sf-voa deploy2sf-release
.PHONY: deploy2sf-src
deploy2sf-src:
hg push ssh://$(SF_USER)@hg.code.sf.net/p/$(pkgname)/code || [ $$? = 1 ]
# Will be accessed via http://$(pkgname).sourceforge.net
.PHONY: deploy2sf-doc
deploy2sf-doc: deploy-check $(RST_HTML_FILES)
( echo 'cd htdocs'; \
for f in $(RST_HTML_FILES); do \
echo "put $$f"; \
echo "chmod 644 $$f"; \
done; \
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@web.sourceforge.net
.PHONY: deploy2sf-voa
deploy2sf-voa: voa
( echo 'cd htdocs'; \
echo "put voa-special.pdf"; \
echo "chmod 644 voa-special.pdf"; \
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@web.sourceforge.net
.PHONY: deploy2sf-release
deploy2sf-release: deploy-check $(DIST_TARBALLS) $(DISTSRC_TARBALLS)
( 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"; \
echo "mkdir v$(vmajor).$(vminor)"; \
echo "cd v$(vmajor).$(vminor)"; \
for f in $(DIST_TARBALLS) $(DISTSRC_TARBALLS); do \
echo "put $$f"; \
echo "chmod 644 $$f"; \
done; \
echo 'quit'; \
) | sftp -b - $(SF_USER),$(pkgname)@frs.sourceforge.net
.PHONY: deploy-check
deploy-check:
\
case ${visclean} in \
no) echo "Local changes found. Build stop."; \
exit 1;; \
esac
\
case $(vatrelease) in \
no) echo "We are not at release. Build stop."; \
exit 1;; \
esac
################################################################
# Dist targets.
.PHONY: dist
dist: dist-dictd dist-src
.PHONY: dist-dictd
dist-dictd: $(DIST_TARBALLS)
.PHONY: dist-src
dist-src: $(DISTSRC_TARBALLS)
%.tar.gz: %
tar zcf $*.tar.gz $*
%.tar.bz2: %
tar jcf $*.tar.bz2 $*
$(DIST_DIR): $(DIST_FILES)
rm -rf $@
mkdir $@
cp $(DIST_FILES) $@
$(DISTSRC_DIR): $(DISTSRC_FILES)
rm -rf $@
mkdir $@
cp $(DISTSRC_FILES) $@
################################################################
# Build targets.
.PHONY: all
all: dict
.PHONY: dict
dict: $(DICTDZ_FILES) $(INDEX_FILES)
# --case-sensitive
%.dict %.index: %.dict-c5
sed '/^#/d' $< | dictfmt -c5 \
--headword-separator '; ' --break-headwords \
--utf8 --allchars \
-u "`sed -n '\|http://[[:print:]]\+/|{s=^.*\(http://\)=\1=;p;q;}' $<`" \
-s "`sed -n '/^ABOUT: /{s=ABOUT: ==;p;q;}' $<`" \
$*
%.dict.dz: %.dict
dictzip -c $< >$@
################################################################
# Install/uninstall targets.
.PHONY: install
install: $(DICTDZ_FILES) $(INDEX_FILES)
mkdir -p $(datadir)
for f in $(DICTDZ_FILES) $(INDEX_FILES); do \
$(INSTALL_DATA) $$f $(datadir); \
done
.PHONY: uninstall
uninstall:
for f in $(DICTDZ_FILES) $(INDEX_FILES); do \
rm -f $(datadir)/$$f; \
done
################################################################
# Documentation targets.
.PHONY: docs
docs: html
.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 $@
VERSION.rst: VERSION $(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 $< $@
################################################################
# Misc targets.
.PHONY: logo
logo: logo-png
.PHONY: logo-png
logo-png: $(LOGO_PNG_FILES)
# Require:
# $ sudo apt-get install imagemagick librsvg2-bin
$(LOGO_PNG_FILES): $(LOGO_NAME)-%.png: $(LOGO_SVG)
convert +antialias -background transparent $< -resize $* $@
.PHONY: voa
voa: voa-special.pdf
voa-special.pdf: contrib/voa-special.tex
$(LATEX2PDF) -output-directory . $<
################################################################
# Helpers targets.
.PHONY: help
help:
@\
echo; \
echo Current configuration:; \
echo; \
sed 's=^= =' <VERSION
@if [ -f Makefile.config ]; then \
echo; \
echo User configuration:; \
echo; \
sed 's=^= =' <Makefile.config; \
fi
@\
echo; \
echo Supported targets:; \
echo; \
sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*= \1=;p;}' $(BUILD_SCRIPTS)
.PHONY: todo
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
# Require:
# $ sudo apt-get install imagemagick librsvg2-bin
%.png: %.svg
convert +antialias -background transparent $< $@
################################################################
# Clean targets.
.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)