Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 05 Sep 2011 00:37:38 +0300
changeset 61 f17dbbf6dabf
parent 56 ee149b4fd006
child 63 f1bd82604661
permissions -rw-r--r--
small addition

# 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

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

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

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

.PHONY: distclean
distclean: clean

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