Makefile
author František Kučera <franta-hg@frantovo.cz>
Fri, 10 May 2024 00:10:08 +0200
branchv_0
changeset 82 a11239f9f9e7
parent 81 47717a4ed4bb
permissions -rw-r--r--
EPUB: move Preamble to the same level as other chapters

# Sane software manifesto helper tools
# Copyright © 2019-2024 František Kučera (Frantovo.cz, GlobalCode.info)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

VERSION_PARAMS := $(shell hg log -r '.' --template '--stringparam versionTag {latesttag} --stringparam versionDistance {latesttagdistance} --stringparam versionHash {node|short}') "--stringparam" "versionChangedFiles" $(shell hg status | wc -l) 

all: validate xhtml txt pdf build/ssm.en.epub logo-png statistics

validate:
	xmllint --noout --schema schema/ssm.xsd text/ssm.en.xml

xhtml: text/ssm.en.xml templates/cmunrm.woff templates/cmunbx.woff
	mkdir -p build
	xsltproc $(VERSION_PARAMS) --output build/index.xhtml --nonet templates/ssm.xhtml.xsl text/ssm.en.xml
	cp --reflink=auto templates/*.css build
	cp --reflink=auto templates/*.woff build

build/ssm.en.epub: text/ssm.en.xml templates/ssm.xhtml.xsl templates/cmunrm.woff templates/cmunbx.woff
	mkdir -p "build/epub/META-INF"
	mkdir -p "build/epub/OEBPS"
	echo -n "application/epub+zip" > "build/epub/mimetype"
	xsltproc \
		--nonet \
		--xinclude \
		$(VERSION_PARAMS) \
		--output "build/epub/" \
		"templates/ssm.epub.xsl" \
		$(<)
	cp --reflink=auto templates/*.css "build/epub/OEBPS/"
	cp --reflink=auto templates/*.woff "build/epub/OEBPS/"
	cd "build/epub/"; zip -r ../../$(@) \
		-X \
		--suffixes mimetype:jpg:jpeg:png:gif \
		mimetype "META-INF/" "OEBPS/"

templates/cmunrm.ttf:
	cd templates/; ln -s /usr/share/fonts/truetype/cmu/cmunrm.ttf

templates/cmunbx.ttf:
	cd templates/; ln -s /usr/share/fonts/truetype/cmu/cmunbx.ttf

templates/cmunrm.woff: templates/cmunrm.ttf
	cd templates/; sfnt2woff cmunrm.ttf

templates/cmunbx.woff: templates/cmunbx.ttf
	cd templates/; sfnt2woff cmunbx.ttf

pdf:
	mkdir -p build
	xsltproc $(VERSION_PARAMS) --output build/ssm.en.fodt --nonet templates/ssm.odt.xsl text/ssm.en.xml
	libreoffice --convert-to pdf --outdir build build/ssm.en.fodt

# TODO: better line wrapping
txt:
	mkdir -p build
	xsltproc $(VERSION_PARAMS) --nonet templates/ssm.txt.xsl text/ssm.en.xml | fmt -w 74 -s | sed -E 's/(  +)([^- ])/\1  \2/g' > build/ssm.en.txt

logo-png:
	mkdir -p build
	inkscape --export-filename=build/sane-software-logo-circle.png     logo/sane-software-logo-circle.svg
	inkscape --export-filename=build/sane-software-logo-rectangle.png  logo/sane-software-logo-rectangle.svg

clean:
	rm -rf build

publish:
	scp build/*.*     globalcode.info:/var/www/sane-software.globalcode.info/v_0/
	scp license/*.*   globalcode.info:/var/www/sane-software.globalcode.info/license/


# Described at: https://relational-pipes.globalcode.info/v_0/examples-in-xmltable-ssm-gui.xhtml
build/statistics.rp: text/ssm.en.xml
	mkdir -p build
	cat text/ssm.en.xml \
		| relpipe-in-xmltable \
			--namespace "m" "tag:globalcode.info,2019:sane-software/manifesto" \
			--relation "chapter" \
				--records "//m:chapter" \
				--attribute "name" string "m:name" \
				--attribute "requirements" integer "count(descendant::m:item[m:type='requirement'])" \
				--attribute "recommendations" integer "count(descendant::m:item[m:type='recommendation'])" \
				--attribute "informations" integer "count(descendant::m:item[m:type='information'])" \
				--attribute "items_total" integer "count(descendant::m:item)" \
		> build/statistics.rp

# Prints a table with number of items in particular chapters:
statistics: build/statistics.rp
	cat build/statistics.rp | relpipe-out-tabular
	
statistics-chart: build/statistics.rp
	cat build/statistics.rp | relpipe-tr-cut --relation ".*" --attribute "(name|.*s)" | relpipe-out-gui -title "Sane software manifesto – chart of rule types"