# Makefile

# This file is part of Brouhabouha Forth repackaged
# http://programandala.net/en.program.brouhabouha_forth.html

# Marcos Cruz (programandala.net)

################################################################
# History

# 2016-01-20: Start.
# 2016-01-21: Improved recipes. Added conversion to PDF. Added
# recipes to create the zip and tar archives.

################################################################
# Requirements

# Available in your Linux distro or from the given URL:

# - make
# - asciidoctor (http://asciidoctor.org)
# - pandoc (http://john‐macfarlane.net/pandoc/)
# - htmldoc (http://htmldoc.org)

################################################################
# Config

dir     = brouhabouha_forth_repackaged/
archive = brouhabouha_forth_repackaged
doc     = doc/

VPATH = ./:$(doc)
MAKEFLAGS = --no-print-directory

################################################################
# Recipes

.PHONEY: all
all: doc

# Delete all conversions
clean:
	rm -f \
	$(doc)bf.dbk \
	$(doc)bf.epub \
	$(doc)bf.html \
	$(doc)bf.pdf \
	$(doc)bf.txt \
	README.dbk \
	README.html \
	README.epub \
	README.pdf \
	README.txt

################################################################
# Documentation recipes

# Convert the documentation from Asciidoctor to all other formats
.PHONEY: doc
doc: readme manual 

# Convert the manual from Asciidoctor to all other formats
.PHONEY: manual
manual: $(doc)bf.html $(doc)bf.epub $(doc)bf.pdf $(doc)bf.txt

# Convert the README from Asciidoctor to all other formats
.PHONEY: readme
readme: README.html README.epub README.pdf README.txt

# From Asciidoctor to HTML
%.html: %.adoc
	asciidoctor --backend=html5 --out-file=$@ $<

# From Asciidoctor to DocBook
%.dbk: %.adoc
	asciidoctor --backend=docbook45 --out-file=$@ $<

# From DocBook to EPUB
%.epub: %.dbk
	pandoc --from=docbook --to=epub --output=$@ $<

# From HTML to PDF
%.pdf: %.html
	htmldoc --no-toc --outfile $@ $<

# From HTML to text
%.txt: %.dbk
	pandoc --from=docbook --to=plain --standalone --output=$@ $<

################################################################
# Archive recipes

# Convert the documentation from Asciidoctor to all other formats
.PHONEY: archives
archives: zipball tarball

# Create the zip archive for distribution
.PHONEY: zipball
zipball:
	cd .. && \
	zip -9 $(dir)$(archive).zip \
	$(dir)README.* \
	$(dir)Makefile \
	$(dir)doc/bf.* \
	$(dir)src/*.fs \
	$(dir)src/*.fb \
	$(dir)media/*.img \
	$(dir)media/*.win \
	$(dir)original/* \
	$(dir)original/files/* ; \
	cd -

.PHONEY: tarball
tarball:
	cd .. && \
	tar --create  \
	--file $(dir)$(archive).tar.gz \
	--gzip \
	$(dir)README.* \
	$(dir)Makefile \
	$(dir)doc/bf.* \
	$(dir)src/*.fs \
	$(dir)src/*.fb \
	$(dir)media/*.img \
	$(dir)media/*.win \
	$(dir)original/* \
	$(dir)original/files/* ; \
	cd -

################################################################
# Old recipes

# ————————————————————————————————————————————--
# html2text

# Some tries with
# html2text (http://www.mbayer.de/html2text/files.shtml).
# Pandoc produces better results.

# From HTML to text
# (using the file encoding metadata of the HTML file)
#%.txt: %.html
#	html2text -style pretty -o $@ $<

# From HTML to ISO-88591-1 text
#
# XXX OLD -- this converts special chars to UTF-8 chars!
#
#%.iso88591.txt: %.html
#	html2text -nometa -style pretty -o $@ $<

# From HTML to ASCII text
#
# XXX OLD -- this converts special chars to HTML entities
#
#%.ascii.txt: %.html
#	html2text -nometa -style pretty -ascii -o $@ $<

# From HTML to UTF-8 text
#
# XXX OLD -- this makes no difference, because the source is
# UTF-8
#
#%.utf8.txt: %.html
#	html2text -nometa -style pretty -utf8 -o $@ $<

# ————————————————————————————————————————————--

# From Asciidoctor to PDF
#
# XXX TODO -- use asciidoctor-pdf instead of asciidoctor-fopub
#
#$(doc)bf.pdf: $(doc)bf.xml
#	fopub $<


# vim: nolist
