Makefile
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 21 Apr 2016 16:18:07 +0300
changeset 14 d9c9bc2d2ac9
parent 1 d1f59db03d01
permissions -rw-r--r--
Prevent wrapping long formulas on RET key.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
# Standard GNU Makefile settings.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
SHELL = /bin/sh
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
export PATH := /bin:/usr/bin:${PATH}
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
# Disable built in pattern rules.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
MAKEFLAGS += -r
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
# Disable built in variables.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
MAKEFLAGS += -R
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
# Disable built in suffix rules.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
.SUFFIXES:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
# Delete target file if command fails.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
.DELETE_ON_ERROR:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
# Default target.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
.DEFAULT_GOAL = all
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
# Platform definition.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
host_os := linux
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
ifneq '' '$(WINDIR)'
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
  host_os := cygwin
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
endif
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
target_os := $(host_os)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
# Build tool definition/switches.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
RST2HTML := rst2html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
ifeq '$(host_os)' 'cygwin'
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
  RST2HTML := rst2html.py
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
endif
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
RST_WARNING_FLAGS := --halt warning
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
RST_RENDER_FLAGS := --strip-comments --embed-stylesheet --no-xml-declaration --math-output=HTML --initial-header-level=2
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
RST_FLAGS := $(RST_WARNING_FLAGS) $(RST_RENDER_FLAGS)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
# Proj dirs/files.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
RST_FILES := $(wildcard *.rst)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
TMPL_DIR := tmpl
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
HTML_DIR := dist/multi-html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
RST_HTML_FILES := $(patsubst %.rst,$(HTML_DIR)/%.html,$(RST_FILES))
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
HTML_FILES := $(RST_HTML_FILES) $(HTML_DIR)/iframe.html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
# Deploy targets.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
WWW_SRV_NAME := defun.work
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    55
WWW_SRV_USER := user
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    56
HG_SRV_NAME := hg.defun.work
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    57
HG_SRV_USER := user
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    58
LOCAL_DIR := /srv/www/stat
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    59
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    60
ifneq '' '$(filter deploy%,$(MAKECMDGOALS))'
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    61
  $(shell rm -f $(HTML_DIR)/rst.tmpl)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    62
endif
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    63
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    64
.PHONY: deploy
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    65
deploy: deploy2defun-web deploy2defun-hg
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    66
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    67
# Will be accessible via: http://stat.defun.work/
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    68
.PHONY: deploy2defun-web
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    69
deploy2defun-web: html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    70
	rsync --delete -avP -e ssh $(HTML_DIR)/ $(WWW_SRV_USER)@$(WWW_SRV_NAME):/srv/www/stat/
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    71
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    72
.PHONY: deploy2defun-hg
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    73
deploy2defun-hg:
1
d1f59db03d01 Fix typo.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 0
diff changeset
    74
	hg push ssh://$(HG_SRV_USER)@$(HG_SRV_NAME)//srv/hg/stat || [ $$? = 1 ]
0
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    75
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    76
.PHONY: deploy2local
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    77
deploy2local: html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    78
	rsync --delete -avP $(HTML_DIR)/ $(LOCAL_DIR)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    79
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    80
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
# Build targets.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
.PHONY: all
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
all:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    85
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    86
.PHONY: html
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    87
html: $(HTML_FILES)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    88
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    89
$(HTML_DIR)/%.html: %.rst $(TMPL_DIR)/rst.css $(TMPL_DIR)/rst.tmpl $(MAKEFILE_LIST) | $(HTML_DIR)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    90
	$(RST2HTML) $(RST_FLAGS) --stylesheet=$(TMPL_DIR)/rst.css --template=$(TMPL_DIR)/rst.tmpl $*.rst $@
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    91
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    92
$(HTML_DIR)/iframe.html: $(RST_FILES) $(MAKEFILE_LIST) | $(HTML_DIR)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    93
	{ \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    94
echo '<html><head>'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    95
echo '<meta charset="utf-8">'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    96
echo '<style>'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    97
echo 'a { text-decoration: none; color: hsl(240, 100%, 50%); }'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    98
echo 'a:hover { opacity: .5; }'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    99
echo '</style></head><body>'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   100
echo '<ul style="padding-left: 1em;">'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   101
for f in $(sort $(RST_FILES)); do \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   102
  n=$${f%.rst}; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   103
  printf '<li><a target="_parent" href="%s.html">%s</a></li>\n' $$n $$n; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   104
done; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   105
echo '</ul>'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   106
echo '</body></html>'; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   107
} >$@
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   108
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   109
$(TMPL_DIR)/rst.tmpl: $(TMPL_DIR)/rst.tmpl.in $(MAKEFILE_LIST)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   110
	sed -e "s|{date}|$$(date +%F)|" -e "s|{rev}|$$(hg id -i)|"  <$< >$@
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   111
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   112
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   113
# Init targets.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   114
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   115
$(HTML_DIR):
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   116
	mkdir -p $@
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   117
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   118
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   119
# Clean targets.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   120
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   121
.PHONY: distclean
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   122
distclean: clean
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   123
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   124
.PHONY: clean
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   125
clean:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   126
	rm -r -f $(HTML_DIR)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   127
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   128
################################################################
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   129
# Helper target.
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   130
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   131
.PHONY: help
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   132
help:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   133
	@echo Supported targets:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   134
	@sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(MAKEFILE_LIST)
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   135
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   136
.PHONY: check-format-policy
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   137
check-format-policy:
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   138
	\
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   139
for f in $(RST_FILES); do \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   140
  if grep '^.. -\*- coding: utf-8; -\*-' $$f >/dev/null; then :; else \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   141
    echo $$f:1:" Has no 'coding: utf-8' directive."; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   142
  fi; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   143
  if grep '^.. contents::' $$f >/dev/null; then :; else \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   144
    echo $$f:7:" Has no 'contents::' directive."; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   145
  fi; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   146
  if grep '^   :local:' $$f >/dev/null; then :; else \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   147
    echo $$f:7:" Has no ':local:' directive."; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   148
  fi; \
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   149
done
328995b5b8fd init stat project
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
   150