Skip to content

Commit

Permalink
WiP reworked makefile for web version
Browse files Browse the repository at this point in the history
Issue #4
  • Loading branch information
nfeske committed Jan 9, 2019
1 parent fda4382 commit e375aac
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 19 deletions.
19 changes: 1 addition & 18 deletions manual/epub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,7 @@ $(chapter_html_dirs): | splitted_html
splitted_html splitted_txt $(chapter_txt_dirs) $(chapter_html_dirs):
mkdir $@


#
# Rules for converting TikZ figures to PNG images, invoked by 'epub_html.gosh'
#

img/%.tikz: ../img/%.tikz
cd img; ln -s ../../img/$*.tikz

img/%.pdf: img/%.tikz
make -C img $*.pdf

GS_DPI := 200

img/%-unscaled.png: img/%.pdf
gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r$(GS_DPI) -sOutputFile=$@ $<

img/%.png: img/%-unscaled.png
convert -filter lanczos -resize 80% $< $@
include img.mk

#
# Rules for generating the table of contents
Expand Down
2 changes: 1 addition & 1 deletion manual/epub/epub_html.gosh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ proc produce_navbar {} {
if {-1 != $top} {
produce_xrefi_link [expr $doc_index - $top - 1]
} else {
puts "<a href=\"$basepath/splitted_html/index.html\">Table of Contents</a>"
puts "<a href=\"$basepath/index.html\">Table of Contents</a>"
}

puts </span></nav>
Expand Down
25 changes: 25 additions & 0 deletions manual/epub/img.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Rules for converting TikZ figures to PNG images, invoked by 'epub_html.gosh'
#

img/%.tikz: ../img/%.tikz
cd img; ln -s ../../img/$*.tikz

img/%.pdf: img/%.tikz
make -C img $*.pdf

GS_DPI := 200

img/%-unscaled.png: img/%.pdf
gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r$(GS_DPI) -sOutputFile=$@ $<

img/%.png: img/%-unscaled.png
convert -filter lanczos -resize 80% $< $@

GENERATED_IMGS_LOG := $(wildcard img/*.log)
GENERATED_IMGS := $(GENERATED_IMGS_LOG:.log=)

clean_generated_imgs:
rm -f $(foreach suffix,.png .log .tikz .aux,$(addsuffix $(suffix),$(GENERATED_IMGS)))

clean: clean_generated_imgs
142 changes: 142 additions & 0 deletions manual/www/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
SHELL := bash

PWD := $(shell pwd)

# XXX just for testing
CHAPTERS := introduction

#CHAPTERS := introduction \
# getting_started \
# architecture \
# components \
# development \
# system_configuration \
# under_the_hood \
# functional_specification

# return list of sections for given basename of chapter
sections = $(shell ../epub/splitter/filter-sec.sh list < ../$1.txt)

# return Nth path element
second_elem = $(word 2,$(subst /, ,$1))
third_elem = $(word 3,$(subst /, ,$1))

# populate 'SECTIONS(i)' variables, using the chapter as index
$(foreach C,$(CHAPTERS),$(eval SECTIONS($C) := $(call sections,$C)))

ALL_SECTIONS := $(foreach C,$(CHAPTERS),\
$(foreach S,${SECTIONS($C)},\
$C/$S))

ALL_SECTIONS_TXT := $(addprefix sections/,$(addsuffix .txt,$(ALL_SECTIONS)))
ALL_CHAPTERS_TXT := $(addprefix chapters/,$(addsuffix .txt,$(CHAPTERS)))
ALL_SECTIONS_HTML := $(addprefix html/,$(addsuffix .html,$(ALL_SECTIONS)))
ALL_CHAPTERS_INDEX_HTML := $(addprefix html/,$(addsuffix /index.html,$(CHAPTERS)))
ALL_HTML := $(ALL_SECTIONS_HTML) $(ALL_CHAPTERS_INDEX_HTML) html/index.html

# gosh arguments used for all html documents
GOSH_DOC_ARGS := --style ../epub/epub_html \
--web-build \
--html-xrefs xrefs \
--stylesheet style.css \

default: html/style.css $(ALL_HTML)

#
# Create img directory before generating html documents to allow epub_html.gosh
# to create the individual images as side effects of creating the html
# documents.
#
IMG_DIR_CONTENT := Makefile \
tikz-common.tex tikz-preamble.tex tikz-standalone.tex \
qt_avplay_screen.png

$(ALL_HTML): $(addprefix img/,$(IMG_DIR_CONTENT))
$(addprefix img/,$(IMG_DIR_CONTENT)):
mkdir -p img
ln -sf ../../img/$(notdir $@) $@

# generate cross-reference index
xrefs: $(ALL_SECTIONS_TXT) $(ALL_CHAPTERS_TXT)
( $(foreach C,$(CHAPTERS),\
gosh --style html_xrefs --html-path $C/index.html \
chapters/$C.txt; \
$(foreach S,${SECTIONS($C)},\
gosh --style html_xrefs --html-path $C/$S.html \
sections/$C/$S.txt | grep -v FAKE-CHAPTER; )) \
)> $@

# install images generated during the creation of the html documents
default: html/img
html/img: $(ALL_HTML)
.PHONY: html/img
html/img:
mkdir -p $@
cp img/*.png $@

# install CSS file
html/style.css: ../epub/style.css
mkdir -p $(dir $@)
cp $< $@

#
# Main index.html file
#

# rule to generate index.html for a chapter
html/index.html : xrefs
mkdir -p $(dir $@)
gosh $(GOSH_DOC_ARGS) --basepath "." --main-index <(echo '') > $@

#
# Chapter index.html files
#

# rule to extract only the intro of a chapter
chapters/%.txt:
mkdir -p $(dir $@)
../epub/splitter/filter-sec.sh chapter < ../$*.txt > $@

# let each chapter index.html file depend from its corresponding chapter text
$(foreach C,$(CHAPTERS),$(eval html/$C/index.html : ../$C.txt))

# rule to generate index.html for a chapter
$(ALL_CHAPTERS_INDEX_HTML) : xrefs
mkdir -p $(dir $@)
gosh $(GOSH_DOC_ARGS) \
--basepath ".." --unique-name $(call second_elem,$@) \
chapters/$(call second_elem,$@).txt > $@

#
# Sections
#

# let each section text depend on its original chapter text
$(foreach C,$(CHAPTERS),\
$(eval $(addprefix sections/$C/,$(addsuffix .txt,${SECTIONS($C)})) : ../$C.txt))

# rule to extract a section txt from a chapter,
# called with the pattern '<chapter>/<section>'
sections/%.txt:
mkdir -p $(dir $@)
../epub/splitter/filter-sec.sh get $(notdir $*) \
< ../$(firstword $(subst /, ,$*)).txt \
> $@

# let each section HTML file depend from its corresponding section text
$(foreach S,$(ALL_SECTIONS),$(eval html/$S.html : sections/$S.txt))

# rule to generate HTML from a section txt
$(ALL_SECTIONS_HTML) : xrefs
mkdir -p $(dir $@)
chapter=$(call second_elem,$@); \
section=$(call third_elem,$(basename $@)); \
gosh $(GOSH_DOC_ARGS) \
--basepath ".." --unique-name $$section \
--style ../epub/splitter/skip-chapter.gosh \
sections/$$chapter/$$section.txt > $@

include ../epub/img.mk

clean:
rm -rf sections chapters html xrefs img

0 comments on commit e375aac

Please sign in to comment.