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