Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 12 Jan 2012 21:52:19 +0200
changeset 97 9c82b18ecc15
parent 94 1b2cf5b2b46c
child 103 b5b1dc62bdc0
permissions -rw-r--r--
up

# 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
#   install-local install dictionaries in user HOME dir, so they been available in stardict for that user
#   uninstall-local remove dictionaries from user HOME directory
#   install-local-symlink create symlink from installed dir to user HOME dir, so dictionaries been available in stardict
#   uninstall-local-symlink remove symlink from user HOME directory

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:
# Default target.
.DEFAULT_GOAL = all

################################################################
# Platform/environment definition.

host_os = unix
ifneq '' '$(COMSPEC)'
  ifneq '' '$(WINDIR)'
    # Probably under Windows.
    host_os = windows
  endif
endif

################################################################
# Build tool definition/switches.

RST2HTML = rst2html
ifeq '$(host_os)' 'windows'
  RST2HTML = rst2html.py
endif

################################################################
# Install paths.

ifeq '$(origin prefix)' 'undefined'
  ifeq '$(shell id -u)' '0'
    prefix = /usr/local
  else
    prefix = $(HOME)/usr
  endif
endif
datarootdir = $(prefix)/share
datadir = $(datarootdir)/dictd

################################################################
# Project dirs/files.

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_FILES := $(wildcard *.rst)
HTML_FILES := $(RST_FILES:.rst=.html)

################################################################
# Build targets.

.PHONY: all
all: dist

.PHONY: dist
dist: $(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: dist
	mkdir -p $(datadir)
	for f in $(DICTDZ_FILES) $(INDEX_FILES); do \
		install -m 644 $$f $(datadir); \
	done

.PHONY: uninstall
uninstall:
	for f in $(DICTDZ_FILES) $(INDEX_FILES); do \
		rm -f $(datadir)/$$f; \
	done

################################################################
# Documentation targets.

.PHONY: html
html: $(HTML_FILES)

$(HTML_FILES): %.html: %.rst
	$(RST2HTML) --stylesheet=rst.css $*.rst $@

################################################################
# Statistics targets.

.PHONY: stat
stat:
	total=0; \
	for dic in *.dict-c5; do \
		cnt=`grep '^_____' $$dic | wc -l`; \
		echo $$dic 'has  ' $$cnt words.; \
		total=$$(($$total + $$cnt)); \
	done; \
	echo Total words count is $$total.

################################################################
# Clean targets.

.PHONY: distclean
distclean: clean

.PHONY: clean
clean:
	rm -f $(DICTDZ_FILES) $(INDEX_FILES) $(HTML_FILES)

################################################################
# Helper target.

.PHONY: help
help:
	@echo
	@echo Supported targets:
	@sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(MAKEFILE_LIST)