Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 27 Dec 2011 23:13:09 +0300
changeset 78 961dec7df9ce
parent 68 ce7aca59cb54
child 85 0ff3715e6176
permissions -rw-r--r--
up

# 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 $@

################################################################
# 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)