Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 25 May 2013 11:19:09 +0300
changeset 46 30e6076ece0a
parent 44 e7fc05196363
child 57 66fd832dee47
permissions -rw-r--r--
Update "Вяление мяса".


################################################################
# Standard GNU Makefile settings.

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:
# Delete target file if command fails.
.DELETE_ON_ERROR:
# Default target.
.DEFAULT_GOAL = all

################################################################
# Platform definition.

host_os := linux
ifneq '' '$(WINDIR)'
  host_os := cygwin
endif
target_os := $(host_os)

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

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

RST_WARNING_FLAGS := --halt warning
RST_FLAGS := --strip-comments
RST_FLAGS += $(RST_WARNING_FLAGS)

################################################################
# Proj dirs/files.

RST_FILES := $(filter-out HEADER.rst,$(wildcard *.rst))
TXT_FILES := $(wildcard *.txt)

HTML_DIR := tips-html
RST_HTML_FILES := $(patsubst %.rst,$(HTML_DIR)/%.html,$(RST_FILES))
HTML_FILES := $(RST_HTML_FILES) \
        $(HTML_DIR)/index.html $(HTML_DIR)/frame.html $(HTML_DIR)/frame-index.html
TXT__FILES := $(addprefix $(HTML_DIR)/,$(TXT_FILES))

CHM_FILES := $(addprefix $(HTML_DIR)/,chm.hhp chm.hhc chm.stp)

DIRS := $(HTML_DIR)

################################################################
# Deploy targets.

ifneq '' '$(filter deploy%,$(MAKECMDGOALS))'
  $(shell rm -f HEADER.rst)
endif

.PHONY: deploy
deploy: deploy2sf-web deploy2sf-hg

# Will be accessible via: http://gavenkoa.users.sourceforge.net/tips-html/frame.html
.PHONY: deploy2sf-web
deploy2sf-web: html
	rsync --delete -avP -e ssh tips-html/ gavenkoa@frs.sourceforge.net:/home/user-web/g/ga/gavenkoa/htdocs/tips-html/

.PHONY: deploy2sf-hg
deploy2sf-hg:
	hg push ssh://gavenkoa@hg.code.sf.net/u/gavenkoa/tips || [ $$? = 1 ]

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

.PHONY: all
all:

.PHONY: html
html: $(HTML_FILES) $(TXT__FILES)

$(HTML_DIR)/%.html: %.rst HEADER.rst rst.css $(MAKEFILE_LIST) | $(HTML_DIR)
	$(RST2HTML) $(RST_FLAGS) --stylesheet=rst.css $*.rst $@

HEADER.rst: Makefile
	{ \
echo '.. _`Home`: index.html'; \
echo '.. _About: README.html'; \
echo '.. _`About author`: http://gavenkoa.users.sourceforge.net/'; \
echo '.. _Licence: README.html#tips-licence'; \
echo '.. _`Contact`: gavenkoa@gmail.com'; \
echo; \
echo '[ Home_ | About_ | Licence_ | `About author`_ | `Contact`_ ]'; \
echo; \
echo 'Written by Oleksandr Gavenko (AKA gavenkoa), compiled at ``'`date +%F`'`` from rev ``'`hg id -i`'``.'; \
} >$@

$(HTML_DIR)/frame-index.html: index.sh $(RST_HTML_FILES) $(MAKEFILE_LIST) | $(HTML_DIR)
	./index.sh frame >$@

$(HTML_DIR)/index.html: index.sh $(RST_HTML_FILES) $(MAKEFILE_LIST) | $(HTML_DIR)
	./index.sh html >$@

$(HTML_DIR)/%.html: %.html $(MAKEFILE_LIST) | $(HTML_DIR)
	cp $< $@

$(HTML_DIR)/%.txt: %.txt $(MAKEFILE_LIST) | $(HTML_DIR)
	cp $< $@

.PHONY: chm
chm: html $(CHM_FILES) $(HTML_DIR)/index-chm.html
	cd $(HTML_DIR); for file in *.html; do sed -i '/<\?xml.*\?>/d' $$file; done

$(HTML_DIR)/%.stp: %.stp $(MAKEFILE_LIST) | $(HTML_DIR)
	cp $< $@

$(HTML_DIR)/chm.hhp: chm-hhp.sh $(MAKEFILE_LIST) | $(HTML_DIR)
	./chm-hhp.sh >$@

$(HTML_DIR)/chm.hhc: chm-hhc.sh $(MAKEFILE_LIST) | $(HTML_DIR)
	./chm-hhc.sh >$@

$(HTML_DIR)/index-chm.html: index.sh $(MAKEFILE_LIST) | $(HTML_DIR)
	./index.sh html >$@

################################################################
# Init targets.

$(DIRS):
	mkdir -p $@

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

.PHONY: distclean
distclean: clean

.PHONY: clean
clean:
	rm -r -f $(DIRS) HEADER.rst

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

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

.PHONY: check-format-policy
check-format-policy:
	\
for f in *.rst; do \
  if grep '.. -\*- coding: utf-8; -\*-' $$f >/dev/null; then :; else \
    echo $$f:1:" Has no 'coding: utf-8' directive."; \
  fi; \
  if grep '.. include:: HEADER.rst' $$f >/dev/null; then :; else \
    echo $$f:2:" Has no 'include:: HEADER.rst' directive."; \
  fi; \
  if grep '.. contents::' $$f >/dev/null; then :; else \
    echo $$f:7:" Has no 'contents::' directive."; \
  fi; \
done